threadctx 0.2.0 → 0.2.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/dist/threadctx.mjs +85 -11
  2. package/package.json +4 -4
@@ -12182,6 +12182,11 @@ function renderAuditText(s, opts) {
12182
12182
  const out = [];
12183
12183
  out.push(`${p.bold(`Agent context audit: ${s.org}`)}`, "");
12184
12184
  out.push(`${gradeColor(p.bold(`Fleet grade ${s.fleet.grade}`))} ${p.dim(`(${s.fleet.score}/100 average)`)}`);
12185
+ if (s.trend) {
12186
+ const t = s.trend;
12187
+ const d = t.after.score - t.before.score;
12188
+ out.push(`${p.bold(`Since ${t.since.slice(0, 10)}:`)} ${t.before.grade} \u2192 ${t.after.grade} (${d > 0 ? "+" : ""}${d}) \xB7 ${t.improved.length} improved \xB7 ${t.regressed.length} got worse \xB7 blockers ${t.before.blockers} \u2192 ${t.after.blockers}${t.added.length ? ` \xB7 ${t.added.length} new` : ""}`);
12189
+ }
12185
12190
  out.push(`${plural(s.repos.scanned, "repository", "repositories")} scanned \xB7 ${s.repos.withContext} with agent context \xB7 ${s.repos.withoutContext} without${s.repos.failed ? ` \xB7 ${s.repos.failed} could not be read` : ""}`);
12186
12191
  out.push(`${plural(s.fleet.counts.blocker, "blocker")} \xB7 ${plural(s.fleet.counts.warning, "warning")} \xB7 ${n(s.fleet.counts.info)} info`);
12187
12192
  if (s.repos.withContext)
@@ -12290,6 +12295,16 @@ function renderAuditHtml(s, repos) {
12290
12295
  <div class="stat"><b>${s.fleet.counts.warning}</b><span class="muted">warnings</span></div>
12291
12296
  <div class="stat"><b>${s.fleet.multiToolRepos}</b><span class="muted">maintain files for 2+ agents</span></div>
12292
12297
  <div class="stat"><b>${auto}</b><span class="muted">auto-fixable</span></div></div></div>`);
12298
+ if (s.trend) {
12299
+ const t = s.trend;
12300
+ const d = t.after.score - t.before.score;
12301
+ const row = (x) => `<tr><td>${esc(x.repo)}</td><td>${x.from} \u2192 ${x.to}</td><td>${x.to - x.from > 0 ? "+" : ""}${x.to - x.from}</td></tr>`;
12302
+ sections.push(`<h2>Since the last audit (${esc(t.since.slice(0, 10))})</h2>
12303
+ <div class="stats"><div class="stat"><b>${esc(t.before.grade)} \u2192 ${esc(t.after.grade)}</b><span class="muted">fleet grade (${d > 0 ? "+" : ""}${d})</span></div><div class="stat"><b>${t.before.blockers} \u2192 ${t.after.blockers}</b><span class="muted">blockers</span></div><div class="stat"><b>${t.before.warnings} \u2192 ${t.after.warnings}</b><span class="muted">warnings</span></div><div class="stat"><b>${t.before.withContext} \u2192 ${t.after.withContext}</b><span class="muted">repos with context</span></div></div>
12304
+ ${t.regressed.length ? `<h3>Got worse (${t.regressed.length})</h3><table><tr><th>Repository</th><th>Score</th><th>Change</th></tr>${t.regressed.map(row).join("")}</table>` : ""}
12305
+ ${t.improved.length ? `<h3>Improved (${t.improved.length})</h3><table><tr><th>Repository</th><th>Score</th><th>Change</th></tr>${t.improved.map(row).join("")}</table>` : ""}
12306
+ ${t.added.length ? `<p class="small muted">New since then: ${t.added.map(esc).join(", ")}</p>` : ""}`);
12307
+ }
12293
12308
  sections.push(`<h2>Summary</h2><ul>${takeaways(s).map((t) => `<li>${t.includes("<code>") ? t : esc(t)}</li>`).join("")}</ul>`);
12294
12309
  if (s.plan.length) {
12295
12310
  sections.push(`<h2>Fix these first</h2><p class="muted small">Ranked by score gained per unit of effort. \u201CAutomatic\u201D fixes are mechanical and safe; \u201Cquick\u201D ones need a one-line decision; \u201Cmanual\u201D ones need a person.</p>
@@ -12455,7 +12470,7 @@ function renderMarkdown(result, opts = {}) {
12455
12470
  const delta = opts.baseline ? result.score === opts.baseline.score ? " (unchanged)" : ` (${opts.baseline.grade} \u2192 ${result.grade}, ${result.score - opts.baseline.score > 0 ? "+" : ""}${result.score - opts.baseline.score})` : "";
12456
12471
  out.push(`### Agent context: grade **${result.grade}** \xB7 ${result.score}/100${delta}`);
12457
12472
  out.push("");
12458
- out.push(`${result.counts.blocker} blocker \xB7 ${result.counts.warning} warning \xB7 ${result.counts.info} info${result.counts.suppressed ? ` \xB7 ${result.counts.suppressed} suppressed` : ""}`);
12473
+ out.push(`${result.counts.blocker} blocker${result.counts.blocker === 1 ? "" : "s"} \xB7 ${result.counts.warning} warning${result.counts.warning === 1 ? "" : "s"} \xB7 ${result.counts.info} info${result.counts.suppressed ? ` \xB7 ${result.counts.suppressed} suppressed` : ""}`);
12459
12474
  const list = opts.newFingerprints ? open.filter((f) => opts.newFingerprints.has(f.fingerprint)) : open;
12460
12475
  if (opts.newFingerprints)
12461
12476
  out.push("", `**${list.length} new** in this change${open.length > list.length ? ` (${open.length - list.length} existing not shown)` : ""}.`);
@@ -12514,7 +12529,10 @@ function renderFactTable(rows, tools, opts) {
12514
12529
  `;
12515
12530
  }
12516
12531
  var BADGE_COLOR = { A: "brightgreen", B: "green", C: "yellow", D: "orange", F: "red" };
12517
- var BADGE_LINK = "https://www.npmjs.com/package/threadctx";
12532
+ var BADGE_LINK = "https://threadctx.dev";
12533
+ function badgeLinkFor(fullName) {
12534
+ return fullName && /^[A-Za-z0-9-]{1,39}\/[A-Za-z0-9_.-]{1,100}$/.test(fullName) ? `https://threadctx.dev/r/${fullName}` : BADGE_LINK;
12535
+ }
12518
12536
  function renderBadge(result, link = BADGE_LINK) {
12519
12537
  const url = `https://img.shields.io/badge/agent%20context-${result.grade}%20%C2%B7%20${result.score}-${BADGE_COLOR[result.grade]}`;
12520
12538
  const alt = `Agent context grade ${result.grade}`;
@@ -14899,7 +14917,7 @@ function applySuppressions(findings, inline, config, now, diagnostics) {
14899
14917
  }
14900
14918
 
14901
14919
  // ../rules/dist/version.js
14902
- var ENGINE_VERSION = "0.2.0";
14920
+ var ENGINE_VERSION = "0.2.1";
14903
14921
  var REGISTRY_VERSION = "2026.10.1";
14904
14922
 
14905
14923
  // ../rules/dist/engine.js
@@ -15084,6 +15102,29 @@ function exitCodeFor(result, failOn) {
15084
15102
  }
15085
15103
 
15086
15104
  // ../rules/dist/audit.js
15105
+ function fleetTrend(previous, current) {
15106
+ const prev = new Map(previous.repoTable.map((r) => [r.repo, r.score]));
15107
+ const cur = new Map(current.repoTable.map((r) => [r.repo, r.score]));
15108
+ const improved = [];
15109
+ const regressed = [];
15110
+ for (const [repo, to] of cur) {
15111
+ const from = prev.get(repo);
15112
+ if (from === void 0 || from === to)
15113
+ continue;
15114
+ (to > from ? improved : regressed).push({ repo, from, to });
15115
+ }
15116
+ const byDelta = (a, b) => Math.abs(b.to - b.from) - Math.abs(a.to - a.from) || (a.repo < b.repo ? -1 : 1);
15117
+ const snap = (s) => ({ grade: s.fleet.grade, score: s.fleet.score, blockers: s.fleet.counts.blocker, warnings: s.fleet.counts.warning, withContext: s.repos.withContext });
15118
+ return {
15119
+ since: previous.generatedAt,
15120
+ before: snap(previous),
15121
+ after: snap(current),
15122
+ improved: improved.sort(byDelta),
15123
+ regressed: regressed.sort(byDelta),
15124
+ added: [...cur.keys()].filter((r) => !prev.has(r)).sort(),
15125
+ removed: [...prev.keys()].filter((r) => !cur.has(r)).sort()
15126
+ };
15127
+ }
15087
15128
  var PENALTY = { blocker: 25, warning: 5, info: 1 };
15088
15129
  var EFFORT_COST = { automatic: 1, quick: 2, manual: 4 };
15089
15130
  var LABELS = {
@@ -15856,6 +15897,11 @@ function gitHistory(root) {
15856
15897
  }
15857
15898
  };
15858
15899
  }
15900
+ function githubRemote(dir) {
15901
+ const url = git(dir, ["remote", "get-url", "origin"]);
15902
+ const m = url?.match(/github\.com[:/]([A-Za-z0-9-]{1,39})\/([A-Za-z0-9_.-]{1,100}?)(?:\.git)?$/);
15903
+ return m ? `${m[1]}/${m[2]}` : void 0;
15904
+ }
15859
15905
 
15860
15906
  // src/mcp.ts
15861
15907
  import { existsSync, realpathSync, statSync as statSync2 } from "node:fs";
@@ -16068,6 +16114,19 @@ async function runAudit(o, io) {
16068
16114
  else io.stderr(`note: the licence from ${found.source} ${LICENSE_PROBLEM[check.reason]}; running the free audit.
16069
16115
  `);
16070
16116
  }
16117
+ let previous;
16118
+ if (o.baseline) {
16119
+ if (!claims) throw new AuditUsageError("--baseline compares two full audits and needs a licence (the free audit has no audit.json to compare).");
16120
+ const file = resolve3(io.cwd, o.baseline);
16121
+ if (!existsSync2(file)) throw new AuditUsageError(`baseline not found: ${o.baseline}`);
16122
+ try {
16123
+ const parsed = JSON.parse(readFileSync2(file, "utf8"));
16124
+ if (parsed.schema !== "threadctx.audit/v1") throw new Error("schema");
16125
+ previous = parsed;
16126
+ } catch {
16127
+ throw new AuditUsageError(`${o.baseline} is not a threadctx audit.json`);
16128
+ }
16129
+ }
16071
16130
  const token = githubToken(io.env);
16072
16131
  if (!token) io.stderr("note: no GitHub token found (set GH_TOKEN or run 'gh auth login'). Only public repositories will be read, with a low rate limit.\n");
16073
16132
  let listing;
@@ -16098,10 +16157,17 @@ async function runAudit(o, io) {
16098
16157
  }
16099
16158
  });
16100
16159
  const summary = summarizeFleet(repos, { org: o.org, generatedAt: io.now().toISOString(), engine: { version: ENGINE_VERSION, registry: REGISTRY_VERSION } });
16160
+ if (previous) {
16161
+ if (previous.org.toLowerCase() !== o.org.toLowerCase()) io.stderr(`note: the baseline is for ${previous.org}, not ${o.org}; comparing anyway.
16162
+ `);
16163
+ summary.trend = fleetTrend(previous, summary);
16164
+ }
16101
16165
  const files = [];
16102
16166
  if (claims) {
16103
16167
  const dir = resolve3(io.cwd, o.outDir ?? `threadctx-audit-${o.org}`);
16104
16168
  mkdirSync(dir, { recursive: true });
16169
+ const last = join3(dir, "audit.json");
16170
+ if (existsSync2(last)) writeFileSync(join3(dir, "previous-audit.json"), readFileSync2(last));
16105
16171
  for (const [name, body] of [["report.html", renderAuditHtml(summary, repos)], ["repos.csv", renderAuditCsv(summary)], ["audit.json", renderAuditJson(summary, repos)]]) {
16106
16172
  writeFileSync(join3(dir, name), body);
16107
16173
  files.push(join3(dir, name));
@@ -16181,6 +16247,8 @@ Usage:
16181
16247
  --include-forks --include-archived
16182
16248
  --license <key|file> Licence key (or THREADCTX_LICENSE, or ~/.threadctx/license)
16183
16249
  --output-dir <dir> Where licensed reports are written
16250
+ --baseline <audit.json> Show what changed since a previous audit (automatic when
16251
+ re-running into the same folder)
16184
16252
  threadctx license [key|file] Check a licence offline
16185
16253
  threadctx explain <file> [--tool <id>|all] [--surface cloud-agent|code-review|chat]
16186
16254
  What each agent loads for this file, in precedence order
@@ -16207,6 +16275,7 @@ var OPTIONS = {
16207
16275
  "include-forks": { type: "boolean" },
16208
16276
  "include-archived": { type: "boolean" },
16209
16277
  "output-dir": { type: "string" },
16278
+ baseline: { type: "string" },
16210
16279
  rule: { type: "string", multiple: true },
16211
16280
  verbose: { type: "boolean" },
16212
16281
  tool: { type: "string" },
@@ -16351,9 +16420,9 @@ async function cmdScan(pathArg, v, io, color) {
16351
16420
  }
16352
16421
  if (remoteLabel && format === "text" && !v.output) io.stdout(`
16353
16422
  README badge:
16354
- ${renderBadge(result).markdown}
16423
+ ${renderBadge(result, badgeLinkFor(parseGithubRef(v.github).fullName)).markdown}
16355
16424
  `);
16356
- if (format === "text" && !v.output && !remoteLabel) maybeUpgradeLine(result, io);
16425
+ if (format === "text" && !v.output && !remoteLabel) maybeUpgradeLine(result, io, githubRemote(view.root));
16357
16426
  const threshold = failOn ?? loadConfig(view).failOn;
16358
16427
  return exitCodeFor(result, threshold);
16359
16428
  }
@@ -16399,10 +16468,15 @@ function cmdCompare(baseFile, headFile, v, io) {
16399
16468
  } else io.stdout(out);
16400
16469
  return compareExitCode(c, failOn);
16401
16470
  }
16471
+ function defaultBaseline(org, outDir, license, io) {
16472
+ if (!/^[A-Za-z0-9-]{1,39}$/.test(org)) return void 0;
16473
+ const file = join4(resolve4(io.cwd, outDir ?? `threadctx-audit-${org}`), "audit.json");
16474
+ return existsSync3(file) && findLicense(license, io) ? file : void 0;
16475
+ }
16402
16476
  async function cmdAudit(v, io, color) {
16403
16477
  if (!v.org) throw new UsageError("usage: threadctx audit --org <github-org-or-user>");
16404
16478
  try {
16405
- return await runAudit({ org: v.org, max: v.max ? Number(v.max) : 200, includeForks: Boolean(v["include-forks"]), includeArchived: Boolean(v["include-archived"]), license: v.license, outDir: v["output-dir"], json: Boolean(v.json), color }, io);
16479
+ return await runAudit({ org: v.org, max: v.max ? Number(v.max) : 200, includeForks: Boolean(v["include-forks"]), includeArchived: Boolean(v["include-archived"]), license: v.license, outDir: v["output-dir"], baseline: v.baseline ?? defaultBaseline(v.org, v["output-dir"], v.license, io), json: Boolean(v.json), color }, io);
16406
16480
  } catch (e) {
16407
16481
  if (e instanceof AuditUsageError) throw new UsageError(e.message);
16408
16482
  throw e;
@@ -16428,7 +16502,7 @@ source: ${found.source}
16428
16502
  function cmdBadge(pathArg, v, io) {
16429
16503
  const repo = openRoot(pathArg, io);
16430
16504
  const result = doScan(repo, v, io);
16431
- const badge = renderBadge(result);
16505
+ const badge = renderBadge(result, badgeLinkFor(githubRemote(repo.root)));
16432
16506
  if (v.json) io.stdout(`${JSON.stringify({ grade: result.grade, score: result.score, ...badge }, null, 2)}
16433
16507
  `);
16434
16508
  else io.stdout(`${badge.markdown}
@@ -16585,8 +16659,8 @@ function cmdPackValidate(file, io) {
16585
16659
  `);
16586
16660
  return 0;
16587
16661
  }
16588
- var UPGRADE_URL = void 0;
16589
- function maybeUpgradeLine(result, io) {
16662
+ var UPGRADE_URL = "https://threadctx.dev/pricing";
16663
+ function maybeUpgradeLine(result, io, remote) {
16590
16664
  if (!UPGRADE_URL || !io.isTTY || io.env.CI || io.env.THREADCTX_NO_UPSELL) return;
16591
16665
  const stateFile = join4(io.env.THREADCTX_HOME ?? join4(homedir2(), ".threadctx"), "state.json");
16592
16666
  let state = {};
@@ -16596,8 +16670,8 @@ function maybeUpgradeLine(result, io) {
16596
16670
  }
16597
16671
  const today = io.now().toISOString().slice(0, 10);
16598
16672
  if (state.lastUpsell === today) return;
16599
- const toolsUsed = result.tools.filter((t) => t.layers > 0).length;
16600
- const msg = toolsUsed >= 2 ? `${toolsUsed} agents read this repository. Grade every pull request and keep them aligned: ${UPGRADE_URL}` : `Track this grade on every pull request: ${UPGRADE_URL}`;
16673
+ const owner = remote?.split("/")[0];
16674
+ const msg = owner ? `See every repository in ${owner} at once (free summary): npx threadctx audit --org ${owner} \xB7 ${UPGRADE_URL}` : `Add a README badge: npx threadctx badge \xB7 Whole-organisation audits: ${UPGRADE_URL}`;
16601
16675
  io.stderr(`
16602
16676
  ${msg}
16603
16677
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "threadctx",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "files": [
@@ -39,11 +39,11 @@
39
39
  "dependencies": {},
40
40
  "devDependencies": {
41
41
  "diff": "^9.0.0",
42
- "@threadctx/adapters": "0.1.0",
42
+ "@threadctx/core": "0.1.0",
43
+ "@threadctx/report": "0.1.0",
43
44
  "@threadctx/rules": "0.1.0",
44
45
  "@threadctx/discovery": "0.1.0",
45
- "@threadctx/report": "0.1.0",
46
- "@threadctx/core": "0.1.0"
46
+ "@threadctx/adapters": "0.1.0"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsc -b && node build.mjs"