@matatbread/matbot-tool-types 0.4.12 → 0.4.13

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "matbotRuntime": [
4
4
  "node"
5
5
  ],
6
- "version": "0.4.12",
6
+ "version": "0.4.13",
7
7
  "engines": {
8
8
  "node": ">=24.0.0"
9
9
  },
@@ -36,14 +36,14 @@
36
36
  "typescript": "^6.0.3"
37
37
  },
38
38
  "peerDependencies": {
39
- "@matatbread/matbot-core": "^0.4.12",
40
- "@matatbread/matbot-plugin-api": "^0.4.12"
39
+ "@matatbread/matbot-plugin-api": "^0.4.14",
40
+ "@matatbread/matbot-core": "^0.4.14"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^22.0.0",
44
44
  "typescript": "^6.0.3",
45
- "@matatbread/matbot-plugin-api": "^0.4.12",
46
- "@matatbread/matbot-core": "^0.4.12"
45
+ "@matatbread/matbot-core": "^0.4.14",
46
+ "@matatbread/matbot-plugin-api": "^0.4.14"
47
47
  },
48
48
  "scripts": {
49
49
  "typecheck": "tsc --noEmit"
package/src/build-dts.ts CHANGED
@@ -157,12 +157,17 @@ export async function buildMatbotToolsDts(
157
157
  // because the name IS live.
158
158
  // Generated `matbot-tools.d.ts` files are skipped (don't feed prior output back in).
159
159
  if (existsSync(join(projectRoot, 'plugins'))) {
160
- const SKIP = new Set(['node_modules', 'dist', '.git', 'compiled-plugins']);
160
+ // Dot-directories wholesale rather than by name: this used to list `compiled-plugins` explicitly,
161
+ // which was both a second spelling of a constant skills_compiler owns (now settings-relocatable, so
162
+ // unknowable here) and unreachable — the walk roots at `plugins/`, and that build dir is its sibling.
163
+ // A source tree keeps no augmentations under a dot-directory; `.git`, `.plugins` and a build root
164
+ // sited there are all covered by one rule that cannot go stale.
165
+ const SKIP = new Set(['node_modules', 'dist']);
161
166
  const walk = (dir: string): void => {
162
167
  let entries: string[];
163
168
  try { entries = readdirSync(dir); } catch { return; }
164
169
  for (const name of entries) {
165
- if (SKIP.has(name)) continue;
170
+ if (SKIP.has(name) || name.startsWith('.')) continue;
166
171
  const p = join(dir, name);
167
172
  let isDir: boolean;
168
173
  try { isDir = statSync(p).isDirectory(); } catch { continue; }
package/src/checker.ts CHANGED
@@ -9,6 +9,9 @@
9
9
  // own virtual file, the same resolved typescript module), so a checker failure is a plumbing bug
10
10
  // that must surface as the caller's error, not be absorbed by a quieter path.
11
11
 
12
+ import { renderToolCheckOmitted } from '@matatbread/matbot-plugin-api';
13
+ import type { ToolCheckDiagnostic, ToolCheckReport } from '@matatbread/matbot-plugin-api';
14
+
12
15
  export interface CheckResult { ok: boolean; output: string }
13
16
 
14
17
  interface DiagnosticRecord {
@@ -20,7 +23,7 @@ interface DiagnosticRecord {
20
23
  frame?: string;
21
24
  sourceLine?: string;
22
25
  related?: string[];
23
- /** True for a cast-gate finding (a structural rule, not a tsc error) — rendered as CAST, not TSnnnn. */
26
+ /** True for a cast-gate finding (a structural rule, not a tsc error) — labelled CAST-GATE, not TSnnnn. */
24
27
  syn?: boolean;
25
28
  }
26
29
 
@@ -82,10 +85,16 @@ function hintFor(d: DiagnosticRecord): string | undefined {
82
85
 
83
86
  const MAX_FULL = 8;
84
87
 
88
+ // One rule, one name, in every renderer: a per-rule label read off the record rather than spelled at
89
+ // each render site, so a summary can never call a finding something its own entry did not.
90
+ function label(d: DiagnosticRecord): string {
91
+ return d.syn ? 'CAST-GATE' : `TS${d.code}`;
92
+ }
93
+
85
94
  function formatOne(d: DiagnosticRecord): string {
86
95
  const loc = d.file !== undefined ? `${d.file}(${d.line},${d.col})`
87
96
  : d.line !== undefined ? `line ${d.line}` : '(project)';
88
- const parts = [`${loc} ${d.syn ? 'CAST-GATE' : `TS${d.code}`}: ${d.message}`];
97
+ const parts = [`${loc} ${label(d)}: ${d.message}`];
89
98
  if (d.frame !== undefined) parts.push(d.frame);
90
99
  if (d.related) for (const r of d.related) parts.push(` related: ${r}`);
91
100
  const hint = hintFor(d);
@@ -93,10 +102,47 @@ function formatOne(d: DiagnosticRecord): string {
93
102
  return parts.join('\n');
94
103
  }
95
104
 
96
- function overflowNote(diags: DiagnosticRecord[]): string {
97
- const byCode = new Map<number, number>();
98
- for (const d of diags.slice(MAX_FULL)) byCode.set(d.code, (byCode.get(d.code) ?? 0) + 1);
99
- return `…plus ${diags.length - MAX_FULL} more: ${[...byCode.entries()].map(([c, n]) => `TS${c}×${n}`).join(', ')} — likely cascading from the errors above.`;
105
+ // The findings the cap hides, tallied by the same `label` the detailed ones carry.
106
+ function omittedOf(diags: DiagnosticRecord[]): { count: number; byLabel: Record<string, number> } | undefined {
107
+ const hidden = diags.slice(MAX_FULL);
108
+ if (hidden.length === 0) return undefined;
109
+ const byLabel: Record<string, number> = {};
110
+ for (const d of hidden) byLabel[label(d)] = (byLabel[label(d)] ?? 0) + 1;
111
+ return { count: hidden.length, byLabel };
112
+ }
113
+
114
+ /**
115
+ * The worker's records as the service's {@link ToolCheckReport}: structured findings, the cap expressed
116
+ * as `omitted` data, and each finding's annotated rendering carried on the record itself.
117
+ *
118
+ * The rendering used to be the WHOLE return value — one `string[]` of formatted blocks with the overflow
119
+ * summary appended as a further element. So `diagnostics.length` counted prose as a finding, and any
120
+ * per-code breakdown taken by iterating the array was unreliable wherever an overflow had occurred.
121
+ * The typed record existed upstream all along and was discarded at render time; it is kept now, and the
122
+ * text is one field of it.
123
+ */
124
+ function reportOf(diags: DiagnosticRecord[]): ToolCheckReport {
125
+ const omitted = omittedOf(diags);
126
+ const detailed: ToolCheckDiagnostic[] = diags.slice(0, MAX_FULL).map(d => ({
127
+ label: label(d),
128
+ code: d.code,
129
+ message: d.message,
130
+ ...(d.file !== undefined ? { file: d.file } : {}),
131
+ ...(d.line !== undefined ? { line: d.line } : {}),
132
+ ...(d.col !== undefined ? { col: d.col } : {}),
133
+ ...(d.frame !== undefined ? { frame: d.frame } : {}),
134
+ ...(d.related !== undefined ? { related: d.related } : {}),
135
+ ...(hintFor(d) !== undefined ? { hint: hintFor(d)! } : {}),
136
+ ...(d.syn === true ? { syn: true as const } : {}),
137
+ rendered: formatOne(d),
138
+ }));
139
+ return {
140
+ ok: diags.length === 0,
141
+ checked: true,
142
+ total: diags.length,
143
+ diagnostics: detailed,
144
+ ...(omitted !== undefined ? { omitted } : {}),
145
+ };
100
146
  }
101
147
 
102
148
  async function runWorker(data: Record<string, unknown>): Promise<DiagnosticRecord[] | null> {
@@ -133,10 +179,11 @@ export async function checkProjectDir(
133
179
  ...(opts?.ownContracts !== undefined ? { ownContracts: [...opts.ownContracts] } : {}),
134
180
  });
135
181
  if (diags === null) return { ok: true, output: '' };
182
+ const report = reportOf(diags);
136
183
  const parts: string[] = [];
137
- if (diags.length > 1) parts.push(`${diags.length} errors. Fix the FIRST error first — later errors often cascade from it.\n`);
138
- for (const d of diags.slice(0, MAX_FULL)) { parts.push(formatOne(d)); parts.push(''); }
139
- if (diags.length > MAX_FULL) parts.push(overflowNote(diags));
184
+ if (report.total > 1) parts.push(`${report.total} errors. Fix the FIRST error first — later errors often cascade from it.\n`);
185
+ for (const d of report.diagnostics) { parts.push(d.rendered); parts.push(''); }
186
+ if (report.omitted !== undefined) parts.push(renderToolCheckOmitted(report.omitted));
140
187
  return { ok: false, output: parts.join('\n').trim() };
141
188
  }
142
189
 
@@ -149,7 +196,7 @@ export async function checkSnippetAgainst(opts: {
149
196
  prefixLen: number;
150
197
  prefixLines: number;
151
198
  apiIndexPath?: string;
152
- }): Promise<string[]> {
199
+ }): Promise<ToolCheckReport> {
153
200
  const diags = await runWorker({
154
201
  mode: 'snippet',
155
202
  root: opts.root,
@@ -159,10 +206,7 @@ export async function checkSnippetAgainst(opts: {
159
206
  virtualPath: `${opts.root}/__mb_toolcheck_${crypto.randomUUID()}.ts`,
160
207
  ...(opts.apiIndexPath !== undefined ? { apiIndexPath: opts.apiIndexPath } : {}),
161
208
  });
162
- if (diags === null) return [];
163
- const out = diags.slice(0, MAX_FULL).map(formatOne);
164
- if (diags.length > MAX_FULL) out.push(overflowNote(diags));
165
- return out;
209
+ return reportOf(diags ?? []);
166
210
  }
167
211
 
168
212
  // The worker body: plain CommonJS (Worker eval mode is CJS, so `require` exists and no loader hooks
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import { dirname, join } from 'node:path';
2
2
  import { existsSync } from 'node:fs';
3
3
  import { createRequire } from 'node:module';
4
4
  import { PLUGIN_API_VERSION, RegistryChangeKind } from '@matatbread/matbot-plugin-api';
5
- import type { MatbotMachine, MatbotPluginSpec, ToolTypeIndex } from '@matatbread/matbot-plugin-api';
5
+ import type { MatbotMachine, MatbotPluginSpec, ToolCheckReport, ToolTypeIndex } from '@matatbread/matbot-plugin-api';
6
6
  import { getRegisteredPlugins } from '@matatbread/matbot-core';
7
7
  import { buildMatbotToolsDts } from './build-dts.js';
8
8
  import { checkSnippetAgainst } from './checker.js';
@@ -160,7 +160,7 @@ class ToolTypeIndexImpl implements ToolTypeIndex {
160
160
  if (this.dirty || this.cache === null) {
161
161
  const root = this.machine.configPath !== undefined ? dirname(this.machine.configPath) : '.';
162
162
  // Scan the source each loaded plugin was actually loaded from (its resolvedUrl) — builtin, compiled
163
- // (compiled-plugins/), or installed (.plugins/) alike — so every registered tool's real augmentation
163
+ // (.compiled-plugins/), or installed (.plugins/) alike — so every registered tool's real augmentation
164
164
  // is read. build-dts UNIONs a glob of the monorepo `plugins/` tree onto these roots (not a fallback:
165
165
  // it catches host-constructed builtins that have no resolvedUrl), so the scanned set is a SUPERSET of
166
166
  // the loaded one — wherever that tree exists, plugins for other runtimes and plugins nobody loaded are
@@ -211,7 +211,7 @@ class ToolTypeIndexImpl implements ToolTypeIndex {
211
211
  return out;
212
212
  }
213
213
 
214
- async check(snippet: string): Promise<string[]> {
214
+ async check(snippet: string): Promise<ToolCheckReport> {
215
215
  const root = this.machine.configPath !== undefined ? dirname(this.machine.configPath) : '.';
216
216
  const prefix = `${await this.dts()}\n`;
217
217
  const source = `${prefix}${snippet}\nexport {};\n`; // trailing export ⇒ this file is a module