agentfootprint 6.24.0 โ†’ 6.25.0

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 (51) hide show
  1. package/README.md +31 -0
  2. package/bin/agentfootprint-lint-tools.mjs +14 -0
  3. package/dist/esm/lib/tool-lint/analyze.js +235 -0
  4. package/dist/esm/lib/tool-lint/analyze.js.map +1 -0
  5. package/dist/esm/lib/tool-lint/cli.js +198 -0
  6. package/dist/esm/lib/tool-lint/cli.js.map +1 -0
  7. package/dist/esm/lib/tool-lint/format.js +61 -0
  8. package/dist/esm/lib/tool-lint/format.js.map +1 -0
  9. package/dist/esm/lib/tool-lint/index.js +23 -0
  10. package/dist/esm/lib/tool-lint/index.js.map +1 -0
  11. package/dist/esm/lib/tool-lint/rules.js +249 -0
  12. package/dist/esm/lib/tool-lint/rules.js.map +1 -0
  13. package/dist/esm/lib/tool-lint/types.js +25 -0
  14. package/dist/esm/lib/tool-lint/types.js.map +1 -0
  15. package/dist/esm/observe.js +13 -0
  16. package/dist/esm/observe.js.map +1 -1
  17. package/dist/esm/recorders/observability/ToolChoiceRecorder.js +261 -0
  18. package/dist/esm/recorders/observability/ToolChoiceRecorder.js.map +1 -0
  19. package/dist/lib/tool-lint/analyze.js +242 -0
  20. package/dist/lib/tool-lint/analyze.js.map +1 -0
  21. package/dist/lib/tool-lint/cli.js +203 -0
  22. package/dist/lib/tool-lint/cli.js.map +1 -0
  23. package/dist/lib/tool-lint/format.js +65 -0
  24. package/dist/lib/tool-lint/format.js.map +1 -0
  25. package/dist/lib/tool-lint/index.js +43 -0
  26. package/dist/lib/tool-lint/index.js.map +1 -0
  27. package/dist/lib/tool-lint/rules.js +256 -0
  28. package/dist/lib/tool-lint/rules.js.map +1 -0
  29. package/dist/lib/tool-lint/types.js +26 -0
  30. package/dist/lib/tool-lint/types.js.map +1 -0
  31. package/dist/observe.js +34 -1
  32. package/dist/observe.js.map +1 -1
  33. package/dist/recorders/observability/ToolChoiceRecorder.js +266 -0
  34. package/dist/recorders/observability/ToolChoiceRecorder.js.map +1 -0
  35. package/dist/types/lib/tool-lint/analyze.d.ts +84 -0
  36. package/dist/types/lib/tool-lint/analyze.d.ts.map +1 -0
  37. package/dist/types/lib/tool-lint/cli.d.ts +44 -0
  38. package/dist/types/lib/tool-lint/cli.d.ts.map +1 -0
  39. package/dist/types/lib/tool-lint/format.d.ts +19 -0
  40. package/dist/types/lib/tool-lint/format.d.ts.map +1 -0
  41. package/dist/types/lib/tool-lint/index.d.ts +24 -0
  42. package/dist/types/lib/tool-lint/index.d.ts.map +1 -0
  43. package/dist/types/lib/tool-lint/rules.d.ts +86 -0
  44. package/dist/types/lib/tool-lint/rules.d.ts.map +1 -0
  45. package/dist/types/lib/tool-lint/types.d.ts +156 -0
  46. package/dist/types/lib/tool-lint/types.d.ts.map +1 -0
  47. package/dist/types/observe.d.ts +2 -0
  48. package/dist/types/observe.d.ts.map +1 -1
  49. package/dist/types/recorders/observability/ToolChoiceRecorder.d.ts +165 -0
  50. package/dist/types/recorders/observability/ToolChoiceRecorder.d.ts.map +1 -0
  51. package/package.json +4 -2
package/README.md CHANGED
@@ -394,6 +394,37 @@ allocates no queue.
394
394
  > ๐Ÿ“– Full semantics (capture policies, backpressure, `'block'` overflow):
395
395
  > [footprintjs deferred-observers guide](https://github.com/footprintjs/footPrint/blob/main/docs/guides/observers-deferred.md)
396
396
 
397
+ ### Lint your tool catalog โ€” before the model picks the wrong twin
398
+
399
+ Tool routing is an LLM decision driven by names + descriptions โ€” so lint the
400
+ catalog like code and gate it in CI. **Zero stack buy-in**: works on any
401
+ OpenAI / Anthropic / MCP / plain tool list, no agentfootprint runtime needed.
402
+
403
+ ```bash
404
+ npx agentfootprint-lint-tools tools.json --threshold 0.94 --strict
405
+ ```
406
+
407
+ ```
408
+ โœ— CONFUSABLE 0.9445 get_fcns_database <> influx_get_fcns_database
409
+ hint: names differ only by 'influx' โ€” make the descriptions say WHEN to choose each
410
+ ~ warn [enum-in-prose] influx_get_port_ranking.metric
411
+ suggest: "enum": ["avg_iops","peak_iops","mbps"]
412
+ ```
413
+
414
+ Pairwise confusability over what the model reads (embedder pluggable,
415
+ content-hash cached) plus a pluggable structural rule pack
416
+ (missing/short descriptions, says-WHAT-not-WHEN, enums hiding in prose,
417
+ undocumented optional params). The runtime counterpart, `toolChoiceRecorder`
418
+ (`agentfootprint/observe`), scores each live LLM call's tool choice against
419
+ the same geometry and flags narrow margins and proxy disagreements โ€” lazily,
420
+ off the hot path.
421
+
422
+ > ๐Ÿ“– **[Tool-catalog lint guide](docs/guides/tool-catalog-lint.md)** โ€” 5 minutes
423
+ > from a tools.json to a gated CI check ยท
424
+ > [`examples/observability/02`](examples/observability/02-lint-confusable-catalog.ts) ยท
425
+ > [`03`](examples/observability/03-lint-fix-and-pass.ts) ยท
426
+ > [`04`](examples/observability/04-tool-choice-margins.ts)
427
+
397
428
  ---
398
429
 
399
430
  ## Quick start โ€” runs offline, no API key
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * agentfootprint-lint-tools โ€” CI gate for tool-catalog confusability
4
+ * (RFC-002 C3). Humble shell: all behavior lives in src/lib/tool-lint/cli.ts
5
+ * (unit-tested there); this wrapper only resolves the built module and maps
6
+ * the returned code onto process.exitCode.
7
+ *
8
+ * npx agentfootprint-lint-tools tools.json
9
+ * npx agentfootprint-lint-tools tools.json --threshold 0.94 --strict
10
+ *
11
+ * Guide: docs/guides/tool-catalog-lint.md
12
+ */
13
+ const { runToolLintCli } = await import('../dist/esm/lib/tool-lint/cli.js');
14
+ process.exitCode = await runToolLintCli(process.argv.slice(2));
@@ -0,0 +1,235 @@
1
+ /**
2
+ * analyzeToolCatalog โ€” the tool-catalog confusability lint
3
+ * (RFC-002 block C1, the adoption front door).
4
+ *
5
+ * Pattern: policy layer over `pairwiseSimilarity` (influence-core) โ€” the
6
+ * geometry is computed there; thresholds, verdicts, hints and
7
+ * the structural rule pack live here. Everything is consumer-
8
+ * injectable with our defaults (the plug-and-play meta-pattern).
9
+ * Role: `src/lib/tool-lint/`. ZERO stack buy-in โ€” plain
10
+ * `{ name, description?, inputSchema? }[]` in, report out.
11
+ * `catalogFromTools` adapts the library's own `Tool[]`;
12
+ * `coerceCatalog` (cli.ts) normalizes OpenAI/Anthropic/MCP
13
+ * shapes.
14
+ *
15
+ * ## What is embedded (and why)
16
+ *
17
+ * `confusabilityText(tool)` = tokenized name + ': ' + description. The
18
+ * model differentiates tools by name AND description together, so two
19
+ * tools with near-identical names and overlapping descriptions ARE the
20
+ * confusability case (`get_fcns_database` vs `influx_get_fcns_database`)
21
+ * โ€” embedding only the prose would miss the name signal.
22
+ *
23
+ * ## Calibration (RFC-002 ยง3 โ€” read this before trusting verdicts)
24
+ *
25
+ * Absolute cosine ranges are PER-EMBEDDER. The default threshold (0.85)
26
+ * is a starting point for real sentence embedders. The test/demo
27
+ * `mockEmbedder` (character-frequency) compresses unrelated prose into
28
+ * ~0.85โ€“0.97 โ€” with it, use `MOCK_EMBEDDER_CALIBRATION` and trust only
29
+ * the RELATIVE ordering in `report.similarity.ranked` (the acceptance
30
+ * fixtures assert ordering, never absolute scores).
31
+ */
32
+ import { pairwiseSimilarity } from '../influence-core/index.js';
33
+ import { defaultStructuralRules } from './rules.js';
34
+ /** Default `confusabilityThreshold` โ€” a starting point for REAL sentence
35
+ * embedders (unrelated tool descriptions typically land 0.3โ€“0.7).
36
+ * Calibrate per embedder; meaningless for the mock (see below). */
37
+ export const DEFAULT_CONFUSABILITY_THRESHOLD = 0.85;
38
+ /** Default `watchBand` below the threshold. */
39
+ export const DEFAULT_WATCH_BAND = 0.05;
40
+ /**
41
+ * Threshold/band calibrated for the char-frequency `mockEmbedder` on
42
+ * realistic tool prose (seed corpus: the Neo SAN catalog). The mock
43
+ * compresses unrelated descriptions into ~0.85โ€“0.97 cosine, so expect
44
+ * false positives even at 0.94 โ€” with the mock, the RELATIVE ordering
45
+ * of `report.similarity.ranked` is the trustworthy signal; absolute
46
+ * verdicts are only honest with a real embedder + per-embedder
47
+ * calibration.
48
+ */
49
+ export const MOCK_EMBEDDER_CALIBRATION = Object.freeze({
50
+ confusabilityThreshold: 0.94,
51
+ watchBand: 0.02,
52
+ });
53
+ /**
54
+ * Adapt the library's `Tool[]` (from `defineTool` / `Agent.tool`) to the
55
+ * lint's plain catalog shape. Trivial on purpose: `Tool.schema` already
56
+ * IS `{ name, description, inputSchema }`.
57
+ */
58
+ export function catalogFromTools(tools) {
59
+ return tools.map((tool) => ({
60
+ name: tool.schema.name,
61
+ description: tool.schema.description,
62
+ inputSchema: tool.schema.inputSchema,
63
+ }));
64
+ }
65
+ /**
66
+ * The text the confusability analysis embeds for one tool: the name with
67
+ * `_`/`-`/camelCase boundaries opened into words, then the description.
68
+ * Exported so consumers can reproduce or replace the construction.
69
+ */
70
+ export function confusabilityText(tool) {
71
+ const name = tool.name
72
+ .replace(/[_-]+/g, ' ')
73
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
74
+ .trim();
75
+ const description = tool.description?.trim() ?? '';
76
+ return description.length > 0 ? `${name}: ${description}` : name;
77
+ }
78
+ /**
79
+ * Lint a tool catalog: pairwise confusability over what the model reads
80
+ * (when an embedder is supplied) + the structural rule pack. Returns a
81
+ * report whose `ok` is the CI gate.
82
+ *
83
+ * Duplicate tool names are themselves reported as structural errors
84
+ * (rule `duplicate-name`, built-in precondition โ€” a catalog where two
85
+ * tools share a name is broken before any similarity question); the
86
+ * duplicates are dropped from the similarity analysis (first one wins).
87
+ */
88
+ export async function analyzeToolCatalog(tools, options = {}) {
89
+ const confusabilityThreshold = options.confusabilityThreshold ?? DEFAULT_CONFUSABILITY_THRESHOLD;
90
+ const watchBand = options.watchBand ?? DEFAULT_WATCH_BAND;
91
+ const rules = options.rules ?? defaultStructuralRules;
92
+ const failOn = options.failOn ?? 'error';
93
+ // โ”€โ”€ built-in precondition: duplicate names โ”€โ”€
94
+ const structural = [];
95
+ const seen = new Set();
96
+ const unique = [];
97
+ for (const tool of tools) {
98
+ if (seen.has(tool.name)) {
99
+ structural.push({
100
+ rule: 'duplicate-name',
101
+ tool: tool.name,
102
+ severity: 'error',
103
+ message: 'two tools share this name โ€” the model cannot address them distinctly',
104
+ });
105
+ }
106
+ else {
107
+ seen.add(tool.name);
108
+ unique.push(tool);
109
+ }
110
+ }
111
+ // โ”€โ”€ structural rule pack โ”€โ”€
112
+ for (const tool of unique) {
113
+ for (const rule of rules) {
114
+ structural.push(...rule.check(tool, unique));
115
+ }
116
+ }
117
+ // โ”€โ”€ pairwise confusability (embedder-gated) โ”€โ”€
118
+ let ranked = [];
119
+ const confusable = [];
120
+ const watch = [];
121
+ const analyzed = options.embedder !== undefined && unique.length >= 2;
122
+ if (options.embedder !== undefined && unique.length >= 2) {
123
+ const byName = new Map(unique.map((tool) => [tool.name, tool]));
124
+ const result = await pairwiseSimilarity({
125
+ items: unique.map((tool) => ({ id: tool.name, text: confusabilityText(tool) })),
126
+ embedder: options.embedder,
127
+ ...(options.signal ? { signal: options.signal } : {}),
128
+ });
129
+ ranked = result.pairs;
130
+ for (const pair of result.pairs) {
131
+ if (pair.similarity >= confusabilityThreshold) {
132
+ confusable.push({
133
+ kind: 'confusable',
134
+ a: pair.a,
135
+ b: pair.b,
136
+ similarity: pair.similarity,
137
+ // byName lookups are safe: pair ids come from `unique` itself.
138
+ hint: differentiationHint(byName.get(pair.a), byName.get(pair.b)),
139
+ });
140
+ }
141
+ else if (pair.similarity >= confusabilityThreshold - watchBand) {
142
+ watch.push({
143
+ kind: 'watch',
144
+ a: pair.a,
145
+ b: pair.b,
146
+ similarity: pair.similarity,
147
+ hint: differentiationHint(byName.get(pair.a), byName.get(pair.b)),
148
+ });
149
+ }
150
+ }
151
+ }
152
+ const errors = structural.filter((f) => f.severity === 'error').length;
153
+ const warnings = structural.length - errors;
154
+ const gateFailures = failOn === 'warn' ? structural.length : errors;
155
+ return {
156
+ ok: confusable.length === 0 && gateFailures === 0,
157
+ toolCount: tools.length,
158
+ similarity: {
159
+ analyzed,
160
+ confusable,
161
+ watch,
162
+ ranked,
163
+ thresholds: { confusabilityThreshold, watchBand },
164
+ },
165
+ structural,
166
+ summary: { confusable: confusable.length, watch: watch.length, errors, warnings },
167
+ };
168
+ }
169
+ // โ”€โ”€ differentiating-axis hint (heuristic, honest) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
170
+ const STOPWORDS = new Set([
171
+ 'a',
172
+ 'an',
173
+ 'and',
174
+ 'are',
175
+ 'by',
176
+ 'for',
177
+ 'from',
178
+ 'get',
179
+ 'in',
180
+ 'into',
181
+ 'is',
182
+ 'its',
183
+ 'of',
184
+ 'on',
185
+ 'or',
186
+ 'the',
187
+ 'to',
188
+ 'which',
189
+ 'with',
190
+ ]);
191
+ function nameTokens(name) {
192
+ return name
193
+ .replace(/[_-]+/g, ' ')
194
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
195
+ .toLowerCase()
196
+ .split(/\s+/)
197
+ .filter((t) => t.length > 0);
198
+ }
199
+ function descriptionTokens(tool) {
200
+ return new Set((tool.description ?? '')
201
+ .toLowerCase()
202
+ .split(/[^a-z0-9_]+/)
203
+ .filter((t) => t.length >= 3 && !STOPWORDS.has(t)));
204
+ }
205
+ /**
206
+ * Suggest the DIFFERENTIATING AXIS for a flagged pair. Heuristic: when
207
+ * the names are near-twins (โ‰ค2 distinct tokens), the qualifier IS the
208
+ * axis โ€” the descriptions must say when to choose each variant. When the
209
+ * names differ, surface the few description terms each tool does NOT
210
+ * share, as the place to anchor an explicit choice condition.
211
+ */
212
+ export function differentiationHint(a, b) {
213
+ const aTokens = nameTokens(a.name);
214
+ const bTokens = nameTokens(b.name);
215
+ const aOnly = aTokens.filter((t) => !bTokens.includes(t));
216
+ const bOnly = bTokens.filter((t) => !aTokens.includes(t));
217
+ const shared = aTokens.filter((t) => bTokens.includes(t));
218
+ if (shared.length >= 2 && aOnly.length + bOnly.length <= 2) {
219
+ const diff = [...aOnly, ...bOnly].map((t) => `'${t}'`).join(' vs ') || 'nothing โ€” the names match';
220
+ return (`names differ only by ${diff} โ€” make the descriptions say WHEN to choose each ` +
221
+ `(different backend/data source? live vs historical? freshness?), ` +
222
+ `e.g. "Use for โ€ฆ; prefer ${b.name} when โ€ฆ"`);
223
+ }
224
+ const aDesc = descriptionTokens(a);
225
+ const bDesc = descriptionTokens(b);
226
+ const aDistinct = [...aDesc].filter((t) => !bDesc.has(t)).slice(0, 3);
227
+ const bDistinct = [...bDesc].filter((t) => !aDesc.has(t)).slice(0, 3);
228
+ if (aDistinct.length === 0 && bDistinct.length === 0) {
229
+ return `the descriptions are near-duplicates โ€” rewrite one to state when it, and not ${b.name}, is the right call`;
230
+ }
231
+ return (`descriptions overlap heavily; the distinct terms are ` +
232
+ `${a.name}: [${aDistinct.join(', ')}] vs ${b.name}: [${bDistinct.join(', ')}] โ€” ` +
233
+ `lead with an explicit choice condition ("use when โ€ฆ") built on those`);
234
+ }
235
+ //# sourceMappingURL=analyze.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyze.js","sourceRoot":"","sources":["../../../../src/lib/tool-lint/analyze.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,EAAE,kBAAkB,EAAuB,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AASpD;;oEAEoE;AACpE,MAAM,CAAC,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAEpD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,MAAM,CAAC;IACrD,sBAAsB,EAAE,IAAI;IAC5B,SAAS,EAAE,IAAI;CAChB,CAAC,CAAC;AAEH;;;;GAIG;AACH,M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AAC;QACxF,OAAO,CACL,wBAAwB,IAAI,mDAAmD;YAC/E,mEAAmE;YACnE,2BAA2B,CAAC,CAAC,IAAI,UAAU,CAC5C,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,SAAS,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtE,MAAM,SAAS,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrD,OAAO,gFAAgF,CAAC,CAAC,IAAI,qBAAqB,CAAC;IACrH,CAAC;IACD,OAAO,CACL,uDAAuD;QACvD,GAAG,CAAC,CAAC,IAAI,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;QACjF,sEAAsE,CACvE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Tool-lint CLI core (RFC-002 block C3 โ€” the CI gate).
3
+ *
4
+ * Pattern: humble shell โ€” `bin/agentfootprint-lint-tools.mjs` is a
5
+ * 3-line wrapper; ALL behavior (arg parsing, catalog coercion,
6
+ * report, exit code) lives here so it is unit-testable without
7
+ * spawning a process.
8
+ * Role: `src/lib/tool-lint/`. Reads ONE JSON file of tools, prints a
9
+ * report, returns the process exit code:
10
+ * 0 โ€” report.ok
11
+ * 1 โ€” findings failed the gate (!ok)
12
+ * 2 โ€” usage / input error (bad flags, unreadable file,
13
+ * unrecognized JSON shape)
14
+ *
15
+ * ## Embedder & gating honesty
16
+ *
17
+ * The CLI has no way to receive a consumer embedder, so it uses the
18
+ * built-in deterministic mock (char-frequency, offline, dependency-free)
19
+ * for the similarity RANKING โ€” and, by default, does NOT gate on it:
20
+ * without `--threshold`, similarity is report-only (relative ordering +
21
+ * watch hints) and the exit code reflects structural findings alone.
22
+ * Pass `--threshold` to make confusable pairs fail the gate โ€” you own
23
+ * the calibration at that point (start from
24
+ * `MOCK_EMBEDDER_CALIBRATION.confusabilityThreshold` = 0.94). For real
25
+ * embedder gating, use `analyzeToolCatalog` from
26
+ * `agentfootprint/observe` in a small script instead.
27
+ */
28
+ import { readFile } from 'node:fs/promises';
29
+ import { mockEmbedder } from '../../memory/embedding/mockEmbedder.js';
30
+ import { analyzeToolCatalog, MOCK_EMBEDDER_CALIBRATION } from './analyze.js';
31
+ import { formatToolCatalogReport } from './format.js';
32
+ const USAGE = `usage: agentfootprint-lint-tools <tools.json> [options]
33
+
34
+ <tools.json> JSON file with your tool catalog. Accepted shapes:
35
+ [{ name, description, inputSchema? }] (plain / MCP tool)
36
+ { tools: [...] } (MCP tools/list result)
37
+ [{ type: 'function', function: {...} }] (OpenAI)
38
+ [{ name, description, input_schema }] (Anthropic)
39
+
40
+ --threshold <num> gate on confusable pairs at this cosine (mock-embedder
41
+ starting point: ${MOCK_EMBEDDER_CALIBRATION.confusabilityThreshold}). Without it, similarity is
42
+ REPORT-ONLY and only structural findings gate.
43
+ --watch-band <num> advisory band below the threshold (default ${MOCK_EMBEDDER_CALIBRATION.watchBand} with --threshold)
44
+ --strict structural warnings also fail the gate
45
+ --no-similarity skip the similarity analysis entirely
46
+ --top <n> ranked pairs to print (default 10)
47
+ --json print the full report as JSON instead of text
48
+
49
+ exit codes: 0 ok ยท 1 findings failed the gate ยท 2 usage/input error`;
50
+ /**
51
+ * Normalize any of the recognized tool-list JSON shapes to the lint's
52
+ * plain catalog. Throws (with a shape description) on unrecognized
53
+ * input โ€” the CLI maps that to exit code 2.
54
+ */
55
+ export function coerceCatalog(json) {
56
+ // { tools: [...] } โ€” MCP `tools/list` result envelope.
57
+ const list = Array.isArray(json)
58
+ ? json
59
+ : json !== null &&
60
+ typeof json === 'object' &&
61
+ Array.isArray(json.tools)
62
+ ? json.tools
63
+ : undefined;
64
+ if (list === undefined) {
65
+ throw new Error('expected a JSON array of tools or { tools: [...] }');
66
+ }
67
+ return list.map((raw, index) => {
68
+ if (raw === null || typeof raw !== 'object') {
69
+ throw new Error(`tools[${index}] is not an object`);
70
+ }
71
+ const entry = raw;
72
+ // OpenAI: { type: 'function', function: { name, description, parameters } }
73
+ const fn = entry.type === 'function' && entry.function !== null && typeof entry.function === 'object'
74
+ ? entry.function
75
+ : entry;
76
+ const name = fn.name;
77
+ if (typeof name !== 'string' || name.length === 0) {
78
+ throw new Error(`tools[${index}] has no string 'name'`);
79
+ }
80
+ const description = typeof fn.description === 'string' ? fn.description : undefined;
81
+ // inputSchema (MCP/ours) | input_schema (Anthropic) | parameters (OpenAI)
82
+ const schema = fn.inputSchema ?? fn.input_schema ?? fn.parameters;
83
+ const inputSchema = schema !== null && typeof schema === 'object'
84
+ ? schema
85
+ : undefined;
86
+ return {
87
+ name,
88
+ ...(description !== undefined ? { description } : {}),
89
+ ...(inputSchema !== undefined ? { inputSchema } : {}),
90
+ };
91
+ });
92
+ }
93
+ function parseArgs(argv) {
94
+ let file;
95
+ let threshold;
96
+ let watchBand;
97
+ let strict = false;
98
+ let similarity = true;
99
+ let top = 10;
100
+ let json = false;
101
+ for (let i = 0; i < argv.length; i++) {
102
+ const arg = argv[i];
103
+ const numberFlag = (name) => {
104
+ const value = Number(argv[++i]);
105
+ if (!Number.isFinite(value))
106
+ throw new Error(`${name} expects a number`);
107
+ return value;
108
+ };
109
+ if (arg === '--threshold')
110
+ threshold = numberFlag('--threshold');
111
+ else if (arg === '--watch-band')
112
+ watchBand = numberFlag('--watch-band');
113
+ else if (arg === '--strict')
114
+ strict = true;
115
+ else if (arg === '--no-similarity')
116
+ similarity = false;
117
+ else if (arg === '--top')
118
+ top = numberFlag('--top');
119
+ else if (arg === '--json')
120
+ json = true;
121
+ else if (arg === '--help' || arg === '-h')
122
+ throw new Error(USAGE);
123
+ else if (arg.startsWith('-'))
124
+ throw new Error(`unknown flag '${arg}'\n\n${USAGE}`);
125
+ else if (file === undefined)
126
+ file = arg;
127
+ else
128
+ throw new Error(`unexpected extra argument '${arg}'\n\n${USAGE}`);
129
+ }
130
+ if (file === undefined)
131
+ throw new Error(USAGE);
132
+ return {
133
+ file,
134
+ ...(threshold !== undefined ? { threshold } : {}),
135
+ ...(watchBand !== undefined ? { watchBand } : {}),
136
+ strict,
137
+ similarity,
138
+ top,
139
+ json,
140
+ };
141
+ }
142
+ /**
143
+ * Run the lint CLI. Returns the exit code (never calls `process.exit` โ€”
144
+ * the bin wrapper assigns it to `process.exitCode`).
145
+ */
146
+ export async function runToolLintCli(argv, io = {
147
+ // eslint-disable-next-line no-console
148
+ stdout: (line) => console.log(line),
149
+ // eslint-disable-next-line no-console
150
+ stderr: (line) => console.error(line),
151
+ }) {
152
+ let args;
153
+ try {
154
+ args = parseArgs(argv);
155
+ }
156
+ catch (error) {
157
+ io.stderr(error.message);
158
+ return 2;
159
+ }
160
+ let catalog;
161
+ try {
162
+ catalog = coerceCatalog(JSON.parse(await readFile(args.file, 'utf8')));
163
+ }
164
+ catch (error) {
165
+ io.stderr(`agentfootprint-lint-tools: ${args.file}: ${error.message}`);
166
+ return 2;
167
+ }
168
+ // Without --threshold the mock-embedder similarity is REPORT-ONLY:
169
+ // rank pairs at an unreachable threshold (no 'confusable'/'watch'
170
+ // verdicts) so only the relative-ordering section prints.
171
+ const gateOnSimilarity = args.threshold !== undefined;
172
+ const threshold = args.threshold ?? Infinity;
173
+ const watchBand = args.watchBand ?? (gateOnSimilarity ? MOCK_EMBEDDER_CALIBRATION.watchBand : 0);
174
+ const report = await analyzeToolCatalog(catalog, {
175
+ ...(args.similarity ? { embedder: mockEmbedder() } : {}),
176
+ confusabilityThreshold: threshold,
177
+ watchBand,
178
+ failOn: args.strict ? 'warn' : 'error',
179
+ });
180
+ if (args.json) {
181
+ io.stdout(JSON.stringify(report, null, 2));
182
+ }
183
+ else {
184
+ if (args.similarity) {
185
+ io.stdout(gateOnSimilarity
186
+ ? 'โš  similarity uses the built-in deterministic mock embedder โ€” you own the ' +
187
+ 'calibration of --threshold (cosine ranges are per-embedder; mock compresses ' +
188
+ 'prose to ~0.85โ€“0.97). Trust relative ordering first.'
189
+ : 'โ„น similarity is REPORT-ONLY (no --threshold): ranked pairs below are the ' +
190
+ 'relative-ordering view from the built-in mock embedder. Pass --threshold ' +
191
+ `(mock starting point ${MOCK_EMBEDDER_CALIBRATION.confusabilityThreshold}) to gate on confusable pairs.`);
192
+ io.stdout('');
193
+ }
194
+ io.stdout(formatToolCatalogReport(report, { topPairs: args.top }));
195
+ }
196
+ return report.ok ? 0 : 1;
197
+ }
198
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../src/lib/tool-lint/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAQtD,MAAM,KAAK,GAAG;;;;;;;;;0CAS4B,yBAAyB,CAAC,sBAAsB;;qEAErB,yBAAyB,CAAC,SAAS;;;;;;oEAMpC,CAAC;AAErE;;;;GAI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CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,sBAAsB,EAAE,SAAS;QACjC,SAAS;QACT,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;KACvC,CAAC,CAAC;IAEH,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;SAAM,CAAC;QACN,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,EAAE,CAAC,MAAM,CACP,gBAAgB;gBACd,CAAC,CAAC,2EAA2E;oBACzE,8EAA8E;oBAC9E,sDAAsD;gBAC1D,CAAC,CAAC,2EAA2E;oBACzE,2EAA2E;oBAC3E,wBAAwB,yBAAyB,CAAC,sBAAsB,gCAAgC,CAC/G,CAAC;YACF,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAChB,CAAC;QACD,EAAE,CAAC,MAAM,CAAC,uBAAuB,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * formatToolCatalogReport โ€” human-readable rendering of a lint report.
3
+ *
4
+ * Pattern: pure presenter. One report โ†’ one string; used verbatim by the
5
+ * CLI (`agentfootprint-lint-tools`) and the examples so output
6
+ * stays byte-identical across surfaces.
7
+ * Role: `src/lib/tool-lint/` leaf. No I/O.
8
+ */
9
+ export function formatToolCatalogReport(report, options = {}) {
10
+ const topPairs = options.topPairs ?? 10;
11
+ const maxWatch = options.maxWatch ?? 10;
12
+ const lines = [];
13
+ const { similarity, structural, summary } = report;
14
+ lines.push(`tool-catalog lint โ€” ${report.toolCount} tools ยท ` +
15
+ `${summary.confusable} confusable ยท ${summary.watch} watch ยท ` +
16
+ `${summary.errors} errors ยท ${summary.warnings} warnings`);
17
+ if (similarity.analyzed) {
18
+ lines.push('', `confusability (threshold ${similarity.thresholds.confusabilityThreshold}, ` +
19
+ `watch band ${similarity.thresholds.watchBand}):`);
20
+ if (similarity.confusable.length === 0 && similarity.watch.length === 0) {
21
+ lines.push(' no pairs at or near the threshold');
22
+ }
23
+ for (const pair of similarity.confusable) {
24
+ lines.push(` โœ— CONFUSABLE ${pair.similarity.toFixed(4)} ${pair.a} <> ${pair.b}`);
25
+ lines.push(` hint: ${pair.hint}`);
26
+ }
27
+ for (const pair of similarity.watch.slice(0, maxWatch)) {
28
+ lines.push(` ~ watch ${pair.similarity.toFixed(4)} ${pair.a} <> ${pair.b}`);
29
+ lines.push(` hint: ${pair.hint}`);
30
+ }
31
+ if (similarity.watch.length > maxWatch) {
32
+ lines.push(` โ€ฆ and ${similarity.watch.length - maxWatch} more watch pairs (see report.similarity.watch)`);
33
+ }
34
+ if (topPairs > 0 && similarity.ranked.length > 0) {
35
+ lines.push('', ` most-similar pairs (relative ordering โ€” top ${topPairs}):`);
36
+ for (const pair of similarity.ranked.slice(0, topPairs)) {
37
+ lines.push(` ${pair.similarity.toFixed(4)} ${pair.a} <> ${pair.b}`);
38
+ }
39
+ }
40
+ }
41
+ else {
42
+ lines.push('', 'confusability: skipped (no embedder supplied โ€” structural rules only)');
43
+ }
44
+ if (structural.length > 0) {
45
+ lines.push('', 'structural findings:');
46
+ for (const finding of structural) {
47
+ const where = finding.param ? `${finding.tool}.${finding.param}` : finding.tool;
48
+ const mark = finding.severity === 'error' ? 'โœ—' : '~';
49
+ lines.push(` ${mark} ${finding.severity.padEnd(5)} [${finding.rule}] ${where}`);
50
+ lines.push(` ${finding.message}`);
51
+ if (finding.suggestion)
52
+ lines.push(` suggest: ${finding.suggestion}`);
53
+ }
54
+ }
55
+ else {
56
+ lines.push('', 'structural findings: none');
57
+ }
58
+ lines.push('', report.ok ? 'RESULT: ok' : 'RESULT: FAIL');
59
+ return lines.join('\n');
60
+ }
61
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/lib/tool-lint/format.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH,MAAM,UAAU,uBAAuB,CACrC,MAAyB,EACzB,UAA+B,EAAE;IAEjC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;IACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;IACxC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAEnD,KAAK,CAAC,IAAI,CACR,uBAAuB,MAAM,CAAC,SAAS,WAAW;QAChD,GAAG,OAAO,CAAC,UAAU,iBAAiB,OAAO,CAAC,KAAK,WAAW;QAC9D,GAAG,OAAO,CAAC,MAAM,aAAa,OAAO,CAAC,QAAQ,WAAW,CAC5D,CAAC;IAEF,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;QACxB,KAAK,CAAC,IAAI,CACR,EAAE,EACF,4BAA4B,UAAU,CAAC,UAAU,CAAC,sBAAsB,IAAI;YAC1E,cAAc,UAAU,CAAC,UAAU,CAAC,SAAS,IAAI,CACpD,CAAC;QACF,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxE,KAAK,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;QACpD,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;YACzC,KAAK,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,C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AAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,sBAAsB,CAAC,CAAC;QACvC,KAAK,MAAM,OAAO,IAAI,UAAU,EAAE,CAAC;YACjC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;YAChF,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YACtD,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;YACjF,KAAK,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;YACvC,IAAI,OAAO,CAAC,UAAU;gBAAE,KAAK,CAAC,IAAI,CAAC,kBAAkB,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,2BAA2B,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * tool-lint โ€” the tool-catalog confusability lint (RFC-002 tier 1,
3
+ * blocks C1โ€“C3).
4
+ *
5
+ * Build-time, CI-gateable, framework-agnostic: a plain
6
+ * `{ name, description?, inputSchema? }[]` in (any OpenAI / Anthropic /
7
+ * LangChain / MCP tool list coerces to it), a report with a CI-gateable
8
+ * `ok` out. The embedding geometry comes from influence-core
9
+ * (`pairwiseSimilarity`); this module is the policy layer โ€” thresholds,
10
+ * verdicts, hints, and the pluggable structural rule pack.
11
+ *
12
+ * Surfaces:
13
+ * - `analyzeToolCatalog(tools, opts)` โ€” the API (C1)
14
+ * - `defaultStructuralRules` + rule factories โ€” the rule pack (C2)
15
+ * - `runToolLintCli` / bin `agentfootprint-lint-tools` โ€” the gate (C3)
16
+ *
17
+ * Front-door guide: docs/guides/tool-catalog-lint.md
18
+ */
19
+ export { analyzeToolCatalog, catalogFromTools, confusabilityText, differentiationHint, DEFAULT_CONFUSABILITY_THRESHOLD, DEFAULT_WATCH_BAND, MOCK_EMBEDDER_CALIBRATION, } from './analyze.js';
20
+ export { defaultStructuralRules, descriptionRule, enumInProseRule, optionalParamRule, saysWhatNotWhenRule, DEFAULT_OMISSION_CUES, DEFAULT_WHEN_CUES, } from './rules.js';
21
+ export { formatToolCatalogReport } from './format.js';
22
+ export { coerceCatalog, runToolLintCli } from './cli.js';
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/tool-lint/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAcH,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,+BAA+B,EAC/B,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,GAIlB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,uBAAuB,EAA4B,MAAM,aAAa,CAAC;AAEhF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAsB,MAAM,UAAU,CAAC"}