224 Commits

Author SHA1 Message Date
FilipBl4gojevic
74ddf873d6 feat(signer): local append-only audit log
Records intent at signing time; the signer has no network so it cannot
observe submission. Refusals are recorded but never consume daily budget.

Hardened beyond the brief after an edge-case pass found two genuine
under-report vectors in committedTodayLovelace() (the function the daily
limit's alreadySpentTodayLovelace comes from): a negative netOutflowLovelace
string parses as a valid negative bigint and would silently subtract from the
total, and a null element in the on-disk array crashes the summation outright
rather than being skipped. Both are neutralized. Also: load() now reports a
non-array log file on stderr instead of resetting silently, recent(0) no
longer returns the whole log (Array.prototype.slice(-0) is slice(0), not "no
entries" - a plain JS gotcha), and append() now throws on a write failure
instead of swallowing it, since a swallowed failure is a normal-looking
return while the entry silently exists only in memory until the next
restart's reload finds it missing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-28 13:38:29 +02:00
FilipBl4gojevic
ea3a23e5f9 fix(signer): match own addresses after trimming, not before
knownAddresses validated the trimmed value but stored the original, so an
own address configured with an incidental leading or trailing space passed
the fail-closed gate yet could never match its own outputs - every change
output was then counted as outflow and normal transactions were refused.

Also pins prefix-match, trim-before-check, and case-sensitivity, none of
which any test previously required.
2026-07-28 13:18:58 +02:00
FilipBl4gojevic
97987427ce fix(signer): close two review-found gaps in ownAddresses validation
Fix 1 (Important, live bypass): the blank-address fix from the prior commit
used .trim().length > 0, which only strips the ECMAScript WhiteSpace set
(NBSP U+00A0, BOM U+FEFF, etc). U+200B ZERO WIDTH SPACE and U+2060 WORD
JOINER are Unicode category Cf (format), not Zs, so trim() leaves them
untouched - ownAddresses: ['\u200B'] passed the filter, bypassed the
fail-closed guard, and reproduced allowed:true against the shipped code
(verified directly, not just against a mutant). Replaced the blank-only
filter with a positive check: an entry only counts as a known own address if
it starts with 'addr' after trimming. A denylist of invisible codepoints is
unwinnable; this rules out anything built from them without enumerating any.
Applies at both call sites (evaluate's guard and computeOutflow's Set) via
the shared knownAddresses() helper, as it already did.

Fix 2 (Important, surviving mutant): added a regression test that exercises
computeOutflow's own Set-construction filtering directly, independent of
evaluate's separate guard - a blank/invisible output address paired with a
matching blank/invisible ownAddresses entry must still count as outflow, not
be matched as change. Nothing previously exercised this combination: every
prior blank-entry test either went through evaluate (whose guard would
refuse first) or paired a blank ownAddresses entry with a real output
address. Confirmed this test now fails if computeOutflow's Set reverts to
unfiltered while evaluate's guard stays filtered (re-verified in this
session; see the report addendum for output).

Fix 3: added a doc comment on evaluate() stating plainly that it bounds
lovelace only - assetMovements is reported for visibility and never gates
allowed. No interface change; this is documentation of the existing,
deliberate v1 scope boundary already flagged in the task report, not new
behavior.

Re-ran the full mutation set after all three fixes: inverted classification,
removed fail-closed guard entirely, guard reverted to raw
ownAddresses.length === 0, and computeOutflow's Set left unfiltered are all
caught. Full before/after evidence in the report addendum.
2026-07-28 12:57:45 +02:00
FilipBl4gojevic
9bbd26b04c fix(signer): treat blank-only ownAddresses as no known own address
Adversarial pass on the spend policy found that ownAddresses.length === 0
does not catch a non-empty array containing only blank entries - a realistic
outcome of ''.split(',') on an empty config/env value, which yields [''] not
[]. A blank entry never matches a real output address, so it degrades to
"every output looks foreign" rather than permitting anything, but it bypassed
the explicit fail-closed path and its message, and if the resulting
over-counted outflow still happened to land under the configured limits the
transaction would be signed without any real own address ever having been
known - exactly the condition that check exists to refuse.

knownAddresses() filters blank entries before both the Set used for
classification and the fail-closed emptiness check, so an all-blank list now
refuses the same way a literally empty one does. A blank entry alongside a
real address is unaffected (regression-tested).

Also adds the rest of the adversarial pass: exact-limit boundaries one
lovelace either side, many-small-outputs summation, aggregation correctness
(duplicate own addresses, repeated foreign addresses, multi-asset and
multi-output asset movements), check-ordering pins, zero-limit and
already-over-budget edge cases, and a pinned note that SpendLimits governs
lovelace only - native asset movements are tracked but not limited.

Every core comparison was verified to actually fail on injection (inverted
own/foreign check, dropped fee, dropped daily history, off-by-one on both
limit comparisons) before being reverted; see the task report.
2026-07-28 12:30:14 +02:00
FilipBl4gojevic
65a3c00994 feat(signer): spend policy over true net outflow
Net outflow is every output that does not return to us, plus the fee - more
accurate than summing declared amounts, and computable without chain access.
Refuses when no own address is known, since change cannot then be identified.
2026-07-28 12:23:12 +02:00
FilipBl4gojevic
2a8623d22a docs(signer): keep the durable rationale, drop the dated verification list
The mechanism explanation is worth keeping; the snapshot of which fixtures
were tested on which day is commit-message content that goes stale silently.
2026-07-28 12:14:39 +02:00
FilipBl4gojevic
5da4447835 fix(signer): reject transactions with unconsumed trailing bytes
from_cbor_hex only requires a valid prefix, so extra bytes were silently
dropped and decode returned a confident, fully-populated result - the exact
fail-open the module exists to prevent, and policy trusts this output.
2026-07-28 12:02:17 +02:00
FilipBl4gojevic
85d718dc14 fix(signer): allow .ts extension imports so tests are typechecked
The signer's tsconfig includes test files, and they import source with an
explicit .ts extension (which tsx resolves at runtime). Without this flag
tsc exits 2, which fails the blocking typecheck gate in CI. Safe because
noEmit is set; the alternative - excluding tests - would leave them
unchecked.
2026-07-28 11:41:31 +02:00
FilipBl4gojevic
b2eb998e41 feat(signer): decode a transaction body into plain data
Pure function over CBOR. Everything policy needs lives in the body, which is
why the signer never resolves inputs and therefore needs no chain access.
Fails closed on anything it cannot fully parse.

readAssets uses AssetName.to_hex() (raw bytes, no CBOR envelope) rather than
to_cbor_hex().slice(2), which corrupts asset names of 24-32 bytes because the
CBOR byte-string header grows from 1 to 2 bytes at length 24. Verified
directly against CML at lengths 0-32; the golden fixture carries no native
assets so the test suite alone can't catch this.
2026-07-28 11:38:59 +02:00
FilipBl4gojevic
de6ae72db9 test(signer): close the shell-out bypass and three evasions in the boundary test
Review found node:child_process had zero coverage across all four assertions:
execSync('curl ...') would have passed every one. Forbidden now, and verified
to fail when injected.

Also closed: backtick-quoted specifiers evaded the substring and regex scans;
sourceFiles() only walked .ts so a stray .js was invisible; the dependency
check ignored optional/peer deps and named only two packages.
2026-07-28 11:30:10 +02:00
FilipBl4gojevic
34b2d7fa18 test(signer): make the no-network boundary test able to actually fail
Two holes: the shared-dependency assertion was a tautology that held for any
manifest, and ambient globals (fetch, WebSocket) need no import so the import
scan was blind to them. Both now enforced, and both verified to fail when a
violation is injected.
2026-07-28 11:13:15 +02:00
FilipBl4gojevic
46e814b7ae feat(signer): scaffold the package and enforce the no-network boundary
The signer's security claim is that it cannot reach the network, not that it
chooses not to. test/boundary.test.ts enforces that mechanically over both the
import graph and the manifest.
2026-07-28 11:05:25 +02:00
david
b7806e8f8d update runs-on for the CI workflow 2026-07-28 10:40:36 +02:00
dcejtlin-apex
10892caa55 Merge pull request #6 from FilipBl4gojevic/refactor/workspaces-shared-builder
Split into npm workspaces: shared + builder
2026-07-28 10:39:47 +02:00
dcejtlin-apex
19d30dd523 Merge pull request #5 from FilipBl4gojevic/fix/zod-v4-typecheck-gate
Fix 8 TypeScript errors (zod/v4) and gate CI on typecheck
2026-07-28 10:39:23 +02:00
dcejtlin-apex
b02fd9ed13 Merge pull request #4 from FilipBl4gojevic/ci/harness-and-gitignore
CI harness, secret hygiene, and the non-custodial architecture doc
2026-07-28 10:38:53 +02:00
FilipBl4gojevic
d318f5233d fix: make the shared package a devDependency and drop stale paths
packages/builder is publishable (private:false) but depended on the
private workspace package at runtime - a published manifest would
advertise an unresolvable dependency. tsup's noExternal inlines it into
the bundle, so devDependencies is the correct home.

Also removes the root tsconfig.json, which still pointed at the deleted
src/, and corrects two README paths the move invalidated.
2026-07-28 10:04:05 +02:00
FilipBl4gojevic
a8912b93d4 build: update Dockerfile for the workspace layout 2026-07-28 10:04:05 +02:00
FilipBl4gojevic
4d7b51b289 test: regenerate the tool-schema snapshot for the AP3X terminology change
PR #3 renamed ADA to AP3X across agent-facing strings. Tool descriptions
are part of inputSchema, so the snapshot correctly flagged 6 tools. Delta
verified as terminology-only - no structural schema change.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
91fa6536cd fix: resolve project root correctly from the new build location
Both projectRoot computations were off by a level after the move: vector.ts
landed one directory above the repo root, and safety.ts's default audit-log
path landed in packages/ rather than the repo root that .env.example and
.gitignore both document. Verified empirically against the built entrypoint.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
d1b2c605fb docs: correct the architecture doc's PR 2 description and root cause
The doc still carried the pre-spike hypothesis (stale SDK, restructure
tool registration) as fact. Neither happened: ^1.4.1 resolves to 1.27.1,
and the real cause is Zod 3 vs the SDK's Zod 4 expectation. Also records
the accepted additionalProperties trade-off and replaces the resolved
spike open-item with the outstanding branch-protection action.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
0299e3176f refactor: move the MCP server into packages/builder
Pure file moves plus import repointing at the shared package. Removes
duplicated endpoint constants and formatting helpers that were copied
across three files. Verified: 23 tools with identical schemas.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
2e1d14fb25 ci: gate on typecheck 2026-07-28 10:04:04 +02:00
FilipBl4gojevic
98f414dedd build: commit the workspace-aware lockfile
npm install regenerated package-lock.json for the workspaces conversion.
Without it, npm ci on a fresh clone cannot resolve the workspace layout
and CI fails.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
b3971aefa5 test: use strict equality for schema snapshot comparisons
A test whose job is catching subtle JSON-serializer drift should not use
loose comparison - deepEqual would pass a string 1 against a numeric 1.
Also documents the zod/v4 isSchemaOptional() quirk on bare .default()
at the call site rather than only in a planning doc.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
4aab6db598 refactor: add workspaces root and @apexfusion/vector-mcp-shared
Extracts pure tx helpers, shared types, endpoint config, and the Ogmios
provider. Subpath exports (./tx vs ./provider) let the forthcoming signer
import pure helpers while being structurally unable to reach the network layer.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
c607c50911 test: add full-schema snapshot to the tool inventory smoke test
The existing smoke test only asserted tool names and count, which is
exactly why the additionalProperties regression from the zod/v4
conversion (previous two commits) went undetected by it — a tool's
argument schema can change shape completely without changing its name.

Add test/smoke/tool-schemas.snapshot.json: the full inputSchema for
all 23 tools, keyed by name, generated from a live built server after
the zod/v4 conversion (so it reflects the corrected, uniform surface,
not the mid-migration split). Extend tool-inventory.test.ts with a
key-set check plus one deepEqual test per tool, so a mismatch names
the specific tool and shows a field-level diff instead of a single
23-tool "objects differ" failure. Verified the failure mode directly:
temporarily corrupting one entry in the fixture failed exactly one
named test with a readable diff, while the other 25 kept passing.

This is a change detector, not a freeze — PRs 6, 7 and 8 are expected
to regenerate the fixture when they deliberately restructure tool
schemas, per the comment in the test file.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
8a42acad8f fix: convert agent-network.ts and self-improvement.ts to zod/v4
Both files carry @ts-nocheck, so there's no type-inference benefit
here (that was vector.ts's problem, fixed separately). This is purely
about making the runtime JSON Schema serializer uniform across all 23
tools: the MCP SDK routes Zod v3 schemas through the vendored
zod-to-json-schema and Zod v4 schemas through Zod's own native
toJSONSchema, and the two disagree on `additionalProperties` for
object schemas. Converting vector.ts alone left the surface split 11
"open" (v4, additionalProperties absent) / 12 "closed" (v3,
additionalProperties: false).

Plain import swaps — neither file uses z.record, so no signature
changes were needed. Both files use z.<type>().default(...) on several
fields (agent-network.ts: limit; self-improvement.ts:
proposalOutputIndex, priority, focus); verified via the SDK's own
zod-compat safeParseAsync/objectFromShape helpers that omitting each
of those fields still resolves to its default under zod/v4, exactly as
under v3. Also verified live: a missing required argument is still
rejected (schema-validation error, not a handler crash) on one tool
from each of the three files.

Confirmed post-conversion: all 23 tools report additionalProperties
consistently (0 false / 23 absent — uniform), typecheck stays clean
(these files are excluded from it), and build + unit tests pass.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
1059c89856 fix: import zod via zod/v4 to satisfy MCP SDK type inference
The SDK's ZodRawShapeCompat degrades on Zod 3 schemas, producing TS2589
and a knock-on TS2769. Importing zod/v4 (already shipped inside zod
3.25.76) clears all 8 type errors with no dependency change. Tool
names and count (23) are unchanged.

This does change the advertised JSON Schema, though. The SDK routes
Zod v3 schemas through the vendored zod-to-json-schema converter, but
Zod v4 schemas through Zod's own native toJSONSchema (see
server/zod-json-schema-compat.js). The two disagree on object schemas:
v4's converter does not emit `additionalProperties: false` where v3's
did. Confirmed live: vector_get_balance (now v4) reports
additionalProperties undefined, while vector_get_agent_profile (still
v3 at this commit) reports additionalProperties: false. Runtime
enforcement is unaffected in both cases — a missing required argument
is still rejected, and extra keys were already stripped under v3 — so
this is a wire-schema difference only, not a validation gap. The two
sibling files (agent-network.ts, self-improvement.ts) still import
plain "zod" (v3) at this commit, so the 23-tool surface is currently
split 11 "open" / 12 "closed" on additionalProperties; a follow-up
commit converts them to zod/v4 to make the surface uniform again and
adds a full-schema snapshot test so this class of regression cannot
land silently in the future.
2026-07-28 10:04:04 +02:00
FilipBl4gojevic
39e33628e4 docs: correct the Koios default in the README config table
The v2 Koios migration landed in main, so the config table's v1 default and
the 503-workaround note are both now false.
2026-07-28 10:03:56 +02:00
FilipBl4gojevic
790cbf80b8 docs: document the test:smoke command in the Testing section
CI runs test:smoke on every PR but the README only listed test:unit and
test:integration, so a contributor following the README wouldn't know to
run it locally.
2026-07-28 09:57:03 +02:00
FilipBl4gojevic
854c5b0005 docs: remove internal planning detail from the public architecture doc
This doc ships into a public repo (PR 1's own remit). Strip process
notes that read as an internal artifact rather than architecture:
the Decisions-table row naming who implements/reviews each PR, the
two "needs a funded testnet wallet from Filip" notes (also invites
"so it's untested?" from outside readers), and the instruction to
hold a line on PR #2, which already merged. Renumbered the Open
items list after dropping the wallet entry. The named-reviewer phrase
in section 10 falls in the same category and is genericized for the
same reason, though it wasn't separately called out.

Section 13 (residual risks) and the §12 typecheck findings are
untouched — those are load-bearing technical content, not planning
chatter.
2026-07-28 09:57:03 +02:00
FilipBl4gojevic
01416af3ab ci: harden workflow permissions, add timeout and concurrency gate
- permissions: contents: read — this workflow only builds and tests,
  it never writes to the repo; matches the convention deploy.yml
  already sets.
- timeout-minutes: 15 on the job so a hung step doesn't burn runner
  time indefinitely.
- concurrency group keyed on the ref so a new push cancels the
  in-flight run for the same branch/PR instead of queuing behind it.

Action versions are left unpinned (still @v4) — SHA-pinning only this
workflow while deploy.yml stays on @v4 would be an inconsistency to
clean up in its own pass, not here.
2026-07-28 09:57:03 +02:00
FilipBl4gojevic
9d4958500e test: add tool-inventory smoke test asserting the 23-tool surface
Every PR in the non-custodial-split series is supposed to preserve
`tools/list` returning 23 tools with identical schemas, but nothing
enforced it — PRs 2, 6, 7 and 8 will restructure and rename tool
families, and a snapshot only means something if it's taken before
that starts. Boot the built server, call listTools(), and assert both
the count and the exact sorted name list against a checked-in
baseline captured from a live run on this branch. Failures report
which names were added/removed rather than a bare array-diff.

Reuses startServer()/stopServer() from test/setup.ts; does not call
getMnemonic(), so it needs no wallet. Wired into CI as a new step
after the unit tests. Also raises the server-start timeout in
setup.ts from 15s to 60s — the Cardano WASM import makes cold starts
slow enough that 15s was flaky on the smoke test's first CI run.

test:smoke is intentionally separate from test:unit (which does not
build) since startServer() spawns build/index.js.
2026-07-28 09:57:02 +02:00
FilipBl4gojevic
ca94722412 docs: correct README testing instructions for unit/integration split
The Testing section still told contributors to write a real mnemonic
to mnemonic.txt and run `npm test`, then claimed the result was full
agent-lifecycle coverage against Vector testnet. Since test:unit is
now the default `test` script (five wallet-free CBOR assertions), that
instruction produced a false green and silently skipped the coverage
it advertised. Document test:unit and test:integration separately and
drop the stale VECTOR_MNEMONIC env-var alternative, which setup.ts
never reads.
2026-07-28 09:57:02 +02:00
FilipBl4gojevic
9ae2095c3a docs: redact unpatched vulnerability detail from the public architecture doc
The repo is public and the referenced fixes are still several PRs out.
Removes the internal audit pointer, the current auth-state confirmation,
the submission failure-mode detail, and the dependency CVE specifics.
Architecture, rationale, and PR sequence are unchanged.
2026-07-28 09:57:02 +02:00
FilipBl4gojevic
a3c38e70db docs: add non-custodial split architecture and correct the custody claim
PR #2 shipped 'never stored server-side', which is true but materially
incomplete - the mnemonic is a tool-call parameter, so it transits the MCP
client, the model provider, and hosted process memory. Replaced with an
accurate notice pointing at the architecture doc.
2026-07-28 09:57:02 +02:00
FilipBl4gojevic
999a8bcc7f ci: run build and unit tests on PRs and main 2026-07-28 09:57:02 +02:00
FilipBl4gojevic
a3c2930655 chore: gitignore mnemonic.txt, .secrets/, and the audit log 2026-07-28 09:57:02 +02:00
FilipBl4gojevic
5c858f1143 test: split unit and integration suites so CI can run without a wallet 2026-07-28 09:57:02 +02:00
dcejtlin-apex
e572ef8e04 Merge pull request #3 from FilipBl4gojevic/docs-consolidation-strings 2026-07-28 08:03:10 +02:00
FilipBl4gojevic
3d34ae41c8 Agent-facing strings: AP3X terminology, working Koios default, vocabulary cleanup
- ADA -> AP3X in tool/param descriptions, outputs, and safety messages
- default testnet Koios URL -> v2 endpoint (old default returns 503)
- self-improvement descriptions: improvement proposals / proposal metrics
- em dashes -> hyphens in strings and comments

No logic changes; code identifiers and protocol field names untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-27 12:47:49 +02:00
HalukG
8e0d381a7f Merge pull request #2 from FilipBl4gojevic/docs-consolidation-readme
README: hosted servers, 23-tool reference, mainnet endpoints, AP3X terminology
2026-07-24 13:45:57 +03:00
FilipBl4gojevic
c67e7a7056 Package metadata: docs-site homepage, description cleanup
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 11:48:40 +02:00
FilipBl4gojevic
9086ceba6a README: canonical Vector mainnet explorer URL
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 11:28:41 +02:00
FilipBl4gojevic
8230ee93ab README: vocabulary pass on Self-Improvement descriptions
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 11:26:56 +02:00
FilipBl4gojevic
2c25a70a3e README: hosted servers, 23-tool reference, mainnet endpoints, AP3X terminology
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 10:46:46 +02:00
david
0cd0a1b85f Rename governance MCP tools to vector_self_improvement_*
Renames the five tools to match the module's public name (Self-Improvement
Module), and renames the source file and registration function in kind.
Consumers relying on the old vector_governance_* names must update.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 11:44:49 +02:00
david
a8403e6082 Derive Vector slot config from chain instead of hardcoding testnet epoch
The SLOT_CONFIG_NETWORK.Mainnet zeroTime was hardcoded to the testnet
system start (1752057484000), causing RATE:slot_mismatch failures on
mainnet where the actual system start is 1756485600000. Now queries
Ogmios queryNetwork/startTime on first use and caches the result.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 00:10:13 +02:00
david
d21bf23307 update gha workflows 2026-04-15 23:23:54 +02:00