certal 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +12 -0
- package/README.md +3 -3
- package/dist/mcp/server.js +22 -8
- package/dist/runtime/store.js +9 -2
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "certal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Work through the Certal gate: leases, verified batches and operator approvals for every change.",
|
|
5
5
|
"author": { "name": "Paweł Olszewski" },
|
|
6
6
|
"repository": "https://github.com/polszewski-pl/certal",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.5
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- The HTTP transport sent `413` while the client was still sending the body and then closed the connection. On Windows the client could see a reset connection instead of the status. The body is now read and dropped first, up to 32 MiB, and the answer follows.
|
|
8
|
+
|
|
9
|
+
## 0.1.4
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- `certal verify --offline` reported `CHECKPOINT_STATE_MISMATCH` for an untouched database after a repeated request, for example an approval that was sent twice. The kernel counts a repeated request in the state and writes no log entry for it, so the checkpoint and the replayed state differed in that counter. Since 0.1.1 the audit compared them in full. It now leaves out the two counters that the log cannot give back. Any other difference is still an error.
|
|
14
|
+
|
|
3
15
|
## 0.1.3
|
|
4
16
|
|
|
5
17
|
Fixes from an audit of 0.1.2. The kernel and the Lean model are unchanged.
|
package/README.md
CHANGED
|
@@ -199,13 +199,13 @@ Witness stages run as child processes. The time limit of a stage is the smaller
|
|
|
199
199
|
|
|
200
200
|
**The operator.** `certal init` creates an Ed25519 key in `~/.certal/operator.key` and writes the public key to the manifest. `certal approve` signs an approval token for the exact content of one attempt. Every operator command that reaches a running server is signed with the same key, carries a timestamp and a nonce, and is refused without a valid signature. The operator keys are fixed by the first start of a log: a later manifest edit cannot add an approver.
|
|
201
201
|
|
|
202
|
-
**Agents over HTTP.** The HTTP transport listens on a loopback address only. Every agent named in `--agents` gets a bearer token of its own, and the token alone decides who the caller is. The tokens are files in the operator home, `~/.certal/run/<project id>/agents/<agentId>.token`, not in the project. `certal mcp` prints the directory and removes it when it stops. A request whose `x-certal-agent` header names another agent is refused with `403`. A request above 4 MiB gets `413
|
|
202
|
+
**Agents over HTTP.** The HTTP transport listens on a loopback address only. Every agent named in `--agents` gets a bearer token of its own, and the token alone decides who the caller is. The tokens are files in the operator home, `~/.certal/run/<project id>/agents/<agentId>.token`, not in the project. `certal mcp` prints the directory and removes it when it stops. A request whose `x-certal-agent` header names another agent is refused with `403`. A request above 4 MiB gets `413` after its body was read and dropped (a body above 32 MiB is cut off without an answer), and a request whose content type is not `application/json` gets `415`. A `tools/call` without an id is not run, because the caller could not receive its answer.
|
|
203
203
|
|
|
204
204
|
**Approval channels.** The webhook address must be `https`, or `http` on this machine only. The default channel waits for `certal approve`. The webhook channel posts the binding hash, a summary of the change and the expiry to a URL, and accepts back only a token with a valid operator signature over the same binding.
|
|
205
205
|
|
|
206
206
|
**File watcher.** With `"watch": true`, a file in a declared scope that changes without a matching batch becomes a human edit: it raises the epoch of that scope and evicts a colliding agent lease. A deleted file counts too. Other scopes are not touched. A write that matches the hash declared in a finalized batch is the agent's own and is not reported.
|
|
207
207
|
|
|
208
|
-
**Offline audit.** `certal verify --offline <db>` replays a copy of the database from the first entry. It compares every stored entry with the replayed one, field by field, checks the chain between entries, compares every stored checkpoint with the replayed state at its position, and compares the operation and approval indexes with the log. It needs no manifest: the operator public keys are stored in the database. A running server starts from its newest checkpoint and does not repeat this audit, so run `verify` on a database that someone else could write. `verify` proves that the stored entries are the ones that the stored events give. It does not prove that a field of an event which does not change the outcome, such as a label of the login method, is the one that was first written.
|
|
208
|
+
**Offline audit.** `certal verify --offline <db>` replays a copy of the database from the first entry. It compares every stored entry with the replayed one, field by field, checks the chain between entries, compares every stored checkpoint with the replayed state at its position, and compares the operation and approval indexes with the log. It needs no manifest: the operator public keys are stored in the database. A running server starts from its newest checkpoint and does not repeat this audit, so run `verify` on a database that someone else could write. A repeated request with the same operation id is answered from the record of the first one and leaves no log entry. The kernel counts such requests in the state, so the state hash of a running server can differ from the one that `verify` prints, in two counters only. `verify` leaves these two counters out when it compares a checkpoint. `verify` proves that the stored entries are the ones that the stored events give. It does not prove that a field of an event which does not change the outcome, such as a label of the login method, is the one that was first written.
|
|
209
209
|
|
|
210
210
|
Limits of this layer:
|
|
211
211
|
|
|
@@ -284,7 +284,7 @@ More limits are listed in [formal/README.md](formal/README.md).
|
|
|
284
284
|
## Checks
|
|
285
285
|
|
|
286
286
|
```bash
|
|
287
|
-
npm run check # structure, lint, typecheck,
|
|
287
|
+
npm run check # structure, lint, typecheck, 80 tests, 47 mutants
|
|
288
288
|
npm run check:formal # token scan, clean lake build, axiom audit, 5,005 vectors, 3 model mutations
|
|
289
289
|
npm run check:all # both
|
|
290
290
|
npm run test:bench # latency of the human lane under agent load
|
package/dist/mcp/server.js
CHANGED
|
@@ -16,6 +16,10 @@ export const SUPPORTED_PROTOCOL_VERSIONS = ['2025-06-18', '2025-03-26', '2024-11
|
|
|
16
16
|
export const PROTOCOL_VERSION = SUPPORTED_PROTOCOL_VERSIONS[0];
|
|
17
17
|
/** Largest message that a transport accepts. */
|
|
18
18
|
export const MAX_MESSAGE_BYTES = 4 * 1024 * 1024;
|
|
19
|
+
/** A request above the limit is read and dropped up to this size, so its sender can get the answer 413. Above it the connection is cut. */
|
|
20
|
+
const MAX_DISCARDED_BYTES = 8 * MAX_MESSAGE_BYTES;
|
|
21
|
+
/** Longest wait for the end of a request that is being dropped. */
|
|
22
|
+
const DISCARD_TIMEOUT_MS = 10_000;
|
|
19
23
|
export const AGENT_ID_PATTERN = /^[A-Za-z0-9_.-]{1,64}$/;
|
|
20
24
|
const APPROVAL_REASONS = /APPROVAL/;
|
|
21
25
|
function nextAction(code, reason, onAllow) {
|
|
@@ -509,25 +513,35 @@ export function serveHttp(gateway, listenHost, listenPort, agents = ['agent-1'])
|
|
|
509
513
|
const chunks = [];
|
|
510
514
|
let size = 0;
|
|
511
515
|
let tooLarge = false;
|
|
516
|
+
let giveUp = null;
|
|
512
517
|
req.on('data', (chunk) => {
|
|
513
|
-
if (tooLarge)
|
|
514
|
-
return;
|
|
515
518
|
size += chunk.length;
|
|
519
|
+
if (tooLarge) {
|
|
520
|
+
// A body far above the limit is not read to its end.
|
|
521
|
+
if (size > MAX_DISCARDED_BYTES)
|
|
522
|
+
req.destroy();
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
516
525
|
if (size <= MAX_MESSAGE_BYTES) {
|
|
517
526
|
chunks.push(chunk);
|
|
518
527
|
return;
|
|
519
528
|
}
|
|
520
|
-
//
|
|
521
|
-
//
|
|
529
|
+
// Nothing more is kept. The rest of the body is read and dropped, and the answer goes out when the
|
|
530
|
+
// client has finished sending. An answer that is sent while the client still writes is lost on
|
|
531
|
+
// some systems: the client sees a reset connection instead of the status.
|
|
522
532
|
tooLarge = true;
|
|
523
533
|
chunks.length = 0;
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
setTimeout(() => req.destroy(), 1000).unref();
|
|
534
|
+
giveUp = setTimeout(() => req.destroy(), DISCARD_TIMEOUT_MS);
|
|
535
|
+
giveUp.unref();
|
|
527
536
|
});
|
|
528
537
|
req.on('end', () => {
|
|
529
|
-
if (tooLarge)
|
|
538
|
+
if (tooLarge) {
|
|
539
|
+
if (giveUp)
|
|
540
|
+
clearTimeout(giveUp);
|
|
541
|
+
res.writeHead(413, { 'content-type': 'application/json', connection: 'close' });
|
|
542
|
+
res.end(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32600, message: `request too large: the limit is ${MAX_MESSAGE_BYTES} bytes` } }));
|
|
530
543
|
return;
|
|
544
|
+
}
|
|
531
545
|
let message;
|
|
532
546
|
try {
|
|
533
547
|
message = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
package/dist/runtime/store.js
CHANGED
|
@@ -741,8 +741,15 @@ export function replayFromStore(store, hooks, options) {
|
|
|
741
741
|
if (!stored)
|
|
742
742
|
return;
|
|
743
743
|
checkpointAt.delete(state.serverSeq);
|
|
744
|
-
|
|
745
|
-
|
|
744
|
+
// A repeated request is answered from the record of the first one and leaves no log entry, but the
|
|
745
|
+
// kernel counts it, and it counts the secrets that were redacted in it. The log cannot give these two
|
|
746
|
+
// counters back, so they are left out of the comparison. A live state can only be ahead in them.
|
|
747
|
+
const withoutReplayCounters = (s) => computeStateHash({ ...s, metrics: { ...s.metrics, idempotentReplays: 0, redactedSecretsTotal: 0 } });
|
|
748
|
+
const selfConsistent = computeStateHash(stored.state) === stored.stateHash;
|
|
749
|
+
const sameState = withoutReplayCounters(stored.state) === withoutReplayCounters(state);
|
|
750
|
+
const countersAhead = stored.state.metrics.idempotentReplays >= state.metrics.idempotentReplays &&
|
|
751
|
+
stored.state.metrics.redactedSecretsTotal >= state.metrics.redactedSecretsTotal;
|
|
752
|
+
if (!selfConsistent || !sameState || !countersAhead) {
|
|
746
753
|
throw new Error(`CHECKPOINT_STATE_MISMATCH at seq=${stored.serverSeq}: the stored snapshot is not the state that the log gives`);
|
|
747
754
|
}
|
|
748
755
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "certal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Deterministic execution firewall and runtime for AI agents. Zero dependencies, SQLite WAL, write-ahead outbox, human-priority undo, and Lean 4 proofs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Paweł Olszewski",
|