antpath 0.1.1 → 0.2.1
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/README.md +40 -4
- package/dist/cli.mjs +367 -0
- package/dist/cli.mjs.sha256 +1 -0
- package/dist/client.js +4 -1
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/platform/client.d.ts +138 -7
- package/dist/platform/client.js +98 -2
- package/dist/platform/client.js.map +1 -1
- package/dist/providers/known-events.d.ts +60 -0
- package/dist/providers/known-events.js +64 -0
- package/dist/providers/known-events.js.map +1 -0
- package/dist/run/controller.d.ts +4 -1
- package/dist/run/controller.js +103 -13
- package/dist/run/controller.js.map +1 -1
- package/dist/template/index.d.ts +1 -1
- package/dist/types.d.ts +20 -0
- package/dist/utils/events.d.ts +21 -0
- package/dist/utils/events.js +97 -18
- package/dist/utils/events.js.map +1 -1
- package/docs/credentials.md +84 -2
- package/docs/events.md +129 -0
- package/docs/skills.md +2 -0
- package/package.json +5 -2
- package/references/architecture-decisions.md +110 -64
- package/references/implementation-plan.md +66 -44
package/dist/utils/events.js
CHANGED
|
@@ -1,39 +1,118 @@
|
|
|
1
1
|
export class AsyncEventBus {
|
|
2
2
|
#history = [];
|
|
3
|
-
#
|
|
3
|
+
#streamSubscribers = new Set();
|
|
4
|
+
#listeners = new Set();
|
|
4
5
|
#closed = false;
|
|
5
6
|
emit(event) {
|
|
6
7
|
if (this.#closed) {
|
|
7
8
|
return;
|
|
8
9
|
}
|
|
9
10
|
this.#history.push(event);
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
for (const subscriber of this.#streamSubscribers) {
|
|
12
|
+
const wake = subscriber.wake;
|
|
13
|
+
if (wake) {
|
|
14
|
+
subscriber.wake = undefined;
|
|
15
|
+
wake();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
for (const listener of this.#listeners) {
|
|
19
|
+
listener.chain = listener.chain.then(() => listener.handler(event)).catch((error) => {
|
|
20
|
+
try {
|
|
21
|
+
listener.onError(error, event);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// onError must never throw; swallow to keep the chain alive for future events.
|
|
25
|
+
}
|
|
26
|
+
});
|
|
13
27
|
}
|
|
14
28
|
}
|
|
15
29
|
close() {
|
|
30
|
+
if (this.#closed) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
16
33
|
this.#closed = true;
|
|
17
|
-
for (const
|
|
18
|
-
|
|
34
|
+
for (const subscriber of this.#streamSubscribers) {
|
|
35
|
+
const wake = subscriber.wake;
|
|
36
|
+
if (wake) {
|
|
37
|
+
subscriber.wake = undefined;
|
|
38
|
+
wake();
|
|
39
|
+
}
|
|
19
40
|
}
|
|
20
41
|
}
|
|
42
|
+
closed() {
|
|
43
|
+
return this.#closed;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Register a callback that is invoked for every emitted event in order.
|
|
47
|
+
*
|
|
48
|
+
* Async handlers are serialized through a per-listener promise chain so
|
|
49
|
+
* invocation order matches emission order. Errors thrown synchronously or
|
|
50
|
+
* via rejected promises are routed to onError. The chain stays fulfilled
|
|
51
|
+
* even when handlers fail, so subsequent events still trigger the handler.
|
|
52
|
+
*/
|
|
53
|
+
addListener(handler, onError) {
|
|
54
|
+
const listener = {
|
|
55
|
+
handler,
|
|
56
|
+
onError,
|
|
57
|
+
chain: Promise.resolve()
|
|
58
|
+
};
|
|
59
|
+
this.#listeners.add(listener);
|
|
60
|
+
return () => {
|
|
61
|
+
this.#listeners.delete(listener);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Await every queued listener invocation that has already been scheduled at
|
|
66
|
+
* the moment this method is called. Callers (e.g., the run controller)
|
|
67
|
+
* must finish emitting before invoking drainListeners; emits that happen
|
|
68
|
+
* after drainListeners is awaited are not guaranteed to be observed by the
|
|
69
|
+
* returned promise.
|
|
70
|
+
*/
|
|
71
|
+
async drainListeners() {
|
|
72
|
+
if (this.#listeners.size === 0) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const snapshot = [...this.#listeners].map((listener) => listener.chain);
|
|
76
|
+
await Promise.all(snapshot);
|
|
77
|
+
}
|
|
21
78
|
stream() {
|
|
22
79
|
const self = this;
|
|
23
80
|
return {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
81
|
+
[Symbol.asyncIterator]() {
|
|
82
|
+
const subscriber = { wake: undefined, done: false };
|
|
83
|
+
self.#streamSubscribers.add(subscriber);
|
|
84
|
+
let cursor = 0;
|
|
85
|
+
return {
|
|
86
|
+
async next() {
|
|
87
|
+
while (true) {
|
|
88
|
+
if (subscriber.done) {
|
|
89
|
+
self.#streamSubscribers.delete(subscriber);
|
|
90
|
+
return { value: undefined, done: true };
|
|
91
|
+
}
|
|
92
|
+
if (cursor < self.#history.length) {
|
|
93
|
+
const value = self.#history[cursor++];
|
|
94
|
+
return { value, done: false };
|
|
95
|
+
}
|
|
96
|
+
if (self.#closed) {
|
|
97
|
+
self.#streamSubscribers.delete(subscriber);
|
|
98
|
+
return { value: undefined, done: true };
|
|
99
|
+
}
|
|
100
|
+
await new Promise((resolve) => {
|
|
101
|
+
subscriber.wake = resolve;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
async return() {
|
|
106
|
+
subscriber.done = true;
|
|
107
|
+
const wake = subscriber.wake;
|
|
108
|
+
if (wake) {
|
|
109
|
+
subscriber.wake = undefined;
|
|
110
|
+
wake();
|
|
111
|
+
}
|
|
112
|
+
self.#streamSubscribers.delete(subscriber);
|
|
113
|
+
return { value: undefined, done: true };
|
|
33
114
|
}
|
|
34
|
-
|
|
35
|
-
yield next.value;
|
|
36
|
-
}
|
|
115
|
+
};
|
|
37
116
|
}
|
|
38
117
|
};
|
|
39
118
|
}
|
package/dist/utils/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/utils/events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/utils/events.ts"],"names":[],"mappings":"AAeA,MAAM,OAAO,aAAa;IACf,QAAQ,GAAQ,EAAE,CAAC;IACnB,kBAAkB,GAAG,IAAI,GAAG,EAAoB,CAAC;IACjD,UAAU,GAAG,IAAI,GAAG,EAAe,CAAC;IAC7C,OAAO,GAAG,KAAK,CAAC;IAEhB,IAAI,CAAC,KAAQ;QACX,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACjD,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;YAC7B,IAAI,IAAI,EAAE,CAAC;gBACT,UAAU,CAAC,IAAI,GAAG,SAAS,CAAC;gBAC5B,IAAI,EAAE,CAAC;YACT,CAAC;QACH,CAAC;QACD,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACvC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBAClF,IAAI,CAAC;oBACH,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBACjC,CAAC;gBAAC,MAAM,CAAC;oBACP,+EAA+E;gBACjF,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,OA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O,EAAE,KAAK,EAAE,SAAc,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;oBAC/C,CAAC;iBACF,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
package/docs/credentials.md
CHANGED
|
@@ -17,7 +17,89 @@ Unsupported in MVP:
|
|
|
17
17
|
|
|
18
18
|
- arbitrary headers;
|
|
19
19
|
- OAuth refresh;
|
|
20
|
-
- persisted antpath vault
|
|
21
|
-
- antpath MCP proxy.
|
|
20
|
+
- persisted antpath vault.
|
|
22
21
|
|
|
23
22
|
For Claude Managed Agents, the SDK creates per-run provider vault credentials and tracks provider IDs for cleanup.
|
|
23
|
+
|
|
24
|
+
## Proxy endpoints (per-run custom HTTP credentials)
|
|
25
|
+
|
|
26
|
+
Some skills need to call non-MCP HTTP services (e.g. Stripe, internal APIs). Embedding the credential in the skill content puts the raw secret on disk in the agent container and in the model's context — both prompt-injection-readable.
|
|
27
|
+
|
|
28
|
+
The platform's managed HTTP proxy is the agent-first alternative. The caller declares **policy** at the top level of the submission (hashed for idempotency) and supplies the matching **auth value** inside `secrets` (not hashed, so key rotation does not collapse onto a stale run). The raw credential value never enters the container.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import {
|
|
32
|
+
AntpathPlatformClient,
|
|
33
|
+
validateProxyAuth,
|
|
34
|
+
buildPlatformAllowedHosts
|
|
35
|
+
} from "antpath";
|
|
36
|
+
|
|
37
|
+
const client = new AntpathPlatformClient({
|
|
38
|
+
baseUrl: "https://dashboard.antpath.dev",
|
|
39
|
+
apiToken: "ant_..."
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const proxyEndpoints = [
|
|
43
|
+
{
|
|
44
|
+
name: "stripe",
|
|
45
|
+
baseUrl: "https://api.stripe.com",
|
|
46
|
+
authShape: { type: "bearer" },
|
|
47
|
+
allowMethods: ["GET", "POST"],
|
|
48
|
+
allowPathPrefixes: ["/v1/charges", "/v1/refunds"],
|
|
49
|
+
maxRequestBytes: 65_536,
|
|
50
|
+
maxResponseBytes: 65_536,
|
|
51
|
+
timeoutMs: 10_000,
|
|
52
|
+
responseMode: "headers_only",
|
|
53
|
+
perCallBudget: 60,
|
|
54
|
+
responseByteBudget: 1_048_576
|
|
55
|
+
}
|
|
56
|
+
] as const;
|
|
57
|
+
|
|
58
|
+
const proxyEndpointAuth = [
|
|
59
|
+
{
|
|
60
|
+
name: "stripe",
|
|
61
|
+
value: { type: "bearer", token: process.env.STRIPE_API_KEY! }
|
|
62
|
+
}
|
|
63
|
+
] as const;
|
|
64
|
+
|
|
65
|
+
// Fail fast at submission time when policy and auth disagree.
|
|
66
|
+
validateProxyAuth(proxyEndpoints, proxyEndpointAuth);
|
|
67
|
+
|
|
68
|
+
const run = await client.submitRun({
|
|
69
|
+
templateId: "tmpl_xxx",
|
|
70
|
+
proxyEndpoints,
|
|
71
|
+
secrets: {
|
|
72
|
+
anthropic: { apiKey: process.env.ANTHROPIC_API_KEY! },
|
|
73
|
+
proxyEndpointAuth
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Inside the run container, every session has the platform CLI mounted at `/antpath/antpath` (a Node ESM bundle) and a manifest at `/antpath/index.json` describing the declared endpoints. The skill calls the proxy via the CLI:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
node /antpath/antpath proxy stripe \
|
|
82
|
+
--method GET \
|
|
83
|
+
--path /v1/charges/ch_123 \
|
|
84
|
+
--response-mode headers_only
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The CLI reads the per-run bearer from `/antpath/run-token`, attaches the `X-Antpath-Proxy-Protocol` header, and the BFF injects the bearer/header/query/basic credential before dispatching the outbound call. Only the response (subject to `responseMode` and `maxResponseBytes`) reaches the container. `--response-mode` can only narrow below the policy ceiling.
|
|
88
|
+
|
|
89
|
+
`node /antpath/antpath --help` reads endpoint details from `/antpath/index.json`. Runs that do not declare any `proxyEndpoints` still have the CLI and an empty manifest mounted, so agents never need to introspect whether the surface exists.
|
|
90
|
+
|
|
91
|
+
### Networking
|
|
92
|
+
|
|
93
|
+
When a Template uses `limited` networking, the platform host must appear in `allowed_hosts`. The worker injects it automatically; for advance validation in user-built Templates use:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
const allowedHosts = buildPlatformAllowedHosts({
|
|
97
|
+
dashboardBaseUrl: "https://dashboard.antpath.dev",
|
|
98
|
+
extraHosts: ["api.stripe.com"]
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Deprecation: `defaultSecrets`
|
|
103
|
+
|
|
104
|
+
`AntpathPlatformClientOptions.defaultSecrets` is deprecated. Pass `secrets` explicitly on every `submitRun` call so the active credentials are visible at the call site (agent-first design). The client emits a one-time deprecation warning when constructed with `defaultSecrets`.
|
|
105
|
+
|
package/docs/events.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Events
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Events
|
|
6
|
+
|
|
7
|
+
Claude Managed Agents sessions run autonomously on Anthropic's infrastructure.
|
|
8
|
+
They are **non-blocking**: the SDK opens a long-lived SSE stream while the
|
|
9
|
+
agent thinks, calls tools, and emits messages on its own schedule. The SDK
|
|
10
|
+
cannot intercept a tool call to return a value — `permission_policy` is
|
|
11
|
+
`always_allow`. This guide covers the observe-only event surface.
|
|
12
|
+
|
|
13
|
+
## Two ways to consume events
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// Push: register a callback in RunOptions.
|
|
17
|
+
const handle = await client.run(template, {
|
|
18
|
+
onEvent: async (event) => {
|
|
19
|
+
if (event.type === "provider.event") {
|
|
20
|
+
// event.event is a ProviderEvent (typed via a type guard below).
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
await handle.wait();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// Pull: iterate the stream concurrently with handle.wait().
|
|
29
|
+
const handle = await client.run(template);
|
|
30
|
+
const collect = (async () => {
|
|
31
|
+
for await (const event of handle.streamEvents()) {
|
|
32
|
+
// ...
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
const result = await handle.wait();
|
|
36
|
+
await collect;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Both surfaces observe the same events. They can be used together; every
|
|
40
|
+
subscriber sees every event. A subscriber attached after `client.run()`
|
|
41
|
+
returns replays the events it missed (including the initial
|
|
42
|
+
`sdk.status` emitted while provider resources were being created), then
|
|
43
|
+
continues live.
|
|
44
|
+
|
|
45
|
+
## Event shape
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
type RunEvent =
|
|
49
|
+
| { type: "sdk.status"; status: RunStatus; at: string }
|
|
50
|
+
| { type: "sdk.message_sent"; index: number; at: string }
|
|
51
|
+
| { type: "sdk.cleanup"; ... } // see "Cleanup events" below
|
|
52
|
+
| { type: "provider.event"; event: ProviderEvent; at: string };
|
|
53
|
+
|
|
54
|
+
interface ProviderEvent {
|
|
55
|
+
type: string; // documented Claude event type, e.g. "agent.tool_use"
|
|
56
|
+
payload: unknown; // raw provider payload, redacted
|
|
57
|
+
receivedAt: string;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
All events pass through the SDK's secret redaction before reaching any
|
|
62
|
+
subscriber, so payloads do not contain the Anthropic key or MCP credentials
|
|
63
|
+
that were supplied to `client.run()`.
|
|
64
|
+
|
|
65
|
+
## Drain-before-`wait()` guarantee
|
|
66
|
+
|
|
67
|
+
By the time `await handle.wait()` resolves, every `onEvent` invocation
|
|
68
|
+
triggered by events emitted before the terminal `sdk.status` has itself
|
|
69
|
+
resolved or rejected. Async handlers are invoked serially in event order on
|
|
70
|
+
a single per-listener promise chain, so callers can persist events in order
|
|
71
|
+
without their own queue.
|
|
72
|
+
|
|
73
|
+
The same drain applies to handlers that throw — both modes (warn-only and
|
|
74
|
+
abort-on-error, see below) wait for the offending invocation to settle
|
|
75
|
+
before resolving.
|
|
76
|
+
|
|
77
|
+
## Error semantics
|
|
78
|
+
|
|
79
|
+
Default: a handler that throws (or returns a rejecting promise) is logged
|
|
80
|
+
via the SDK's configured `logger` at `warn`. The run continues, and the
|
|
81
|
+
final result is unaffected.
|
|
82
|
+
|
|
83
|
+
Opt-in: `onEventAbortOnError: true` upgrades the **first** pre-terminal
|
|
84
|
+
handler error into a `RunStateError` that fails the run. Once terminal
|
|
85
|
+
status has been reached, listener errors are always logged only — they
|
|
86
|
+
never mutate the result, and they cannot trigger recursion when the
|
|
87
|
+
terminal `sdk.status: failed` event itself causes another error.
|
|
88
|
+
|
|
89
|
+
`RunStateError.message` and its `cause` field pass through the same
|
|
90
|
+
redaction layer used for events.
|
|
91
|
+
|
|
92
|
+
## Cleanup events
|
|
93
|
+
|
|
94
|
+
`sdk.cleanup` events are part of the `RunEvent` union, but they are
|
|
95
|
+
emitted by `handle.cleanup()` after `handle.wait()` has already resolved.
|
|
96
|
+
By that time the event bus has been closed; subscribers attached during
|
|
97
|
+
the run do **not** see them. Inspect cleanup outcomes via the
|
|
98
|
+
`CleanupResult.operations` array returned by `cleanup()` instead.
|
|
99
|
+
|
|
100
|
+
## Typed helpers
|
|
101
|
+
|
|
102
|
+
`packages/sdk/src/providers/known-events.ts` exports conservative type
|
|
103
|
+
guards that narrow `ProviderEvent.type` to documented Claude event strings.
|
|
104
|
+
They do **not** assert payload field shapes — the raw provider payload
|
|
105
|
+
stays `unknown` until callers parse it themselves.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import {
|
|
109
|
+
isAgentMessage,
|
|
110
|
+
isAgentToolUse,
|
|
111
|
+
isAgentToolResult,
|
|
112
|
+
isAgentMcpToolUse,
|
|
113
|
+
isAgentMcpToolResult,
|
|
114
|
+
isAgentCustomToolUse,
|
|
115
|
+
isAgentThinking,
|
|
116
|
+
isUserMessage,
|
|
117
|
+
isSessionStatusRunning,
|
|
118
|
+
isSessionStatusIdle,
|
|
119
|
+
isSessionStatusTerminated,
|
|
120
|
+
isSessionError,
|
|
121
|
+
isAgentEvent,
|
|
122
|
+
isUserEvent,
|
|
123
|
+
isSessionEvent,
|
|
124
|
+
isSpanEvent
|
|
125
|
+
} from "antpath";
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The official list of event types is maintained at
|
|
129
|
+
[`platform.claude.com/docs/en/managed-agents/events-and-streaming`](https://platform.claude.com/docs/en/managed-agents/events-and-streaming).
|
package/docs/skills.md
CHANGED
|
@@ -14,3 +14,5 @@ MVP skill inputs:
|
|
|
14
14
|
Local directories are packaged as zip files and mounted under `/antpath/skills/` unless overridden.
|
|
15
15
|
|
|
16
16
|
Inline skills are uploaded as markdown files and mounted under `/antpath/skills/` unless overridden.
|
|
17
|
+
|
|
18
|
+
The platform also mounts the `antpath` CLI at `/antpath/antpath` and a per-run manifest at `/antpath/index.json` on **every** run. Skills can invoke the managed HTTP proxy via `node /antpath/antpath proxy …` — see `credentials.md` for the policy/auth model.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "antpath",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "TypeScript SDK for running autonomous Claude Managed Agents sessions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"import": "./dist/index.js"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"antpath": "./dist/cli.mjs"
|
|
20
|
+
},
|
|
18
21
|
"files": [
|
|
19
22
|
"dist",
|
|
20
23
|
"README.md",
|
|
@@ -30,7 +33,7 @@
|
|
|
30
33
|
"node": ">=20"
|
|
31
34
|
},
|
|
32
35
|
"scripts": {
|
|
33
|
-
"build": "tsc -p tsconfig.build.json",
|
|
36
|
+
"build": "pnpm --filter @antpath/cli run build && tsc -p tsconfig.build.json && node ./scripts/bundle-cli.mjs",
|
|
34
37
|
"lint": "tsc --noEmit",
|
|
35
38
|
"test": "vitest run test/unit",
|
|
36
39
|
"test:unit": "vitest run test/unit",
|