toolcrib 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -143,7 +143,7 @@ anything. It reports:
143
143
  - **Stale instruction-file blocks** — if the `<!-- toolcrib:managed:... -->`
144
144
  block in your `AGENTS.md`/`CLAUDE.md` was hand-edited instead of
145
145
  regenerated, or is out of date with your installed version.
146
- - **Whether a newer release is available.**
146
+ - **Whether a newer release is available** — and, when a known, fixed vulnerability affects your installed version specifically, its severity and a link to the fix (generated from real, fixed toolcrib CodeQL findings — see the project's own `AGENTS.md` for how).
147
147
  - **A `tsconfig.json` compatibility check** — if `moduleResolution` isn't
148
148
  set to `"bundler"`, `"node16"`, or `"nodenext"`, `import { ... } from
149
149
  '#toolcrib'` will run fine but your editor/`tsc` may falsely report
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcrib",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Bootstrap the toolcrib UI toolkit into your project",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,8 +30,8 @@
30
30
  "semver": "^7.6.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@vitest/coverage-v8": "^4.1.10",
33
+ "@vitest/coverage-v8": "^5.0.0",
34
34
  "cross-spawn": "^7.0.6",
35
- "vitest": "^4.1.10"
35
+ "vitest": "^5.0.0"
36
36
  }
37
37
  }
@@ -1,9 +1,10 @@
1
1
  import path from 'node:path';
2
+ import semver from 'semver';
2
3
  import * as p from '@clack/prompts';
3
4
  import { fetchRelease } from '../lib/release.js';
4
5
  import { normalize } from '../lib/patches.js';
5
6
  import { readJsonIfExists, readLock, readTextIfExists, fileExists } from '../lib/project.js';
6
- import { fetchLatestVersion } from '../lib/github.js';
7
+ import { fetchLatestVersion, fetchSecurityAdvisories } from '../lib/github.js';
7
8
  import { MANAGED_DOCS, KNOWN_TARGET_FILES, listManagedBlocks } from '../lib/managedDocs.js';
8
9
  import { detectBundler } from '../lib/bundler.js';
9
10
  import { checkRootProviderWired } from '../lib/rootProvider.js';
@@ -186,52 +187,94 @@ export async function doctorCommand(options = {}) {
186
187
 
187
188
  const spinner = p.spinner();
188
189
  spinner.start(`Checking against installed version v${lock.version}`);
189
- let release;
190
+ // Network-dependent section 1 of 2: drift check against the installed
191
+ // release. A failure here (rate limit, network down, bad release asset)
192
+ // should only skip *this* check, not abort bundler detection/root-provider
193
+ // check/etc. below — those are 100% local and would otherwise succeed.
194
+ let release = null;
195
+ let releaseFetchError = null;
190
196
  try {
191
197
  release = await fetchRelease(lock.version);
192
198
  } catch (err) {
193
- spinner.stop('Failed to fetch release');
194
- throw err;
199
+ releaseFetchError = err;
195
200
  }
196
201
 
197
- const drifted = [];
198
- for (const relPath of release.allFiles()) {
199
- const targetPath = path.join(projectRoot, TOOLKIT_DIR, relPath);
200
- const local = readTextIfExists(targetPath);
201
- const shipped = release.readFile(relPath);
202
- if (normalize(local) !== normalize(shipped)) {
203
- drifted.push(relPath);
202
+ if (release) {
203
+ const drifted = [];
204
+ for (const relPath of release.allFiles()) {
205
+ const targetPath = path.join(projectRoot, TOOLKIT_DIR, relPath);
206
+ const local = readTextIfExists(targetPath);
207
+ const shipped = release.readFile(relPath);
208
+ if (normalize(local) !== normalize(shipped)) {
209
+ drifted.push(relPath);
210
+ }
204
211
  }
205
- }
206
- const managedBlockMessages = await checkManagedBlocks(projectRoot, release);
207
- await release.cleanup();
208
- spinner.stop('Drift check complete');
212
+ const managedBlockMessages = await checkManagedBlocks(projectRoot, release);
213
+ await release.cleanup();
214
+ spinner.stop('Drift check complete');
209
215
 
210
- if (drifted.length === 0) {
211
- p.log.success(`No local drift detected from v${lock.version}.`);
212
- } else {
213
- p.log.warn(
214
- `${drifted.length} file(s) differ from the shipped v${lock.version}:\n` +
215
- drifted.map((f) => ` ${f}`).join('\n')
216
- );
217
- }
216
+ if (drifted.length === 0) {
217
+ p.log.success(`No local drift detected from v${lock.version}.`);
218
+ } else {
219
+ p.log.warn(
220
+ `${drifted.length} file(s) differ from the shipped v${lock.version}:\n` +
221
+ drifted.map((f) => ` ${f}`).join('\n')
222
+ );
223
+ }
218
224
 
219
- if (managedBlockMessages.length === 0) {
220
- p.log.success('No managed AGENTS.md/CLAUDE.md blocks found, or none have drifted.');
221
- } else {
222
- for (const message of managedBlockMessages) {
223
- p.log[message.level](message.text);
225
+ if (managedBlockMessages.length === 0) {
226
+ p.log.success('No managed AGENTS.md/CLAUDE.md blocks found, or none have drifted.');
227
+ } else {
228
+ for (const message of managedBlockMessages) {
229
+ p.log[message.level](message.text);
230
+ }
224
231
  }
232
+ } else {
233
+ spinner.stop('Drift check skipped');
234
+ p.log.warn(`Could not fetch v${lock.version} to check for drift: ${releaseFetchError.message}`);
225
235
  }
226
236
 
237
+ // Network-dependent section 2 of 2: "is a newer version available."
238
+ // Independent failure point from the drift check above (different
239
+ // GitHub endpoint, same rate limit) — same rule applies: a failure here
240
+ // shouldn't take out the local-only checks that follow.
227
241
  // fetchLatestVersion (GitHub's dedicated /releases/latest endpoint), not
228
242
  // listVersions — doctor only ever needs the single newest release to
229
243
  // compare against what's installed, not every release's full metadata.
230
- const newestVersion = await fetchLatestVersion();
231
- if (newestVersion !== lock.version) {
232
- p.log.info(`A newer version is available: v${newestVersion} (installed: v${lock.version}). Run 'toolcrib merge'.`);
233
- } else {
234
- p.log.info('You are on the latest release.');
244
+ try {
245
+ const newestVersion = await fetchLatestVersion();
246
+ if (newestVersion !== lock.version) {
247
+ p.log.info(`A newer version is available: v${newestVersion} (installed: v${lock.version}). Run 'toolcrib merge'.`);
248
+ } else {
249
+ p.log.info('You are on the latest release.');
250
+ }
251
+ } catch (err) {
252
+ p.log.warn(`Could not check for a newer release: ${err.message}`);
253
+ }
254
+
255
+ // Network-dependent section 3 of 3: security advisories, generated from
256
+ // real CodeQL findings (see scripts/generate-security-advisories.js).
257
+ // Independent failure point from the version check above -- this file
258
+ // always lives on the toolcrib repo's own main branch, never in a
259
+ // consumer's vendored copy (a frozen snapshot that structurally can't
260
+ // know about anything published after it), so it's fetched fresh on
261
+ // every run for the same reason fetchLatestVersion is. Enriches the
262
+ // version check above rather than replacing it: same underlying
263
+ // question ("is there a newer version worth getting"), this just says
264
+ // *why* when the answer is yes for a real, fixed vulnerability.
265
+ try {
266
+ const advisories = await fetchSecurityAdvisories();
267
+ const relevant = advisories
268
+ .filter((a) => semver.gt(a.fixedIn, lock.version))
269
+ .sort((a, b) => semver.compare(b.fixedIn, a.fixedIn));
270
+ for (const a of relevant) {
271
+ p.log.warn(
272
+ `Security: v${a.fixedIn} fixes a ${a.severity.toUpperCase()}-severity issue (installed: v${lock.version}) -- ` +
273
+ `${a.summary}\n ${a.url}\n Run 'toolcrib merge' to update.`
274
+ );
275
+ }
276
+ } catch (err) {
277
+ p.log.warn(`Could not check for security advisories: ${err.message}`);
235
278
  }
236
279
 
237
280
  if (!checkTypeScriptAdopted(projectRoot)) {
@@ -272,7 +315,7 @@ export async function doctorCommand(options = {}) {
272
315
  p.log.warn(
273
316
  "Root providers: couldn't find <ToolcribProvider> or a manual <ThemeProvider>/<ToastProvider>/<ToastContainer> " +
274
317
  'composition anywhere under src/. Every toolcrib component throws or silently no-ops without one of these ' +
275
- "wrapping your app root — see CORE.md §1. (Heuristic text scan — a false warning is possible if your root " +
318
+ "wrapping your app root — see CORE.md's Root Setup section. (Heuristic text scan — a false warning is possible if your root " +
276
319
  'setup uses an unusual file layout or a re-exported alias; verify directly if you believe it\'s already wired.)'
277
320
  );
278
321
  }
package/src/lib/github.js CHANGED
@@ -88,6 +88,36 @@ export async function fetchLatestVersion() {
88
88
  return release.tag_name.replace(/^v/, '');
89
89
  }
90
90
 
91
+ /**
92
+ * Fetch security-advisories.json fresh from the toolcrib repo's own
93
+ * `main` branch -- never from a consumer's vendored copy, which is a
94
+ * frozen snapshot from whatever version they installed and structurally
95
+ * can't know about anything published after that (see
96
+ * scripts/generate-security-advisories.js for how the file itself is
97
+ * generated, from real CodeQL alert state, never hand-authored).
98
+ *
99
+ * Uses the Contents API's raw media type to get the file's bytes
100
+ * directly rather than base64-decoding the default JSON-wrapped
101
+ * response. A missing file (a fresh main with nothing published yet, or
102
+ * before this file's first commit) is treated as "no advisories," not an
103
+ * error -- unlike every other call in this file, absence here is the
104
+ * normal, expected starting state, not a failure.
105
+ *
106
+ * Public, unauthenticated read (unlike the generator script, which needs
107
+ * a token to read the code-scanning alerts API this file is derived
108
+ * from) -- a consumer's `doctor` run never needs credentials for this.
109
+ */
110
+ export async function fetchSecurityAdvisories() {
111
+ const res = await fetch(`${API_BASE}/repos/${REPO}/contents/security-advisories.json?ref=main`, {
112
+ headers: { Accept: 'application/vnd.github.raw+json' },
113
+ });
114
+
115
+ if (res.status === 404) return [];
116
+ if (!res.ok) throwGitHubApiError(res, 'security-advisories.json');
117
+
118
+ return JSON.parse(await res.text());
119
+ }
120
+
91
121
  function assetUrl(version, assetName) {
92
122
  return version === 'latest'
93
123
  ? `${RELEASES_BASE}/latest/download/${assetName}`
@@ -41,7 +41,7 @@ function listCandidateFiles(rootDir) {
41
41
  * Read-only heuristic: does this project's own source wire up toolcrib's
42
42
  * root providers, via `<ToolcribProvider>` or the equivalent manual
43
43
  * `<ThemeProvider>` + `<ToastProvider>` + `<ToastContainer>` composition?
44
- * Both are legitimate per `CORE.md` §1 -- this doesn't prefer one, it just
44
+ * Both are legitimate per `CORE.md`'s Root Setup section -- this doesn't prefer one, it just
45
45
  * confirms *something* is wired, since every toolcrib component throws or
46
46
  * silently no-ops without it, and that failure mode gives no clue back to
47
47
  * "you forgot the root setup."