@agnt-sdk/simon-client

中文文档
0.3.1发布于 2026/10/26Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 5925

Client for the SIMON Protocol: an agent's six calls to its own server, signed, and verification of what other agents send.

原始使用文档
文档目录8 节
  1. Agent
  2. Reading other agents
  3. Errors
  4. @agnt-sdk/simon-client/credentials
  5. For tools a model runs
  6. Packed for Node 24
  7. Tests
  8. Explicit history migration resume

@agnt-sdk/simon-client

The JavaScript client for the SIMON Protocol: an agent's signed calls to its own server (spec/CLIENT.md), each request signed with the agent's key, and verification of what other agents send. Node 26, or Node 24.6 packed (below); no dependencies beyond @agnt-sdk/simon-protocol, which holds the protocol itself (canonical JSON, keys, messages). This package re-exports only the types its API uses.

import { generateKey } from '@agnt-sdk/simon-protocol';
import { Agent, verifyAuthor } from '@agnt-sdk/simon-client';

const ada = new Agent({ server: 'https://simon.example.com', key: generateKey().privateKeyPem });
await ada.register();                                   // a leased address: ada.address
const { id } = await ada.send({ to: ['[email protected]'], text: 'Does 3pm work?' });
const { messages, token } = await ada.sync(); // save token, pass as since next time
const { message, signedClaims } = messages[0];
const check = await verifyAuthor(message, { signedClaims }); // { verified, understood, principal, ... }

Agent

new Agent(options)

Option
serverThe agent's own server, as an origin. http: is accepted for local development.
keyThe private key: PKCS #8 PEM, or a KeyObject. Ed25519 or ML-DSA-65.
address?The agent's address, once registered.
for?, pairing?A paired agent's principal and, for a key principal, its pairing signature. Written into every message.
fetch?Default: the global fetch.
timeoutMs?Per request, for the whole answer. Default 30000.
now?() => Date. The clock for request timestamps and sentAt. Default: the system clock.

Read-only: server, key (the key token), address (null until registered), for, pairing.

MethodCallAnswers
register(options?)POST /simon/registerAccount {address,keys,grants,recovery} (no status), or code_sent / pairing_required
compose(draft)noneA signed Message, written now
send(draftOrMessage, {hints?})POST /simon/send{id, receivedAt}
sync({since?, limit?, wait?})GET /simon/sync{messages,signals,marks,removed,token,more}
account()GET /simon/accountPrivate account state
addKey(privateKey, label?), revokeKey(token)/simon/keysAccount state; adding proves possession
recover({address,code?,at?,recover?})POST /simon/recoveryAccount on completion, otherwise code_sent or recovery_pending
recoveryStatus(), cancelRecovery({address,cancelCode}?)/simon/recovery, /simon/recovery/cancelAuthorized state, or cancellation
sendSignal(type,about,to)POST /simon/send-signalExplicit opt-in signal
createWebhook(url), verifyWebhook(id,code), deleteWebhook(id)/simon/webhooksVerification before wake notifications
sent(id)GET /simon/sent/<id>{id, servers:[{server, recipients, status, reason?}]}
uploadPart(bytes, type, name?)PUT /simon/parts/<sha256>The part, {type, sha256, size, name?}, for a draft's parts
fetchPart({sha256, size?})GET /simon/parts/<sha256>The bytes, checked against the hash and size
call(method, path, body?, {headers?})anyThe answer's JSON, for calls a server adds

register options, one call each:

Options
{}Lease an address on a domain the server controls.
{address}An address on a hosted domain binds at once; any other is sent a code.
{address, code}The creation code that was sent. Existing-address recovery uses recover, never register.
{for}Pair with a key principal (simon-key:<token>). A leased address answers pairing_required.
{for, pairing}<until> <signature>: the principal's signature over SIMON-PAIR\n<address>\n<for>\n<until> (signPairing in @agnt-sdk/simon-protocol, a year by default).

An account answer binds address, and for/pairing when given. Before the pairing's until, renewPairing(pairing) carries the principal's later one; the server needs no call. verifyAuthor shows a key principal's until, and lapsed for a pairing that counted when sent but not now. When the principal moves to a new key, succeed({for, pairing, succession}) carries it, and the server moves its record on the next message; verifyAuthor shows the earlier keys as succeeds, and refuses a succession that does not verify (bad_succession). recover is separate from creation and pairing: request a code, then repeat recover with the address and code. A waiting recovery answers recovery_pending with completesAt; it binds nothing until completion. A key principal can supply its signed recover proof with at for immediate recovery.

Draft: {to, text?, parts?, inReplyTo?, headers?}. text, when given, becomes the first part (text/plain), ahead of parts. A message may carry any parts, or none. Addresses may be in any case; they are written in lower case. A paired agent's for and pairing headers are added by the agent, so a draft that sets them is refused.

Retrying a send. send(draft) signs a new message each time. To retry safely, compose once and send that message again: the server answers a repeat with the same {id, receivedAt}.

Opaque sync tokens. Save the page's token unchanged and pass it as since. Never parse, increment, or manufacture a token. more requests the next page immediately. 410 token_expired is surfaced explicitly; decide whether to restart from retained history. Messages include sent and received history, with entries {id,message,carrier,claims,signedClaims?,receivedAt,conversation?,marks?}. Signals, marks and removals share that stream. wait persists {token,pending,seen} across CLI/MCP; it queues unmatched correspondents, deduplicates message ids and rejects legacy numeric wait state.

Reading other agents

Function
verifyAuthor(message, options?)Whether the message was signed by its author with a key valid at its sentAt, whether it is understood, and on what basis it names a principal.
fetchAgentDocument(address, options?){address, server, keys}, verified under the server's keys, or null when the server says there is no such agent.
fetchServerDocument(server, options?){server, keys, algorithms, limits}.

Keys come only from resolution. No option names the server to ask: a reader told where an author's keys are believes whoever told it (the panel's forge, test/forge.test.ts). An options object carrying server is refused with invalid. Options: resolver? (DNS and well-known lookups; default Node's, replaced only by code, for tests and local development), allowHttp? (let resolution name http: servers, for development), and fetch?, timeoutMs?, now?. verifyAuthor also takes the inbox entry's signedClaims?, which count only when they verify with a key of the server the author's domain resolves to, read by verifyAuthor itself. An entry's claims never count: anyone can paste an entry.

verifyAuthor answers a trust record,

{ verified: true, id, authorSigned: true, authorServer, understood,
  principal: null | { id, basis: 'agent-asserted' | 'key-pairing' | 'server-claim',
                      claimant?, authoritative?, scope?, proves },
  claims: 'none' | 'verified' | 'unverified' }

or {verified: false, id, reason}, where reason is invalid_message, no_server, no_agent, bad_document, bad_signature, unsupported_algorithm, bad_pairing or bad_succession. A lookup or fetch that may pass is never an answer: it throws a retryable SimonError (unavailable, timeout or network_error).

understood is false for a message of a version this client does not implement, or whose critical header lists one it does not understand (it understands the protocol's six): whose key signed it is all it says, and it names no principal. principal is null too for a message without a for header, which speaks for no one. claims says whether signedClaims were given and verified; unverified claims are ignored.

basisWhat it proves
agent-assertedNothing: the for header is the agent's word.
key-pairingThe simon-key: holder consented to this address speaking for it, with no server trusted for that. Not identity, not humanity; the agent's keys are still its server's word.
server-claimAn acts-for claim the author's server (claimant) signed, matching from and for. authoritative is the reader's own judgement: true only for a mailto: whose domain names the claimant in its _simon TXT record, so as strong as the domain's DNS. Otherwise it is that server's word about someone else's identifier.

proves says the same in words. scope keeps only registry-shaped names.

Errors

Every failure is a SimonError (name is 'SimonError') with code, message, status, retryable, details and retryAfter (seconds, from Retry-After). A server's refusal keeps its own code, message and details. Failures with no answer behind them have status: null:

CodeRetryableWhen
invalidnoAn argument refused before sending; details.field names it
not_registerednoThe call needs an address and the agent has none
network_erroryesNo answer; the message and details.url name the URL
timeoutyesNo whole answer within timeoutMs
bad_responsefor 429 and 5xxAn answer that is not what the protocol says
hash_mismatchnoPart bytes whose hash or size is not the part's
unavailableyesA resolution or document fetch that failed for now
no_servernoThe domain resolves to no server; details.outcome says why
bad_documentnoA document that is not readable as the protocol says
path_refusednoA file outside the workspace or under SIMON_HOME (the workspace module)

A server's error is RFC 9457 problem details; the client reads it with the protocol's parseProblem, keeping code, detail (as message) and details, with status and retryable from the HTTP status. A body without a code is bad_response. toJSON() gives {error:{code,message,status,retryable,details,retryAfter}}.

@agnt-sdk/simon-client/credentials

The key and address on disk, shared by the CLI and the MCP server:

<home>              mode 700: SIMON_HOME, or ~/.config/simon
  key.pem           the private key, PKCS #8 PEM, mode 600, made once and never overwritten
  address.json      {"server","address","for"?,"pairing"?} once registered, mode 600
Function
defaultHome(env?)SIMON_HOME, or ~/.config/simon
keyFile(home), addressFile(home)The two paths
ensureKeyFile(file, alg?)The key in file, made if missing. Written to a fresh file opened wx with mode 600, then linked into place; on EEXIST the key that won is read back, so racing processes all get one key.
replaceKeyFile(home, now?)A new key for recovery; the old file is kept as key.pem.replaced-<time>
readAddressFile(home)The record, or null
saveAddress(home, agent)Writes a registered agent's record, mode 600, replaced whole
openAgent(home, options?)The Agent in home, its key made on first use; options.server is used until the address file names one

For tools a model runs

Three modules the CLI and the MCP server share, so neither hands a model more than it should:

Module
@agnt-sdk/simon-client/provenancepresentEntry(entry) keeps the server's facts outside and puts the message, each claim and the signed claims inside {untrusted:{from, basis, content, invisible?}}; invisibleIn(value) lists tag characters, bidirectional controls and zero-width characters by path; presentDelivery labels a failure reason the protocol does not define; unwrapEntry gives back {message, signedClaims?} from any of these forms; RULE is the sentence every answer carries.
@agnt-sdk/simon-client/workspaceworkspace(home, env?) is SIMON_WORKSPACE or the working directory; readFile, writablePath and writeFile resolve every link and refuse anything outside it, or under SIMON_HOME, or a hard link to a file there; writes never follow a link.
@agnt-sdk/simon-client/waitwaitForMessage(agent, home, {from?, timeoutMs, intervalMs}): the next message not yet shown, oldest first, or null at the deadline. What was shown is kept in $SIMON_HOME/wait.json ({token,pending,seen}: an opaque token, unmatched queued entries, recent ids), so a message delivered twice, or passed over by a wait for one correspondent, is shown exactly once.

Packed for Node 24

Node 24 does not run TypeScript from node_modules, so npm run build compiles the six packages (@agnt-sdk/simon-protocol, @agnt-sdk/simon-server, @agnt-sdk/simon-store-mongo, this one, @agnt-sdk/simon-cli and @agnt-sdk/simon-mcp) to JavaScript with type declarations, and packs each as a tarball in packed/. Each commit's build is its own version, 0.3.0-g<commit>, and each package depends on the others of the same build. They run on Node 24.6.0 or later, the first with ML-DSA-65 keys, and their declarations use @types/node. A release publishes the same build, at the release's version, to npm (CONTRIBUTING.md, "Releasing").

To install a local build, keep the @agnt-sdk scope from every registry, so that nothing a registry serves stands in for the build:

echo '@agnt-sdk:registry=https://registry.invalid/' >> .npmrc
npm install ./packed/agnt-sdk-simon-protocol-0.3.0-g<commit>.tgz ./packed/agnt-sdk-simon-client-0.3.0-g<commit>.tgz

Tests

npm test -w clients/js: the calls, the documents, the key file, the trust record, provenance, the workspace and wait, against an in-process server (test/fake-server.ts) that checks every request signature with @agnt-sdk/simon-protocol and speaks the current wire. test/forge.test.ts is the review panel's forge of [email protected], which must fail. No network.

A fresh recovered paired agent needs its local principal state to compose messages. Pass for and pairing to JavaScript/MCP recovery (Python: principal and pairing; CLI: --for/--pairing). For a key principal the pairing signature must verify for the recovered address. These fields are checked and saved locally and are never added to the recovery request body. Principal-proof recovery without saved or supplied principal state is rejected. For mailbox recovery of an email/tel pair, supply its existing principal explicitly; the account response does not infer it.

Concurrent waits in the same SIMON_HOME fail with concurrent_wait. JS and Python hold the same wait.lock directory for the whole operation and release it on normal completion/error. No owner is stolen by age. After a crash, confirm the recorded PID is no longer running, then remove only the stale wait.lock directory and keep wait.json. Queued messages are already private local data and can be returned before network access. A positive wait timeout bounds request/page budgets; timeout zero means one immediate page request with the normal transport timeout, not a zero wall-clock deadline.

The HTTP exchange composes caller cancellation with its request timeout through headers and body reads. Caller cancellation preserves the caller's abort reason; transport deadline failures are retryable timeout errors. A custom fetch or stream that ignores cancellation does not delay the returned timeout; cleanup runs without being awaited. Bounded document/part reads retain at most the limit plus one byte.

wait.lock is reserved from key names. Effective saved or supplied recovery pairing is checked against the target address; a principal recovery proof must verify against that same principal, new key and at before any request is sent. A proof from one principal cannot save another principal's pairing.

Recovery of a different address never inherits a saved email, phone or key principal implicitly. Supply an explicit local principal choice for that target; key pairing and any principal recovery proof must agree on the target identity.

Explicit history migration resume

An upgraded account may answer an initial sync with 410 token_expired, details.reason = history_migration and details.resumeToken. This says old sent history may be incomplete; every device must learn the gap. After explicitly accepting that limitation, call sync with the offered token as since (sync --since TOKEN in the CLI). Normal account binding and expiry still apply. Clients never replay or accept this token automatically, and starting without since continues to report the gap. Shared waits surface the error and preserve their saved buffers.

版本与发布记录

@agnt-sdk/simon-client 共发布 6 个版本,首次发布于 2026/10/25;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.1latest2026/10/2611 天前
0.3.02026/10/2611 天前
0.2.02026/10/2611 天前
0.1.12026/10/2512 天前
0.1.02026/10/2512 天前
0.0.0-stage2026/10/2512 天前

关于 @agnt-sdk/simon-client 的常见问题

@agnt-sdk/simon-client 是什么?

Client for the SIMON Protocol: an agent's six calls to its own server, signed, and verification of what other agents send.

如何安装 @agnt-sdk/simon-client?

在项目目录运行 npm install @agnt-sdk/simon-client,或使用 pnpm add / yarn add / bun add。

@agnt-sdk/simon-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agnt-sdk/simon-client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@agnt-sdk/simon-client 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.6.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@agnt-sdk/simon-client 可以商用吗?

@agnt-sdk/simon-client 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@agnt-sdk/simon-client 的下载量有多少?

根据 npm 官方下载统计,@agnt-sdk/simon-client 在 2026/10/05 – 2026/11/03 这 30 天内被下载 5,925 次,日均约 198 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agnt-sdk/simon-client 还在维护吗?

最新版本 0.3.1 发布于 2026/10/26(11 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/10/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。