@mysten-incubation/sui-agent-pass 0.1.10 → 0.1.12

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 CHANGED
@@ -38,9 +38,10 @@ serves compatibility tests with small sums until launch.
38
38
 
39
39
  The agent pays its own gas from the session address. Setup seeds an initial gas stipend and issues
40
40
  a separate small SUI allowance for gas; when the session's balance runs low the agent tops it up
41
- from that allowance, within its own lifetime cap and daily window, so gas spend is bounded apart
42
- from the asset rules. Owners cannot bill an agent's transaction gas to the wallet directly yet,
43
- because gas is authorized by a signature and `sui::allowance` cannot authorize it.
41
+ from that allowance, within its own lifetime cap and a limit per 24 hours from its first top-up,
42
+ so gas spend is bounded apart from the asset rules, whose daily limits reset at 00:00 UTC
43
+ (`docs/ARCHITECTURE.md` §7). Owners cannot bill an agent's transaction gas to the wallet
44
+ directly yet, because gas is authorized by a signature and `sui::allowance` cannot authorize it.
44
45
 
45
46
  Transfers and staking are the real thing on every network. DeepBook, Cetus and NAVI are called
46
47
  through their mainnet interfaces; off mainnet the demo publishes local stand-ins with the same
@@ -9,13 +9,11 @@ and the chain identifier for that network. The stdio server loads one of these w
9
9
  the agent names a `network` in `propose_authorization`, so an installed client needs no local
10
10
  publish; a private `deployment.json` under `~/.sui-agent-pass` or a `deployment` path overrides.
11
11
 
12
- `mainnet.json` is the mainnet test copy of the package (`0x4c9010b0…f403`, upgraded to
13
- `0x08d82880…f744`, version 2), published for dogfooding and for testing the publish and upgrade
14
- process with small sums; the real launch will be a fresh publish and a new file here. Add
15
- `siteUrl` to it once the hosted site has its address, so the plugin sends owners there.
16
- `testnet.json` is the current package (Sui Agent Pass), published to testnet on 2026-10-20 with
17
- the version gate and the per-coin deployment shape (`coins`, `pools`, NAVI `reserves`, the demo
18
- faucet). The shipped copy lists no pools and no reserves on purpose: the testnet markets are
12
+ `mainnet.json` is the mainnet test copy of the package (`0x4736026b…0a22`, published
13
+ 2026-10-28 from the code that will launch, caps with its publisher), for dogfooding with small
14
+ sums; the real launch will be a fresh publish and a new file here. Its `siteUrl` sends owners to
15
+ the hosted site. `testnet.json` is the same code, published to testnet on 2026-10-28
16
+ (`0x52017f8e…17b6`) with its stand-in markets and the demo faucet. The shipped copy lists no pools and no reserves on purpose: the testnet markets are
19
17
  stand-ins with 2 SUI of depth, so dogfooders get transfers and staking there and trade on
20
18
  mainnet. The stand-in pools stay on chain, and the previous revision of this file in git keeps
21
19
  their ids; the tests publish their own stand-ins. Any Move change means a new publish and a new
@@ -2,10 +2,9 @@
2
2
  "network": "mainnet",
3
3
  "grpcUrl": "https://fullnode.mainnet.sui.io:443",
4
4
  "chainIdentifier": "4btiuiMPvEENsttpZC7CZ53DruC3MAgfznDbASZ7DR6S",
5
- "packageId": "0x4c9010b0be6022e8a4bd91219d5174edc36d524b42d4790784035f424e01f403",
6
- "publishedAt": "0x08d82880b61c531ffbe9eb9eccf3c025d6182ec50f7f61e1f6095a6b81a1f744",
7
- "configId": "0xf7b33e20564b26c0685b8d86669345a0121ff6b290911a04f1ff37fcd1f5716d",
8
- "siteUrl": "https://sui-agent-pass.vercel.app",
5
+ "packageId": "0x4736026bde8ef425b243013e6e25431a9b5c9c5ccf62ff87ceb0d4e67c700a22",
6
+ "publishedAt": "0x4736026bde8ef425b243013e6e25431a9b5c9c5ccf62ff87ceb0d4e67c700a22",
7
+ "configId": "0x7d472b14c833c4d8442ac3a176e25d47e946847f293af58934ff2e3fb3109f7c",
9
8
  "coins": [
10
9
  {
11
10
  "type": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
@@ -32,6 +31,7 @@
32
31
  "coinB": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
33
32
  }
34
33
  ],
34
+ "maxTermDays": 365,
35
35
  "protocols": {
36
36
  "deepbook": {
37
37
  "packageId": "0x2c8d603bc51326b8c13cef9dd07031a408a48dddb541963357661df5d3204809",
@@ -63,5 +63,6 @@
63
63
  }
64
64
  }
65
65
  }
66
- }
66
+ },
67
+ "siteUrl": "https://sui-agent-pass.vercel.app"
67
68
  }
@@ -2,9 +2,9 @@
2
2
  "network": "testnet",
3
3
  "grpcUrl": "https://fullnode.testnet.sui.io:443",
4
4
  "chainIdentifier": "69WiPg3DAQiwdxfncX6wYQ2siKwAe6L9BZthQea3JNMD",
5
- "packageId": "0xfea0b9f60c752e98e950c1994a3805ba28c5f559e3ea72da2ac3d68b90728b11",
6
- "publishedAt": "0xfea0b9f60c752e98e950c1994a3805ba28c5f559e3ea72da2ac3d68b90728b11",
7
- "configId": "0x3bb796cd3fe0d9b85b1db972478616e717fe5bdbd1ff864615a3995f4e1c1c60",
5
+ "packageId": "0x52017f8e68e133c6dc84c8733a9f52de0d2a9fb5e2c63b8949b0f7c0c47917b6",
6
+ "publishedAt": "0x52017f8e68e133c6dc84c8733a9f52de0d2a9fb5e2c63b8949b0f7c0c47917b6",
7
+ "configId": "0xe58594af166a1280f9ab04d0e615ceb7209211bc9bee6780a4b00878b023a65b",
8
8
  "coins": [
9
9
  {
10
10
  "type": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
@@ -12,35 +12,36 @@
12
12
  "decimals": 9
13
13
  },
14
14
  {
15
- "type": "0x7ffc375a2bebedcec3753cfe4687f3bb104074eb55b014f8185ccc8ee8bf47fa::usdc::USDC",
15
+ "type": "0xd85020ee4adfa8137605184ad876c96ca293577533a37bff43ac2778b97f2938::usdc::USDC",
16
16
  "symbol": "USDC",
17
17
  "decimals": 6
18
18
  }
19
19
  ],
20
20
  "pools": [],
21
+ "maxTermDays": 365,
21
22
  "demoFaucet": {
22
- "packageId": "0x7ffc375a2bebedcec3753cfe4687f3bb104074eb55b014f8185ccc8ee8bf47fa",
23
- "faucetId": "0x14d07fd3eff80c868c0bab116cbc2f65c8903c77fcb41721ad6db4ba0c6480cf",
24
- "coin": "0x7ffc375a2bebedcec3753cfe4687f3bb104074eb55b014f8185ccc8ee8bf47fa::usdc::USDC"
23
+ "packageId": "0xd85020ee4adfa8137605184ad876c96ca293577533a37bff43ac2778b97f2938",
24
+ "faucetId": "0x853a8e316634215fc297f07a3d23a98b4d40222a7819a07068737689d6c8fc00",
25
+ "coin": "0xd85020ee4adfa8137605184ad876c96ca293577533a37bff43ac2778b97f2938::usdc::USDC"
25
26
  },
26
27
  "protocols": {
27
28
  "deepbook": {
28
- "packageId": "0xfe5ce722543b1e3056aba9f44fd0ac69238c97baae9ac96d0bc1594dfe8ef7b1",
29
- "publishedAt": "0xfe5ce722543b1e3056aba9f44fd0ac69238c97baae9ac96d0bc1594dfe8ef7b1"
29
+ "packageId": "0xf6331717135b1e7edc75ba2cfb3b08a9ec8549884cfc18abc534e4a0bbada9e8",
30
+ "publishedAt": "0xf6331717135b1e7edc75ba2cfb3b08a9ec8549884cfc18abc534e4a0bbada9e8"
30
31
  },
31
32
  "cetus": {
32
- "packageId": "0x23200a7f55d23555844bca491e5422e495d1a9082f4fb39b868d95440655a8d9",
33
- "publishedAt": "0x23200a7f55d23555844bca491e5422e495d1a9082f4fb39b868d95440655a8d9",
34
- "configId": "0x9e4115923d7ba4405a9c918a1d517325a9491b7e2eb3f1e469debae3ceb690cd"
33
+ "packageId": "0xffa6ea563e395f3fd3d86e227a59bdd0ed98ad23c2940822bf9c30c70ce1f167",
34
+ "publishedAt": "0xffa6ea563e395f3fd3d86e227a59bdd0ed98ad23c2940822bf9c30c70ce1f167",
35
+ "configId": "0x2105734227e38828ba69289d4cce4edc1e45666a717c692a9575b6d467ee3bef"
35
36
  },
36
37
  "navi": {
37
- "packageId": "0xd75f91c29ae9b0597f82ff636940199e5004089d17991fafbabb9a180f51b5f7",
38
- "publishedAt": "0xd75f91c29ae9b0597f82ff636940199e5004089d17991fafbabb9a180f51b5f7",
39
- "oraclePackageId": "0x9d2c0e390e32e75b2c6be7a33d12319c912caae11874fcf6e1d79ae8b594e9a6",
40
- "storageId": "0xc8b3b4882625279ce505b94902a33e4cf0364bd1ee2f52563e66f9a42de7af26",
41
- "oracleId": "0xc962d8795540426c4dce1fea621d89f12f00766a6d4b0d00087fde6fefb2d343",
42
- "incentiveV2Id": "0x679e3525405bb43ba27b0839dcaae2469d59225856cd6c2e8318a094efe593c5",
43
- "incentiveV3Id": "0x9488d70edbfd67babcc72b8eb1f3fbf60dd47f080d830e2af27abcecdd6771c6",
38
+ "packageId": "0x5cacd4bed4e0502280b0fe94eb51e02244dea86b584e1f91d9ded493c72eebb5",
39
+ "publishedAt": "0x5cacd4bed4e0502280b0fe94eb51e02244dea86b584e1f91d9ded493c72eebb5",
40
+ "oraclePackageId": "0x4891910b7259bff2f220f017c7e7e4628f5c26efff47eeb75453cf997387a56b",
41
+ "storageId": "0x37d8af65a9ac8ae7c4e99304ae8347ef72dcd30759f509f8c4376e86107087bc",
42
+ "oracleId": "0x3730ff06112853476c9b8c6121206776c6ed912ecc61ce8ffe25b697250f0131",
43
+ "incentiveV2Id": "0xb776dbb5e7a27a766d8fb4087000d58831eec3061a30c95edc5c728ef1508407",
44
+ "incentiveV3Id": "0xbafebe7c1a71f024f304f626215f6706c40cff72c45163e09d62d97cadea4f9e",
44
45
  "reserves": {}
45
46
  }
46
47
  }
package/dist/agent.js CHANGED
@@ -342,7 +342,7 @@ async function naviAmount(i, entry, coin, amount) {
342
342
  await refreshNaviPrices(tx, d);
343
343
  // NAVI's SUI pool stakes idle SUI and may unstake to pay out, hence the system state.
344
344
  tx.moveCall({
345
- target: `${d.publishedAt}::pass::${entry}_v2`,
345
+ target: `${d.publishedAt}::pass::${entry}`,
346
346
  typeArguments: [coin],
347
347
  arguments: [
348
348
  ...pass(tx, i),
package/dist/describe.js CHANGED
@@ -105,7 +105,7 @@ export function describeSetup(d, setup) {
105
105
  .join(', '),
106
106
  },
107
107
  {
108
- label: 'Max gas allowance, lifetime / per UTC day',
108
+ label: 'Max gas allowance, lifetime / per 24 hours from first top-up',
109
109
  value: `${showCoin(d, SUI, setup.gasCap)} / ${showCoin(d, SUI, setup.gasDaily)}`,
110
110
  },
111
111
  {
@@ -123,10 +123,9 @@ const OWNER_ONLY = new Set([
123
123
  'navi_open',
124
124
  'destroy',
125
125
  'issue',
126
- 'rotate_allowance',
127
126
  'add_policy',
128
127
  'remove_policy',
129
- 'set_agent',
128
+ 'set_term',
130
129
  'revoke_agent',
131
130
  ]);
132
131
  /**
@@ -288,7 +287,8 @@ export function describeRefusal(d, error, recipient) {
288
287
  const system = {
289
288
  allowance: {
290
289
  3: "Over the lifetime cap of the owner's allowance for this coin (checked before the daily limit, so when the two are equal the day is used up as well)",
291
- 4: "Over the allowance's daily window",
290
+ // Only the gas allowance has a rate limit; the asset allowances have caps alone.
291
+ 4: "Over the gas allowance's limit per 24 hours from first top-up",
292
292
  },
293
293
  validator_set: { 10: 'Below the 1 SUI minimum stake', 0: 'Not an active validator' },
294
294
  };
package/dist/domain.js CHANGED
@@ -5,6 +5,8 @@ import { z } from 'zod';
5
5
  /** The gas coin, in the normalized spelling every coin-keyed record uses. */
6
6
  export const SUI = normalizeStructTag('0x2::sui::SUI');
7
7
  export const DAY_MS = 86_400_000;
8
+ /** The longest agent term the current contract accepts (`MAX_TERM_MS` in `control.move`). */
9
+ export const MAX_TERM_DAYS = 365;
8
10
  /** NAVI's fixed-point scale for health factors: 1e27 is 1.0. */
9
11
  export const RAY = 10n ** 27n;
10
12
  export const address = z
@@ -151,6 +153,8 @@ export const DeploymentSchema = z
151
153
  coins: z.array(CoinSchema).min(1),
152
154
  /** The pools a swap rule can list, in either direction. */
153
155
  pools: z.array(PoolSchema),
156
+ /** The longest agent term, in days, this deployment's contract accepts. */
157
+ maxTermDays: z.number().int().min(1).max(MAX_TERM_DAYS),
154
158
  /** A demo stablecoin's faucet, which the authorization mints from instead of converting coins. */
155
159
  demoFaucet: z
156
160
  .object({ packageId: address, faucetId: address, coin: coinType })
@@ -244,9 +248,9 @@ const ttlMs = z
244
248
  .number()
245
249
  .int()
246
250
  .positive()
247
- .max(30 * DAY_MS);
251
+ .max(MAX_TERM_DAYS * DAY_MS);
248
252
  const gasAmount = positive;
249
- /** Absolute end of the agent's term, written on chain. The chain requires it within 30 days. */
253
+ /** Absolute end of the agent's term, written on chain, within the deployment's `maxTermDays`. */
250
254
  const expiresMs = z.number().int().positive();
251
255
  const name = z.string().regex(/^[\x20-\x7e]{1,64}$/);
252
256
  /**
@@ -262,12 +266,13 @@ export const SetupSchema = z
262
266
  /** Lifetime caps, by coin type: the hard backstop under the policies. */
263
267
  allowances: z.record(coinType, positive),
264
268
  gasAmount,
265
- /** A separate SUI allowance for gas top-ups: lifetime cap and daily window. */
269
+ /** A separate SUI allowance for gas top-ups: lifetime cap and a 24-hour window that the
270
+ * framework starts at the first top-up, not at UTC midnight. */
266
271
  gasCap: positive,
267
272
  gasDaily: positive,
268
273
  })
269
274
  .strict()
270
- .refine((s) => BigInt(s.gasDaily) <= BigInt(s.gasCap), 'Daily gas limit must not exceed the gas lifetime cap')
275
+ .refine((s) => BigInt(s.gasDaily) <= BigInt(s.gasCap), 'The 24-hour gas limit must not exceed the gas lifetime cap')
271
276
  .refine((s) => {
272
277
  const caps = new Set(Object.keys(s.allowances).map((c) => normalizeStructTag(c)));
273
278
  const spent = spentCoins(s.policy);
@@ -391,8 +396,8 @@ export function limitDisplay(d, coinIn, coinOut, minPrice) {
391
396
  }
392
397
  /** Health factors are entered with two decimals and stored on chain in ray units. */
393
398
  export const healthFactorRay = (hf) => hf === null ? '0' : ((BigInt(units(hf.toFixed(2), 2)) * RAY) / 100n).toString();
394
- /** Gas top-ups per UTC day when the owner names none: a fifth of the lifetime cap, so a runaway
395
- * agent burns the gas budget over days, not hours. */
399
+ /** Gas top-ups per 24-hour window when the owner names none: a fifth of the lifetime cap, so a
400
+ * runaway agent burns the gas budget over days, not hours. */
396
401
  export const defaultGasDaily = (gasCap) => {
397
402
  const fifth = BigInt(gasCap) / 5n;
398
403
  return (fifth > 0n ? fifth : BigInt(gasCap)).toString();
@@ -438,8 +443,11 @@ export function conversion(setup, held, mintable = null) {
438
443
  export function uncovered(setup, held, mintable = null) {
439
444
  const convert = conversion(setup, held, mintable);
440
445
  return Object.fromEntries(Object.entries(drawable(setup)).flatMap(([coin, want]) => {
441
- const covered = BigInt(held[normalizeStructTag(coin)]?.addressBalance ?? '0') + BigInt(convert[coin] ?? '0');
442
- return covered >= BigInt(want) ? [] : [[coin, { drawable: want, covered: covered.toString() }]];
446
+ const covered = BigInt(held[normalizeStructTag(coin)]?.addressBalance ?? '0') +
447
+ BigInt(convert[coin] ?? '0');
448
+ return covered >= BigInt(want)
449
+ ? []
450
+ : [[coin, { drawable: want, covered: covered.toString() }]];
443
451
  }));
444
452
  }
445
453
  /**
package/dist/explorer.js CHANGED
@@ -1,6 +1,11 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { normalizeSuiAddress } from '@mysten/sui/utils';
3
+ /**
4
+ * Reads for the hosted explorer: everything about a pass from the chain alone, with no local
5
+ * session state. Browser-safe: no Node imports.
6
+ */
7
+ import { bcs } from '@mysten/sui/bcs';
8
+ import { deriveObjectID, normalizeSuiAddress } from '@mysten/sui/utils';
4
9
  import { createdEventType, discoverAllowances, parseCreated, readControl, } from './chain.js';
5
10
  import { describeAttempt } from './describe.js';
6
11
  async function createdEvents(client, d, limit, before = null) {
@@ -23,55 +28,23 @@ async function createdEvents(client, d, limit, before = null) {
23
28
  return { summaries, hasNextPage: page.hasNextPage, endCursor: page.endCursor };
24
29
  }
25
30
  /**
26
- * The pass most recently created for an agent key, among the newest `Created` events: how the
27
- * process that proposed a pass learns that the owner signed, with nothing sent back to it.
31
+ * The ID a pass for an agent key has, whether or not the owner has created it: the contract
32
+ * derives it from the config and the key (`pass::pass_of`), so a key has at most one pass.
28
33
  */
29
- export async function findPassByAgent(client, d, agent) {
30
- const wanted = normalizeSuiAddress(agent);
31
- let cursor = null;
32
- for (let pages = 0; pages < 10; pages++) {
33
- const page = await client.listEvents({
34
- filter: { eventType: createdEventType(d) },
35
- order: 'descending',
36
- limit: 50,
37
- ...(cursor ? { before: cursor } : {}),
38
- });
39
- for (const e of page.events) {
40
- const created = parseCreated(e.bcs);
41
- if (created.agent === wanted)
42
- return { ...created, digest: e.transactionDigest };
43
- }
44
- if (!page.hasNextPage || !page.endCursor)
45
- return null;
46
- cursor = page.endCursor;
47
- }
48
- return null;
49
- }
34
+ export const passIdOf = (d, agent) => deriveObjectID(d.configId, `${d.packageId}::pass::AgentKey`, bcs.Address.serialize(normalizeSuiAddress(agent)).toBytes());
50
35
  /**
51
- * Every pass ever created for an agent key, newest first, among the package's `Created`
52
- * events. A key is meant to sign one authorization; more than one here means a proposal was
53
- * signed again.
36
+ * The pass of an agent key once the owner has created it, with its owner and the transaction
37
+ * that last changed it, which before the agent's first action is the authorization itself.
54
38
  */
55
- export async function passesByAgent(client, d, agent) {
56
- const wanted = normalizeSuiAddress(agent), found = [];
57
- let cursor = null;
58
- for (let pages = 0; pages < 10; pages++) {
59
- const page = await client.listEvents({
60
- filter: { eventType: createdEventType(d) },
61
- order: 'descending',
62
- limit: 50,
63
- ...(cursor ? { before: cursor } : {}),
64
- });
65
- for (const e of page.events) {
66
- const created = parseCreated(e.bcs);
67
- if (created.agent === wanted)
68
- found.push({ ...created, digest: e.transactionDigest });
69
- }
70
- if (!page.hasNextPage || !page.endCursor)
71
- break;
72
- cursor = page.endCursor;
73
- }
74
- return found;
39
+ export async function findPassByAgent(client, d, agent) {
40
+ const id = passIdOf(d, agent);
41
+ const found = await client
42
+ .getObject({ objectId: id, include: { previousTransaction: true } })
43
+ .catch(() => null);
44
+ if (!found?.object.previousTransaction)
45
+ return null;
46
+ const { owner } = await readControl(client, d, id);
47
+ return { id, owner, digest: found.object.previousTransaction };
75
48
  }
76
49
  /** The most recently created passes on this package. */
77
50
  export async function listPasses(client, d, limit = 50) {
@@ -127,6 +100,22 @@ export async function agentAttempts(client, d, agent, recipients, limit = 30) {
127
100
  });
128
101
  return page.transactions.map((r) => describeAttempt(d, agent, recipients, (r.Transaction ?? r.FailedTransaction)));
129
102
  }
103
+ /**
104
+ * Recent transactions sent from a session address that are not among the digests this machine
105
+ * signed for it: the key is being used somewhere else. Newest first.
106
+ */
107
+ export async function foreignTransactions(client, sessionAddress, signed, limit = 50) {
108
+ const page = await client.listTransactions({
109
+ filter: { sender: sessionAddress },
110
+ order: 'descending',
111
+ limit,
112
+ include: {},
113
+ });
114
+ return page.transactions
115
+ .map((r) => (r.Transaction ?? r.FailedTransaction))
116
+ .filter((t) => !signed.has(t.digest))
117
+ .map((t) => ({ digest: t.digest, success: t.status.success }));
118
+ }
130
119
  /** Every recent call into the package's `pass` module, from any agent or owner. */
131
120
  export async function packageFeed(client, d, limit = 40) {
132
121
  const page = await client.listTransactions({
package/dist/float.js CHANGED
@@ -69,8 +69,10 @@ async function sweepOnce(client, directory, sessionAddress, owner) {
69
69
  if (float <= budget)
70
70
  return null;
71
71
  const amount = float - budget;
72
+ const bytes = await build(amount, budget).build({ client });
73
+ await SessionStore.recordSigned(directory, await Transaction.from(bytes).getDigest());
72
74
  const result = await client.signAndExecuteTransaction({
73
- transaction: build(amount, budget),
75
+ transaction: bytes,
74
76
  signer: await SessionStore.keyOf(directory),
75
77
  });
76
78
  if (result.$kind !== 'Transaction')
package/dist/mcp.js CHANGED
@@ -7,6 +7,8 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
7
7
  import { z } from 'zod';
8
8
  import { clientFor, deepbookSizes, readAllHoldings, readStatus } from './chain.js';
9
9
  import { coinInfo, DAY_MS } from './domain.js';
10
+ import { foreignTransactions } from './explorer.js';
11
+ import { SessionStore } from './storage.js';
10
12
  export const result = (value) => ({
11
13
  content: [{ type: 'text', text: JSON.stringify(value) }],
12
14
  });
@@ -14,6 +16,9 @@ export const failure = (error, fallback) => ({
14
16
  ...result({ error: error instanceof Error ? error.message : fallback }),
15
17
  isError: true,
16
18
  });
19
+ /** Array elements and object members one tool call's arguments may hold. The largest real input,
20
+ * a full rule set, is a few hundred; the SDK validates without a limit unless one is set. */
21
+ export const MAX_TOOL_INPUT_ELEMENTS = 10_000;
17
22
  /**
18
23
  * What every client shows the model before any tool call, so a plain request ("sell 0.05 SUI")
19
24
  * is enough: no resource to know about, no project file to read.
@@ -131,6 +136,21 @@ export async function venues(client, d) {
131
136
  * Everything an agent needs to act: identity, live rules and usage, connection details and the
132
137
  * SDK. `directory` is the session directory when the server knows it, for `Agent.open`.
133
138
  */
139
+ /**
140
+ * When the chain shows transactions from the session address that this machine never signed, the
141
+ * agent key is in use somewhere else; the agent must tell the owner, who can stop it.
142
+ */
143
+ export async function keyAlert(client, directory, sessionAddress) {
144
+ const foreign = await foreignTransactions(client, sessionAddress, await SessionStore.signedDigests(directory)).catch(() => []);
145
+ if (!foreign.length)
146
+ return {};
147
+ return {
148
+ keyAlert: {
149
+ transactions: foreign,
150
+ note: `The chain shows ${foreign.length} transaction(s) from this agent key that this machine never signed, so a copy of the key is being used elsewhere. Tell the owner now, list the digests, and ask them to use "Stop the agent now" on the pass page (revoke_pass opens it). Do not act with this key until they decide.`,
151
+ },
152
+ };
153
+ }
134
154
  export async function sessionInfo(identity, directory = null) {
135
155
  const { deployment: d, active, sessionAddress } = identity;
136
156
  const client = clientFor(d);
@@ -142,6 +162,7 @@ export async function sessionInfo(identity, directory = null) {
142
162
  readAllHoldings(client, d, active.owner).catch(() => null),
143
163
  ]);
144
164
  return {
165
+ ...(directory ? await keyAlert(client, directory, sessionAddress) : {}),
145
166
  ...identity,
146
167
  ...status,
147
168
  ...(directory ? { directory } : {}),
@@ -194,7 +215,7 @@ export function registerDocs(server) {
194
215
  }
195
216
  /** The single-session server behind the authenticated HTTP transport. */
196
217
  export function createMcp(identity, signer, directory = null) {
197
- const server = new McpServer({ name: 'sui-agent-pass', version: '0.1.0' }, { instructions: INSTRUCTIONS });
218
+ const server = new McpServer({ name: 'sui-agent-pass', version: '0.1.0' }, { instructions: INSTRUCTIONS, maxToolInputElements: MAX_TOOL_INPUT_ELEMENTS });
198
219
  registerDocs(server);
199
220
  server.registerTool('session_info', {
200
221
  description: "Read the pass's installed policies with their live usage, the owner's balances and allowances, the agent term, protocol object IDs, Sui connection details and the SDK install command. Act with a Node script against the SDK, which signs here and submits to Sui itself; or build your own PTB, call sign_transaction and submit the returned bytes and signature yourself.",
package/dist/owner.js CHANGED
@@ -138,7 +138,9 @@ function rateLimitOption(tx, dailyLimit) {
138
138
  }
139
139
  /**
140
140
  * A separate, non-app-bound SUI allowance the agent spends to top up its own gas float. Its own
141
- * lifetime cap and daily window bound gas spend independently of the asset-management allowances.
141
+ * lifetime cap and 24-hour window bound gas spend independently of the asset-management
142
+ * allowances. `periodic_rate_limit` starts its windows at the first successful charge, so the
143
+ * window runs from the agent's first top-up rather than from UTC midnight like the policy meters.
142
144
  */
143
145
  function issueGasAllowance(tx, setup, session) {
144
146
  tx.moveCall({
@@ -252,14 +254,8 @@ export function buildAmendment(d, current, next, owner) {
252
254
  const { active, control } = current, pass = tx.object(active.passId), session = control.agent;
253
255
  if (String(next.expiresMs) !== control.agentExpiresMs)
254
256
  tx.moveCall({
255
- target: `${d.publishedAt}::pass::set_agent`,
256
- arguments: [
257
- pass,
258
- tx.object(d.configId),
259
- tx.pure.address(session),
260
- tx.pure.u64(next.expiresMs),
261
- tx.object(CLOCK),
262
- ],
257
+ target: `${d.publishedAt}::pass::set_term`,
258
+ arguments: [pass, tx.object(d.configId), tx.pure.u64(next.expiresMs), tx.object(CLOCK)],
263
259
  });
264
260
  removePolicies(tx, d, pass, control.policies);
265
261
  installPolicies(tx, d, pass, next.policy, next.policy.lending.length > 0 && !control.naviPosition);
package/dist/plugin.js CHANGED
@@ -22,10 +22,10 @@ import { fromBase64, normalizeSuiAddress } from '@mysten/sui/utils';
22
22
  import { z } from 'zod';
23
23
  import { clientFor, deepbookSizes, findPools, quoteSwap, readAllHoldings, readHoldings, readStatus, withMarketFacts, } from './chain.js';
24
24
  import { describePolicy, describeSetup, renderRows } from './describe.js';
25
- import { address, coinBySymbol, coinInfo, DAY_MS, defaultGasDaily, DeploymentSchema, display, isStable, limitUnits, poolsFor, recipientName, requiredSui, sameCoin, SetupSchema, showCoin, SUI, uncovered, units, VenueSchema, } from './domain.js';
26
- import { passesByAgent } from './explorer.js';
25
+ import { address, coinBySymbol, coinInfo, DAY_MS, defaultGasDaily, DeploymentSchema, display, isStable, limitUnits, MAX_TERM_DAYS, poolsFor, recipientName, requiredSui, sameCoin, SetupSchema, showCoin, SUI, uncovered, units, VenueSchema, } from './domain.js';
26
+ import { passIdOf } from './explorer.js';
27
27
  import { passEnded, returnGasFloat } from './float.js';
28
- import { failure, INSTRUCTIONS, registerDocs, result, serverInfo, sessionInfo, SIGN_ANNOTATIONS, SIGN_DESCRIPTION, } from './mcp.js';
28
+ import { failure, INSTRUCTIONS, keyAlert, MAX_TOOL_INPUT_ELEMENTS, registerDocs, result, serverInfo, sessionInfo, SIGN_ANNOTATIONS, SIGN_DESCRIPTION, } from './mcp.js';
29
29
  import { authenticated, body, ownerPageUrl, startServer } from './server.js';
30
30
  import { SessionSigner } from './signer.js';
31
31
  import { SessionStore, token } from './storage.js';
@@ -125,7 +125,7 @@ class Registry {
125
125
  return session.server;
126
126
  }
127
127
  async signer(session) {
128
- session.signer ??= new SessionSigner(await session.store.key(), session.store.state.deployment.chainIdentifier);
128
+ session.signer ??= new SessionSigner(await session.store.key(), session.store.state.deployment.chainIdentifier, (digest) => SessionStore.recordSigned(session.store.directory, digest));
129
129
  return session.signer;
130
130
  }
131
131
  async close() {
@@ -295,6 +295,8 @@ async function toSetup(client, d0, input) {
295
295
  pools: input.swaps.flatMap((sw) => sw.pools ?? []),
296
296
  });
297
297
  const coin = (s) => (isType(s) ? coinInfo(d, s) : coinBySymbol(d, s)), inUnits = (s, v) => units(v, coin(s).decimals), sui = (v) => units(v, 9);
298
+ if (input.days > d0.maxTermDays)
299
+ throw new Error(`The contract on ${d0.network} accepts an agent term of at most ${d0.maxTermDays} days; propose ${d0.maxTermDays} or fewer`);
298
300
  const ttlMs = input.days * DAY_MS, gasCap = sui(input.gasCapSui);
299
301
  const setup = SetupSchema.parse({
300
302
  name: input.name,
@@ -363,40 +365,23 @@ function summary(s) {
363
365
  directory: s.store.directory,
364
366
  };
365
367
  }
366
- /**
367
- * The summary plus what the chain says about the key: every pass created for it. A key is
368
- * meant to sign one authorization, so a second pass here is a proposal signed twice, live on
369
- * chain with its own allowances, which the session file knows nothing about.
370
- */
368
+ /** The summary plus what the chain says: whether the key's pass still exists, and a key alert. */
371
369
  async function summaryWithChain(s) {
372
370
  const base = summary(s), { state } = s.store, client = clientFor(state.deployment);
373
- const created = await passesByAgent(client, state.deployment, state.sessionAddress).catch(() => null);
374
- // A creation record outlives the pass; only an existing object is a live pass.
375
- const onChain = created
376
- ? await Promise.all(created.map(async (c) => ({
377
- id: c.id,
378
- live: await client.getObject({ objectId: c.id }).then(() => true, () => false),
379
- })))
380
- : null;
381
- const own = onChain?.find((c) => c.id === state.active?.passId);
382
- const closed = !!state.active && !!onChain && !own?.live;
383
- const extra = onChain?.filter((c) => c.live && c.id !== state.active?.passId) ?? [];
371
+ const passId = passIdOf(state.deployment, state.sessionAddress);
372
+ const live = await client.getObject({ objectId: passId }).then(() => true, () => false);
373
+ const closed = !!state.active && !live;
384
374
  return {
385
375
  ...base,
376
+ ...(state.active && !closed
377
+ ? await keyAlert(client, s.store.directory, state.sessionAddress)
378
+ : {}),
386
379
  ...(closed
387
380
  ? {
388
381
  status: 'closed',
389
382
  note: 'The owner closed this pass; its key has nothing left to act on.',
390
383
  }
391
384
  : {}),
392
- passesOnChain: onChain,
393
- ...(extra.length
394
- ? {
395
- warning: `This key is the agent of ${extra.length + (own?.live ? 1 : 0)} live passes, not one: ${extra
396
- .map((c) => c.id)
397
- .join(', ')} were created by signing the same proposal again. Each is live with its own allowances and gas until the owner stops or closes it from its pass page (#/pass/<id>).`,
398
- }
399
- : {}),
400
385
  };
401
386
  }
402
387
  /** `forget_pass` for one session directory, from outside the MCP: the CLI and tests. */
@@ -422,6 +407,7 @@ async function poolPrice(d, p) {
422
407
  export function createPluginMcp(registry) {
423
408
  const server = new McpServer({ name: 'agent-pass', version: '0.1.0' }, {
424
409
  instructions: `${INSTRUCTIONS} This server also runs the owner flow: propose_authorization turns reviewed rules into a pass proposal and opens the owner's wallet page; session_info (with wait) reports when the owner has signed and the on-chain policies match; revoke_pass reopens the owner page for revocation. Show the owner the exact "rules" text returned by propose_authorization before they sign; never paraphrase amounts.`,
410
+ maxToolInputElements: MAX_TOOL_INPUT_ELEMENTS,
425
411
  });
426
412
  registerDocs(server);
427
413
  server.registerTool('list_passes', {
@@ -436,6 +422,7 @@ export function createPluginMcp(registry) {
436
422
  const path = registry.deploymentPath();
437
423
  const markets = async (d) => ({
438
424
  network: d.network,
425
+ maxTermDays: d.maxTermDays,
439
426
  coins: d.coins,
440
427
  pools: await Promise.all(d.pools.map(async (p) => ({
441
428
  venue: p.venue,
@@ -511,7 +498,12 @@ export function createPluginMcp(registry) {
511
498
  .regex(/^[\x20-\x7e]{1,64}$/)
512
499
  .default('Agent session'),
513
500
  ...rulesInput,
514
- days: z.number().int().min(1).max(30).describe('agent term'),
501
+ days: z
502
+ .number()
503
+ .int()
504
+ .min(1)
505
+ .max(MAX_TERM_DAYS)
506
+ .describe("agent term; at most the network's maxTermDays from list_passes"),
515
507
  gasSui: decimal
516
508
  .default('0.05')
517
509
  .describe('gas stipend to the agent address, outside the rules'),
@@ -520,7 +512,7 @@ export function createPluginMcp(registry) {
520
512
  .describe('lifetime SUI the agent may pull to top up its gas, a separate allowance'),
521
513
  gasDailySui: decimal
522
514
  .optional()
523
- .describe('SUI the agent may pull for gas per UTC day; defaults to a fifth of gasCapSui'),
515
+ .describe('SUI the agent may pull for gas in each 24 hours counted from its first top-up, not per UTC day; defaults to a fifth of gasCapSui'),
524
516
  network: z
525
517
  .enum(['mainnet', 'testnet', 'devnet', 'localnet'])
526
518
  .optional()
@@ -685,9 +677,16 @@ export function createPluginMcp(registry) {
685
677
  .optional()
686
678
  .describe('pass id prefix from list_passes; omit if there is one'),
687
679
  ...rulesInput,
688
- days: z.number().int().min(1).max(30).describe('agent term from now'),
680
+ days: z
681
+ .number()
682
+ .int()
683
+ .min(1)
684
+ .max(MAX_TERM_DAYS)
685
+ .describe("agent term from now; at most the network's maxTermDays"),
689
686
  gasCapSui: decimal.describe('lifetime SUI the agent may pull to top up its gas'),
690
- gasDailySui: decimal.optional().describe('per UTC day; defaults to a fifth of gasCapSui'),
687
+ gasDailySui: decimal
688
+ .optional()
689
+ .describe('per 24 hours counted from the first top-up, not per UTC day; defaults to a fifth of gasCapSui'),
691
690
  },
692
691
  annotations: { readOnlyHint: false, destructiveHint: false },
693
692
  }, async ({ pass, ...input }) => {
package/dist/server.js CHANGED
@@ -19,6 +19,7 @@ import { findPassByAgent } from './explorer.js';
19
19
  import { passClosed, returnGasFloat } from './float.js';
20
20
  import { createMcp, sessionInfo } from './mcp.js';
21
21
  import { SessionSigner } from './signer.js';
22
+ import { SessionStore } from './storage.js';
22
23
  export function authenticated(request, expected) {
23
24
  const supplied = Buffer.from(request.headers.authorization ?? ''), wanted = Buffer.from(`Bearer ${expected}`);
24
25
  return supplied.length === wanted.length && timingSafeEqual(supplied, wanted);
@@ -102,7 +103,7 @@ async function sweepGasIfEnded(store, client) {
102
103
  export async function startServer(store, port = 0) {
103
104
  const d = store.state.deployment, client = clientFor(d);
104
105
  await assertChain(client, d);
105
- const mcpToken = await store.mcpToken(), signer = new SessionSigner(await store.key(), d.chainIdentifier);
106
+ const mcpToken = await store.mcpToken(), signer = new SessionSigner(await store.key(), d.chainIdentifier, (digest) => SessionStore.recordSigned(store.directory, digest));
106
107
  let origin = '', closed = false;
107
108
  const webRoot = fileURLToPath(new URL('../web-dist/', import.meta.url));
108
109
  const server = createServer(async (request, response) => {
package/dist/signer.js CHANGED
@@ -5,9 +5,13 @@ import { fromBase64, normalizeSuiAddress, toBase64 } from '@mysten/sui/utils';
5
5
  export class SessionSigner {
6
6
  key;
7
7
  chainIdentifier;
8
- constructor(key, chainIdentifier) {
8
+ record;
9
+ constructor(key, chainIdentifier,
10
+ /** Called with each digest before its signature is returned. */
11
+ record) {
9
12
  this.key = key;
10
13
  this.chainIdentifier = chainIdentifier;
14
+ this.record = record;
11
15
  }
12
16
  get address() {
13
17
  return this.key.toSuiAddress();
@@ -29,12 +33,9 @@ export class SessionSigner {
29
33
  throw new Error('Transaction must carry a ValidDuring/Validity expiration bound to the configured chain (use address-balance gas)');
30
34
  // Sign precisely the supplied bytes with Sui's TransactionData intent. No rebuilding,
31
35
  // simulation, submission, arbitrary-message signing, or financial allowlist here.
36
+ const digest = await tx.getDigest();
37
+ await this.record(digest);
32
38
  const signed = await this.key.signTransaction(bytes);
33
- return {
34
- bytes: signed.bytes,
35
- signature: signed.signature,
36
- digest: await tx.getDigest(),
37
- signer: this.address,
38
- };
39
+ return { bytes: signed.bytes, signature: signed.signature, digest, signer: this.address };
39
40
  }
40
41
  }