@su-sws/synthetic-web-team 0.1.2 → 0.2.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.
@@ -15,7 +15,7 @@ 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 } from '../src/emit.mjs';
18
+ import { plan, write, remove, ensureDevDependency, plannedMigration, STANDARDS_DIR } from '../src/emit.mjs';
19
19
 
20
20
  const HERE = dirname(fileURLToPath(import.meta.url));
21
21
 
@@ -108,13 +108,16 @@ const HELP = `
108
108
  init a new site, in an empty directory
109
109
  add an existing project, in its root
110
110
 
111
- 'install' writes the 30 skills into ~/.claude/skills and ~/.agents/skills and
111
+ 'install' writes the 31 skills into ~/.claude/skills and ~/.agents/skills and
112
112
  nothing else: no standards, no AGENTS.md, nothing per-site, because at that
113
113
  point there is no site. Undo it with 'install --remove'.
114
114
 
115
- 'init' and 'add' write AGENTS.md, the standards, and the per-site record
116
- (owners, compliance tier, divergences, accepted risks) into one repository,
117
- and no skills, because those are installed once for every project. 'init'
115
+ 'init' and 'add' write the contract into AGENTS.md, and the standards and the
116
+ per-site record (owners, compliance tier, divergences, accepted risks) into
117
+ .sws/, and no skills, because those are installed once for every project.
118
+ An existing AGENTS.md, CLAUDE.md or MCP config keeps its content: the
119
+ contract goes between markers, CLAUDE.md only needs the line @AGENTS.md, and
120
+ the sws server is added next to the servers already there. 'init'
118
121
  additionally hands back the recipe to follow to build the pages; 'add' assumes
119
122
  you already have a site and leaves your source alone.
120
123
 
@@ -155,6 +158,8 @@ const HELP = `
155
158
  and any file you edited yourself is reported as a conflict and left alone on
156
159
  every run until it matches again. .sws/installed.json records what was written
157
160
  so an edit can be told from an old version. Pass --force to discard your edits.
161
+ A project with standards/ at its root from an earlier version has them moved
162
+ into .sws/standards/, edits and all.
158
163
 
159
164
  An editor install and a project install carry their own versions, so they can
160
165
  drift. 'sws doctor' reports the difference as a note rather than a finding:
@@ -423,9 +428,20 @@ if (mode === 'user') {
423
428
  }
424
429
 
425
430
  if (wr.conflicts.length) {
426
- say(` ${B('Left alone because you edited them:')}`);
427
- for (const c of wr.conflicts) say(` ${c}`);
428
- say(` ${D('Re-run with --force to take the new versions and discard your edits.')}`);
431
+ // A link is never written through, and --force does not change that, so it
432
+ // must not be listed as an edit that --force would discard.
433
+ const linked = new Set(wr.results.filter((r) => r.reason === 'symlink').map((r) => r.path));
434
+ const edited = wr.conflicts.filter((c) => !linked.has(c));
435
+ if (edited.length) {
436
+ say(` ${B('Left alone because you edited them:')}`);
437
+ for (const c of edited) say(` ${c}`);
438
+ say(` ${D('Re-run with --force to take the new versions and discard your edits.')}`);
439
+ }
440
+ if (linked.size) {
441
+ say(` ${B('Left alone because they are symbolic links:')}`);
442
+ for (const c of linked) say(` ${c}`);
443
+ say(` ${D('Nothing is written through a link, with or without --force.')}`);
444
+ }
429
445
  say('');
430
446
  }
431
447
 
@@ -525,8 +541,8 @@ if (interactive && !flags.editors) {
525
541
  }
526
542
 
527
543
  if (!chosen.length) {
528
- console.log(`\n ${D('No editors selected. The universal core still works everywhere:')}`);
529
- console.log(` ${D('AGENTS.md plus .agents/skills and .claude/skills.')}`);
544
+ say(`\n ${D('No editors selected. AGENTS.md still works in every tool that reads it,')}`);
545
+ say(` ${D('and the skills come from the once-per-machine install.')}`);
530
546
  }
531
547
 
532
548
  // --- the machine-readable result --------------------------------------------
@@ -536,7 +552,7 @@ if (!chosen.length) {
536
552
  //
537
553
  // `next` is DATA, not prose. The caller of this tool is an agent whose whole
538
554
  // reason for installing is to then act, and "Hand your agent
539
- // standards/recipes/astro-static/RECIPE.md" is a sentence a robot has to parse
555
+ // .sws/standards/recipes/astro-static/RECIPE.md" is a sentence a robot has to parse
540
556
  // out of decorated terminal output. Each step names a kind, a path or command,
541
557
  // and why — so the agent can pick the one it is able to do.
542
558
  //
@@ -558,13 +574,22 @@ function emitJson({ written, write: wr }) {
558
574
  kind: 'read-contract', path: 'AGENTS.md',
559
575
  why: 'The behavioral contract. Read it before doing anything else in this project.',
560
576
  });
577
+ // A move held back because the project's code reads the old path. Early in
578
+ // the list: until those references change, the layout cannot finish.
579
+ const held = wr ? wr.deferred : migration.deferred;
580
+ if (held) {
581
+ next.push({
582
+ kind: 'update-references', from: held.from, to: held.to, references: held.references,
583
+ why: `These read the standards at ${held.from}, so the ${held.files} files there were not moved: moving them would break the next build. Change each to ${held.to} and run add . again; the files move then. --force moves them now regardless.`,
584
+ });
585
+ }
561
586
  next.push({
562
587
  kind: 'orient', skill: 'sws-onboard',
563
588
  why: 'Reads .sws/manifest.yml and states the stack, tier, and decisions already made.',
564
589
  });
565
590
  if (mode === 'new') {
566
591
  next.push({
567
- kind: 'follow-recipe', path: `standards/recipes/${answers.recipe}/RECIPE.md`,
592
+ kind: 'follow-recipe', path: `${STANDARDS_DIR}/recipes/${answers.recipe}/RECIPE.md`,
568
593
  why: 'The build contract, with acceptance criteria. Follow it rather than improvising.',
569
594
  });
570
595
  }
@@ -577,7 +602,7 @@ function emitJson({ written, write: wr }) {
577
602
  if (chosen.some((e) => e.emits.some((x) => x.endsWith('mcp.json')))) {
578
603
  next.push({
579
604
  kind: 'optional-mcp', command: 'npx -y @su-sws/synthetic-web-team-mcp --help',
580
- 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/. Remove the entry if you do not want it.',
605
+ 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.`,
581
606
  });
582
607
  }
583
608
  // `npx sws` has to resolve to node_modules/.bin/sws. Unscoped `sws` on the
@@ -624,7 +649,8 @@ function emitJson({ written, write: wr }) {
624
649
  standards: stdCount,
625
650
  ...(wr ? {
626
651
  created: wr.created, updated: wr.updated, unchanged: wr.unchanged,
627
- preserved: wr.preserved, conflicts: wr.conflicts.length,
652
+ preserved: wr.preserved, merged: wr.merged, moved: wr.moved.length,
653
+ conflicts: wr.conflicts.length,
628
654
  } : {}),
629
655
  },
630
656
  files: wr ? wr.results : files.map((x) => ({ path: x.path, status: 'planned' })),
@@ -632,6 +658,10 @@ function emitJson({ written, write: wr }) {
632
658
  dependency: { name: DEP_NAME, range: depRange, ...depResult },
633
659
  conflicts: wr?.conflicts ?? [],
634
660
  orphans: wr?.orphans ?? [],
661
+ // On a dry run, what WOULD move. Always { from, to }.
662
+ moved: wr ? wr.moved : migration.moved,
663
+ // A move held back, with the references that hold it. null when there is none.
664
+ deferred: wr ? wr.deferred : migration.deferred,
635
665
  next,
636
666
  notes: [
637
667
  'Everything is advisory except committed credentials, which are the one blocking check.',
@@ -646,23 +676,33 @@ say(`\n ${B('Compliance tier: ' + tier.tier.toUpperCase())} ${D('because ' + t
646
676
  for (const a of tier.adds) say(` ${D('·')} ${a}`);
647
677
  if (tier.tier !== 'low') {
648
678
  say(`\n ${B('This is above a basic static site.')} ${D('A Data Risk Assessment may be')}`);
649
- say(` ${D('required before deploy. Route to UIT Security: standards/policy/escalation.md')}`);
679
+ say(` ${D(`required before deploy. Route to UIT Security: ${STANDARDS_DIR}/policy/escalation.md`)}`);
650
680
  }
651
681
 
652
682
  // --- review, then write -----------------------------------------------------
653
683
 
654
684
  const files = plan({ root, source, editors: chosen, answers, tier });
655
685
 
686
+ // Always 0 at project scope, and kept in the JSON counts so the schema holds.
687
+ // Not printed: a project holds no skills, and the line that used to be here
688
+ // named .claude/skills, which a project install never writes.
656
689
  const skillCount = files.filter((f) => f.path.endsWith('SKILL.md')).length;
657
- const stdCount = files.filter((f) => f.path.startsWith('standards/')).length;
658
- const shown = files.filter((f) => !f.path.endsWith('SKILL.md') && !f.path.startsWith('standards/'));
690
+ const stdCount = files.filter((f) => f.path.startsWith(`${STANDARDS_DIR}/`)).length;
691
+ const shown = files.filter((f) => !f.path.endsWith('SKILL.md') && !f.path.startsWith(`${STANDARDS_DIR}/`));
692
+ const migration = plannedMigration(root, files, { force: flags.force });
659
693
 
660
694
  say(`\n ${B('Files to write')} ${D(root)}\n`);
661
695
  for (const f of shown) {
662
696
  say(` ${f.path}${f.note ? D(' ' + f.note) : ''}`);
663
697
  }
664
- say(` ${D(`+ ${skillCount} skill files across .agents/skills and .claude/skills`)}`);
665
- say(` ${D(`+ ${stdCount} files under standards/`)}`);
698
+ if (migration.deferred) {
699
+ say(` ${D(`+ ${stdCount} files under standards/, where they are now (the move to ${STANDARDS_DIR}/ waits, see below)`)}`);
700
+ } else {
701
+ say(` ${D(`+ ${stdCount} files under ${STANDARDS_DIR}/`)}`);
702
+ if (migration.moved.length) {
703
+ say(` ${D(`${migration.moved.length} of them move there from standards/ at the root, where an earlier version put them`)}`);
704
+ }
705
+ }
666
706
 
667
707
  if (flags['dry-run']) {
668
708
  depResult = ensureDevDependency(root, { name: DEP_NAME, range: depRange, dryRun: true });
@@ -689,23 +729,71 @@ depResult = ensureDevDependency(root, { name: DEP_NAME, range: depRange });
689
729
  // Say what actually changed, not how many files were considered. On a re-run
690
730
  // this reads "nothing to do", which is the truth and what a caller should
691
731
  // report onward.
692
- if (result.created === 0 && result.updated === 0) {
732
+ if (result.created === 0 && result.updated === 0 && result.merged === 0 && result.moved.length === 0) {
693
733
  say(`\n ${B('Already installed.')} ${result.unchanged + result.preserved} files, nothing to change.\n`);
694
734
  } else {
695
735
  const parts = [];
696
736
  if (result.created) parts.push(`${result.created} created`);
697
737
  if (result.updated) parts.push(`${result.updated} updated`);
738
+ if (result.merged) parts.push(`${result.merged} merged into your own`);
698
739
  if (result.unchanged) parts.push(`${result.unchanged} unchanged`);
699
740
  if (result.preserved) parts.push(`${result.preserved} preserved`);
700
741
  if (result.conflicts.length) parts.push(`${result.conflicts.length} left alone`);
701
742
  say(`\n ${B('Done.')} ${parts.join(', ')}.\n`);
702
743
  }
703
744
 
745
+ if (result.moved.length) {
746
+ say(` ${B(`Moved ${result.moved.length} file(s) from standards/ to ${STANDARDS_DIR}/.`)}`);
747
+ say(` ${D('Everything this tool installs now lives under .sws/, so the root of the')}`);
748
+ say(` ${D('repository is yours. Edits came along and are still reported below.')}`);
749
+ say('');
750
+ }
751
+
752
+ if (result.deferred) {
753
+ const d = result.deferred;
754
+ say(` ${B(`Not moved yet: ${d.files} file(s) stay in ${d.from} this run.`)}`);
755
+ say(` ${D('Your project reads them there, and moving them would break its next build:')}`);
756
+ for (const r of d.references.slice(0, 10)) say(` ${r.file}${r.line ? `:${r.line}` : ''} ${D(r.text)}`);
757
+ if (d.references.length > 10) say(` ${D(`and ${d.references.length - 10} more, listed in the --json result`)}`);
758
+ say(` ${D(`Point these at ${d.to} and run add . again: the files move then.`)}`);
759
+ say(` ${D('They are kept current where they are. --force moves them now regardless.')}`);
760
+ say('');
761
+ }
762
+
763
+ // Merged files, so nobody is surprised by a diff in a file they think of as theirs.
764
+ const merged = result.results.filter((r) => r.status === 'merged');
765
+ if (merged.length) {
766
+ const adds = new Map(files.map((f) => [f.path, f.adds]));
767
+ say(` ${B('Added to your own file, the rest left as it was:')}`);
768
+ for (const m of merged) say(` ${m.path} ${D(adds.get(m.path) ?? '')}`);
769
+ say('');
770
+ }
771
+
704
772
  // Conflicts and orphans, before the next steps: they need a decision.
705
773
  if (result.conflicts.length) {
706
- say(` ${B('Left alone because you edited them:')}`);
707
- for (const c of result.conflicts) say(` ${c}`);
708
- say(` ${D('Re-run with --force to take the new versions and discard your edits.')}`);
774
+ const why = new Map(result.results.filter((r) => r.status === 'conflict').map((r) => [r.path, r.reason]));
775
+ say(` ${B('Left alone:')}`);
776
+ for (const c of result.conflicts) {
777
+ const r = why.get(c);
778
+ if (r === 'legacy-contract') {
779
+ say(` ${c} ${D('holds an older copy of the contract with no markers, next to other')}`);
780
+ say(` ${' '.repeat(c.length)} ${D('content, so nothing says where ours ends. Delete that copy (from')}`);
781
+ say(` ${' '.repeat(c.length)} ${D('"# Stanford Web Services: agent contract" to the end of it), keep your')}`);
782
+ say(` ${' '.repeat(c.length)} ${D('own rules, and re-run: the contract goes back in between markers.')}`);
783
+ say(` ${' '.repeat(c.length)} ${D('--force replaces from that heading to the next top-level heading.')}`);
784
+ } else if (r === 'symlink') {
785
+ say(` ${c} ${D('is a symbolic link, and nothing is written through one.')}`);
786
+ } else if (r === 'outside') {
787
+ say(` ${c} ${D('sits under a directory that links out of the project, so nothing was written.')}`);
788
+ } else if (r === 'unparseable') {
789
+ say(` ${c} ${D('is not plain JSON (comments, perhaps), so the sws server was not added.')}`);
790
+ say(` ${' '.repeat(c.length)} ${D('Writing it back would strip them. Add the server yourself if you want it.')}`);
791
+ } else {
792
+ say(` ${c} ${D('you edited it')}`);
793
+ }
794
+ }
795
+ say(` ${D('--force takes the new versions and discards your edits, for EVERY file listed')}`);
796
+ say(` ${D('here at once. Resolve the ones you want to keep first.')}`);
709
797
  say('');
710
798
  }
711
799
  if (result.orphans.length) {
@@ -748,7 +836,7 @@ say(` ${B('Next')}`);
748
836
  let stepNo = 0;
749
837
  const step = () => ++stepNo;
750
838
  if (mode === 'new') {
751
- say(` ${step()}. Scaffold the site. Hand your agent standards/recipes/${answers.recipe}/RECIPE.md,`);
839
+ say(` ${step()}. Scaffold the site. Hand your agent ${STANDARDS_DIR}/recipes/${answers.recipe}/RECIPE.md,`);
752
840
  say(` ${D('or run the upstream scaffolder yourself: npm create astro@latest')}`);
753
841
  }
754
842
  if (depResult.status === 'added' || depResult.status === 'present') {