@agentcash/discovery 0.1.0 → 0.1.2

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/AGENTS.md CHANGED
@@ -16,7 +16,6 @@ This repo implements canonical discovery logic for the agentcash ecosystem.
16
16
 
17
17
  - `src/core/*`: canonical OpenAPI-first discovery.
18
18
  - `src/compat/legacy-x402scan/*`: `/.well-known/x402` + DNS `_x402` compatibility.
19
- - `src/compat/interop-mpp/*`: optional registry interop adapter.
20
19
 
21
20
  ## Result Contract
22
21
 
package/README.md CHANGED
@@ -1,26 +1,26 @@
1
1
  # @agentcash/discovery
2
2
 
3
- Canonical discovery library for the agentcash ecosystem.
3
+ Canonical discovery runtime for the agentcash ecosystem.
4
4
 
5
- ## What It Solves
5
+ Use one library for CLI, server, and client so discovery behavior is identical everywhere.
6
6
 
7
- - One deterministic discovery contract across `agentcash`, `agentcash-router`, `the-stables`, and scanners.
8
- - OpenAPI-first discovery with explicit compatibility fallbacks.
9
- - Progressive runtime output (`discover`) and full debug/indexer output (`discoverDetailed`).
7
+ ## Why One Library
10
8
 
11
- ## Discovery Order
9
+ - Same parsing logic across surfaces: no CLI/server/client drift.
10
+ - Same warning codes and precedence rules: fewer integration surprises.
11
+ - Same compatibility adapters in one place: legacy behavior is isolated and removable.
12
+ - Same L0-L5 harness model: easier context-budget auditing and rollout decisions.
12
13
 
13
- Default order is:
14
+ ## L0-L5 Mental Model
14
15
 
15
- 1. explicit override URLs (if provided)
16
- 2. OpenAPI (`/openapi.json`, then `/.well-known/openapi.json`)
17
- 3. `/.well-known/x402` (compat path)
18
- 4. DNS TXT `_x402` pointers (compat path)
19
- 5. live probe fallback (only when probe candidates are provided)
20
-
21
- `discover` stops on the first valid non-empty stage.
16
+ - `L0` trigger layer: intents like `x402`, `pay for` should route to agentcash.
17
+ - `L1` installed domain index: which domains are installed and when to fan out.
18
+ - `L2` domain resources: token-light list (`discover <domain>`).
19
+ - `L3` resource details: schema and deep metadata (`discover <domain> --verbose`).
20
+ - `L4` domain guidance: unstructured guidance (`llms.txt`) when available.
21
+ - `L5` cross-domain composition: intentionally out of scope for discovery v1.
22
22
 
23
- `discoverDetailed` runs the full waterfall and merges deterministically.
23
+ Design rule: `L0` + `L1` are zero-hop critical. `L2+` should be fetched on demand.
24
24
 
25
25
  ## Install
26
26
 
@@ -28,88 +28,170 @@ Default order is:
28
28
  pnpm add @agentcash/discovery
29
29
  ```
30
30
 
31
- CLI audit:
31
+ ## CLI Usage
32
+
33
+ Quick audit:
32
34
 
33
35
  ```bash
34
36
  npx @agentcash/discovery stabletravel.dev
37
+ ```
38
+
39
+ Verbose matrices:
40
+
41
+ ```bash
35
42
  npx @agentcash/discovery stabletravel.dev -v
43
+ ```
44
+
45
+ Machine-readable output:
46
+
47
+ ```bash
36
48
  npx @agentcash/discovery stabletravel.dev --json
37
49
  ```
38
50
 
39
- ## Usage
51
+ L0-L5 context harness summary for a client:
40
52
 
41
- ```ts
42
- import { discover, discoverDetailed } from '@agentcash/discovery';
53
+ ```bash
54
+ npx @agentcash/discovery stabletravel.dev --harness --client claude-code
55
+ ```
56
+
57
+ L0-L5 harness verbose with explicit budget:
43
58
 
44
- const result = await discover({
45
- target: 'https://api.example.com',
59
+ ```bash
60
+ npx @agentcash/discovery stabletravel.dev --harness -v --client skill-cli --context-window-tokens 200000
61
+ ```
62
+
63
+ Useful flags:
64
+
65
+ - `--compat on|off|strict`
66
+ - `--probe`
67
+ - `--timeout-ms <ms>`
68
+ - `--no-truncate`
69
+ - `--no-color`
70
+
71
+ ## Programmatic Usage
72
+
73
+ ```ts
74
+ import {
75
+ auditContextHarness,
76
+ discover,
77
+ discoverDetailed,
78
+ type HarnessClientId,
79
+ } from '@agentcash/discovery';
80
+
81
+ const progressive = await discover({
82
+ target: 'stabletravel.dev',
46
83
  compatMode: 'on',
47
84
  });
48
85
 
49
86
  const detailed = await discoverDetailed({
50
- target: 'api.example.com',
87
+ target: 'stabletravel.dev',
51
88
  compatMode: 'strict',
52
89
  rawView: 'full',
53
- includeInteropMpp: true,
54
- txtResolver: async (fqdn) => {
55
- // Provide DNS TXT lookup in your runtime.
56
- return [];
57
- },
90
+ });
91
+
92
+ const client: HarnessClientId = 'claude-code';
93
+ const harness = await auditContextHarness({
94
+ target: 'stabletravel.dev',
95
+ client,
96
+ contextWindowTokens: 200000,
97
+ compatMode: 'on',
58
98
  });
59
99
  ```
60
100
 
61
- ## Key API
101
+ ## MCP Adapter Contract
62
102
 
63
- - `discover(options)`: token-light, progressive, first-valid-non-empty.
64
- - `discoverDetailed(options)`: full trace/details, merge across stages, optional raw artifacts.
65
- - Both results include:
66
- - `upgradeSuggested` (`boolean`)
67
- - `upgradeReasons` (`string[]` warning-code reasons such as legacy-path usage)
103
+ This section is the canonical contract for MCP-facing discovery adapters:
68
104
 
69
- ## Compatibility Controls
105
+ - `discoverForMcp(options)` for L2 resources + L4 guidance policy projection.
106
+ - `inspectEndpointForMcp(options)` for L3 OpenAPI advisory projection.
70
107
 
71
- - `compatMode: 'on'` (default): enable legacy adapters.
72
- - `compatMode: 'off'`: disable all legacy adapters.
73
- - `compatMode: 'strict'`: enable legacy adapters and escalate legacy warnings to errors.
108
+ `discoverForMcp` guarantees:
74
109
 
75
- ## Internal Registry Audit Harness
110
+ - `guidanceAvailable` is always present.
111
+ - `guidanceTokens` is present when guidance exists.
112
+ - `guidance` is included when `includeGuidance=true`, excluded when
113
+ `includeGuidance=false`, and auto-included under the token threshold when not
114
+ specified.
76
115
 
77
- Use this to benchmark compatibility against the x402scan registry dataset.
116
+ `inspectEndpointForMcp` guarantees:
78
117
 
79
- ```bash
80
- SCAN_DATABASE_URL='postgresql://...' pnpm audit:registry
81
- ```
118
+ - Spec-derived HTTP methods for the selected endpoint path.
119
+ - Per-method advisory data: summary, estimated price, protocols, auth mode, and
120
+ input schema.
82
121
 
83
- Quick sample mode:
122
+ Ownership boundary:
84
123
 
85
- ```bash
86
- SCAN_DATABASE_URL='postgresql://...' pnpm audit:registry:quick
87
- ```
124
+ - `@agentcash/discovery` owns discovery/advisory contracts.
125
+ - Runtime probe truth (live 402 parsing/payment option extraction/divergence)
126
+ belongs to the `agentcash` MCP package.
88
127
 
89
- Outputs are written to:
128
+ Reference integration boundary:
90
129
 
91
- - `audit/registry-audit-<timestamp>.json`
92
- - `audit/registry-audit-latest.json`
130
+ - `https://github.com/Merit-Systems/agentcash/blob/main/packages/external/mcp/docs/discovery-boundary.md`
131
+
132
+ ## Discovery Waterfall
133
+
134
+ Default order:
135
+
136
+ 1. Explicit override URLs (if provided)
137
+ 2. OpenAPI (`/openapi.json`, then `/.well-known/openapi.json`)
138
+ 3. `/.well-known/x402` (compat)
139
+ 4. DNS TXT `_x402` pointers (compat)
140
+ 5. Probe fallback (only when probe candidates are provided)
93
141
 
94
- ## Canonical Contract
142
+ Behavior:
95
143
 
96
- Each normalized resource key is:
144
+ - `discover(...)` stops at first valid non-empty stage.
145
+ - `discoverDetailed(...)` runs full waterfall and merges deterministically.
146
+
147
+ ## Compatibility Modes
148
+
149
+ - `on` (default): legacy adapters enabled.
150
+ - `off`: canonical-only behavior.
151
+ - `strict`: legacy adapters enabled, selected warnings escalated.
152
+
153
+ ## Contract Guarantees
154
+
155
+ Resource identity:
97
156
 
98
157
  ```text
99
158
  ${origin} ${method} ${path}
100
159
  ```
101
160
 
102
- Required per-resource fields:
161
+ Required normalized fields:
103
162
 
104
163
  - `resourceKey`
105
164
  - `origin`
106
165
  - `method`
107
166
  - `path`
108
167
  - `source`
109
- - `verified` (defaults to `false`)
168
+ - `verified` (default `false`)
169
+
170
+ Philosophy boundary:
171
+
172
+ - Machine-parsable discovery metadata belongs in OpenAPI.
173
+ - `llms.txt` is optional, unstructured guidance.
174
+ - Discovery is advisory. Runtime payment challenge/probe is authoritative.
175
+
176
+ ## Internal Registry Audit Harness
177
+
178
+ For x402scan registry benchmarking:
179
+
180
+ ```bash
181
+ SCAN_DATABASE_URL='postgresql://...' pnpm audit:registry
182
+ ```
183
+
184
+ Quick sample:
185
+
186
+ ```bash
187
+ SCAN_DATABASE_URL='postgresql://...' pnpm audit:registry:quick
188
+ ```
189
+
190
+ Output:
191
+
192
+ - `audit/registry-audit-<timestamp>.json`
193
+ - `audit/registry-audit-latest.json`
110
194
 
111
- ## Philosophy Boundary
195
+ ## Deeper Docs
112
196
 
113
- - Machine-parsable discovery metadata lives in OpenAPI.
114
- - `llms.txt` is unstructured, optional domain guidance.
115
- - Discovery is advisory. Runtime challenge/probe is authoritative.
197
+ Architecture and planning artifacts live in `.claude/`.