@su-sws/synthetic-web-team 0.2.4 → 0.2.5

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
@@ -100,6 +100,14 @@ your `devDependencies`, so that `npx sws` afterwards runs this CLI. Unscoped
100
100
  `sws` on the public registry is an unrelated package, and without the local
101
101
  dependency that is what you would get.
102
102
 
103
+ **Or keep it all in `.sws/`.** Some teams keep SWS apart from their own files.
104
+ For them, `add . --layout contained` writes nothing outside `.sws/`: the
105
+ contract is `.sws/AGENTS.md`, a file of its own, and no editor pointer, MCP
106
+ config or `package.json` is touched. Nothing reads the contract until you point
107
+ your own `AGENTS.md` at it, and `next[]` says so. Add the devDependency yourself
108
+ if you want `npx sws`. The install record remembers the layout, so a plain
109
+ `add .` updates it in place, and `--layout root` switches back.
110
+
103
111
  ### Or drive the installer yourself
104
112
 
105
113
  **The primary caller is an agent, so that is the first-class path.** One command,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-sws/synthetic-web-team",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
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,7 @@
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",
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",
13
13
  "check": "npm run validate && npm run sync-skills -- --check",
14
14
  "pack:all": "mkdir -p .pack && npm pack --pack-destination ./.pack && npm pack -w @su-sws/synthetic-web-team-mcp --pack-destination ./.pack"
15
15
  },
@@ -15,7 +15,10 @@ import { fileURLToPath } from 'node:url';
15
15
  import { parseArgs } from 'node:util';
16
16
  import { createInterface } from 'node:readline/promises';
17
17
  import { detect, deriveTier } from '../src/detect.mjs';
18
- import { plan, write, remove, ensureDevDependency, plannedMigration, STANDARDS_DIR } from '../src/emit.mjs';
18
+ import {
19
+ plan, write, remove, ensureDevDependency, plannedMigration, readInstalled,
20
+ STANDARDS_DIR, LAYOUTS, CONTAINED_CONTRACT,
21
+ } from '../src/emit.mjs';
19
22
 
20
23
  const HERE = dirname(fileURLToPath(import.meta.url));
21
24
 
@@ -30,6 +33,7 @@ const { values: flags, positionals } = parseArgs({
30
33
  json: { type: 'boolean', default: false },
31
34
  interactive: { type: 'boolean', default: false },
32
35
  force: { type: 'boolean', default: false },
36
+ layout: { type: 'string' },
33
37
  remove: { type: 'boolean', default: false },
34
38
  help: { type: 'boolean', short: 'h', default: false },
35
39
  },
@@ -143,6 +147,11 @@ const HELP = `
143
147
  --interactive Force prompts even without a TTY.
144
148
  --force Overwrite files you have edited locally. Off by default.
145
149
  --dry-run Report what would be written, write nothing.
150
+ --layout <name> Where 'init' and 'add' write. root (the default): the
151
+ contract into AGENTS.md, plus a pointer for each editor and
152
+ the devDependency. contained: nothing outside .sws/; the
153
+ contract is .sws/AGENTS.md, and you point your own files at
154
+ it. Remembered in .sws/installed.json, so a re-run keeps it.
146
155
  --remove Uninstall. Valid with 'install' only. Deletes just the files the
147
156
  install record lists, so unrelated skills in your skills
148
157
  directories are never touched, and a file you edited is kept
@@ -159,7 +168,7 @@ const HELP = `
159
168
  every run until it matches again. .sws/installed.json records what was written
160
169
  so an edit can be told from an old version. Pass --force to discard your edits.
161
170
  A project with standards/ at its root from an earlier version has them moved
162
- into .sws/standards/, edits and all.
171
+ into .sws/standards/, edits and all. A contained project stays contained.
163
172
 
164
173
  An editor install and a project install carry their own versions, so they can
165
174
  drift. 'sws doctor' reports the difference as a note rather than a finding:
@@ -301,6 +310,20 @@ if (!source) {
301
310
  'Expected it beside this tool, or in the current directory. Pass --source <dir>.');
302
311
  }
303
312
 
313
+ // The layout: the flag, else what the install record says this project chose,
314
+ // else root. Remembering it is what lets a contained project update with a
315
+ // plain `add .`; forgetting it would write AGENTS.md on the next update.
316
+ const layout = flags.layout ?? (mode === 'user' ? null : readInstalled(root)?.layout) ?? 'root';
317
+ if (flags.layout !== undefined && mode === 'user') {
318
+ die(2, '--layout applies to init and add', "'install' writes skills into your editor and nothing per-site.");
319
+ }
320
+ if (!LAYOUTS.includes(layout)) {
321
+ die(2, `unknown --layout: ${layout}`,
322
+ 'Expected root (the contract in AGENTS.md, and a pointer for each editor) or contained (nothing outside .sws/).');
323
+ }
324
+ const contained = layout === 'contained';
325
+ const contractPath = contained ? CONTAINED_CONTRACT : 'AGENTS.md';
326
+
304
327
  const B = (s) => (process.stdout.isTTY ? `\x1b[1m${s}\x1b[0m` : s);
305
328
  const D = (s) => (process.stdout.isTTY ? `\x1b[2m${s}\x1b[0m` : s);
306
329
 
@@ -571,9 +594,15 @@ function emitJson({ written, write: wr }) {
571
594
 
572
595
  const next = [];
573
596
  next.push({
574
- kind: 'read-contract', path: 'AGENTS.md',
597
+ kind: 'read-contract', path: contractPath,
575
598
  why: 'The behavioral contract. Read it before doing anything else in this project.',
576
599
  });
600
+ if (contained) {
601
+ next.push({
602
+ kind: 'point-to-contract', path: CONTAINED_CONTRACT,
603
+ why: 'Nothing outside .sws/ was written, so no tool reads the contract yet. Point your own AGENTS.md, or your editor\'s instructions, at .sws/AGENTS.md.',
604
+ });
605
+ }
577
606
  // A move held back because the project's code reads the old path. Early in
578
607
  // the list: until those references change, the layout cannot finish.
579
608
  const held = wr ? wr.deferred : migration.deferred;
@@ -599,7 +628,7 @@ function emitJson({ written, write: wr }) {
599
628
  why: 'These are placeholders, not answers. MinWeb requires a named business owner and technical administrator with valid Stanford email. Ask the user; do not invent them.',
600
629
  });
601
630
  }
602
- if (chosen.some((e) => e.emits.some((x) => x.endsWith('mcp.json')))) {
631
+ if (!contained && chosen.some((e) => e.emits.some((x) => x.endsWith('mcp.json')))) {
603
632
  next.push({
604
633
  kind: 'optional-mcp', command: 'npx -y @su-sws/synthetic-web-team-mcp --help',
605
634
  why: `An MCP server for these standards was added to your client config. It is a second entry point, never a requirement: sws_get_standard, sws_footer_html, sws_check, sws_decanter_token, sws_scaffold. Everything it exposes is also a file under ${STANDARDS_DIR}/. It was added next to any servers you already had. Remove the entry if you do not want it, and later updates will leave it out.`,
@@ -616,7 +645,9 @@ function emitJson({ written, write: wr }) {
616
645
  } else {
617
646
  next.push({
618
647
  kind: 'add-dependency', command: `npm install -D ${DEP_NAME}`,
619
- why: `Do this once the project has a package.json. Without the local dependency \`npx sws\` fetches the unrelated \`sws\` package from the public registry rather than this CLI.`,
648
+ why: contained
649
+ ? `The contained layout leaves package.json alone. Add it yourself if you want \`npx sws\`: without the local dependency it fetches the unrelated \`sws\` package from the public registry rather than this CLI.`
650
+ : `Do this once the project has a package.json. Without the local dependency \`npx sws\` fetches the unrelated \`sws\` package from the public registry rather than this CLI.`,
620
651
  });
621
652
  }
622
653
  next.push({
@@ -636,6 +667,7 @@ function emitJson({ written, write: wr }) {
636
667
  warnings: versionWarning ? [versionWarning] : [],
637
668
  previousVersion: wr?.previousVersion ?? null,
638
669
  mode: mode === 'add' ? 'add' : 'init',
670
+ layout,
639
671
  written,
640
672
  root,
641
673
  source,
@@ -681,7 +713,7 @@ if (tier.tier !== 'low') {
681
713
 
682
714
  // --- review, then write -----------------------------------------------------
683
715
 
684
- const files = plan({ root, source, editors: chosen, answers, tier });
716
+ const files = plan({ root, source, editors: chosen, answers, tier, layout });
685
717
 
686
718
  // Always 0 at project scope, and kept in the JSON counts so the schema holds.
687
719
  // Not printed: a project holds no skills, and the line that used to be here
@@ -706,6 +738,7 @@ if (migration.deferred) {
706
738
 
707
739
  if (flags['dry-run']) {
708
740
  depResult = ensureDevDependency(root, { name: DEP_NAME, range: depRange, dryRun: true });
741
+ if (contained && depResult.status === 'would-add') depResult = { status: 'not-added', range: depRange, reason: 'contained' };
709
742
  say(`\n ${D('Dry run. Nothing written.')}\n`);
710
743
  if (flags.json) emitJson({ written: false, write: null });
711
744
  process.exit(0);
@@ -723,8 +756,10 @@ if (interactive) {
723
756
  }
724
757
  }
725
758
 
726
- const result = write(root, files, { force: flags.force, version: contentVersion });
727
- depResult = ensureDevDependency(root, { name: DEP_NAME, range: depRange });
759
+ const result = write(root, files, { force: flags.force, version: contentVersion, layout });
760
+ // Contained never writes package.json. An existing declaration is still reported.
761
+ depResult = ensureDevDependency(root, { name: DEP_NAME, range: depRange, dryRun: contained });
762
+ if (contained && depResult.status === 'would-add') depResult = { status: 'not-added', range: depRange, reason: 'contained' };
728
763
 
729
764
  // Say what actually changed, not how many files were considered. On a re-run
730
765
  // this reads "nothing to do", which is the truth and what a caller should
@@ -803,6 +838,12 @@ if (result.orphans.length) {
803
838
  say('');
804
839
  }
805
840
 
841
+ if (contained) {
842
+ say(` ${B('Contained:')} ${D('nothing outside .sws/ was written. Point your own AGENTS.md at')}`);
843
+ say(` ${D(`${CONTAINED_CONTRACT} so agents read the contract.`)}`);
844
+ say('');
845
+ }
846
+
806
847
  // The dependency decides whether `npx sws` runs this CLI or an unrelated
807
848
  // package of the same name off the public registry, so it is reported, never
808
849
  // silent -- either way round.
@@ -820,6 +861,10 @@ if (depResult.status === 'added') {
820
861
  say(` ${B('Could not read package.json:')} ${D(depResult.detail)}`);
821
862
  say(` ${D('Left alone. Add ' + DEP_NAME + ' to devDependencies yourself.')}`);
822
863
  say('');
864
+ } else if (depResult.status === 'not-added') {
865
+ say(` ${B('package.json left alone,')} ${D('as the contained layout does. Add ' + DEP_NAME)}`);
866
+ say(` ${D('to devDependencies yourself if you want `npx sws` to run this CLI.')}`);
867
+ say('');
823
868
  } else if (depResult.status === 'skipped-unknown-version') {
824
869
  say(` ${B('No version to pin,')} ${D('so package.json was left alone. Add')}`);
825
870
  say(` ${D(DEP_NAME + ' to devDependencies yourself.')}`);
@@ -28,6 +28,16 @@ import { join, dirname, resolve, sep } from 'node:path';
28
28
  // Where a project's vendored standards live.
29
29
  export const STANDARDS_DIR = '.sws/standards';
30
30
 
31
+ // Where the project's SWS files go. `root`, the default, merges the contract
32
+ // into the project's AGENTS.md and adds a pointer for each editor. `contained`
33
+ // writes nothing outside .sws/: the contract is .sws/AGENTS.md, a file of its
34
+ // own, and no editor pointer, MCP config or package.json is touched. It is for
35
+ // a team that keeps SWS separate from its own files and points its AGENTS.md
36
+ // at .sws/AGENTS.md itself. The install record remembers the layout, so a
37
+ // plain re-run of `add .` keeps it.
38
+ export const LAYOUTS = ['root', 'contained'];
39
+ export const CONTAINED_CONTRACT = '.sws/AGENTS.md';
40
+
31
41
  // Layouts an earlier version wrote, and where those files live now. A re-run
32
42
  // moves every file the install record lists; see migrate().
33
43
  const MOVED = [['standards/', `${STANDARDS_DIR}/`]];
@@ -67,7 +77,7 @@ export const SKILL_TARGETS = ['.agents/skills', '.claude/skills'];
67
77
  const skillNames = (source) => readdirSync(join(source, 'skills'))
68
78
  .filter((d) => existsSync(join(source, 'skills', d, 'SKILL.md')));
69
79
 
70
- export function plan({ root, source, editors, answers, tier, scope = 'project' }) {
80
+ export function plan({ root, source, editors, answers, tier, scope = 'project', layout = 'root' }) {
71
81
  const files = [];
72
82
  const add = (path, contents, note, opts = {}) => files.push({ path, contents, note, ...opts });
73
83
 
@@ -95,11 +105,18 @@ export function plan({ root, source, editors, answers, tier, scope = 'project' }
95
105
  // they are byte-identical in every repository and referencing them in place is
96
106
  // not available: most editors that read .agents/skills offer no configurable
97
107
  // path to redirect. See docs/skill-paths.md and docs/two-part-install.md.
98
- add('AGENTS.md', contract(source),
99
- 'behavioral contract, between markers; the rest of the file is yours', {
100
- merge: 'block', markers: [CONTRACT_BEGIN, CONTRACT_END], legacyHeading: LEGACY_CONTRACT_HEADING,
101
- adds: 'the contract, between sws-agent-contract markers',
102
- });
108
+ const contained = layout === 'contained';
109
+ if (contained) {
110
+ const text = contract(source);
111
+ add(CONTAINED_CONTRACT, text.endsWith('\n') ? text : `${text}\n`,
112
+ 'behavioral contract; nothing outside .sws/ is written, so point your AGENTS.md here');
113
+ } else {
114
+ add('AGENTS.md', contract(source),
115
+ 'behavioral contract, between markers; the rest of the file is yours', {
116
+ merge: 'block', markers: [CONTRACT_BEGIN, CONTRACT_END], legacyHeading: LEGACY_CONTRACT_HEADING,
117
+ adds: 'the contract, between sws-agent-contract markers',
118
+ });
119
+ }
103
120
 
104
121
  const skills = skillNames(source);
105
122
 
@@ -136,7 +153,9 @@ export function plan({ root, source, editors, answers, tier, scope = 'project' }
136
153
  // Most of these are files a project may already have for its own reasons,
137
154
  // so they are ADDED TO, never written: see SHARED. Only the rules files under
138
155
  // our own name (.cursor/rules/sws.mdc, .devin/rules/sws.md) are whole files.
139
- for (const e of editors) {
156
+ //
157
+ // None in the contained layout: every one of them lives outside .sws/.
158
+ for (const e of contained ? [] : editors) {
140
159
  for (const f of e.emits) {
141
160
  if (files.some((x) => x.path === f)) continue;
142
161
  if (SHARED[f]) {
@@ -443,7 +462,7 @@ const ACKNOWLEDGED_TEMPLATE = `# Accepted risks.
443
462
  * and writing the import through it would replace the contract with a line that
444
463
  * imports itself.
445
464
  */
446
- export function write(root, files, { force = false, version = null, scope = 'project' } = {}) {
465
+ export function write(root, files, { force = false, version = null, scope = 'project', layout = 'root' } = {}) {
447
466
  const prev = readInstalled(root);
448
467
  let planned = new Set(files.map((f) => f.path));
449
468
 
@@ -574,7 +593,7 @@ export function write(root, files, { force = false, version = null, scope = 'pro
574
593
  // when it has been seen once.
575
594
  for (const x of orphans) nextHashes[x] = prev.files[x];
576
595
 
577
- writeInstalled(root, { version, files: nextHashes, scope });
596
+ writeInstalled(root, { version, files: nextHashes, scope, layout });
578
597
 
579
598
  const count = (s) => results.filter((r) => r.status === s).length;
580
599
  return {
@@ -1036,7 +1055,7 @@ export function readInstalled(root) {
1036
1055
  }
1037
1056
  }
1038
1057
 
1039
- function writeInstalled(root, { version, files, scope = 'project' }) {
1058
+ function writeInstalled(root, { version, files, scope = 'project', layout = 'root' }) {
1040
1059
  // The advice differs by scope, and getting it wrong matters: "commit this" is
1041
1060
  // right in a repository and nonsense in a home directory.
1042
1061
  const advice = scope === 'user'
@@ -1051,6 +1070,8 @@ function writeInstalled(root, { version, files, scope = 'project' }) {
1051
1070
  + `re-install can tell an update from a local edit. ${advice}`,
1052
1071
  tool: '@su-sws/synthetic-web-team',
1053
1072
  scope,
1073
+ // Only when it is not the default, so a root install's record is unchanged.
1074
+ ...(layout === 'contained' ? { layout } : {}),
1054
1075
  version,
1055
1076
  at: new Date().toISOString(),
1056
1077
  files,
@@ -50,6 +50,16 @@ So: knowledge installs once per tool, the record installs once per site.
50
50
  Nothing else goes at the root, and nothing goes in `.claude/`: many teams
51
51
  git-ignore it, so a committed file pointing there breaks for everyone else.
52
52
 
53
+ **The contained layout writes only the `.sws/` rows.** `add . --layout contained`
54
+ is for a team that keeps SWS apart from its own files. The contract is
55
+ `.sws/AGENTS.md` instead of a block in `AGENTS.md`, and there are no editor
56
+ pointers, no MCP configs and no `package.json` change: an existing devDependency
57
+ is reported as `present`, a missing one as `not-added`. `.sws/installed.json`
58
+ records `"layout": "contained"`, so a plain `add .` keeps it; `--layout root`
59
+ switches back. Use it only when the person asks. Afterwards, `next[]` has a
60
+ `point-to-contract` step: the project points its own `AGENTS.md` at
61
+ `.sws/AGENTS.md`. Suggest the line; don't write it, because that file is theirs.
62
+
53
63
  **No skills.** If you find `.agents/skills/` or `.claude/skills/` inside a
54
64
  project, it predates the two-part install. That is not a fault and nothing
55
65
  breaks, but the copies there are frozen and the user-level ones are what update.
@@ -76,6 +76,9 @@ Listed so the recipe covers them.
76
76
  `@AGENTS.md` if it lacks it, and the `sws` server joins the project's own MCP
77
77
  servers. Scripts that a committed file calls belong in `scripts/`, not in
78
78
  `.claude/`, which many teams git-ignore.
79
+ - **A team that keeps SWS apart from its own files.** `add . --layout contained`
80
+ writes only into `.sws/`, with the contract at `.sws/AGENTS.md`, and a re-run
81
+ keeps that layout. The team points its own `AGENTS.md` at it.
79
82
 
80
83
  ## What to do now
81
84