@su-sws/synthetic-web-team 0.2.3 → 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.
|
|
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",
|
|
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
|
},
|
|
@@ -99,6 +99,26 @@ export function projectFiles(root) {
|
|
|
99
99
|
return files.sort((a, b) => depth(a) - depth(b) || a.localeCompare(b));
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
// The framework the project is built with: 'next', 'astro', or null for a
|
|
103
|
+
// static site with neither. A check written for one framework never runs on
|
|
104
|
+
// another, because its advice is wrong there: Astro sets response headers in
|
|
105
|
+
// host config, Next in headers(); Astro's canonical URLs come from `site`,
|
|
106
|
+
// Next's from metadataBase. Next wins if a project somehow has both.
|
|
107
|
+
export function framework(root) {
|
|
108
|
+
const d = deps(root);
|
|
109
|
+
if (nextConfig(root) || d.next) return 'next';
|
|
110
|
+
if (['astro.config.mjs', 'astro.config.js', 'astro.config.ts'].some((f) => existsSync(join(root, f))) || d.astro) {
|
|
111
|
+
return 'astro';
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Source without its comments, so a check reading config never counts a
|
|
117
|
+
// commented-out line: `// key: 'Content-Security-Policy'` is not a CSP. Line
|
|
118
|
+
// comments are only taken where `//` cannot be part of a URL in a string.
|
|
119
|
+
const withoutJsComments = (s) => s.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^:'"`\\])\/\/.*$/gm, '$1');
|
|
120
|
+
const withoutTomlComments = (s) => s.replace(/^\s*#.*$/gm, '');
|
|
121
|
+
|
|
102
122
|
// --------------------------------------------------------------------------
|
|
103
123
|
// footer: reads the contract, never hardcodes the link set
|
|
104
124
|
// --------------------------------------------------------------------------
|
|
@@ -456,16 +476,23 @@ export function seo({ root, html, dist }) {
|
|
|
456
476
|
? bad('seo.meta-description', `${noDesc.length} page(s) without one: ${noDesc.slice(0, 3).join(', ')}`)
|
|
457
477
|
: ok('seo.meta-description', 'all pages have a meta description'));
|
|
458
478
|
|
|
479
|
+
// The fix depends on the framework: Astro derives canonical URLs and the
|
|
480
|
+
// sitemap from `site`; Next from the metadata API and app/sitemap.ts.
|
|
481
|
+
const isNext = framework(root) === 'next';
|
|
459
482
|
out.push(noCanon.length
|
|
460
483
|
? bad('seo.canonical', `${noCanon.length} page(s) without a canonical link`,
|
|
461
|
-
|
|
484
|
+
isNext
|
|
485
|
+
? "Set `alternates.canonical` in each page's metadata, with `metadataBase` in the root layout so it resolves absolutely."
|
|
486
|
+
: 'Requires `site` set in the framework config. Missing `site` also silently breaks the sitemap.')
|
|
462
487
|
: ok('seo.canonical', 'canonical links present'));
|
|
463
488
|
|
|
464
489
|
const sitemap = ['sitemap-index.xml', 'sitemap.xml'].find((f) => existsSync(join(dist, f)));
|
|
465
490
|
out.push(sitemap
|
|
466
491
|
? ok('seo.sitemap', `${sitemap} emitted`)
|
|
467
492
|
: bad('seo.sitemap', 'no sitemap in the build output',
|
|
468
|
-
|
|
493
|
+
isNext
|
|
494
|
+
? 'Add app/sitemap.ts, which Next serves at /sitemap.xml.'
|
|
495
|
+
: 'Add @astrojs/sitemap and set `site` in the config.'));
|
|
469
496
|
|
|
470
497
|
const robotsPath = join(dist, 'robots.txt');
|
|
471
498
|
if (!existsSync(robotsPath)) {
|
|
@@ -1339,14 +1366,34 @@ const DEFAULT_HEADER_SET = [
|
|
|
1339
1366
|
['X-Frame-Options', 'frame options'],
|
|
1340
1367
|
];
|
|
1341
1368
|
|
|
1369
|
+
// Where a CSP comes from, if anywhere: the Next config's headers(), the Netlify
|
|
1370
|
+
// plugin that adds a per-request nonce, or host config. Bodies are read
|
|
1371
|
+
// without comments, so a commented-out policy is not one.
|
|
1372
|
+
function cspSource(root, nextBody, host) {
|
|
1373
|
+
if (nextBody && /Content-Security-Policy/i.test(nextBody)) return 'headers() in the Next config';
|
|
1374
|
+
if (deps(root)['@netlify/plugin-csp-nonce']
|
|
1375
|
+
|| (host?.kind === 'netlify' && /@netlify\/plugin-csp-nonce/.test(host.body))) return '@netlify/plugin-csp-nonce';
|
|
1376
|
+
if (host && /Content-Security-Policy/i.test(host.body)) return host.file;
|
|
1377
|
+
return null;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1342
1380
|
export function security({ root }) {
|
|
1343
|
-
const
|
|
1344
|
-
const
|
|
1381
|
+
const found = nextConfig(root);
|
|
1382
|
+
const cfg = found && { ...found, body: withoutJsComments(found.body) };
|
|
1383
|
+
const rawHost = hostConfig(root);
|
|
1384
|
+
const host = rawHost && {
|
|
1385
|
+
...rawHost, body: rawHost.kind === 'netlify' ? withoutTomlComments(rawHost.body) : rawHost.body,
|
|
1386
|
+
};
|
|
1345
1387
|
const out = [];
|
|
1346
1388
|
|
|
1347
|
-
//
|
|
1348
|
-
//
|
|
1349
|
-
|
|
1389
|
+
// Headers in host config: how Astro and a static build send them, because
|
|
1390
|
+
// Astro middleware misses prerendered routes. Never on a Next project, which
|
|
1391
|
+
// sets them in headers() for every route, static files included, and
|
|
1392
|
+
// security.headers-set checks that instead.
|
|
1393
|
+
out.push(framework(root) === 'next'
|
|
1394
|
+
? na('astro.headers-in-host-config',
|
|
1395
|
+
'a Next project: response headers come from headers() in the Next config (see security.headers-set)')
|
|
1396
|
+
: host
|
|
1350
1397
|
? (() => {
|
|
1351
1398
|
const missing = DEFAULT_HEADER_SET.filter(([h]) => !new RegExp(h, 'i').test(host.body)).map(([, l]) => l);
|
|
1352
1399
|
return missing.length
|
|
@@ -1377,15 +1424,15 @@ export function security({ root }) {
|
|
|
1377
1424
|
// header that breaks pages at CONTENT-EDIT time rather than at deploy time.
|
|
1378
1425
|
// MinWeb requires no response headers at all. The default header set below
|
|
1379
1426
|
// is what we actually ask for, because none of it can break a page.
|
|
1427
|
+
const csp = cspSource(root, hasHeaders ? b : null, host);
|
|
1428
|
+
out.push(csp
|
|
1429
|
+
? ok('security.csp-present', `CSP set by ${csp}; record it in .sws/manifest.yml`)
|
|
1430
|
+
: ok('security.csp-present', 'no CSP, which is compliant: CSP is optional'));
|
|
1380
1431
|
if (!hasHeaders) {
|
|
1381
|
-
out.push(ok('security.csp-present', 'no CSP, which is compliant: CSP is optional'));
|
|
1382
1432
|
out.push(bad('security.headers-set', 'no headers() function in the Next config',
|
|
1383
1433
|
'Add headers() returning the default set: HSTS, nosniff, Referrer-Policy, ' +
|
|
1384
1434
|
'Permissions-Policy, and X-Frame-Options: SAMEORIGIN. See standards/hosting/capabilities.yml.'));
|
|
1385
1435
|
} else {
|
|
1386
|
-
out.push(/Content-Security-Policy/i.test(b)
|
|
1387
|
-
? ok('security.csp-present', 'CSP configured in headers(); record it in .sws/manifest.yml')
|
|
1388
|
-
: ok('security.csp-present', 'no CSP, which is compliant: CSP is optional'));
|
|
1389
1436
|
|
|
1390
1437
|
const want = [
|
|
1391
1438
|
['Strict-Transport-Security', 'HSTS'],
|
|
@@ -1422,7 +1469,7 @@ export function security({ root }) {
|
|
|
1422
1469
|
|
|
1423
1470
|
export function next({ root, html }) {
|
|
1424
1471
|
const cfg = nextConfig(root);
|
|
1425
|
-
const isNext =
|
|
1472
|
+
const isNext = framework(root) === 'next';
|
|
1426
1473
|
if (!isNext) {
|
|
1427
1474
|
return ['next.postcss-configured', 'next.no-vite-tailwind', 'next.no-tailwind-config', 'next.metadata-base']
|
|
1428
1475
|
.map((id) => na(id, 'not a Next project'));
|
|
@@ -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 {
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
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
|
|