monoforge 0.0.0-stage → 0.9.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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -2
  3. package/bin/forge.mjs +65 -0
  4. package/package.json +49 -4
  5. package/src/cut.mjs +244 -0
  6. package/src/doctor.mjs +230 -0
  7. package/src/index.mjs +4 -0
  8. package/src/lint-packs.mjs +77 -0
  9. package/src/lock.mjs +37 -0
  10. package/src/stamp.mjs +201 -0
  11. package/src/templates.mjs +133 -0
  12. package/templates/monoforge/AGENTS.md +30 -0
  13. package/templates/monoforge/CHANGELOG.md +19 -0
  14. package/templates/monoforge/DEPLOY.md +53 -0
  15. package/templates/monoforge/LICENSE +21 -0
  16. package/templates/monoforge/README.md +16 -0
  17. package/templates/monoforge/TEMPLATE.md +19 -0
  18. package/templates/monoforge/docs/Gemfile +5 -0
  19. package/templates/monoforge/docs/_config.yml +36 -0
  20. package/templates/monoforge/docs/_layouts/default.html +29 -0
  21. package/templates/monoforge/docs/assets/css/style.css +14 -0
  22. package/templates/monoforge/docs/freestruct.config.yml +7 -0
  23. package/templates/monoforge/docs/index.md +27 -0
  24. package/templates/monoforge/docs/search.md +28 -0
  25. package/templates/monoforge/functions/api/health.js +10 -0
  26. package/templates/monoforge/gitignore.tmpl +9 -0
  27. package/templates/monoforge/horcrux/HORCRUX.md +7 -0
  28. package/templates/monoforge/labs/.eyes/ledger.json +1 -0
  29. package/templates/monoforge/labs/.eyes/manifest.yml +5 -0
  30. package/templates/monoforge/labs/TASKS.md +11 -0
  31. package/templates/monoforge/scripts/build-docs.sh +12 -0
  32. package/templates/monoforge/scripts/check-docs-frontmatter.cjs +112 -0
  33. package/templates/monoforge/scripts/check-docs-links.cjs +81 -0
  34. package/templates/monoforge/scripts/check-docs-style.cjs +79 -0
  35. package/templates/monoforge/scripts/check-fiction-signatures.cjs +69 -0
  36. package/templates/monoforge/scripts/check-jekyll-filters.cjs +62 -0
  37. package/templates/monoforge/scripts/check-language.cjs +171 -0
  38. package/templates/monoforge/site/robots.txt +4 -0
  39. package/templates/monoforge/wrangler.toml +11 -0
  40. package/templates/monoforge-headless/.github/workflows/docs.yml +102 -0
  41. package/templates/monoforge-headless/.github/workflows/publish.yml +141 -0
  42. package/templates/monoforge-headless/.github/workflows/staging-ff-sync.yml +44 -0
  43. package/templates/monoforge-headless/.github/workflows/test.yml +21 -0
  44. package/templates/monoforge-headless/TEMPLATE.md +17 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dhaupin (Rook) / Creadev.org
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # monoforge 0.9.0
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The struct-family factory: stamp a fleet repo from proven template blocks, doctor it for truth, lock it verifiably.
4
+
5
+ One law: **generated green is never shipped.** The stamp layer carries only what two proven instances already validated (poststruct + packstruct); the doctor runs the same truth battery the fleet reads (tests, docs gates, release ladder, dash law); unfilled `FORGE-TODO` slots are failures, not warnings, because a shipped placeholder is a shipped lie.
6
+
7
+ ## Usage
8
+
9
+ ```bash
10
+ # 1. config: create factory.json in an empty directory
11
+ monoforge new ./my-tool # stamps template blocks + fills tokens, never the truth
12
+ monoforge doctor ./my-tool # the truth battery (refuses FORGE-TODO, broken gates, dash law)
13
+ monoforge lock ./my-tool # doctor must pass, then archive + checksum
14
+ monoforge cut ./family # release cuts: components/<name>/ from a living lib per cutlist.json
15
+ ```
16
+
17
+ factory.json:
18
+
19
+ ```json
20
+ {
21
+ "name": "my-tool",
22
+ "species": "one-liner",
23
+ "pitch": "the one-line pitch",
24
+ "description": "the long form",
25
+ "siteDomain": "https://my-tool.creadev.org",
26
+ "version": "0.9.0",
27
+ "profile": "monoforge"
28
+ }
29
+ ```
30
+
31
+ `docsPath` defaults to `docs.creadev.org/<name>`. `profile` defaults to
32
+ `monoforge` (the full scaffold); set it to `monoforge-headless` to stamp only the
33
+ `.github/` battery - a repo that brings its own docs tree still inherits the
34
+ gates, the docs lane, and the release ladder. Profiles CHAIN (the coreforge
35
+ shape): `monoforge` composes `monoforge-headless` first, so the battery lives
36
+ once. `node src/templates.mjs --list` names the profiles;
37
+ `node src/templates.mjs --resolve <name>` prints the resolved file set.
38
+
39
+ Component families take a `scope` field (npm scope for the cut packages) plus a `cutlist.json` beside `factory.json`:
40
+
41
+ ```json
42
+ {
43
+ "source": "/path/to/the/living/lib",
44
+ "shortfall": ["lazies", "allowed", "to", "degrade"],
45
+ "packages": [
46
+ { "name": "my-lib", "sources": ["my-lib.js"], "deps": ["primitives"] },
47
+ { "name": "primitives", "sources": ["primitives.js"] }
48
+ ]
49
+ }
50
+ ```
51
+
52
+ Every unmapped internal dependency refuses; shortfall lazies must be declared and ship as documented call-site degrades (each package README carries the list). The realized receipt: the creadev-lib generation-1 cut, 7 packages from the vant lib, in the mono PRD.
53
+
54
+ ## What stamps, what does not
55
+
56
+ | Layer | monoforge carries it | Source of truth |
57
+ |---|---|---|
58
+ | Docs system (Jekyll + Pagefind + Freestruct + 6 gates) | template | two proven instances |
59
+ | Workflows (test, docs, publish 0.x refusal, staging ff-sync) | template | same |
60
+ | Release ladder + DEPLOY runbook shape | template | same |
61
+ | `FORGE-TODO` slots (README pitch, AGENTS core law, coverage list) | **author** | the tool itself |
62
+ | the core code, the check catalog, the spec | **author** | the tool itself |
63
+
64
+ The template blocks were extracted 2026-10-24 from the proven trees; they follow the poststruct and packstruct shape, with names tokenized.
65
+
66
+ ## Status
67
+
68
+ This cut: stamp + doctor + lock all negative-tested (bad configs refused, stray dirs refused, unfilled slots flagged, filled trees pass). Manual npm ladder; 1.0.0 flips OIDC.
69
+
70
+ ## Related
71
+
72
+ - [poststruct](https://github.com/dhaupin/poststruct) + [packstruct](https://github.com/dhaupin/packstruct): the proven instances the templates were extracted from
73
+ - **The workshop** → [Creadev.org](https://creadev.org) (monoforge is made by Rook @ Creadev.org - the same home as the docs and site surfaces above)
package/bin/forge.mjs ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ // bin/forge.mjs - monoforge: stamp / doctor / lock. Zero dependencies.
3
+ // Law: generated green is never shipped - the doctor refuses placeholder
4
+ // text, missing entries, and broken gates; the lock refuses a dirty tree.
5
+ import { resolve } from 'node:path'
6
+ import { readFileSync } from 'node:fs'
7
+
8
+ const Help = `monoforge - the struct-family factory
9
+
10
+ Usage:
11
+ monoforge new <dir> stamp a fleet repo from factory.json (config in <dir>)
12
+ re-running over a stamped tree overlays only the
13
+ files still matching its receipt; host-edited
14
+ files are skipped by name, never clobbered
15
+ monoforge doctor [dir] run the truth battery (default: cwd)
16
+ monoforge cut [dir] cut a component-family workspace (cutlist.json + factory.json required)
17
+ monoforge lock [dir] doctor, then archive with a checksum
18
+ monoforge lint-packs packstruct passthrough over the repo's own install (loud exit 2 until the packs land)
19
+ monoforge help this
20
+
21
+ factory.json (in <dir>, required):
22
+ { "name": "kebab-name", "species": "one-liner", "pitch": "the one-line pitch",
23
+ "description": "the long form", "siteDomain": "https://x.creadev.org",
24
+ "docsPath": "docs.creadev.org/x (optional, defaults to that)",
25
+ "version": "0.9.0 (optional)" }
26
+ `
27
+ const [cmd, arg1, arg2] = process.argv.slice(2)
28
+ const dir = resolve(arg2 || arg1 || '.')
29
+ const show = (r) => { console.log(JSON.stringify(r, null, 2)); process.exit(r.ok ? 0 : 1) }
30
+
31
+ if (!cmd || cmd === 'help' || cmd === '--help') { console.log(Help); process.exit(0) }
32
+ // The version truth is package.json (the family rule, flowforge#28): the
33
+ // publish lane's verify job probes the INSTALLED bin with --version, and
34
+ // this is the bare global it answers.
35
+ if (cmd === '--version') { console.log(JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version); process.exit(0) }
36
+ if (cmd === 'new') {
37
+ const stamp = (await import('../src/stamp.mjs')).default
38
+ show(await stamp(resolve(process.argv[3] || '.')))
39
+ } else if (cmd === 'doctor') {
40
+ const doctor = (await import('../src/doctor.mjs')).default
41
+ const r = await doctor(dir)
42
+ for (const f of r.findings) console.log(`${f.level.toUpperCase()} ${f.id}: ${f.message}`)
43
+ console.log(`doctor: ${r.counts.fail} fail(s), ${r.counts.warn} warn(s) - ${r.ok ? 'PASS' : 'FAIL'}`)
44
+ process.exit(r.ok ? 0 : 1)
45
+ } else if (cmd === 'cut') {
46
+ const cut = (await import('../src/cut.mjs')).default
47
+ const r = await cut((await import('node:path')).resolve(process.argv[3] || '.'))
48
+ console.log(`cut: OK (${r.packages} packages from rev ${r.sourceRev.slice(0, 7)}) stamped ${r.files} files into ${r.dir}/`)
49
+ process.exit(0)
50
+ } else if (cmd === 'lock') {
51
+ const lock = (await import('../src/lock.mjs')).default
52
+ const r = await lock(dir)
53
+ if (!r.ok) { console.error(`lock: ${r.error}`); if (r.doctor) { for (const f of r.doctor.findings) console.log(` ${f.level.toUpperCase()} ${f.id}: ${f.message}`) } process.exit(1) }
54
+ console.log(`lock: OK (sha256 ${r.sha}...) archived ${r.archive}`)
55
+ process.exit(0)
56
+ } else if (cmd === 'lint-packs') {
57
+ // The pack lint lane as a discoverable verb (mirrors crashtest's
58
+ // lint-packs, issue #32): ready now, honest exit 2 until the factory's
59
+ // own packs + packstruct devDep land - never a silent skip.
60
+ const { runLintPacks } = await import('../src/lint-packs.mjs')
61
+ process.exit(runLintPacks({ argv: process.argv.slice(3), cwd: process.cwd(), json: process.argv.includes('--json') }))
62
+ } else {
63
+ console.log(Help)
64
+ process.exit(2)
65
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "monoforge",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.9.0",
4
+ "description": "The struct-family factory: stamps a new fleet repo from proven template blocks, doctors it for truth, and locks it. Generated green is never shipped: the doctor refuses placeholder text and unverified gates.\n",
5
+ "type": "module",
6
+ "bin": {
7
+ "monoforge": "bin/forge.mjs"
8
+ },
9
+ "exports": {
10
+ ".": "./src/index.mjs"
11
+ },
12
+ "files": [
13
+ "bin/",
14
+ "src/",
15
+ "templates/"
16
+ ],
17
+ "scripts": {
18
+ "test": "node test/run.mjs && node test/version-truth.mjs && node --test test/templates.test.cjs test/ship-from-download.test.cjs test/release-verify.test.cjs test/docs-frontmatter.test.cjs test/web-imports.test.cjs test/status.test.mjs",
19
+ "lint:packs": "node bin/forge.mjs lint-packs --deep",
20
+ "lint:docs": "node scripts/check-docs-frontmatter.cjs && node scripts/check-docs-links.cjs && node scripts/check-docs-style.cjs && node scripts/check-fiction-signatures.cjs && node scripts/check-jekyll-filters.cjs",
21
+ "lint:language": "node scripts/check-language.cjs",
22
+ "check": "npm test && npm run lint:docs && npm run lint:language",
23
+ "prepublishOnly": "npm run check",
24
+ "icons:adopt": "node scripts/adopt-icons.mjs"
25
+ },
26
+ "devDependencies": {
27
+ "eyestruct": "1.0.0",
28
+ "packstruct": "1.0.0",
29
+ "crashtest": "1.1.0"
30
+ },
31
+ "engines": {
32
+ "node": ">=20"
33
+ },
34
+ "keywords": [
35
+ "scaffold",
36
+ "generator",
37
+ "factory",
38
+ "ci",
39
+ "struct-family",
40
+ "creadev"
41
+ ],
42
+ "license": "SEE LICENSE IN LICENSE",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/dhaupin/monoforge.git"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/dhaupin/monoforge/issues"
49
+ },
50
+ "homepage": "https://github.com/dhaupin/monoforge#readme"
51
+ }
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
+ }