token-goat 2.9.12 → 2.9.14

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 (45) hide show
  1. package/README.md +20 -1
  2. package/dist/token-goat-chunk-2ESBO4IN.mjs +209 -0
  3. package/dist/token-goat-chunk-3BTK54F3.mjs +1733 -0
  4. package/dist/{token-goat-chunk-6NIGPPN6.mjs → token-goat-chunk-3XQPEJMV.mjs} +1 -1
  5. package/dist/token-goat-chunk-4SDX3QP3.mjs +122 -0
  6. package/dist/token-goat-chunk-7OGKZ7AP.mjs +142 -0
  7. package/dist/token-goat-chunk-AH6QILZM.mjs +26 -0
  8. package/dist/token-goat-chunk-AMYCQJX4.mjs +1548 -0
  9. package/dist/{token-goat-chunk-OTW7LC4Y.mjs → token-goat-chunk-ASVVF4JV.mjs} +13 -10
  10. package/dist/{token-goat-chunk-GCXX67HM.mjs → token-goat-chunk-DAMXYVIW.mjs} +12477 -12156
  11. package/dist/token-goat-chunk-DBNY4RLN.mjs +308 -0
  12. package/dist/token-goat-chunk-EG3663UT.mjs +226 -0
  13. package/dist/token-goat-chunk-EZNVAIR3.mjs +21 -0
  14. package/dist/token-goat-chunk-GMOUBOX4.mjs +386 -0
  15. package/dist/{token-goat-chunk-6F5TLJC7.mjs → token-goat-chunk-HF6H7RNK.mjs} +1 -1
  16. package/dist/{token-goat-chunk-GM6QZWCF.mjs → token-goat-chunk-IT6O3PNN.mjs} +2660 -6877
  17. package/dist/token-goat-chunk-NEI4NC54.mjs +424 -0
  18. package/dist/token-goat-chunk-O5WAMISC.mjs +167 -0
  19. package/dist/{token-goat-chunk-LHLQFGWQ.mjs → token-goat-chunk-OMNQUUIT.mjs} +9 -27
  20. package/dist/{token-goat-chunk-SF2CKCFQ.mjs → token-goat-chunk-PGGDW7DZ.mjs} +30 -13
  21. package/dist/token-goat-chunk-POBYR64E.mjs +1632 -0
  22. package/dist/token-goat-chunk-PRJVGIC5.mjs +58 -0
  23. package/dist/{token-goat-chunk-4CK445AW.mjs → token-goat-chunk-RUDOKYPJ.mjs} +10074 -9765
  24. package/dist/token-goat-chunk-SAQ5PG4L.mjs +2634 -0
  25. package/dist/token-goat-chunk-T2IWWTHB.mjs +3155 -0
  26. package/dist/{token-goat-chunk-TOGYS5A7.mjs → token-goat-chunk-VZYD4OZB.mjs} +1469 -5752
  27. package/dist/token-goat-chunk-XEH6KBWW.mjs +23 -0
  28. package/dist/token-goat-chunk-XQF5J25J.mjs +33 -0
  29. package/dist/token-goat-chunk-XTQAOTSO.mjs +89 -0
  30. package/dist/{token-goat-chunk-THLHC6QJ.mjs → token-goat-chunk-XVZ4MNQC.mjs} +614 -603
  31. package/dist/token-goat-chunk-Y4AFKTHK.mjs +22 -0
  32. package/dist/token-goat-chunk-YHGTGG6K.mjs +396 -0
  33. package/dist/{token-goat-chunk-SBYRP3X4.mjs → token-goat-chunk-YTQHZJXW.mjs} +61 -27
  34. package/dist/token-goat-chunk-Z6UXPYJA.mjs +62 -0
  35. package/dist/token-goat-chunk-ZD4EM4LR.mjs +30 -0
  36. package/dist/token-goat-chunk-ZFM4PWXL.mjs +585 -0
  37. package/dist/{token-goat-chunk-A6QTLAWO.mjs → token-goat-chunk-ZYNNQ36L.mjs} +128 -328
  38. package/dist/token-goat-hook.mjs +12 -6
  39. package/dist/token-goat.core.mjs +22 -7
  40. package/docs/cli.md +12 -8
  41. package/docs/security.md +1 -1
  42. package/package.json +4 -2
  43. package/dist/token-goat-chunk-HKFOH6JH.mjs +0 -28
  44. package/dist/token-goat-chunk-LOCOX2ML.mjs +0 -3564
  45. package/dist/token-goat-chunk-VRWX6QYW.mjs +0 -24
@@ -2,7 +2,7 @@ import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  detectHarness
5
- } from "./token-goat-chunk-TOGYS5A7.mjs";
5
+ } from "./token-goat-chunk-SAQ5PG4L.mjs";
6
6
  import {
7
7
  init_define_import_meta_env
8
8
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -0,0 +1,122 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ NotAnOfficeDocumentError,
5
+ collectElements,
6
+ collectTextRuns,
7
+ decodeZipEntry,
8
+ ooxmlPartBudget,
9
+ parseOoxmlPart,
10
+ readOoxmlZip
11
+ } from "./token-goat-chunk-YHGTGG6K.mjs";
12
+ import {
13
+ displaySafeText
14
+ } from "./token-goat-chunk-AMYCQJX4.mjs";
15
+ import {
16
+ init_define_import_meta_env
17
+ } from "./token-goat-chunk-A37V4PBF.mjs";
18
+
19
+ // src/docx_extract.ts
20
+ init_define_import_meta_env();
21
+ function paragraphStyleVal(p) {
22
+ return p["w:pPr"]?.["w:pStyle"]?.["@_w:val"];
23
+ }
24
+ function headingLevel(styleVal) {
25
+ if (styleVal === void 0) return null;
26
+ if (/^title$/i.test(styleVal)) return 1;
27
+ const m = /^heading\s*(\d)$/i.exec(styleVal);
28
+ return m?.[1] !== void 0 ? parseInt(m[1], 10) : null;
29
+ }
30
+ async function loadDocumentBody(filePath) {
31
+ const entries = await readOoxmlZip(filePath, ".docx");
32
+ const xml = decodeZipEntry(entries, "word/document.xml", ooxmlPartBudget());
33
+ if (xml === null) throw new NotAnOfficeDocumentError(`no word/document.xml found in ${filePath} (not a valid .docx?)`);
34
+ return parseOoxmlPart(xml);
35
+ }
36
+ async function docxOutline(filePath) {
37
+ const parsed = await loadDocumentBody(filePath);
38
+ const paragraphs = collectElements(parsed, "w:p");
39
+ const out = [];
40
+ for (const p of paragraphs) {
41
+ const level = headingLevel(paragraphStyleVal(p));
42
+ if (level === null) continue;
43
+ const text = collectTextRuns(p, "w:t").join("").trim();
44
+ if (text.length > 0) out.push({ level, text });
45
+ }
46
+ return out;
47
+ }
48
+ async function docxText(filePath) {
49
+ const parsed = await loadDocumentBody(filePath);
50
+ const paragraphs = collectElements(parsed, "w:p");
51
+ const lines = paragraphs.map((p) => collectTextRuns(p, "w:t").join("")).filter((t) => t.trim().length > 0);
52
+ return lines.join("\n\n");
53
+ }
54
+ async function docxTables(filePath) {
55
+ const parsed = await loadDocumentBody(filePath);
56
+ const tbls = collectElements(parsed, "w:tbl");
57
+ const out = [];
58
+ for (let i = 0; i < tbls.length; i++) {
59
+ const tbl = tbls[i];
60
+ const trElements = collectElements(tbl, "w:tr");
61
+ const rows = [];
62
+ let maxCols = 0;
63
+ for (const tr of trElements) {
64
+ const tcElements = collectElements(tr, "w:tc");
65
+ const rowCells = [];
66
+ for (const tc of tcElements) {
67
+ const cellText = collectTextRuns(tc, "w:t").join("").replace(/\r?\n/g, " ").trim();
68
+ rowCells.push(cellText);
69
+ }
70
+ if (rowCells.length > maxCols) maxCols = rowCells.length;
71
+ rows.push(rowCells);
72
+ }
73
+ if (rows.length > 0) {
74
+ out.push({
75
+ tableIndex: i + 1,
76
+ rowCount: rows.length,
77
+ colCount: maxCols,
78
+ rows
79
+ });
80
+ }
81
+ }
82
+ return out;
83
+ }
84
+ function formatDocxTables(tables, opts) {
85
+ if (tables.length === 0) return "no tables found in document";
86
+ const selected = opts?.tableIndex !== void 0 ? tables.filter((t) => t.tableIndex === opts.tableIndex) : tables;
87
+ if (selected.length === 0) {
88
+ return `table ${opts?.tableIndex} not found (document has ${tables.length} table${tables.length === 1 ? "" : "s"})`;
89
+ }
90
+ const sections = [];
91
+ for (const table of selected) {
92
+ const lines = [
93
+ `Table ${table.tableIndex} (${table.rowCount} row${table.rowCount === 1 ? "" : "s"} x ${table.colCount} col${table.colCount === 1 ? "" : "s"}):`
94
+ ];
95
+ if (table.rows.length === 0) {
96
+ lines.push(" (empty)");
97
+ sections.push(lines.join("\n"));
98
+ continue;
99
+ }
100
+ const header = table.rows[0];
101
+ const padCols = Math.max(table.colCount, 1);
102
+ const paddedHeader = [...header];
103
+ while (paddedHeader.length < padCols) paddedHeader.push("");
104
+ lines.push("| " + paddedHeader.map((c) => displaySafeText(c.replace(/\|/g, "\\|"))).join(" | ") + " |");
105
+ lines.push("| " + Array.from({ length: padCols }, () => "---").join(" | ") + " |");
106
+ for (let r = 1; r < table.rows.length; r++) {
107
+ const row = table.rows[r];
108
+ const paddedRow = [...row];
109
+ while (paddedRow.length < padCols) paddedRow.push("");
110
+ lines.push("| " + paddedRow.map((c) => displaySafeText(c.replace(/\|/g, "\\|"))).join(" | ") + " |");
111
+ }
112
+ sections.push(lines.join("\n"));
113
+ }
114
+ return sections.join("\n\n");
115
+ }
116
+
117
+ export {
118
+ docxOutline,
119
+ docxText,
120
+ docxTables,
121
+ formatDocxTables
122
+ };
@@ -0,0 +1,142 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ loadConfig
5
+ } from "./token-goat-chunk-SAQ5PG4L.mjs";
6
+ import "./token-goat-chunk-EEIDFMEM.mjs";
7
+ import {
8
+ VERSION,
9
+ displaySafeJson
10
+ } from "./token-goat-chunk-AMYCQJX4.mjs";
11
+ import "./token-goat-chunk-GMOUBOX4.mjs";
12
+ import {
13
+ init_define_import_meta_env
14
+ } from "./token-goat-chunk-A37V4PBF.mjs";
15
+
16
+ // src/cli_upgrade.ts
17
+ init_define_import_meta_env();
18
+ import { spawnSync } from "node:child_process";
19
+ import * as fs from "node:fs";
20
+ import * as path from "node:path";
21
+ import * as https from "node:https";
22
+ async function fetchLatestVersion(timeoutMs = 3500) {
23
+ if (loadConfig().network.offline) {
24
+ return null;
25
+ }
26
+ return new Promise((resolve) => {
27
+ const req = https.get(
28
+ "https://registry.npmjs.org/token-goat/latest",
29
+ {
30
+ headers: { "User-Agent": `token-goat/${VERSION} (node/${process.version})` },
31
+ timeout: timeoutMs
32
+ },
33
+ (res) => {
34
+ if (res.statusCode !== 200) {
35
+ res.resume();
36
+ resolve(null);
37
+ return;
38
+ }
39
+ let data = "";
40
+ res.setEncoding("utf8");
41
+ res.on("data", (chunk) => {
42
+ data += chunk;
43
+ if (data.length > 32768) {
44
+ req.destroy();
45
+ resolve(null);
46
+ }
47
+ });
48
+ res.on("end", () => {
49
+ try {
50
+ const parsed = JSON.parse(data);
51
+ resolve(typeof parsed.version === "string" ? parsed.version : null);
52
+ } catch {
53
+ resolve(null);
54
+ }
55
+ });
56
+ }
57
+ );
58
+ req.on("timeout", () => {
59
+ req.destroy();
60
+ resolve(null);
61
+ });
62
+ req.on("error", () => {
63
+ resolve(null);
64
+ });
65
+ });
66
+ }
67
+ function compareSemver(a, b) {
68
+ const pa = a.split("-")[0].split(".").map((x) => parseInt(x, 10) || 0);
69
+ const pb = b.split("-")[0].split(".").map((x) => parseInt(x, 10) || 0);
70
+ for (let i = 0; i < 3; i++) {
71
+ const na = pa[i] ?? 0;
72
+ const nb = pb[i] ?? 0;
73
+ if (na > nb) return 1;
74
+ if (na < nb) return -1;
75
+ }
76
+ return 0;
77
+ }
78
+ async function checkUpdateStatus(timeoutMs = 3500) {
79
+ const latest = await fetchLatestVersion(timeoutMs);
80
+ if (!latest) {
81
+ return {
82
+ current: VERSION,
83
+ latest: null,
84
+ updateAvailable: false,
85
+ error: "Could not reach npm registry (offline or request timed out)"
86
+ };
87
+ }
88
+ const updateAvailable = compareSemver(latest, VERSION) > 0;
89
+ return {
90
+ current: VERSION,
91
+ latest,
92
+ updateAvailable
93
+ };
94
+ }
95
+ async function cmdUpgrade(opts = {}, onSyncHooks) {
96
+ const status = await checkUpdateStatus();
97
+ if (opts.check) {
98
+ if (opts.json) {
99
+ console.log(displaySafeJson(status, 2));
100
+ return;
101
+ }
102
+ if (status.error) {
103
+ console.log(`Current version: v${status.current}`);
104
+ console.log(`[!] ${status.error}`);
105
+ return;
106
+ }
107
+ if (status.updateAvailable && status.latest) {
108
+ console.log(`Update available: v${status.current} -> v${status.latest}`);
109
+ console.log(`Run 'token-goat upgrade' to update.`);
110
+ } else {
111
+ console.log(`token-goat is up to date (v${status.current})`);
112
+ }
113
+ return;
114
+ }
115
+ const isLocalGitRepo = fs.existsSync(path.join(process.cwd(), ".git")) && fs.existsSync(path.join(process.cwd(), "esbuild.config.mjs"));
116
+ if (isLocalGitRepo) {
117
+ console.log(`Detected local token-goat development repository.`);
118
+ console.log(`To update your local build, run:`);
119
+ console.log(` git pull && npm run build && token-goat install`);
120
+ return;
121
+ }
122
+ console.log(`Upgrading token-goat to latest...`);
123
+ const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
124
+ const npmRes = spawnSync(npmCmd, ["install", "-g", "token-goat@latest"], {
125
+ stdio: "inherit"
126
+ });
127
+ if (npmRes.status !== 0) {
128
+ console.error(`npm install failed with exit code ${npmRes.status ?? 1}.`);
129
+ process.exit(npmRes.status ?? 1);
130
+ }
131
+ console.log(`Syncing token-goat hooks and integration manifests...`);
132
+ if (onSyncHooks) {
133
+ await onSyncHooks();
134
+ }
135
+ console.log(`[\u2713] token-goat successfully updated.`);
136
+ }
137
+ export {
138
+ checkUpdateStatus,
139
+ cmdUpgrade,
140
+ compareSemver,
141
+ fetchLatestVersion
142
+ };
@@ -0,0 +1,26 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ init_define_import_meta_env
5
+ } from "./token-goat-chunk-A37V4PBF.mjs";
6
+
7
+ // src/lazy_module.ts
8
+ init_define_import_meta_env();
9
+ function createLazyModuleLoader(load, errorLabel) {
10
+ let cache;
11
+ return async () => {
12
+ if (cache !== void 0) return cache;
13
+ try {
14
+ cache = await load();
15
+ } catch (err) {
16
+ process.stderr.write(`token-goat: ${errorLabel}: ${String(err)}
17
+ `);
18
+ cache = null;
19
+ }
20
+ return cache;
21
+ };
22
+ }
23
+
24
+ export {
25
+ createLazyModuleLoader
26
+ };