textoneitor 0.0.0-stage → 1.2.1

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 (77) hide show
  1. package/LICENSE +101 -0
  2. package/LICENSE-AGPL-3.0 +661 -0
  3. package/README.md +69 -2
  4. package/dist/api/index.d.ts +34 -0
  5. package/dist/api/index.js +98 -0
  6. package/dist/baseline/index.d.ts +20 -0
  7. package/dist/baseline/index.js +81 -0
  8. package/dist/bundle/dist/cli.mjs +29861 -0
  9. package/dist/bundle/package.json +6 -0
  10. package/dist/bundle/rulepack/rulepack.json +1496 -0
  11. package/dist/bundle/rules/situaciones.yml +27 -0
  12. package/dist/cli/benchmark.d.ts +89 -0
  13. package/dist/cli/benchmark.js +185 -0
  14. package/dist/cli/main.d.ts +2 -0
  15. package/dist/cli/main.js +357 -0
  16. package/dist/config/core.d.ts +55 -0
  17. package/dist/config/core.js +244 -0
  18. package/dist/config/glob.d.ts +2 -0
  19. package/dist/config/glob.js +72 -0
  20. package/dist/config/index.d.ts +8 -0
  21. package/dist/config/index.js +38 -0
  22. package/dist/config/situaciones.d.ts +17 -0
  23. package/dist/config/situaciones.js +43 -0
  24. package/dist/contracts/index.d.ts +238 -0
  25. package/dist/contracts/index.js +4 -0
  26. package/dist/document/index.d.ts +10 -0
  27. package/dist/document/index.js +68 -0
  28. package/dist/document/text.d.ts +22 -0
  29. package/dist/document/text.js +91 -0
  30. package/dist/document/tokenize.d.ts +4 -0
  31. package/dist/document/tokenize.js +59 -0
  32. package/dist/markdown/index.d.ts +7 -0
  33. package/dist/markdown/index.js +178 -0
  34. package/dist/paths.d.ts +4 -0
  35. package/dist/paths.js +14 -0
  36. package/dist/reporters/index.d.ts +29 -0
  37. package/dist/reporters/index.js +182 -0
  38. package/dist/rules/compiler/build.d.ts +1 -0
  39. package/dist/rules/compiler/build.js +46 -0
  40. package/dist/rules/compiler/index.d.ts +40 -0
  41. package/dist/rules/compiler/index.js +343 -0
  42. package/dist/rules/compiler/safety.d.ts +16 -0
  43. package/dist/rules/compiler/safety.js +124 -0
  44. package/dist/rules/detectors/index.d.ts +4 -0
  45. package/dist/rules/detectors/index.js +636 -0
  46. package/dist/rules/detectors/shared.d.ts +30 -0
  47. package/dist/rules/detectors/shared.js +87 -0
  48. package/dist/rules/runtime/index.d.ts +17 -0
  49. package/dist/rules/runtime/index.js +74 -0
  50. package/dist/runner/index.d.ts +16 -0
  51. package/dist/runner/index.js +171 -0
  52. package/dist/runner/lint-text.d.ts +19 -0
  53. package/dist/runner/lint-text.js +20 -0
  54. package/dist/scoring/index.d.ts +16 -0
  55. package/dist/scoring/index.js +41 -0
  56. package/dist/suppressions/index.d.ts +23 -0
  57. package/dist/suppressions/index.js +86 -0
  58. package/dist/web/engine.meta.json +1 -0
  59. package/dist/web/engine.mjs +11018 -0
  60. package/dist/web/index.d.ts +39 -0
  61. package/dist/web/index.js +37 -0
  62. package/dist/web/node-crypto-shim.d.ts +9 -0
  63. package/dist/web/node-crypto-shim.js +24 -0
  64. package/dist/web/sha256.d.ts +11 -0
  65. package/dist/web/sha256.js +89 -0
  66. package/package.json +88 -4
  67. package/rulepack/rulepack.json +1496 -0
  68. package/rules/profiles/academico.yml +4 -0
  69. package/rules/profiles/chat.yml +4 -0
  70. package/rules/profiles/correo.yml +3 -0
  71. package/rules/profiles/general.yml +2 -0
  72. package/rules/profiles/marketing.yml +4 -0
  73. package/rules/profiles/readme.yml +5 -0
  74. package/rules/profiles/redes.yml +6 -0
  75. package/rules/profiles/tecnico.yml +4 -0
  76. package/rules/situaciones.yml +27 -0
  77. package/schemas/rule.schema.json +90 -0
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Motor para el navegador. Mismo análisis que la CLI, sin disco y sin red.
3
+ *
4
+ * La CLI descubre archivos, lee `textoneitor.yml` y escribe informes; nada de eso existe
5
+ * aquí. Lo que queda es el análisis de un texto, que es el mismo código
6
+ * (`runner/lint-text.ts`) y el mismo Rule Pack. `test/web-parity.test.ts` comprueba que
7
+ * los dos caminos devuelven exactamente los mismos hallazgos y el mismo índice.
8
+ *
9
+ * El Rule Pack no se empaqueta con el motor: se pasa desde fuera, para que la web sirva
10
+ * el `rulepack.json` de la versión que tenga instalada y no una copia congelada.
11
+ */
12
+ import type { Config, FileResult, ProfileName, Register, RulePack } from "../contracts/index.js";
13
+ import { type RunnerContext } from "../runner/lint-text.js";
14
+ export type { Config, FileResult, Finding, ProfileName, Register, RulePack, ScoreResult } from "../contracts/index.js";
15
+ export type { RunnerContext } from "../runner/lint-text.js";
16
+ export { SCHEMA_VERSION } from "../contracts/index.js";
17
+ export { defaultConfig, resolveEffectiveRules, PROFILES } from "../config/core.js";
18
+ export { computeScore } from "../scoring/index.js";
19
+ export interface WebContextOptions {
20
+ /** Rule Pack ya cargado (`rulepack/rulepack.json` del paquete). */
21
+ pack: RulePack;
22
+ /** Perfil de situación. Por defecto `general`. */
23
+ profile?: ProfileName;
24
+ /** Registro. Por defecto el que traiga la configuración base. */
25
+ register?: Register;
26
+ /** Ajustes sueltos, con las mismas claves que `textoneitor.yml`. */
27
+ config?: Partial<Config>;
28
+ }
29
+ export declare function createWebContext(opts: WebContextOptions): RunnerContext;
30
+ export interface LintTextOptions {
31
+ /** Ruta ficticia que decide el formato y los overrides por ruta. `texto.md` analiza como Markdown. */
32
+ relPath?: string;
33
+ format?: "text" | "markdown";
34
+ }
35
+ /** Analiza un texto. Devuelve los mismos hallazgos y el mismo índice que `textoneitor lint`. */
36
+ export declare function lintText(text: string, ctx: RunnerContext, opts?: LintTextOptions): FileResult;
37
+ /** Atajo para un solo análisis suelto. */
38
+ export declare function lintOnce(text: string, opts: WebContextOptions & LintTextOptions): FileResult;
39
+ export declare const availableProfiles: ProfileName[];
@@ -0,0 +1,37 @@
1
+ import { defaultConfig, mergeConfig, validateConfigObject, PROFILES } from "../config/core.js";
2
+ import { lintDocumentText } from "../runner/lint-text.js";
3
+ import { SCHEMA_VERSION } from "../contracts/index.js";
4
+ export { SCHEMA_VERSION } from "../contracts/index.js";
5
+ export { defaultConfig, resolveEffectiveRules, PROFILES } from "../config/core.js";
6
+ export { computeScore } from "../scoring/index.js";
7
+ export function createWebContext(opts) {
8
+ const { pack } = opts;
9
+ if (pack.schema_version !== SCHEMA_VERSION) {
10
+ throw new Error(`Rule Pack con schema_version ${pack.schema_version}; se esperaba ${SCHEMA_VERSION}.`);
11
+ }
12
+ const raw = { ...(opts.config ?? {}) };
13
+ if (opts.profile)
14
+ raw.profile = opts.profile;
15
+ if (opts.register)
16
+ raw.register = opts.register;
17
+ const issues = validateConfigObject(raw);
18
+ if (issues.length) {
19
+ throw new Error(`Configuración inválida: ${issues.map((i) => `${i.path}: ${i.message}`).join("; ")}`);
20
+ }
21
+ return {
22
+ config: mergeConfig(defaultConfig(), raw),
23
+ root: "/",
24
+ pack,
25
+ toolVersion: pack.version,
26
+ };
27
+ }
28
+ /** Analiza un texto. Devuelve los mismos hallazgos y el mismo índice que `textoneitor lint`. */
29
+ export function lintText(text, ctx, opts = {}) {
30
+ return lintDocumentText(text, ctx, opts);
31
+ }
32
+ /** Atajo para un solo análisis suelto. */
33
+ export function lintOnce(text, opts) {
34
+ const { pack, profile, register, config, ...rest } = opts;
35
+ return lintText(text, createWebContext({ pack, profile, register, config }), rest);
36
+ }
37
+ export const availableProfiles = PROFILES;
@@ -0,0 +1,9 @@
1
+ interface Hash {
2
+ update(chunk: string): Hash;
3
+ digest(encoding: "hex"): string;
4
+ }
5
+ export declare function createHash(algorithm: string): Hash;
6
+ declare const _default: {
7
+ createHash: typeof createHash;
8
+ };
9
+ export default _default;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Sustituto de `node:crypto` para el bundle de navegador. Solo cubre lo que usa el motor:
3
+ * `createHash("sha256").update(texto).digest("hex")`. El alias lo pone `scripts/bundle-web.mjs`.
4
+ */
5
+ import { sha256Hex } from "./sha256.js";
6
+ export function createHash(algorithm) {
7
+ if (algorithm !== "sha256") {
8
+ throw new Error(`El motor web solo implementa sha256, no ${algorithm}.`);
9
+ }
10
+ let data = "";
11
+ const hash = {
12
+ update(chunk) {
13
+ data += chunk;
14
+ return hash;
15
+ },
16
+ digest(encoding) {
17
+ if (encoding !== "hex")
18
+ throw new Error(`El motor web solo devuelve hex, no ${encoding}.`);
19
+ return sha256Hex(data);
20
+ },
21
+ };
22
+ return hash;
23
+ }
24
+ export default { createHash };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * SHA-256 síncrono en JavaScript puro.
3
+ *
4
+ * El motor calcula la huella de cada hallazgo con `node:crypto`, que no existe en el
5
+ * navegador, y `crypto.subtle` es asíncrono, así que no sirve para una función pura.
6
+ * Esta implementación cubre ese hueco. No es criptografía de seguridad: solo genera la
7
+ * misma huella que Node para que los hallazgos del navegador y los de la CLI sean
8
+ * idénticos, y eso lo verifica `test/web-parity.test.ts`.
9
+ */
10
+ export declare function sha256HexBytes(bytes: Uint8Array): string;
11
+ export declare function sha256Hex(text: string): string;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * SHA-256 síncrono en JavaScript puro.
3
+ *
4
+ * El motor calcula la huella de cada hallazgo con `node:crypto`, que no existe en el
5
+ * navegador, y `crypto.subtle` es asíncrono, así que no sirve para una función pura.
6
+ * Esta implementación cubre ese hueco. No es criptografía de seguridad: solo genera la
7
+ * misma huella que Node para que los hallazgos del navegador y los de la CLI sean
8
+ * idénticos, y eso lo verifica `test/web-parity.test.ts`.
9
+ */
10
+ const K = new Uint32Array([
11
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
12
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
13
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
14
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
15
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
16
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
17
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
18
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
19
+ ]);
20
+ const rotr = (x, n) => ((x >>> n) | (x << (32 - n))) >>> 0;
21
+ const HEX = "0123456789abcdef";
22
+ export function sha256HexBytes(bytes) {
23
+ const h = new Uint32Array([
24
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
25
+ ]);
26
+ const len = bytes.length;
27
+ const total = Math.ceil((len + 9) / 64) * 64;
28
+ const buf = new Uint8Array(total);
29
+ buf.set(bytes);
30
+ buf[len] = 0x80;
31
+ const view = new DataView(buf.buffer);
32
+ const bits = len * 8;
33
+ view.setUint32(total - 8, Math.floor(bits / 0x100000000), false);
34
+ view.setUint32(total - 4, bits >>> 0, false);
35
+ const w = new Uint32Array(64);
36
+ for (let off = 0; off < total; off += 64) {
37
+ for (let i = 0; i < 16; i += 1)
38
+ w[i] = view.getUint32(off + i * 4, false);
39
+ for (let i = 16; i < 64; i += 1) {
40
+ const x = w[i - 15];
41
+ const y = w[i - 2];
42
+ const s0 = (rotr(x, 7) ^ rotr(x, 18) ^ (x >>> 3)) >>> 0;
43
+ const s1 = (rotr(y, 17) ^ rotr(y, 19) ^ (y >>> 10)) >>> 0;
44
+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
45
+ }
46
+ let a = h[0];
47
+ let b = h[1];
48
+ let c = h[2];
49
+ let d = h[3];
50
+ let e = h[4];
51
+ let f = h[5];
52
+ let g = h[6];
53
+ let hh = h[7];
54
+ for (let i = 0; i < 64; i += 1) {
55
+ const S1 = (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) >>> 0;
56
+ const ch = ((e & f) ^ (~e & g)) >>> 0;
57
+ const t1 = (hh + S1 + ch + K[i] + w[i]) >>> 0;
58
+ const S0 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) >>> 0;
59
+ const maj = ((a & b) ^ (a & c) ^ (b & c)) >>> 0;
60
+ const t2 = (S0 + maj) >>> 0;
61
+ hh = g;
62
+ g = f;
63
+ f = e;
64
+ e = (d + t1) >>> 0;
65
+ d = c;
66
+ c = b;
67
+ b = a;
68
+ a = (t1 + t2) >>> 0;
69
+ }
70
+ h[0] = (h[0] + a) >>> 0;
71
+ h[1] = (h[1] + b) >>> 0;
72
+ h[2] = (h[2] + c) >>> 0;
73
+ h[3] = (h[3] + d) >>> 0;
74
+ h[4] = (h[4] + e) >>> 0;
75
+ h[5] = (h[5] + f) >>> 0;
76
+ h[6] = (h[6] + g) >>> 0;
77
+ h[7] = (h[7] + hh) >>> 0;
78
+ }
79
+ let out = "";
80
+ for (let i = 0; i < 8; i += 1) {
81
+ const v = h[i];
82
+ for (let s = 28; s >= 0; s -= 4)
83
+ out += HEX[(v >>> s) & 0xf];
84
+ }
85
+ return out;
86
+ }
87
+ export function sha256Hex(text) {
88
+ return sha256HexBytes(new TextEncoder().encode(text));
89
+ }
package/package.json CHANGED
@@ -1,6 +1,90 @@
1
1
  {
2
2
  "name": "textoneitor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.2.1",
4
+ "description": "Revisor de textos en español: marca lo que suena a máquina (muletillas, rayas de inciso, tríadas, frases todas del mismo largo) y explica por qué. Determinista, sin IA y sin red.",
5
+ "license": "BUSL-1.1",
6
+ "author": "Josulo72 (https://github.com/Josulo72)",
7
+ "homepage": "https://josulo72.github.io/textoneitor/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Josulo72/textoneitor.git",
11
+ "directory": "packages/linter"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/Josulo72/textoneitor/issues"
15
+ },
16
+ "keywords": [
17
+ "español",
18
+ "spanish",
19
+ "escritura",
20
+ "estilo",
21
+ "texto",
22
+ "markdown",
23
+ "revisor",
24
+ "prose",
25
+ "writing",
26
+ "cli",
27
+ "pre-commit",
28
+ "claude-code"
29
+ ],
30
+ "type": "module",
31
+ "main": "./dist/api/index.js",
32
+ "types": "./dist/api/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/api/index.d.ts",
36
+ "import": "./dist/api/index.js"
37
+ },
38
+ "./package.json": "./package.json",
39
+ "./web": {
40
+ "types": "./dist/web/index.d.ts",
41
+ "import": "./dist/web/engine.mjs"
42
+ },
43
+ "./rulepack.json": "./rulepack/rulepack.json"
44
+ },
45
+ "bin": {
46
+ "textoneitor": "./dist/cli/main.js"
47
+ },
48
+ "files": [
49
+ "dist",
50
+ "rulepack",
51
+ "rules/profiles",
52
+ "rules/situaciones.yml",
53
+ "schemas",
54
+ "README.md",
55
+ "LICENSE",
56
+ "LICENSE-AGPL-3.0"
57
+ ],
58
+ "engines": {
59
+ "node": ">=20"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public"
63
+ },
64
+ "scripts": {
65
+ "build": "pnpm run build:ts && pnpm run build:rules && pnpm run build:bundle && pnpm run build:web",
66
+ "build:ts": "tsc -p tsconfig.build.json",
67
+ "build:rules": "node dist/rules/compiler/build.js",
68
+ "build:bundle": "node scripts/bundle.mjs",
69
+ "typecheck": "tsc -p tsconfig.json --noEmit",
70
+ "test": "vitest run",
71
+ "test:watch": "vitest",
72
+ "build:web": "node scripts/bundle-web.mjs",
73
+ "prepublishOnly": "pnpm run build"
74
+ },
75
+ "dependencies": {
76
+ "ajv": "^8.17.0",
77
+ "commander": "^13.0.0",
78
+ "fast-glob": "^3.3.0",
79
+ "ignore": "^7.0.0",
80
+ "mdast-util-from-markdown": "^2.0.0",
81
+ "mdast-util-frontmatter": "^2.0.0",
82
+ "mdast-util-gfm": "^3.0.0",
83
+ "micromark-extension-frontmatter": "^2.0.0",
84
+ "micromark-extension-gfm": "^3.0.0",
85
+ "yaml": "^2.6.0"
86
+ },
87
+ "devDependencies": {
88
+ "@types/mdast": "^4.0.0"
89
+ }
90
+ }