@wipcomputer/wip-ai-devops-toolbox 1.9.20

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 (146) hide show
  1. package/.license-guard.json +7 -0
  2. package/.publish-skill.json +4 -0
  3. package/CHANGELOG.md +1120 -0
  4. package/CLA.md +19 -0
  5. package/DEV-GUIDE-GENERAL-PUBLIC.md +882 -0
  6. package/LICENSE +52 -0
  7. package/README.md +238 -0
  8. package/SKILL.md +728 -0
  9. package/TECHNICAL.md +282 -0
  10. package/UNIVERSAL-INTERFACE.md +180 -0
  11. package/_trash/RELEASE-NOTES-v1-8-0.md +29 -0
  12. package/_trash/RELEASE-NOTES-v1-8-1.md +7 -0
  13. package/_trash/RELEASE-NOTES-v1-8-2.md +7 -0
  14. package/_trash/RELEASE-NOTES-v1-9-0.md +37 -0
  15. package/_trash/RELEASE-NOTES-v1-9-1.md +38 -0
  16. package/_trash/RELEASE-NOTES-v1-9-10.md +40 -0
  17. package/_trash/RELEASE-NOTES-v1-9-2.md +40 -0
  18. package/_trash/RELEASE-NOTES-v1-9-6.md +72 -0
  19. package/_trash/RELEASE-NOTES-v1-9-7.md +23 -0
  20. package/_trash/RELEASE-NOTES-v1-9-9.md +75 -0
  21. package/_trash/guide 2/DEV-GUIDE.md +487 -0
  22. package/_trash/guide 2/scripts/deploy-public.sh +152 -0
  23. package/package.json +27 -0
  24. package/scripts/SKILL-deploy-public.md +61 -0
  25. package/scripts/SKILL-post-merge-rename.md +47 -0
  26. package/scripts/deploy-public.sh +264 -0
  27. package/scripts/post-merge-rename.sh +205 -0
  28. package/scripts/publish-skill.sh +134 -0
  29. package/tools/deploy-public/LICENSE +52 -0
  30. package/tools/deploy-public/README.md +31 -0
  31. package/tools/deploy-public/SKILL.md +71 -0
  32. package/tools/deploy-public/deploy-public.sh +264 -0
  33. package/tools/deploy-public/package.json +9 -0
  34. package/tools/ldm-jobs/LICENSE +52 -0
  35. package/tools/ldm-jobs/README.md +46 -0
  36. package/tools/ldm-jobs/backup.sh +16 -0
  37. package/tools/ldm-jobs/branch-protect.sh +39 -0
  38. package/tools/ldm-jobs/crystal-capture.sh +19 -0
  39. package/tools/ldm-jobs/setup-shell.sh +27 -0
  40. package/tools/ldm-jobs/visibility-audit.sh +27 -0
  41. package/tools/post-merge-rename/LICENSE +52 -0
  42. package/tools/post-merge-rename/README.md +29 -0
  43. package/tools/post-merge-rename/SKILL.md +57 -0
  44. package/tools/post-merge-rename/package.json +9 -0
  45. package/tools/post-merge-rename/post-merge-rename.sh +122 -0
  46. package/tools/wip-branch-guard/INSTALL.md +41 -0
  47. package/tools/wip-branch-guard/guard.mjs +259 -0
  48. package/tools/wip-branch-guard/package.json +11 -0
  49. package/tools/wip-file-guard/CHANGELOG.md +6 -0
  50. package/tools/wip-file-guard/LICENSE +52 -0
  51. package/tools/wip-file-guard/README.md +113 -0
  52. package/tools/wip-file-guard/REFERENCE.md +86 -0
  53. package/tools/wip-file-guard/SKILL.md +105 -0
  54. package/tools/wip-file-guard/guard.mjs +128 -0
  55. package/tools/wip-file-guard/openclaw.plugin.json +8 -0
  56. package/tools/wip-file-guard/package.json +27 -0
  57. package/tools/wip-file-guard/test.sh +119 -0
  58. package/tools/wip-license-guard/LICENSE +52 -0
  59. package/tools/wip-license-guard/README.md +32 -0
  60. package/tools/wip-license-guard/SKILL.md +65 -0
  61. package/tools/wip-license-guard/cli.mjs +464 -0
  62. package/tools/wip-license-guard/core.mjs +310 -0
  63. package/tools/wip-license-guard/hook.mjs +146 -0
  64. package/tools/wip-license-guard/package.json +15 -0
  65. package/tools/wip-license-hook/CHANGELOG.md +17 -0
  66. package/tools/wip-license-hook/LICENSE +52 -0
  67. package/tools/wip-license-hook/README.md +200 -0
  68. package/tools/wip-license-hook/SKILL.md +111 -0
  69. package/tools/wip-license-hook/dist/cli/index.d.ts +15 -0
  70. package/tools/wip-license-hook/dist/cli/index.js +170 -0
  71. package/tools/wip-license-hook/dist/cli/index.js.map +1 -0
  72. package/tools/wip-license-hook/dist/core/detector.d.ts +12 -0
  73. package/tools/wip-license-hook/dist/core/detector.js +104 -0
  74. package/tools/wip-license-hook/dist/core/detector.js.map +1 -0
  75. package/tools/wip-license-hook/dist/core/index.d.ts +4 -0
  76. package/tools/wip-license-hook/dist/core/index.js +5 -0
  77. package/tools/wip-license-hook/dist/core/index.js.map +1 -0
  78. package/tools/wip-license-hook/dist/core/ledger.d.ts +49 -0
  79. package/tools/wip-license-hook/dist/core/ledger.js +72 -0
  80. package/tools/wip-license-hook/dist/core/ledger.js.map +1 -0
  81. package/tools/wip-license-hook/dist/core/reporter.d.ts +14 -0
  82. package/tools/wip-license-hook/dist/core/reporter.js +227 -0
  83. package/tools/wip-license-hook/dist/core/reporter.js.map +1 -0
  84. package/tools/wip-license-hook/dist/core/scanner.d.ts +39 -0
  85. package/tools/wip-license-hook/dist/core/scanner.js +325 -0
  86. package/tools/wip-license-hook/dist/core/scanner.js.map +1 -0
  87. package/tools/wip-license-hook/hooks/pre-pull.sh +55 -0
  88. package/tools/wip-license-hook/hooks/pre-push.sh +51 -0
  89. package/tools/wip-license-hook/mcp-server.mjs +119 -0
  90. package/tools/wip-license-hook/package-lock.json +54 -0
  91. package/tools/wip-license-hook/package.json +43 -0
  92. package/tools/wip-license-hook/src/cli/index.ts +189 -0
  93. package/tools/wip-license-hook/src/core/detector.ts +130 -0
  94. package/tools/wip-license-hook/src/core/index.ts +4 -0
  95. package/tools/wip-license-hook/src/core/ledger.ts +116 -0
  96. package/tools/wip-license-hook/src/core/reporter.ts +255 -0
  97. package/tools/wip-license-hook/src/core/scanner.ts +367 -0
  98. package/tools/wip-license-hook/tsconfig.json +16 -0
  99. package/tools/wip-readme-format/README.md +49 -0
  100. package/tools/wip-readme-format/SKILL.md +84 -0
  101. package/tools/wip-readme-format/format.mjs +570 -0
  102. package/tools/wip-readme-format/package.json +15 -0
  103. package/tools/wip-release/CHANGELOG.md +42 -0
  104. package/tools/wip-release/LICENSE +52 -0
  105. package/tools/wip-release/README.md +45 -0
  106. package/tools/wip-release/REFERENCE.md +100 -0
  107. package/tools/wip-release/SKILL.md +139 -0
  108. package/tools/wip-release/cli.js +161 -0
  109. package/tools/wip-release/core.mjs +1174 -0
  110. package/tools/wip-release/mcp-server.mjs +109 -0
  111. package/tools/wip-release/package.json +36 -0
  112. package/tools/wip-repo-init/README.md +38 -0
  113. package/tools/wip-repo-init/SKILL.md +77 -0
  114. package/tools/wip-repo-init/init.mjs +142 -0
  115. package/tools/wip-repo-init/package.json +11 -0
  116. package/tools/wip-repo-permissions-hook/LICENSE +52 -0
  117. package/tools/wip-repo-permissions-hook/README.md +86 -0
  118. package/tools/wip-repo-permissions-hook/SKILL.md +73 -0
  119. package/tools/wip-repo-permissions-hook/cli.js +83 -0
  120. package/tools/wip-repo-permissions-hook/core.mjs +122 -0
  121. package/tools/wip-repo-permissions-hook/guard.mjs +64 -0
  122. package/tools/wip-repo-permissions-hook/mcp-server.mjs +92 -0
  123. package/tools/wip-repo-permissions-hook/openclaw.plugin.json +8 -0
  124. package/tools/wip-repo-permissions-hook/package.json +31 -0
  125. package/tools/wip-repos/LICENSE +52 -0
  126. package/tools/wip-repos/README.md +77 -0
  127. package/tools/wip-repos/SKILL.md +80 -0
  128. package/tools/wip-repos/cli.mjs +176 -0
  129. package/tools/wip-repos/core.mjs +290 -0
  130. package/tools/wip-repos/mcp-server.mjs +157 -0
  131. package/tools/wip-repos/package.json +34 -0
  132. package/tools/wip-universal-installer/CHANGELOG.md +57 -0
  133. package/tools/wip-universal-installer/LICENSE +52 -0
  134. package/tools/wip-universal-installer/README.md +81 -0
  135. package/tools/wip-universal-installer/REFERENCE.md +122 -0
  136. package/tools/wip-universal-installer/SKILL.md +87 -0
  137. package/tools/wip-universal-installer/SPEC.md +180 -0
  138. package/tools/wip-universal-installer/detect.mjs +130 -0
  139. package/tools/wip-universal-installer/examples/minimal/README.md +20 -0
  140. package/tools/wip-universal-installer/examples/minimal/SKILL.md +28 -0
  141. package/tools/wip-universal-installer/examples/minimal/cli.mjs +4 -0
  142. package/tools/wip-universal-installer/examples/minimal/core.mjs +8 -0
  143. package/tools/wip-universal-installer/examples/minimal/mcp-server.mjs +27 -0
  144. package/tools/wip-universal-installer/examples/minimal/package.json +12 -0
  145. package/tools/wip-universal-installer/install.js +930 -0
  146. package/tools/wip-universal-installer/package.json +36 -0
@@ -0,0 +1,464 @@
1
+ #!/usr/bin/env node
2
+ // wip-license-guard
3
+ // License compliance for your own repos.
4
+ // Ensures correct copyright, dual-license blocks, and LICENSE files.
5
+
6
+ import { existsSync, readFileSync, writeFileSync, readdirSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { createInterface } from 'node:readline';
9
+ import { generateLicense, generateCLA, generateReadmeBlock, replaceReadmeLicenseSection, removeReadmeLicenseSection } from './core.mjs';
10
+
11
+ const args = process.argv.slice(2);
12
+ const HELP_FLAGS = ['--help', '-h', 'help'];
13
+ const command = HELP_FLAGS.some(f => args.includes(f)) ? 'help' : (args.find(a => !a.startsWith('--')) || 'check');
14
+ const target = args.find((a, i) => i > 0 && !a.startsWith('--')) || '.';
15
+ const FIX = args.includes('--fix');
16
+ const DRY_RUN = args.includes('--dry-run');
17
+ const QUIET = args.includes('--quiet');
18
+ const FROM_STANDARD = args.includes('--from-standard');
19
+
20
+ function log(msg) { if (!QUIET) console.log(msg); }
21
+ function ok(msg) { if (!QUIET) console.log(` \u2713 ${msg}`); }
22
+ function warn(msg) { console.log(` \u2717 ${msg}`); }
23
+
24
+ function ask(question) {
25
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
26
+ return new Promise(resolve => {
27
+ rl.question(question, answer => {
28
+ rl.close();
29
+ resolve(answer.trim());
30
+ });
31
+ });
32
+ }
33
+
34
+ // WIP Computer standard defaults
35
+ const WIP_STANDARD = {
36
+ copyright: 'WIP Computer, Inc.',
37
+ license: 'MIT+AGPL',
38
+ year: String(new Date().getFullYear()),
39
+ attribution: 'Built by Parker Todd Brooks, Lēsa (OpenClaw, Claude Opus 4.6), Claude Code (Claude Opus 4.6).',
40
+ };
41
+
42
+ async function init(repoPath) {
43
+ const configPath = join(repoPath, '.license-guard.json');
44
+
45
+ // --from-standard: apply WIP Computer defaults without prompting
46
+ if (FROM_STANDARD) {
47
+ log('\n wip-license-guard init --from-standard\n');
48
+
49
+ const config = { ...WIP_STANDARD, created: new Date().toISOString() };
50
+
51
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
52
+ ok(`Config saved to .license-guard.json`);
53
+
54
+ const licensePath = join(repoPath, 'LICENSE');
55
+ writeFileSync(licensePath, generateLicense(config, repoPath));
56
+ ok(`LICENSE file generated (dual MIT+AGPLv3)`);
57
+
58
+ const claPath = join(repoPath, 'CLA.md');
59
+ if (!existsSync(claPath)) {
60
+ writeFileSync(claPath, generateCLA(repoPath));
61
+ ok(`CLA.md generated`);
62
+ } else {
63
+ ok(`CLA.md already exists`);
64
+ }
65
+
66
+ log(`\n Standard: ${config.copyright}, ${config.license}, ${config.year}`);
67
+ log(` Done. Run \`wip-license-guard check\` to audit.\n`);
68
+ return config;
69
+ }
70
+
71
+ if (existsSync(configPath)) {
72
+ const existing = JSON.parse(readFileSync(configPath, 'utf8'));
73
+ log(`\nLicense guard already configured:`);
74
+ log(` Copyright: ${existing.copyright}`);
75
+ log(` License: ${existing.license}`);
76
+ log(` Year: ${existing.year}`);
77
+ const update = await ask('\nUpdate? (y/N) ');
78
+ if (update.toLowerCase() !== 'y') {
79
+ log('Keeping existing config.');
80
+ return existing;
81
+ }
82
+ }
83
+
84
+ log('\n wip-license-guard init\n');
85
+
86
+ const copyright = await ask(' Copyright holder (e.g. WIP Computer, Inc.): ');
87
+ if (!copyright) {
88
+ console.error('Copyright holder is required.');
89
+ process.exit(1);
90
+ }
91
+
92
+ log('\n License types:');
93
+ log(' 1. MIT only');
94
+ log(' 2. AGPLv3 only');
95
+ log(' 3. MIT + AGPLv3 dual-license (recommended for WIP repos)');
96
+ const licenseChoice = await ask('\n Choose (1/2/3): ');
97
+
98
+ const licenseMap = { '1': 'MIT', '2': 'AGPL-3.0', '3': 'MIT+AGPL' };
99
+ const license = licenseMap[licenseChoice] || 'MIT+AGPL';
100
+
101
+ const currentYear = new Date().getFullYear();
102
+ const yearInput = await ask(` Copyright year (${currentYear}): `);
103
+ const year = yearInput || String(currentYear);
104
+
105
+ const attribution = await ask(' Attribution (e.g. Built by Parker Todd Brooks, ...): ');
106
+
107
+ const config = { copyright, license, year, attribution, created: new Date().toISOString() };
108
+
109
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
110
+ ok(`Config saved to .license-guard.json`);
111
+
112
+ const licensePath = join(repoPath, 'LICENSE');
113
+ const licenseText = generateLicense(config, repoPath);
114
+ writeFileSync(licensePath, licenseText);
115
+ ok(`LICENSE file generated`);
116
+
117
+ // Generate CLA.md if it doesn't exist
118
+ const claPath = join(repoPath, 'CLA.md');
119
+ if (!existsSync(claPath)) {
120
+ writeFileSync(claPath, generateCLA(repoPath));
121
+ ok(`CLA.md generated`);
122
+ }
123
+
124
+ log(`\nDone. Run \`wip-license-guard check\` to audit.`);
125
+ return config;
126
+ }
127
+
128
+ async function check(repoPath) {
129
+ const configPath = join(repoPath, '.license-guard.json');
130
+
131
+ if (!existsSync(configPath)) {
132
+ log('\n No .license-guard.json found.');
133
+ const doInit = await ask(' Initialize license guard? (Y/n) ');
134
+ if (doInit.toLowerCase() !== 'n') {
135
+ await init(repoPath);
136
+ return 0;
137
+ }
138
+ process.exit(1);
139
+ }
140
+
141
+ const config = JSON.parse(readFileSync(configPath, 'utf8'));
142
+ let issues = 0;
143
+
144
+ log(`\n wip-license-guard check\n`);
145
+ log(` Copyright: ${config.copyright}`);
146
+ log(` License: ${config.license}\n`);
147
+
148
+ // Check LICENSE file
149
+ const licensePath = join(repoPath, 'LICENSE');
150
+ if (!existsSync(licensePath)) {
151
+ warn('LICENSE file missing');
152
+ issues++;
153
+ if (FIX) {
154
+ writeFileSync(licensePath, generateLicense(config, repoPath));
155
+ ok('LICENSE file created (--fix)');
156
+ issues--;
157
+ }
158
+ } else {
159
+ const licenseText = readFileSync(licensePath, 'utf8');
160
+
161
+ if (!licenseText.includes(config.copyright)) {
162
+ warn(`LICENSE copyright does not match "${config.copyright}"`);
163
+ issues++;
164
+ if (FIX) {
165
+ writeFileSync(licensePath, generateLicense(config, repoPath));
166
+ ok('LICENSE file updated (--fix)');
167
+ issues--;
168
+ }
169
+ } else {
170
+ ok('LICENSE copyright correct');
171
+ }
172
+
173
+ if (config.license === 'MIT+AGPL') {
174
+ if (!licenseText.includes('AGPL') && !licenseText.includes('GNU Affero')) {
175
+ warn('LICENSE file is MIT-only but config says MIT+AGPL');
176
+ issues++;
177
+ if (FIX) {
178
+ writeFileSync(licensePath, generateLicense(config, repoPath));
179
+ ok('LICENSE file updated to dual-license (--fix)');
180
+ issues--;
181
+ }
182
+ } else {
183
+ ok('LICENSE includes AGPLv3 terms');
184
+ }
185
+ }
186
+ }
187
+
188
+ // Check CLA.md
189
+ const claPath = join(repoPath, 'CLA.md');
190
+ if (!existsSync(claPath)) {
191
+ warn('CLA.md missing');
192
+ issues++;
193
+ if (FIX) {
194
+ writeFileSync(claPath, generateCLA(repoPath));
195
+ ok('CLA.md created (--fix)');
196
+ issues--;
197
+ }
198
+ } else {
199
+ ok('CLA.md exists');
200
+ }
201
+
202
+ // Check README (license + structure standard)
203
+ const readmePath = join(repoPath, 'README.md');
204
+ if (existsSync(readmePath)) {
205
+ const readme = readFileSync(readmePath, 'utf8');
206
+
207
+ // License checks
208
+ if (!readme.includes('## License')) {
209
+ warn('README.md missing ## License section');
210
+ issues++;
211
+ } else {
212
+ ok('README.md has License section');
213
+ }
214
+
215
+ if (config.license === 'MIT+AGPL' && !readme.includes('AGPL')) {
216
+ warn('README.md License section missing AGPL reference');
217
+ issues++;
218
+ } else if (config.license === 'MIT+AGPL') {
219
+ ok('README.md references AGPL');
220
+ }
221
+
222
+ // README structure standard checks
223
+ if (!readme.match(/^#\s+\S/m)) {
224
+ warn('README.md missing # title');
225
+ issues++;
226
+ } else {
227
+ ok('README.md has title');
228
+ }
229
+
230
+ if (config.attribution && !readme.includes(config.attribution.split(',')[0])) {
231
+ warn('README.md missing attribution');
232
+ issues++;
233
+ } else if (config.attribution) {
234
+ ok('README.md has attribution');
235
+ }
236
+
237
+ // Warn if README contains content that belongs in TECHNICAL.md
238
+ const technicalPatterns = [
239
+ /## (Architecture|API|Config|Configuration|Build|Development Setup|Quick Start)/i,
240
+ /```json\s*\n\s*\{[\s\S]*?"command"/, // MCP config blocks
241
+ /npm install -g /, // install commands belong in TECHNICAL.md
242
+ ];
243
+ for (const pattern of technicalPatterns) {
244
+ if (pattern.test(readme)) {
245
+ warn('README.md contains technical content (move to TECHNICAL.md)');
246
+ issues++;
247
+ break;
248
+ }
249
+ }
250
+ } else {
251
+ warn('README.md not found');
252
+ issues++;
253
+ }
254
+
255
+ // Check sub-tools (toolbox mode)
256
+ const toolsDir = join(repoPath, 'tools');
257
+ if (existsSync(toolsDir)) {
258
+ try {
259
+ const entries = readdirSync(toolsDir, { withFileTypes: true });
260
+ for (const entry of entries) {
261
+ if (!entry.isDirectory()) continue;
262
+ const toolPath = join(toolsDir, entry.name);
263
+ const toolLicense = join(toolPath, 'LICENSE');
264
+
265
+ if (!existsSync(toolLicense)) {
266
+ warn(`tools/${entry.name}/LICENSE missing`);
267
+ issues++;
268
+ if (FIX) {
269
+ writeFileSync(toolLicense, generateLicense(config, repoPath));
270
+ ok(`tools/${entry.name}/LICENSE created (--fix)`);
271
+ issues--;
272
+ }
273
+ } else {
274
+ const text = readFileSync(toolLicense, 'utf8');
275
+ if (!text.includes(config.copyright)) {
276
+ warn(`tools/${entry.name}/LICENSE wrong copyright`);
277
+ issues++;
278
+ if (FIX) {
279
+ writeFileSync(toolLicense, generateLicense(config, repoPath));
280
+ ok(`tools/${entry.name}/LICENSE updated (--fix)`);
281
+ issues--;
282
+ }
283
+ } else {
284
+ ok(`tools/${entry.name}/LICENSE correct`);
285
+ }
286
+ }
287
+ }
288
+ } catch {}
289
+ }
290
+
291
+ log('');
292
+ if (issues === 0) {
293
+ log(' All checks passed.\n');
294
+ } else {
295
+ log(` ${issues} issue(s) found. Run with --fix to auto-repair.\n`);
296
+ }
297
+
298
+ return issues;
299
+ }
300
+
301
+ async function readmeLicense(targetPath) {
302
+ const mode = FIX ? '--fix' : DRY_RUN ? '--dry-run' : '';
303
+ log(`\n wip-license-guard readme-license${mode ? ' ' + mode : ''}\n`);
304
+
305
+ // Detect if targetPath is a single repo or a directory of repos
306
+ const repos = [];
307
+ const configPath = join(targetPath, '.license-guard.json');
308
+ if (existsSync(configPath)) {
309
+ // Single repo
310
+ repos.push(targetPath);
311
+ } else {
312
+ // Directory of repos (or nested categories like ldm-os/components/)
313
+ const scanDir = (dir) => {
314
+ try {
315
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
316
+ if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === '_trash') continue;
317
+ const sub = join(dir, entry.name);
318
+ if (existsSync(join(sub, '.license-guard.json'))) {
319
+ repos.push(sub);
320
+ } else if (existsSync(join(sub, 'package.json')) || existsSync(join(sub, 'README.md'))) {
321
+ repos.push(sub);
322
+ } else {
323
+ scanDir(sub); // recurse into category folders
324
+ }
325
+ }
326
+ } catch {}
327
+ };
328
+ scanDir(targetPath);
329
+ }
330
+
331
+ if (repos.length === 0) {
332
+ warn('No repos found. Point at a repo or a directory containing repos.');
333
+ return 1;
334
+ }
335
+
336
+ log(` Found ${repos.length} repo(s)\n`);
337
+
338
+ let totalIssues = 0;
339
+
340
+ for (const repoPath of repos) {
341
+ const repoName = repoPath.split('/').pop();
342
+ const repoConfig = join(repoPath, '.license-guard.json');
343
+ const config = existsSync(repoConfig)
344
+ ? JSON.parse(readFileSync(repoConfig, 'utf8'))
345
+ : WIP_STANDARD;
346
+
347
+ // 1. Check main README
348
+ const readmePath = join(repoPath, 'README.md');
349
+ if (existsSync(readmePath)) {
350
+ const content = readFileSync(readmePath, 'utf8');
351
+ const expected = generateReadmeBlock(config);
352
+
353
+ if (content.includes('### Can I use this?') && content.includes('Dual-license model')) {
354
+ ok(`${repoName}/README.md ... standard license block`);
355
+ } else if (content.includes('## License')) {
356
+ warn(`${repoName}/README.md ... non-standard license section`);
357
+ totalIssues++;
358
+ if (DRY_RUN) {
359
+ // Extract current license section for preview
360
+ const match = content.match(/## License[\s\S]*?(?=\n## [^#]|$)/);
361
+ if (match) {
362
+ log(` current: ${match[0].split('\n').slice(0, 3).join(' | ').substring(0, 80)}...`);
363
+ }
364
+ log(` would replace with: standard dual MIT/AGPLv3 block`);
365
+ }
366
+ if (FIX) {
367
+ const updated = replaceReadmeLicenseSection(content, config, repoPath);
368
+ writeFileSync(readmePath, updated);
369
+ ok(`${repoName}/README.md ... updated to standard (--fix)`);
370
+ totalIssues--;
371
+ }
372
+ } else {
373
+ warn(`${repoName}/README.md ... missing ## License`);
374
+ totalIssues++;
375
+ if (DRY_RUN) {
376
+ log(` would add: standard dual MIT/AGPLv3 block at end of README`);
377
+ }
378
+ if (FIX) {
379
+ const updated = replaceReadmeLicenseSection(content, config, repoPath);
380
+ writeFileSync(readmePath, updated);
381
+ ok(`${repoName}/README.md ... added standard block (--fix)`);
382
+ totalIssues--;
383
+ }
384
+ }
385
+ } else {
386
+ warn(`${repoName}/README.md ... not found`);
387
+ totalIssues++;
388
+ }
389
+
390
+ // 2. Check sub-tool READMEs (should NOT have license sections)
391
+ const toolsDir = join(repoPath, 'tools');
392
+ if (existsSync(toolsDir)) {
393
+ try {
394
+ for (const tool of readdirSync(toolsDir, { withFileTypes: true })) {
395
+ if (!tool.isDirectory()) continue;
396
+ const subReadme = join(toolsDir, tool.name, 'README.md');
397
+ if (!existsSync(subReadme)) continue;
398
+
399
+ const subContent = readFileSync(subReadme, 'utf8');
400
+ if (subContent.includes('## License')) {
401
+ warn(`${repoName}/tools/${tool.name}/README.md ... has license section (should be removed)`);
402
+ totalIssues++;
403
+ if (DRY_RUN) {
404
+ log(` would remove: ## License section from sub-tool README`);
405
+ }
406
+ if (FIX) {
407
+ const cleaned = removeReadmeLicenseSection(subContent);
408
+ writeFileSync(subReadme, cleaned);
409
+ ok(`${repoName}/tools/${tool.name}/README.md ... license section removed (--fix)`);
410
+ totalIssues--;
411
+ }
412
+ }
413
+ }
414
+ } catch {}
415
+ }
416
+ }
417
+
418
+ log('');
419
+ if (totalIssues === 0) {
420
+ log(' All README license sections are correct.\n');
421
+ } else if (DRY_RUN) {
422
+ log(` ${totalIssues} issue(s) found. Dry run complete. No changes made.`);
423
+ log(` Run with --fix to apply changes.\n`);
424
+ } else {
425
+ log(` ${totalIssues} issue(s) found. Run with --dry-run to preview or --fix to apply.\n`);
426
+ }
427
+
428
+ return totalIssues;
429
+ }
430
+
431
+ // Main
432
+ if (command === 'init') {
433
+ await init(target === 'init' ? '.' : target);
434
+ } else if (command === 'check') {
435
+ const repoPath = (target === 'check') ? '.' : target;
436
+ const issues = await check(repoPath);
437
+ process.exit(issues > 0 ? 1 : 0);
438
+ } else if (command === 'readme-license') {
439
+ const repoPath = (target === 'readme-license') ? '.' : target;
440
+ const issues = await readmeLicense(repoPath);
441
+ process.exit(issues > 0 ? 1 : 0);
442
+ } else if (command === '--help' || command === '-h' || command === 'help') {
443
+ console.log(`
444
+ wip-license-guard
445
+
446
+ Commands:
447
+ init [path] Interactive setup. Asks license type, copyright, year.
448
+ init --from-standard Apply WIP Computer defaults (MIT+AGPL, CLA, attribution).
449
+ check [path] Audit repo against saved config. Exit 1 if issues found.
450
+ check --fix [path] Auto-fix issues (update LICENSE files, wrong copyright).
451
+ readme-license [path] Scan README license sections. Works on one repo or a directory of repos.
452
+ readme-license --dry-run Preview what would change. Shows current vs standard for each README.
453
+ readme-license --fix Apply standard license block to all READMEs. Remove from sub-tools.
454
+ help Show this help.
455
+
456
+ On first run, if no config exists, check will offer to run init.
457
+ Use --from-standard for new WIP Computer repos (no prompts, just works).
458
+
459
+ Config file: .license-guard.json (commit this to your repo)
460
+ `);
461
+ } else {
462
+ console.error(`Unknown command: ${command}. Run wip-license-guard help.`);
463
+ process.exit(1);
464
+ }