Skip to content

Commit 29880cb

Browse files
committed
test: lock in multi-service contract via EchoService test
Demonstrates that a new service can be implemented using only the public primitives from src/core/ — HttpClient, StaticAuthHeaderProvider, and resolveCoreConfig — without touching auth/ or services/atlantic/. Also asserts the disambiguation property: two services exposing a method with the same name (e.g. submitQuery) stay unambiguous because each lives on its own instance/namespace. The full registration walkthrough (HcloudSurface enum, HcloudClient namespace, CLI dispatcher list, src/index.ts re-exports) is documented in docs/guides/adding-a-service.md. Phase 5 of /docs/plans/2026-05-07-001-feat-rename-to-hcloud-multi-service-sdk-plan.md
1 parent cc70a11 commit 29880cb

3 files changed

Lines changed: 844 additions & 0 deletions

File tree

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
---
2+
date: 2026-05-06
3+
topic: atlantic-bun-sdk
4+
---
5+
6+
# Atlantic Bun SDK
7+
8+
## Summary
9+
10+
Build a Bun-first TypeScript SDK and CLI for Atlantic that covers the full public API while also providing agent-friendly workflow helpers for query submission, lifecycle tracking, retries, buckets, artifacts, and x402 payments.
11+
12+
---
13+
14+
## Problem Frame
15+
16+
Atlantic already exposes proving, query lifecycle, bucket, and payment capabilities through public API documentation and the `atlantic-api` AI skill. A developer or coding agent can call those endpoints directly, but doing so forces every integration to rediscover request composition, multipart file handling, polling, retry semantics, x402 payment flow, artifact lookup, and error interpretation.
17+
18+
The SDK should make Atlantic easier to use from Bun and TypeScript projects without hiding the underlying API model. It should also give agents a predictable surface with clear method descriptions, safer defaults, and workflow-level helpers so agent-built integrations are less likely to hallucinate endpoints, mishandle payments, or lose query state.
19+
20+
---
21+
22+
## Actors
23+
24+
- A1. SDK user: A developer integrating Atlantic into a Bun or TypeScript application.
25+
- A2. CLI user: A developer or operator running Atlantic workflows from a terminal.
26+
- A3. AI agent: A coding or operations agent using the SDK/CLI with limited context and needing strong descriptions and guardrails.
27+
- A4. Atlantic API: The existing Herodotus Atlantic service that receives queries, tracks jobs, manages buckets, and handles x402 challenges.
28+
29+
---
30+
31+
## Key Flows
32+
33+
- F1. Submit and track a query
34+
- **Trigger:** A user wants to submit a Cairo program, PIE, or proof-related input to Atlantic.
35+
- **Actors:** A1, A2, A3, A4
36+
- **Steps:** The caller prepares input files and query options, submits the request, receives an Atlantic query ID, and can poll or inspect details until the query reaches a terminal state.
37+
- **Outcome:** The caller has a durable query ID, current status, and a clear path to metadata or artifacts.
38+
- **Covered by:** R1, R2, R5, R8, R9
39+
40+
- F2. Recover or retry a query
41+
- **Trigger:** A query fails, a submit operation is ambiguous, or a caller needs to locate a query by deduplication key.
42+
- **Actors:** A1, A2, A3, A4
43+
- **Steps:** The caller retrieves query details or looks up by deduplication key, determines whether retry is allowed, retries through the API when valid, and surfaces non-retriable states clearly.
44+
- **Outcome:** Retriable failures are restarted without guessing; non-retriable failures are explained.
45+
- **Covered by:** R3, R4, R6, R9, R10
46+
47+
- F3. Work with Applicative Recursion buckets
48+
- **Trigger:** A caller wants to group multiple Atlantic queries into a bucket for Applicative Recursion.
49+
- **Actors:** A1, A2, A3, A4
50+
- **Steps:** The caller creates or lists buckets, submits bucket-linked queries when supported, inspects bucket details and associated queries, and closes a bucket when ready.
51+
- **Outcome:** Bucket workflows are available through both SDK and CLI without manual endpoint composition.
52+
- **Covered by:** R7, R8, R9, R11
53+
54+
- F4. Pay with x402 when required
55+
- **Trigger:** A submit request receives a payment challenge because project credits are insufficient or the caller uses an anonymous wallet flow.
56+
- **Actors:** A1, A3, A4
57+
- **Steps:** The SDK exposes the challenge, signs or delegates signing through a wallet adapter, retries the original submit with a payment signature, and returns the settlement response alongside the query result.
58+
- **Outcome:** Payment is handled according to the public x402 flow, without preemptive signatures or invented payment endpoints.
59+
- **Covered by:** R12, R13, R14, R15
60+
61+
---
62+
63+
## Requirements
64+
65+
**API coverage**
66+
- R1. The SDK must expose typed methods for every public Atlantic API capability documented in the current Atlantic OpenAPI contract: health check, submit query, get query by ID, get query by dedup ID, list queries, query stats, query jobs, retry query, list buckets, create bucket, get bucket details, and close bucket.
67+
- R2. Query submission must support the documented Atlantic inputs and options, including program, input, PIE, and proof file inputs; Cairo version and VM options; result selection; layouts; prover selection; declared job size; network selection; deduplication identifiers; external identifiers; and bucket-related fields.
68+
- R3. Query lookup must support direct query ID lookup and deduplication-key lookup as separate explicit capabilities.
69+
- R4. Retry support must call the public retry capability and clearly distinguish retriable, non-retriable, max-retry, missing-query, forbidden, and wrong-state outcomes.
70+
- R5. Query lifecycle support must make status, step, job list, metadata URLs, and terminal-state inspection easy to consume without requiring callers to manually understand every raw API response.
71+
- R6. List operations must support pagination where the Atlantic API supports it.
72+
- R7. Bucket support must cover listing buckets, creating buckets, fetching bucket details with associated queries, closing buckets, and submitting bucket-linked queries where the API permits them.
73+
74+
**Agent-first workflow helpers**
75+
- R8. The SDK must include higher-level helpers for common workflows: submit-and-return-ID, submit-and-wait, wait-for-query, retry-if-retriable, get-query-with-jobs, and bucket-oriented submission.
76+
- R9. Workflow helpers must preserve caller control over polling intervals, timeout budgets, retry budgets, and terminal-state behavior.
77+
- R10. The SDK must keep Atlantic query IDs, dedup IDs, and bucket IDs visible as first-class outputs rather than hiding them inside opaque workflow results.
78+
- R11. Agent-facing helper descriptions must include what the helper does, when to use it, required inputs, important constraints, expected result, and common failure modes.
79+
80+
**x402 payments**
81+
- R12. The SDK must support Atlantic's documented x402 v2 flow for `submit query`, including challenge parsing, payment-signature retry, and settlement-response parsing.
82+
- R13. The SDK must support both API-key fallback payments and anonymous wallet payments, while making their behavioral differences explicit to the caller.
83+
- R14. The SDK must prevent or clearly warn against unsafe x402 usage: preemptive payment signatures, reused successful payment signatures, hardcoded payment requirements, anonymous `dedupId` usage, anonymous bucket usage, and double-payment after ambiguous settlement.
84+
- R15. x402 signing must be wallet-adapter friendly so applications can provide their own signing implementation rather than coupling the SDK to a single wallet source.
85+
86+
**CLI**
87+
- R16. The CLI must expose commands for the same main capabilities as the SDK: submit query, retry query, get query details, get query by dedup ID, list queries, get query jobs, query stats, list buckets, create bucket, get bucket, close bucket, and health check.
88+
- R17. CLI commands must support file-path inputs for query submission and must print machine-readable JSON by default or through an explicit mode.
89+
- R18. CLI commands must support environment-based configuration for the Atlantic base URL, API key, and payment-related wallet configuration.
90+
- R19. CLI output must preserve important identifiers, status, payment receipt data, and error details so agents can chain commands reliably.
91+
92+
**Developer experience and quality**
93+
- R20. The package must be Bun-first while remaining idiomatic TypeScript for library consumers.
94+
- R21. Public SDK methods must have clear names, strong TypeScript types, and documentation comments that explain behavior rather than merely restating parameter names.
95+
- R22. The SDK must separate low-level API methods from higher-level workflow helpers so advanced users can keep exact control while agents and common integrations get safer defaults.
96+
- R23. Errors must be structured enough for callers to branch on category, HTTP status where available, Atlantic message/code where available, and payment-specific failure class where available.
97+
- R24. The codebase must be organized for maintainability, with focused modules, minimal duplication, and tests that cover request construction, response parsing, x402 behavior, workflow helpers, and CLI command behavior.
98+
99+
---
100+
101+
## Acceptance Examples
102+
103+
- AE1. **Covers R1, R16.** Given a user wants to inspect their Atlantic usage from code or terminal, when they list queries, fetch query details, fetch query jobs, or query stats, then both SDK and CLI expose those capabilities without requiring manual URL construction.
104+
- AE2. **Covers R2, R8, R10.** Given a user submits a query using a local PIE file, when submission succeeds, then the result includes the Atlantic query ID and any relevant metadata needed for later polling or artifact inspection.
105+
- AE3. **Covers R4, R23.** Given a failed query is not retriable or has exceeded retry limits, when the caller retries it, then the SDK/CLI returns a structured failure that lets the caller distinguish the reason without parsing prose.
106+
- AE4. **Covers R7, R16.** Given a user is building an Applicative Recursion flow, when they create a bucket, submit bucket-linked queries, inspect the bucket, and close it, then each step is available through documented SDK methods and CLI commands.
107+
- AE5. **Covers R12, R14, R15.** Given a submit request receives an x402 challenge, when the caller provides a wallet signing adapter, then the SDK signs the documented payment authorization, retries the original submit, returns the query result and settlement response, and does not reuse a successful payment signature for a later query.
108+
- AE6. **Covers R11, R21.** Given an AI agent sees only the SDK method descriptions, when it chooses between direct API methods and workflow helpers, then the descriptions are concrete enough to avoid inventing unsupported payment endpoints or unsupported anonymous-flow bucket/dedup behavior.
109+
- AE7. **Covers R17, R19.** Given an agent runs the CLI in a shell workflow, when a command succeeds or fails, then the output includes stable JSON fields for IDs, status, result data, payment receipt data, and structured errors.
110+
111+
---
112+
113+
## Success Criteria
114+
115+
- A developer can complete a normal Atlantic proof workflow from Bun using the SDK without reading the raw OpenAPI spec for every call.
116+
- An AI agent can use the SDK/CLI safely for submit, poll, retry, bucket, and x402 workflows with low hallucination risk.
117+
- Full public API coverage exists without sacrificing clear higher-level workflow helpers.
118+
- Payment behavior follows Atlantic's documented x402 flow and avoids double-payment or unsupported anonymous-flow behavior.
119+
- A downstream planning or implementation agent can proceed from this document without inventing SDK product behavior or CLI scope.
120+
121+
---
122+
123+
## Scope Boundaries
124+
125+
- Do not change the Atlantic backend or public API as part of this SDK effort.
126+
- Do not invent payment endpoints or payment flows outside the documented x402 behavior on query submission.
127+
- Do not build a GUI, dashboard, or hosted service.
128+
- Do not hide all Atlantic concepts behind a single opaque workflow; query IDs, dedup IDs, statuses, jobs, buckets, and payment receipts remain visible.
129+
- Do not implement persistent state storage as a required SDK feature in the first version; applications may persist IDs and results themselves.
130+
- Do not make on-chain verification adapters a blocker unless they are thin helpers around documented Atlantic results and public integration points.
131+
132+
---
133+
134+
## Key Decisions
135+
136+
- Full API plus agent-first helpers: The SDK should not choose between complete endpoint coverage and ergonomic workflows; it needs both because direct developers and AI agents have different needs.
137+
- SDK as the source of logic, CLI as operational surface: Shared SDK behavior prevents divergent request handling, x402 semantics, and error interpretation between code and terminal usage.
138+
- x402 scoped to documented submit flow: This keeps payment support useful while avoiding hallucinated endpoints and unsafe payment abstractions.
139+
- Explicit IDs and structured errors: Atlantic workflows are asynchronous and operational; callers need durable identifiers and branchable errors more than opaque convenience wrappers.
140+
- Documentation comments are part of the product: Method descriptions should guide agents and developers toward correct usage, not merely satisfy generated API documentation.
141+
142+
---
143+
144+
## Dependencies / Assumptions
145+
146+
- The current source of truth is the Atlantic OpenAPI contract, the Atlantic API docs, the `atlantic-api` AI skill, and the existing Atlantic route schemas.
147+
- Bun is the primary runtime and package manager target.
148+
- TypeScript users are a primary audience, so types and documentation comments carry product value.
149+
- Wallet signing should be adapter-based because caller environments vary across agents, CLIs, server apps, and local scripts.
150+
- API-key authentication remains the normal flow; x402 is used when required by Atlantic or when anonymous wallet flow is intentionally used.
151+
152+
---
153+
154+
## Outstanding Questions
155+
156+
### Deferred to Planning
157+
158+
- [Affects R12, R15][Technical] Which wallet/signing adapter shape best supports Bun CLI, server-side SDK use, and external wallet clients without overcoupling?
159+
- [Affects R17, R18][Technical] What exact CLI command naming and configuration precedence should be used for environment variables, flags, and config files?
160+
- [Affects R24][Needs research] Should SDK types be generated from OpenAPI, hand-authored from source schemas, or combined with a generated base plus curated workflow types?
161+
- [Affects R8, R9][Technical] What default polling interval, timeout, and retry budgets should helpers use?

0 commit comments

Comments
 (0)