diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ef2e11e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + cache: npm + - run: npm ci + - run: npm run typecheck + # claude plugin test needs no sign-in or network; the version is pinned in package.json. + - run: npm test diff --git a/README.md b/README.md index 00598cd..7368b5b 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,16 @@ Needs Claude Code 2.1.287 or later (mods are on by default). - The cache countdown assumes the 1-hour prompt-cache TTL. On the 5-minute TTL it will still count down from 60. - Limits come from the usage Claude Code reports after each turn, refreshed once a minute. +## Develop + +``` +npm ci +npm run typecheck +npm test +``` + +`npm run typecheck` runs `tsc` against the mods API types. When you load the mod with `claude --plugin-dir plugins/usage-deck`, Claude Code writes types for your version into `plugins/usage-deck/.claude-plugin/types/`, and the typecheck uses those. In a fresh clone or CI, `scripts/mod-types.mjs` fetches Anthropic's published copy at a pinned commit instead. `npm test` runs `claude plugin test` with the Claude Code version pinned in `package.json`. + ## Credits - **Clawd** is Claude Code's mascot, created by **[Anthropic](https://www.anthropic.com)**. The sprite and the poses here are hand-drawn for the terminal from Anthropic's own Clawd: the pixel mark and animations on [claude.dev](https://claude.dev) and the working-at-a-laptop animation in the Claude Code app. All credit for the character goes to them. diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..75d64e6 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,537 @@ +{ + "name": "usage-deck", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "usage-deck", + "devDependencies": { + "@anthropic-ai/claude-code": "2.1.322", + "typescript": "7.0.2" + } + }, + "node_modules/@anthropic-ai/claude-code": { + "version": "2.1.322", + "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-2.1.322.tgz", + "integrity": "sha512-oP7oW4vM5DREWfL1jn4JSGlmLcrJ5QmppgADrVNJBUPiC1mQ5YvRrke0on+YZ/3QhKIaCJtdr6jPvehcAQIHLQ==", + "dev": true, + "hasInstallScript": true, + "license": "SEE LICENSE IN README.md", + "bin": { + "claude": "bin/claude.exe" + }, + "engines": { + "node": ">=22.0.0" + }, + "optionalDependencies": { + "@anthropic-ai/claude-code-darwin-arm64": "2.1.322", + "@anthropic-ai/claude-code-darwin-x64": "2.1.322", + "@anthropic-ai/claude-code-linux-arm64": "2.1.322", + "@anthropic-ai/claude-code-linux-arm64-musl": "2.1.322", + "@anthropic-ai/claude-code-linux-x64": "2.1.322", + "@anthropic-ai/claude-code-linux-x64-musl": "2.1.322", + "@anthropic-ai/claude-code-win32-arm64": "2.1.322", + "@anthropic-ai/claude-code-win32-x64": "2.1.322" + } + }, + "node_modules/@anthropic-ai/claude-code-darwin-arm64": { + "version": "2.1.322", + "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-darwin-arm64/-/claude-code-darwin-arm64-2.1.322.tgz", + "integrity": "sha512-OAx5Y7V7tGCi0tWuDV3lwcDWmIua512NgpClLbqvwC9m+mbLiaytgVLXf4unTXBjMf+QbQiIUO1Kus90PklDhA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "SEE LICENSE IN LICENSE.md", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@anthropic-ai/claude-code-darwin-x64": { + "version": "2.1.322", + "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-darwin-x64/-/claude-code-darwin-x64-2.1.322.tgz", + "integrity": "sha512-nGpWAtSEI1OMMVzlMGS4MuXZ6Op0kzXPnTzhbipgEA7Ym3LFHuCWE//9jB20xcy55zx9lagSe4tb9kRfvZ9Xdw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "SEE LICENSE IN LICENSE.md", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@anthropic-ai/claude-code-linux-arm64": { + "version": "2.1.322", + "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-linux-arm64/-/claude-code-linux-arm64-2.1.322.tgz", + "integrity": "sha512-YYNp1op87WWcBEE6jC1neOjMDPdn4Iy+kUHyFcI1GsLl4IwH7EjZlwVKcpsZqVbE0IXEFaOldmyOHC1y3j18Ag==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "SEE LICENSE IN LICENSE.md", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@anthropic-ai/claude-code-linux-arm64-musl": { + "version": "2.1.322", + "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-linux-arm64-musl/-/claude-code-linux-arm64-musl-2.1.322.tgz", + "integrity": "sha512-lcJl5oH4RtUVp7uRSpj/jrXubXDrK1v62lt50lyAaILH5wJM/psaTTlF8E+aFGFd0MT7nGinypjYapgB88Zhvg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "SEE LICENSE IN LICENSE.md", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@anthropic-ai/claude-code-linux-x64": { + "version": "2.1.322", + "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-linux-x64/-/claude-code-linux-x64-2.1.322.tgz", + "integrity": "sha512-0DoaNAXLWCYYIGachWBCkTUsS8dOOgvk4R2fFKdrLejO9XlRTwaWUMD9ONdDmv0csdpwxj4qLUN6zWMaG2Sz6g==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "SEE LICENSE IN LICENSE.md", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@anthropic-ai/claude-code-linux-x64-musl": { + "version": "2.1.322", + "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-linux-x64-musl/-/claude-code-linux-x64-musl-2.1.322.tgz", + "integrity": "sha512-Tmb7C0xAFVLe4pWBmIxlAfulysXfdqgAd1GGp0DWrGxY9YZ5uiIaq25GeddBxB9IfNfWrZBcWU2g9Skb4piazQ==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "SEE LICENSE IN LICENSE.md", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@anthropic-ai/claude-code-win32-arm64": { + "version": "2.1.322", + "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-win32-arm64/-/claude-code-win32-arm64-2.1.322.tgz", + "integrity": "sha512-UTmhBanbWh5/i3a3o2CWfewluw5xWvvSr8TpfZs/XHBKQsWybMorUwDJIJDErkyy+cQ55UklH7foJIqGBMjjGQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "SEE LICENSE IN LICENSE.md", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@anthropic-ai/claude-code-win32-x64": { + "version": "2.1.322", + "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-win32-x64/-/claude-code-win32-x64-2.1.322.tgz", + "integrity": "sha512-MCf137rbW8N6PjmF04HHmKfc+yKHu8w3Uq0yqkIj5snr3KHAL4et+H5bMe05DgFmjdnRoXIVcaXg4QXgHNUw4A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "SEE LICENSE IN LICENSE.md", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@typescript/typescript-aix-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-aix-ppc64/-/typescript-aix-ppc64-7.0.2.tgz", + "integrity": "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-arm64/-/typescript-darwin-arm64-7.0.2.tgz", + "integrity": "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-x64/-/typescript-darwin-x64-7.0.2.tgz", + "integrity": "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-arm64/-/typescript-freebsd-arm64-7.0.2.tgz", + "integrity": "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-x64/-/typescript-freebsd-x64-7.0.2.tgz", + "integrity": "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm/-/typescript-linux-arm-7.0.2.tgz", + "integrity": "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm64/-/typescript-linux-arm64-7.0.2.tgz", + "integrity": "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-loong64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-loong64/-/typescript-linux-loong64-7.0.2.tgz", + "integrity": "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-mips64el": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-mips64el/-/typescript-linux-mips64el-7.0.2.tgz", + "integrity": "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-ppc64/-/typescript-linux-ppc64-7.0.2.tgz", + "integrity": "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-riscv64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-riscv64/-/typescript-linux-riscv64-7.0.2.tgz", + "integrity": "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-s390x": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-s390x/-/typescript-linux-s390x-7.0.2.tgz", + "integrity": "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-x64/-/typescript-linux-x64-7.0.2.tgz", + "integrity": "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-arm64/-/typescript-netbsd-arm64-7.0.2.tgz", + "integrity": "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-x64/-/typescript-netbsd-x64-7.0.2.tgz", + "integrity": "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-arm64/-/typescript-openbsd-arm64-7.0.2.tgz", + "integrity": "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-x64/-/typescript-openbsd-x64-7.0.2.tgz", + "integrity": "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-sunos-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-sunos-x64/-/typescript-sunos-x64-7.0.2.tgz", + "integrity": "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-arm64/-/typescript-win32-arm64-7.0.2.tgz", + "integrity": "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-x64/-/typescript-win32-x64-7.0.2.tgz", + "integrity": "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/typescript": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz", + "integrity": "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc" + }, + "engines": { + "node": ">=16.20.0" + }, + "optionalDependencies": { + "@typescript/typescript-aix-ppc64": "7.0.2", + "@typescript/typescript-darwin-arm64": "7.0.2", + "@typescript/typescript-darwin-x64": "7.0.2", + "@typescript/typescript-freebsd-arm64": "7.0.2", + "@typescript/typescript-freebsd-x64": "7.0.2", + "@typescript/typescript-linux-arm": "7.0.2", + "@typescript/typescript-linux-arm64": "7.0.2", + "@typescript/typescript-linux-loong64": "7.0.2", + "@typescript/typescript-linux-mips64el": "7.0.2", + "@typescript/typescript-linux-ppc64": "7.0.2", + "@typescript/typescript-linux-riscv64": "7.0.2", + "@typescript/typescript-linux-s390x": "7.0.2", + "@typescript/typescript-linux-x64": "7.0.2", + "@typescript/typescript-netbsd-arm64": "7.0.2", + "@typescript/typescript-netbsd-x64": "7.0.2", + "@typescript/typescript-openbsd-arm64": "7.0.2", + "@typescript/typescript-openbsd-x64": "7.0.2", + "@typescript/typescript-sunos-x64": "7.0.2", + "@typescript/typescript-win32-arm64": "7.0.2", + "@typescript/typescript-win32-x64": "7.0.2" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..afcfc31 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "usage-deck", + "private": true, + "type": "module", + "scripts": { + "typecheck": "node scripts/mod-types.mjs && tsc -p plugins/usage-deck", + "test": "claude plugin test plugins/usage-deck" + }, + "devDependencies": { + "@anthropic-ai/claude-code": "2.1.322", + "typescript": "7.0.2" + }, + "allowScripts": { + "@anthropic-ai/claude-code@2.1.322": true + } +} diff --git a/plugins/usage-deck/hooks/register.test.ts b/plugins/usage-deck/hooks/register.test.ts index b429b88..d58aa95 100644 --- a/plugins/usage-deck/hooks/register.test.ts +++ b/plugins/usage-deck/hooks/register.test.ts @@ -1,3 +1,4 @@ +import type { CommandRunInput, On } from 'claude-code' import { test, expect, mock } from 'claude-code/testing' import { bar, colorOf, metersOf, untilReset } from './register' @@ -16,7 +17,10 @@ test('meter is 16 dithered cells', () => { const BODY = ['#d97757', '#be684d'] function eyeMarks(row: [string, string | null, string | null, boolean?][]): number { const cells = row.flatMap(([s, fg, bg, inv]) => [...s].map(ch => ({ ch, fg, bg, inv: !!inv }))) - const body = (i: number) => i >= 0 && i < cells.length && cells[i].ch !== ' ' && BODY.includes(cells[i].fg ?? '') + const body = (i: number) => { + const c = cells[i] + return c !== undefined && c.ch !== ' ' && BODY.includes(c.fg ?? '') + } let n = 0 cells.forEach((c, i) => { if (c.inv && (c.ch === '▂' || c.ch === '^')) n += 1 @@ -32,7 +36,9 @@ test('every clawd frame is 4 rows of 16 cells and keeps a face', () => { clip.frames.forEach((f, i) => { expect(f.length).toBe(4) for (const row of f) expect(row.reduce((a, [s]) => a + [...s].length, 0)).toBe(16) - if (eyeMarks(f[clip.face[i]] as never) < 2) throw new Error(`${name}[${i}] has no face`) + const face = clip.face[i] + const row = face === undefined ? undefined : f[face] + if (!row || eyeMarks(row) < 2) throw new Error(`${name}[${i}] has no face`) }) } }) @@ -42,12 +48,18 @@ test('countdown and meters', () => { expect(untilReset('2026-10-04T03:03:00Z', now)).toBe('3h3m') const ms = metersOf({ startedAt: 0, rateLimits: [{ kind: 'five_hour', percentUsed: 3 }, { kind: 'seven_day', percentUsed: 91 }], context: { tokens: 407_000, window: 1_000_000, percent: 40.7 } } as never, now) expect(ms.map(m => m.label)).toEqual(['5H', '7D', 'CTX']) - expect(ms[2].note).toBe('407k / 1M') + expect(ms[2]?.note).toBe('407k / 1M') }) import { clipFor, clipMs, frameIndex, isEmpty } from './register' import { CLIPS } from './frames' +function clipNamed(name: string) { + const clip = CLIPS[name] + if (!clip) throw new Error(`no clip named ${name}`) + return clip +} + test('clawd plays the right clip for the state', () => { const base = { working: false, nowMs: 100_000, lastToolMs: 99_000, lastActiveMs: 90_000, happyUntilMs: 0, turnStartMs: 90_000 } expect(clipFor({ ...base, working: true })).toBe('typing') @@ -67,8 +79,9 @@ test('clawd plays the right clip for the state', () => { expect(clipFor({ ...base, working: true, turnStartMs: 50_000, lastActiveMs: 60_000 })).toBe('walk') expect(clipFor({ ...base, nowMs: 8_000, lastActiveMs: 7_000, turnStartMs: 7_000 })).toBe('wave') for (const name of ['typing', 'typing-start', 'typing-end', 'think', 'happy', 'doze', 'look', 'yawn', 'wave', 'walk']) { - expect(CLIPS[name].frames.length).toBeGreaterThan(3) - expect(frameIndex(name, 123_456)).toBeLessThan(CLIPS[name].frames.length) + const clip = clipNamed(name) + expect(clip.frames.length).toBeGreaterThan(3) + expect(frameIndex(name, 123_456)).toBeLessThan(clip.frames.length) } }) @@ -89,7 +102,7 @@ test('cache warmth counts down the 1h TTL', () => { }) test('one-shot clips play once from their start and hold the last frame', () => { - const n = CLIPS['typing-start'].frames.length + const n = clipNamed('typing-start').frames.length expect(frameIndex('typing-start', 5_000, 5_000)).toBe(0) expect(frameIndex('typing-start', 5_100, 5_000)).toBe(1) expect(frameIndex('typing-start', 60_000, 5_000)).toBe(n - 1) @@ -109,14 +122,14 @@ const BAND = { component: 'AbovePrompt', requestId: 'above-prompt', viewport: { columns: 120, rows: 40 }, - props: { hasSurvey: false, isWorking: false, maxRows: 20, bodyColumns: 120, scroll: { offset: 0, bodyRows: 20 }, view: {} }, + props: { hasSurvey: false, isCollapsed: false, isWorking: false, maxRows: 20, bodyColumns: 120, scroll: { offset: 0, bodyRows: 20 }, view: {} }, } as const const USAGE = { startedAt: 0, rateLimits: [{ kind: 'five_hour', percentUsed: 3 }, { kind: 'seven_day', percentUsed: 41 }] } // A tall tree from another plugin (image-view's tiles), standing as the rest of the AbovePrompt chain. const TILES = { type: 'Box', props: { flexDirection: 'column' }, children: Array.from({ length: 9 }, (_, i) => ({ type: 'Text', props: {}, children: [`tile row ${i}`] })) } -function band(on: Parameters[1] & ((...a: never[]) => unknown)>[1], below: unknown) { - mock.clock(on as never) +function band(on: On, below: unknown) { + mock.clock(on) on('session.start', () => ({ cwd: '/work' })) on('session.usage', () => ({ value: USAGE }) as never) on('command.register', () => ({ value: undefined }) as never) @@ -146,5 +159,17 @@ test('beside another plugin\'s tree the deck shrinks to one row, or steps aside test('a window missing from usage still shows as a fresh row', () => { const ms = metersOf({ startedAt: 0, rateLimits: [{ kind: 'seven_day', percentUsed: 93 }], context: { tokens: 1000, window: 1_000_000, percent: 0.1 } } as never, 0) expect(ms.map(m => m.label)).toEqual(['5H', '7D', 'CTX']) - expect(ms[0].note).toBe('new window') + expect(ms[0]?.note).toBe('new window') +}) + +// A command the person types at the prompt. +const typed = (command: string): CommandRunInput => ({ command, args: '', origin: { kind: 'composer' }, presentation: { isFullscreen: false, columns: 120 } }) + +test('/deck hides and shows the deck, and leaves other commands to the rest of the chain', async ($, on) => { + band(on, { type: 'Box', props: {}, children: [] }) + on('command.run', () => ({ text: 'from below' })) + await $.session.start({ surface: 'terminal', isInteractive: true, cwd: '/work' }) + expect((await $.command.run(typed('deck'))).text).toBe('usage-deck: hidden (/deck shows it again)') + expect((await $.command.run(typed('deck'))).text).toBe('usage-deck: shown') + expect((await $.command.run(typed('help'))).text).toBe('from below') }) diff --git a/plugins/usage-deck/hooks/register.tsx b/plugins/usage-deck/hooks/register.tsx index e5f40a6..22624b4 100644 --- a/plugins/usage-deck/hooks/register.tsx +++ b/plugins/usage-deck/hooks/register.tsx @@ -86,7 +86,7 @@ export function clipFor(s: { working: boolean; nowMs: number; lastToolMs: number return s.nowMs - s.lastToolMs > 8_000 ? 'think' : 'typing' } if (s.nowMs - s.lastActiveMs > 10 * 60_000) return 'doze' - return ['look', 'look', 'wave', 'look', 'yawn'][Math.floor(s.nowMs / 4_000) % 5] + return ['look', 'look', 'wave', 'look', 'yawn'][Math.floor(s.nowMs / 4_000) % 5] ?? 'look' } // One clip row as Text: fg/bg per segment; a 4th `true` draws it inverse, so the glyph is a hole in the @@ -190,7 +190,7 @@ export const register: Register = on => { return r }) - on('command.run', { name: 'deck' }, async $ => { + on('command.run', { command: 'deck' }, async $ => { const hidden = await read($, isHidden) await update($, isHidden, () => !hidden) return { text: hidden ? 'usage-deck: shown' : 'usage-deck: hidden (/deck shows it again)' } @@ -221,6 +221,9 @@ export const register: Register = on => { const clip = CLIPS[clipName] const once = clipName === 'typing-start' ? turnStartMs : clipName === 'typing-end' ? endStartMs : undefined const fi = frameIndex(clipName, nowMs, once) + const frameRows = clip?.frames[fi] + const faceRow = frameRows?.[clip?.face[fi] ?? -1] + if (!frameRows || !faceRow) return below // clipFor and frameIndex name only frames that frames.ts has // Compact: one row while the engine's spinner squeezes the band: the clip's eye row, so Clawd keeps a face. if (e.props.maxRows < 4 || crowded) { @@ -228,7 +231,7 @@ export const register: Register = on => { return ( - {segsOf(Text, clip.frames[fi][clip.face[fi]])} + {segsOf(Text, faceRow)} {order.map(m => { const b = bar(m.percent, w) return ( @@ -247,7 +250,7 @@ export const register: Register = on => { } // Full: Clawd on the left (a space, 16 cells, a gap so props never touch the meters), three columns. - const rows = clip.frames[fi].slice(-Math.max(3, e.props.maxRows)) + const rows = frameRows.slice(-Math.max(3, e.props.maxRows)) const colW = Math.min(44, Math.floor((cols - 18) / order.length)) const barW = Math.max(8, Math.min(28, colW - 9)) return ( diff --git a/scripts/mod-types.mjs b/scripts/mod-types.mjs new file mode 100644 index 0000000..bfd1c1f --- /dev/null +++ b/scripts/mod-types.mjs @@ -0,0 +1,60 @@ +// Lays out the mods API types that plugins/usage-deck/tsconfig.json extends, so tsc runs in a clean clone. +// +// Claude Code writes plugins/usage-deck/.claude-plugin/types/ (gitignored) for the version you run, but only +// when it loads the mod with --plugin-dir in an interactive, signed-in session. A fresh clone and CI have no +// such session, so this script fetches the copy Anthropic publishes (anthropics/claude-code, +// mods/types/claude-code.d.ts) at a pinned commit, checks its sha256, and writes it where Claude Code would, +// with a tsconfig.json beside it. A folder Claude Code wrote is left alone, so a local typecheck uses the +// types of the version you run. +// +// To move the pin: set COMMIT to a newer anthropics/claude-code commit and SHA256 to the file's hash there. +import { createHash } from 'node:crypto' +import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' + +const COMMIT = 'e2c963a886e345ca22d5e882ff8a63e3192529d0' +const SHA256 = '5dba5fe27a0f2161df65bbc46fcfa62138b5db4db928ec3965179345e78b771b' +const SOURCE = `https://raw.githubusercontent.com/anthropics/claude-code/${COMMIT}/mods/types/claude-code.d.ts` +const TAG = '// usage-deck pinned types:' +const MARK = `${TAG} anthropics/claude-code@${COMMIT} mods/types/claude-code.d.ts` + +// The compiler options of anthropics/claude-code's own mods/tsconfig.json at COMMIT. Paths are relative to +// this generated file: the declarations beside it, and the plugin's hooks/ and types/. +const TSCONFIG = { + compilerOptions: { + target: 'es2023', + lib: ['es2023'], + types: [], + module: 'esnext', + moduleResolution: 'bundler', + strict: true, + noUncheckedIndexedAccess: true, + noEmit: true, + skipLibCheck: true, + jsx: 'react', + jsxFactory: 'h', + jsxFragmentFactory: 'Fragment', + }, + include: ['./**/*.d.ts', '../../hooks', '../../types'], +} + +const dir = join(dirname(fileURLToPath(import.meta.url)), '../plugins/usage-deck/.claude-plugin/types') +const dts = join(dir, 'claude-code/index.d.ts') +const first = existsSync(dts) ? readFileSync(dts, 'utf8').split('\n', 1)[0] : null + +if (first !== null && !first.startsWith(TAG)) { + console.log(`mod-types: keeping the types Claude Code wrote (${first})`) +} else { + if (first !== MARK) { + const res = await fetch(SOURCE) + if (!res.ok) throw new Error(`mod-types: ${SOURCE}: HTTP ${res.status}`) + const body = Buffer.from(await res.arrayBuffer()) + const got = createHash('sha256').update(body).digest('hex') + if (got !== SHA256) throw new Error(`mod-types: ${SOURCE}: sha256 ${got}, expected ${SHA256}`) + mkdirSync(dirname(dts), { recursive: true }) + writeFileSync(dts, `${MARK}\n${body}`) + } + writeFileSync(join(dir, 'tsconfig.json'), `${JSON.stringify(TSCONFIG, null, 2)}\n`) + console.log(`mod-types: ${MARK.slice(TAG.length + 1)}`) +}