@beardedunicorn/thetowersdk 1.0.0 → 1.0.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 (3) hide show
  1. package/README.md +5 -0
  2. package/mcp/server.mjs +38 -8
  3. package/package.json +48 -46
package/README.md CHANGED
@@ -1255,6 +1255,11 @@ pnpm docs:seed # regenerate the wiki pages and the shared code snippets
1255
1255
  pnpm docs:check # fail if any of them are stale (runs in `pnpm verify`)
1256
1256
  ```
1257
1257
 
1258
+ The wiki also carries the game itself — a page for every workshop stat, lab, card, module and
1259
+ ultimate weapon, plus tiers, tournaments, the vault and the patch notes. Those pages are generated
1260
+ by [`scripts/game-wiki/`](scripts/game-wiki) from this package's own data, so they say exactly what
1261
+ the SDK says. Every release regenerates and publishes the wiki from the released tag.
1262
+
1258
1263
  The wiki is rendered by [`scripts/build-wiki.mjs`](scripts/build-wiki.mjs). A GitHub wiki is a
1259
1264
  separate repository that no pull request reviews, so hand-editing it would create a third docs
1260
1265
  surface that silently drifts — every page carries a banner saying so, and an edit made there is
package/mcp/server.mjs CHANGED
@@ -566,17 +566,28 @@ const sampleSize = (limit, fallback = 40, ceiling = MAX_PREVIEW) => {
566
566
  * A path is the one argument here that comes from a person typing, so wrong paths are the ordinary
567
567
  * case rather than the exotic one, and "not a file" deserves a sentence rather than an errno.
568
568
  */
569
- async function readSaveOrExplain(savePath) {
570
- if (typeof savePath !== 'string' || savePath.length === 0) {
569
+ async function readSaveOrExplain(givenPath) {
570
+ if (typeof givenPath !== 'string' || givenPath.trim().length === 0) {
571
571
  return { error: 'decode needs an absolute path to a tool_export.json.' }
572
572
  }
573
573
 
574
+ /*
575
+ * `~` is the shell's, not the filesystem's. A path typed the way a person types one came back
576
+ * as "no file at ~/Downloads/tool_export.json", which reads as "you have not exported yet".
577
+ */
578
+ const savePath = /^~(?=$|[\\/])/.test(givenPath) ? path.join(os.homedir(), givenPath.slice(1)) : givenPath
579
+
574
580
  let stats
575
581
  try {
576
582
  stats = fs.statSync(savePath)
577
583
  }
578
584
  catch {
579
- return { error: `no file at ${savePath}` }
585
+ return {
586
+ error: `no file at ${savePath}`,
587
+ ...(path.isAbsolute(savePath)
588
+ ? {}
589
+ : { hint: `That is a relative path, read from ${process.cwd()}. Give the absolute path to the export.` }),
590
+ }
580
591
  }
581
592
 
582
593
  if (stats.isDirectory()) {
@@ -588,7 +599,11 @@ async function readSaveOrExplain(savePath) {
588
599
  bytes = fs.readFileSync(savePath)
589
600
  }
590
601
  catch (error) {
591
- return { error: `could not read ${savePath}: ${error.message}` }
602
+ return { error: `could not read ${savePath}: ${reasonOf(error)}` }
603
+ }
604
+
605
+ if (bytes.length === 0) {
606
+ return { error: `${savePath} is empty (0 bytes), so there is no export in it. Export again from the game.` }
592
607
  }
593
608
 
594
609
  try {
@@ -598,11 +613,26 @@ async function readSaveOrExplain(savePath) {
598
613
  return {
599
614
  error:
600
615
  `${savePath} is not a tool_export.json, or is incomplete — the decoder reported: `
601
- + `${error.message}`,
616
+ + `${reasonOf(error)}`,
602
617
  }
603
618
  }
604
619
  }
605
620
 
621
+ /**
622
+ * Why something threw, as one line of prose.
623
+ *
624
+ * The decoder validates with a schema, and a schema error's `message` is its issue list as
625
+ * indented JSON. Passed through, an export that was merely the wrong file answered with a
626
+ * bracketed dump of `code`, `path` and `expected` in the middle of a sentence. A thrown value
627
+ * that is not an Error has no `message` at all, and reported "undefined".
628
+ */
629
+ function reasonOf(error) {
630
+ if (Array.isArray(error?.issues) && error.issues.length > 0) {
631
+ return [...new Set(error.issues.map(issue => String(issue?.message ?? 'invalid')))].join('; ')
632
+ }
633
+ return error instanceof Error && error.message ? error.message : String(error)
634
+ }
635
+
606
636
  /**
607
637
  * What one extractor finds, as shape rather than values; `run_extractor` returns the values.
608
638
  *
@@ -614,14 +644,14 @@ function summariseExtractor(extractor, parsedRoot) {
614
644
  result = sdk.save[extractor](parsedRoot)
615
645
  }
616
646
  catch (error) {
617
- return { extractor, found: false, error: error.message }
647
+ return { extractor, found: false, error: reasonOf(error) }
618
648
  }
619
649
  if (result === null || result === undefined) return { extractor, found: false }
620
650
  return {
621
651
  extractor,
622
652
  found: true,
623
- ...(Array.isArray(result) ? { count: result.length } : { fields: Object.keys(result) }),
624
- warnings: result.warnings?.length ?? 0,
653
+ ...(Array.isArray(result) ? { count: result.length } : { fields: isRecord(result) ? Object.keys(result) : [] }),
654
+ warnings: Array.isArray(result.warnings) ? result.warnings.length : 0,
625
655
  }
626
656
  }
627
657
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beardedunicorn/thetowersdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Game data and save-file reading for The Tower — build your own calculators and tools.",
5
5
  "license": "MIT",
6
6
  "author": "Mike Herold (https://github.com/BeardedUnicorn)",
@@ -33,11 +33,56 @@
33
33
  ],
34
34
  "publishConfig": {
35
35
  "access": "public",
36
- "registry": "https://registry.npmjs.org"
36
+ "registry": "https://registry.npmjs.org/"
37
37
  },
38
+ "packageManager": "pnpm@12.21.0+sha512.66fd8278ee28935ce951792d34367ff3af5c432a2756445823029533835b8da529bbe0be5130afd56ed0713fb8789e47bad82d93bd5ae2fe54b15562d6276ef0",
38
39
  "engines": {
39
40
  "node": ">=22"
40
41
  },
42
+ "scripts": {
43
+ "build": "pnpm run clean && tsc -p tsconfig.build.json && node scripts/copy-assets.mjs && pnpm run knowledge:emit",
44
+ "knowledge:emit": "node scripts/emit-knowledge-graph.mjs",
45
+ "daily-missions:goals": "node scripts/build-daily-mission-goals.mjs",
46
+ "labs:categories": "node scripts/build-lab-categories.mjs",
47
+ "clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\"",
48
+ "test": "vitest run",
49
+ "type-check": "tsc -p tsconfig.build.json --noEmit",
50
+ "type-check:examples": "tsc -p tsconfig.examples.json",
51
+ "prepublishOnly": "pnpm run clean && pnpm run build",
52
+ "lint": "eslint .",
53
+ "lint:fix": "eslint . --fix",
54
+ "lint:docs": "node scripts/check-readme-links.mjs",
55
+ "wiki:build": "node scripts/build-wiki.mjs",
56
+ "wiki:publish": "node scripts/publish-wiki.mjs",
57
+ "wiki:check": "node scripts/build-wiki.mjs --check",
58
+ "lint:published": "node scripts/audit-published-surface.mjs",
59
+ "lint:specifiers": "node scripts/check-sdk-specifiers.mjs",
60
+ "examples:run": "node scripts/run-examples.mjs",
61
+ "lint:conventions": "node scripts/check-conventions.mjs",
62
+ "lint:boundaries": "node scripts/check-source-boundaries.mjs",
63
+ "lint:organization": "node scripts/check-organization.mjs",
64
+ "map": "node scripts/map-the-repo.mjs",
65
+ "lint:map": "node scripts/map-the-repo.mjs --check",
66
+ "lint:acronyms": "tsx scripts/check-acronym-expansions.ts",
67
+ "test:schema": "vitest run tests/data/schemas.test.ts tests/data/schemas-cover-what-they-claim.test.ts",
68
+ "verify": "node scripts/verify.mjs",
69
+ "verify:serial": "node scripts/verify.mjs --serial",
70
+ "mcp": "node mcp/server.mjs",
71
+ "glossary": "pnpm run build && node scripts/generate-glossary.mjs",
72
+ "bot:demo": "tsx templates/bot-starter.ts",
73
+ "bot:test": "vitest run src/bot",
74
+ "sheets:test": "vitest run src/sheets",
75
+ "docs:snippets": "node scripts/build-doc-snippets.mjs",
76
+ "docs:seed": "pnpm run docs:snippets && pnpm run wiki:build",
77
+ "docs:check": "node scripts/build-doc-snippets.mjs --check && pnpm run wiki:check && node scripts/check-readme-links.mjs && node scripts/build-patch-notes.mjs --check",
78
+ "patch-notes:ingest": "node scripts/ingest-patch-notes.mjs",
79
+ "patch-notes:build": "node scripts/build-patch-notes.mjs",
80
+ "wasm:build": "node wasm/build.mjs",
81
+ "wasm:check": "node wasm/build.mjs --check",
82
+ "wasm:call": "node wasm/run.mjs",
83
+ "lint:package": "node scripts/audit-package-contents.mjs",
84
+ "epaths:refresh-reference": "node scripts/refresh-effective-paths-reference.mjs"
85
+ },
41
86
  "exports": {
42
87
  ".": {
43
88
  "types": "./dist/index.d.ts",
@@ -199,48 +244,5 @@
199
244
  "typescript-eslint": "^8.73.0",
200
245
  "vite": "^7.3.8",
201
246
  "vitest": "^5.1.1"
202
- },
203
- "scripts": {
204
- "build": "pnpm run clean && tsc -p tsconfig.build.json && node scripts/copy-assets.mjs && pnpm run knowledge:emit",
205
- "knowledge:emit": "node scripts/emit-knowledge-graph.mjs",
206
- "daily-missions:goals": "node scripts/build-daily-mission-goals.mjs",
207
- "labs:categories": "node scripts/build-lab-categories.mjs",
208
- "clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\"",
209
- "test": "vitest run",
210
- "type-check": "tsc -p tsconfig.build.json --noEmit",
211
- "type-check:examples": "tsc -p tsconfig.examples.json",
212
- "lint": "eslint .",
213
- "lint:fix": "eslint . --fix",
214
- "lint:docs": "node scripts/check-readme-links.mjs",
215
- "wiki:build": "node scripts/build-wiki.mjs",
216
- "wiki:publish": "node scripts/publish-wiki.mjs",
217
- "wiki:check": "node scripts/build-wiki.mjs --check",
218
- "lint:published": "node scripts/audit-published-surface.mjs",
219
- "lint:specifiers": "node scripts/check-sdk-specifiers.mjs",
220
- "examples:run": "node scripts/run-examples.mjs",
221
- "lint:conventions": "node scripts/check-conventions.mjs",
222
- "lint:boundaries": "node scripts/check-source-boundaries.mjs",
223
- "lint:organization": "node scripts/check-organization.mjs",
224
- "map": "node scripts/map-the-repo.mjs",
225
- "lint:map": "node scripts/map-the-repo.mjs --check",
226
- "lint:acronyms": "tsx scripts/check-acronym-expansions.ts",
227
- "test:schema": "vitest run tests/data/schemas.test.ts tests/data/schemas-cover-what-they-claim.test.ts",
228
- "verify": "node scripts/verify.mjs",
229
- "verify:serial": "node scripts/verify.mjs --serial",
230
- "mcp": "node mcp/server.mjs",
231
- "glossary": "pnpm run build && node scripts/generate-glossary.mjs",
232
- "bot:demo": "tsx templates/bot-starter.ts",
233
- "bot:test": "vitest run src/bot",
234
- "sheets:test": "vitest run src/sheets",
235
- "docs:snippets": "node scripts/build-doc-snippets.mjs",
236
- "docs:seed": "pnpm run docs:snippets && pnpm run wiki:build",
237
- "docs:check": "node scripts/build-doc-snippets.mjs --check && pnpm run wiki:check && node scripts/check-readme-links.mjs && node scripts/build-patch-notes.mjs --check",
238
- "patch-notes:ingest": "node scripts/ingest-patch-notes.mjs",
239
- "patch-notes:build": "node scripts/build-patch-notes.mjs",
240
- "wasm:build": "node wasm/build.mjs",
241
- "wasm:check": "node wasm/build.mjs --check",
242
- "wasm:call": "node wasm/run.mjs",
243
- "lint:package": "node scripts/audit-package-contents.mjs",
244
- "epaths:refresh-reference": "node scripts/refresh-effective-paths-reference.mjs"
245
247
  }
246
- }
248
+ }