twombly 0.3.0 → 0.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.
- package/dist/cli.js +156 -50
- package/dist/ui/assets/Landing-D4-acwRF.js +111 -0
- package/dist/ui/assets/LandingStage-cWuvBaKD.js +1 -0
- package/dist/ui/assets/agentPrompt-Bg7-ijHJ.js +1 -0
- package/dist/ui/assets/index-COkd0b_O.js +10 -0
- package/dist/ui/assets/index-DBaMyh-f.css +1 -0
- package/dist/ui/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
- package/dist/ui/index.html +5 -2
- package/dist/ui/legal.css +34 -10
- package/dist/ui/privacy.html +11 -7
- package/dist/ui/terms.html +4 -2
- package/dist/ui/theme.js +6 -0
- package/package.json +1 -1
- package/dist/ui/assets/Landing-BKJA0CJt.js +0 -111
- package/dist/ui/assets/LandingStage-DyrNB5Ea.js +0 -1
- package/dist/ui/assets/index-B5osE1GC.js +0 -10
- package/dist/ui/assets/index-Dw-Z6e31.css +0 -1
package/dist/cli.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { spawn as spawn2 } from "node:child_process";
|
|
5
|
-
import { randomBytes as
|
|
6
|
-
import { copyFile as copyFile2, mkdtemp, readFile as
|
|
5
|
+
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
6
|
+
import { copyFile as copyFile2, mkdtemp, readFile as readFile8, rm as rm6, stat as stat5, writeFile as writeFile8 } from "node:fs/promises";
|
|
7
7
|
import { tmpdir } from "node:os";
|
|
8
|
-
import { basename as basename2, extname as extname3, join as
|
|
8
|
+
import { basename as basename2, extname as extname3, join as join10, resolve as resolve2 } from "node:path";
|
|
9
9
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
10
10
|
|
|
11
11
|
// ../protocol/src/gates.ts
|
|
@@ -261,7 +261,7 @@ function nextPosition(frames, newRow = false) {
|
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
// ../../skills/twombly/SKILL.md
|
|
264
|
-
var SKILL_default = "---\nname: twombly\ndescription: Lay out design explorations on a shared canvas. Use when asked to \"put this on Twombly\", \"put these on a canvas\", \"lay out these versions\", \"show me all the variations side by side\", or to share explorations with real-time cursors and comments. Works with any framework in any repo.\n---\n\n# Twombly\n\nTwombly shows design work as live frames on an infinite canvas. You build each version, turn it into a folder of static files, and add it. The canvas opens on `localhost`; `init` returns its address. Nothing is online until the person clicks Share. After that the local canvas and the link are one state: everything you add, update or move appears for everyone straight away.\n\nRun every command as `npx -y twombly@latest <command>`; this guide shortens that to `twombly <command>`. Output is JSON.\n\n## The rule that decides everything\n\n**A frame is a folder of static files that runs with no server and no network.** It can use anything in its own folder and nothing else. The browser enforces this: outside requests, form posts and server code all fail, locally and once shared.\n\nThe person's repo may have a database, an API, auth and environment keys. None of that goes in a frame. Your job is to adapt the design so it works without them:\n\n- **Data and APIs:** replace with realistic mock data, written inline or as JSON in the folder. For public CMS content, save a snapshot as JSON when you build.\n- **Auth and providers:** skip login, and mount the design with mock providers and a fake signed-in user.\n- **Environment values:** never include them. Build with none set. Don't copy `.env` files. If the build needs a value to compile, use an obviously fake one. **Never run or read a secret manager such as Infisical or Doppler for this, even if the project is set up for it.** If you can't get what you need without one, ask the person.\n- **Analytics and widgets:** remove tag managers, analytics, chat widgets and similar scripts, including any in page templates such as `app.html` or `_document`.\n- **Real customer data:** never copy it from a database, fixture or log. Invent names, emails and numbers. The gates can't detect this, so it's on you. Links are public.\n- **Fonts, images and video:** copy the files into the folder with relative or root paths. For a hosted font such as Google Fonts, download the files and use `@font-face`; Google only serves `woff2` to a browser user agent. If a font is licensed, tell the person it will be publicly hosted. Add up media sizes before downloading, take only what the design shows, and compress video.\n- **One screen of a routed app:** a router reads the page's address, which won't match the screen you want. Write a small entry file that mounts that screen with a memory or hash router, instead of trying to reach its route.\n\n## Limits\n\n100 MB per frame, 25 MB per file, 5000 files per frame, 500 frames per canvas. A URL can't be added, not even `localhost`: build it or `capture` it. Refused files: `.env`, credentials, keys, databases, source maps, server code, `node_modules` and project files such as `package.json`. Pop-ups, camera and microphone are off.\n\n## Steps\n\n1. **Start the canvas.** From the project root, or in a monorepo from the app's own folder so `.twombly/work` can find its packages: `twombly init --name \"Notification Explorations\" --no-open`. Pick a short, specific name. Run it once per canvas. The result's `local` field is the canvas's address. If `created` is false, the canvas already existed: see [Other agents and more canvases](#other-agents-and-more-canvases).\n2. **Open it beside the chat.** The person should see the canvas next to this conversation, in the app they're already using. Open the `local` address in that app's built-in browser: the Claude desktop app's browser pane, the ChatGPT app's in-app browser, or the built-in browser in Cursor, VS Code or any other editor. Only if the app has none, run `twombly open`, which uses their default browser.\n3. **Build each version** as its own static folder, keeping work under `.twombly/work/<task>/<version>` so the person's source stays clean. Pick a `<task>` no other agent would, because a shared folder gets overwritten. Use the first approach below that works. The canvas tells people an agent is working: `init` and the slow commands keep that showing for three minutes. Run `twombly working` only before a longer gap.\n4. **Add it:** `twombly add <folder> --title \"V1 Compact\" --width 1280 --height 800 --level build`, saying which level below it is. Use the design's real size, such as `--width 390 --height 844` for a phone. Use `--height auto` to fit a tall page.\n5. **Read the output.** If `ok` is false, fix every item in `problems` and run `add` again. Each one includes a `fix`. The frame isn't placed until it passes.\n6. **Look at it.** The result has a `screenshot` path. Open it and check the frame shows the design you meant, with the content in the right state. The gates can't tell if a page came out unstyled or on the wrong screen; a common miss is Tailwind classes that were never generated. Tailwind 4 skips gitignored folders, so source copied into `.twombly` needs an `@source`.\n7. **Test interactions, if they matter.** Open the `url` from `twombly preview <frame>` in your browser tool and use the page inside its iframe. On the canvas, a frame ignores clicks until it's double-clicked, and frame URLs refuse to open on their own. Tell the person what you didn't test.\n8. **Finish:** run `twombly done` so the background goes still, then tell the person the canvas is open. They click Share when they're ready. The first time, Google sign-in opens in their regular browser, and sharing continues on its own once they finish.\n\n## Choosing how to build a frame\n\nUse the first one that fits. Say so if you end up lower than the first, because the frame is less faithful. **If the app has server routes, auth or a database, skip straight to `component`**: a static export of that kind of app rarely works and isn't worth the attempt.\n\n1. `--level build`: **a real static build.** Vite: `vite build --base ./ --outDir .twombly/work/v1`. Next.js: `output: 'export'` in a temporary config (static export can't use server features). SvelteKit: `adapter-static` with a `fallback`, `ssr = false` in the root layout, and any server `load` swapped for mock data in a universal `+layout.ts`. Astro: `astro build`. Plain HTML: use the folder as is. To show one state of a bigger app, add a build entry that renders just that screen.\n2. `--level component`: **the component on its own.** Write a tiny entry file that imports the real component with mock props, and bundle it with Vite or esbuild into a folder. This is the usual answer when the app needs a backend. It keeps the real code and styles.\n3. `--level capture`: **freeze what's on screen.** With the app already running: `twombly capture http://localhost:3000/page --out .twombly/work/v1 --width 1280 --height 800`, then add that folder. It looks right but no longer responds, because scripts are removed.\n4. `--level image`: **a picture**, as a last resort. `twombly capture <url> --out <folder> --image`, or `twombly add shot.png --title \"V1\"`.\n\nSeveral versions can share one build: read the variant from `location.search` and pass `--entry \"index.html?variant=2\"`. Shared files are only uploaded once.\n\nAdd several frames in one command, which is faster, instead of writing a loop. Nothing is placed unless all of them pass. Each item takes `folder`, `title`, `entry`, `width`, `height`, `level`, `newRow`, `x` and `y`, and flags on the command apply to all:\n\n```sh\ntwombly add out --width 1280 --height 800 --level component --frames '[{\"title\":\"A\",\"entry\":\"index.html?variant=a\"},{\"title\":\"B\",\"entry\":\"index.html?variant=b\"}]'\n```\n\n### Example: the component level with Vite\n\nFor most projects, this is all it takes. It works the same for React, Svelte or Vue with that framework's Vite plugin. Keep it in your own folder under `.twombly/work`; here, `composer`.\n\n```js\n// .twombly/work/composer/vite.config.mjs\nimport { defineConfig } from 'vite';\nimport { resolve } from 'node:path';\nimport react from '@vitejs/plugin-react';\n\nconst root = resolve(import.meta.dirname, '../../..');\nexport default defineConfig({\n root: import.meta.dirname,\n base: './',\n plugins: [react()],\n resolve: { alias: { '@': root } }, // match the project's path aliases\n define: { 'process.env': {} },\n build: { outDir: 'out', emptyOutDir: true, sourcemap: false },\n});\n```\n\n```html\n<!-- .twombly/work/composer/index.html -->\n<!doctype html><html><body><div id=\"root\"></div><script type=\"module\" src=\"./main.jsx\"></script></body></html>\n```\n\n```jsx\n// .twombly/work/composer/main.jsx: the real component, the real styles, invented data.\nimport { createRoot } from 'react-dom/client';\nimport '@/styles/globals.css';\nimport { Composer } from '@/components/composer';\n\nconst variant = new URLSearchParams(location.search).get('variant');\ncreateRoot(document.getElementById('root')).render(<Composer variant={variant} onSend={() => {}} messages={MOCK_MESSAGES} />);\n```\n\nThen: `npx vite build --config .twombly/work/composer/vite.config.mjs` and `twombly add .twombly/work/composer/out --title \"A\" --entry \"index.html?variant=a\" --level component`. If the project uses Tailwind, add its Vite or PostCSS plugin to the config so the classes are generated.\n\n## Commands\n\n`twombly help` lists every command and flag. `<frame>` is a frame's id or its exact title. Frames fill in left to right; use `--new-row` to start a new group, for example one row per direction.\n\nUse `update` to change a version. Don't remove and re-add it, because that loses its comments. It keeps the frame's entry and size unless you change them. Each frame keeps its own copy of its files, so after rebuilding, update the set together: `twombly update out --frames '[{\"frame\":\"A\"},{\"frame\":\"B\"}]'`. Nothing changes unless all of them pass.\n\n## What the person is looking at\n\nWhen the person says \"this\" or \"these\" without naming a frame, run `twombly context`. It returns the frames they have open fullscreen, are using, or have selected, in that order, plus any comment they have open. `looking: false` means no canvas is open in a browser. If nothing is selected, ask which frame they mean.\n\n`twombly comments` returns every comment, with the frame it's on, where on the frame (in the frame's pixels), whether it's resolved, and `mine: true` for the person's own comments.\n\nEach frame in `context` and `list` has a `source`: the folder or file it was last added or updated from. Edit what built it, rebuild, then `update` the frame. Frames added before this existed show `null`.\n\n## Other agents and more canvases\n\nA folder has one default canvas, and every agent in that folder or below it lands on it. `init` on an existing canvas joins it and keeps its name. A folder can also hold any number of named canvases, each with its own address, frames and link.\n\n**Use a named canvas** when your work is a separate exploration, or the person asks for its own canvas: `twombly init --canvas \"Pricing\" --no-open`. Then pass `--canvas \"Pricing\"` on every command, because nothing remembers it between commands. `init --canvas` with a name that exists joins it, so agents can share one by agreeing on the name. `twombly canvases` lists what's here.\n\n**On a canvas with other agents:**\n\n- Only change your own frames, unless the person asks. Any agent's `update`, `move` and `remove` work on any frame, and `arrange` moves all of them.\n- Give frames titles no one else would use, such as \"Pricing: V1\", since commands find frames by title. A repeated title gets a warning, and then has to be addressed by id.\n- Add each set in one `--frames` command, with `--new-row` on its first frame, so it stays together.\n- If `update` says someone else changed a frame, run `twombly list` and don't retry without checking whose work you'd replace.\n- Run `twombly done` when you finish. The canvas keeps showing work until every agent that ran `init` has finished, or three minutes after the last activity.\n\n**Worktrees:** a canvas lives in the folder it was started in. A worktree outside the repo gets its own canvas, which is deleted with the worktree, so tell the person that before removing it. A worktree inside the repo joins the repo's default canvas if there is one.\n\n## Sharing\n\nThe person shares by clicking Share. Only run `twombly share` if they explicitly ask you to, because it publishes the canvas to a public link. If they ask you to take it down, run `twombly unshare`. That deletes the link and keeps the canvas on this machine, comments included.\n\nOnce it's shared, every `add`, `update`, `move` and `remove` goes live immediately. Check your work with `twombly check` before updating a canvas people are looking at.\n";
|
|
264
|
+
var SKILL_default = "---\nname: twombly\ndescription: Lay out design explorations on a shared canvas. Use when asked to \"put this on Twombly\", \"put these on a canvas\", \"lay out these versions\", \"show me all the variations side by side\", or to share explorations with real-time cursors and comments. Works with any framework in any repo.\n---\n\n# Twombly\n\nTwombly shows design work as live frames on an infinite canvas. You build each version, turn it into a folder of static files, and add it. The canvas opens on `localhost`; `init` returns its address. Nothing is online until the person clicks Share. After that the local canvas and the link are one state: everything you add, update or move appears for everyone straight away.\n\nRun every command as `npx -y twombly@latest <command>`; this guide shortens that to `twombly <command>`. Output is JSON.\n\n## The rule that decides everything\n\n**A frame is a folder of static files that runs with no server and no network.** It can use anything in its own folder and nothing else. The browser enforces this: outside requests, form posts and server code all fail, locally and once shared.\n\nThe person's repo may have a database, an API, auth and environment keys. None of that goes in a frame. Your job is to adapt the design so it works without them:\n\n- **Data and APIs:** replace with realistic mock data, written inline or as JSON in the folder. For public CMS content, save a snapshot as JSON when you build.\n- **Auth and providers:** skip login, and mount the design with mock providers and a fake signed-in user.\n- **Environment values:** never include them. Build with none set. Don't copy `.env` files. If the build needs a value to compile, use an obviously fake one. **Never run or read a secret manager such as Infisical or Doppler for this, even if the project is set up for it.** If you can't get what you need without one, ask the person.\n- **Analytics and widgets:** remove tag managers, analytics, chat widgets and similar scripts, including any in page templates such as `app.html` or `_document`.\n- **Real customer data:** never copy it from a database, fixture or log. Invent names, emails and numbers. The gates can't detect this, so it's on you. Links are public.\n- **Fonts, images and video:** copy the files into the folder with relative or root paths. For a hosted font such as Google Fonts, download the files and use `@font-face`; Google only serves `woff2` to a browser user agent. If a font is licensed, tell the person it will be publicly hosted. Add up media sizes before downloading, take only what the design shows, and compress video.\n- **One screen of a routed app:** a router reads the page's address, which won't match the screen you want. Write a small entry file that mounts that screen with a memory or hash router, instead of trying to reach its route.\n\n## Limits\n\n100 MB per frame, 25 MB per file, 5000 files per frame, 500 frames per canvas. A URL can't be added, not even `localhost`: build it or `capture` it. Refused files: `.env`, credentials, keys, databases, source maps, server code, `node_modules` and project files such as `package.json`. Pop-ups, camera and microphone are off.\n\n## Steps\n\n1. **Start the canvas.** From the project root, or in a monorepo from the app's own folder so `.twombly/work` can find its packages: `twombly init --name \"Notification Explorations\" --no-open`. Pick a short, specific name. Run it once per canvas. The result's `local` field is the canvas's address. If `created` is false, the canvas already existed: see [Other agents and more canvases](#other-agents-and-more-canvases).\n2. **Open it beside the chat.** The person should see the canvas next to this conversation, in the app they're already using. Open the `local` address in that app's built-in browser: the Claude desktop app's browser pane, the ChatGPT app's in-app browser, or the built-in browser in Cursor, VS Code or any other editor. Only if the app has none, run `twombly open`, which uses their default browser.\n3. **Build each version** as its own static folder, keeping work under `.twombly/work/<task>/<version>` so the person's source stays clean. Pick a `<task>` no other agent would, because a shared folder gets overwritten. Use the first approach below that works. The canvas tells people an agent is working: `init` and the slow commands keep that showing for three minutes. Run `twombly working` only before a longer gap.\n4. **Add it:** `twombly add <folder> --title \"V1 Compact\" --width 1280 --height 800 --level build`, saying which level below it is. Use the design's real size, such as `--width 390 --height 844` for a phone. Use `--height auto` to fit a tall page.\n5. **Read the output.** If `ok` is false, fix every item in `problems` and run `add` again. Each one includes a `fix`. The frame isn't placed until it passes.\n6. **Look at it.** The result has a `screenshot` path. Open it and check the frame shows the design you meant, with the content in the right state. The gates can't tell if a page came out unstyled or on the wrong screen; a common miss is Tailwind classes that were never generated. Tailwind 4 skips gitignored folders, so source copied into `.twombly` needs an `@source`.\n7. **Test interactions, if they matter.** Open the `url` from `twombly preview <frame>` in your browser tool and use the page inside its iframe. Frame URLs refuse to open on their own. Tell the person what you didn't test.\n8. **Finish:** run `twombly done` so the background goes still, then tell the person the canvas is open. They click Share when they're ready. The first time, Google sign-in opens in their regular browser, and sharing continues on its own once they finish.\n\n## Choosing how to build a frame\n\nUse the first one that fits. Say so if you end up lower than the first, because the frame is less faithful. **If the app has server routes, auth or a database, skip straight to `component`**: a static export of that kind of app rarely works and isn't worth the attempt.\n\n1. `--level build`: **a real static build.** Vite: `vite build --base ./ --outDir .twombly/work/v1`. Next.js: `output: 'export'` in a temporary config (static export can't use server features). SvelteKit: `adapter-static` with a `fallback`, `ssr = false` in the root layout, and any server `load` swapped for mock data in a universal `+layout.ts`. Astro: `astro build`. Plain HTML: use the folder as is. To show one state of a bigger app, add a build entry that renders just that screen.\n2. `--level component`: **the component on its own.** Write a tiny entry file that imports the real component with mock props, and bundle it with Vite or esbuild into a folder. This is the usual answer when the app needs a backend. It keeps the real code and styles.\n3. `--level capture`: **freeze what's on screen.** With the app already running: `twombly capture http://localhost:3000/page --out .twombly/work/v1 --width 1280 --height 800`, then add that folder. It looks right but no longer responds, because scripts are removed.\n4. `--level image`: **a picture**, as a last resort. `twombly capture <url> --out <folder> --image`, or `twombly add shot.png --title \"V1\"`.\n\nSeveral versions can share one build: read the variant from `location.search` and pass `--entry \"index.html?variant=2\"`. Shared files are only uploaded once.\n\nAdd several frames in one command, which is faster, instead of writing a loop. Nothing is placed unless all of them pass. Each item takes `folder`, `title`, `entry`, `width`, `height`, `level`, `newRow`, `x` and `y`, and flags on the command apply to all:\n\n```sh\ntwombly add out --width 1280 --height 800 --level component --frames '[{\"title\":\"A\",\"entry\":\"index.html?variant=a\"},{\"title\":\"B\",\"entry\":\"index.html?variant=b\"}]'\n```\n\n### Example: the component level with Vite\n\nFor most projects, this is all it takes. It works the same for React, Svelte or Vue with that framework's Vite plugin. Keep it in your own folder under `.twombly/work`; here, `composer`.\n\n```js\n// .twombly/work/composer/vite.config.mjs\nimport { defineConfig } from 'vite';\nimport { resolve } from 'node:path';\nimport react from '@vitejs/plugin-react';\n\nconst root = resolve(import.meta.dirname, '../../..');\nexport default defineConfig({\n root: import.meta.dirname,\n base: './',\n plugins: [react()],\n resolve: { alias: { '@': root } }, // match the project's path aliases\n define: { 'process.env': {} },\n build: { outDir: 'out', emptyOutDir: true, sourcemap: false },\n});\n```\n\n```html\n<!-- .twombly/work/composer/index.html -->\n<!doctype html><html><body><div id=\"root\"></div><script type=\"module\" src=\"./main.jsx\"></script></body></html>\n```\n\n```jsx\n// .twombly/work/composer/main.jsx: the real component, the real styles, invented data.\nimport { createRoot } from 'react-dom/client';\nimport '@/styles/globals.css';\nimport { Composer } from '@/components/composer';\n\nconst variant = new URLSearchParams(location.search).get('variant');\ncreateRoot(document.getElementById('root')).render(<Composer variant={variant} onSend={() => {}} messages={MOCK_MESSAGES} />);\n```\n\nThen: `npx vite build --config .twombly/work/composer/vite.config.mjs` and `twombly add .twombly/work/composer/out --title \"A\" --entry \"index.html?variant=a\" --level component`. If the project uses Tailwind, add its Vite or PostCSS plugin to the config so the classes are generated.\n\n## Commands\n\n`twombly help` lists every command and flag. `<frame>` is a frame's id or its exact title. Frames fill in left to right; use `--new-row` to start a new group, for example one row per direction.\n\nUse `update` to change a version. Don't remove and re-add it, because that loses its comments. It keeps the frame's entry and size unless you change them. Each frame keeps its own copy of its files, so after rebuilding, update the set together: `twombly update out --frames '[{\"frame\":\"A\"},{\"frame\":\"B\"}]'`. Nothing changes unless all of them pass.\n\n## What the person is looking at\n\nWhen the person says \"this\" or \"these\" without naming a frame, run `twombly context`. It returns the frames they have open fullscreen, are using, or have selected, in that order, plus any comment they have open. `looking: false` means no canvas is open in a browser. If nothing is selected, ask which frame they mean.\n\n`twombly comments` returns every comment, with the frame it's on, where on the frame (in the frame's pixels), whether it's resolved, and `mine: true` for the person's own comments.\n\nEach frame in `context` and `list` has a `source`: the folder or file it was last added or updated from. Edit what built it, rebuild, then `update` the frame. Frames added before this existed show `null`.\n\n## Other agents and more canvases\n\nA folder has one default canvas, and every agent in that folder or below it lands on it. `init` on an existing canvas joins it and keeps its name. A folder can also hold any number of named canvases, each with its own address, frames and link.\n\n**Use a named canvas** when your work is a separate exploration, or the person asks for its own canvas: `twombly init --canvas \"Pricing\" --no-open`. Then pass `--canvas \"Pricing\"` on every command, because nothing remembers it between commands. `init --canvas` with a name that exists joins it, so agents can share one by agreeing on the name. `twombly canvases` lists what's here.\n\n**On a canvas with other agents:**\n\n- Only change your own frames, unless the person asks. Any agent's `update`, `move` and `remove` work on any frame, and `arrange` moves all of them.\n- Give frames titles no one else would use, such as \"Pricing: V1\", since commands find frames by title. A repeated title gets a warning, and then has to be addressed by id.\n- Add each set in one `--frames` command, with `--new-row` on its first frame, so it stays together.\n- If `update` says someone else changed a frame, run `twombly list` and don't retry without checking whose work you'd replace.\n- Run `twombly done` when you finish. The canvas keeps showing work until every agent that ran `init` has finished, or three minutes after the last activity.\n\n**Worktrees:** a canvas lives in the folder it was started in. A worktree outside the repo gets its own canvas, which is deleted with the worktree, so tell the person that before removing it. A worktree inside the repo joins the repo's default canvas if there is one.\n\n## Sharing\n\nThe person shares by clicking Share. Only run `twombly share` if they explicitly ask you to, because it publishes the canvas to a public link. If they ask you to take it down, run `twombly unshare`. That deletes the link and keeps the canvas on this machine, comments included.\n\nOnce it's shared, every `add`, `update`, `move` and `remove` goes live immediately. Check your work with `twombly check` before updating a canvas people are looking at.\n";
|
|
265
265
|
|
|
266
266
|
// src/capture.ts
|
|
267
267
|
import { createHash } from "node:crypto";
|
|
@@ -303,7 +303,7 @@ async function capture(url, out, options) {
|
|
|
303
303
|
return { folder: out, assets: 1, failed: [] };
|
|
304
304
|
}
|
|
305
305
|
const saved2 = /* @__PURE__ */ new Map(), failed = [];
|
|
306
|
-
const
|
|
306
|
+
const save2 = async (assetUrl) => {
|
|
307
307
|
if (assetUrl.startsWith("data:") || assetUrl.startsWith("blob:")) return null;
|
|
308
308
|
if (saved2.has(assetUrl)) return saved2.get(assetUrl);
|
|
309
309
|
try {
|
|
@@ -333,7 +333,7 @@ async function capture(url, out, options) {
|
|
|
333
333
|
} catch {
|
|
334
334
|
continue;
|
|
335
335
|
}
|
|
336
|
-
const name = await
|
|
336
|
+
const name = await save2(absolute);
|
|
337
337
|
if (!name) continue;
|
|
338
338
|
output = output.split(match[0]).join(`url("${from === "css" ? name.replace("assets/", "") : name}")`);
|
|
339
339
|
}
|
|
@@ -391,7 +391,7 @@ async function capture(url, out, options) {
|
|
|
391
391
|
});
|
|
392
392
|
const replacements = [];
|
|
393
393
|
for (const attribute of found.attributes) {
|
|
394
|
-
const name = await
|
|
394
|
+
const name = await save2(attribute.value);
|
|
395
395
|
if (name) replacements.push({ tag: attribute.tag, name: attribute.name, value: name });
|
|
396
396
|
}
|
|
397
397
|
const styles = await Promise.all(found.styles.map((style) => rewriteCss(style, found.base, "html")));
|
|
@@ -414,11 +414,11 @@ async function capture(url, out, options) {
|
|
|
414
414
|
}
|
|
415
415
|
|
|
416
416
|
// src/daemon.ts
|
|
417
|
-
import { createHash as createHash3, randomBytes } from "node:crypto";
|
|
417
|
+
import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
|
|
418
418
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
419
|
-
import { copyFile, mkdir as
|
|
419
|
+
import { copyFile, mkdir as mkdir7, readFile as readFile6, stat as stat3 } from "node:fs/promises";
|
|
420
420
|
import { createServer as createServer2 } from "node:http";
|
|
421
|
-
import { dirname as dirname3, extname as extname2, join as
|
|
421
|
+
import { dirname as dirname3, extname as extname2, join as join9 } from "node:path";
|
|
422
422
|
import { WebSocketServer, WebSocket } from "ws";
|
|
423
423
|
|
|
424
424
|
// src/credentials.ts
|
|
@@ -593,7 +593,7 @@ var checkedAt = 0;
|
|
|
593
593
|
function interfaceFolders() {
|
|
594
594
|
if (OVERRIDE) return [OVERRIDE];
|
|
595
595
|
const folder = (released) => join5(STORE, String(released));
|
|
596
|
-
return [...saved.filter((released) => released >
|
|
596
|
+
return [...saved.filter((released) => released > 1793918977725).map(folder), BUNDLED, ...saved.filter((released) => released <= 1793918977725).map(folder)];
|
|
597
597
|
}
|
|
598
598
|
function unpack(body) {
|
|
599
599
|
const { payload, signature } = JSON.parse(body);
|
|
@@ -627,7 +627,7 @@ async function check() {
|
|
|
627
627
|
const release = unpack(body);
|
|
628
628
|
if (!release) return;
|
|
629
629
|
etag = response.headers.get("etag") || "";
|
|
630
|
-
if (release.released > Math.max(saved[0] ?? 0,
|
|
630
|
+
if (release.released > Math.max(saved[0] ?? 0, 1793918977725)) await install(release.released, release.files);
|
|
631
631
|
}
|
|
632
632
|
function startCheck() {
|
|
633
633
|
if (checking) return;
|
|
@@ -784,7 +784,7 @@ import { join as join7 } from "node:path";
|
|
|
784
784
|
var FILE = join7(HOME, "settings.json");
|
|
785
785
|
async function readSettings() {
|
|
786
786
|
const saved2 = await readFile4(FILE, "utf8").then(JSON.parse).catch(() => null);
|
|
787
|
-
return { invertScroll: saved2?.invertScroll === true };
|
|
787
|
+
return { invertScroll: saved2?.invertScroll === true, theme: saved2?.theme === "light" || saved2?.theme === "dark" ? saved2.theme : void 0 };
|
|
788
788
|
}
|
|
789
789
|
async function writeSettings(settings2) {
|
|
790
790
|
await mkdir5(HOME, { recursive: true });
|
|
@@ -793,11 +793,89 @@ async function writeSettings(settings2) {
|
|
|
793
793
|
await rename3(temporary, FILE);
|
|
794
794
|
}
|
|
795
795
|
|
|
796
|
+
// src/usage.ts
|
|
797
|
+
import { randomBytes } from "node:crypto";
|
|
798
|
+
import { existsSync } from "node:fs";
|
|
799
|
+
import { mkdir as mkdir6, readFile as readFile5, rename as rename4, rm as rm5, writeFile as writeFile6 } from "node:fs/promises";
|
|
800
|
+
import { homedir as homedir2 } from "node:os";
|
|
801
|
+
import { join as join8 } from "node:path";
|
|
802
|
+
var FILE2 = join8(HOME, "usage.json");
|
|
803
|
+
var OFF = join8(HOME, "usage-off");
|
|
804
|
+
var CHECK_MS2 = 36e5;
|
|
805
|
+
var ERRORS_PER_RUN = 20;
|
|
806
|
+
var state = null;
|
|
807
|
+
var saving = null;
|
|
808
|
+
var errorsSent = 0;
|
|
809
|
+
var usageOn = () => process.env.TWOMBLY_NO_USAGE !== "1" && !existsSync(OFF);
|
|
810
|
+
var scrub = (text2, max) => text2.split(homedir2()).join("~").slice(0, max);
|
|
811
|
+
var today = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
812
|
+
var post = (path, body) => fetch(ENDPOINT + path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body), signal: AbortSignal.timeout(1e4) });
|
|
813
|
+
async function setUsage(on) {
|
|
814
|
+
await mkdir6(HOME, { recursive: true });
|
|
815
|
+
if (on) await rm5(OFF, { force: true });
|
|
816
|
+
else await writeFile6(OFF, "");
|
|
817
|
+
}
|
|
818
|
+
async function load() {
|
|
819
|
+
const saved2 = await readFile5(FILE2, "utf8").then(JSON.parse).catch(() => null);
|
|
820
|
+
const install3 = typeof saved2?.install === "string" && /^[a-z0-9]{16,40}$/.test(saved2.install) ? saved2.install : randomBytes(12).toString("hex");
|
|
821
|
+
return { install: install3, day: typeof saved2?.day === "string" ? saved2.day : today(), counts: saved2?.counts && typeof saved2.counts === "object" ? saved2.counts : {} };
|
|
822
|
+
}
|
|
823
|
+
function save() {
|
|
824
|
+
if (saving) return;
|
|
825
|
+
saving = setTimeout(async () => {
|
|
826
|
+
saving = null;
|
|
827
|
+
if (!state) return;
|
|
828
|
+
await mkdir6(HOME, { recursive: true }).catch(() => {
|
|
829
|
+
});
|
|
830
|
+
const temporary = `${FILE2}.${process.pid}`;
|
|
831
|
+
await writeFile6(temporary, JSON.stringify(state)).then(() => rename4(temporary, FILE2)).catch(() => {
|
|
832
|
+
});
|
|
833
|
+
}, 1e3);
|
|
834
|
+
}
|
|
835
|
+
function tally(key, by = 1) {
|
|
836
|
+
if (!state || !usageOn()) return;
|
|
837
|
+
state.counts[key] = (state.counts[key] || 0) + by;
|
|
838
|
+
save();
|
|
839
|
+
}
|
|
840
|
+
async function flush() {
|
|
841
|
+
if (!state || state.day === today()) return;
|
|
842
|
+
const { day, counts } = state;
|
|
843
|
+
state.day = today();
|
|
844
|
+
state.counts = {};
|
|
845
|
+
save();
|
|
846
|
+
if (!usageOn() || !Object.values(counts).some(Boolean)) return;
|
|
847
|
+
const canvases2 = Object.keys(await readRegistry()).length;
|
|
848
|
+
await post("/api/usage", { install: state.install, day, version: "0.4.0", platform: process.platform, counts: { ...counts, canvases: canvases2 } }).catch(() => {
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
async function startUsage() {
|
|
852
|
+
state = await load();
|
|
853
|
+
await flush();
|
|
854
|
+
tally("starts");
|
|
855
|
+
setInterval(() => {
|
|
856
|
+
flush().catch(() => {
|
|
857
|
+
});
|
|
858
|
+
}, CHECK_MS2).unref();
|
|
859
|
+
}
|
|
860
|
+
function reportError(error, source = "tool") {
|
|
861
|
+
if (!usageOn() || ++errorsSent > ERRORS_PER_RUN) return;
|
|
862
|
+
post("/api/errors", {
|
|
863
|
+
source,
|
|
864
|
+
mode: "local",
|
|
865
|
+
install: state?.install,
|
|
866
|
+
version: "0.4.0",
|
|
867
|
+
type: String(error.type || "Error").slice(0, 80),
|
|
868
|
+
message: scrub(String(error.message), 500),
|
|
869
|
+
stack: scrub(String(error.stack || ""), 4e3)
|
|
870
|
+
}).catch(() => {
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
|
|
796
874
|
// src/daemon.ts
|
|
797
875
|
var IDLE_MS = 6 * 36e5;
|
|
798
876
|
var LOGIN_MS = 10 * 6e4;
|
|
799
877
|
var ID_ALPHABET = "abcdefghijkmnpqrstuvwxyz23456789";
|
|
800
|
-
var randomId = (length) => [...
|
|
878
|
+
var randomId = (length) => [...randomBytes2(length)].map((b) => ID_ALPHABET[b % ID_ALPHABET.length]).join("");
|
|
801
879
|
var Failure = class extends Error {
|
|
802
880
|
status;
|
|
803
881
|
extra;
|
|
@@ -812,7 +890,7 @@ var credential = null;
|
|
|
812
890
|
var pendingLogin = null;
|
|
813
891
|
function loginUrl() {
|
|
814
892
|
if (!pendingLogin || Date.now() - pendingLogin.at > LOGIN_MS) {
|
|
815
|
-
pendingLogin = { state:
|
|
893
|
+
pendingLogin = { state: randomBytes2(24).toString("hex"), verifier: randomBytes2(32).toString("base64url"), at: Date.now() };
|
|
816
894
|
}
|
|
817
895
|
const challenge = createHash3("sha256").update(pendingLogin.verifier).digest("base64url");
|
|
818
896
|
return `${ENDPOINT}/auth/machine/start?` + new URLSearchParams({ port: String(PORT), state: pendingLogin.state, challenge });
|
|
@@ -1165,7 +1243,7 @@ var Canvas = class {
|
|
|
1165
1243
|
const { files } = await folderContent(frameDir(this.project, frame.id));
|
|
1166
1244
|
let poster = null, posterBytes = null;
|
|
1167
1245
|
if (frame.hasPoster) {
|
|
1168
|
-
posterBytes = await
|
|
1246
|
+
posterBytes = await readFile6(posterFile(this.project, frame.id)).catch(() => null);
|
|
1169
1247
|
if (posterBytes) poster = createHash3("sha256").update(posterBytes).digest("hex");
|
|
1170
1248
|
}
|
|
1171
1249
|
const manifest = files.map(({ path, hash, size: size2 }) => ({ path, hash, size: size2 }));
|
|
@@ -1179,7 +1257,7 @@ var Canvas = class {
|
|
|
1179
1257
|
await Promise.all(Array.from({ length: 6 }, async () => {
|
|
1180
1258
|
while (next < queue.length) {
|
|
1181
1259
|
const file2 = queue[next++];
|
|
1182
|
-
await put(file2.hash, await
|
|
1260
|
+
await put(file2.hash, await readFile6(file2.absolute));
|
|
1183
1261
|
}
|
|
1184
1262
|
}));
|
|
1185
1263
|
if (poster && posterBytes && wanted.has(poster)) await put(poster, posterBytes);
|
|
@@ -1354,6 +1432,7 @@ async function command(name, input) {
|
|
|
1354
1432
|
found = project;
|
|
1355
1433
|
}
|
|
1356
1434
|
const canvas2 = await canvasForProject(found);
|
|
1435
|
+
if (created) tally("canvasesCreated");
|
|
1357
1436
|
if (input.open !== false && !canvas2.watchers) openBrowser(`${DAEMON_ORIGIN}/${canvas2.id}`);
|
|
1358
1437
|
canvas2.working(WORKING_MS, true);
|
|
1359
1438
|
return { ...summary(canvas2), created };
|
|
@@ -1410,7 +1489,7 @@ async function command(name, input) {
|
|
|
1410
1489
|
return summary(canvas);
|
|
1411
1490
|
}
|
|
1412
1491
|
case "rename":
|
|
1413
|
-
await
|
|
1492
|
+
await rename5(canvas, input.name);
|
|
1414
1493
|
return summary(canvas);
|
|
1415
1494
|
case "share": {
|
|
1416
1495
|
if (!credential) throw new Failure(401, "The person needs to sign in first. Ask them to click Share on the canvas.");
|
|
@@ -1425,7 +1504,7 @@ async function command(name, input) {
|
|
|
1425
1504
|
}
|
|
1426
1505
|
});
|
|
1427
1506
|
}
|
|
1428
|
-
async function
|
|
1507
|
+
async function rename5(canvas, name) {
|
|
1429
1508
|
const clean = String(name || "").trim().slice(0, LIMITS.nameChars);
|
|
1430
1509
|
if (!clean) throw new Failure(400, "Expected a name");
|
|
1431
1510
|
if (canvas.data.remote) await edge(`/api/canvases/${canvas.data.remote.id}`, { method: "PATCH", body: JSON.stringify({ name: clean }) });
|
|
@@ -1442,7 +1521,7 @@ async function install2(canvas, id, folder, screenshot) {
|
|
|
1442
1521
|
await replaceFolder(folder, frameDir(canvas.project, id));
|
|
1443
1522
|
if (screenshot) {
|
|
1444
1523
|
const poster = posterFile(canvas.project, id);
|
|
1445
|
-
await
|
|
1524
|
+
await mkdir7(dirname3(poster), { recursive: true });
|
|
1446
1525
|
await copyFile(screenshot, poster);
|
|
1447
1526
|
}
|
|
1448
1527
|
return (await folderContent(frameDir(canvas.project, id))).content;
|
|
@@ -1480,6 +1559,7 @@ async function place(canvas, input) {
|
|
|
1480
1559
|
frames.push({ ...placedFrame(frame), warnings });
|
|
1481
1560
|
}
|
|
1482
1561
|
canvas.working(WORKING_TAIL_MS);
|
|
1562
|
+
tally("framesAdded", frames.length);
|
|
1483
1563
|
return { frames, canvas: canvasResult(canvas) };
|
|
1484
1564
|
}
|
|
1485
1565
|
async function revise(canvas, input) {
|
|
@@ -1507,6 +1587,7 @@ async function revise(canvas, input) {
|
|
|
1507
1587
|
frames.push({ ...placedFrame(frame), warnings: [] });
|
|
1508
1588
|
}
|
|
1509
1589
|
canvas.working(WORKING_TAIL_MS);
|
|
1590
|
+
tally("framesUpdated", frames.length);
|
|
1510
1591
|
return { frames, canvas: canvasResult(canvas) };
|
|
1511
1592
|
}
|
|
1512
1593
|
var JSON_HEADERS = { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" };
|
|
@@ -1557,7 +1638,7 @@ async function serveUi(response, pathname) {
|
|
|
1557
1638
|
let file2 = null;
|
|
1558
1639
|
if (clean && !clean.includes("..")) {
|
|
1559
1640
|
for (const folder of interfaceFolders()) {
|
|
1560
|
-
const candidate =
|
|
1641
|
+
const candidate = join9(folder, clean);
|
|
1561
1642
|
if ((await stat3(candidate).catch(() => null))?.isFile()) {
|
|
1562
1643
|
file2 = candidate;
|
|
1563
1644
|
break;
|
|
@@ -1566,7 +1647,7 @@ async function serveUi(response, pathname) {
|
|
|
1566
1647
|
}
|
|
1567
1648
|
if (!file2) {
|
|
1568
1649
|
await freshInterface();
|
|
1569
|
-
file2 =
|
|
1650
|
+
file2 = join9(interfaceFolders()[0], "index.html");
|
|
1570
1651
|
}
|
|
1571
1652
|
const type = contentType(file2);
|
|
1572
1653
|
const headers = { "content-type": type, "x-content-type-options": "nosniff", "cache-control": extname2(file2) === ".html" ? "no-cache" : "public, max-age=3600" };
|
|
@@ -1593,15 +1674,15 @@ async function servePreview(response, canvasId, frameId) {
|
|
|
1593
1674
|
async function route(request, response) {
|
|
1594
1675
|
const url = new URL(request.url || "/", DAEMON_ORIGIN);
|
|
1595
1676
|
const path = url.pathname, method = request.method || "GET";
|
|
1596
|
-
if (path === "/health") return reply(response, 200, { ok: true, build: "0.
|
|
1677
|
+
if (path === "/health") return reply(response, 200, { ok: true, build: "0.4.0+1793918977725", api: TOOL_API, pid: process.pid });
|
|
1597
1678
|
if (path.startsWith("/cli/") && method === "POST") return reply(response, 200, await command(path.slice(5), await readBody(request)));
|
|
1598
1679
|
if (path === "/auth/callback" && method === "GET") {
|
|
1599
|
-
const code = url.searchParams.get("code"),
|
|
1680
|
+
const code = url.searchParams.get("code"), state2 = url.searchParams.get("state");
|
|
1600
1681
|
const page = (text2, status = 200) => {
|
|
1601
1682
|
response.writeHead(status, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store", "referrer-policy": "no-referrer", "content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'" });
|
|
1602
1683
|
response.end(`<!doctype html><meta charset="utf-8"><title>Twombly</title><style>body{font:13px/1.5 -apple-system,system-ui,sans-serif;display:grid;place-items:center;height:100vh;margin:0}@media(prefers-color-scheme:dark){body{background:#1e1e1e;color:#fff}}</style><p>${text2}</p><script>setTimeout(()=>window.close(),600)</script>`);
|
|
1603
1684
|
};
|
|
1604
|
-
if (!code || !pendingLogin ||
|
|
1685
|
+
if (!code || !pendingLogin || state2 !== pendingLogin.state) return page("That sign-in expired. Try again.", 400);
|
|
1605
1686
|
const exchange = await fetch(`${ENDPOINT}/auth/machine/exchange`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ code, verifier: pendingLogin.verifier }) });
|
|
1606
1687
|
const data = await exchange.json().catch(() => ({}));
|
|
1607
1688
|
pendingLogin = null;
|
|
@@ -1625,8 +1706,9 @@ async function route(request, response) {
|
|
|
1625
1706
|
}
|
|
1626
1707
|
if (path === "/api/login" && method === "POST") return reply(response, 200, await command("login", {}));
|
|
1627
1708
|
if (path === "/api/settings" && method === "POST") {
|
|
1628
|
-
const { invertScroll } = await readBody(request);
|
|
1709
|
+
const { invertScroll, theme } = await readBody(request);
|
|
1629
1710
|
if (typeof invertScroll === "boolean") settings = { ...settings, invertScroll };
|
|
1711
|
+
if (theme === "light" || theme === "dark") settings = { ...settings, theme };
|
|
1630
1712
|
await writeSettings(settings);
|
|
1631
1713
|
for (const canvas of canvases.values()) canvas.event({ t: "settings", settings });
|
|
1632
1714
|
return reply(response, 200, settings);
|
|
@@ -1638,8 +1720,18 @@ async function route(request, response) {
|
|
|
1638
1720
|
if (!canvas.data.remote || !credential) return reply(response, 200, { url: `ws://localhost:${PORT}/local/${canvas.id}` });
|
|
1639
1721
|
return reply(response, 200, await edge(`/api/canvases/${canvas.data.remote.id}/ticket`, { method: "POST", body: "{}" }));
|
|
1640
1722
|
}
|
|
1641
|
-
if (match[2] === "share")
|
|
1723
|
+
if (match[2] === "share") {
|
|
1724
|
+
const url2 = await canvas.run(() => canvas.share());
|
|
1725
|
+
tally("shares");
|
|
1726
|
+
return reply(response, 200, { url: url2 });
|
|
1727
|
+
}
|
|
1642
1728
|
await canvas.run(() => canvas.unshare());
|
|
1729
|
+
tally("unshares");
|
|
1730
|
+
return reply(response, 200, { ok: true });
|
|
1731
|
+
}
|
|
1732
|
+
if (path === "/api/errors" && method === "POST") {
|
|
1733
|
+
const body = await readBody(request);
|
|
1734
|
+
if (typeof body.message === "string") reportError(body, "canvas");
|
|
1643
1735
|
return reply(response, 200, { ok: true });
|
|
1644
1736
|
}
|
|
1645
1737
|
if (path.startsWith("/api/")) return reply(response, 404, { error: "Not found" });
|
|
@@ -1677,6 +1769,7 @@ async function runDaemon() {
|
|
|
1677
1769
|
}
|
|
1678
1770
|
if (error instanceof Failure) return reply(response, error.status, { error: error.message, ...error.extra });
|
|
1679
1771
|
console.error(error);
|
|
1772
|
+
reportError(error instanceof Error ? { type: error.name, message: error.message, stack: error.stack } : { message: String(error) });
|
|
1680
1773
|
reply(response, 500, { error: error instanceof Error ? error.message : "Something went wrong" });
|
|
1681
1774
|
} finally {
|
|
1682
1775
|
if (counted) inFlight--;
|
|
@@ -1696,7 +1789,10 @@ async function runDaemon() {
|
|
|
1696
1789
|
}
|
|
1697
1790
|
sockets.handleUpgrade(request, socket, head, (client) => {
|
|
1698
1791
|
if (match[2]) canvas.attachEvents(client);
|
|
1699
|
-
else
|
|
1792
|
+
else {
|
|
1793
|
+
tally("canvasViews");
|
|
1794
|
+
canvas.attach(client).catch(() => client.close());
|
|
1795
|
+
}
|
|
1700
1796
|
});
|
|
1701
1797
|
});
|
|
1702
1798
|
await new Promise((resolve3, reject) => {
|
|
@@ -1706,11 +1802,13 @@ async function runDaemon() {
|
|
|
1706
1802
|
touch();
|
|
1707
1803
|
startInterfaceUpdates().catch(() => {
|
|
1708
1804
|
});
|
|
1805
|
+
startUsage().catch(() => {
|
|
1806
|
+
});
|
|
1709
1807
|
}
|
|
1710
1808
|
|
|
1711
1809
|
// src/gates.ts
|
|
1712
1810
|
import { createServer as createServer3 } from "node:http";
|
|
1713
|
-
import { mkdir as
|
|
1811
|
+
import { mkdir as mkdir8, readFile as readFile7, stat as stat4, writeFile as writeFile7 } from "node:fs/promises";
|
|
1714
1812
|
import { dirname as dirname4 } from "node:path";
|
|
1715
1813
|
var dedupe = (problems) => [...new Map(problems.map((p) => [`${p.code}:${p.file || ""}:${p.message}`, p])).values()];
|
|
1716
1814
|
async function scanFolder(folder) {
|
|
@@ -1727,7 +1825,7 @@ async function scanFolder(folder) {
|
|
|
1727
1825
|
continue;
|
|
1728
1826
|
}
|
|
1729
1827
|
if (file2.size > LIMITS.fileBytes) problems.push({ code: "FILE_TOO_LARGE", message: `"${file2.path}" is ${(file2.size / 1048576).toFixed(1)} MB; the limit is ${LIMITS.fileBytes / 1048576} MB.`, fix: "Compress it, or swap in a smaller asset.", file: file2.path });
|
|
1730
|
-
problems.push(...scanBytes(file2.path, await
|
|
1828
|
+
problems.push(...scanBytes(file2.path, await readFile7(file2.absolute)));
|
|
1731
1829
|
}
|
|
1732
1830
|
if (files.length > LIMITS.frameFiles) problems.push({ code: "TOO_MANY_FILES", message: `${files.length} files; the limit is ${LIMITS.frameFiles}.`, fix: "This looks like more than one built page. Add only what the frame needs." });
|
|
1733
1831
|
if (bytes > LIMITS.frameBytes) {
|
|
@@ -1745,7 +1843,7 @@ function entryProblems(files, entry) {
|
|
|
1745
1843
|
async function findReferences(folder, needle) {
|
|
1746
1844
|
const found = [];
|
|
1747
1845
|
for (const file2 of await hashFolder(folder)) {
|
|
1748
|
-
const bytes = await
|
|
1846
|
+
const bytes = await readFile7(file2.absolute);
|
|
1749
1847
|
if (looksLikeText(bytes) && bytes.includes(needle)) found.push(file2.path);
|
|
1750
1848
|
if (found.length === 3) break;
|
|
1751
1849
|
}
|
|
@@ -1838,8 +1936,8 @@ async function browserGates(folder, options, launch) {
|
|
|
1838
1936
|
const shot = await page.locator("#frame").screenshot({ type: "png", timeout: 15e3 }).catch(() => null);
|
|
1839
1937
|
if (shot) {
|
|
1840
1938
|
if (options.poster) {
|
|
1841
|
-
await
|
|
1842
|
-
await
|
|
1939
|
+
await mkdir8(dirname4(options.poster), { recursive: true });
|
|
1940
|
+
await writeFile7(options.poster, shot);
|
|
1843
1941
|
}
|
|
1844
1942
|
const colors = await page.evaluate(async (base64) => {
|
|
1845
1943
|
const image = new Image();
|
|
@@ -1902,7 +2000,7 @@ async function runGates(folder, options) {
|
|
|
1902
2000
|
}
|
|
1903
2001
|
|
|
1904
2002
|
// src/cli.ts
|
|
1905
|
-
var HELP = `twombly ${"0.
|
|
2003
|
+
var HELP = `twombly ${"0.4.0"}: put design explorations on a shared canvas.
|
|
1906
2004
|
|
|
1907
2005
|
init [--name "Name"] [--no-open] create or join this folder's canvas
|
|
1908
2006
|
init --canvas "Name" [--no-open] create or join a separate named canvas in this folder
|
|
@@ -1925,6 +2023,7 @@ var HELP = `twombly ${"0.3.0"}: put design explorations on a shared canvas.
|
|
|
1925
2023
|
list | move <frame> --x N --y N | resize <frame> --width N --height N
|
|
1926
2024
|
retitle <frame> "T" | remove <frame> | arrange [--columns N] | rename "Name"
|
|
1927
2025
|
open | status | login | logout | stop
|
|
2026
|
+
usage on | off the daily counts and error reports this machine sends to Twombly
|
|
1928
2027
|
share | unshare only when the person asks: this publishes a public link
|
|
1929
2028
|
guide how to adapt a project into frames. Read this first.`;
|
|
1930
2029
|
var SWITCHES = /* @__PURE__ */ new Set(["no-open", "new-row", "image"]);
|
|
@@ -2003,12 +2102,12 @@ async function health() {
|
|
|
2003
2102
|
var builtAt = (build) => Number(build.split("+")[1]) || 0;
|
|
2004
2103
|
var sleep = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
2005
2104
|
var IDLE_WAIT_MS = 6e4;
|
|
2006
|
-
var usable = (running) => !!running && (running.build === "0.
|
|
2105
|
+
var usable = (running) => !!running && (running.build === "0.4.0+1793918977725" || running.api === TOOL_API && builtAt(running.build) > builtAt("0.4.0+1793918977725"));
|
|
2007
2106
|
async function ensureDaemon() {
|
|
2008
2107
|
const running = await health();
|
|
2009
2108
|
if (usable(running)) return;
|
|
2010
2109
|
if (running) {
|
|
2011
|
-
if (builtAt(running.build) > builtAt("0.
|
|
2110
|
+
if (builtAt(running.build) > builtAt("0.4.0+1793918977725")) fail("A newer twombly is running on this machine. Run this with twombly@latest.");
|
|
2012
2111
|
let stopped = false;
|
|
2013
2112
|
for (const end = Date.now() + IDLE_WAIT_MS; !stopped && Date.now() < end; ) {
|
|
2014
2113
|
const answer = await fetch(`${DAEMON_ORIGIN}/cli/stop`, { method: "POST", body: '{"ifIdle":true}' }).then((response) => response.json()).catch(() => ({ stopped: true }));
|
|
@@ -2043,13 +2142,13 @@ async function prepare(source) {
|
|
|
2043
2142
|
const extension = extname3(source).toLowerCase();
|
|
2044
2143
|
const isImage = IMAGE.has(extension);
|
|
2045
2144
|
if (!isImage && extension !== ".html" && extension !== ".htm") fail("Point at a folder of static files, an HTML file or an image.");
|
|
2046
|
-
const temporary = await mkdtemp(
|
|
2145
|
+
const temporary = await mkdtemp(join10(tmpdir(), "twombly-"));
|
|
2047
2146
|
if (isImage) {
|
|
2048
2147
|
const name = `image${extension}`;
|
|
2049
|
-
await copyFile2(source,
|
|
2050
|
-
await
|
|
2148
|
+
await copyFile2(source, join10(temporary, name));
|
|
2149
|
+
await writeFile8(join10(temporary, "index.html"), `<!doctype html><meta charset="utf-8"><title>${basename2(source)}</title><style>html,body{margin:0;background:#fff}img{display:block;width:100%;height:auto}</style><img src="${name}" alt="">`);
|
|
2051
2150
|
} else {
|
|
2052
|
-
await copyFile2(source,
|
|
2151
|
+
await copyFile2(source, join10(temporary, "index.html"));
|
|
2053
2152
|
}
|
|
2054
2153
|
return { folder: temporary, temporary, image: isImage };
|
|
2055
2154
|
}
|
|
@@ -2082,7 +2181,7 @@ async function frameItems(flags, known) {
|
|
|
2082
2181
|
const { frames: _, ...shared } = flags;
|
|
2083
2182
|
let items;
|
|
2084
2183
|
try {
|
|
2085
|
-
items = JSON.parse(value.trimStart().startsWith("[") ? value : await
|
|
2184
|
+
items = JSON.parse(value.trimStart().startsWith("[") ? value : await readFile8(value, "utf8"));
|
|
2086
2185
|
} catch (error) {
|
|
2087
2186
|
fail(`--frames: ${error instanceof Error ? error.message : error}`);
|
|
2088
2187
|
}
|
|
@@ -2102,7 +2201,7 @@ async function frameItems(flags, known) {
|
|
|
2102
2201
|
}
|
|
2103
2202
|
async function placeFrames(project, many, jobs, command2, item) {
|
|
2104
2203
|
await markWorking();
|
|
2105
|
-
const scratch = await mkdtemp(
|
|
2204
|
+
const scratch = await mkdtemp(join10(tmpdir(), "twombly-gates-"));
|
|
2106
2205
|
const gates = gateSession(), prepared = /* @__PURE__ */ new Map(), temporary = [];
|
|
2107
2206
|
let keepScratch = false;
|
|
2108
2207
|
try {
|
|
@@ -2117,7 +2216,7 @@ async function placeFrames(project, many, jobs, command2, item) {
|
|
|
2117
2216
|
await Promise.all(Array.from({ length: CONCURRENT_GATES }, async () => {
|
|
2118
2217
|
while (next < jobs.length) {
|
|
2119
2218
|
const index = next++, job = jobs[index];
|
|
2120
|
-
results[index] = await gates.run(prepared.get(job.source).folder, { entry: job.entry, width: job.width, height: job.height, poster:
|
|
2219
|
+
results[index] = await gates.run(prepared.get(job.source).folder, { entry: job.entry, width: job.width, height: job.height, poster: join10(scratch, `${job.id}.png`) });
|
|
2121
2220
|
}
|
|
2122
2221
|
}));
|
|
2123
2222
|
if (results.some((result) => !result.ok)) {
|
|
@@ -2141,8 +2240,8 @@ async function placeFrames(project, many, jobs, command2, item) {
|
|
|
2141
2240
|
print({ ok: true, placed: true, frames: placed.map(({ frame, ...rest }) => ({ ...frame, ...rest })), canvas, next: NEXT });
|
|
2142
2241
|
} finally {
|
|
2143
2242
|
await gates.close();
|
|
2144
|
-
for (const folder of temporary) await
|
|
2145
|
-
if (!keepScratch) await
|
|
2243
|
+
for (const folder of temporary) await rm6(folder, { recursive: true, force: true });
|
|
2244
|
+
if (!keepScratch) await rm6(scratch, { recursive: true, force: true });
|
|
2146
2245
|
}
|
|
2147
2246
|
}
|
|
2148
2247
|
async function addFrames(project, source, many, items) {
|
|
@@ -2159,7 +2258,7 @@ async function addFrames(project, source, many, items) {
|
|
|
2159
2258
|
entry: text(flags, "entry") || "index.html",
|
|
2160
2259
|
width: size(flags, "width", 1280),
|
|
2161
2260
|
height: flags.height === "auto" ? "auto" : size(flags, "height", 800),
|
|
2162
|
-
id:
|
|
2261
|
+
id: randomBytes3(8).toString("hex").replace(/[01lo]/g, "a").slice(0, 12)
|
|
2163
2262
|
};
|
|
2164
2263
|
});
|
|
2165
2264
|
await placeFrames(project, many, jobs, "place", (job, { result, image }) => ({
|
|
@@ -2229,7 +2328,7 @@ async function main() {
|
|
|
2229
2328
|
return;
|
|
2230
2329
|
case "--version":
|
|
2231
2330
|
case "version":
|
|
2232
|
-
process.stdout.write("0.
|
|
2331
|
+
process.stdout.write("0.4.0\n");
|
|
2233
2332
|
return;
|
|
2234
2333
|
case "guide":
|
|
2235
2334
|
process.stdout.write(SKILL_default);
|
|
@@ -2260,15 +2359,15 @@ async function main() {
|
|
|
2260
2359
|
if (!source) fail("twombly check <folder> checks a build before it is added. It needs the build's folder.");
|
|
2261
2360
|
await markWorking();
|
|
2262
2361
|
const { folder, temporary } = await prepare(resolve2(source));
|
|
2263
|
-
const scratch = await mkdtemp(
|
|
2264
|
-
const shot =
|
|
2362
|
+
const scratch = await mkdtemp(join10(tmpdir(), "twombly-check-"));
|
|
2363
|
+
const shot = join10(scratch, "screenshot.png");
|
|
2265
2364
|
try {
|
|
2266
2365
|
const height = flags.height === "auto" ? "auto" : size(flags, "height", 800);
|
|
2267
2366
|
const result = await runGates(folder, { entry: text(flags, "entry") || "index.html", width: size(flags, "width", 1280), height, poster: shot });
|
|
2268
2367
|
print(result);
|
|
2269
2368
|
if (!result.ok) process.exitCode = 1;
|
|
2270
2369
|
} finally {
|
|
2271
|
-
if (temporary) await
|
|
2370
|
+
if (temporary) await rm6(temporary, { recursive: true, force: true });
|
|
2272
2371
|
}
|
|
2273
2372
|
return;
|
|
2274
2373
|
}
|
|
@@ -2370,6 +2469,13 @@ async function main() {
|
|
|
2370
2469
|
case "logout":
|
|
2371
2470
|
print({ ok: true, ...await call("logout") });
|
|
2372
2471
|
return;
|
|
2472
|
+
case "usage": {
|
|
2473
|
+
const choice = positional[0];
|
|
2474
|
+
if (choice !== void 0 && choice !== "on" && choice !== "off") fail("Run: twombly usage on, or twombly usage off");
|
|
2475
|
+
if (choice) await setUsage(choice === "on");
|
|
2476
|
+
print({ ok: true, usage: usageOn() ? "on" : "off" });
|
|
2477
|
+
return;
|
|
2478
|
+
}
|
|
2373
2479
|
case "stop": {
|
|
2374
2480
|
if (await health()) await fetch(`${DAEMON_ORIGIN}/cli/stop`, { method: "POST", body: "{}" }).catch(() => {
|
|
2375
2481
|
});
|