@cmdoss/agent-pass-plugin 0.0.0-stage → 0.1.0-dev.5.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 +131 -2
- package/dist/agentpass.js +199 -0
- package/dist/cli.js +37 -0
- package/dist/domain.js +103 -0
- package/dist/engine.js +260 -0
- package/dist/http.js +170 -0
- package/dist/mcp.js +259 -0
- package/dist/onboarding.js +258 -0
- package/dist/public/catalog.js +35 -0
- package/dist/public/http.js +89 -0
- package/dist/public-server.js +11 -0
- package/dist/runtime/config.js +16 -0
- package/dist/runtime/installation.js +107 -0
- package/dist/runtime/lock.js +38 -0
- package/dist/runtime/paths.js +56 -0
- package/dist/runtime/setup.js +155 -0
- package/dist/sdk-ui.js +48 -0
- package/dist/server.js +107 -0
- package/dist/shared/constants.js +9 -0
- package/dist/store.js +84 -0
- package/dist/testnet/adapter.js +275 -0
- package/dist/testnet/authorization.js +620 -0
- package/dist/testnet/chain/codec.js +68 -0
- package/dist/testnet/chain/inspection.js +54 -0
- package/dist/testnet/chain/policy.js +78 -0
- package/dist/testnet/chain/prepared.js +150 -0
- package/dist/testnet/chain/receipt.js +49 -0
- package/dist/testnet/chain/sdk.js +34 -0
- package/dist/testnet/chain/types.js +1 -0
- package/dist/testnet/engine.js +395 -0
- package/dist/testnet/http.js +139 -0
- package/dist/testnet/model.js +49 -0
- package/dist/testnet/policy.js +44 -0
- package/dist/testnet/read-model.js +217 -0
- package/dist/testnet/repository.js +62 -0
- package/dist/testnet/runner.js +306 -0
- package/dist/testnet/types.js +1 -0
- package/dist/workflows.js +379 -0
- package/docs/agent-pass-integration.md +75 -0
- package/docs/architecture.md +93 -0
- package/docs/npm-release.md +83 -0
- package/npm-shrinkwrap.json +5376 -0
- package/package.json +72 -4
- package/public/assets/agent-pass-plugin-client.js +16 -0
- package/public/assets/agent-pass-plugin-sdk.js +1 -0
- package/public/assets/sui-payment-rails.avif +0 -0
- package/public/assets/sui-payments-hero.json +1 -0
- package/public/fonts/TWKEverett-Medium.woff2 +0 -0
- package/public/fonts/TWKEverett-Regular.woff2 +0 -0
- package/public/fonts/TWKEverettMono-Medium.woff2 +0 -0
- package/public/fonts/TWKEverettMono-Regular.woff2 +0 -0
- package/public/index.html +81 -0
- package/public/styles/base.css +117 -0
- package/public/styles/catalog.css +279 -0
- package/public/styles/controls.css +118 -0
- package/public/styles/dialog.css +257 -0
- package/public/styles/home.css +82 -0
- package/public/styles/layout.css +45 -0
- package/public/styles/plans.css +271 -0
- package/public/styles/responsive.css +643 -0
- package/public/styles/review.css +150 -0
- package/public/styles/sdk-wallet.css +125 -0
- package/public/styles/sdk.css +441 -0
- package/public/styles/shell.css +348 -0
- package/public/styles/tokens.css +75 -0
- package/public/styles.css +11 -0
- package/scripts/setup.mjs +10 -0
- package/skills/agent-pass-plugin-trading/SKILL.md +60 -0
package/README.md
CHANGED
|
@@ -1,3 +1,132 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Agent Pass Plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Local Sui trading strategies for Claude Code and Codex. One local service owns
|
|
4
|
+
execution; the browser and MCP are interfaces to it.
|
|
5
|
+
|
|
6
|
+
**Default: Sui Testnet.** Uses the official Agent Pass SDK and its demo-asset,
|
|
7
|
+
protocol stand-in pools. Mainnet is disabled. Paper is a separate simulator.
|
|
8
|
+
|
|
9
|
+
## npm package
|
|
10
|
+
|
|
11
|
+
The compiled CLI is distributed as `@cmdoss/agent-pass-plugin`. After an
|
|
12
|
+
approved registry release, install it with npm or invoke the selected version
|
|
13
|
+
through npx:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npx @cmdoss/agent-pass-plugin@<version> setup --client codex --register --start
|
|
17
|
+
# Use --client claude for Claude Code.
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Setup pins a durable runtime outside the npm cache before writing MCP registration.
|
|
21
|
+
State and SDK keys default to `~/.agent-pass-plugin/data`; executable versions and
|
|
22
|
+
assets live in `~/.agent-pass-plugin/runtimes`. Override these independently with
|
|
23
|
+
`AGENT_PASS_PLUGIN_DATA_DIR` and `AGENT_PASS_PLUGIN_INSTALL_DIR`. An already-running
|
|
24
|
+
different build requires an explicit stop/restart; setup never replaces it silently.
|
|
25
|
+
No wallet authorization or trading Start occurs during installation.
|
|
26
|
+
|
|
27
|
+
`agent-pass-plugin --help`, `--version`, `start` and `mcp` use compiled JavaScript;
|
|
28
|
+
consumers do not need TypeScript or tsx. Source-checkout instructions follow below.
|
|
29
|
+
The package includes an npm shrinkwrap so consumer and managed installations use
|
|
30
|
+
the reviewed production dependency tree. See [npm CI and release](docs/npm-release.md)
|
|
31
|
+
for validation, release channels and first-publication setup.
|
|
32
|
+
|
|
33
|
+
## Quick start
|
|
34
|
+
|
|
35
|
+
Requires Node **22.13+**, npm and a Sui wallet extension.
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm ci
|
|
39
|
+
npm run dev
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Open [localhost:4317](http://127.0.0.1:4317).
|
|
43
|
+
Connect wallet → choose a strategy → set amounts, price and limits → review and
|
|
44
|
+
sign in Agent Pass → **Start** explicitly. Connecting or authorizing never starts a plan.
|
|
45
|
+
|
|
46
|
+
For MCP, run one of:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
npm run build
|
|
50
|
+
node scripts/setup.mjs --client codex --register --start
|
|
51
|
+
node scripts/setup.mjs --client claude --register --start
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Setup updates only the selected client entry and starts/reuses the matching local
|
|
55
|
+
service. Reopen the client if needed. Call `marketplace_status`, then `onboard` and
|
|
56
|
+
poll `onboarding_status`; onboarding opens the wallet connection page automatically.
|
|
57
|
+
See the [trading skill](skills/agent-pass-plugin-trading/SKILL.md) for tool sequencing.
|
|
58
|
+
|
|
59
|
+
## Operation
|
|
60
|
+
|
|
61
|
+
- Keep the machine and local service running. Closing chat/browser or logging out
|
|
62
|
+
does not stop an active plan. Restarted plans pause and require explicit Resume.
|
|
63
|
+
- Pause/Stop prevent new trades. Revoke requires owner review and chain confirmation.
|
|
64
|
+
Holdings are not automatically sold; submitted transactions still reconcile.
|
|
65
|
+
- Delegated keys stay in the official local SDK's `agent-pass/` data directory.
|
|
66
|
+
Never commit runtime data or signer sessions. No owner seed is requested.
|
|
67
|
+
- Buying PnL uses verified fills and the last confirmed venue mark. A mark older
|
|
68
|
+
than 60 seconds stays visible with its time and is not a live quote. Missing
|
|
69
|
+
cost basis, including SUI sales, stays unavailable. Gas is recorded separately.
|
|
70
|
+
Funding is not profit.
|
|
71
|
+
- One active plan per runtime. No hosted custody, futures or copy-trading engine.
|
|
72
|
+
|
|
73
|
+
Paper experiment, isolated from Testnet:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
AGENT_PASS_PLUGIN_MODE=paper AGENT_PASS_PLUGIN_DATA_DIR=.data/paper-demo PORT=4318 npm run dev
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Configuration: [.env.example](.env.example). Scripts read shell variables; they do
|
|
80
|
+
not automatically load `.env`. Never run two processes against one data directory.
|
|
81
|
+
A stale lock requires inspecting its process before removing only `runner.lock`.
|
|
82
|
+
|
|
83
|
+
## Develop and verify
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
npm run check
|
|
87
|
+
npm run smoke
|
|
88
|
+
npm run smoke:package
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`check` runs formatting, typecheck, tests, build and repository hygiene.
|
|
92
|
+
Smoke uses temporary Paper data and actual HTTP/MCP processes; it does not trade,
|
|
93
|
+
register clients or touch normal plans. `npm run doctor -- --probe` optionally
|
|
94
|
+
reads a Testnet quote without trading. Build before `npm start` or after client changes.
|
|
95
|
+
|
|
96
|
+
## Deploy the website
|
|
97
|
+
|
|
98
|
+
The hosted website serves the same Home/catalog UI. Setup prompts and local-app
|
|
99
|
+
links hand off to the user's installation. Wallet sessions, plans, SDK signing and
|
|
100
|
+
execution stay local; the public server has no trading or session-token endpoints.
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
npm run build
|
|
104
|
+
npm run start:web # public catalog, port 3000
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
For Coolify, use the repository's Dockerfile and port 3000, with
|
|
108
|
+
`/api/health` as the health check. No persistent storage or keys are needed.
|
|
109
|
+
See [deployment instructions](docs/deployment.md). `npm start` remains the local
|
|
110
|
+
trading runtime and must not be used as the hosted container command.
|
|
111
|
+
|
|
112
|
+
## Code map
|
|
113
|
+
|
|
114
|
+
| Path | Responsibility |
|
|
115
|
+
| ----------------------------------- | ------------------------------------------------------------------- |
|
|
116
|
+
| `src/client/` | Browser pages, controllers, components, wallet and SDK presentation |
|
|
117
|
+
| `src/runtime/`, `src/shared/` | Configuration, process lock and shared defaults |
|
|
118
|
+
| `src/testnet/` | Plan lifecycle, storage, read models and durable runner |
|
|
119
|
+
| `src/testnet/chain/` | SDK loading, policy checks, prepared transactions and receipts |
|
|
120
|
+
| `src/engine.ts`, `src/workflows.ts` | Isolated Paper execution and review workflows |
|
|
121
|
+
| `src/http.ts`, `src/mcp.ts` | Loopback HTTP and stdio MCP transports |
|
|
122
|
+
| `public/styles/` | Ordered Sui styles; generated JS lives in ignored `public/assets/` |
|
|
123
|
+
| `tests/` | Client, Paper, Testnet, runtime and transport regression suites |
|
|
124
|
+
|
|
125
|
+
## References
|
|
126
|
+
|
|
127
|
+
- [Architecture and invariants](docs/architecture.md)
|
|
128
|
+
- [Testnet owner runbook](docs/agent-pass-integration.md)
|
|
129
|
+
- [Testing and evidence](docs/verification.md)
|
|
130
|
+
- [Epic 1 scope](docs/epic-1.md) · [Design system](docs/design-system.md)
|
|
131
|
+
- [This morning’s test history](docs/testnet-acceptance-2026-11-11.md): live Testnet
|
|
132
|
+
evidence and post-cleanup checks. Both final plans are revoked.
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { readFile, stat } from "node:fs/promises";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
4
|
+
/** Read-only bridge to the official SDK. Paper execution never calls this signer. */
|
|
5
|
+
export const AGENT_PASS_SDK_VERSION = "0.1.35";
|
|
6
|
+
const PACKAGE_NAME = "@mysten-incubation/sui-agent-pass";
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
async function readJson(path) {
|
|
9
|
+
return JSON.parse(await readFile(path, "utf8"));
|
|
10
|
+
}
|
|
11
|
+
function packageRoot() {
|
|
12
|
+
return dirname(dirname(require.resolve(`${PACKAGE_NAME}/agent`)));
|
|
13
|
+
}
|
|
14
|
+
async function bundledTestnet() {
|
|
15
|
+
const deployment = await readJson(join(packageRoot(), "deployments", "testnet.json"));
|
|
16
|
+
if (deployment.network !== "testnet" ||
|
|
17
|
+
!Array.isArray(deployment.pools) ||
|
|
18
|
+
!Array.isArray(deployment.coins)) {
|
|
19
|
+
throw new Error("The installed SDK has an invalid bundled testnet deployment.");
|
|
20
|
+
}
|
|
21
|
+
return deployment;
|
|
22
|
+
}
|
|
23
|
+
async function withDeadline(operation, ms = 12_000) {
|
|
24
|
+
let timeout;
|
|
25
|
+
try {
|
|
26
|
+
return await Promise.race([
|
|
27
|
+
operation,
|
|
28
|
+
new Promise((_resolve, reject) => {
|
|
29
|
+
timeout = setTimeout(() => reject(new Error("Read-only SDK check timed out; readiness is unverified.")), ms);
|
|
30
|
+
timeout.unref();
|
|
31
|
+
}),
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
if (timeout)
|
|
36
|
+
clearTimeout(timeout);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Connect only to an already-running official signer. Does not read a private key,
|
|
41
|
+
* create a session, start a signer, sign, submit, refill gas, or change authorization.
|
|
42
|
+
* mcp.token is read internally as a local transport credential and is never returned.
|
|
43
|
+
*/
|
|
44
|
+
export async function inspectAgentPassSession(directory) {
|
|
45
|
+
if (!isAbsolute(directory))
|
|
46
|
+
throw new Error("AGENT_PASS_SESSION_DIR must be an absolute path.");
|
|
47
|
+
if (!(await stat(directory)).isDirectory())
|
|
48
|
+
throw new Error("Agent Pass session directory is not a directory.");
|
|
49
|
+
const runtime = await readJson(join(directory, "runtime.json"));
|
|
50
|
+
if (!runtime.mcpUrl)
|
|
51
|
+
throw new Error("No running official signer was found. Start agent-pass serve explicitly.");
|
|
52
|
+
const endpoint = new URL(runtime.mcpUrl);
|
|
53
|
+
if (endpoint.protocol !== "http:" ||
|
|
54
|
+
!["127.0.0.1", "localhost", "[::1]"].includes(endpoint.hostname)) {
|
|
55
|
+
throw new Error("The session signer must be an HTTP loopback endpoint.");
|
|
56
|
+
}
|
|
57
|
+
const bearer = (await readFile(join(directory, "mcp.token"), "utf8")).trim();
|
|
58
|
+
if (!bearer)
|
|
59
|
+
throw new Error("The official signer transport credential is missing.");
|
|
60
|
+
const sdkModule = `${PACKAGE_NAME}/agent`;
|
|
61
|
+
const { Agent } = (await import(sdkModule));
|
|
62
|
+
const agent = await withDeadline(Agent.connect(endpoint.toString(), bearer));
|
|
63
|
+
try {
|
|
64
|
+
const identity = agent.identity;
|
|
65
|
+
if (!identity.active?.passId)
|
|
66
|
+
throw new Error("The session has not completed owner authorization.");
|
|
67
|
+
return {
|
|
68
|
+
network: identity.deployment.network,
|
|
69
|
+
sessionAddress: identity.sessionAddress,
|
|
70
|
+
passId: identity.active.passId,
|
|
71
|
+
owner: identity.active.owner,
|
|
72
|
+
revoked: identity.revoked === true,
|
|
73
|
+
signerRunning: true,
|
|
74
|
+
note: "Read-only session inspection. No key was exported and no transaction was signed or submitted.",
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
await agent.close();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Fetches pool objects and simulates a quote using the official testnet deployment. */
|
|
82
|
+
export async function probeTestnetRoute() {
|
|
83
|
+
const base = {
|
|
84
|
+
network: "testnet",
|
|
85
|
+
checkedAt: new Date().toISOString(),
|
|
86
|
+
note: "Read-only quote from testnet stand-in markets; not a production Cetus/DeepBook fill or permission proof.",
|
|
87
|
+
};
|
|
88
|
+
try {
|
|
89
|
+
const deployment = await bundledTestnet();
|
|
90
|
+
const sui = deployment.coins.find((coin) => coin.symbol === "SUI");
|
|
91
|
+
const usdc = deployment.coins.find((coin) => coin.symbol === "USDC");
|
|
92
|
+
if (!sui || !usdc)
|
|
93
|
+
throw new Error("Bundled deployment does not list the SUI/USDC pair.");
|
|
94
|
+
const pool = deployment.pools.find((candidate) => candidate.venue === "cetus");
|
|
95
|
+
if (!pool)
|
|
96
|
+
throw new Error("Bundled deployment does not list the expected testnet Cetus stand-in.");
|
|
97
|
+
const chainModule = `${PACKAGE_NAME}/chain`;
|
|
98
|
+
const sdkModule = `${PACKAGE_NAME}/agent`;
|
|
99
|
+
const { clientFor } = (await import(chainModule));
|
|
100
|
+
const { quote } = (await import(sdkModule));
|
|
101
|
+
const client = clientFor(deployment);
|
|
102
|
+
await withDeadline(Promise.all([
|
|
103
|
+
client.getObject({ objectId: deployment.packageId }),
|
|
104
|
+
client.getObject({ objectId: pool.poolId }),
|
|
105
|
+
]));
|
|
106
|
+
const result = await withDeadline(quote({ deployment }, { coinIn: sui.type, coinOut: usdc.type, poolId: pool.poolId }, "1000000"));
|
|
107
|
+
if (BigInt(result.amountOut) <= 0n)
|
|
108
|
+
throw new Error("The testnet stand-in returned no output for the probe quote.");
|
|
109
|
+
return {
|
|
110
|
+
...base,
|
|
111
|
+
ok: true,
|
|
112
|
+
venue: pool.venue,
|
|
113
|
+
poolId: pool.poolId,
|
|
114
|
+
coinIn: sui.type,
|
|
115
|
+
coinOut: usdc.type,
|
|
116
|
+
...result,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return {
|
|
121
|
+
...base,
|
|
122
|
+
ok: false,
|
|
123
|
+
error: error instanceof Error ? error.message : "Unknown SDK read error.",
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Default status is local and read-only. Network reads require probeNetwork=true. */
|
|
128
|
+
export async function getIntegrationStatus(options = {}) {
|
|
129
|
+
const sessionDirectory = options.sessionDirectory ?? process.env.AGENT_PASS_SESSION_DIR;
|
|
130
|
+
const status = {
|
|
131
|
+
sdk: {
|
|
132
|
+
expectedVersion: AGENT_PASS_SDK_VERSION,
|
|
133
|
+
installedVersion: null,
|
|
134
|
+
available: false,
|
|
135
|
+
},
|
|
136
|
+
node: {
|
|
137
|
+
version: process.versions.node,
|
|
138
|
+
supported: Number(process.versions.node.split(".")[0]) >= 22,
|
|
139
|
+
},
|
|
140
|
+
keyCustody: "official-local-signer",
|
|
141
|
+
liveTradingEnabled: false,
|
|
142
|
+
readiness: "sdk_missing",
|
|
143
|
+
sessionConfigured: Boolean(sessionDirectory),
|
|
144
|
+
testnet: { bundledPools: 0, venues: [] },
|
|
145
|
+
nextSteps: [],
|
|
146
|
+
warnings: [
|
|
147
|
+
"This diagnostic is read-only. An installed SDK or successful quote does not prove an authorized transaction; runtime authorization and confirmed receipts are separate checks.",
|
|
148
|
+
"Bundled testnet markets are mock protocol stand-ins. Testnet USD amounts and PnL have no monetary value.",
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
try {
|
|
152
|
+
const metadata = await readJson(join(packageRoot(), "package.json"));
|
|
153
|
+
status.sdk = {
|
|
154
|
+
...status.sdk,
|
|
155
|
+
installedVersion: metadata.version,
|
|
156
|
+
available: true,
|
|
157
|
+
};
|
|
158
|
+
const deployment = await bundledTestnet();
|
|
159
|
+
status.testnet.bundledPools = deployment.pools.length;
|
|
160
|
+
status.testnet.venues = [
|
|
161
|
+
...new Set(deployment.pools.map((pool) => pool.venue)),
|
|
162
|
+
];
|
|
163
|
+
status.readiness =
|
|
164
|
+
metadata.version === AGENT_PASS_SDK_VERSION
|
|
165
|
+
? "session_not_configured"
|
|
166
|
+
: "sdk_version_mismatch";
|
|
167
|
+
if (metadata.version !== AGENT_PASS_SDK_VERSION)
|
|
168
|
+
status.warnings.push("The installed SDK differs from the version inspected for this bridge. Revalidate before live integration.");
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
status.nextSteps.push("Run npm ci to install the pinned official SDK.");
|
|
172
|
+
return status;
|
|
173
|
+
}
|
|
174
|
+
if (!status.node.supported)
|
|
175
|
+
status.warnings.push("Agent Pass requires Node 22 or later.");
|
|
176
|
+
if (sessionDirectory) {
|
|
177
|
+
try {
|
|
178
|
+
status.session = await inspectAgentPassSession(sessionDirectory);
|
|
179
|
+
if (status.readiness !== "sdk_version_mismatch")
|
|
180
|
+
status.readiness = "read_only_connected";
|
|
181
|
+
if (status.session.network === "mainnet")
|
|
182
|
+
status.warnings.push("A mainnet session was inspected read-only. This application never executes mainnet trades.");
|
|
183
|
+
if (status.session.revoked)
|
|
184
|
+
status.warnings.push("The inspected pass is revoked; it is not usable for execution.");
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
status.readiness = "signer_unavailable";
|
|
188
|
+
// Avoid leaking paths, transport credentials, or SDK internals through the public API.
|
|
189
|
+
status.warnings.push("Configured official signer could not be inspected. Check the session and start its official signer explicitly.");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
status.nextSteps.push("In the Testnet workspace, configure an exact owner-bound plan, request its official Agent Pass review, and sign personally in your wallet. Agent Pass Plugin manages its isolated local session; Start remains separate.");
|
|
194
|
+
}
|
|
195
|
+
if (options.probeNetwork)
|
|
196
|
+
status.testnet.probe = await probeTestnetRoute();
|
|
197
|
+
status.nextSteps.push("Verify repeated confirmed Testnet receipts, digest reconciliation, restart and owner-signed revocation before recording Epic 1 onchain acceptance. Mainnet remains disabled.");
|
|
198
|
+
return status;
|
|
199
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { ensureRuntime } from "./runtime/installation.js";
|
|
3
|
+
import { packageMetadata } from "./runtime/paths.js";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
const [command, ...args] = process.argv.slice(2);
|
|
7
|
+
try {
|
|
8
|
+
if (command === "--version" || command === "-v")
|
|
9
|
+
console.log(packageMetadata().version);
|
|
10
|
+
else if (!command ||
|
|
11
|
+
command === "--help" ||
|
|
12
|
+
command === "-h" ||
|
|
13
|
+
args.includes("--help"))
|
|
14
|
+
console.log("Usage: agent-pass-plugin setup --client codex|claude [--register] [--start]\n agent-pass-plugin start | mcp\n\nSetup prepares a durable local installation. Registration and startup require explicit flags. Wallet authorization and Start remain separate user actions.");
|
|
15
|
+
else if (command === "setup") {
|
|
16
|
+
const { setup } = await import("./runtime/setup.js");
|
|
17
|
+
await setup(args);
|
|
18
|
+
}
|
|
19
|
+
else if (command === "mcp") {
|
|
20
|
+
if (args.length)
|
|
21
|
+
throw new Error("mcp accepts no arguments.");
|
|
22
|
+
await import("./mcp.js");
|
|
23
|
+
}
|
|
24
|
+
else if (command === "start") {
|
|
25
|
+
if (args.length)
|
|
26
|
+
throw new Error("start accepts no arguments; configure PORT, mode and data directory through the environment.");
|
|
27
|
+
const root = await ensureRuntime();
|
|
28
|
+
// Managed runtimes must resolve assets/dependencies outside npx's temporary cache.
|
|
29
|
+
await import(pathToFileURL(join(root, "dist/server.js")).href);
|
|
30
|
+
}
|
|
31
|
+
else
|
|
32
|
+
throw new Error(`Unknown command: ${command}. Run agent-pass-plugin --help.`);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error(error instanceof Error ? error.message : "Command failed");
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
}
|
package/dist/domain.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const MICRO = 1_000_000;
|
|
4
|
+
export const NANO = 1_000_000_000;
|
|
5
|
+
export const inputSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
botId: z.enum(["steady-dca", "price-watch"]),
|
|
8
|
+
amountUsdc: z.number().finite().min(0.01).max(1000),
|
|
9
|
+
budgetUsdc: z.number().finite().min(0.01).max(10000),
|
|
10
|
+
intervalSeconds: z.number().int().min(5).max(86400).default(60),
|
|
11
|
+
targetPrice: z.number().finite().min(0.01).max(1000).default(3),
|
|
12
|
+
slippageBps: z.number().int().min(1).max(500).default(50),
|
|
13
|
+
durationHours: z.number().finite().min(0.01).max(168).default(24),
|
|
14
|
+
dailyLimitUsdc: z.number().finite().min(0.01).max(10000).optional(),
|
|
15
|
+
})
|
|
16
|
+
.strict()
|
|
17
|
+
.refine((v) => v.amountUsdc <= v.budgetUsdc, "Order amount exceeds total budget")
|
|
18
|
+
.refine((v) => v.dailyLimitUsdc === undefined || v.dailyLimitUsdc >= v.amountUsdc, "Daily limit must cover at least one full order");
|
|
19
|
+
const rules = {
|
|
20
|
+
"steady-dca": "Buy the fixed input amount once when the interval is due. Skip missed intervals. Never catch up.",
|
|
21
|
+
"price-watch": "Buy the fixed input amount if SUI/USDC price is at or below target. At most one confirmed buy per UTC day.",
|
|
22
|
+
};
|
|
23
|
+
export const catalog = Object.entries(rules).map(([id, rule]) => ({
|
|
24
|
+
id,
|
|
25
|
+
name: id === "steady-dca" ? "Steady DCA" : "Price Watch",
|
|
26
|
+
version: "1.0.0",
|
|
27
|
+
description: rule,
|
|
28
|
+
hash: hash(rule),
|
|
29
|
+
}));
|
|
30
|
+
export function hash(value) {
|
|
31
|
+
return createHash("sha256")
|
|
32
|
+
.update(typeof value === "string" ? value : JSON.stringify(value))
|
|
33
|
+
.digest("hex");
|
|
34
|
+
}
|
|
35
|
+
export function fingerprint(p) {
|
|
36
|
+
return hash({
|
|
37
|
+
id: p.id,
|
|
38
|
+
mode: p.mode,
|
|
39
|
+
botId: p.botId,
|
|
40
|
+
botVersion: p.botVersion,
|
|
41
|
+
skillHash: p.skillHash,
|
|
42
|
+
amountUsdc: p.amountUsdc,
|
|
43
|
+
budgetUsdc: p.budgetUsdc,
|
|
44
|
+
intervalSeconds: p.intervalSeconds,
|
|
45
|
+
targetPrice: p.targetPrice,
|
|
46
|
+
slippageBps: p.slippageBps,
|
|
47
|
+
dailyLimitUsdc: p.dailyLimitUsdc,
|
|
48
|
+
expiresAt: p.expiresAt,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export function newPlan(raw, now = Date.now()) {
|
|
52
|
+
const v = inputSchema.parse(raw), bot = catalog.find((b) => b.id === v.botId);
|
|
53
|
+
const p = {
|
|
54
|
+
id: randomUUID(),
|
|
55
|
+
...v,
|
|
56
|
+
dailyLimitUsdc: v.dailyLimitUsdc ?? v.budgetUsdc,
|
|
57
|
+
botVersion: bot.version,
|
|
58
|
+
skillHash: bot.hash,
|
|
59
|
+
mode: "paper",
|
|
60
|
+
createdAt: new Date(now).toISOString(),
|
|
61
|
+
expiresAt: new Date(now + v.durationHours * 3600000).toISOString(),
|
|
62
|
+
reviewHash: "",
|
|
63
|
+
status: "draft",
|
|
64
|
+
spentMicro: 0,
|
|
65
|
+
quantityNano: 0,
|
|
66
|
+
feesMicro: 0,
|
|
67
|
+
lastReason: "Review and approve this paper plan before starting.",
|
|
68
|
+
nextRunAt: now,
|
|
69
|
+
history: [],
|
|
70
|
+
};
|
|
71
|
+
p.reviewHash = fingerprint(p);
|
|
72
|
+
return p;
|
|
73
|
+
}
|
|
74
|
+
export function activity(p, type, reason, now, extra = {}) {
|
|
75
|
+
p.lastReason = reason;
|
|
76
|
+
p.history.push({
|
|
77
|
+
id: randomUUID(),
|
|
78
|
+
at: new Date(now).toISOString(),
|
|
79
|
+
type,
|
|
80
|
+
reason,
|
|
81
|
+
...extra,
|
|
82
|
+
});
|
|
83
|
+
// Retain full audit history in SQLite. The HTTP response limits presentation separately.
|
|
84
|
+
}
|
|
85
|
+
export function micros(value) {
|
|
86
|
+
return Math.round(value * MICRO);
|
|
87
|
+
}
|
|
88
|
+
export function paperOutput(amountMicro, priceMicro) {
|
|
89
|
+
const feeMicro = Math.ceil((amountMicro * 30) / 10000);
|
|
90
|
+
const quantityNano = Number((BigInt(amountMicro - feeMicro) * BigInt(NANO)) / BigInt(priceMicro));
|
|
91
|
+
return { quantityNano, feeMicro };
|
|
92
|
+
}
|
|
93
|
+
export function present(p, price) {
|
|
94
|
+
const markMicro = Number((BigInt(p.quantityNano) * BigInt(micros(price))) / BigInt(NANO));
|
|
95
|
+
return {
|
|
96
|
+
...p,
|
|
97
|
+
history: p.history.slice(-200).reverse(),
|
|
98
|
+
spentUsdc: p.spentMicro / MICRO,
|
|
99
|
+
holdingsSui: p.quantityNano / NANO,
|
|
100
|
+
feesUsdc: p.feesMicro / MICRO,
|
|
101
|
+
pnlUsdc: (markMicro - p.spentMicro) / MICRO,
|
|
102
|
+
};
|
|
103
|
+
}
|