brainchain-verify 0.6.0 → 0.7.1
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 +88 -12
- package/dist/abi.js +1 -1
- package/dist/cli.js +201 -27
- package/dist/verify.d.ts +112 -5
- package/dist/verify.js +499 -81
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
# brainchain-verify
|
|
2
2
|
|
|
3
|
-
Check any BrainChain decision against the chain. The tool reads the decision from the `DecisionLog`, fetches
|
|
3
|
+
Check any BrainChain decision against the chain. The tool reads the decision from the `DecisionLog`, fetches its published record, recomputes its hashes and confidence, and applies the task's thresholds the way the contracts do. It needs a public RPC and nothing else: no keys, no account.
|
|
4
|
+
|
|
5
|
+
Each record holds the question BrainChain asked Jev, a decision model served by TypeSafe, and Jev's answer with its probabilities.
|
|
6
|
+
|
|
7
|
+
It also checks the reputation BrainChain writes for its workers. Each entry in the ERC-8004 registry on Robinhood Chain is followed through its signed receipt to the decision, the payment and the task on the board.
|
|
4
8
|
|
|
5
9
|
```sh
|
|
6
10
|
npx brainchain-verify mainnet 1
|
|
7
11
|
npx brainchain-verify mainnet --task 11 --set v3-1
|
|
8
12
|
npx brainchain-verify testnet 100 --json
|
|
9
13
|
npx brainchain-verify mainnet --receipt receipt.json
|
|
14
|
+
npx brainchain-verify mainnet --entry 20424:7
|
|
15
|
+
npx brainchain-verify mainnet --agent 20424
|
|
10
16
|
```
|
|
11
17
|
|
|
12
18
|
Requires Node.js 22 or later.
|
|
@@ -17,6 +23,8 @@ Requires Node.js 22 or later.
|
|
|
17
23
|
brainchain-verify <mainnet|testnet|chainId> <decisionId> [--set <TaskBoard>] [--rpc <url>] [--offline] [--json]
|
|
18
24
|
brainchain-verify <mainnet|testnet|chainId> --task <taskId> [--set <TaskBoard>] [--rpc <url>] [--offline] [--json]
|
|
19
25
|
brainchain-verify <mainnet|testnet|chainId> [<decisionId>] --receipt <file|url> [--set <TaskBoard>] [--rpc <url>] [--json]
|
|
26
|
+
brainchain-verify mainnet --entry <agentId>:[<writer>:]<feedbackIndex> [--rpc <url>] [--registry-rpc <url>] [--json]
|
|
27
|
+
brainchain-verify mainnet --agent <agentId> [--rpc <url>] [--registry-rpc <url>] [--json]
|
|
20
28
|
```
|
|
21
29
|
|
|
22
30
|
| Argument | Meaning |
|
|
@@ -26,18 +34,22 @@ brainchain-verify <mainnet|testnet|chainId> [<decisionId>] --receipt <file|url>
|
|
|
26
34
|
| `--task <id>` | Check every decision about one task, oldest first. |
|
|
27
35
|
| `--set <TaskBoard>` | A retired contract set from 3.0.0 on, by its TaskBoard address, by the key a decision page uses (`?set=v3-1`, or an older one the site still opens, such as `v4` for `v3-4`) or by release (`3.1.0`). Without it, the active set. Each set numbers its tasks and decisions from 1. The `v2` set is not supported: its board named tasks by id alone, which the subject check does not read. |
|
|
28
36
|
| `--rpc <url>` | Another RPC for the same chain. Records and briefs on private addresses are read only when this RPC is on one too. |
|
|
29
|
-
| `--receipt <file\|url>` | Check the receipt for a paid job, from a JSON file or an http(s) URL. Without a decision id, the tool checks the decision the receipt names, in the contract set its DecisionLog belongs to. See [receipts](#receipts). |
|
|
37
|
+
| `--receipt <file\|url>` | Check the receipt for a paid job, from a JSON file or an http(s) URL, of at most 64 KB. Without a decision id, the tool checks the decision the receipt names, in the contract set its DecisionLog belongs to. See [receipts](#receipts). |
|
|
38
|
+
| `--entry <agentId>:[<writer>:]<index>` | Check one reputation entry BrainChain wrote. See [reputation entries](#reputation-entries). |
|
|
39
|
+
| `--agent <agentId>` | Check every reputation entry BrainChain wrote for one agent, oldest first. |
|
|
40
|
+
| `--registry-rpc <url>` | Another RPC for Robinhood Chain, where the ERC-8004 registries are. |
|
|
30
41
|
| `--offline` | Fetch no receipt from the brain host. A receipt given with `--receipt` is still checked. |
|
|
31
42
|
| `--json` | One JSON object on stdout. |
|
|
32
43
|
| `--version` | Print the version. |
|
|
33
44
|
|
|
34
|
-
The package carries the active and retired contract sets from [`deployments/`](
|
|
45
|
+
The package carries the active and retired contract sets from [`deployments/`](https://github.com/usebrainchain/brainchain/tree/main/deployments) as they stood when it was built. An unknown `--set` lists them.
|
|
35
46
|
|
|
36
47
|
## Output
|
|
37
48
|
|
|
38
49
|
```text
|
|
39
50
|
$ npx brainchain-verify mainnet 22 --set v3-1
|
|
40
51
|
Decision 22 on BrainChain mainnet, contract set v3-1 (DecisionLog 0xbe8E68EbDEaf2C65bc13D8AD070d17098Be6d335)
|
|
52
|
+
Task 11: Compare the rule of 72 with the exact doubling time
|
|
41
53
|
|
|
42
54
|
ok read from DecisionLog 0xbe8E…d335: grade, recorded 2026-11-01 00:40:23 UTC in block 419, confidence 8000 bps
|
|
43
55
|
ok fetched the record from https://brain.usebrainchain.com/records/0xc6570be10e86227b06d9ce78b739c83dac8d62e9f9cf33b67f25b7d148e8182a.json
|
|
@@ -57,7 +69,9 @@ Verdict: match. The published record is exactly what the chain recorded, and the
|
|
|
57
69
|
Not checked: that Jev produced the answer. See https://docs.usebrainchain.com/trust-model
|
|
58
70
|
```
|
|
59
71
|
|
|
60
|
-
|
|
72
|
+
Under the header, a decision about a task names the task by its brief's title, or the brief's first line, cut to 100 characters, once the brief committed on chain has been read. With `--task` that line reads `Brief:`. If the title is not the task you meant, check `--set`: each set numbers its own tasks and decisions.
|
|
73
|
+
|
|
74
|
+
Each line is one check. `ok` passed and `FAIL` means the record and the chain disagree. `skip` is a check with nothing to run on, such as a brief the host does not have, with the reason on the line. `ERROR` is a check that could not run because something it reads could not be read: the host did not answer in up to three tries and 30 seconds in all, answered with an error, or sent more than the tool reads. A record the host does not have, or one the tool refuses to read (see `fetch`), is an `ERROR` too, since no other check can run without it. With `--task` or `--agent`, a decision or entry the RPC cannot read gets one `ERROR` line, named `rpc`, and the others are still checked. Each RPC call gets two tries of 8 seconds, and an RPC error names the RPC by chain and origin, such as `BrainChain RPC https://rpc.usebrainchain.com` or `Robinhood Chain RPC https://rpc.mainnet.chain.robinhood.com`.
|
|
61
75
|
|
|
62
76
|
The verdict is `match`, `withheld`, `UNVERIFIED` or `MISMATCH`. `withheld` means a record served without the work passed the checks that could run, and says what they leave out.
|
|
63
77
|
|
|
@@ -66,12 +80,12 @@ The verdict is `match`, `withheld`, `UNVERIFIED` or `MISMATCH`. `withheld` means
|
|
|
66
80
|
| Check | What passes |
|
|
67
81
|
| --- | --- |
|
|
68
82
|
| `read` | `DecisionLog.get(id)` and the decision's `Recorded` event agree. |
|
|
69
|
-
| `fetch` | The record at the event's `payloadURI` (https, http or a base64 `data:` URI, with redirects refused) is a decision record of at most 4 MB. Briefs are read the same way, up to 256 KB. Anything on a private or loopback address is refused, however its name resolves, unless `--rpc` is on one too. |
|
|
83
|
+
| `fetch` | The record at the event's `payloadURI` (https, http or a base64 `data:` URI, with redirects refused) is a decision record of at most 4 MB. A body that is not JSON, such as a proxy's error page, is an `ERROR`; JSON that is not a decision record is a `FAIL`. Briefs are read the same way, up to 256 KB. Anything on a private or loopback address is refused, however its name resolves, unless `--rpc` is on one too. |
|
|
70
84
|
| `withheld` | On a record served without the work: the kind is a grade or ruling, the request carries the service's marker where the work was, and the chain shows the work is not public. If any of these fails, the record is held to its hashes like any other. |
|
|
71
85
|
| `record-hash` | `keccak256` of the fetched bytes equals `payloadHash`. |
|
|
72
86
|
| `input-hash` | `keccak256` of the record's `request`, serialized canonically (keys sorted, no whitespace), equals `inputHash`. |
|
|
73
87
|
| `kind` | The record's kind is the one on chain. |
|
|
74
|
-
| `subject` | A task decision names `TaskBoard.subjectOf(task)` for this chain and board. A change
|
|
88
|
+
| `subject` | A task decision names `TaskBoard.subjectOf(task)` for this chain and board. A change's subject is the one on chain; it is tied to the call Jev was shown only once the change is queued, by `change-subject` and `change-call`. A grade of outside work is matched by the rules below. |
|
|
75
89
|
| `options` | The probabilities cover exactly the options in the question. A panel that decided without Jev records none of Jev's, and `panel` checks that it names Jev as missing. |
|
|
76
90
|
| `answer` | The record's answer encodes to the one on chain: the hired model's id or worker address, or 1 for accept, pay, adopt and allow and 0 for their opposites. |
|
|
77
91
|
| `confidence` | The record's confidence times 10,000, rounded, equals `confidenceBps`. |
|
|
@@ -80,7 +94,7 @@ The verdict is `match`, `withheld`, `UNVERIFIED` or `MISMATCH`. `withheld` means
|
|
|
80
94
|
| `second-grader` | On a decision graded twice: the second grader's probability of paying recomputes from its probabilities, and the receipt id it carries is shown. |
|
|
81
95
|
| `judge` | On a decision by a panel, one line for each judge after the second grader: its probability of paying recomputes from its probabilities, which cover the question's options, and the receipt id it carries is shown. |
|
|
82
96
|
| `panel` | On a decision by a panel: the candidate rules recompute from the judges' probabilities of paying, the record's rule is one of them, and a panel short of a member says which and pays only from 90%. |
|
|
83
|
-
| `brief` | The question quotes the task's brief, fetched from its `Posted` event and checked against `briefHash`. Bytes that miss the hash are a `FAIL
|
|
97
|
+
| `brief` | The question quotes the task's brief, fetched from its `Posted` event and checked against `briefHash`. Bytes that miss the hash are a `FAIL`. A host that answers 404, or a location the tool refuses, is a `skip`. A host that does not answer, answers with an error or sends more than 256 KB is an `ERROR`. Either way, a grade's confidence is still recomputed, from the record's own pass level. |
|
|
84
98
|
| `checks` | A brief can carry checks: a fenced block marked `python checks` or `javascript checks`. The record of a grade or ruling on that brief holds BrainChain's run of them after the delivered code, and the line names the run's language and outcome. A run that failed, timed out, found no code in that language or was too long to run makes the answer reject, or refund on a ruling, at 10,000 bps. A run that passed is in the question the graders read, in BrainChain's own wording. A task record with checks in its brief and no run is a `FAIL`. |
|
|
85
99
|
| `levels` | A grade or ruling used the brief's own quality levels and pass level. On a grade of outside work, the pass level is a whole number naming one of the question's levels above the lowest. |
|
|
86
100
|
| `threshold` | The task's threshold, applied as `TaskBoard.hire`, `grade`, `rule` and `ruleAppeal` do, gives the outcome the board emitted. A poster can raise the grade and ruling thresholds while the task is open, so they can be higher than when it was posted; they cannot change after the hire. A ruling on appeal (set 3.5.0 and later) is checked against the board's `AppealRuled` event. A change is queued only on a yes. |
|
|
@@ -95,6 +109,7 @@ The verdict is `match`, `withheld`, `UNVERIFIED` or `MISMATCH`. `withheld` means
|
|
|
95
109
|
Some checks skip by design:
|
|
96
110
|
|
|
97
111
|
- A decision the board never applied, because a later decision or a closed window settled the task, skips `threshold`.
|
|
112
|
+
- A brief the host does not have, or one at a location the tool refuses, skips `brief`. A grade's confidence is then recomputed from the record's own pass level, and `levels` skips.
|
|
98
113
|
- A grade recorded before the chain gated on the paid levels skips `confidence-recomputed`: its confidence is Jev's score confidence, which the probabilities alone do not give.
|
|
99
114
|
- A grade or ruling recorded before BrainChain ran a brief's checks skips `checks` when its brief carries some. Such a record has no `jevPaid`, which every later grade and ruling states unless its panel decided without Jev.
|
|
100
115
|
- A grade of outside work skips `checks` when its brief ends in a checks block and its record holds no run. The section on grades of outside work says why.
|
|
@@ -125,9 +140,9 @@ The chain holds the hash too. A decision's `payloadURI` in its `Recorded` event
|
|
|
125
140
|
|
|
126
141
|
### Receipts
|
|
127
142
|
|
|
128
|
-
Every job an agent pays BrainChain for gets a receipt, signed by the key that records decisions. A paid grade gets one once
|
|
143
|
+
Every job an agent pays BrainChain for gets a receipt, signed by the key that records decisions. A paid grade gets one once BrainChain decides it. A paid task gets one once the board pays or refunds it, for the grade or ruling it settled on. Receipts come with a brain release that is not yet live on mainnet, so no record there carries one yet, and records from before that release never will. The receipt is EIP-712 under the domain `BrainChain receipt`, version 1, on the DecisionLog, in the envelope of the x402 offer-and-receipt extension (version 0.6): `{ format, payload, signature }`.
|
|
129
144
|
|
|
130
|
-
For
|
|
145
|
+
For a grade or ruling whose record has a `payments` field, the tool asks the host that serves the record for its receipt at `/receipts/<DecisionLog in lowercase>/<decision id>.json`. A record without one, as every record from before receipts is, gets no receipt line. A host that has none yet is a `skip`. A host that does not answer, or answers with an error, is an `ERROR`. `--offline` turns this off, and `--receipt` checks a receipt you kept instead.
|
|
131
146
|
|
|
132
147
|
On a receipt, the tool checks that:
|
|
133
148
|
|
|
@@ -136,7 +151,7 @@ On a receipt, the tool checks that:
|
|
|
136
151
|
- for a task, the board paid it for `accepted` and refunded it for `rejected`, and the last grade or ruling it applied is this decision. For a paid grade, `accepted` means accept at or above the board's grade bar when the decision was recorded.
|
|
137
152
|
- `network`, `asset`, `amount`, `payer` and `transaction` are those of a payment in the record, and on that network the transaction moved `amount` of `asset` from `payer` to the desk. The desk is the `payTo` for that network in the brain host's `/network.json`, which the tool believes only when `brain()` on the active DecisionLog signed it. A desk's former addresses count on EVM networks.
|
|
138
153
|
|
|
139
|
-
The tool reads payments on Base, Robinhood Chain and Solana, and on their testnets, from their public RPCs.
|
|
154
|
+
The tool reads payments on Base, Robinhood Chain and Solana, and on their testnets, from their public RPCs. A `/network.json` signed by another key, or naming another chain, fails `receipt-payment`. A host with no `/network.json`, or a payment on a network the tool has no RPC for, skips it. A host or RPC that does not answer is an `ERROR`, and so is a payment transaction the RPC does not find yet, since a node that lags or a Solana transaction not yet finalized can miss one. Only a transaction that reverted, or failed on Solana, fails.
|
|
140
155
|
|
|
141
156
|
### Keeping a receipt
|
|
142
157
|
|
|
@@ -167,6 +182,64 @@ Its answer and confidence are checked, and the confidence is recomputed from the
|
|
|
167
182
|
|
|
168
183
|
A paid grade runs the checks sent with its request. BrainChain appends them to the brief as its last block, and `checks` holds their run to the same rule as a task's. A caller can also write such a block into the brief's own text, where nothing runs it, and the record reads the same either way. So a brief that ends in a checks block with no run is a `skip`. An ACP evaluation runs no checks.
|
|
169
184
|
|
|
185
|
+
## Reputation entries
|
|
186
|
+
|
|
187
|
+
Each task that settles for a registered worker becomes one entry in the ERC-8004 reputation registry on Robinhood Chain (`0x8004BAa17C55a88189AE136b182e5fdA19dE9b63`). The value is 100 when the board paid the bounty and 0 when it refunded it, under the tags `brainchain` and `task`, and the endpoint is the task's page. An entry for a task an agent paid BrainChain for points at the task's signed [receipt](#receipts): `feedbackURI` is where the receipt is served, and `feedbackHash` is the `keccak256` of the receipt as served there. Every other entry names the task page again and carries a zero hash. That covers house tasks, tasks posted straight on the board, ACP orders and entries written before receipts.
|
|
188
|
+
|
|
189
|
+
```sh
|
|
190
|
+
npx brainchain-verify mainnet --entry 20424:7
|
|
191
|
+
npx brainchain-verify mainnet --entry 20424:0xafB0C4Ef895D4895040cdC6435B96D3EE8350c6E:12
|
|
192
|
+
npx brainchain-verify mainnet --agent 20424 --json
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The registry names an entry by its agent id, the address that wrote it and its index, which counts from 1 for each agent and writer. `--entry` takes the three in that order, separated by colons. BrainChain writes from `0x97D558417c3D61f1074422AD843e1Db1E565b952`, and wrote from `0xafB0C4Ef895D4895040cdC6435B96D3EE8350c6E` before 10 November 2026. Leave the writer out for an entry from the first. Anyone can write under the same tags, so the tool reads entries from these two addresses only.
|
|
196
|
+
|
|
197
|
+
On an entry, the tool checks, in order:
|
|
198
|
+
|
|
199
|
+
| Check | What passes |
|
|
200
|
+
| --- | --- |
|
|
201
|
+
| `entry` | The entry's `NewFeedback` event and the registry's `readFeedback` agree. The tags are `brainchain` and `task`, and the value is 100 or 0 with no decimals. |
|
|
202
|
+
| `endpoint` | The endpoint is a task page naming the task and its board, and the board is in one of the contract sets the tool carries. Entries written before 5 November name the task alone. Task ids restart with each board, so `endpoint` skips on them and the task's checks do not run. |
|
|
203
|
+
| `feedback-hash` | The `keccak256` of the bytes served at `feedbackURI` equals `feedbackHash`. A zero hash is a `skip` that reads `no receipt`. |
|
|
204
|
+
| `entry-receipt` | The receipt is one BrainChain signs. It names a decision its DecisionLog holds, in one of the contract sets the tool carries, and `feedbackURI` is that decision's receipt address. |
|
|
205
|
+
| the decision's checks | The decision the receipt names, checked as any decision is, with this receipt. That covers its record, its evidence hash, and the receipt's signature, outcome and payment. The lines keep their names. |
|
|
206
|
+
| `entry-task` | The decision's subject is `subjectOf(task)` on the board the endpoint names. |
|
|
207
|
+
| `entry-value` | The board paid the task for 100 and refunded it for 0. With a receipt, its outcome is `accepted` for 100 and `rejected` for 0. |
|
|
208
|
+
| `entry-worker` | The board's `WorkerHired` event for the task names the agent. A house worker is hired by the `keccak256` of its model name, so agent 20424 is `keccak256("claude")`. The tool carries the five house agents, 20424 to 20428, as [Worker models](https://docs.usebrainchain.com/workers#erc-8004-identity) lists them. An outside worker is hired by its address, left-padded to 32 bytes. That address must have owned the agent, or been its registered wallet, on the identity registry (`0x8004A169FB4a3325136EB29fA0ceB6D2e539a432`) when the board hired it. |
|
|
209
|
+
|
|
210
|
+
The public RPC for Robinhood Chain keeps no past state, so the tool replays the agent's transfers and wallet changes on the identity registry up to the hire's block time. A transfer clears the wallet, as the registry does.
|
|
211
|
+
|
|
212
|
+
```text
|
|
213
|
+
$ npx brainchain-verify mainnet --entry 20424:7
|
|
214
|
+
Entry 20424:7 in the ERC-8004 reputation registry on Robinhood Chain (0x8004BAa17C55a88189AE136b182e5fdA19dE9b63)
|
|
215
|
+
|
|
216
|
+
ok entry: value 100 for agent 20424 under brainchain and task, written by 0x97D5…b952 in block 114772689, as the registry holds it
|
|
217
|
+
ok endpoint: task 49 on board 0x44b8…A211, contract set v3-5
|
|
218
|
+
skip no receipt: the entry's feedbackHash is zero. Only a task an agent paid BrainChain for has a signed receipt; house tasks, tasks posted straight on the board, ACP orders and older entries have none
|
|
219
|
+
ok value: 100, as the board paid task 49
|
|
220
|
+
ok worker: the board hired claude for task 49 as keccak256("claude"), and agent 20424 is the house worker claude
|
|
221
|
+
|
|
222
|
+
Verdict: no receipt. No signed receipt backs this entry, and the checks the chain allows without one passed.
|
|
223
|
+
Not checked: that Jev produced the answer. See https://docs.usebrainchain.com/trust-model
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
An entry's verdict is `match`, `no receipt`, `withheld`, `MISMATCH` or `UNVERIFIED`. `no receipt` means the hash is zero and every check that could run passed. `withheld` is a decision record served without the work, as for any decision.
|
|
227
|
+
|
|
228
|
+
`--agent` gives one line per entry: its verdict, its name and what it is about. Below an entry go the lines of any check that failed or could not run. The last line counts the entries, those with a receipt, those whose receipt and decision fully matched, those withheld, and those that failed. A withheld entry is never counted as verified. `--entry` with a name from the list shows every check.
|
|
229
|
+
|
|
230
|
+
```text
|
|
231
|
+
$ npx brainchain-verify mainnet --agent 20425
|
|
232
|
+
Agent 20425 in the ERC-8004 reputation registry on Robinhood Chain (0x8004BAa17C55a88189AE136b182e5fdA19dE9b63): 8 entries BrainChain wrote
|
|
233
|
+
|
|
234
|
+
no receipt 20425:0xafB0C4Ef895D4895040cdC6435B96D3EE8350c6E:1 value 100, task 1
|
|
235
|
+
no receipt 20425:0xafB0C4Ef895D4895040cdC6435B96D3EE8350c6E:4 value 100, task 22 in set v3-5
|
|
236
|
+
no receipt 20425:2 value 100, task 41 in set v3-5
|
|
237
|
+
|
|
238
|
+
8 entries, 0 with a receipt, 0 verified, 0 failed.
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Trimmed to three entries.
|
|
242
|
+
|
|
170
243
|
## What it cannot check
|
|
171
244
|
|
|
172
245
|
That Jev produced the answer. BrainChain records Jev's answers, and the contracts bound what a recorded answer can do. A decision that passes every check has the question, answer and probabilities the chain acted on. The [trust model](https://docs.usebrainchain.com/trust-model) explains what the chain relies on and what bounds it.
|
|
@@ -176,12 +249,12 @@ That Jev produced the answer. BrainChain records Jev's answers, and the contract
|
|
|
176
249
|
| Code | Meaning |
|
|
177
250
|
| --- | --- |
|
|
178
251
|
| 0 | Every check that could run passed. Skips do not fail a decision. A `withheld` verdict also exits 0, so read the verdict if you need to tell it from a full match. |
|
|
179
|
-
| 1 | A check failed, a
|
|
252
|
+
| 1 | A check failed, a check could not run (an `ERROR` line, such as a record, brief or receipt the host did not serve), or the decision or entry could not be read: an unknown id, a task with no decisions, an entry the registry does not hold, an RPC error, a `--receipt` that cannot be read or is not a receipt. |
|
|
180
253
|
| 2 | Bad arguments, or an RPC that serves another chain. |
|
|
181
254
|
|
|
182
255
|
## JSON
|
|
183
256
|
|
|
184
|
-
`--json` prints one object. `decisions` holds one entry, or one per decision with `--task`. `verdict` is `match`, `withheld`, `mismatch` or `unverified` (a
|
|
257
|
+
`--json` prints one object. `decisions` holds one entry, or one per decision with `--task`. `verdict` is `match`, `withheld`, `mismatch` or `unverified` (a check could not run). With `withheld`, `withheldNotChecked` says what was left out, and the decision carries `withheld: true`. A decision about a task whose brief was read carries `title`, as the header shows it. A grade of outside work carries `outside: true`. A grade or ruling that holds a run of its brief's checks carries `run`, with the run's `language` and `outcome`. A grade or ruling decided by a panel carries `panel`: its `rule`, `judges` with each judge that answered by `model` and `paid`, Jev first, and `degraded`. A degraded panel also carries `missing` and `bar`. These are the record's own values, and the `judge` and `panel` checks say whether they recompute. A decision whose record matched the evidence hash on chain carries it as `evidence`. A decision whose receipt was checked carries `receipt`: where it was read as `from`, and the `job` and `outcome` it states. Each check keeps its `name` across releases, and its `status` is `ok`, `fail`, `skip` or `error`. When the tool cannot run, it prints `{ "error": "..." }` and exits 1, or 2 for bad arguments or an RPC that serves another chain. Trimmed to one check:
|
|
185
258
|
|
|
186
259
|
```json
|
|
187
260
|
{
|
|
@@ -204,6 +277,7 @@ That Jev produced the answer. BrainChain records Jev's answers, and the contract
|
|
|
204
277
|
"id": 22,
|
|
205
278
|
"kind": "grade",
|
|
206
279
|
"task": 11,
|
|
280
|
+
"title": "Compare the rule of 72 with the exact doubling time",
|
|
207
281
|
"block": 419,
|
|
208
282
|
"recordedAt": "2026-11-01 00:40:23 UTC",
|
|
209
283
|
"confidenceBps": 8000,
|
|
@@ -219,6 +293,8 @@ That Jev produced the answer. BrainChain records Jev's answers, and the contract
|
|
|
219
293
|
}
|
|
220
294
|
```
|
|
221
295
|
|
|
296
|
+
With `--entry` or `--agent`, the object holds `registry`, `verdict`, `summary` and `entries` instead of `set` and `decisions`, and `agentId` with `--agent`. `verdict` is `match`, `no-receipt`, `withheld`, `mismatch` or `unverified`. It is `no-receipt` only when every check passed and no entry had a receipt. `summary` counts `entries`, `withReceipt`, `verified`, `withheld`, `failed` and `unverified`. `verified` counts only entries whose verdict is `match`. Each entry carries its name as `entry`, the fields of its `NewFeedback` event, the `task`, `board` and `set` its endpoint names, the `decision` its receipt names with its `id`, `set` and `kind`, its own `verdict` and its `checks`.
|
|
297
|
+
|
|
222
298
|
## Building
|
|
223
299
|
|
|
224
300
|
```sh
|
package/dist/abi.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by scripts/abi.mjs from
|
|
1
|
+
// Generated by scripts/abi.mjs from usebrainchain/brainchain 348cc37. Do not edit.
|
|
2
2
|
export const decisionLogAbi = [
|
|
3
3
|
{ "type": "function", "name": "acceptOwnership", "inputs": [], "outputs": [], "stateMutability": "nonpayable" },
|
|
4
4
|
{ "type": "function", "name": "allowApp", "inputs": [{ "name": "app", "type": "bytes32", "internalType": "bytes32" }, { "name": "allowed", "type": "bool", "internalType": "bool" }], "outputs": [], "stateMutability": "nonpayable" },
|
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import { createPublicClient,
|
|
3
|
+
import { createPublicClient, isAddress } from "viem";
|
|
4
4
|
import { decisionLogAbi, taskBoardAbi } from "./abi.js";
|
|
5
5
|
import { NETWORKS } from "./deployments.js";
|
|
6
|
-
import { clean, decisionsOf, errorMessage, outcomeOf, readReceipt, receiptDecision, verifyDecision, withheldNotChecked, } from "./verify.js";
|
|
6
|
+
import { clean, decisionsOf, entriesOf, entryName, entryOutcome, entryReport, entrySummary, errorMessage, isReceipt, outcomeOf, readReceipt, receiptDecision, REPUTATION, rpcTransport, verifyDecision, verifyEntry, withheldNotChecked, } from "./verify.js";
|
|
7
7
|
const USAGE = `Usage:
|
|
8
8
|
brainchain-verify <mainnet|testnet|chainId> <decisionId> [--set <TaskBoard>] [--rpc <url>] [--offline] [--json]
|
|
9
9
|
brainchain-verify <mainnet|testnet|chainId> --task <taskId> [--set <TaskBoard>] [--rpc <url>] [--offline] [--json]
|
|
10
10
|
brainchain-verify <mainnet|testnet|chainId> [<decisionId>] --receipt <file|url> [--set <TaskBoard>] [--rpc <url>] [--json]
|
|
11
|
+
brainchain-verify mainnet --entry <agentId>:[<writer>:]<feedbackIndex> [--rpc <url>] [--registry-rpc <url>] [--json]
|
|
12
|
+
brainchain-verify mainnet --agent <agentId> [--rpc <url>] [--registry-rpc <url>] [--json]
|
|
11
13
|
|
|
12
14
|
Checks a BrainChain decision against the chain: reads it from the DecisionLog,
|
|
13
15
|
fetches the published record, recomputes its hashes and confidence, and applies
|
|
@@ -16,20 +18,29 @@ the task's thresholds as the contracts do. Needs no keys.
|
|
|
16
18
|
--task <id> check every decision about one task
|
|
17
19
|
--receipt <r> check the receipt for a paid job, from a file or a URL, against
|
|
18
20
|
the decision it names, or the one given
|
|
21
|
+
--entry <e> check one ERC-8004 reputation entry BrainChain wrote: the entry,
|
|
22
|
+
its receipt, the decision and payment the receipt names, and the
|
|
23
|
+
task, value and worker on the board. The writer is needed only
|
|
24
|
+
for an entry from an address BrainChain no longer writes from
|
|
25
|
+
--agent <id> check every entry BrainChain wrote for one agent
|
|
19
26
|
--offline fetch no receipt from the brain host
|
|
20
27
|
--set <board> a retired contract set from 3.0.0 on, by TaskBoard address, by
|
|
21
28
|
its key on the site (v3-1) or by release (3.1.0); without it, the
|
|
22
29
|
active set
|
|
23
30
|
--rpc <url> another RPC for the same chain; records and briefs on private
|
|
24
31
|
addresses are read only when this is on one too
|
|
32
|
+
--registry-rpc <url>
|
|
33
|
+
another RPC for Robinhood Chain, where the registries are
|
|
25
34
|
--json one JSON object on stdout
|
|
26
35
|
--version print the version
|
|
27
36
|
|
|
28
37
|
Exit status: 0 when every check that could run matches, 1 on a mismatch or when
|
|
29
38
|
a decision or its record cannot be read, 2 on bad arguments.`;
|
|
30
39
|
const TRUST_MODEL = "https://docs.usebrainchain.com/trust-model";
|
|
40
|
+
const NOT_CHECKED = "That Jev produced the answer. BrainChain records Jev's answers, and the contracts bound what a recorded answer can do.";
|
|
31
41
|
// Sets before 3.0.0 named tasks by id alone, which the subject check does not model, so the package carries none.
|
|
32
42
|
const BEFORE_3 = /^(v2(-|$)|2\.|0x83b31d99fa31a9e5257955a737ef34c40f1c57bf$)/i;
|
|
43
|
+
// Only a command line of the wrong shape gets the usage. A value that names nothing the tool can read gets a message that says what would.
|
|
33
44
|
function usage(message) {
|
|
34
45
|
if (json)
|
|
35
46
|
fail(message, 2);
|
|
@@ -53,13 +64,16 @@ const flag = (name) => {
|
|
|
53
64
|
if (value === undefined || value.startsWith("--"))
|
|
54
65
|
usage(`${name} needs a value`);
|
|
55
66
|
args.splice(at, 2);
|
|
67
|
+
if (args.includes(name))
|
|
68
|
+
usage(`${name} given twice`);
|
|
56
69
|
return value;
|
|
57
70
|
};
|
|
71
|
+
// A switch given twice means the same as once.
|
|
58
72
|
const toggle = (name) => {
|
|
59
|
-
const
|
|
60
|
-
|
|
73
|
+
const given = args.length;
|
|
74
|
+
for (let at = args.indexOf(name); at >= 0; at = args.indexOf(name))
|
|
61
75
|
args.splice(at, 1);
|
|
62
|
-
return
|
|
76
|
+
return args.length < given;
|
|
63
77
|
};
|
|
64
78
|
const json = toggle("--json");
|
|
65
79
|
const offline = toggle("--offline");
|
|
@@ -67,12 +81,18 @@ const taskArg = flag("--task");
|
|
|
67
81
|
const setArg = flag("--set");
|
|
68
82
|
const rpcArg = flag("--rpc");
|
|
69
83
|
const receiptArg = flag("--receipt");
|
|
84
|
+
const entryArg = flag("--entry");
|
|
85
|
+
const agentArg = flag("--agent");
|
|
86
|
+
const registryRpcArg = flag("--registry-rpc");
|
|
70
87
|
// -1 is a bad id, not an option; the id check below says so.
|
|
71
88
|
const unknown = args.find((arg) => arg.startsWith("-") && !/^-\d/.test(arg));
|
|
72
89
|
if (unknown)
|
|
73
90
|
usage(`Unknown option ${unknown}`);
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
const web = (url) => URL.canParse(url) && ["http:", "https:"].includes(new URL(url).protocol);
|
|
92
|
+
if (rpcArg !== undefined && !web(rpcArg))
|
|
93
|
+
fail("--rpc needs an http or https URL", 2);
|
|
94
|
+
if (registryRpcArg !== undefined && !web(registryRpcArg))
|
|
95
|
+
fail("--registry-rpc needs an http or https URL", 2);
|
|
76
96
|
const [networkArg, idArg, ...extra] = args;
|
|
77
97
|
if (networkArg === undefined)
|
|
78
98
|
usage("Name a network: mainnet, testnet or a chain id");
|
|
@@ -80,23 +100,40 @@ if (extra.length > 0 || (taskArg !== undefined && idArg !== undefined))
|
|
|
80
100
|
usage("Too many arguments");
|
|
81
101
|
if (taskArg !== undefined && receiptArg !== undefined)
|
|
82
102
|
usage("A receipt is for one decision: name it, not a task");
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
const reputation = entryArg !== undefined || agentArg !== undefined;
|
|
104
|
+
if (reputation && (idArg !== undefined || taskArg !== undefined || receiptArg !== undefined || setArg !== undefined || offline)) {
|
|
105
|
+
usage("An entry names its own task, decision and receipt, so --entry and --agent take only --rpc, --registry-rpc and --json");
|
|
106
|
+
}
|
|
107
|
+
if (!reputation && registryRpcArg !== undefined)
|
|
108
|
+
usage("--registry-rpc is for --entry and --agent");
|
|
109
|
+
if (entryArg !== undefined && agentArg !== undefined)
|
|
110
|
+
usage("Name one entry with --entry, or an agent with --agent");
|
|
111
|
+
if (!reputation && taskArg === undefined && idArg === undefined && receiptArg === undefined)
|
|
112
|
+
usage("Name a decision id, a task with --task, or an entry with --entry");
|
|
85
113
|
const given = taskArg ?? idArg;
|
|
86
114
|
if (given !== undefined && !/^[1-9]\d*$/.test(given))
|
|
87
|
-
|
|
115
|
+
fail(`${taskArg === undefined ? "A decision" : "A task"} id is a whole number from 1`, 2);
|
|
88
116
|
const foundNetwork = Object.hasOwn(NETWORKS, networkArg)
|
|
89
117
|
? NETWORKS[networkArg]
|
|
90
118
|
: Object.values(NETWORKS).find((n) => String(n.chainId) === networkArg);
|
|
91
119
|
if (!foundNetwork)
|
|
92
|
-
|
|
120
|
+
fail(`Unknown network "${networkArg}": use mainnet, testnet, 274663 or 274630`, 2);
|
|
93
121
|
const network = foundNetwork;
|
|
94
|
-
const client = createPublicClient({ transport:
|
|
122
|
+
const client = createPublicClient({ transport: rpcTransport("BrainChain", rpcArg ?? network.rpc) });
|
|
123
|
+
const TAGS = { ok: "ok", fail: "FAIL", skip: "skip", error: "ERROR" };
|
|
124
|
+
const tally = (checks, status) => checks.filter((c) => c.status === status).length;
|
|
125
|
+
// With --task or --agent, one decision or entry the RPC cannot read is an error line of its own, and the rest still run.
|
|
126
|
+
const unread = (what, error) => ({ name: "rpc", status: "error", message: `could not check ${what}: ${errorMessage(error)}` });
|
|
127
|
+
const ENTRY_TAGS = { match: "match", "no-receipt": "no receipt", withheld: "withheld", mismatch: "MISMATCH", unverified: "UNVERIFIED" };
|
|
128
|
+
if (reputation)
|
|
129
|
+
await checkEntries();
|
|
95
130
|
const receipt = receiptArg === undefined ? undefined : await readReceipt(client, receiptArg).catch((error) => fail(errorMessage(error)));
|
|
131
|
+
if (receipt && !isReceipt(receipt.value))
|
|
132
|
+
fail(`${receipt.from} is not a receipt as BrainChain or the x402 extension signs one`);
|
|
96
133
|
const named = receipt && receiptDecision(receipt.value);
|
|
97
134
|
const target = given ?? named?.decision;
|
|
98
135
|
if (target === undefined || !/^[1-9]\d*$/.test(target))
|
|
99
|
-
|
|
136
|
+
fail("The receipt names no decision; give the decision's id", 2);
|
|
100
137
|
// A receipt names its log, so it opens a retired set on its own.
|
|
101
138
|
const receiptSet = named && network.sets.find((s) => s.log.toLowerCase() === named.decisionLog.toLowerCase());
|
|
102
139
|
const foundSet = setArg === undefined
|
|
@@ -104,9 +141,9 @@ const foundSet = setArg === undefined
|
|
|
104
141
|
: network.sets.find((s) => (isAddress(setArg) ? s.board.toLowerCase() === setArg.toLowerCase() : s.key === setArg || s.release === setArg || s.aliases?.includes(setArg)));
|
|
105
142
|
if (!foundSet) {
|
|
106
143
|
if (setArg !== undefined && BEFORE_3.test(setArg))
|
|
107
|
-
|
|
144
|
+
fail(`Contract set ${setArg} predates release 3.0.0, which this tool does not read: those boards named tasks by id alone.`, 2);
|
|
108
145
|
const sets = network.sets.map((s, i) => `${s.key} (TaskBoard ${s.board}${i === 0 ? ", active" : ""})`);
|
|
109
|
-
|
|
146
|
+
fail(`No contract set ${setArg} on ${network.name}. Sets: ${sets.join(", ")}`, 2);
|
|
110
147
|
}
|
|
111
148
|
const set = foundSet;
|
|
112
149
|
const ctx = { client, network, set, briefs: new Map(), offline };
|
|
@@ -117,8 +154,6 @@ function fail(message, status = 1) {
|
|
|
117
154
|
console.error(clean(message));
|
|
118
155
|
process.exit(status);
|
|
119
156
|
}
|
|
120
|
-
const TAGS = { ok: "ok", fail: "FAIL", skip: "skip", error: "ERROR" };
|
|
121
|
-
const tally = (checks, status) => checks.filter((c) => c.status === status).length;
|
|
122
157
|
function verdict(reports) {
|
|
123
158
|
const all = reports.flatMap((r) => r.checks);
|
|
124
159
|
const failed = tally(all, "fail");
|
|
@@ -127,7 +162,7 @@ function verdict(reports) {
|
|
|
127
162
|
case "mismatch":
|
|
128
163
|
return `Verdict: MISMATCH. ${failed} check${failed === 1 ? "" : "s"} failed; see the FAIL lines.`;
|
|
129
164
|
case "unverified":
|
|
130
|
-
return "Verdict: UNVERIFIED.
|
|
165
|
+
return "Verdict: UNVERIFIED. Some checks could not run; the ERROR lines say what could not be read.";
|
|
131
166
|
case "withheld":
|
|
132
167
|
return `Verdict: withheld, not a full match${many ? ` (decision${reports.filter((r) => r.withheld).length === 1 ? "" : "s"} ${reports.filter((r) => r.withheld).map((r) => r.id).join(", ")})` : ""}. ${withheldNotChecked(reports)}`;
|
|
133
168
|
case "match":
|
|
@@ -149,6 +184,7 @@ function report(reports, header, task) {
|
|
|
149
184
|
id: r.id,
|
|
150
185
|
kind: r.kind,
|
|
151
186
|
task: r.task,
|
|
187
|
+
...(r.title ? { title: r.title } : {}),
|
|
152
188
|
...(r.outside ? { outside: true } : {}),
|
|
153
189
|
...(r.withheld ? { withheld: true } : {}),
|
|
154
190
|
...(r.run ? { run: r.run } : {}),
|
|
@@ -173,7 +209,7 @@ function report(reports, header, task) {
|
|
|
173
209
|
skipped,
|
|
174
210
|
decisions,
|
|
175
211
|
...(overall === "withheld" ? { withheldNotChecked: withheldNotChecked(reports) } : {}),
|
|
176
|
-
notChecked:
|
|
212
|
+
notChecked: NOT_CHECKED,
|
|
177
213
|
trustModel: TRUST_MODEL,
|
|
178
214
|
};
|
|
179
215
|
console.log(JSON.stringify(out, null, 2));
|
|
@@ -189,23 +225,159 @@ function report(reports, header, task) {
|
|
|
189
225
|
console.log(`Not checked: that Jev produced the answer. See ${TRUST_MODEL}`);
|
|
190
226
|
process.exit(failed + errors > 0 ? 1 : 0);
|
|
191
227
|
}
|
|
192
|
-
|
|
193
|
-
const chainId = await
|
|
228
|
+
async function sameChain(registry) {
|
|
229
|
+
const chainId = await client.getChainId();
|
|
194
230
|
if (chainId !== network.chainId)
|
|
195
|
-
|
|
231
|
+
fail(`The RPC serves chain ${chainId}, not ${network.name} (${network.chainId})`, 2);
|
|
232
|
+
const registryChain = await registry?.client.getChainId();
|
|
233
|
+
if (registry && registryChain !== registry.chainId)
|
|
234
|
+
fail(`The registry RPC serves chain ${registryChain}, not Robinhood Chain (${registry.chainId})`, 2);
|
|
235
|
+
}
|
|
236
|
+
function entryVerdict(r) {
|
|
237
|
+
const failed = tally(r.checks, "fail");
|
|
238
|
+
switch (entryOutcome([r])) {
|
|
239
|
+
case "mismatch":
|
|
240
|
+
return `Verdict: MISMATCH. ${failed} check${failed === 1 ? "" : "s"} failed; see the FAIL lines.`;
|
|
241
|
+
case "unverified":
|
|
242
|
+
return "Verdict: UNVERIFIED. Some checks could not run; the ERROR lines say what could not be read.";
|
|
243
|
+
case "withheld":
|
|
244
|
+
return `Verdict: withheld, not a full match. ${withheldNotChecked([r.decision])}`;
|
|
245
|
+
case "no-receipt":
|
|
246
|
+
return "Verdict: no receipt. No signed receipt backs this entry, and the checks the chain allows without one passed.";
|
|
247
|
+
case "match":
|
|
248
|
+
if (tally(r.checks, "skip") > 0)
|
|
249
|
+
return "Verdict: match. Every check that could run passed; the skip lines say what could not be checked.";
|
|
250
|
+
return "Verdict: match. The entry, its receipt, the decision and payment the receipt names, and the task on the board agree with the chain.";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/** What an entry is about, on its line in an agent's list. */
|
|
254
|
+
function about(r) {
|
|
255
|
+
const task = r.task === undefined ? `endpoint ${r.endpoint}` : `task ${r.task}${r.set ? ` in set ${r.set}` : r.board ? ` on board ${r.board}` : ""}`;
|
|
256
|
+
return `value ${r.value}, ${task}${r.decision ? `, decision ${r.decision.id}` : ""}`;
|
|
257
|
+
}
|
|
258
|
+
function reportEntries(reports, header, agentId) {
|
|
259
|
+
const outcomes = reports.map((r) => entryOutcome([r]));
|
|
260
|
+
const summary = entrySummary(reports);
|
|
261
|
+
const all = reports.flatMap((r) => r.checks);
|
|
262
|
+
const status = tally(all, "fail") + tally(all, "error") > 0 ? 1 : 0;
|
|
263
|
+
if (json) {
|
|
264
|
+
const entries = reports.map(({ checks, decision, ...r }, i) => ({
|
|
265
|
+
...r,
|
|
266
|
+
...(decision ? { decision: { id: decision.id, set: decision.set, kind: decision.kind, ...(decision.task === undefined ? {} : { task: decision.task }) } } : {}),
|
|
267
|
+
verdict: outcomes[i],
|
|
268
|
+
checks,
|
|
269
|
+
}));
|
|
270
|
+
const out = {
|
|
271
|
+
network: network.name,
|
|
272
|
+
chainId: network.chainId,
|
|
273
|
+
registry: { chainId: REPUTATION.chainId, address: REPUTATION.address, writers: REPUTATION.writers },
|
|
274
|
+
...(agentId === undefined ? {} : { agentId }),
|
|
275
|
+
verdict: entryOutcome(reports),
|
|
276
|
+
summary,
|
|
277
|
+
entries,
|
|
278
|
+
notChecked: NOT_CHECKED,
|
|
279
|
+
trustModel: TRUST_MODEL,
|
|
280
|
+
};
|
|
281
|
+
console.log(JSON.stringify(out, null, 2));
|
|
282
|
+
process.exit(status);
|
|
283
|
+
}
|
|
284
|
+
console.log(`${header}\n`);
|
|
285
|
+
const [one] = reports;
|
|
286
|
+
if (agentId === undefined && one) {
|
|
287
|
+
for (const c of one.checks)
|
|
288
|
+
console.log(` ${TAGS[c.status].padEnd(5)} ${c.message}`);
|
|
289
|
+
console.log(`\n${entryVerdict(one)}`);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
for (const [i, r] of reports.entries()) {
|
|
293
|
+
console.log(` ${ENTRY_TAGS[outcomes[i]].padEnd(10)} ${r.entry} ${about(r)}`);
|
|
294
|
+
for (const c of r.checks)
|
|
295
|
+
if (c.status === "fail" || c.status === "error")
|
|
296
|
+
console.log(` ${TAGS[c.status].padEnd(5)} ${c.message}`);
|
|
297
|
+
}
|
|
298
|
+
const { entries, withReceipt, verified, withheld, failed, unverified } = summary;
|
|
299
|
+
console.log(`\n${entries} entr${entries === 1 ? "y" : "ies"}, ${withReceipt} with a receipt, ${verified} verified${withheld > 0 ? `, ${withheld} withheld` : ""}, ${failed} failed${unverified > 0 ? `, ${unverified} could not be checked` : ""}.`);
|
|
300
|
+
}
|
|
301
|
+
console.log(`Not checked: that Jev produced the answer. See ${TRUST_MODEL}`);
|
|
302
|
+
process.exit(status);
|
|
303
|
+
}
|
|
304
|
+
/** --entry and --agent: BrainChain's entries in the ERC-8004 reputation registry, each checked through its receipt to the chain. */
|
|
305
|
+
async function checkEntries() {
|
|
306
|
+
if (network.chainId !== REPUTATION.network)
|
|
307
|
+
fail("BrainChain writes reputation entries for mainnet tasks only, so --entry and --agent read mainnet", 2);
|
|
308
|
+
const registry = { ...REPUTATION, client: createPublicClient({ transport: rpcTransport("Robinhood Chain", registryRpcArg ?? REPUTATION.rpc) }) };
|
|
309
|
+
const [current, ...earlier] = registry.writers;
|
|
310
|
+
const where = `in the ERC-8004 reputation registry on Robinhood Chain (${registry.address})`;
|
|
311
|
+
const ctx = { client, network, set: network.sets[0], briefs: new Map() };
|
|
312
|
+
if (entryArg !== undefined) {
|
|
313
|
+
const parts = /^(0|[1-9]\d{0,77}):(?:(0x[0-9a-fA-F]{40}):)?([1-9]\d{0,19})$/.exec(entryArg);
|
|
314
|
+
if (!parts)
|
|
315
|
+
fail("An entry is <agentId>:<feedbackIndex>, or <agentId>:<writer>:<feedbackIndex> for one BrainChain wrote from an earlier address", 2);
|
|
316
|
+
const named = parts[2];
|
|
317
|
+
const writer = named === undefined ? current : registry.writers.find((w) => w.toLowerCase() === named.toLowerCase());
|
|
318
|
+
if (!writer)
|
|
319
|
+
fail(`BrainChain writes its entries from ${registry.writers.join(" and ")}, not ${named}`, 2);
|
|
320
|
+
const agentId = BigInt(parts[1]);
|
|
321
|
+
const index = BigInt(parts[3]);
|
|
322
|
+
try {
|
|
323
|
+
await sameChain(registry);
|
|
324
|
+
const found = await entriesOf(registry, agentId, [writer]);
|
|
325
|
+
const entry = found.find((f) => f.feedbackIndex === index);
|
|
326
|
+
if (!entry) {
|
|
327
|
+
const held = found.length === 0 ? `has written no entry for agent ${agentId}` : `wrote entries 1 to ${found.at(-1).feedbackIndex} for agent ${agentId}`;
|
|
328
|
+
const hint = named === undefined && earlier.length > 0 ? `. It wrote earlier ones from ${earlier.join(" and ")}: name one as ${agentId}:<writer>:<feedbackIndex>` : "";
|
|
329
|
+
fail(`BrainChain ${held} from ${writer}${hint}`);
|
|
330
|
+
}
|
|
331
|
+
reportEntries([await verifyEntry(ctx, registry, entry)], `Entry ${entryName(registry, entry)} ${where}`);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
fail(errorMessage(error));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (!/^(0|[1-9]\d{0,77})$/.test(agentArg))
|
|
338
|
+
fail("An agent id is a whole number", 2);
|
|
339
|
+
const agentId = BigInt(agentArg);
|
|
340
|
+
try {
|
|
341
|
+
await sameChain(registry);
|
|
342
|
+
const found = await entriesOf(registry, agentId);
|
|
343
|
+
if (found.length === 0)
|
|
344
|
+
fail(`BrainChain has written no entry for agent ${agentId} ${where}`);
|
|
345
|
+
const reports = [];
|
|
346
|
+
for (const f of found)
|
|
347
|
+
reports.push(await verifyEntry(ctx, registry, f).catch((error) => entryReport(registry, f, [unread(`entry ${entryName(registry, f)}`, error)])));
|
|
348
|
+
reportEntries(reports, `Agent ${agentId} ${where}: ${found.length} entr${found.length === 1 ? "y" : "ies"} BrainChain wrote`, agentId.toString());
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
fail(errorMessage(error));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/** The other sets whose boards hold a task with this id, for a task this set's board does not hold or decided nothing on. */
|
|
355
|
+
async function otherBoards(task) {
|
|
356
|
+
const others = network.sets.filter((s) => s !== set);
|
|
357
|
+
// Only a hint, so a board the RPC cannot read is left out of it.
|
|
358
|
+
const counts = await Promise.allSettled(others.map((s) => client.readContract({ address: s.board, abi: taskBoardAbi, functionName: "count" })));
|
|
359
|
+
const holding = others.filter((_, i) => {
|
|
360
|
+
const count = counts[i];
|
|
361
|
+
return count.status === "fulfilled" && count.value >= task;
|
|
362
|
+
});
|
|
363
|
+
return holding.length > 0 ? ` Each set numbers its own tasks; try --set ${holding.map((s) => s.key).join(" or ")}.` : "";
|
|
364
|
+
}
|
|
365
|
+
try {
|
|
366
|
+
await sameChain();
|
|
196
367
|
const where = `on ${network.name}, contract set ${set.key}`;
|
|
197
368
|
if (taskArg !== undefined) {
|
|
198
369
|
const task = BigInt(taskArg);
|
|
199
370
|
const tasks = await ctx.client.readContract({ address: set.board, abi: taskBoardAbi, functionName: "count" });
|
|
200
371
|
if (task > tasks)
|
|
201
|
-
fail(`TaskBoard ${set.board} (set ${set.key}) holds tasks 1 to ${tasks}`);
|
|
372
|
+
fail(`TaskBoard ${set.board} (set ${set.key}) holds tasks 1 to ${tasks}.${await otherBoards(task)}`);
|
|
202
373
|
const ids = await decisionsOf(ctx, task);
|
|
203
374
|
if (ids.length === 0)
|
|
204
|
-
fail(`Task ${task} has no decisions ${where}`);
|
|
375
|
+
fail(`Task ${task} has no decisions ${where}.${await otherBoards(task)}`);
|
|
205
376
|
const reports = [];
|
|
206
377
|
for (const id of ids)
|
|
207
|
-
reports.push(await verifyDecision(ctx, id));
|
|
208
|
-
|
|
378
|
+
reports.push(await verifyDecision(ctx, id).catch((error) => ({ id: Number(id), checks: [unread(`decision ${id}`, error)] })));
|
|
379
|
+
const title = reports.find((r) => r.title)?.title;
|
|
380
|
+
report(reports, `Task ${task} ${where} (TaskBoard ${set.board}): decision${ids.length === 1 ? "" : "s"} ${ids.join(", ")}${title ? `\nBrief: ${title}` : ""}`, Number(task));
|
|
209
381
|
}
|
|
210
382
|
const id = BigInt(target);
|
|
211
383
|
const decisions = await ctx.client.readContract({ address: set.log, abi: decisionLogAbi, functionName: "count" });
|
|
@@ -214,7 +386,9 @@ try {
|
|
|
214
386
|
const hint = others.length > 0 ? ` Each set numbers its own decisions; try --set ${others.join(" or ")}.` : "";
|
|
215
387
|
fail(`DecisionLog ${set.log} (set ${set.key}) holds decisions 1 to ${decisions}.${hint}`);
|
|
216
388
|
}
|
|
217
|
-
|
|
389
|
+
const checked = await verifyDecision(ctx, id, receipt);
|
|
390
|
+
// What the task is about, so a decision read from the wrong set does not pass for the one meant.
|
|
391
|
+
report([checked], `Decision ${id} ${where} (DecisionLog ${set.log})${checked.title ? `\nTask ${checked.task}: ${checked.title}` : ""}`);
|
|
218
392
|
}
|
|
219
393
|
catch (error) {
|
|
220
394
|
fail(errorMessage(error));
|