antpath 0.1.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 (68) hide show
  1. package/README.md +67 -0
  2. package/dist/client.d.ts +14 -0
  3. package/dist/client.js +36 -0
  4. package/dist/client.js.map +1 -0
  5. package/dist/credentials.d.ts +3 -0
  6. package/dist/credentials.js +27 -0
  7. package/dist/credentials.js.map +1 -0
  8. package/dist/errors.d.ts +25 -0
  9. package/dist/errors.js +39 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/files/downloader.d.ts +3 -0
  12. package/dist/files/downloader.js +35 -0
  13. package/dist/files/downloader.js.map +1 -0
  14. package/dist/index.d.ts +5 -0
  15. package/dist/index.js +5 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/providers/anthropic/provider.d.ts +30 -0
  18. package/dist/providers/anthropic/provider.js +302 -0
  19. package/dist/providers/anthropic/provider.js.map +1 -0
  20. package/dist/providers/types.d.ts +42 -0
  21. package/dist/providers/types.js +2 -0
  22. package/dist/providers/types.js.map +1 -0
  23. package/dist/run/controller.d.ts +27 -0
  24. package/dist/run/controller.js +224 -0
  25. package/dist/run/controller.js.map +1 -0
  26. package/dist/skills/packager.d.ts +11 -0
  27. package/dist/skills/packager.js +76 -0
  28. package/dist/skills/packager.js.map +1 -0
  29. package/dist/template/compiler.d.ts +28 -0
  30. package/dist/template/compiler.js +116 -0
  31. package/dist/template/compiler.js.map +1 -0
  32. package/dist/template/index.d.ts +10 -0
  33. package/dist/template/index.js +14 -0
  34. package/dist/template/index.js.map +1 -0
  35. package/dist/template/types.d.ts +67 -0
  36. package/dist/template/types.js +2 -0
  37. package/dist/template/types.js.map +1 -0
  38. package/dist/types.d.ts +129 -0
  39. package/dist/types.js +2 -0
  40. package/dist/types.js.map +1 -0
  41. package/dist/utils/events.d.ts +6 -0
  42. package/dist/utils/events.js +41 -0
  43. package/dist/utils/events.js.map +1 -0
  44. package/dist/utils/paths.d.ts +3 -0
  45. package/dist/utils/paths.js +21 -0
  46. package/dist/utils/paths.js.map +1 -0
  47. package/dist/utils/secrets.d.ts +10 -0
  48. package/dist/utils/secrets.js +59 -0
  49. package/dist/utils/secrets.js.map +1 -0
  50. package/dist/utils/stable.d.ts +2 -0
  51. package/dist/utils/stable.js +20 -0
  52. package/dist/utils/stable.js.map +1 -0
  53. package/docs/cleanup.md +15 -0
  54. package/docs/credentials.md +23 -0
  55. package/docs/mcp.md +18 -0
  56. package/docs/outputs.md +16 -0
  57. package/docs/quickstart.md +13 -0
  58. package/docs/release.md +22 -0
  59. package/docs/skills.md +16 -0
  60. package/docs/templates.md +24 -0
  61. package/docs/testing.md +27 -0
  62. package/examples/mcp-static-bearer.ts +30 -0
  63. package/examples/quickstart.ts +23 -0
  64. package/package.json +51 -0
  65. package/references/architecture-decisions.md +203 -0
  66. package/references/implementation-plan.md +527 -0
  67. package/references/research-sources.md +30 -0
  68. package/references/testing-strategy.md +108 -0
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "antpath",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript SDK for running autonomous Claude Managed Agents sessions.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/weilueluo/antpath.git"
8
+ },
9
+ "type": "module",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "docs",
22
+ "examples",
23
+ "references"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.build.json",
27
+ "lint": "tsc --noEmit",
28
+ "test": "vitest run test/unit test/integration/components test/integration/api-recorded",
29
+ "test:unit": "vitest run test/unit",
30
+ "test:integration:components": "vitest run test/integration/components",
31
+ "test:integration:api": "vitest run test/integration/api-recorded",
32
+ "test:e2e:live": "vitest run test/integration/live",
33
+ "fixtures:record:anthropic": "tsx scripts/record-api-fixtures.ts",
34
+ "fixtures:sanitize": "tsx scripts/sanitize-api-fixtures.ts",
35
+ "prepack": "npm run build"
36
+ },
37
+ "dependencies": {
38
+ "eventsource-parser": "3.0.6",
39
+ "fflate": "0.8.2"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "22.15.3",
43
+ "dotenv": "16.5.0",
44
+ "tsx": "4.19.4",
45
+ "typescript": "5.8.3",
46
+ "vitest": "3.1.2"
47
+ },
48
+ "engines": {
49
+ "node": ">=20"
50
+ }
51
+ }
@@ -0,0 +1,203 @@
1
+ ---
2
+ title: antpath architecture decisions
3
+ status: accepted
4
+ scope: sdk-only MVP
5
+ ---
6
+
7
+ # antpath architecture decisions
8
+
9
+ ## Product framing
10
+
11
+ antpath starts as a **TypeScript-first SDK** for launching autonomous agent runs on provider-managed agent infrastructure. The MVP is intentionally not a dashboard, not a cloud control plane, not an agent-loop framework, and not a sandbox provider.
12
+
13
+ The SDK gives users a typed way to define reusable, code-first Templates and run them with caller-held provider credentials. The SDK returns a handle for monitoring, waiting, streaming events, downloading files, terminating, and cleaning up provider resources.
14
+
15
+ ## Non-goals for MVP
16
+
17
+ - No dashboard.
18
+ - No antpath-hosted run orchestration service.
19
+ - No stored provider API keys.
20
+ - No stored MCP credentials.
21
+ - No stored output file contents.
22
+ - No local stdio MCP bridge.
23
+ - No arbitrary MCP auth headers.
24
+ - No OpenAI integration in MVP.
25
+ - No runtime human approval flow.
26
+ - No antpath-managed sandbox.
27
+
28
+ ## Core MVP decisions
29
+
30
+ | Area | Decision |
31
+ | --- | --- |
32
+ | Product surface | SDK-only MVP. |
33
+ | Primary language | TypeScript first. |
34
+ | Provider | Claude Managed Agents only. |
35
+ | Future providers | OpenAI is backlog; do not force a lowest-common-denominator abstraction into MVP. |
36
+ | Template model | Code-only, immutable, secret-free Template snapshots. |
37
+ | Template name | Use `Template`, not `Environment`, to avoid collision with provider environment objects. |
38
+ | Provider key handling | User creates a SDK `Client` with the provider key; antpath does not store it. |
39
+ | MCP credential handling | Credentials are supplied at run time in typed objects; antpath creates provider vault credentials per run where needed. |
40
+ | MCP auth scope | Provider-native static bearer and OAuth access token only. |
41
+ | Runtime approvals | No runtime approval/HITL. Tool allow/deny policy is configured before session start. |
42
+ | MCP server scope | User-provided remote HTTPS MCP servers only. |
43
+ | Provider objects | SDK creates Agent, Environment, Vault/Credentials, and Session per run. |
44
+ | Cleanup default | Manual cleanup via `handle.cleanup()` by default. |
45
+ | Orphan risk | Accepted for MVP if the SDK process exits before cleanup. |
46
+ | Run input | One or more queued `user.message` events. |
47
+ | Queue behavior | First message starts the session; subsequent messages are sent whenever the session becomes idle. |
48
+ | Completion | First idle state after all queued messages have been sent. |
49
+ | Error behavior | Abort on any provider session error or terminated state. |
50
+ | Budget guardrails | Timeout and manual terminate only. |
51
+ | Outputs | `downloadOutputs()` downloads all session-scoped files by default. `/antpath/outputs` is a recommended convention, not a provider default. |
52
+ | Skills | Support local skill upload plus inline skill definitions. |
53
+ | Variables | Strict Template variable resolution with escaping for literal placeholders. |
54
+ | Secret boundary | Secrets are allowed only in typed credential inputs, never interpolated as Template variables. |
55
+ | Handle API | `status`, `streamEvents`, `wait`, `listFiles`, `downloadFile`, `downloadOutputs`, `cleanup`, `terminate`, `usage`, `result`. |
56
+ | Development workflow | Test-first development with unit, component integration, recorded API integration, and live e2e tests. |
57
+
58
+ ## Template contract
59
+
60
+ Templates are code-defined, immutable configuration snapshots. A Template may include:
61
+
62
+ - model;
63
+ - system prompt;
64
+ - one or more user messages;
65
+ - inline skills;
66
+ - local skill paths to upload;
67
+ - MCP server declarations;
68
+ - MCP tool allow/deny policy;
69
+ - required credential declarations;
70
+ - environment packages and setup commands;
71
+ - network allowlist;
72
+ - output path conventions or file filters;
73
+ - non-secret metadata.
74
+
75
+ Templates may use typed variables in:
76
+
77
+ - system prompt;
78
+ - user messages;
79
+ - skill content/config;
80
+ - MCP URLs;
81
+ - MCP tool policy;
82
+ - environment packages/setup;
83
+ - network allowlist;
84
+ - output paths;
85
+ - metadata.
86
+
87
+ All variables must resolve before provider object creation. Unresolved variables fail fast. Literal placeholder syntax must be escaped explicitly.
88
+
89
+ ## Credential contract
90
+
91
+ Templates declare credential requirements but never contain credential values.
92
+
93
+ MVP credential types:
94
+
95
+ - `static_bearer`;
96
+ - `oauth_access_token`.
97
+
98
+ Out of scope for MVP:
99
+
100
+ - arbitrary headers;
101
+ - OAuth refresh handling;
102
+ - persisted credential vault in antpath;
103
+ - antpath-hosted MCP proxy.
104
+
105
+ For Claude Managed Agents, the SDK creates a per-run provider vault and credentials, passes the vault ID to session creation, and deletes the provider vault during cleanup. Since the SDK caller owns the provider key, cleanup requires the SDK process or a later caller with the same key.
106
+
107
+ ## Run lifecycle
108
+
109
+ 1. Resolve Template variables and validate the resolved Template.
110
+ 2. Validate typed credentials against Template credential requirements.
111
+ 3. Create provider Environment.
112
+ 4. Upload local skill/resources and create inline skill resources as required.
113
+ 5. Create provider Agent with tools, skills, MCP servers, and permission policies.
114
+ 6. Create per-run provider Vault and Credentials when MCP credentials are supplied.
115
+ 7. Create provider Session with Agent, Environment, resources, and vault IDs.
116
+ 8. Send the first queued `user.message`.
117
+ 9. Stream provider events and update local run state.
118
+ 10. If the session becomes idle and queued messages remain, send the next message.
119
+ 11. If any provider error or terminated state occurs, abort and return a failed result.
120
+ 12. When the session becomes idle and no queued messages remain, mark the run succeeded.
121
+ 13. On `downloadOutputs()`, list and download session-scoped files.
122
+ 14. On `cleanup()`, delete/cleanup created provider resources according to policy.
123
+
124
+ ## State model
125
+
126
+ MVP state lives in the SDK handle and returned result. There is no cloud persistence requirement.
127
+
128
+ Run states:
129
+
130
+ - `initializing`;
131
+ - `creating_provider_resources`;
132
+ - `running`;
133
+ - `idle_waiting_to_send_next_message`;
134
+ - `downloading_outputs`;
135
+ - `succeeded`;
136
+ - `failed`;
137
+ - `terminating`;
138
+ - `terminated`;
139
+ - `cleanup_pending`;
140
+ - `cleaned_up`;
141
+
142
+ The handle should retain enough non-secret data to support local inspection:
143
+
144
+ - provider object IDs;
145
+ - Template version/hash;
146
+ - status timestamps;
147
+ - usage/cost summary when available;
148
+ - error details;
149
+ - cleanup state;
150
+ - downloaded file manifest if files were downloaded locally.
151
+
152
+ ## Cleanup policy
153
+
154
+ Manual cleanup is the default. This preserves post-run provider access and avoids surprising users by deleting files/events before they inspect them.
155
+
156
+ The SDK may support configurable cleanup policies:
157
+
158
+ - manual;
159
+ - cleanup after successful output download;
160
+ - cleanup on success;
161
+ - cleanup always after terminal state;
162
+ - delete only vault/credentials.
163
+
164
+ If the process exits before cleanup, provider resources may remain in the user's provider workspace. The SDK should expose cleanup state and enough provider IDs to support later cleanup when the user recreates a Client with the same provider key.
165
+
166
+ ## Risks accepted for MVP
167
+
168
+ | Risk | Status | Mitigation |
169
+ | --- | --- | --- |
170
+ | Provider objects can be orphaned if the SDK process dies before cleanup. | Accepted | Manual cleanup default; expose cleanup state and provider IDs. |
171
+ | Per-run Environment creation may be slow. | Accepted | Keep design simple for MVP; later cache by Template hash if needed. |
172
+ | Timeout-only budgeting does not cap token/tool spend. | Accepted | BYOK MVP; expose usage summary where provider supports it. |
173
+ | Arbitrary remote MCP servers can exfiltrate context. | Accepted with guardrails | Require explicit MCP declarations and tool allow/deny config; no runtime approvals. |
174
+ | No dashboard/cloud persistence. | Accepted | SDK-only MVP; dashboard is backlog. |
175
+ | OpenAI MCP auth differs from Claude vaults. | Backlog design risk | Add provider-specific auth adapters later; avoid pretending uniform support exists now. |
176
+
177
+ ## Verification contract
178
+
179
+ Every feature starts with the narrowest failing test that describes the intended behavior. Implementation follows only after the test shape is clear.
180
+
181
+ Required test layers:
182
+
183
+ 1. Unit tests for pure functions and small state transitions.
184
+ 2. Component integration tests across SDK modules using fake providers and local fixtures.
185
+ 3. Recorded API integration tests using persisted, sanitized responses captured from real provider API calls and reproducible recording scripts.
186
+ 4. Live e2e tests gated behind local credentials in `.env.local`.
187
+
188
+ Secrets must never appear in committed fixtures, logs, snapshots, manifests, errors, or reference docs.
189
+
190
+ ## Backlog
191
+
192
+ - Dashboard and cloud metadata sync.
193
+ - Cloud Template registry.
194
+ - OpenAI Responses/Agents adapter.
195
+ - Encrypted run-scoped keys for guaranteed cleanup.
196
+ - Cost/token/iteration caps.
197
+ - OAuth refresh credential support.
198
+ - Arbitrary MCP headers through an antpath MCP proxy.
199
+ - Curated MCP adapter catalog.
200
+ - Provider Environment caching by Template hash.
201
+ - Artifact retention service.
202
+ - Webhook-based monitoring.
203
+ - Team/workspace/multi-tenant permissions.