Skip to content

feat(agent): add remaining-spend helper and harden amount conversion - #228

Open
Olasunkanmi975 wants to merge 3 commits into
Sub-Rosa-Issue:mainfrom
Olasunkanmi975:feat/agent-remaining-spend-helper-193
Open

feat(agent): add remaining-spend helper and harden amount conversion#228
Olasunkanmi975 wants to merge 3 commits into
Sub-Rosa-Issue:mainfrom
Olasunkanmi975:feat/agent-remaining-spend-helper-193

Conversation

@Olasunkanmi975

Copy link
Copy Markdown

Summary

Implements issue #193 for the autonomous agent service.

Remaining-spend helper

  • Added remainingAppraisalSpend(mandate, spentSoFarStroops?) which returns the
    remaining x402 appraisal budget in stroops and throws a MandateCapError when
    cumulative spend already exceeds the mandate cap. Exported from the package
    entrypoint.

Hardened amount conversion

  • usdcToStroops now rejects non-finite (NaN/Infinity), negative and
    out-of-safe-range inputs with a clear MandateError instead of silently
    producing junk via BigInt(Math.round(...)).
  • stroopsToUsdc now requires a bigint, rejects negative values, and splits
    the whole/fraction parts to avoid Number(bigint) precision loss for large
    escrow/bid amounts.

Test plan

  • Extended services/agent/src/mandate.test.ts with cases for the hardened
    conversions (NaN/Infinity/negative rejection, round-trip) and for
    remainingAppraisalSpend (full budget, partial spend, over-cap and bad
    input).
  • pnpm test (13 passing) and pnpm typecheck for @sub-rosa/agent are green.
  • Existing mandate-cap-negative.test.ts still passes.

closes #193

…d comparator

Previously a single malformed/non-numeric round entry in
.keeper-store.json caused listRounds() ordering (which did BigInt() on
the id) to throw, which the load path surfaced as a full corrupted-file
backup that dropped every entry.

- Drop individual malformed round entries on load instead of nuking the
  whole store (still warn, still back up on truly corrupted JSON).
- Extract a shared compareRoundIds() numeric comparator so listRounds
  and callers (parseRoundIdSpec) order rounds consistently regardless of
  id type.

Closes Sub-Rosa-Issue#194
@Olasunkanmi975

Copy link
Copy Markdown
Author

@karagozemin please kindly review and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agent: add remaining-spend helper and harden amount conversion

1 participant