@agentcash/discovery 0.0.0-pr-21-20260306191442

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 ADDED
@@ -0,0 +1,22 @@
1
+ # AGENTS.md
2
+
3
+ ## Purpose
4
+
5
+ This repo implements canonical discovery logic for the agentcash ecosystem.
6
+
7
+ ## Hard Constraints
8
+
9
+ 1. Keep canonical core and compatibility modules physically separate.
10
+ 2. Avoid legacy conditionals in `src/core/*`.
11
+ 3. Preserve stable warning codes.
12
+ 4. Keep `discover` token-light and deterministic.
13
+ 5. Keep compatibility removable via a single top-level mode.
14
+
15
+ ## Module Boundaries
16
+
17
+ - `src/core/*`: canonical OpenAPI-first discovery.
18
+ - `src/compat/legacy-x402scan/*`: `/.well-known/x402` + DNS `_x402` compatibility.
19
+
20
+ ## Result Contract
21
+
22
+ Resource identity is always `origin + method + path`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Merit Systems
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,217 @@
1
+ # @agentcash/discovery
2
+
3
+ Canonical discovery runtime for the agentcash ecosystem.
4
+
5
+ Use one library for CLI, server, and client so discovery behavior is identical everywhere.
6
+
7
+ ## Why One Library
8
+
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.
13
+
14
+ ## L0-L5 Mental Model
15
+
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
+
23
+ Design rule: `L0` + `L1` are zero-hop critical. `L2+` should be fetched on demand.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pnpm add @agentcash/discovery
29
+ ```
30
+
31
+ ## CLI Usage
32
+
33
+ Quick audit:
34
+
35
+ ```bash
36
+ npx @agentcash/discovery stabletravel.dev
37
+ ```
38
+
39
+ Verbose matrices:
40
+
41
+ ```bash
42
+ npx @agentcash/discovery stabletravel.dev -v
43
+ ```
44
+
45
+ Machine-readable output:
46
+
47
+ ```bash
48
+ npx @agentcash/discovery stabletravel.dev --json
49
+ ```
50
+
51
+ L0-L5 context harness summary for a client:
52
+
53
+ ```bash
54
+ npx @agentcash/discovery stabletravel.dev --harness --client claude-code
55
+ ```
56
+
57
+ L0-L5 harness verbose with explicit budget:
58
+
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
+ validatePaymentRequiredDetailed,
79
+ type HarnessClientId,
80
+ } from '@agentcash/discovery';
81
+
82
+ const progressive = await discover({
83
+ target: 'stabletravel.dev',
84
+ compatMode: 'on',
85
+ });
86
+
87
+ const detailed = await discoverDetailed({
88
+ target: 'stabletravel.dev',
89
+ compatMode: 'strict',
90
+ rawView: 'full',
91
+ });
92
+
93
+ const client: HarnessClientId = 'claude-code';
94
+ const harness = await auditContextHarness({
95
+ target: 'stabletravel.dev',
96
+ client,
97
+ contextWindowTokens: 200000,
98
+ compatMode: 'on',
99
+ });
100
+
101
+ const validation = validatePaymentRequiredDetailed(payload, {
102
+ compatMode: 'strict',
103
+ metadata: {
104
+ title: 'Example API',
105
+ description: 'Sample description',
106
+ favicon: 'https://example.com/favicon.ico',
107
+ ogImages: [{ url: 'https://example.com/og.png' }],
108
+ },
109
+ });
110
+ ```
111
+
112
+ ## MCP Adapter Contract
113
+
114
+ This section is the canonical contract for MCP-facing discovery adapters:
115
+
116
+ - `discoverForMcp(options)` for L2 resources + L4 guidance policy projection.
117
+ - `inspectEndpointForMcp(options)` for L3 OpenAPI advisory projection.
118
+
119
+ `discoverForMcp` guarantees:
120
+
121
+ - `guidanceAvailable` is always present.
122
+ - `guidanceTokens` is present when guidance exists.
123
+ - `guidance` is included when `includeGuidance=true`, excluded when
124
+ `includeGuidance=false`, and auto-included under the token threshold when not
125
+ specified.
126
+
127
+ `inspectEndpointForMcp` guarantees:
128
+
129
+ - Spec-derived HTTP methods for the selected endpoint path.
130
+ - Per-method advisory data: summary, estimated price, protocols, auth mode, and
131
+ input schema.
132
+
133
+ Ownership boundary:
134
+
135
+ - `@agentcash/discovery` owns discovery/advisory contracts.
136
+ - Runtime probe truth (live 402 parsing/payment option extraction/divergence)
137
+ belongs to the `agentcash` MCP package.
138
+
139
+ Reference integration boundary:
140
+
141
+ - `https://github.com/Merit-Systems/agentcash/blob/main/packages/external/mcp/docs/discovery-boundary.md`
142
+
143
+ ## Discovery Waterfall
144
+
145
+ Default order:
146
+
147
+ 1. Explicit override URLs (if provided)
148
+ 2. OpenAPI (`/openapi.json`, then `/.well-known/openapi.json`)
149
+ 3. `/.well-known/x402` (compat)
150
+ 4. DNS TXT `_x402` pointers (compat)
151
+ 5. Probe fallback (only when probe candidates are provided)
152
+
153
+ Behavior:
154
+
155
+ - `discover(...)` stops at first valid non-empty stage.
156
+ - `discoverDetailed(...)` runs full waterfall and merges deterministically.
157
+
158
+ Validation behavior:
159
+
160
+ - `validatePaymentRequiredDetailed(...)` uses Coinbase `@x402/core` schemas as the structural base gate.
161
+ - Product policy diagnostics (network/schema/metadata) are layered on top with stable issue codes.
162
+
163
+ ## Compatibility Modes
164
+
165
+ - `on` (default): legacy adapters enabled.
166
+ - `off`: canonical-only behavior.
167
+ - `strict`: legacy adapters enabled, selected warnings escalated.
168
+
169
+ ## Contract Guarantees
170
+
171
+ Resource identity:
172
+
173
+ ```text
174
+ ${origin} ${method} ${path}
175
+ ```
176
+
177
+ Required normalized fields:
178
+
179
+ - `resourceKey`
180
+ - `origin`
181
+ - `method`
182
+ - `path`
183
+ - `source`
184
+ - `verified` (default `false`)
185
+
186
+ Philosophy boundary:
187
+
188
+ - Machine-parsable discovery metadata belongs in OpenAPI.
189
+ - `llms.txt` is optional, unstructured guidance.
190
+ - Discovery is advisory. Runtime payment challenge/probe is authoritative.
191
+
192
+ ## Internal Registry Audit Harness
193
+
194
+ For x402scan registry benchmarking:
195
+
196
+ ```bash
197
+ SCAN_DATABASE_URL='postgresql://...' pnpm audit:registry
198
+ ```
199
+
200
+ Quick sample:
201
+
202
+ ```bash
203
+ SCAN_DATABASE_URL='postgresql://...' pnpm audit:registry:quick
204
+ ```
205
+
206
+ Output:
207
+
208
+ - `audit/registry-audit-<timestamp>.json`
209
+ - `audit/registry-audit-latest.json`
210
+
211
+ ## Deeper Docs
212
+
213
+ Architecture and planning artifacts live in `.claude/`.
214
+
215
+ Validation design doc:
216
+
217
+ - `docs/VALIDATION_DIAGNOSTICS_DESIGN_2026-03-03.md`
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { main } from '../dist/cli.js';
4
+
5
+ const exitCode = await main(process.argv.slice(2));
6
+ process.exit(exitCode);
package/dist/flags.cjs ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/flags.ts
21
+ var flags_exports = {};
22
+ __export(flags_exports, {
23
+ DEFAULT_COMPAT_MODE: () => DEFAULT_COMPAT_MODE,
24
+ LEGACY_SUNSET_DATE: () => LEGACY_SUNSET_DATE,
25
+ STRICT_ESCALATION_CODES: () => STRICT_ESCALATION_CODES
26
+ });
27
+ module.exports = __toCommonJS(flags_exports);
28
+ var LEGACY_SUNSET_DATE = "2026-03-24";
29
+ var DEFAULT_COMPAT_MODE = "on";
30
+ var STRICT_ESCALATION_CODES = [
31
+ "LEGACY_WELL_KNOWN_USED",
32
+ "LEGACY_DNS_USED",
33
+ "LEGACY_DNS_PLAIN_URL",
34
+ "LEGACY_MISSING_METHOD",
35
+ "LEGACY_INSTRUCTIONS_USED",
36
+ "LEGACY_OWNERSHIP_PROOFS_USED",
37
+ "INTEROP_MPP_USED"
38
+ ];
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ DEFAULT_COMPAT_MODE,
42
+ LEGACY_SUNSET_DATE,
43
+ STRICT_ESCALATION_CODES
44
+ });
@@ -0,0 +1,6 @@
1
+ declare const LEGACY_SUNSET_DATE = "2026-03-24";
2
+ type CompatibilityMode = 'on' | 'off' | 'strict';
3
+ declare const DEFAULT_COMPAT_MODE: CompatibilityMode;
4
+ declare const STRICT_ESCALATION_CODES: readonly ["LEGACY_WELL_KNOWN_USED", "LEGACY_DNS_USED", "LEGACY_DNS_PLAIN_URL", "LEGACY_MISSING_METHOD", "LEGACY_INSTRUCTIONS_USED", "LEGACY_OWNERSHIP_PROOFS_USED", "INTEROP_MPP_USED"];
5
+
6
+ export { type CompatibilityMode, DEFAULT_COMPAT_MODE, LEGACY_SUNSET_DATE, STRICT_ESCALATION_CODES };
@@ -0,0 +1,6 @@
1
+ declare const LEGACY_SUNSET_DATE = "2026-03-24";
2
+ type CompatibilityMode = 'on' | 'off' | 'strict';
3
+ declare const DEFAULT_COMPAT_MODE: CompatibilityMode;
4
+ declare const STRICT_ESCALATION_CODES: readonly ["LEGACY_WELL_KNOWN_USED", "LEGACY_DNS_USED", "LEGACY_DNS_PLAIN_URL", "LEGACY_MISSING_METHOD", "LEGACY_INSTRUCTIONS_USED", "LEGACY_OWNERSHIP_PROOFS_USED", "INTEROP_MPP_USED"];
5
+
6
+ export { type CompatibilityMode, DEFAULT_COMPAT_MODE, LEGACY_SUNSET_DATE, STRICT_ESCALATION_CODES };
package/dist/flags.js ADDED
@@ -0,0 +1,17 @@
1
+ // src/flags.ts
2
+ var LEGACY_SUNSET_DATE = "2026-03-24";
3
+ var DEFAULT_COMPAT_MODE = "on";
4
+ var STRICT_ESCALATION_CODES = [
5
+ "LEGACY_WELL_KNOWN_USED",
6
+ "LEGACY_DNS_USED",
7
+ "LEGACY_DNS_PLAIN_URL",
8
+ "LEGACY_MISSING_METHOD",
9
+ "LEGACY_INSTRUCTIONS_USED",
10
+ "LEGACY_OWNERSHIP_PROOFS_USED",
11
+ "INTEROP_MPP_USED"
12
+ ];
13
+ export {
14
+ DEFAULT_COMPAT_MODE,
15
+ LEGACY_SUNSET_DATE,
16
+ STRICT_ESCALATION_CODES
17
+ };