@priors/mcp 0.8.4 → 0.8.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @priors/mcp changelog
2
2
 
3
+ ## 0.8.5 (2026-10-12)
4
+
5
+ - **Money counts in the UTC day it lands** (GHSA-266h-jfr9-42cx). A call reserved its room in the day it started and
6
+ kept what it did there, so a borrow sent before 00:00 UTC that landed after was invisible to the new day's
7
+ `PRIORS_MAX_BORROW_DAY_USD` (and to `credit_status`'s "Today"), and a day could carry twice its limit; the same for
8
+ `PRIORS_MAX_SPEND_DAY_USD`. A call's money is now filed in the day it ends, and while a call is in flight every
9
+ process counts it in the days after the one it started, however long its transaction takes; one cut short by a
10
+ crash stays counted for the day it started and the two after.
11
+ - **`fund_base` counts against the session caps from its check** (GHSA-24qq-9p83-8798). It checked
12
+ `PRIORS_MAX_BORROW_TOTAL_USD` and `PRIORS_MAX_BRIDGE_TOTAL_USD`, then read the transfer record and the Base float,
13
+ and only then counted, so a second call made while the first waited on a late Base read could pass both caps
14
+ beside it. It now counts right after the check, as `borrow` and `pay_url` do (GHSA-cq9v), and gives it back when it
15
+ is refused.
16
+
3
17
  ## 0.8.4 (2026-10-11)
4
18
 
5
19
  - **SeatVaultV5 lines work out of the box.** The bundled `deployments/4663.v2.json` names SeatVaultV5
package/README.md CHANGED
@@ -171,7 +171,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
171
171
  "mcpServers": {
172
172
  "priors": {
173
173
  "command": "npx",
174
- "args": ["-y", "@priors/mcp@0.8.4"],
174
+ "args": ["-y", "@priors/mcp@0.8.5"],
175
175
  "env": {
176
176
  "PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
177
177
  "PRIORS_AGENT_ID": "1234"
@@ -193,7 +193,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
193
193
  "mcpServers": {
194
194
  "priors": {
195
195
  "command": "npx",
196
- "args": ["-y", "@priors/mcp@0.8.4"],
196
+ "args": ["-y", "@priors/mcp@0.8.5"],
197
197
  "env": {
198
198
  "PRIORS_KEY": "${PRIORS_KEY}",
199
199
  "PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
@@ -206,7 +206,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
206
206
  or, for your user only, from a macOS or Linux terminal:
207
207
 
208
208
  ```sh
209
- (read -rs PRIORS_KEY && umask 077 && mkdir -p ~/.config/priors && rm -f ~/.config/priors/agent.key && printf '%s\n' "$PRIORS_KEY" > ~/.config/priors/agent.key) && claude mcp add priors --scope user -- sh -c 'read -r PRIORS_KEY < "$1" && export PRIORS_KEY && exec npx -y @priors/mcp@0.8.4' priors-mcp ~/.config/priors/agent.key
209
+ (read -rs PRIORS_KEY && umask 077 && mkdir -p ~/.config/priors && rm -f ~/.config/priors/agent.key && printf '%s\n' "$PRIORS_KEY" > ~/.config/priors/agent.key) && claude mcp add priors --scope user -- sh -c 'read -r PRIORS_KEY < "$1" && export PRIORS_KEY && exec npx -y @priors/mcp@0.8.5' priors-mcp ~/.config/priors/agent.key
210
210
  ```
211
211
 
212
212
  It waits for the key without showing it (paste it, then Enter), saves it in a file only you can read, and gives Claude
@@ -243,7 +243,10 @@ they require: without it the server does not start) and for the wallet whose key
243
243
  every process that shares `PRIORS_STATE_DIR`, kept as one file per money call under `<state dir>/daily-agent-<id>/` and
244
244
  `<state dir>/daily-wallet-<address>/`. Every key and every client acting for the agent shares one count, and a key run
245
245
  under another agent id still shares its wallet's. A call counts at the most it may sign or borrow (`max_price_usd`,
246
- `max_borrow_usd`) while it runs, then at what it did; one cut short by a crash stays counted at its most for that day.
246
+ `max_borrow_usd`) while it runs, then at what it did, in the UTC day it ended (a borrow sent just before 00:00 UTC that
247
+ lands after counts in the new day). A call still in flight at 00:00 UTC counts in the new day too, however long its
248
+ transaction takes, so a call another process makes after midnight already sees it; one cut short by a crash stays
249
+ counted at its most for the day it started and the two days after.
247
250
  Two processes racing for the last dollar never both get it. Only a server that sets a daily limit counts toward it, so
248
251
  give every client that uses the agent's key the same limits. `PRIORS_MAX_BORROW_DAY_USD=0` turns borrowing off;
249
252
  `credit_status` shows what is used today.
@@ -259,7 +262,7 @@ to approve a borrow; this package, with the key, pays for APIs. With borrowing o
259
262
  approves each loan in Priors' Go mode. ElizaOS (`@elizaos/plugin-mcp`):
260
263
 
261
264
  ```ts
262
- "priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.8.4"],
265
+ "priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.8.5"],
263
266
  env: { PRIORS_KEY_FILE: "/home/agent/.config/priors/agent-7311.key", PRIORS_AGENT_ID: "7311",
264
267
  PRIORS_MAX_BORROW_USD: "0", PRIORS_MAX_BORROW_DAY_USD: "0", PRIORS_MAX_SPEND_DAY_USD: "1", PRIORS_MAX_PRICE_USD: "0.10",
265
268
  PRIORS_PAY_HOSTS: "api.example.com" } }
@@ -271,7 +274,7 @@ OpenClaw (`mcp.servers`, JSON5) takes the same `command`, `args` and `env`; Herm
271
274
  mcp_servers:
272
275
  priors-wallet:
273
276
  command: npx
274
- args: ["-y", "@priors/mcp@0.8.4"]
277
+ args: ["-y", "@priors/mcp@0.8.5"]
275
278
  env:
276
279
  PRIORS_KEY_FILE: /home/agent/.config/priors/agent-7311.key
277
280
  PRIORS_AGENT_ID: "7311"
@@ -298,7 +301,7 @@ key proves it is there: it signs the ERC-8004 identity registry's `AgentWalletSe
298
301
  agent's).
299
302
 
300
303
  ```sh
301
- PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.8.4 link-wallet --agent 7311
304
+ PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.8.5 link-wallet --agent 7311
302
305
  ```
303
306
 
304
307
  It reads the registry's EIP-712 domain and refuses to sign for any other, takes the owner from the chain (`--owner`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@priors/mcp",
3
3
  "mcpName": "io.github.priors-agents/priors",
4
- "version": "0.8.4",
4
+ "version": "0.8.5",
5
5
  "private": false,
6
6
  "description": "MCP server for Priors on Robinhood Chain: pay x402 URLs in USDG, read balances, credit lines and scores, borrow and repay, and buy, sell and redeem PT-USDG. Key from PRIORS_KEY_FILE (a file only you can read) or PRIORS_KEY, never the command line.",
7
7
  "type": "module",
package/src/daily.mjs CHANGED
@@ -19,8 +19,18 @@
19
19
  // in (a count named after the wallet when the id was left out split one agent's day in two). And the wallet's,
20
20
  // "wallet-<address>": a key run under another agent id, by mistake or for a second agent it controls, still shares
21
21
  // one count of the money it holds. All of a call's files are created before any ledger is listed, so the argument
22
- // above holds in each. The day is the UTC date when the call starts; days before yesterday are deleted as new ones
23
- // begin. A file whose name is not a ledger entry is left alone and not counted.
22
+ // above holds in each. Money counts in the UTC day it lands (GHSA-266h). A call reserves in the day it starts, and also
23
+ // leaves a marker in <owner>/pending/, named after that day and its amounts, which every process counts in each day
24
+ // after it (up to PENDING_DAYS) for as long as the call is in flight, however long its transaction takes to mine. Once
25
+ // it ends, its entry becomes what it did, filed in the day it ended (never in a day before the one it started: a
26
+ // clock set back moves nothing back), and only then does its marker go. So a borrow sent before 00:00 UTC that lands
27
+ // after counts in the new day, and while it is still in flight a call another process makes after midnight already
28
+ // sees it. A process that dies mid-call leaves its entry at its most in the day it started and its marker counted
29
+ // PENDING_DAYS days more, the safe direction. Days before yesterday, and markers older than that count, are deleted as
30
+ // new days begin. A file whose name is not a ledger entry is left alone and not counted.
31
+ // SHORTCUT: a call still in flight more than PENDING_DAYS days after the day it started stops counting in later days.
32
+ // Ceiling: none on this chain, whose sequencer includes or refuses a transaction within seconds and whose forced
33
+ // inclusion is bounded to 24 h. Upgrade trigger: a money call that can stay in flight longer.
24
34
  import { closeSync, mkdirSync, openSync, readdirSync, renameSync, rmSync, unlinkSync } from "node:fs";
25
35
  import { join } from "node:path";
26
36
  import { randomBytes } from "node:crypto";
@@ -28,9 +38,14 @@ import { randomBytes } from "node:crypto";
28
38
  const ENTRY = /^(\d{1,30})-(\d{1,30})-\d{1,10}-[0-9a-f]{16}\.r$/;
29
39
  const DAY = /^\d{4}-\d{2}-\d{2}$/;
30
40
  const OWNER = /^(agent-\d{1,78}|wallet-0x[0-9a-f]{40})$/;
41
+ const PENDING = "pending";
42
+ const MARKER = /^(\d{4}-\d{2}-\d{2})_(\d{1,30})-(\d{1,30})-\d{1,10}-[0-9a-f]{16}\.r$/;
43
+ /** The days after the one it started in which a call still in flight is counted. */
44
+ export const PENDING_DAYS = 2;
31
45
 
32
46
  /** The UTC date of `ms` (YYYY-MM-DD). */
33
47
  export const utcDay = (ms) => new Date(ms).toISOString().slice(0, 10);
48
+ const dayPlus = (day, n) => utcDay(Date.parse(`${day}T00:00:00Z`) + n * 86_400_000);
34
49
 
35
50
  /** The agent PRIORS_AGENT_ID names, as a BigInt (leading zeros dropped: 007 and 7 are one agent), or null when it is
36
51
  * not a decimal id. */
@@ -56,6 +71,19 @@ function sum(dir, fs) {
56
71
  return { signed, borrowed };
57
72
  }
58
73
 
74
+ /** What calls started in the PENDING_DAYS days before `day` and still in flight hold: their markers in `pdir`. */
75
+ function inFlight(pdir, day, fs) {
76
+ let signed = 0n, borrowed = 0n;
77
+ let names;
78
+ try { names = fs.readdirSync(pdir); } catch (e) { if (e?.code === "ENOENT") return { signed, borrowed }; throw e; }
79
+ const oldest = dayPlus(day, -PENDING_DAYS);
80
+ for (const n of names) {
81
+ const m = MARKER.exec(n);
82
+ if (m && m[1] < day && m[1] >= oldest) { signed += BigInt(m[2]); borrowed += BigInt(m[3]); }
83
+ }
84
+ return { signed, borrowed };
85
+ }
86
+
59
87
  /**
60
88
  * A daily ledger under `stateDir` that counts in every one of `owners` (ledgerOwners; or `owner`, one name).
61
89
  * `caps.signed` / `caps.borrowed` are base units, or null for no limit of that kind; each holds in every owner's
@@ -66,17 +94,29 @@ export function dailyLedger({ stateDir, owners, owner, caps, now = () => Date.no
66
94
  if (!list.length || !list.every((o) => OWNER.test(String(o)))) throw new Error(`not a daily ledger owner: ${list.join(", ")}`);
67
95
  const rootOf = (o) => join(stateDir, `daily-${o}`);
68
96
  const swept = new Map();
69
- /** Days before yesterday go, once per owner and new day (best effort: a leftover day is never read again). */
97
+ /** Days before yesterday, and markers no day counts any more, go, once per owner and new day (best effort: a leftover
98
+ * is never read again). */
70
99
  function sweep(o, today) {
71
100
  if (swept.get(o) === today) return;
72
101
  swept.set(o, today);
73
- const yesterday = utcDay(Date.parse(`${today}T00:00:00Z`) - 86_400_000);
102
+ const yesterday = dayPlus(today, -1), oldest = dayPlus(today, -PENDING_DAYS);
74
103
  try { for (const d of fs.readdirSync(rootOf(o))) if (DAY.test(d) && d < yesterday) fs.rmSync(join(rootOf(o), d), { recursive: true, force: true }); } catch (_) { /* best effort */ }
104
+ try {
105
+ for (const n of fs.readdirSync(join(rootOf(o), PENDING))) {
106
+ const m = MARKER.exec(n);
107
+ if (m && m[1] < oldest) fs.unlinkSync(join(rootOf(o), PENDING, n));
108
+ }
109
+ } catch (_) { /* best effort */ }
75
110
  }
76
111
  const entryName = (s, b) => `${s}-${b}-${process.pid}-${randomBytes(8).toString("hex")}.r`;
77
112
  /** Takes a call's files back (a refusal, or a ledger that could not be written): best effort, since one left behind
78
- * only counts until the day ends, the safe direction. */
113
+ * only counts too much, the safe direction. */
79
114
  const drop = (files) => { for (const f of files) { try { fs.unlinkSync(join(f.dir, f.name)); } catch (_) { /* counted */ } } };
115
+ /** What an owner's ledger holds on `day`: that day's entries, and the calls started before it still in flight. */
116
+ const totalOn = (o, day) => {
117
+ const a = sum(join(rootOf(o), day), fs), p = inFlight(join(rootOf(o), PENDING), day, fs);
118
+ return { signed: a.signed + p.signed, borrowed: a.borrowed + p.borrowed };
119
+ };
80
120
  return {
81
121
  caps,
82
122
  owners: list,
@@ -85,7 +125,7 @@ export function dailyLedger({ stateDir, owners, owner, caps, now = () => Date.no
85
125
  const day = utcDay(now());
86
126
  const out = { signed: 0n, borrowed: 0n };
87
127
  for (const o of list) {
88
- const t = sum(join(rootOf(o), day), fs);
128
+ const t = totalOn(o, day);
89
129
  if (t.signed > out.signed) out.signed = t.signed;
90
130
  if (t.borrowed > out.borrowed) out.borrowed = t.borrowed;
91
131
  }
@@ -102,39 +142,61 @@ export function dailyLedger({ stateDir, owners, owner, caps, now = () => Date.no
102
142
  const files = [];
103
143
  try {
104
144
  for (const o of list) {
105
- const dir = join(rootOf(o), day);
106
- fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
107
145
  sweep(o, day);
146
+ const dir = join(rootOf(o), day), pdir = join(rootOf(o), PENDING);
147
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
148
+ fs.mkdirSync(pdir, { recursive: true, mode: 0o700 });
108
149
  const name = entryName(signed, borrowed);
109
150
  fs.closeSync(fs.openSync(join(dir, name), "wx", 0o600));
110
- files.push({ owner: o, dir, name });
151
+ files.push({ owner: o, day, dir, name });
152
+ // in flight: counted in the days after this one until it ends (GHSA-266h)
153
+ fs.closeSync(fs.openSync(join(pdir, `${day}_${name}`), "wx", 0o600));
154
+ files.push({ owner: o, day, dir: pdir, name: `${day}_${name}`, marker: true });
111
155
  }
112
156
  } catch (e) { drop(files); throw e; }
113
- // each ledger is listed only once all of this call's files exist: a racing process sees them, or this one sees its
114
- for (const f of files) {
115
- let total;
116
- try { total = sum(f.dir, fs); } catch (e) { drop(files); throw e; }
117
- for (const [kind, want] of [["signed", signed], ["borrowed", borrowed]]) {
118
- const cap = caps[kind];
119
- if (cap === null || cap === undefined || want === 0n || total[kind] <= cap) continue;
120
- drop(files);
121
- throw Object.assign(new Error(`daily ${kind} limit`), { code: "DAY_LIMIT", kind, owner: f.owner, used: total[kind] - want, cap, want });
157
+ // each ledger is listed only once all of this call's files exist: a racing process sees them, or this one sees its.
158
+ // A reservation that straddled 00:00 UTC is held against the new day too (its marker counts there).
159
+ const after = utcDay(now());
160
+ const days = after > day ? [day, after] : [day];
161
+ for (const o of list) {
162
+ for (const d of days) {
163
+ let total;
164
+ try { total = totalOn(o, d); } catch (e) { drop(files); throw e; }
165
+ for (const [kind, want] of [["signed", signed], ["borrowed", borrowed]]) {
166
+ const cap = caps[kind];
167
+ if (cap === null || cap === undefined || want === 0n || total[kind] <= cap) continue;
168
+ drop(files);
169
+ throw Object.assign(new Error(`daily ${kind} limit`), { code: "DAY_LIMIT", kind, owner: o, used: total[kind] - want, cap, want });
170
+ }
122
171
  }
123
172
  }
124
173
  return { files, signed, borrowed };
125
174
  },
126
- /** Once the call has ended: its entries become what it really did (signed, borrowed: what the server counted, which
127
- * includes anything that may have happened, like a payment signed before the request failed), or go when that is
128
- * nothing. Best effort: an entry that cannot be renamed stays at its most. */
175
+ /** Once the call has ended: in each owner's ledger its entry becomes what it really did (signed, borrowed: what the
176
+ * server counted, which includes anything that may have happened, like a payment signed before the request failed),
177
+ * filed in the UTC day it ends but never in a day before the one it started (GHSA-266h), or goes when that is
178
+ * nothing; then its in-flight marker goes. Best effort: an entry that cannot be moved stays at its most, and its
179
+ * marker stays too, so the days after still count it. */
129
180
  settle(r, signed, borrowed) {
130
181
  if (!r) return;
131
182
  const s = signed < 0n ? 0n : signed, b = borrowed < 0n ? 0n : borrowed;
132
- if (s === r.signed && b === r.borrowed) return;
133
- for (const f of r.files) {
183
+ const today = utcDay(now());
184
+ for (const o of list) {
185
+ const entry = r.files.find((f) => f.owner === o && !f.marker), marker = r.files.find((f) => f.owner === o && f.marker);
186
+ if (!entry) continue;
187
+ const start = entry.day ?? entry.dir.slice(-10);
188
+ const day = today > start ? today : start;
189
+ const dir = join(rootOf(o), day);
190
+ let done = true;
134
191
  try {
135
- if (s === 0n && b === 0n) fs.unlinkSync(join(f.dir, f.name));
136
- else fs.renameSync(join(f.dir, f.name), join(f.dir, entryName(s, b)));
137
- } catch (_) { /* stays counted at its most */ }
192
+ if (s === 0n && b === 0n) fs.unlinkSync(join(entry.dir, entry.name));
193
+ else if (entry.dir !== dir || s !== r.signed || b !== r.borrowed) {
194
+ if (entry.dir !== dir) fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
195
+ fs.renameSync(join(entry.dir, entry.name), join(dir, entryName(s, b)));
196
+ }
197
+ } catch (_) { done = false; /* stays counted at its most */ }
198
+ // the entry is final first: a crash between the two leaves the marker counted, never nothing
199
+ if (done && marker) drop([marker]);
138
200
  }
139
201
  },
140
202
  };
package/src/server.mjs CHANGED
@@ -1309,12 +1309,14 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
1309
1309
  const maxBorrow = dollars(max_borrow_usd ?? 0, "max_borrow_usd");
1310
1310
  if (maxBorrow > maxBorrowCeiling) throw new ToolError(`max_borrow_usd ${X.formatUsdg(maxBorrow)} is above this server's ceiling of ${usd(maxBorrowCeiling)} (PRIORS_MAX_BORROW_USD).`);
1311
1311
  if (maxBorrow > 0n && session.borrowed + maxBorrow > borrowTotalCap) throw new ToolError(`this could bring what is borrowed in this session to ${usd(session.borrowed + maxBorrow)}, above ${usd(borrowTotalCap)} (PRIORS_MAX_BORROW_TOTAL_USD).`);
1312
+ reserveDay(0n, maxBorrow); // the day's borrowing limit (PRIORS_MAX_BORROW_DAY_USD), before anything is moved
1313
+ // the most it may move and borrow, from its check with no await between (GHSA-cq9v) until it ends: counted after
1314
+ // the reads below, a call made once the hold of one stalled in them had ended passed both caps beside it (GHSA-24qq)
1315
+ count("bridged", amount); count("borrowed", maxBorrow);
1312
1316
  const f = await settleFlight();
1313
1317
  if (f) throw new ToolError(blocked(f));
1314
1318
  const float = await bridge.floatOf(wallet.address);
1315
1319
  if (float + amount > maxBaseFloat) throw new ToolError(`this would bring the Base float to about ${X.formatUsdg(float + amount)} USDC, above ${X.formatUsdg(maxBaseFloat)} (PRIORS_MAX_BASE_FLOAT_USD); it holds ${X.formatUsdg(float)} now. Nothing was done.`);
1316
- reserveDay(0n, maxBorrow); // the day's borrowing limit (PRIORS_MAX_BORROW_DAY_USD), before anything is moved
1317
- count("bridged", amount); count("borrowed", maxBorrow); // the most it may move and borrow, until it ends (GHSA-cq9v)
1318
1320
  // What stays on Robinhood Chain: what Autopay pulls in the next 24 h, and the USDG of payments signed there and not
1319
1321
  // settled (the borrow-the-gap rule alone does not know either).
1320
1322
  const nowS = Math.floor(Date.now() / 1000);