@wenathlan/saddle 1.8.4 → 1.8.6
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 +10 -10
- package/browser/playwright.js +22 -0
- package/docs/.gitkeep +0 -0
- package/docs/actionsincident.md +29 -0
- package/docs/branchaudit.md +21 -0
- package/docs/ecosystemplan.md +3 -3
- package/docs/featureaudit.md +1 -1
- package/docs/gapmatrix.md +8 -7
- package/docs/libraryapi.md +1 -0
- package/docs/logs/.gitkeep +0 -0
- package/docs/packageaudit185.md +23 -0
- package/docs/plans/00.index.md +50 -0
- package/docs/plans/01.architecture.md +86 -0
- package/docs/plans/02.research.computer.use.md +58 -0
- package/docs/plans/03.research.captcha.bypass.md +68 -0
- package/docs/plans/04.research.sandbox.ai.md +52 -0
- package/docs/plans/05.capture.platform.md +57 -0
- package/docs/plans/06.dependencies.md +97 -0
- package/docs/plans/07.captcha.test.page.md +41 -0
- package/docs/plans/08.production.infra.md +70 -0
- package/docs/plans/09.database.schema.md +121 -0
- package/docs/plans/10.cloudinary.storage.md +57 -0
- package/docs/plans/11.movement.logs.json.md +72 -0
- package/docs/plans/12.research.atlas.agent.browser.md +79 -0
- package/docs/plans/13.research.anti.detection.md +898 -0
- package/docs/plans/14.research.proxy.md +1495 -0
- package/docs/plans/15.research.retry.rate.limit.md +1958 -0
- package/docs/plans/16.research.crawling.md +1417 -0
- package/docs/plans/17.research.caching.md +1610 -0
- package/docs/plans/18.research.content.extraction.md +1952 -0
- package/docs/plans/19.research.errors.events.md +1523 -0
- package/docs/plans/20.research.zod.validation.md +1350 -0
- package/docs/plans/21.research.batch.concurrency.md +1888 -0
- package/docs/plans/22.research.universal.runtime.md +944 -0
- package/docs/plans/23.research.ai.integration.md +1465 -0
- package/docs/plans/24.research.memory.persistence.md +1979 -0
- package/docs/plans/25.research.server.api.md +342 -0
- package/docs/plans/26.research.compilation.md +249 -0
- package/docs/plans/27.research.html.parsing.md +251 -0
- package/docs/plans/28.action.plan.md +50 -0
- package/docs/plans/29.api.reference.md +174 -0
- package/docs/plans/30.architecture.plan.md +94 -0
- package/docs/plans/31.auditoria.dados.md +163 -0
- package/docs/plans/32.bots.automacao.computacional.md +214 -0
- package/docs/plans/33.bots.codigo.revisao.md +220 -0
- package/docs/plans/34.bots.seguranca.cicd.md +366 -0
- package/docs/plans/35.comparativo.concorrencia.md +464 -0
- package/docs/plans/36.computational.memory.md +340 -0
- package/docs/plans/37.deploystrategy.md +394 -0
- package/docs/plans/38.flow.md +155 -0
- package/docs/plans/39.multi.platform.bot.md +252 -0
- package/docs/plans/40.npm.publish.md +250 -0
- package/docs/plans/41.o.que.falta.md +407 -0
- package/docs/plans/42.pesquisa.concorrencia.md +721 -0
- package/docs/plans/43.plan.universal.architecture.md +496 -0
- package/docs/plans/44.reference.md +100 -0
- package/docs/plans/45.robotarchitecture.md +237 -0
- package/docs/plans/46.scdnintegration.md +284 -0
- package/docs/plans/47.multiforge.readme.md +129 -0
- package/docs/plans/48.theory.v4.repo.os.md +152 -0
- package/docs/plans/49.third.party.infra.md +12 -0
- package/docs/plans/50.file.as.compute.md +39 -0
- package/docs/plans/51.architecture.virtual.processor.md +80 -0
- package/docs/plans/52.manifesto.v8.md +11 -0
- package/docs/plans/58.cdn.list.md +23 -0
- package/docs/plans/59.sql.frameworks.md +33 -0
- package/docs/plans/60.sql.thirdparty.md +26 -0
- package/docs/plans/61.objective.multiforge.md +63 -0
- package/docs/plans/62.huggingface.upload.md +26 -0
- package/docs/plans/63.kaggle.upload.md +24 -0
- package/docs/plans/64.npm.storage.md +30 -0
- package/docs/plans/65.rclone.terabox.md +32 -0
- package/docs/plans/66.buckets.and.models.todo.md +14 -0
- package/docs/plans/67.database.todo.md +13 -0
- package/docs/plans/68.deploy.packages.todo.md +12 -0
- package/docs/plans/69.report.human.operator.md +133 -0
- package/docs/plans/70.report.brain2qwerty.ems.md +135 -0
- package/docs/plans/71.report.hd.infinito.vram.md +155 -0
- package/docs/plans/72.plan.hd.infinito.node.md +146 -0
- package/docs/plans/73.plan.scifi.repos.md +125 -0
- package/docs/plans/74.000.manifesto.v8.flat.2..md +11 -0
- package/docs/plans/README.md +489 -0
- package/docs/plans/aggregate_platforms.mjs +146 -0
- package/docs/plans/examplesession.json +36 -0
- package/docs/plans/missing-facts.md +192 -0
- package/docs/plans/models.md +64 -0
- package/docs/plans/organize.cjs +270 -0
- package/docs/plans/platforms.md +2887 -0
- package/docs/plans/sites.md +31322 -0
- package/docs/platformpipelineaudit.md +6 -2
- package/docs/registryresearch.md +2 -0
- package/docs/release.md +4 -4
- package/docs/release184notes.md +2 -2
- package/docs/release185notes.md +7 -0
- package/docs/releaseassets.md +16 -0
- package/docs/sources/farm.py +117 -0
- package/docs/sources/html/saddle1.html +132 -0
- package/docs/sources/html/saddle2.html +157 -0
- package/docs/sources/html/saddle3.html +119 -0
- package/docs/sources/html/saddle4.html +144 -0
- package/docs/sources/html/saddle5.html +72 -0
- package/docs/sources/html/saddle6.html +171 -0
- package/docs/sources/html/saddle7.html +236 -0
- package/docs/sources/saddle.ts +74 -0
- package/docs/sources/schema.prisma +88 -0
- package/docs/sources/script.sh +64 -0
- package/docs/sources/workflows.yml +458 -0
- package/docs/talks1/_body.txt +14 -0
- package/docs/talks1/_index.md +15 -0
- package/docs/talks1/_screenshot.png +0 -0
- package/docs/talks1/assistant-01.md +5 -0
- package/docs/talks1/assistant-02.md +5 -0
- package/docs/talks1/assistant-03.md +531 -0
- package/docs/talks1/assistant-04.md +26 -0
- package/docs/talks1/assistant-05.md +774 -0
- package/docs/talks1/assistant-06.md +1718 -0
- package/docs/talks1/scrape-share.cjs +185 -0
- package/docs/talks1/scrape-share.ts +183 -0
- package/docs/talks1/user-01.md +3 -0
- package/docs/talks1/user-02.md +3 -0
- package/docs/talks1/user-03.md +88 -0
- package/docs/talks1/user-04.md +3 -0
- package/docs/talks1/user-05.md +3 -0
- package/docs/talks1/user-06.md +88 -0
- package/docs/talks1/user-07.md +88 -0
- package/docs/talks2/_body.txt +14 -0
- package/docs/talks2/_index.md +16 -0
- package/docs/talks2/_screenshot.png +0 -0
- package/docs/talks2/assistant-01.md +5 -0
- package/docs/talks2/assistant-02.md +5 -0
- package/docs/talks2/assistant-03.md +424 -0
- package/docs/talks2/assistant-04.md +598 -0
- package/docs/talks2/assistant-05.md +1280 -0
- package/docs/talks2/assistant-06.md +1227 -0
- package/docs/talks2/assistant-07.md +1252 -0
- package/docs/talks2/user-01.md +3 -0
- package/docs/talks2/user-02.md +3 -0
- package/docs/talks2/user-03.md +88 -0
- package/docs/talks2/user-04.md +88 -0
- package/docs/talks2/user-05.md +88 -0
- package/docs/talks2/user-06.md +88 -0
- package/docs/talks2/user-07.md +3 -0
- package/docs/talks3/_body.txt +467 -0
- package/docs/talks3/_index.md +10 -0
- package/docs/talks3/_screenshot.png +0 -0
- package/docs/talks3/assistant-01.md +417 -0
- package/docs/talks3/assistant-02.md +417 -0
- package/docs/talks3/assistant-03.md +29 -0
- package/docs/talks3/assistant-04.md +727 -0
- package/docs/talks3/user-01.md +88 -0
- package/docs/talks3/user-02.md +88 -0
- package/docs/talks3/user-03.md +3 -0
- package/docs/talks3/user-04.md +3 -0
- package/docs/talks4/_body.txt +14 -0
- package/docs/talks4/_index.md +12 -0
- package/docs/talks4/_screenshot.png +0 -0
- package/docs/talks4/assistant-01.md +5 -0
- package/docs/talks4/assistant-02.md +5 -0
- package/docs/talks4/assistant-03.md +35 -0
- package/docs/talks4/assistant-04.md +512 -0
- package/docs/talks4/assistant-05.md +599 -0
- package/docs/talks4/user-01.md +3 -0
- package/docs/talks4/user-02.md +3 -0
- package/docs/talks4/user-03.md +88 -0
- package/docs/talks4/user-04.md +88 -0
- package/docs/talks4/user-05.md +7 -0
- package/docs/talks5/_body.txt +14 -0
- package/docs/talks5/_index.md +13 -0
- package/docs/talks5/_screenshot.png +0 -0
- package/docs/talks5/assistant-01.md +5 -0
- package/docs/talks5/assistant-02.md +5 -0
- package/docs/talks5/assistant-03.md +690 -0
- package/docs/talks5/assistant-04.md +758 -0
- package/docs/talks5/assistant-05.md +974 -0
- package/docs/talks5/user-01.md +3 -0
- package/docs/talks5/user-02.md +3 -0
- package/docs/talks5/user-03.md +105 -0
- package/docs/talks5/user-04.md +105 -0
- package/docs/talks5/user-05.md +63 -0
- package/docs/talks5/user-06.md +105 -0
- package/docs/talks6/_body.txt +14 -0
- package/docs/talks6/_index.md +9 -0
- package/docs/talks6/_screenshot.png +0 -0
- package/docs/talks6/assistant-01.md +5 -0
- package/docs/talks6/assistant-02.md +5 -0
- package/docs/talks6/assistant-03.md +1499 -0
- package/docs/talks6/user-01.md +3 -0
- package/docs/talks6/user-02.md +3 -0
- package/docs/talks6/user-03.md +88 -0
- package/docs/talks6/user-04.md +88 -0
- package/docs/talks7/_body.txt +14 -0
- package/docs/talks7/_index.md +10 -0
- package/docs/talks7/_screenshot.png +0 -0
- package/docs/talks7/assistant-01.md +5 -0
- package/docs/talks7/assistant-02.md +5 -0
- package/docs/talks7/assistant-03.md +523 -0
- package/docs/talks7/assistant-04.md +617 -0
- package/docs/talks7/user-01.md +3 -0
- package/docs/talks7/user-02.md +3 -0
- package/docs/talks7/user-03.md +105 -0
- package/docs/talks7/user-04.md +67 -0
- package/docs/talks8/conversa1.txt +1322 -0
- package/docs/talks8/conversa2.txt +237 -0
- package/docs/talks9/Beyond the Obvious_ 50 Plataformas Auto-Hospedadas de Forja de C/303/263digo para Al/303/251m de Gitea e GitLab.md" +174 -0
- package/docs/talks9/De NPM a Multi-Linguagem_ Uma Arquitetura T/303/251cnica para a Execu/303/247/303/243o Integrada de C/303/263digo no Ecossistema Node.js.md" +59 -0
- package/docs/talks9/De NPM a VMs Virtuais_ Uma An/303/241lise Arquitet/303/264nica para a Realiza/303/247/303/243o do Ciclo de Vida do Projeto SADDLE.md" +91 -0
- package/docs/talks9/Mapeamento da Engrenagem Computacional_ Uma Arquitetura para Execu/303/247/303/243o Isolada e Persist/303/252ncia em Ambientes Distribu/303/255dos.md" +116 -0
- package/docs/talks9/O Cen/303/241rio Pr/303/241tico do SADDLE_ Uma An/303/241lise de Viabilidade e Modelo de Ciclo de Vida Integrado.md" +128 -0
- package/docs/talks9/README (2).md +489 -0
- package/docs/talks9/README.md +198 -0
- package/docs/talks9/Viabilidade do Saddle_ Uma An/303/241lise T/303/251cnica da Transforma/303/247/303/243o de Armazenamento Remoto em Mem/303/263ria Computacional.md" +80 -0
- package/docs/talks9/conversa.txt +544 -0
- package/docs/talks9/other (2).md +39 -0
- package/docs/talks9/other.md +57 -0
- package/docs/talks9/outro.txt +24 -0
- package/extension/README.md +2 -2
- package/extension/build.js +1 -1
- package/extension/content.js +46 -4
- package/extension/manifest.json +1 -1
- package/extension/pagebridge.js +41 -0
- package/extension/protocol.js +21 -2
- package/extension/serviceworker.js +12 -5
- package/package.json +165 -10
- package/release/assets.js +70 -0
- package/scrape/agent.ts +122 -0
- package/scrape/batch.ts +79 -0
- package/scrape/biome.json +76 -0
- package/scrape/browser.ts +222 -0
- package/scrape/cache.ts +84 -0
- package/scrape/chunking.ts +193 -0
- package/scrape/cli.ts +105 -0
- package/scrape/crawler.ts +115 -0
- package/scrape/dev-server.ts +94 -0
- package/scrape/errors.ts +132 -0
- package/scrape/events.ts +26 -0
- package/scrape/extract.ts +165 -0
- package/scrape/fetch.ts +105 -0
- package/scrape/formats.ts +85 -0
- package/scrape/headers.ts +71 -0
- package/scrape/index.ts +92 -0
- package/scrape/jsdom.d.ts +6 -0
- package/scrape/llms-txt.ts +84 -0
- package/scrape/middleware.ts +90 -0
- package/scrape/package-lock.json +9397 -0
- package/scrape/package.json +1420 -0
- package/scrape/pool.ts +95 -0
- package/scrape/port.ts +18 -0
- package/scrape/proxy.ts +103 -0
- package/scrape/rate-limiter.ts +95 -0
- package/scrape/renderer.ts +194 -0
- package/scrape/retry.ts +64 -0
- package/scrape/robots.ts +137 -0
- package/scrape/scrape.ts +123 -0
- package/scrape/serialize.ts +310 -0
- package/scrape/server.ts +137 -0
- package/scrape/session.ts +109 -0
- package/scrape/sitemap.ts +131 -0
- package/scrape/tokens.ts +45 -0
- package/scrape/tsconfig.json +28 -0
- package/scrape/types.ts +214 -0
- package/scrape/utils.ts +77 -0
- package/scrape/vite.config.ts +55 -0
- package/scrape/vitest.config.ts +17 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const ROOT = __dirname; // docs/plans
|
|
6
|
+
const MESSY = path.join(ROOT, 'messy');
|
|
7
|
+
const APPLY = process.argv.includes('--apply');
|
|
8
|
+
|
|
9
|
+
// Boilerplate that pollutes the messy files ("mocado"):
|
|
10
|
+
// - the whole V8-FLAT preamble block
|
|
11
|
+
// - the repeated "SQL Sentido ..." template fragment
|
|
12
|
+
function isBoilerplateLine(l) {
|
|
13
|
+
return (
|
|
14
|
+
/V8 ?FLAT/i.test(l) ||
|
|
15
|
+
/Este arquivo faz parte da estrutura/i.test(l) ||
|
|
16
|
+
/Todo conteudo V1-V7/i.test(l) ||
|
|
17
|
+
/migrado para arquivos planos numerados/i.test(l) ||
|
|
18
|
+
/^>\s*V8/i.test(l) ||
|
|
19
|
+
/^Regra:/i.test(l) ||
|
|
20
|
+
/^-\s*(NOME|SEM|Flat)\b/i.test(l) ||
|
|
21
|
+
/Conteudo original de:/i.test(l) ||
|
|
22
|
+
/^SQL Sentido/i.test(l) ||
|
|
23
|
+
/^E DDL\. E CREATE/i.test(l) ||
|
|
24
|
+
/^Trigger: \/api\/init/i.test(l)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// strip every boilerplate line, collapse 3+ blank lines into 2, trim
|
|
29
|
+
function stripStub(text) {
|
|
30
|
+
const stripped = text
|
|
31
|
+
.split(/\r?\n/)
|
|
32
|
+
.filter((l) => !isBoilerplateLine(l))
|
|
33
|
+
.join('\n');
|
|
34
|
+
return stripped.replace(/\n{3,}/g, '\n\n').trim() + (stripped.includes('\n') ? '\n' : '');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// a file is a pure stub if, after stripping boilerplate, only a title/whitespace remains
|
|
38
|
+
function isStub(text) {
|
|
39
|
+
const body = stripStub(text)
|
|
40
|
+
.replace(/^#{1,6}\s.*$/m, '')
|
|
41
|
+
.replace(/[\r\n#*`>\-\s]/g, '')
|
|
42
|
+
.trim();
|
|
43
|
+
return body.length < 50;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const normExt = (n) => path.extname(n).toLowerCase().replace(/^\./, '');
|
|
47
|
+
const hash = (b) => crypto.createHash('sha256').update(b).digest('hex');
|
|
48
|
+
|
|
49
|
+
// canonical docs (md/txt) -> numbered plans doc. TXT and MD are the same: result is MD.
|
|
50
|
+
const DOCS = [
|
|
51
|
+
['README.md', '47.multiforge.readme.md'],
|
|
52
|
+
['V4 TEORIA COMPLETA.md', '48.theory.v4.repo.os.md'],
|
|
53
|
+
['V5 THIRD PARTY.md', '49.third.party.infra.md'],
|
|
54
|
+
['V6 FILE AS COMPUTE.md', '50.file.as.compute.md'],
|
|
55
|
+
['ARCHITECTURE.md', '51.architecture.virtual.processor.md'],
|
|
56
|
+
['000 Manifesto V8 Flat.txt', '52.manifesto.v8.md'],
|
|
57
|
+
['001 Documentacao Objetivo.md', '53.objective.md'],
|
|
58
|
+
['002 Documentacao Arquitetura Flat.md', '54.architecture.flat.md'],
|
|
59
|
+
['003 Documentacao V7 Postmortem Pastas.md', '55.v7.postmortem.md'],
|
|
60
|
+
['004 Documentacao Regras Nomenclatura.md', '56.naming.rules.md'],
|
|
61
|
+
['005 Documentacao Indice Completo.md', '57.index.complete.md'],
|
|
62
|
+
['10 CDNS.md', '58.cdn.list.md'],
|
|
63
|
+
['SQL FRAMEWORKS.md', '59.sql.frameworks.md'],
|
|
64
|
+
['1 sql thirdparty.md', '60.sql.thirdparty.md'],
|
|
65
|
+
['1 Objetivo.md', '61.objective.multiforge.md'],
|
|
66
|
+
['1 huggingface upload.md', '62.huggingface.upload.md'],
|
|
67
|
+
['1 kaggle upload.md', '63.kaggle.upload.md'],
|
|
68
|
+
['1 npm storage.md', '64.npm.storage.md'],
|
|
69
|
+
['1 rclone terabox.md', '65.rclone.terabox.md'],
|
|
70
|
+
['Human-Operator-Relatório-Completo.md', '69.report.human.operator.md'],
|
|
71
|
+
['Relatório-Brain2Qwerty-+-Acupuntura-vs-EMS.md', '70.report.brain2qwerty.ems.md'],
|
|
72
|
+
['Relatório-HD-Infinito-e-VRAM-Limites-e-Arquitetura-Viável.md', '71.report.hd.infinito.vram.md'],
|
|
73
|
+
['Plano-30-Soluções-HD-Infinito-via-Node.md', '72.plan.hd.infinito.node.md'],
|
|
74
|
+
['Plano-de-Tópicos-Sci-Fi-com-Repos.md', '73.plan.scifi.repos.md'],
|
|
75
|
+
];
|
|
76
|
+
const DOC_SRC_SET = new Set(DOCS.map((d) => d[0]));
|
|
77
|
+
|
|
78
|
+
// stale stub-topic fragments (011-050) are routed into these consolidation docs
|
|
79
|
+
const TODO_BASE = {
|
|
80
|
+
'66.buckets.and.models.todo.md':
|
|
81
|
+
'# Buckets & Models (TODO)\n\nConsolidated placeholder for stub topics originally in `docs/plans/messy` (011-018).\n\n- Hugging Face Datasets bucket\n- Hugging Face Models bucket\n- Cloudflare R2 config\n- Local file system\n- Whisper transcription\n- Embeddings / vectors\n- LLM classification\n- Vision OCR\n\nSee also: `10.cloudinary.storage.md`, `08.production.infra.md`.',
|
|
82
|
+
'67.database.todo.md':
|
|
83
|
+
'# Database (TODO)\n\nConsolidated placeholder for stub topics originally in `docs/plans/messy` (019-025).\n\n- Prisma schema\n- Drizzle schema\n- SQLite local\n- Turso / libSQL\n- Postgres Neon\n- Auto migrations\n- BigInt pointers\n\nSee also: `09.database.schema.md`, `06.dependencies.md`.',
|
|
84
|
+
'68.deploy.packages.todo.md':
|
|
85
|
+
'# Deploy & Packages (TODO)\n\nConsolidated placeholder for stub topics originally in `docs/plans/messy` (032-050).\n\n- Vercel config\n- Package scripts\n- Env vars\n- Build pipeline\n- Packages: better-sqlite3, libsql-client, drizzle-orm, prisma-client, vercel-blob, netlify-blobs, unstorage, piscina, p-queue, isolated-vm\n- Storage queue / atomic rename / pending jobs\n\nSee also: `37.deploystrategy.md`, `40.npm.publish.md`, `09.database.schema.md`, `21.research.batch.concurrency.md`, `04.research.sandbox.ai.md`, `24.research.memory.persistence.md`.',
|
|
86
|
+
};
|
|
87
|
+
const TODO_ORDER = [
|
|
88
|
+
'66.buckets.and.models.todo.md',
|
|
89
|
+
'67.database.todo.md',
|
|
90
|
+
'68.deploy.packages.todo.md',
|
|
91
|
+
];
|
|
92
|
+
const notesByTodo = {
|
|
93
|
+
'66.buckets.and.models.todo.md': new Map(),
|
|
94
|
+
'67.database.todo.md': new Map(),
|
|
95
|
+
'68.deploy.packages.todo.md': new Map(),
|
|
96
|
+
};
|
|
97
|
+
function routeNote(dest, h, content) {
|
|
98
|
+
const m = notesByTodo[dest];
|
|
99
|
+
if (!m.has(h)) m.set(h, content);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// merged single-file name per code extension (formats kept separate)
|
|
103
|
+
const CODE_NAME = {
|
|
104
|
+
ts: 'saddle.ts',
|
|
105
|
+
sh: 'script.sh',
|
|
106
|
+
py: 'farm.py',
|
|
107
|
+
prisma: 'schema.prisma',
|
|
108
|
+
yml: 'workflows.yml',
|
|
109
|
+
yaml: 'workflows.yaml',
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
function walk(dir) {
|
|
113
|
+
const out = [];
|
|
114
|
+
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
115
|
+
const full = path.join(dir, e.name);
|
|
116
|
+
if (e.isDirectory()) walk(full).forEach((x) => out.push(x));
|
|
117
|
+
else if (e.isFile()) out.push(full);
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const all = walk(MESSY);
|
|
123
|
+
const actions = [];
|
|
124
|
+
const outputs = []; // { dest, content }
|
|
125
|
+
const codeByExt = {};
|
|
126
|
+
const htmlSeen = new Set();
|
|
127
|
+
const htmlOut = [];
|
|
128
|
+
const mdDocSeen = new Set();
|
|
129
|
+
let docStray = 74;
|
|
130
|
+
let nDoc = 0;
|
|
131
|
+
let nCode = 0;
|
|
132
|
+
let nHtml = 0;
|
|
133
|
+
|
|
134
|
+
// 1) canonical docs
|
|
135
|
+
for (const [src, dest] of DOCS) {
|
|
136
|
+
const abs = path.join(MESSY, src);
|
|
137
|
+
if (!fs.existsSync(abs)) {
|
|
138
|
+
actions.push(`MISSING ${src}`);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
let raw;
|
|
142
|
+
try {
|
|
143
|
+
raw = fs.readFileSync(abs, 'utf8');
|
|
144
|
+
} catch {
|
|
145
|
+
actions.push(`READERR ${src}`);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const clean = stripStub(raw);
|
|
149
|
+
if (isStub(clean)) {
|
|
150
|
+
actions.push(`SKIP-STUB ${src}`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
mdDocSeen.add(hash(Buffer.from(clean)));
|
|
154
|
+
outputs.push({ dest, content: clean });
|
|
155
|
+
nDoc++;
|
|
156
|
+
actions.push(`DOC ${src} -> ${dest}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 2) everything else: merge code per ext, keep html separate, catch stray md/txt
|
|
160
|
+
for (const f of all) {
|
|
161
|
+
const rel = path.relative(MESSY, f);
|
|
162
|
+
const ext = normExt(f);
|
|
163
|
+
let raw;
|
|
164
|
+
try {
|
|
165
|
+
raw = fs.readFileSync(f, 'utf8');
|
|
166
|
+
} catch {
|
|
167
|
+
continue; // binary / unreadable -> skip
|
|
168
|
+
}
|
|
169
|
+
const clean = stripStub(raw);
|
|
170
|
+
if (isStub(clean)) continue; // drop stubs (incl. the "SQL Sentido" template-only files)
|
|
171
|
+
|
|
172
|
+
if (ext === 'md' || ext === 'txt') {
|
|
173
|
+
if (DOC_SRC_SET.has(rel)) continue; // already handled as canonical doc
|
|
174
|
+
const h = hash(Buffer.from(clean));
|
|
175
|
+
const n = parseInt((path.basename(f).match(/^(\d+)/) || [])[1] || '0', 10);
|
|
176
|
+
if (n >= 11 && n <= 18) { routeNote('66.buckets.and.models.todo.md', h, clean); actions.push(`NOTE 66 <- ${rel}`); continue; }
|
|
177
|
+
if (n >= 19 && n <= 25) { routeNote('67.database.todo.md', h, clean); actions.push(`NOTE 67 <- ${rel}`); continue; }
|
|
178
|
+
if (n >= 32 && n <= 50) { routeNote('68.deploy.packages.todo.md', h, clean); actions.push(`NOTE 68 <- ${rel}`); continue; }
|
|
179
|
+
// other genuinely-real md/txt -> keep as separate numbered doc
|
|
180
|
+
if (mdDocSeen.has(h)) continue;
|
|
181
|
+
mdDocSeen.add(h);
|
|
182
|
+
const base = path
|
|
183
|
+
.basename(f)
|
|
184
|
+
.replace(/\.[^.]+$/, '')
|
|
185
|
+
.toLowerCase()
|
|
186
|
+
.replace(/[^a-z0-9]+/g, '.');
|
|
187
|
+
const dest = `${docStray++}.${base}.md`;
|
|
188
|
+
outputs.push({ dest, content: clean });
|
|
189
|
+
nDoc++;
|
|
190
|
+
actions.push(`DOC* ${rel} -> ${dest}`);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (ext === 'html') {
|
|
195
|
+
const h = hash(Buffer.from(clean));
|
|
196
|
+
if (htmlSeen.has(h)) continue;
|
|
197
|
+
htmlSeen.add(h);
|
|
198
|
+
const name = path.basename(f).replace(/[ ()]/g, '_');
|
|
199
|
+
htmlOut.push({ name, content: clean });
|
|
200
|
+
nHtml++;
|
|
201
|
+
actions.push(`HTML ${rel}`);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// code / other text formats -> merge into one file per extension (no name prefixes)
|
|
206
|
+
const arr = codeByExt[ext] || (codeByExt[ext] = []);
|
|
207
|
+
const h = hash(Buffer.from(clean));
|
|
208
|
+
if (arr.some((x) => x.hash === h)) continue; // skip byte-identical copies
|
|
209
|
+
arr.push({ content: clean, hash: h });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 3) build merged code files (one per extension; concatenated clean content, skip empty)
|
|
213
|
+
for (const ext of Object.keys(codeByExt).sort()) {
|
|
214
|
+
const parts = codeByExt[ext];
|
|
215
|
+
const body = parts
|
|
216
|
+
.map((p) => p.content)
|
|
217
|
+
.join('\n\n')
|
|
218
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
219
|
+
.trim();
|
|
220
|
+
if (isStub(body)) {
|
|
221
|
+
actions.push(`SKIP-MERGE ${ext} (boilerplate only)`);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const name = CODE_NAME[ext] || `all.${ext}`;
|
|
225
|
+
outputs.push({ dest: `sources/${name}`, content: body + '\n' });
|
|
226
|
+
nCode++;
|
|
227
|
+
actions.push(`MERGE ${ext} (${parts.length}) -> sources/${name}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 4) html outputs
|
|
231
|
+
for (const h of htmlOut) {
|
|
232
|
+
outputs.push({ dest: `sources/html/${h.name}`, content: h.content });
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// 5) consolidation docs (66/67/68) with any captured real fragments
|
|
236
|
+
const todoDocs = TODO_ORDER.map((dest) => {
|
|
237
|
+
let c = TODO_BASE[dest];
|
|
238
|
+
const notes = [...notesByTodo[dest].values()];
|
|
239
|
+
if (notes.length) {
|
|
240
|
+
c += '\n\n## Captured notes (real fragments from messy/)\n';
|
|
241
|
+
for (const note of notes) c += `\n---\n\n${note}\n`;
|
|
242
|
+
}
|
|
243
|
+
return [dest, c];
|
|
244
|
+
});
|
|
245
|
+
for (const [dest, content] of todoDocs) {
|
|
246
|
+
outputs.push({ dest, content });
|
|
247
|
+
actions.push(`CREATE ${dest}`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const lines = [...actions];
|
|
251
|
+
if (APPLY) {
|
|
252
|
+
const srcDir = path.join(ROOT, 'sources');
|
|
253
|
+
if (fs.existsSync(srcDir)) fs.rmSync(srcDir, { recursive: true, force: true });
|
|
254
|
+
for (const o of outputs) {
|
|
255
|
+
const p = path.join(ROOT, o.dest);
|
|
256
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
257
|
+
fs.writeFileSync(p, o.content);
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
fs.rmSync(MESSY, { recursive: true, force: true });
|
|
261
|
+
lines.push('removed messy/');
|
|
262
|
+
} catch (e) {
|
|
263
|
+
lines.push('messy/ not removed: ' + e.message);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
lines.push('');
|
|
267
|
+
lines.push(
|
|
268
|
+
`${APPLY ? '[APPLY] ' : '[DRY-RUN] '}docs=${nDoc} codeMerge(exts)=${nCode} html=${nHtml} todo=${todoDocs.length} totalOutputs=${outputs.length}`
|
|
269
|
+
);
|
|
270
|
+
console.log(lines.join('\n'));
|