monoforge 0.0.0-stage → 1.0.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.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -2
  3. package/bin/forge.mjs +98 -0
  4. package/package.json +56 -4
  5. package/packs/README.md +62 -0
  6. package/packs/public/forge-shapes/index.mjs +161 -0
  7. package/packs/public/forge-shapes/pack.json +13 -0
  8. package/packs/public/forge-shapes/test/fixtures/bad-publish/.github/workflows/publish.yml +11 -0
  9. package/packs/public/forge-shapes/test/fixtures/bad-publish/.monoforge-stamp.json +12 -0
  10. package/packs/public/forge-shapes/test/fixtures/bad-publish/README.md +3 -0
  11. package/packs/public/forge-shapes/test/fixtures/bad-publish/bin/probe.mjs +2 -0
  12. package/packs/public/forge-shapes/test/fixtures/bad-publish/package.json +14 -0
  13. package/packs/public/forge-shapes/test/fixtures/clean/.github/workflows/publish.yml +12 -0
  14. package/packs/public/forge-shapes/test/fixtures/clean/.monoforge-stamp.json +12 -0
  15. package/packs/public/forge-shapes/test/fixtures/clean/README.md +3 -0
  16. package/packs/public/forge-shapes/test/fixtures/clean/bin/probe.mjs +2 -0
  17. package/packs/public/forge-shapes/test/fixtures/clean/package.json +14 -0
  18. package/packs/public/forge-shapes/test/fixtures/missing-file/.github/workflows/publish.yml +12 -0
  19. package/packs/public/forge-shapes/test/fixtures/missing-file/.monoforge-stamp.json +13 -0
  20. package/packs/public/forge-shapes/test/fixtures/missing-file/README.md +3 -0
  21. package/packs/public/forge-shapes/test/fixtures/missing-file/bin/probe.mjs +2 -0
  22. package/packs/public/forge-shapes/test/fixtures/missing-file/package.json +14 -0
  23. package/packs/public/forge-shapes/test/fixtures/token/.github/workflows/publish.yml +12 -0
  24. package/packs/public/forge-shapes/test/fixtures/token/.monoforge-stamp.json +12 -0
  25. package/packs/public/forge-shapes/test/fixtures/token/README.md +3 -0
  26. package/packs/public/forge-shapes/test/fixtures/token/bin/probe.mjs +2 -0
  27. package/packs/public/forge-shapes/test/fixtures/token/package.json +14 -0
  28. package/packs/public/forge-shapes/test/fixtures/unfilled/.github/workflows/publish.yml +12 -0
  29. package/packs/public/forge-shapes/test/fixtures/unfilled/.monoforge-stamp.json +12 -0
  30. package/packs/public/forge-shapes/test/fixtures/unfilled/README.md +3 -0
  31. package/packs/public/forge-shapes/test/fixtures/unfilled/bin/probe.mjs +2 -0
  32. package/packs/public/forge-shapes/test/fixtures/unfilled/package.json +14 -0
  33. package/packs/public/forge-shapes/test/run.mjs +67 -0
  34. package/spec/refusals.json +35 -0
  35. package/src/cut.mjs +244 -0
  36. package/src/doctor.mjs +253 -0
  37. package/src/fs-adapter.mjs +143 -0
  38. package/src/fs-node.mjs +15 -0
  39. package/src/harness.mjs +118 -0
  40. package/src/index.mjs +19 -0
  41. package/src/lint-packs.mjs +77 -0
  42. package/src/lock.mjs +37 -0
  43. package/src/packs.mjs +200 -0
  44. package/src/paths.mjs +48 -0
  45. package/src/refusals.mjs +45 -0
  46. package/src/sha256.mjs +61 -0
  47. package/src/stamp.mjs +215 -0
  48. package/src/templates.mjs +147 -0
  49. package/src/workers.mjs +16 -0
  50. package/templates/monoforge/AGENTS.md +30 -0
  51. package/templates/monoforge/CHANGELOG.md +19 -0
  52. package/templates/monoforge/DEPLOY.md +53 -0
  53. package/templates/monoforge/LICENSE +21 -0
  54. package/templates/monoforge/README.md +16 -0
  55. package/templates/monoforge/TEMPLATE.md +19 -0
  56. package/templates/monoforge/docs/Gemfile +5 -0
  57. package/templates/monoforge/docs/_config.yml +36 -0
  58. package/templates/monoforge/docs/_layouts/default.html +29 -0
  59. package/templates/monoforge/docs/assets/css/style.css +14 -0
  60. package/templates/monoforge/docs/freestruct.config.yml +7 -0
  61. package/templates/monoforge/docs/index.md +27 -0
  62. package/templates/monoforge/docs/search.md +28 -0
  63. package/templates/monoforge/functions/api/health.js +10 -0
  64. package/templates/monoforge/gitignore.tmpl +9 -0
  65. package/templates/monoforge/horcrux/HORCRUX.md +7 -0
  66. package/templates/monoforge/labs/.eyes/ledger.json +1 -0
  67. package/templates/monoforge/labs/.eyes/manifest.yml +5 -0
  68. package/templates/monoforge/labs/TASKS.md +11 -0
  69. package/templates/monoforge/scripts/build-docs.sh +12 -0
  70. package/templates/monoforge/scripts/check-docs-frontmatter.cjs +112 -0
  71. package/templates/monoforge/scripts/check-docs-links.cjs +81 -0
  72. package/templates/monoforge/scripts/check-docs-style.cjs +79 -0
  73. package/templates/monoforge/scripts/check-fiction-signatures.cjs +69 -0
  74. package/templates/monoforge/scripts/check-jekyll-filters.cjs +62 -0
  75. package/templates/monoforge/scripts/check-language.cjs +171 -0
  76. package/templates/monoforge/site/robots.txt +4 -0
  77. package/templates/monoforge/wrangler.toml +11 -0
  78. package/templates/monoforge-headless/.github/workflows/docs.yml +102 -0
  79. package/templates/monoforge-headless/.github/workflows/publish.yml +141 -0
  80. package/templates/monoforge-headless/.github/workflows/staging-ff-sync.yml +44 -0
  81. package/templates/monoforge-headless/.github/workflows/test.yml +21 -0
  82. package/templates/monoforge-headless/TEMPLATE.md +17 -0
@@ -0,0 +1,12 @@
1
+ name: publish
2
+ on:
3
+ push:
4
+ tags: ['v*']
5
+ jobs:
6
+ publish:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - run: |
10
+ case "$V" in 0.*) echo "refusing 0.x"; exit 1;; esac
11
+ env:
12
+ V: ${{ github.ref_name }}
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "probe",
3
+ "profile": "monoforge",
4
+ "version": "0.9.0",
5
+ "files": [
6
+ "package.json",
7
+ "README.md",
8
+ ".github/workflows/publish.yml",
9
+ "bin/probe.mjs"
10
+ ],
11
+ "hashes": {}
12
+ }
@@ -0,0 +1,3 @@
1
+ # probe
2
+
3
+ __DESCRIPTION__
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ console.log('probe')
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "probe",
3
+ "version": "0.9.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "probe": "./bin/probe.mjs"
7
+ },
8
+ "files": [
9
+ "bin/"
10
+ ],
11
+ "engines": {
12
+ "node": ">=20"
13
+ }
14
+ }
@@ -0,0 +1,12 @@
1
+ name: publish
2
+ on:
3
+ push:
4
+ tags: ['v*']
5
+ jobs:
6
+ publish:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - run: |
10
+ case "$V" in 0.*) echo "refusing 0.x"; exit 1;; esac
11
+ env:
12
+ V: ${{ github.ref_name }}
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "probe",
3
+ "profile": "monoforge",
4
+ "version": "0.9.0",
5
+ "files": [
6
+ "package.json",
7
+ "README.md",
8
+ ".github/workflows/publish.yml",
9
+ "bin/probe.mjs"
10
+ ],
11
+ "hashes": {}
12
+ }
@@ -0,0 +1,3 @@
1
+ # probe
2
+
3
+ FORGE-TODO: describe this repo
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ console.log('probe')
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "probe",
3
+ "version": "0.9.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "probe": "./bin/probe.mjs"
7
+ },
8
+ "files": [
9
+ "bin/"
10
+ ],
11
+ "engines": {
12
+ "node": ">=20"
13
+ }
14
+ }
@@ -0,0 +1,67 @@
1
+ // packs/public/forge-shapes/test/run.mjs - the pack's self-audit (packstruct
2
+ // SPEC section 4: every pack ships test/fixtures/ proving its own claims).
3
+ //
4
+ // Runs the pack against each fixture tree and asserts the verdict each one
5
+ // claims. A fixture that stops producing its verdict fails here, in the pack's
6
+ // own CI, before any host loads it. Zero dependencies.
7
+ import { readdirSync, readFileSync, statSync } from 'node:fs'
8
+ import { join, resolve } from 'node:path'
9
+ import { run } from '../index.mjs'
10
+
11
+ const HERE = resolve(new URL('.', import.meta.url).pathname)
12
+ const FIXTURES = join(HERE, 'fixtures')
13
+
14
+ function treeAt(root) {
15
+ const inside = (rel) => {
16
+ if (typeof rel !== 'string' || !rel) return null
17
+ const abs = resolve(root, rel)
18
+ return abs === root || abs.startsWith(root + '/') ? abs : null
19
+ }
20
+ return {
21
+ root,
22
+ exists(rel) { const abs = inside(rel); return abs ? statSync(abs, { throwIfNoEntry: false }) != null : false }, // file OR dir
23
+ text(rel) {
24
+ const abs = inside(rel)
25
+ if (!abs) return null
26
+ try { return statSync(abs).isFile() ? readFileSync(abs, 'utf8') : null } catch { return null }
27
+ },
28
+ readdir(rel) { const abs = inside(rel ?? ''); try { return readdirSync(abs) } catch { return [] } },
29
+ }
30
+ }
31
+
32
+ const verdicts = (root) => new Map(run({ forgeTree: treeAt(root) }).rows.map((r) => [r.id, r.verdict]))
33
+
34
+ let failures = 0
35
+ const check = (label, cond) => { if (!cond) { console.error(` FAIL ${label}`); failures++ } else { console.log(` ok ${label}`) } }
36
+
37
+ // Each fixture claims a verdict for one check id.
38
+ const CASES = [
39
+ ['clean', 'forge/receipt-present', 'PASSED'],
40
+ ['clean', 'forge/receipt-files-exist', 'PASSED'],
41
+ ['clean', 'forge/truth-slot-clean', 'PASSED'],
42
+ ['clean', 'forge/stamp-token-clean', 'PASSED'],
43
+ ['clean', 'forge/package-paths', 'PASSED'],
44
+ ['clean', 'forge/publish-gate', 'PASSED'],
45
+ ['unfilled', 'forge/truth-slot-clean', 'EXPLOITED'],
46
+ ['unfilled', 'forge/receipt-present', 'PASSED'],
47
+ ['token', 'forge/stamp-token-clean', 'EXPLOITED'],
48
+ ['missing-file', 'forge/receipt-files-exist', 'EXPLOITED'],
49
+ ['missing-file', 'forge/receipt-present', 'PASSED'],
50
+ ['bad-publish', 'forge/publish-gate', 'EXPLOITED'],
51
+ ['bad-publish', 'forge/truth-slot-clean', 'PASSED'],
52
+ ]
53
+
54
+ console.log('forge-shapes self-audit:')
55
+ const cache = new Map()
56
+ for (const [fixture, id, want] of CASES) {
57
+ if (!cache.has(fixture)) cache.set(fixture, verdicts(join(FIXTURES, fixture)))
58
+ const got = cache.get(fixture).get(id)
59
+ check(`${fixture}: ${id} -> ${want} (got ${got})`, got === want)
60
+ }
61
+
62
+ // An absent target dockets BOUNDED and never a pass.
63
+ const absent = new Map(run({ forgeTree: { root: null } }).rows.map((r) => [r.id, r.verdict]))
64
+ check('absent target: forge/receipt-present -> BOUNDED', absent.get('forge/receipt-present') === 'BOUNDED')
65
+
66
+ console.log(failures ? `forge-shapes self-audit: ${failures} FAILURE(S)` : 'forge-shapes self-audit: PASS')
67
+ process.exit(failures ? 1 : 0)
@@ -0,0 +1,35 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "description": "monoforge's refusal-code registry, in the govstruct spec/refusals.json shape (the G10 model): one namespaced vocabulary so a refusal one tool emits is a refusal the next tool can read. The harness refuses to emit a code it has not registered here, and test/harness.test.mjs holds that law. Codes are namespaced by tool; monoforge's namespace is `monoforge`.",
4
+ "namespaces": {
5
+ "monoforge": {
6
+ "E_BIN_PATH": "a package.json bin entry does not exist in the tree",
7
+ "E_CANON_PIN": "the .eyes canon manifest carries no pin block, or a pin is missing or still UNSET",
8
+ "E_CONFIG_INVALID": "factory.json is not valid JSON",
9
+ "E_CONFIG_MISSING": "factory.json is absent (the stamp needs a config)",
10
+ "E_DANGLING_CANON": "a .eyes canon ledger row points at a file that does not exist, escapes the canon home, or the ledger is corrupt",
11
+ "E_DASH_LAW": "an em or en dash appears in md prose (the house law is none, ever)",
12
+ "E_DOCS_GATE": "a docs gate script failed over the tree",
13
+ "E_EXPORTS_PATH": "a package.json exports entry does not exist in the tree",
14
+ "E_FIELD_MISSING": "a required factory.json key is missing or empty",
15
+ "E_FILES_PATH": "a package.json files entry does not exist in the tree",
16
+ "E_GRANT_INVALID": "the grant context is malformed (kind and scope must be non-empty strings)",
17
+ "E_IDENTITY_DRIFT": "a re-stamp targets a tree stamped under a different name",
18
+ "E_ID_FORMAT": "factory.json name is not kebab-case",
19
+ "E_LOCK_REFUSED": "lock refused because the doctor reported at least one failure",
20
+ "E_NPM_TEST": "npm test failed over the tree",
21
+ "E_PACKAGE_JSON": "package.json is not valid JSON",
22
+ "E_PROFILE_UNKNOWN": "factory.json profile is not a known profile",
23
+ "E_PUBLISH_GATE": "publish.yml does not refuse 0.x refs (the OIDC ladder gate)",
24
+ "E_PUBLISH_TOKEN": "publish.yml references a publish token (the law is OIDC only)",
25
+ "E_SITE_DOMAIN": "factory.json siteDomain is not an absolute https URL",
26
+ "E_STAMP_MANIFEST": ".monoforge-stamp.json is present but unparseable",
27
+ "E_STAMP_TOKEN": "a raw __TOKEN__ survived the stamp (the stamp never finished)",
28
+ "E_STRAY_DIR": "the stamp target is a non-empty directory that is not a re-stamp",
29
+ "E_TEMPLATE_EMPTY": "a profile resolved to no files (the scaffold is missing its template dir)",
30
+ "E_TEMPLATE_RESOLUTION": "template chain resolution failed (a cycle, or a missing chained profile)",
31
+ "E_TRUTH_SLOT": "a FORGE-TODO truth slot is still unfilled (a shipped placeholder is a shipped lie)",
32
+ "E_VERB_UNKNOWN": "the harness was asked for a verb it does not drive"
33
+ }
34
+ }
35
+ }
package/src/cut.mjs ADDED
@@ -0,0 +1,244 @@
1
+ // src/cut.mjs - monoforge cut: stamp a component-family workspace by
2
+ // cutting opt-in sources out of a living lib. The release-cut doctrine's
3
+ // defining operation: install follows the tag, not the repo.
4
+ // Inputs: factory.json (workspace identity) + cutlist.json (the ONE
5
+ // authored input: component -> source list). Output: components/<name>/
6
+ // packages with intra-graph deps rewritten (./x -> @scope/x), smoke
7
+ // tests, root workspaces, per-package provenance. Law: an unmapped
8
+ // internal dependency is a LOUD refusal, never a silent vant-internal
9
+ // copy; publish is always a later decision the owner makes.
10
+ import { execFileSync } from 'node:child_process'
11
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs'
12
+ import { join, relative } from 'node:path'
13
+
14
+ function readJson(p) {
15
+ try { return JSON.parse(readFileSync(p, 'utf8')) } catch (e) {
16
+ throw new Error(`${p} is not valid JSON: ${e.message}`)
17
+ }
18
+ }
19
+
20
+ // rewrite bare intra-lib requires (./x or ./x.js) to scoped package
21
+ // requires using the module->package map. Unmapped './x' = LOUD refusal.
22
+ function rewriteDeps(source, map, shortfall, scope, ownerModule) {
23
+ const s = String(source)
24
+ const re = /require\(\s*['"]\.\/([A-Za-z0-9_-]+?)(?:\.js)?['"]\s*\)/g
25
+ let out = '', m, last = 0
26
+ while ((m = re.exec(s)) !== null) {
27
+ const mod = m[1]
28
+ const mapped = map.get(mod)
29
+ if (mapped) {
30
+ out += s.slice(last, m.index) + `require('@${scope}/${mapped}')`
31
+ last = m.index + m[0].length
32
+ continue
33
+ }
34
+ if (!shortfall.has(mod)) {
35
+ throw new Error(`unmapped internal dependency "${mod}" in ${ownerModule}: refuse (cut it, or declare it in cutlist.shortfall as a documented capability degrade)`)
36
+ }
37
+ out += s.slice(last, m.index) + `require('@${scope}/${mod}')`
38
+ last = m.index + m[0].length
39
+ }
40
+ return out + s.slice(last)
41
+ }
42
+
43
+
44
+ export default async function cut(targetDir) {
45
+ if (!targetDir) throw new Error('usage: monoforge cut <dir>')
46
+ const factory = readJson(join(targetDir, 'factory.json'))
47
+ if (typeof factory.name !== 'string' || !factory.name || !/^[a-z0-9_-]+$/.test(factory.name)) {
48
+ throw new Error(`factory.name must be a npm-safe name (got ${JSON.stringify(factory.name)})`)
49
+ }
50
+ const cutlistPath = join(targetDir, 'cutlist.json')
51
+ if (!existsSync(cutlistPath)) {
52
+ throw new Error(`no cutlist.json in ${join(targetDir)}: the cutlist is the ONE authored input (component -> source list)`)
53
+ }
54
+ const cutlist = readJson(cutlistPath)
55
+ const srcRoot = cutlist.source
56
+ if (!srcRoot || !existsSync(join(srcRoot))) throw new Error(`cutlist.source does not exist: ${srcRoot}`)
57
+ if (!Array.isArray(cutlist.packages) || !cutlist.packages.length) {
58
+ throw new Error('cutlist.packages must be a non-empty list of {name, sources}')
59
+ }
60
+
61
+ // provenance: the exact source revision the cut captures
62
+ let rev = 'unknown'
63
+ let revWarn = null
64
+ try { rev = execFileSync('git', ['-C', srcRoot, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim() } catch (e) { revWarn = `source rev unavailable: ${e.message.split('\n')[0]}` }
65
+
66
+ // shortfall registry: declared lazy dependencies that are NOT cut but
67
+ // are allowed to be referenced (rewritten to scoped names whose
68
+ // absence is a documented, nameable call-site degrade). Anything
69
+ // unmapped and unregistered refuses.
70
+ const shortfall = new Set(cutlist.shortfall || [])
71
+ for (const sf of shortfall) {
72
+ if (!/^[a-z0-9][a-z0-9_-]*$/.test(sf)) throw new Error(`shortfall entry must be a module name (got ${sf})`)
73
+ }
74
+ // module -> package map driven ONLY by the cutlist
75
+ const map = new Map()
76
+ for (const pkg of cutlist.packages) {
77
+ if (!/^[a-z0-9][a-z0-9-]*$/.test(pkg.name)) throw new Error(`package name must be kebab-case (got ${pkg.name})`)
78
+ if (!Array.isArray(pkg.sources) || !pkg.sources.length) throw new Error(`package ${pkg.name}: a non-empty sources list is required`)
79
+ for (const src of pkg.sources) {
80
+ if (!existsSync(join(srcRoot, src))) throw new Error(`package ${pkg.name}: source not found: ${src}`)
81
+ map.set(src.replace(/\.js$/, ''), `${pkg.name}`)
82
+ }
83
+ }
84
+ if (new Set(cutlist.packages.map(p => p.name)).size !== cutlist.packages.length) {
85
+ throw new Error('duplicate package names in cutlist')
86
+ }
87
+
88
+ mkdirSync(targetDir, { recursive: true })
89
+ const touched = []
90
+ const today = new Date().toISOString()
91
+ // scope: factory.scope wins (e.g. "@creadev.org"); otherwise factory.name
92
+ const SCOPE = factory.scope ? `${factory.scope.replace(/^@/, '')}` : factory.name
93
+
94
+ for (const pkg of cutlist.packages) {
95
+ const pkDir = join(targetDir, 'components', pkg.name)
96
+ mkdirSync(join(pkDir, 'src'), { recursive: true })
97
+ mkdirSync(join(pkDir, 'test'), { recursive: true })
98
+
99
+ // sources, with intra-graph requires rewritten to scoped deps
100
+ const deps = {}
101
+ const usedShortfalls = new Set()
102
+ for (const src of pkg.sources) {
103
+ let body = String(readFileSync(join(srcRoot, src)))
104
+ body = rewriteDeps(body, map, shortfall, SCOPE, src)
105
+ for (const m of body.matchAll(/require\('@[^']*\/([a-z0-9_-]+)'\)/g)) {
106
+ const name = m[1]
107
+ if (!cutlist.packages.some(p2 => p2.name === name)) usedShortfalls.add(name)
108
+ }
109
+ const dst = join(pkDir, 'src', src)
110
+ mkdirSync(join(dst, '..'), { recursive: true })
111
+ writeFileSync(dst, body)
112
+ touched.push(relative(targetDir, dst))
113
+ }
114
+ // declared deps must be cut packages, keyed by their scoped names
115
+ for (const d of pkg.deps || []) {
116
+ if (!map.has(d)) throw new Error(`package ${pkg.name}: declared dep "${d}" is not in this cut (add it to the cutlist, or declare it in shortfall if it is a lazy capability)`)
117
+ deps[`@${SCOPE}/${d}`] = '~0.9.0'
118
+ }
119
+
120
+ const main = pkg.sources[0]
121
+ const pkgJson = {
122
+ name: `@${SCOPE}/${pkg.name}`,
123
+ version: '0.9.0',
124
+ description: pkg.description || `${pkg.name}: a component cut of the ${factory.name} family`,
125
+ license: 'MIT',
126
+ main: `src/${main}`,
127
+ files: ['src/', 'CHANGELOG.md', 'test/'],
128
+ publishConfig: { access: 'public' },
129
+ scripts: { test: 'node test/smoke.cjs' },
130
+ engines: { node: '>=20' },
131
+ dependencies: deps,
132
+ }
133
+ writeFileSync(join(pkDir, 'package.json'), JSON.stringify(pkgJson, null, 2) + '\n')
134
+ touched.push(`components/${pkg.name}/package.json`)
135
+
136
+ const revLine = revWarn
137
+ ? `Provenance: cut from ${srcRoot}; ${revWarn}.`
138
+ : `Provenance: cut from ${srcRoot} at revision ${rev}.`
139
+ const changelog = [
140
+ '# Changelog',
141
+ '',
142
+ `All notable changes to @${SCOPE}/${pkg.name}.`,
143
+ '',
144
+ 'The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Versions are cuts of the source lib: see each entry for the exact origin revision. Release ladder: 0.9.x manual npm; 1.0.0 flips OIDC trusted publishing.',
145
+ '',
146
+ `## [0.9.0] - ${today.slice(0, 10)}`,
147
+ '',
148
+ '### Added',
149
+ '- First cut of this component.',
150
+ `- ${revLine}`,
151
+ '',
152
+ ].join('\n') + '\n'
153
+ writeFileSync(join(pkDir, 'CHANGELOG.md'), changelog)
154
+ touched.push(`components/${pkg.name}/CHANGELOG.md`)
155
+
156
+ const smoke = `#!/usr/bin/env node\n// smoke: the cut loads standalone and exports a real module shape.\nconst assert = require('node:assert')\nconst { join } = require('node:path')\nconst mod = require(join(__dirname, '..', 'src', ${JSON.stringify(main)}))\nassert(mod && (typeof mod === 'object' || typeof mod === 'function'), 'module.exports must be object or function')\nassert(Object.keys(mod).length > 0, 'module.exports must expose at least one key')\nconsole.log('smoke ok: ${pkg.name} (' + Object.keys(mod).length + ' exports)')\n`
157
+ writeFileSync(join(pkDir, 'test', 'smoke.cjs'), smoke)
158
+ touched.push(`components/${pkg.name}/test/smoke.cjs`)
159
+
160
+ // per-package README: the provenance + the HONEST shortfall list
161
+ const sfList = [...usedShortfalls].sort()
162
+ const readme = [
163
+ `# @${SCOPE}/${pkg.name}`,
164
+ '',
165
+ pkg.description || `${pkg.name}: a component cut of the ${factory.name} family.`,
166
+ '',
167
+ '## Provenance',
168
+ '',
169
+ `- ${revLine}`,
170
+ '',
171
+ '## What this package is',
172
+ '',
173
+ 'A release cut: versioned, gated files frozen from the source lib at',
174
+ 'the revision above. Install follows the tag, not the repo. Updates',
175
+ 'happen only when a new cut is deliberately made, tested, and tagged.',
176
+ '',
177
+ '## Capability shortfalls (HONEST)',
178
+ '',
179
+ sfList.length
180
+ ? ['The source module lazily references these internal modules that', 'are NOT part of this cut (they are its upstream-vant internals or', 'larger candidates cut separately later). At consumer runtime,', 'reaching those call sites raises a nameable MODULE_NOT_FOUND under', `@${SCOPE}/${sfList[0]}: that is the documented degrade, not a bug.`, ''].join('\n') + sfList.map((x) => `- \`${x}\``).join('\n') + '\n'
181
+ : 'None: every capability this module references is in the cut.\n',
182
+ ].join('\n') + '\n'
183
+ writeFileSync(join(pkDir, 'README.md'), readme)
184
+ touched.push(`components/${pkg.name}/README.md`)
185
+ }
186
+
187
+ // root workspace
188
+ const rootPkg = {
189
+ name: factory.name,
190
+ version: factory.version || '0.9.0',
191
+ private: true,
192
+ workspaces: ['components/*'],
193
+ scripts: { test: 'node scripts/test-all.cjs' },
194
+ engines: { node: '>=20' },
195
+ }
196
+ writeFileSync(join(targetDir, 'package.json'), JSON.stringify(rootPkg, null, 2) + '\n')
197
+ touched.push('package.json')
198
+
199
+ const testAll = `#!/usr/bin/env node\n// run every component smoke test (installs workspace links first).\nconst { execFileSync } = require('node:child_process')\nconst { join } = require('node:path')\nconst { readdirSync } = require('node:fs')\nexecFileSync('npm', ['install', '--no-fund', '--no-audit', '--silent'], { stdio: 'inherit' })\nconst comps = readdirSync('components').filter((c) => !c.startsWith('.'))\nfor (const c of comps) {\n execFileSync('node', ['test/smoke.cjs'], { cwd: join('components', c), stdio: 'inherit' })\n}\nconsole.log('all ' + comps.length + ' package smokes PASS')\n`
200
+ mkdirSync(join(targetDir, 'scripts'), { recursive: true })
201
+ writeFileSync(join(targetDir, 'scripts', 'test-all.cjs'), testAll)
202
+ touched.push('scripts/test-all.cjs')
203
+
204
+ // root README: the family index, honest
205
+ const note = revWarn ? `(source rev unavailable: ${revWarn})` : `(source rev ${rev.slice(0, 7)})`
206
+ const perPkg = cutlist.packages.map((pkg) => {
207
+ const src = join(targetDir, 'components', pkg.name, 'README.md')
208
+ const sfm = (readFileSync(src, 'utf8').match(/^- `(.+)`$/gm) || []).map((x) => x.slice(3, -1))
209
+ return `| ${pkg.name} | ${pkg.sources.join(', ')} | ${(sfm.join(', ') || 'none')} |`
210
+ }).join('\n')
211
+ const rootReadme = [
212
+ `# ${factory.name}`,
213
+ '',
214
+ factory.description.replace(/!$/, '.') || 'The component family.',
215
+ '',
216
+ `A release-cut family: every package is a versioned slice of the living source lib, provenance-tagged to its origin revision ${note}.`,
217
+ 'Install follows the tag, not the repo; updates are deliberate cuts, never followers.',
218
+ '',
219
+ '## The cut',
220
+ '',
221
+ '| Package | Cut from | Shortfall modules (documented degrade) |',
222
+ '|---|---|---|',
223
+ perPkg,
224
+ '',
225
+ '## Release ladder',
226
+ '',
227
+ '0.9.x: manual npm, per package. 1.0.0 flips OIDC trusted publishing.',
228
+ '',
229
+ ].join('\n') + '\n'
230
+ writeFileSync(join(targetDir, 'README.md'), rootReadme)
231
+ touched.push('README.md')
232
+
233
+ // manifest: what the cut actually stamped (the doctor scopes its slot
234
+ // scan to exactly these files)
235
+ writeFileSync(join(targetDir, '.monoforge-stamp.json'), JSON.stringify({
236
+ stampTool: 'monoforge-cut',
237
+ name: factory.name,
238
+ date: today.slice(0, 10),
239
+ sourceRev: rev,
240
+ files: touched,
241
+ }, null, 2) + '\n')
242
+
243
+ return { ok: true, dir: targetDir, packages: cutlist.packages.length, sourceRev: rev, files: touched.length }
244
+ }