@su-sws/synthetic-web-team 0.2.7 → 0.2.8

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/AGENTS.md CHANGED
@@ -5,6 +5,12 @@ is the block between the `sws-agent-contract` markers below, and it is the only
5
5
  part of this file `add .` copies into a project. The standards it cites as
6
6
  `.sws/standards/` are at `standards/` here.
7
7
 
8
+ `adapters/claude/` (with its manifests in `.claude-plugin/`) is the optional
9
+ Claude Code plugin: entry points, read-only reviewers, advisory hooks, evals.
10
+ **It holds no knowledge.** It wires and sequences; facts go in `skills/`,
11
+ `standards/` or the CLI, and the adapter points at them. `scripts/validate-plugin.mjs`
12
+ holds it to that. See `docs/claude-harness.md`.
13
+
8
14
  ## Setting up a Stanford site
9
15
 
10
16
  **Three named jobs, no default:** `install` puts the skills in a person's tool
package/README.md CHANGED
@@ -23,18 +23,19 @@ Early. The plan is complete and reviewed; the implementation is partway through.
23
23
  | `astro-ssr` recipe | Written, extends `astro-static`. **Not executed**, and no SWS Astro project runs SSR, so its hosting half is reasoned rather than copied |
24
24
  | `next-ssr` recipe | Written, extends `astro-static`. Renamed from `next-netlify` on 2026-09-03. Not yet executed end to end |
25
25
  | Hosting profiles | **New.** `standards/hosting/`: a capability contract plus GitHub Pages, Netlify, and Vercel |
26
- | Shared skills | **8 of 8 done**, including `sws-github` (provisions a repo and Pages deploy through `gh`) and `sws-preflight` (is this machine equipped?) |
26
+ | Shared skills | **12 of 12 done**, including `sws-github` (provisions a repo and Pages deploy through `gh`), `sws-preflight` (is this machine equipped?) and `sws-code-review` |
27
27
  | Role skills | **8 of 8 built, 11 of 11 stubs.** 31 skills total, all validated |
28
28
  | Documentation site | **Working.** [`site/`](site/), built by our own recipe, scores 100/100 with zero failures |
29
- | `sws` CLI | **Working.** `preflight` reports whether the machine has the tools to build at all. `doctor` and `check` run 13 check modules against 68 criteria. `sws a11y` runs axe and an interactive-state audit — hover and focus measured with a real mouse and a real Tab key — and `sws perf` measures a byte budget, all in real Chromium |
29
+ | `sws` CLI | **Working.** `preflight` reports whether the machine has the tools to build at all. `doctor` and `check` run 13 check modules against 68 criteria. `sws a11y` runs axe and an interactive-state audit — hover and focus measured with a real mouse and a real Tab key — and `sws perf` measures a byte budget, all in real Chromium. `--format brief` prints the report as one line of JSON for an agent working in a loop, `--no-history` leaves the score history alone, and `prior-art find` searches the catalog of existing SWS work. Those three are newer than the published 0.2.7 and reach npm with the next release |
30
30
  | Report delivery | **Working.** PR comment and a persistent "Site health" issue, both updated in place. Score trend, sparkline, HTML artifact, README badge |
31
- | Install wizard | **Working, agent-first, two-part.** `user` scope installs the skills into your tools once per machine and is removable; project scope merges the contract into `AGENTS.md` and puts the standards and the per-site record under `.sws/`. Non-interactive by default off a TTY, `--json` result with machine-readable next steps, `--answers` input, idempotent re-runs that preserve project state |
31
+ | Install wizard | **Working, agent-first, two-part.** `user` scope installs the skills into your tools once per machine and is removable; project scope merges the contract into `AGENTS.md` and puts the standards and the per-site record under `.sws/`. Non-interactive by default off a TTY, `--json` result with machine-readable next steps, `--answers` input, idempotent re-runs that preserve project state. `install --claude-plugin` steps aside for the Claude Code plugin so no skill is listed twice |
32
32
  | Copy-a-prompt install | **Working.** Five prompts on the site — install into your editor, start a new site, add to an existing project, review, update — each carrying an `npx` route and a `git clone` fallback |
33
- | Publishable packages | **Working, not yet published.** Two packages — `@su-sws/synthetic-web-team` and `@su-sws/synthetic-web-team-mcp` — verified by installing the tarballs into a clean project with no repository present |
33
+ | Published packages | **On npm.** Two packages, `@su-sws/synthetic-web-team` and `@su-sws/synthetic-web-team-mcp`, released together on every push to `main` and verified by installing the tarballs into a clean project with no repository present |
34
+ | Claude Code plugin | **Built.** Optional, for Claude Code only: the same 31 skills plus five entry points, five read-only reviewers, advisory hooks and the MCP server, in [`adapters/claude/`](adapters/claude/). Installs from this repository's default branch. Design in [`docs/claude-harness.md`](docs/claude-harness.md) |
34
35
  | Updates | **Working.** Re-install is the update: project state preserved, local edits reported as conflicts rather than overwritten, stale files reported not deleted, staleness nag in `sws doctor` |
35
36
  | Recipe canary | **Deliberately deferred**, 2026-09-01. Not in production, so nobody is exposed to upstream drift yet. Revisit before the first pilot |
36
37
  | Standards freshness CI | Planned, and the priority ahead of the canary. Keeps policy, prior art, and sourced facts from going stale |
37
- | MCP server | **Working.** [`packages/mcp/`](packages/mcp/). 5 tools, 26 resources, verified over the real stdio protocol |
38
+ | MCP server | **Working.** [`packages/mcp/`](packages/mcp/). 5 tools, 26 resources, verified over the real stdio protocol. In the published 0.2.7, `sws_check` and `sws_scaffold` fail outside this repository; the fix is in this repository and ships with the next release |
38
39
 
39
40
  End to end, verified: `synthetic-web-team` installs, an agent follows the recipe, then `npm run build && sws a11y && sws perf && sws check` reports **100/100 with zero automated failures** — 52 criteria passing, none to fix, 8 unchecked. axe runs in real Chromium against every built route and finds 0 violations at WCAG 2.1 AA; the byte budget passes at 154 KB of 800. **Every one of the 8 unchecked items is genuinely unautomatable** — the manual WCAG checklist, ODA review, subdomain approval, MFA attestation, the DRA question — and each says so with a reason rather than being quietly dropped.
40
41
 
@@ -108,6 +109,90 @@ your own `AGENTS.md` at it, and `next[]` says so. Add the devDependency yourself
108
109
  if you want `npx sws`. The install record remembers the layout, so a plain
109
110
  `add .` updates it in place, and `--layout root` switches back.
110
111
 
112
+ ### Claude Code plugin
113
+
114
+ In Claude Code the first part can be a plugin instead of the skill copies. In a
115
+ Claude Code session, in one step:
116
+
117
+ ```text
118
+ /plugin install sws --marketplace SU-SWS/synthetic-web-team
119
+ ```
120
+
121
+ Or from a terminal:
122
+
123
+ ```bash
124
+ claude plugin marketplace add SU-SWS/synthetic-web-team
125
+ claude plugin install sws@su-sws
126
+ ```
127
+
128
+ It is optional and Claude Code only. Cursor, Codex, Copilot and the rest keep
129
+ using `install` exactly as above, and so can Claude Code.
130
+
131
+ **What it adds over the portable install:**
132
+
133
+ - **The same 31 skills**, read from this repository's `skills/` and named
134
+ `sws:<skill>`, so `sws-onboard` is `/sws:sws-onboard`. No copy in your home
135
+ directory.
136
+ - **Five entry points** that run a whole job in order and stop where a person
137
+ has to decide: `/sws:new-site`, `/sws:retrofit`, `/sws:review`, `/sws:fix` and
138
+ `/sws:ship`. Claude may start the first four when you ask in your own words;
139
+ `/sws:ship` runs only when you type it.
140
+ - **Five read-only reviewers** (`sws:accessibility-reviewer`,
141
+ `sws:brand-reviewer`, `sws:compliance-reviewer`, `sws:discoverability-reviewer`,
142
+ `sws:security-reviewer`). `/sws:review` runs them side by side over one report
143
+ and merges what they find. They can read files and nothing else.
144
+ - **Advisory hooks.** At the start of a session inside an SWS project, a short
145
+ note with the project's state from `sws doctor`. After a build command
146
+ succeeds, a short summary of the report and what to do next. After an edit
147
+ to a file that names the Global Footer or the Identity Bar, a pointer to the
148
+ contract for it, once per file per session. They add context and nothing else: every hook exits 0
149
+ and none can stop a command. `SWS_HARNESS_HOOKS=off` in your shell silences
150
+ all of them.
151
+ - **The MCP server**, the same `sws` entry `init` and `add` write to `.mcp.json`.
152
+ Where a project has both, Claude Code connects one copy.
153
+
154
+ **What it does not replace:** `init` and `add .`. The plugin writes nothing into
155
+ a project. The contract in `AGENTS.md`, `.sws/standards/` and the per-site record
156
+ still come from one of those two commands, and CI reads those files, not your
157
+ Claude Code setup. `/sws:new-site` and `/sws:retrofit` run them for you.
158
+
159
+ **Using it alongside `install`.** With the plugin and `~/.claude/skills/` both
160
+ present, Claude Code lists every skill twice: once bare, once as `sws:`. Pick
161
+ one for Claude Code:
162
+
163
+ ```bash
164
+ npx @su-sws/synthetic-web-team install --claude-plugin
165
+ ```
166
+
167
+ That leaves Claude Code to the plugin, removes the copies `install` put in
168
+ `~/.claude/skills/` (only files its record lists that you have not edited), and
169
+ keeps writing `~/.agents/skills/` for every other tool. It is remembered, so a
170
+ later plain `install` keeps it; `install --no-claude-plugin` switches back.
171
+ `--dry-run` shows what would go first. With `--json`, the result's `plugin`
172
+ field says whether the plugin was found, and `next[]` names the plugin commands
173
+ where they apply. The installer reports them and never runs them.
174
+
175
+ **Honest limits:**
176
+
177
+ - After a marketplace install, `claude plugin list` shows a note that the
178
+ packages it lists were not installed. That is expected. The plugin is this
179
+ repository, and its lockfile lists workspace links that Claude Code does not
180
+ install. Nothing in the plugin needs them: the hooks use Node built-ins, the
181
+ installer has no dependencies, and the CLI comes from your project.
182
+ - The session-start state needs the project's own dependency. Until `npm
183
+ install` has put `@su-sws/synthetic-web-team` in `node_modules`, the note says
184
+ the CLI is not installed and how to fix it. It also needs a release with
185
+ `--format brief`, which 0.2.7 does not have.
186
+ - The MCP tools `sws_check` and `sws_scaffold` work once the fixed MCP package
187
+ is released (see Status). The entry points call the CLI and the installer
188
+ directly, so they do not wait on it.
189
+ - Nothing here blocks. The hooks advise, the reviewers report, and
190
+ `/sws:ship` asks before each outward step: creating a repository, pushing,
191
+ connecting a host, DNS.
192
+
193
+ Updates come through Claude Code: `claude plugin update sws@su-sws`, then
194
+ restart. `claude plugin uninstall sws@su-sws` removes it.
195
+
111
196
  ### Or drive the installer yourself
112
197
 
113
198
  **The primary caller is an agent, so that is the first-class path.** One command,
@@ -172,6 +257,10 @@ lose conflict detection until the next install.
172
257
  `npx sws doctor` tells you when a project is behind: content and tools ship in
173
258
  one package, so the CLI's version *is* the standards version — no network call.
174
259
 
260
+ The Claude Code plugin is the one part that updates separately, through Claude
261
+ Code itself (see [Claude Code plugin](#claude-code-plugin)). It carries the same
262
+ version number as the package, and updating it changes nothing in a project.
263
+
175
264
  ### If you are a human
176
265
 
177
266
  Same command without `--json`. It detects your editors, asks a handful of
@@ -179,8 +268,9 @@ questions, and shows you the file list before writing anything. `--dry-run`
179
268
  reports what it would do and writes nothing; `--interactive` forces prompts even
180
269
  without a TTY.
181
270
 
182
- Nothing is published to npm yet. Until it is, install from a checkout — the
183
- wizard finds its content beside itself or in the current directory:
271
+ Both packages are on npm. Where the registry is unreachable, or to try
272
+ unreleased work, install from a checkout. The wizard finds its content beside
273
+ itself or in the current directory:
184
274
 
185
275
  ```bash
186
276
  git clone https://github.com/SU-SWS/synthetic-web-team
@@ -202,7 +292,7 @@ cp -r path/to/synthetic-web-team/skills ~/.agents/skills
202
292
  cp -r path/to/synthetic-web-team/skills ~/.claude/skills
203
293
  ```
204
294
 
205
- Those two skill paths between them are read natively by Claude Code, VS Code Copilot, Cursor, Codex CLI, Gemini CLI, Zed, Antigravity, and Cline. No build step, no compiler, no plugin to install.
295
+ Those two skill paths between them are read natively by Claude Code, VS Code Copilot, Cursor, Codex CLI, Gemini CLI, Zed, Antigravity, and Cline. No build step, no compiler, and no plugin required: the [Claude Code plugin](#claude-code-plugin) is optional and reads the same `skills/` folder.
206
296
 
207
297
  Two copies because no single path is read by every editor, and we deliberately have no compiler. If you only use one editor, delete the other directory. See [`docs/skill-paths.md`](docs/skill-paths.md).
208
298
 
@@ -232,6 +322,8 @@ node packages/cli/bin/sws.mjs doctor --standards standards
232
322
  | [`packages/cli/`](packages/cli/) | The `sws` CLI. 13 check modules, plus axe, interactive-state, and performance runners in real Chromium |
233
323
  | [`packages/wizard/`](packages/wizard/) | The install wizard |
234
324
  | [`packages/mcp/`](packages/mcp/) | `@su-sws/synthetic-web-team-mcp`. The same standards as MCP tools and resources, for agents that prefer calling a tool to shelling out |
325
+ | [`.claude-plugin/`](.claude-plugin/) | The Claude Code plugin and marketplace manifests. The plugin's root is this repository's root |
326
+ | [`adapters/claude/`](adapters/claude/) | The Claude Code adapter: entry-point skills, read-only reviewer agents, advisory hooks and eval cases. It holds no knowledge of its own and points at `skills/`, `standards/` and the CLI. See [`docs/claude-harness.md`](docs/claude-harness.md) |
235
327
 
236
328
  **Two published packages, not four.** `@su-sws/synthetic-web-team` ships the content, the CLI
237
329
  and the wizard together — one version number, so the CLI always knows which
@@ -241,13 +333,16 @@ download an MCP SDK to run `sws check`. `packages/cli` and
241
333
  `@su-sws/synthetic-web-team`, which is why there is no staging script and no empty-looking
242
334
  package directory.
243
335
 
336
+ The Claude Code plugin is a third way in, not a third package. Claude Code
337
+ installs it from this repository with git, and neither npm tarball contains it.
338
+
244
339
  ## Five decisions that surprise people
245
340
 
246
341
  **Recipes, not starter templates.** We do not ship or maintain application code. A recipe says what must be true and delegates boilerplate to the upstream scaffolder (`npm create astro@latest`), so you get current versions and we have nothing to keep updated. A template starts rotting the day it is committed and every consumer inherits the rot.
247
342
 
248
343
  **Install latest. Pin nothing.** Recipes name no version numbers, with exactly one exception: Decanter 8 rather than 7, because they are architecturally different and getting it wrong fails silently. Standards are expressed as things to avoid, which age far better than versions to require.
249
344
 
250
- **Advisory, not blocking.** Findings are reports, PR comments, and a visible score that trends. Exactly one thing fails a build: committed credentials, because that harm is irreversible. A tool that fails your build over a contrast ratio gets uninstalled by Friday, and then nothing is compliant.
345
+ **Advisory, not blocking.** Findings are reports, PR comments, and a visible score that trends. Exactly one thing fails a build: committed credentials, because that harm is irreversible. A tool that fails your build over a contrast ratio gets uninstalled by Friday, and then nothing is compliant. The Claude Code plugin's hooks follow the same rule: they add a note for the model and cannot stop a command.
251
346
 
252
347
  The report is designed to **find the reader** rather than expecting the reader to find CI. A run on the default branch rewrites one long-lived "Site health" issue in place — findable by someone who has never opened the Actions tab, and it notifies watchers. A pull request gets one comment, also updated in place, because a new comment per push is noise people mute. A push to any other branch reports in its job summary only, so a release branch never overwrites the default branch's report or its trend. The score trend lives in that issue's body as an HTML comment, which is why it needs no database, no artifact that expires, and no commit churn.
253
348
 
@@ -336,6 +431,13 @@ match `0.2.0`, so a published server would quietly resolve *old* standards.
336
431
  with the versions, which is the whole reason `npm version` is not used here. Run
337
432
  it with `--dry-run` to see what a bump would do.
338
433
 
434
+ **The plugin manifest moves with them.** `.claude-plugin/plugin.json` carries the
435
+ same version as `package.json`, and Claude Code offers an update only when that
436
+ string changes. `set-version.mjs` rewrites it with the others, the release
437
+ commit includes it, and `scripts/validate-plugin.mjs` fails if the two numbers
438
+ differ. The marketplace entry carries none, because a version in both places is
439
+ a conflict Claude Code resolves in the manifest's favour.
440
+
339
441
  Ordering is deliberate: the gates run before anything is versioned, the version
340
442
  is checked against the registry before anything is committed, and the tag is
341
443
  pushed before anything is published. A failure at any point leaves the registry
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-sws/synthetic-web-team",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Stanford Web Services standards and agent team: policy, patterns, recipes, fragments, prior art, 31 skills, the two-part install wizard, and the advisory compliance CLI.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -9,7 +9,8 @@
9
9
  },
10
10
  "scripts": {
11
11
  "sync-skills": "node scripts/sync-skills.mjs",
12
- "validate": "node scripts/validate-skills.mjs && node scripts/validate-emit.mjs && node scripts/validate-install.mjs && node scripts/validate-criteria.mjs && node scripts/validate-state-classifier.mjs && node scripts/validate-hooks.mjs && node scripts/validate-acknowledged.mjs && node scripts/validate-layouts.mjs && node scripts/validate-divergences.mjs && node scripts/validate-frameworks.mjs && node scripts/validate-contained.mjs && node scripts/validate-publish.mjs && node scripts/validate-packed.mjs",
12
+ "validate": "node scripts/validate-skills.mjs && node scripts/validate-emit.mjs && node scripts/validate-install.mjs && node scripts/validate-criteria.mjs && node scripts/validate-state-classifier.mjs && node scripts/validate-hooks.mjs && node scripts/validate-acknowledged.mjs && node scripts/validate-layouts.mjs && node scripts/validate-divergences.mjs && node scripts/validate-frameworks.mjs && node scripts/validate-contained.mjs && node scripts/validate-publish.mjs && node scripts/validate-packed.mjs && node scripts/validate-brief.mjs && node scripts/validate-prior-art.mjs && node scripts/validate-plugin.mjs",
13
+ "eval:claude": "claude plugin eval . --trust-plugin --scaffold --model haiku --judge-model haiku --runs 1 --ablation none --threshold 0.8 --no-publish --max-cost-usd 1 --allow-tools Write Edit \"Bash(npm run build*)\" \"Bash(npx --no-install sws doctor *)\"",
13
14
  "check": "npm run validate && npm run sync-skills -- --check",
14
15
  "pack:all": "mkdir -p .pack && npm pack --pack-destination ./.pack && npm pack -w @su-sws/synthetic-web-team-mcp --pack-destination ./.pack"
15
16
  },
@@ -8,7 +8,7 @@
8
8
  // - A check that cannot run reports `unknown`, never `pass`.
9
9
 
10
10
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
11
- import { join, resolve, dirname, relative } from 'node:path';
11
+ import { join, resolve, dirname, relative, isAbsolute } from 'node:path';
12
12
  import { fileURLToPath } from 'node:url';
13
13
  import { parseArgs } from 'node:util';
14
14
  import YAML from 'yaml';
@@ -17,12 +17,13 @@ import { runAxe, RESULTS_PATH as AXE_RESULTS_PATH } from '../src/axe.mjs';
17
17
  import { runPerf, RESULTS_PATH as PERF_RESULTS_PATH } from '../src/perf.mjs';
18
18
  import { runStates, RESULTS_PATH as STATE_RESULTS_PATH } from '../src/states.mjs';
19
19
  import {
20
- score, renderTerminal, renderMarkdown, renderJson, group,
20
+ score, renderTerminal, renderMarkdown, renderJson, renderBrief, group,
21
21
  renderPrComment, renderIssueBody, renderHtml, renderBadge,
22
22
  } from '../src/report.mjs';
23
23
  import * as history from '../src/history.mjs';
24
24
  import * as gh from '../src/github.mjs';
25
- import { preflight, summarise } from '../src/preflight.mjs';
25
+ import { preflight, summarise, whichPackageManager } from '../src/preflight.mjs';
26
+ import { findCatalog, loadCatalog, search, findJson, findText } from '../src/prior-art.mjs';
26
27
  import { findStandards as locateStandards } from '../src/standards.mjs';
27
28
  import { loadAcknowledged, applyAcknowledgements, sha256 } from '../src/acknowledged.mjs';
28
29
  import { loadDivergences, applyDivergences } from '../src/divergences.mjs';
@@ -60,6 +61,9 @@ const { values: flags, positionals } = parseArgs({
60
61
  strict: { type: 'boolean', default: false },
61
62
  'no-summary': { type: 'boolean', default: false },
62
63
  'no-publish': { type: 'boolean', default: false },
64
+ 'no-history': { type: 'boolean', default: false },
65
+ json: { type: 'boolean', default: false },
66
+ limit: { type: 'string' },
63
67
  'html': { type: 'string' },
64
68
  'badge': { type: 'string' },
65
69
  help: { type: 'boolean', short: 'h', default: false },
@@ -69,14 +73,20 @@ const { values: flags, positionals } = parseArgs({
69
73
  const cmd = positionals[0] ?? 'doctor';
70
74
  const root = resolve(process.cwd());
71
75
 
72
- // With --format json, stdout is exactly one JSON document. Every other line --
73
- // the trend, publish confirmations, warnings -- goes to stderr.
76
+ // --json is shorthand for --format json, wherever --format json is understood.
77
+ // An explicit --format wins.
78
+ if (flags.json && flags.format === 'terminal') flags.format = 'json';
79
+
80
+ // With --format json or --format brief, stdout is exactly one JSON document.
81
+ // Every other line -- the trend, publish confirmations, warnings -- goes to
82
+ // stderr.
74
83
  //
75
84
  // This was a real bug: the trend line was appended to stdout after the JSON, so
76
85
  // `sws doctor --format json | jq` failed, and the MCP server's sws_check tool
77
86
  // reported "output that is not JSON" while looking at valid JSON with a
78
87
  // sentence stuck to the end of it. Machine-readable means machine-readable.
79
- const note = (...a) => (flags.format === 'json' ? console.error(...a) : console.log(...a));
88
+ const MACHINE = flags.format === 'json' || flags.format === 'brief';
89
+ const note = (...a) => (MACHINE ? console.error(...a) : console.log(...a));
80
90
 
81
91
  const USAGE = `
82
92
  sws <command>
@@ -100,17 +110,38 @@ const USAGE = `
100
110
  Print the sha256 of each value the secrets check matches in
101
111
  a file, to narrow an acknowledgement to one false positive.
102
112
  Local only: no report ever carries these hashes.
103
- prior-art scan Index Stanford projects on this machine. Never transmitted.
113
+ prior-art find <query>
114
+ Search the curated catalog of existing SWS work for
115
+ something like what you are about to build. Prints each
116
+ match with its era, its rating (a cautionary entry is
117
+ listed, and flagged), and what to use it for and not use it
118
+ for. Reads standards/prior-art/ in this project, else the
119
+ copy that ships with this CLI. Nothing found is an answer,
120
+ and it says so, with exit 0. --json for one JSON document,
121
+ --limit <n> for more than five results.
122
+ prior-art scan Index Stanford projects on this machine. Not built yet.
104
123
  version
105
124
 
106
125
  --dist <dir> Build output (default: auto-detect dist, _site, build, out)
107
126
  --standards <dir> Standards directory (default: auto-detect)
108
127
  --recipe <id> Recipe id (default: from .sws/manifest.yml, else astro-static)
109
- --format terminal | json | markdown
128
+ --format terminal | json | markdown | brief (--json means json)
129
+ brief is for an agent or a script that has to act on the
130
+ report: one line of JSON, a few kilobytes at most, with the
131
+ score, counts, the top failures (each with its fix and the
132
+ standards file to read), why the rest could not be checked,
133
+ manifest fields still holding placeholders, accepted risks
134
+ past their review date, and next[], the ordered steps to
135
+ take. Lists are cut to fit and dropped{} says by how much.
136
+ doctor and check only. Exit codes are unchanged.
110
137
  --out <file> Write the report to a file as well as stdout
111
138
  --strict Treat every failure as blocking. Opt-in, off by default.
112
139
  --no-summary Do not append to \$GITHUB_STEP_SUMMARY.
113
140
  --no-publish Do not write the PR comment or the Site health issue.
141
+ --no-history Do not record this run in .sws/score-history.json. For a
142
+ run nobody asked for, such as a hook or a script: it leaves
143
+ "since your last local run" meaning the last run a person
144
+ made, and writes no file into the project.
114
145
  --html <file> Also write a standalone HTML report.
115
146
  --badge <file> Write a shields.io endpoint JSON for a README badge.
116
147
 
@@ -231,6 +262,49 @@ function loadAcceptance(standards, recipeId, seen = new Set()) {
231
262
  };
232
263
  }
233
264
 
265
+ // --- facts for the brief format ---------------------------------------------
266
+ //
267
+ // What `--format brief` reports that is not a finding. Everything here is read
268
+ // from disk, never asked of the network, and nothing is written.
269
+
270
+ // Is this CLI reachable as `npx --no-install sws` from the project? npx looks
271
+ // in node_modules/.bin of the project and of each directory above it, which is
272
+ // how a workspace member finds a bin installed at the workspace root.
273
+ function localCli(dir) {
274
+ for (let d = dir; ; d = dirname(d)) {
275
+ if (existsSync(join(d, 'node_modules', '.bin', 'sws'))) return true;
276
+ if (dirname(d) === d) return false;
277
+ }
278
+ }
279
+
280
+ function briefFacts({ standards, manifest, html, ack, now }) {
281
+ // A path the reader can open from the project root: relative when the
282
+ // standards are inside the project, absolute when they are the copy that
283
+ // ships with this CLI.
284
+ const rel = relative(root, standards);
285
+ const inside = !rel.startsWith('..') && !isAbsolute(rel);
286
+ const shown = (p) => (inside ? relative(root, p) || '.' : p).split('\\').join('/');
287
+ let pkg = null;
288
+ try { pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')); } catch { /* no package.json */ }
289
+ const declared = { ...(pkg?.dependencies ?? {}), ...(pkg?.devDependencies ?? {}) };
290
+
291
+ return {
292
+ tool: OWN_VERSION,
293
+ projectVersion: readInstalled(root)?.version ?? null,
294
+ standards: shown(standards),
295
+ standardPath: (file) => (existsSync(join(standards, file)) ? shown(join(standards, file)) : null),
296
+ manifestPresent: existsSync(join(root, '.sws', 'manifest.yml')),
297
+ manifest,
298
+ ackEntries: ack,
299
+ now,
300
+ builtPages: html.length,
301
+ buildScript: Boolean(pkg?.scripts?.build),
302
+ packageManager: whichPackageManager(root),
303
+ localCli: localCli(root),
304
+ declaresPackage: '@su-sws/synthetic-web-team' in declared,
305
+ };
306
+ }
307
+
234
308
  // --- run --------------------------------------------------------------------
235
309
 
236
310
  async function run() {
@@ -345,7 +419,15 @@ async function run() {
345
419
  const blocking = findings.filter((f) => f.blocking && f.state === 'fail');
346
420
 
347
421
  const payload = { findings, sc, recipe: recipeId, blocking };
348
- const render = { json: renderJson, markdown: renderMarkdown, terminal: renderTerminal };
422
+ const render = {
423
+ json: renderJson, markdown: renderMarkdown, terminal: renderTerminal,
424
+ // The brief format needs what the findings do not carry: the criteria they
425
+ // came from, and facts about the project. Gathered only when asked for.
426
+ brief: (p) => renderBrief({
427
+ ...p, command: cmd, criteria: byId,
428
+ facts: briefFacts({ standards, manifest, html, ack, now }),
429
+ }),
430
+ };
349
431
  const text = (render[flags.format] ?? renderTerminal)(payload);
350
432
  console.log(text);
351
433
 
@@ -383,8 +465,13 @@ async function run() {
383
465
 
384
466
  // Local delta. Recorded for both commands, shown only by doctor: in CI the
385
467
  // shared trend is the meaningful one and two numbers would confuse.
468
+ //
469
+ // --no-history reads the history and does not add to it. A run nobody asked
470
+ // for (a hook at session start, a script in a loop) would otherwise move the
471
+ // "since your last local run" baseline out from under the person, and create
472
+ // a file in a project that has not ignored it.
386
473
  const localBefore = history.readLocal(root);
387
- history.appendLocal(root, entry);
474
+ if (!flags['no-history']) history.appendLocal(root, entry);
388
475
  if (cmd === 'doctor') {
389
476
  const t = history.trend(sc.value, localBefore);
390
477
  if (t) {
@@ -750,6 +837,70 @@ function runDigest() {
750
837
  return 0;
751
838
  }
752
839
 
840
+ // --- prior art --------------------------------------------------------------
841
+ // `find` searches the curated catalog: see src/prior-art.mjs for what a match
842
+ // does and does not mean. The catalog is located the way the standards are, in
843
+ // the project first and then beside this CLI, with one difference: a project
844
+ // whose own standards carry no prior-art directory falls through to the bundled
845
+ // copy rather than reporting nothing.
846
+
847
+ function runPriorArt() {
848
+ const sub = positionals[1];
849
+
850
+ if (sub === 'scan') {
851
+ console.log('prior-art scan is not implemented yet. It will index Stanford');
852
+ console.log('projects on this machine (metadata only) to .sws/prior-art.local.yml,');
853
+ console.log('which is gitignored and never transmitted.');
854
+ console.log('');
855
+ console.log('To search the curated catalog: sws prior-art find "<what you are building>"');
856
+ return 0;
857
+ }
858
+
859
+ const usage = 'Usage: sws prior-art find "<what you are building>" [--json] [--limit <n>]';
860
+ if (!sub) { console.log(usage); return 0; }
861
+ if (sub !== 'find') { console.error(usage); return 2; }
862
+
863
+ const query = positionals.slice(2).join(' ').trim();
864
+ if (!query) { console.error(usage); return 2; }
865
+
866
+ const bundled = resolve(HERE, '..', '..', '..', 'standards');
867
+ const dir = findCatalog(flags.standards
868
+ ? [resolve(flags.standards)]
869
+ : [join(root, '.sws', 'standards'), join(root, 'standards'), bundled]);
870
+ if (!dir) {
871
+ console.error('Could not find the prior-art catalog: looked in .sws/standards/prior-art/, '
872
+ + 'standards/prior-art/, and beside this CLI. Pass --standards <dir>.');
873
+ return 2;
874
+ }
875
+
876
+ const limit = Number.parseInt(flags.limit ?? '5', 10);
877
+ if (!Number.isInteger(limit) || limit < 1) {
878
+ console.error('--limit takes a whole number, 1 or more.');
879
+ return 2;
880
+ }
881
+
882
+ let catalog;
883
+ try { catalog = loadCatalog(dir); }
884
+ catch (err) {
885
+ console.error(`Could not read the prior-art catalog in ${dir}: ${err.message}`);
886
+ return 2;
887
+ }
888
+ const { entries, sources } = catalog;
889
+ const { terms, results, total } = search(entries, query, { limit });
890
+ if (!terms.length) {
891
+ console.error(`Nothing to search for in "${query}": every word is too common to tell one entry from another.`);
892
+ console.error('Name the thing: sws prior-art find "event listing", "faceted search", "giving form".');
893
+ return 2;
894
+ }
895
+
896
+ // Shown relative to the project when the catalog is inside it.
897
+ const rel = relative(root, dir);
898
+ const shownDir = (!rel.startsWith('..') && !isAbsolute(rel) ? rel : dir).split('\\').join('/');
899
+ const out = { query, dir: shownDir, sources, entries, terms, results, total };
900
+ console.log(flags.format === 'json' ? findJson(out) : findText(out));
901
+ return 0;
902
+ }
903
+
753
904
  // --- dispatch ---------------------------------------------------------------
754
905
 
755
906
  switch (cmd) {
@@ -770,10 +921,7 @@ switch (cmd) {
770
921
  process.exit(runDigest());
771
922
  break;
772
923
  case 'prior-art':
773
- console.log('prior-art scan is not implemented yet. It will index Stanford');
774
- console.log('projects on this machine (metadata only) to .sws/prior-art.local.yml,');
775
- console.log('which is gitignored and never transmitted.');
776
- process.exit(0);
924
+ process.exit(runPriorArt());
777
925
  break;
778
926
  case 'version':
779
927
  if (!OWN_VERSION) {
@@ -98,11 +98,16 @@ function covers(entry, loc) {
98
98
  return true;
99
99
  }
100
100
 
101
+ // Past its review date. One definition: the note in a finding's detail and the
102
+ // list in the brief format both read it, so they cannot disagree about a date.
103
+ export const isOverdue = (entry, now = new Date()) =>
104
+ Boolean(entry?.review_by) && new Date(entry.review_by) < now;
105
+
101
106
  function acceptedBy(entries, now) {
102
107
  const by = [...new Set(entries.map((a) => a.accepted_by ?? 'unknown'))].join(', ');
103
108
  const reasons = [...new Set(entries.map((a) => a.reason).filter(Boolean))];
104
109
  let note = `accepted by ${by}${reasons.length === 1 ? `: ${reasons[0]}` : ''}`;
105
- const overdue = entries.map((a) => a.review_by).filter((d) => d && new Date(d) < now).sort();
110
+ const overdue = entries.filter((a) => isOverdue(a, now)).map((a) => a.review_by).sort();
106
111
  if (overdue.length) note += ` [review overdue since ${overdue[0]}]`;
107
112
  return note;
108
113
  }