toolcrib 0.1.0 → 0.1.1

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 (2) hide show
  1. package/README.md +187 -146
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -6,198 +6,239 @@ changed, and stages every addition/modification as a reviewable patch — it
6
6
  never writes to a pre-existing file directly. You (or your AI assistant)
7
7
  apply what you want with `toolcrib apply`.
8
8
 
9
+ This file covers the CLI itself, start to finish. It doesn't cover how to
10
+ use any individual component; for that, point your AI assistant at the
11
+ toolkit's `ai-docs/` folder, which `toolcrib init` vendors into your project
12
+ (see [What this guide doesn't cover](#what-this-guide-doesnt-cover)).
13
+
9
14
  ## Install
10
15
 
16
+ No install needed — run it directly:
17
+
18
+ ```bash
19
+ npx toolcrib <command>
20
+ ```
21
+
22
+ Or install it globally if you'll use it often:
23
+
11
24
  ```bash
12
25
  npm install -g toolcrib
26
+ toolcrib <command>
13
27
  ```
14
28
 
15
- Or run without installing, via `npx toolcrib <command>`.
29
+ Run every command from your project's root — the same directory as your
30
+ `package.json`.
16
31
 
17
- ## Commands
32
+ ## The lifecycle, at a glance
18
33
 
19
- | Command | What it does |
20
- |---|---|
21
- | `toolcrib init [--version <x.y.z>]` | Stage installation of the toolkit into the current project. Defaults to the latest release. |
22
- | `toolcrib merge [--version <x.y.z>]` | Stage an update from the currently installed version to another. |
23
- | `toolcrib apply` | Apply every staged patch in `./toolcrib-patches/`, then delete the folder regardless of outcome. |
24
- | `toolcrib doctor` | Read-only check for local drift and available updates. |
25
- | `toolcrib versions` | List available toolkit releases. |
34
+ ```
35
+ toolcrib init → review ./toolcrib-patches/ → toolcrib apply
36
+ │
37
+ (later, to check in on things) │
38
+ ▼
39
+ toolcrib doctor
40
+ │
41
+ (when a new version exists)
42
+ ▼
43
+ toolcrib merge → review ./toolcrib-patches/ → toolcrib apply
44
+ ```
26
45
 
27
- Nothing is ever written to an existing file outside of `toolcrib apply` —
28
- `init`/`merge` only ever produce patches for you to review first.
46
+ Two ideas make everything else make sense:
29
47
 
30
- ## Local development / running without publishing
48
+ 1. **Nothing is ever written to an existing file except by `toolcrib
49
+ apply`.** `init` and `merge` only ever compute a diff and save it as a
50
+ `.patch` file in `./toolcrib-patches/` — a folder you can open, read,
51
+ and delete without anything in your project changing. `apply` is the
52
+ only command that actually touches your files, and only for patches
53
+ sitting in that folder.
54
+ 2. **Every command is safe to run "just to see."** `init`/`merge` never
55
+ modify anything by themselves, and `doctor`/`versions` are read-only.
56
+ If you're ever unsure what a command will do, running it costs nothing
57
+ — the worst case is a `./toolcrib-patches/` folder you don't apply.
58
+
59
+ ## Commands
31
60
 
32
- Three ways to run this CLI against your own changes, in increasing order
33
- of fidelity to what a real published install behaves like.
61
+ ### `toolcrib init`
34
62
 
35
- ### 1. Run the file directly — fastest iteration
63
+ Stages the toolkit into your project for the first time.
36
64
 
37
65
  ```bash
38
- node src/index.js init
39
- node src/index.js apply
66
+ toolcrib init
67
+ toolcrib init --version 1.2.0 # a specific release instead of latest
68
+ toolcrib init --situation new # greenfield project, no existing UI
69
+ toolcrib init --situation refactor # adopting toolcrib into an existing app
40
70
  ```
41
71
 
42
- Good for quick iteration on logic. Skips the `bin`/shebang/executable-
43
- permission resolution path entirely, so it won't catch packaging issues.
72
+ What it does: downloads the requested release (`latest` by default),
73
+ computes what's new or different compared to what's already in `./toolcrib`
74
+ (nothing, the first time you run it), and writes every addition as a
75
+ numbered `.patch` file under `./toolcrib-patches/`. It also proposes
76
+ patches for `package.json` (adding the toolkit's dependencies and the
77
+ `#toolcrib` import alias), `.gitignore`, and an `AGENTS.md`/`CLAUDE.md`
78
+ block your AI assistant should read.
44
79
 
45
- ### 2. `npm link` — live global command, best for active development
80
+ `--situation` controls whether a **New Project** or **Refactor** guide gets
81
+ added to that instruction-file block, on top of the core rules that are
82
+ always included. Skip it and you'll get the core rules only, with a note
83
+ telling you to re-run with `--situation` (or add the missing block by hand)
84
+ when you're ready.
46
85
 
47
- ```bash
48
- cd cli
49
- npm link # once
50
- toolcrib init # now works from anywhere on your machine
51
- ```
86
+ One thing worth knowing up front: **`init` doesn't take a target folder
87
+ argument.** It always vendors into `./toolcrib` relative to wherever you
88
+ run it — there's no way to point it at, say, `./src/ui` instead. Run it
89
+ from your project root.
52
90
 
53
- This creates a real global symlink back to this folder — edits to `src/`
54
- take effect immediately, no relinking needed. Exercises the actual `bin`
55
- entry and shebang, unlike option 1.
91
+ Nothing is written to your project yet — see [Reviewing and applying
92
+ patches](#reviewing-and-applying-patches) below.
56
93
 
57
- ```bash
58
- npm unlink -g toolcrib # when done
59
- ```
94
+ ### `toolcrib apply`
60
95
 
61
- ### 3. `npm pack` + real global install — closest simulation of a real publish
96
+ Applies everything staged in `./toolcrib-patches/`.
62
97
 
63
98
  ```bash
64
- cd cli
65
- npm pack # produces toolcrib-<version>.tgz
66
- npm install -g ./toolcrib-<version>.tgz # a real install: real deps, real files[] whitelist applied
67
- toolcrib init # exactly what an end user would type
99
+ toolcrib apply
68
100
  ```
69
101
 
70
- This is the only option of the three that actually respects the `files`
71
- field in `package.json` (see below) — it's the real tarball a publish
72
- would produce, not a symlink to your live source tree. Worth running once
73
- before an actual `npm publish` as a final sanity check.
102
+ This is the command that actually creates/modifies files. It applies each
103
+ patch in order, reports how many succeeded, and **deletes the
104
+ `./toolcrib-patches/` folder afterward regardless of outcome** — a failed
105
+ patch isn't kept around to retry; if something fails, re-run `init` or
106
+ `merge` afterward to regenerate fresh patches against your project's
107
+ current state, which is more likely to apply cleanly than retrying a stale
108
+ one.
74
109
 
75
- ```bash
76
- npm uninstall -g toolcrib # when done
77
- ```
110
+ If your project isn't already a git repository, `apply` will offer to run
111
+ `git init` for you first (it uses `git apply` when possible, since that
112
+ gives you normal git tooling — `git diff`, `git checkout -- .` — to inspect
113
+ or undo what just landed). Say no and it falls back to a built-in patcher
114
+ that doesn't need git at all.
78
115
 
79
- ## Testing
116
+ ### `toolcrib doctor`
80
117
 
81
- ### Unit tests
118
+ Read-only. Never modifies anything.
82
119
 
83
120
  ```bash
84
- npm install
85
- npm test
121
+ toolcrib doctor
86
122
  ```
87
123
 
88
- Covers the pure-logic modules without any network access:
89
- - `test/patches.test.js` — `PendingChanges` (patch generation, idempotency,
90
- line-ending normalization, new-file vs. modification detection)
91
- - `test/deps.test.js` — semver-based dependency classification (add /
92
- compatible / conflict), including the `workspace:*`-style unrecognized-
93
- specifier case
94
- - `test/project.test.js` — `.gitignore` proposal idempotency, lock file
95
- read/write, and a regression test for a real bug (see below)
96
- - `test/github.test.js` — checksum verification (match / mismatch /
97
- missing-checksum-asset), version resolution, release listing — all with
98
- `fetch` mocked, no real network calls
99
-
100
- A `vitest.config.js` is present in this folder specifically so vitest
101
- doesn't walk up to the repo root's `vite.config.ts` (the toolkit's own dev
102
- app config, which needs `vite` — not installed here, since this is a
103
- separate Node CLI project).
104
-
105
- ### End-to-end integration test (real network-shaped, no GitHub release required)
106
-
107
- This exercises the full `init` → `apply` pipeline for real — real zip
108
- download, real sha256 verification, real extraction, real `git apply` —
109
- against a genuine `npm init`'d project, without needing a published
110
- GitHub release. It works by running a tiny local server
111
- (`integration-test/mock-github-server.js`) that serves a real release zip
112
- built from this repo's own toolkit source, shaped exactly like GitHub's
113
- API and release-asset URLs.
114
-
115
- **1. Build a real release from the toolkit source (repo root, not cli/)**
124
+ Run this any time you want to sanity-check your install without changing
125
+ anything. It reports:
126
+
127
+ - **Local drift** — files under `./toolcrib` that no longer match what the
128
+ installed version actually shipped (usually from hand-editing a vendored
129
+ file directly, which is supported — that's the whole point of vendoring
130
+ — but worth knowing about).
131
+ - **Stale instruction-file blocks** — if the `<!-- toolcrib:managed:... -->`
132
+ block in your `AGENTS.md`/`CLAUDE.md` was hand-edited instead of
133
+ regenerated, or is out of date with your installed version.
134
+ - **Whether a newer release is available.**
135
+ - **A `tsconfig.json` compatibility check** — if `moduleResolution` isn't
136
+ set to `"bundler"`, `"node16"`, or `"nodenext"`, `import { ... } from
137
+ '#toolcrib'` will run fine but your editor/`tsc` may falsely report
138
+ "Cannot find module." `doctor` tells you the exact setting to fix it.
139
+ - **Bundler-specific notes**, when relevant — for example, on a Next.js
140
+ project it'll remind you that any file rendering toolcrib components
141
+ needs a `'use client'` directive, since Next's App Router treats
142
+ components as server-only by default.
143
+
144
+ ### `toolcrib merge`
145
+
146
+ Stages an upgrade from your currently installed version to another.
116
147
 
117
148
  ```bash
118
- cd .. # repo root, alongside src/, ai-docs/, scripts/
119
- node scripts/build-release.js
120
- node scripts/package-release.js
149
+ toolcrib merge # upgrade to latest
150
+ toolcrib merge --version 2.1.0 # upgrade to a specific version
121
151
  ```
122
152
 
123
- This produces `toolcrib.zip` and `toolcrib.zip.sha256` in the repo root.
124
-
125
- **2. Serve it locally**
153
+ Works like `init`, but smarter: for every vendored file, it compares three
154
+ things — what you originally got, what's actually on disk now, and what
155
+ the new version ships — and sorts each file into one of three outcomes:
126
156
 
127
- ```bash
128
- cd cli
129
- mkdir -p integration-test/releases
130
- cp ../toolcrib.zip ../toolcrib.zip.sha256 integration-test/releases/
131
- node integration-test/mock-github-server.js
132
- ```
157
+ - **Safe update** — you never touched the file; the new version's copy is
158
+ staged as a patch.
159
+ - **Kept as-is** — you edited the file yourself and upstream didn't change
160
+ it; left alone, no patch generated.
161
+ - **Conflict** — you edited it *and* upstream changed it too. `merge` won't
162
+ guess which version wins. Instead it writes a `.upstream-diff` note
163
+ explaining what upstream changed, so you (or your AI assistant) can
164
+ reconcile it by hand.
133
165
 
134
- Leave this running in its own terminal — it listens on `localhost:9999`.
166
+ As with `init`, nothing is written until you run `apply` afterward.
135
167
 
136
- **3. Run the real CLI against a real dummy project**
168
+ ### `toolcrib versions`
137
169
 
138
- In another terminal — either via `node src/index.js` directly, or via
139
- `npm link` (see above) for the real `toolcrib` command:
170
+ Lists every published release.
140
171
 
141
172
  ```bash
142
- mkdir /tmp/dummy-project && cd /tmp/dummy-project
143
- npm init -y
173
+ toolcrib versions
174
+ ```
144
175
 
145
- TOOLCRIB_API_BASE=http://localhost:9999/api \
146
- TOOLCRIB_RELEASES_BASE=http://localhost:9999/releases \
147
- toolcrib init
176
+ Useful for picking an exact `--version` for `init` or `merge` instead of
177
+ always taking `latest`.
148
178
 
149
- TOOLCRIB_API_BASE=http://localhost:9999/api \
150
- TOOLCRIB_RELEASES_BASE=http://localhost:9999/releases \
151
- toolcrib apply
152
- ```
179
+ ## Reviewing and applying patches
180
+
181
+ After `init` or `merge`, you'll have a `./toolcrib-patches/` folder full of
182
+ numbered `.patch` files — plain unified diffs. Before running `apply`:
183
+
184
+ - Open a few and skim them. They're ordinary text; any editor or `git
185
+ diff`-style tool can show them.
186
+ - If you're not going to apply them, just delete the folder — nothing else
187
+ has changed yet.
188
+ - If everything looks right, run `toolcrib apply`.
153
189
 
154
- Then inspect `/tmp/dummy-project` — `toolcrib/` should contain every
155
- vendored file, `package.json` should have the real peer dependencies
156
- added, `.gitignore` should have `/toolcrib-patches/`, and
157
- `toolcrib/.toolcrib-lock.json` should record the installed version.
158
-
159
- `TOOLCRIB_API_BASE` / `TOOLCRIB_RELEASES_BASE` are the only two overrides
160
- this CLI recognizes — unset, everything targets real GitHub. They exist
161
- specifically to make this kind of test possible without a published
162
- release or real network access.
163
-
164
- ### Bugs this integration test has already found
165
-
166
- Worth keeping this test around — it already found three real issues that
167
- unit tests, by construction, couldn't have caught:
168
-
169
- 1. **Hang on error** — a failed fetch left `@clack/prompts`' spinner
170
- interval alive, so the process never exited even after printing the
171
- error. Fixed by calling `process.exit(1)` explicitly in the CLI's
172
- top-level error handler rather than only setting `process.exitCode`.
173
- 2. **Crash in non-interactive environments** — `p.confirm()` throws a raw
174
- libuv TTY error (not a catchable message) when stdin/stdout aren't a
175
- real terminal (CI, scripts, sandboxes). Fixed by detecting
176
- `process.stdin.isTTY` and defaulting to "yes" for the (safe,
177
- recoverable) `git init` prompt when non-interactive.
178
- 3. **`git apply` rejected the lockfile patch** — its path was built with a
179
- leading `./`, which `git apply` treats as invalid even though every
180
- other file's path (built without the leading `./`) applied fine. Fixed
181
- by dropping the leading `./`; a regression test now locks this in.
182
-
183
- ## Publishing
190
+ ## Upgrading — a full example
184
191
 
185
192
  ```bash
186
- cd cli
187
- npm pack --dry-run # confirm exactly what would ship — should be
188
- # package.json + src/ only, ~15 files
189
- npm publish
193
+ toolcrib versions # see what's available
194
+ toolcrib merge --version 1.4.0 # stage the upgrade
195
+ # review ./toolcrib-patches/
196
+ toolcrib apply # actually upgrade
197
+ toolcrib doctor # confirm nothing's left drifted
190
198
  ```
191
199
 
192
- ### What the `files` field is for
193
-
194
- `package.json`'s `files` array is an explicit whitelist of what
195
- `npm publish`/`npm pack` include in the published package — everything
196
- else in this folder (tests, the integration-test mock server, this
197
- README, `package-lock.json`) is left out even though it's sitting right
198
- here in the repo. Without it, npm defaults to "include everything not
199
- gitignored," which would have shipped `test/`, `vitest.config.js`, and
200
- `package-lock.json` to every installer for no reason. `["src"]` was
201
- chosen by actually running `npm pack --dry-run` and confirming it's the
202
- complete, correct set — `package.json` and the `bin` entry are always
203
- included automatically regardless of what's listed.
200
+ ## Troubleshooting
201
+
202
+ **`toolcrib apply` says "No pending patches."**
203
+ There's nothing staged — run `init` (first install) or `merge` (upgrade)
204
+ first.
205
+
206
+ **`doctor` warns about `moduleResolution`.**
207
+ Set `"moduleResolution": "bundler"` (or `"node16"`/`"nodenext"`) in your
208
+ `tsconfig.json`'s `compilerOptions`. Your code still runs fine either way —
209
+ this only affects whether `tsc`/your editor understands the `#toolcrib`
210
+ import.
211
+
212
+ **`doctor` (or `merge`) flags a hand-edited instruction-file block.**
213
+ The `<!-- toolcrib:managed:... -->` block in `AGENTS.md`/`CLAUDE.md` is
214
+ meant to be regenerated by `toolcrib merge`, not edited by hand. Move any
215
+ notes of your own outside the fence, then run `merge` to restore it
216
+ cleanly.
217
+
218
+ **`merge` reports a conflict.**
219
+ You changed a vendored file yourself, and the new version changed it too.
220
+ Check the matching `.upstream-diff` file in `./toolcrib-patches/` for what
221
+ upstream did, and reconcile manually — or hand it to your AI assistant with
222
+ "reconcile my local changes to `<file>` with the upstream update."
223
+
224
+ **A bundler-specific note from `doctor`.**
225
+ `doctor` detects Next.js, Create React App, Vite, webpack, and Parcel from
226
+ files already in your project and calls out anything that specific
227
+ tool needs — for instance, Create React App's frozen webpack config
228
+ predating `package.json` "imports" support. If nothing's flagged for your
229
+ bundler, there's nothing to do.
230
+
231
+ ## What this guide doesn't cover
232
+
233
+ Everything about actually *using* the toolkit — which component to reach
234
+ for, how theming and the event bus work, first-run gotchas with providers
235
+ — lives in `ai-docs/`, vendored into your project the first time you run
236
+ `toolcrib init`. That folder is written for your AI assistant to read, not
237
+ for you to read directly: point your AI assistant at it and let it handle
238
+ the rest.
239
+
240
+ ## Contributing to the CLI itself
241
+
242
+ Working on this tool's own source (not just using it)? See
243
+ [CONTRIBUTING.md](CONTRIBUTING.md) for the local-dev workflow, test suite,
244
+ and publishing process.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcrib",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Bootstrap the toolcrib UI toolkit into your project",
5
5
  "type": "module",
6
6
  "license": "MIT",