@atrib/attest 0.0.0
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/LICENSE +216 -0
- package/README.md +187 -0
- package/dist/annotate.d.ts +56 -0
- package/dist/annotate.js +135 -0
- package/dist/attest.d.ts +69 -0
- package/dist/attest.js +214 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +729 -0
- package/dist/index.d.ts +312 -0
- package/dist/index.js +1028 -0
- package/dist/keys.d.ts +21 -0
- package/dist/keys.js +134 -0
- package/dist/local-substrate-host.d.ts +93 -0
- package/dist/local-substrate-host.js +467 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +18 -0
- package/dist/reference-resolution.d.ts +12 -0
- package/dist/reference-resolution.js +31 -0
- package/dist/revise.d.ts +43 -0
- package/dist/revise.js +133 -0
- package/dist/session-checkpoint.d.ts +103 -0
- package/dist/session-checkpoint.js +285 -0
- package/dist/sign.d.ts +69 -0
- package/dist/sign.js +74 -0
- package/dist/storage.d.ts +27 -0
- package/dist/storage.js +59 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
|
204
|
+
Copyright 2025-2026 atrib contributors
|
|
205
|
+
|
|
206
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
207
|
+
you may not use this file except in compliance with the License.
|
|
208
|
+
You may obtain a copy of the License at
|
|
209
|
+
|
|
210
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
211
|
+
|
|
212
|
+
Unless required by applicable law or agreed to in writing, software
|
|
213
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
214
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
215
|
+
implied. See the License for the specific language governing
|
|
216
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# `@atrib/attest`
|
|
2
|
+
|
|
3
|
+
atrib's write-verb home. One `attest` tool signs observations, annotations,
|
|
4
|
+
and revisions under the agent's own atrib identity. The legacy `emit`,
|
|
5
|
+
`atrib-annotate`, and `atrib-revise` tool names stay mounted as permanent
|
|
6
|
+
aliases over the same handler, so records are byte-identical in canonical
|
|
7
|
+
form regardless of which name signed them. This is the attest/recall rename
|
|
8
|
+
([D164](../../DECISIONS.md#d164-attestrecall-verb-rename-and-primitive-surface-collapse)).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @atrib/attest
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Verify a local build with `pnpm --filter @atrib/attest test`.
|
|
17
|
+
|
|
18
|
+
## Why this exists
|
|
19
|
+
|
|
20
|
+
`@atrib/mcp` middleware auto-signs every MCP tool call as it passes through.
|
|
21
|
+
That captures the mechanical record-of-tool-call. But agents do cognitive
|
|
22
|
+
work that doesn't go through MCP: reasoning steps, decisions, annotations
|
|
23
|
+
against prior records, and revisions of a prior position all live in the
|
|
24
|
+
agent's prose, not in a tool invocation. `attest` is the explicit signing
|
|
25
|
+
tool the agent calls when it wants on-chain provenance for one of these.
|
|
26
|
+
|
|
27
|
+
## The `attest` tool
|
|
28
|
+
|
|
29
|
+
One handler, one `ref` argument decides the record shape:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
attest({
|
|
33
|
+
// Required. Free-form semantic content; committed through the default
|
|
34
|
+
// args_hash per D099. For annotations: { importance, summary, topics? }.
|
|
35
|
+
// For revisions: { prior_position, new_position }.
|
|
36
|
+
content: Record<string, unknown>,
|
|
37
|
+
|
|
38
|
+
// Optional: the declared relationship decides the signed record shape.
|
|
39
|
+
// There is no event_type argument; absent ref signs an observation.
|
|
40
|
+
ref?: {
|
|
41
|
+
kind: "annotates",
|
|
42
|
+
target: string, // sha256:<64-hex> record_hash to annotate
|
|
43
|
+
} | {
|
|
44
|
+
kind: "revises",
|
|
45
|
+
target: string, // sha256:<64-hex> record_hash to revise
|
|
46
|
+
reason: string, // REQUIRED for a revision; composed into content
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
// Optional, same as the legacy emit tool
|
|
50
|
+
context_id?: string,
|
|
51
|
+
informed_by?: string[],
|
|
52
|
+
allow_unresolved_informed_by?: boolean,
|
|
53
|
+
chain_root?: string,
|
|
54
|
+
provenance_token?: string,
|
|
55
|
+
tool_name?: string,
|
|
56
|
+
args_hash?: string,
|
|
57
|
+
result_hash?: string,
|
|
58
|
+
producer?: string, // sidecar label override; defaults to 'atrib-attest'
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Ref mapping
|
|
63
|
+
|
|
64
|
+
| `ref` argument | Signed record | Signed field carried |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| absent | observation | none |
|
|
67
|
+
| `{ kind: "annotates", target, ... }` | annotation | signed `annotates` field |
|
|
68
|
+
| `{ kind: "revises", target, reason, ... }` (`reason` required) | revision | signed `revises` field |
|
|
69
|
+
|
|
70
|
+
The three shapes route through the same `handleEmit` funnel used by the
|
|
71
|
+
legacy tools. There is no separate signing path for `attest`: the ref
|
|
72
|
+
argument decides which event_type byte and which signed field get attached
|
|
73
|
+
before the record goes through the shared sign-and-mirror pipeline.
|
|
74
|
+
|
|
75
|
+
## Legacy write tools stay mounted
|
|
76
|
+
|
|
77
|
+
`emit`, `atrib-annotate`, and `atrib-revise` remain mounted as permanent
|
|
78
|
+
aliases during the alias window described in the attest/recall rename
|
|
79
|
+
([D164](../../DECISIONS.md#d164-attestrecall-verb-rename-and-primitive-surface-collapse)).
|
|
80
|
+
Calling `atrib-annotate` and calling `attest` with `ref.kind: "annotates"`
|
|
81
|
+
against the same target produce byte-identical annotation records: same key,
|
|
82
|
+
same chain state, same `handleEmit` funnel. Only the `_local.producer`
|
|
83
|
+
sidecar label differs between the two call paths.
|
|
84
|
+
|
|
85
|
+
## Byte-identity
|
|
86
|
+
|
|
87
|
+
A verifier cannot distinguish a record signed through `attest` from one
|
|
88
|
+
signed through the legacy `emit`/`atrib-annotate`/`atrib-revise` names. Same
|
|
89
|
+
signing key, same canonical form, same chain composition. The only
|
|
90
|
+
observable difference is the `_local.producer` sidecar label, which is
|
|
91
|
+
metadata for local mirror consumers, not signed protocol bytes.
|
|
92
|
+
|
|
93
|
+
## Bins
|
|
94
|
+
|
|
95
|
+
- **`atrib-attest`**: the MCP server. Long-lived stdio child. Serves the
|
|
96
|
+
four-tool write union: `attest` plus the three legacy write tool names
|
|
97
|
+
(`emit`, `atrib-annotate`, `atrib-revise`).
|
|
98
|
+
- **`atrib-attest-cli`**: an in-process CLI, same wire contract as
|
|
99
|
+
`atrib-emit-cli`. Reads one JSON envelope on stdin, signs the record
|
|
100
|
+
in-process, writes the output JSON to stdout. Default producer label is
|
|
101
|
+
derived from the invoked bin name (`atrib-attest-cli` for this bin,
|
|
102
|
+
`atrib-emit-cli` when invoked under that name).
|
|
103
|
+
|
|
104
|
+
The legacy bins `atrib-emit`, `atrib-emit-cli`, `atrib-local-substrate`,
|
|
105
|
+
`atrib-annotate`, and `atrib-revise` still forward to this package's
|
|
106
|
+
handlers through the `@atrib/emit`, `@atrib/annotate`, and `@atrib/revise`
|
|
107
|
+
re-export shims.
|
|
108
|
+
|
|
109
|
+
## Programmatic surface
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import {
|
|
113
|
+
createAtribAttestServer, // mounts the four-tool write union
|
|
114
|
+
createAtribEmitServer, // legacy factory; also mounts attest
|
|
115
|
+
createAtribAnnotateServer, // legacy factory; also mounts attest
|
|
116
|
+
createAtribReviseServer, // legacy factory; also mounts attest
|
|
117
|
+
handleAttest,
|
|
118
|
+
attestInProcess,
|
|
119
|
+
|
|
120
|
+
// Re-exported legacy emit surface
|
|
121
|
+
handleEmit,
|
|
122
|
+
emitInProcess,
|
|
123
|
+
EmitInput,
|
|
124
|
+
resolveKey,
|
|
125
|
+
emitSessionCheckpoint,
|
|
126
|
+
} from "@atrib/attest";
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Each legacy factory (`createAtribEmitServer`, `createAtribAnnotateServer`,
|
|
130
|
+
`createAtribReviseServer`) mounts `attest` alongside its own named tool, so
|
|
131
|
+
any MCP host wired to a legacy factory still gets the two-verb surface.
|
|
132
|
+
|
|
133
|
+
## Configuration
|
|
134
|
+
|
|
135
|
+
Environment variables are unchanged from the legacy emit surface:
|
|
136
|
+
`ATRIB_PRIVATE_KEY`, `ATRIB_KEY_FILE`, `ATRIB_MIRROR_FILE`,
|
|
137
|
+
`ATRIB_LOG_ENDPOINT`, `ATRIB_CONTEXT_ID`, `ATRIB_AUTOCHAIN_SOURCE`,
|
|
138
|
+
`ATRIB_AGENT`, `ATRIB_KEYCHAIN_ACCOUNT`, `ATRIB_KEY_RESOLVE_RETRY_MS`,
|
|
139
|
+
`ATRIB_REQUIRE_EXPLICIT_CONTEXT_ID`, `CLAUDE_CODE_SESSION_ID`,
|
|
140
|
+
`CODEX_THREAD_ID`, `ATRIB_PARENT_RECORD_HASH`,
|
|
141
|
+
`ATRIB_LOCAL_SUBSTRATE_ENDPOINT`, `ATRIB_LOCAL_SUBSTRATE_MODE`,
|
|
142
|
+
`ATRIB_LOCAL_SUBSTRATE_TIMEOUT_MS`. See
|
|
143
|
+
[`services/atrib-emit/README.md`](../atrib-emit/README.md) for the full
|
|
144
|
+
table with descriptions; the values and resolution order carried over
|
|
145
|
+
unchanged.
|
|
146
|
+
|
|
147
|
+
## Degradation and privacy
|
|
148
|
+
|
|
149
|
+
atrib failures never affect the primary call ([spec §5.8](../../atrib-spec.md#58-degradation-contract)), and for the write
|
|
150
|
+
verb that contract is the most important thing to know:
|
|
151
|
+
|
|
152
|
+
- **Log endpoint unreachable.** `attest` still returns `signed: true` with
|
|
153
|
+
the `record_hash`, the mirror write to `~/.atrib/records/` lands before
|
|
154
|
+
the tool returns, and log submission is queued and retried silently in
|
|
155
|
+
the background. The `warnings` array names the degradation (for example
|
|
156
|
+
"submission queued; proof not yet available"). Nothing throws; nothing
|
|
157
|
+
blocks.
|
|
158
|
+
- **What stays local vs what reaches the public log.** The full `content`
|
|
159
|
+
body stays in the local mirror's `_local` sidecar; the signed record
|
|
160
|
+
carries only the replay-checkable `args_hash` commitment over it. The
|
|
161
|
+
public log stores the 90-byte commitment entry (record hash, creator key,
|
|
162
|
+
context_id, timestamp, event_type byte), never the content.
|
|
163
|
+
- **Refused writes are loud, not silent.** A malformed call (unknown
|
|
164
|
+
`ref.kind`, missing revises reason, a `ref`/content contradiction, a
|
|
165
|
+
provenance_token off genesis, or no resolvable signing key) returns
|
|
166
|
+
`signed: false` with a `refusals` array over the MCP error surface and
|
|
167
|
+
signs nothing. The CLI exits 3 on refusal and still prints the structured
|
|
168
|
+
JSON, so hook callers can absorb the exit code without losing the reason.
|
|
169
|
+
- **No key, no crash.** With no resolvable signing key the server stays up
|
|
170
|
+
and every write refuses with the key-resolution hint; pass-through per
|
|
171
|
+
[§5.8](../../atrib-spec.md#58-degradation-contract).
|
|
172
|
+
|
|
173
|
+
## Conformance
|
|
174
|
+
|
|
175
|
+
The attest/recall byte-identity, ref-mapping, and alias-window guarantees
|
|
176
|
+
are pinned by the shared corpus at
|
|
177
|
+
[`spec/conformance/attest-recall/`](../../spec/conformance/attest-recall/):
|
|
178
|
+
byte-identity, ref-mapping, read-equivalence, alias-window,
|
|
179
|
+
persisted-labels, and frozen-constants.
|
|
180
|
+
|
|
181
|
+
## Part of atrib
|
|
182
|
+
|
|
183
|
+
atrib is an open protocol for verifiable agent actions. Every action becomes
|
|
184
|
+
a signed, chain-linked record that anyone can verify against a public
|
|
185
|
+
Merkle log, with no operator to trust. This package is one entrypoint. See
|
|
186
|
+
the [full package family](https://github.com/creatornader/atrib#packages)
|
|
187
|
+
and the [protocol spec](../../atrib-spec.md).
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type EmitLocalSubstrateShadowOptions, type WriteToolDeps } from './index.js';
|
|
4
|
+
import { type ResolvedKey } from './keys.js';
|
|
5
|
+
export declare const Importance: z.ZodEnum<{
|
|
6
|
+
high: "high";
|
|
7
|
+
critical: "critical";
|
|
8
|
+
medium: "medium";
|
|
9
|
+
low: "low";
|
|
10
|
+
noise: "noise";
|
|
11
|
+
}>;
|
|
12
|
+
export declare const AnnotateInput: z.ZodObject<{
|
|
13
|
+
annotates: z.ZodString;
|
|
14
|
+
importance: z.ZodEnum<{
|
|
15
|
+
high: "high";
|
|
16
|
+
critical: "critical";
|
|
17
|
+
medium: "medium";
|
|
18
|
+
low: "low";
|
|
19
|
+
noise: "noise";
|
|
20
|
+
}>;
|
|
21
|
+
summary: z.ZodString;
|
|
22
|
+
topics: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
+
context_id: z.ZodOptional<z.ZodString>;
|
|
24
|
+
informed_by: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
export interface AtribAnnotateServer {
|
|
27
|
+
/** Underlying McpServer; expose for testing or composition. */
|
|
28
|
+
mcp: McpServer;
|
|
29
|
+
/** Drain pending submissions (for tests/shutdown). */
|
|
30
|
+
flush(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export interface CreateAtribAnnotateServerOptions {
|
|
33
|
+
/** Override the resolved key (primarily for testing). */
|
|
34
|
+
key?: ResolvedKey | null | undefined;
|
|
35
|
+
/** Override the log endpoint (defaults to env or @atrib/mcp default). */
|
|
36
|
+
logEndpoint?: string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Optional long-lived-agent local substrate shadow probe. `undefined` reads
|
|
39
|
+
* opt-in env config; `false` disables env config for this server.
|
|
40
|
+
*/
|
|
41
|
+
localSubstrate?: EmitLocalSubstrateShadowOptions | false | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Register the legacy `atrib-annotate` tool. The handler call shape is
|
|
45
|
+
* unchanged from the standalone @atrib/annotate server (no logEndpoint or
|
|
46
|
+
* reference-resolver threading), so historical behavior is preserved
|
|
47
|
+
* exactly; only the mounting surface moved.
|
|
48
|
+
*/
|
|
49
|
+
export declare function registerAnnotateTool(mcp: McpServer, deps: WriteToolDeps): void;
|
|
50
|
+
/**
|
|
51
|
+
* Wire up the legacy atrib-annotate MCP server. Mounts `atrib-annotate`
|
|
52
|
+
* plus `attest` (alias-window rule W1). The underlying signing pipeline is
|
|
53
|
+
* shared via handleEmit so annotation records are byte-identical regardless
|
|
54
|
+
* of which tool produced them.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createAtribAnnotateServer(options?: CreateAtribAnnotateServerOptions): Promise<AtribAnnotateServer>;
|
package/dist/annotate.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The legacy `atrib-annotate` tool: cognitive primitive #2 of D079, kept as
|
|
3
|
+
// a permanent alias over the attest write funnel. Narrows the schema to the
|
|
4
|
+
// annotation event_type (spec §1.2.7 / D058) with the annotation-specific
|
|
5
|
+
// required fields (annotates + importance + summary). The signing + chain
|
|
6
|
+
// composition path is byte-identical to `attest` with ref.kind='annotates';
|
|
7
|
+
// a verifier MUST NOT distinguish annotation records by the tool name that
|
|
8
|
+
// signed them.
|
|
9
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { createSubmissionQueue, EVENT_TYPE_ANNOTATION_URI } from '@atrib/mcp';
|
|
12
|
+
import { handleEmit, registerAttestTool, resolveEmitLocalSubstrateShadowFromEnv, } from './index.js';
|
|
13
|
+
import { resolveKey } from './keys.js';
|
|
14
|
+
const SHA256_REF_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
15
|
+
const HEX_32_PATTERN = /^[0-9a-f]{32}$/;
|
|
16
|
+
export const Importance = z.enum(['critical', 'high', 'medium', 'low', 'noise']);
|
|
17
|
+
export const AnnotateInput = z.object({
|
|
18
|
+
annotates: z.string().regex(SHA256_REF_PATTERN).describe("'sha256:<64-hex>' record_hash this annotation describes per spec §1.2.7 / D058. " +
|
|
19
|
+
'REQUIRED. The target record can be any prior record (yours or another agent\'s).'),
|
|
20
|
+
importance: Importance.describe('Felt importance for future-self recall ranking. ' +
|
|
21
|
+
"'critical' (decisions that shape future recall, identity claims), " +
|
|
22
|
+
"'high' (worth surfacing in default recall), " +
|
|
23
|
+
"'medium' (general signal), " +
|
|
24
|
+
"'low' (background noting), " +
|
|
25
|
+
"'noise' (deliberately deprioritized for recall)."),
|
|
26
|
+
summary: z.string().min(1).max(2048).describe('One-line semantic gist of the annotation. The recall pipeline reads this verbatim ' +
|
|
27
|
+
'for snippet display; keep it under ~120 chars when possible. ' +
|
|
28
|
+
'Distinct from the annotated record\'s own content, this summary captures what ' +
|
|
29
|
+
'future-you should know about why this record matters.'),
|
|
30
|
+
topics: z.array(z.string().min(1).max(128)).max(16).optional().describe('Optional topic tags. Used by recall\'s topics filter. ' +
|
|
31
|
+
'Lowercase-hyphenated convention (e.g. "bug-fix", "design-decision").'),
|
|
32
|
+
context_id: z.string().regex(HEX_32_PATTERN).optional().describe('32-hex context_id. Defaults to process.env.ATRIB_CONTEXT_ID per D078 when omitted; ' +
|
|
33
|
+
'falls back to a fresh genesis context_id if neither is set.'),
|
|
34
|
+
informed_by: z.array(z.string().regex(SHA256_REF_PATTERN)).optional().describe("Array of 'sha256:<64-hex>' record_hashes that informed this annotation. " +
|
|
35
|
+
'Sorted lexicographically before signing per §1.2.5. The `annotates` reference ' +
|
|
36
|
+
'is separate from `informed_by` and need not be duplicated here.'),
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Register the legacy `atrib-annotate` tool. The handler call shape is
|
|
40
|
+
* unchanged from the standalone @atrib/annotate server (no logEndpoint or
|
|
41
|
+
* reference-resolver threading), so historical behavior is preserved
|
|
42
|
+
* exactly; only the mounting surface moved.
|
|
43
|
+
*/
|
|
44
|
+
export function registerAnnotateTool(mcp, deps) {
|
|
45
|
+
const localSubstrate = deps.options.localSubstrate === false
|
|
46
|
+
? undefined
|
|
47
|
+
: (deps.options.localSubstrate ??
|
|
48
|
+
resolveEmitLocalSubstrateShadowFromEnv({
|
|
49
|
+
producer: 'atrib-annotate',
|
|
50
|
+
transport: 'stdio-mcp-server',
|
|
51
|
+
}));
|
|
52
|
+
mcp.registerTool('atrib-annotate', {
|
|
53
|
+
description: 'Mark a past record\'s importance and meaning without superseding it. ' +
|
|
54
|
+
'Produces a signed annotation event (spec §1.2.7 / D058) that adds an ' +
|
|
55
|
+
'ANNOTATES graph edge to the target. Use when you want future-self or ' +
|
|
56
|
+
'other agents to read back this past record with weighted importance and ' +
|
|
57
|
+
'a one-line gist. Legacy alias: new callers should prefer `attest` with ' +
|
|
58
|
+
'ref.kind="annotates"; records are byte-identical either way.',
|
|
59
|
+
inputSchema: AnnotateInput.shape,
|
|
60
|
+
}, async (rawInput) => {
|
|
61
|
+
const input = AnnotateInput.parse(rawInput);
|
|
62
|
+
const result = await handleEmit({
|
|
63
|
+
input: {
|
|
64
|
+
event_type: EVENT_TYPE_ANNOTATION_URI,
|
|
65
|
+
content: {
|
|
66
|
+
annotates: input.annotates,
|
|
67
|
+
importance: input.importance,
|
|
68
|
+
summary: input.summary,
|
|
69
|
+
...(input.topics ? { topics: input.topics } : {}),
|
|
70
|
+
},
|
|
71
|
+
annotates: input.annotates,
|
|
72
|
+
...(input.context_id ? { context_id: input.context_id } : {}),
|
|
73
|
+
...(input.informed_by ? { informed_by: input.informed_by } : {}),
|
|
74
|
+
},
|
|
75
|
+
key: await deps.resolveServerKey(),
|
|
76
|
+
queue: deps.queue,
|
|
77
|
+
producer: 'atrib-annotate',
|
|
78
|
+
...(localSubstrate ? { localSubstrate } : {}),
|
|
79
|
+
});
|
|
80
|
+
if (!result.signed) {
|
|
81
|
+
return {
|
|
82
|
+
isError: true,
|
|
83
|
+
content: [{ type: 'text', text: result.refusals.join('\n') }],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const out = {
|
|
87
|
+
signed: true,
|
|
88
|
+
record_hash: result.record_hash,
|
|
89
|
+
log_index: result.log_index,
|
|
90
|
+
inclusion_proof: result.inclusion_proof,
|
|
91
|
+
context_id: result.context_id,
|
|
92
|
+
warnings: result.warnings,
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
content: [{ type: 'text', text: JSON.stringify(out, null, 2) }],
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Wire up the legacy atrib-annotate MCP server. Mounts `atrib-annotate`
|
|
101
|
+
* plus `attest` (alias-window rule W1). The underlying signing pipeline is
|
|
102
|
+
* shared via handleEmit so annotation records are byte-identical regardless
|
|
103
|
+
* of which tool produced them.
|
|
104
|
+
*/
|
|
105
|
+
export async function createAtribAnnotateServer(options = {}) {
|
|
106
|
+
const deps = buildAnnotateWriteToolDeps(options);
|
|
107
|
+
const mcp = new McpServer({ name: 'atrib-annotate', version: '0.1.0' });
|
|
108
|
+
registerAnnotateTool(mcp, deps);
|
|
109
|
+
registerAttestTool(mcp, deps);
|
|
110
|
+
return {
|
|
111
|
+
mcp,
|
|
112
|
+
flush: () => deps.queue.flush(),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function buildAnnotateWriteToolDeps(options) {
|
|
116
|
+
const logEndpoint = options.logEndpoint ?? process.env['ATRIB_LOG_ENDPOINT'];
|
|
117
|
+
const queue = createSubmissionQueue(logEndpoint);
|
|
118
|
+
return {
|
|
119
|
+
resolveServerKey: createServerKeyResolver(options),
|
|
120
|
+
queue,
|
|
121
|
+
logEndpoint,
|
|
122
|
+
options,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function createServerKeyResolver(options) {
|
|
126
|
+
if (Object.prototype.hasOwnProperty.call(options, 'key')) {
|
|
127
|
+
const fixed = options.key ?? null;
|
|
128
|
+
return async () => fixed;
|
|
129
|
+
}
|
|
130
|
+
let resolved = null;
|
|
131
|
+
return async () => {
|
|
132
|
+
resolved ??= resolveKey();
|
|
133
|
+
return resolved;
|
|
134
|
+
};
|
|
135
|
+
}
|
package/dist/attest.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const AttestRef: z.ZodObject<{
|
|
3
|
+
kind: z.ZodEnum<{
|
|
4
|
+
annotates: "annotates";
|
|
5
|
+
revises: "revises";
|
|
6
|
+
}>;
|
|
7
|
+
target: z.ZodString;
|
|
8
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export declare const AttestInput: z.ZodObject<{
|
|
11
|
+
content: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
12
|
+
ref: z.ZodOptional<z.ZodObject<{
|
|
13
|
+
kind: z.ZodEnum<{
|
|
14
|
+
annotates: "annotates";
|
|
15
|
+
revises: "revises";
|
|
16
|
+
}>;
|
|
17
|
+
target: z.ZodString;
|
|
18
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
context_id: z.ZodOptional<z.ZodString>;
|
|
21
|
+
informed_by: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
22
|
+
allow_unresolved_informed_by: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
chain_root: z.ZodOptional<z.ZodString>;
|
|
24
|
+
provenance_token: z.ZodOptional<z.ZodString>;
|
|
25
|
+
tool_name: z.ZodOptional<z.ZodString>;
|
|
26
|
+
args_hash: z.ZodOptional<z.ZodString>;
|
|
27
|
+
result_hash: z.ZodOptional<z.ZodString>;
|
|
28
|
+
producer: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type AttestInputT = z.infer<typeof AttestInput>;
|
|
31
|
+
/**
|
|
32
|
+
* The EmitInput-shaped object handleEmit accepts, plus the resolved
|
|
33
|
+
* event_type so callers can surface it in the attest result.
|
|
34
|
+
*/
|
|
35
|
+
export interface MappedAttestInput {
|
|
36
|
+
event_type: string;
|
|
37
|
+
emitInput: {
|
|
38
|
+
event_type: string;
|
|
39
|
+
content: Record<string, unknown>;
|
|
40
|
+
context_id?: string;
|
|
41
|
+
informed_by?: string[];
|
|
42
|
+
allow_unresolved_informed_by?: boolean;
|
|
43
|
+
chain_root?: string;
|
|
44
|
+
provenance_token?: string;
|
|
45
|
+
annotates?: string;
|
|
46
|
+
revises?: string;
|
|
47
|
+
tool_name?: string;
|
|
48
|
+
args_hash?: string;
|
|
49
|
+
result_hash?: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface AttestMappingRefusal {
|
|
53
|
+
refusals: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Map an AttestInput onto the legacy EmitInput shape. Pure; no signing.
|
|
57
|
+
* Returns refusals instead of throwing so the tool surface can return the
|
|
58
|
+
* same isError shape the legacy write names use (§5.8: refuse loudly,
|
|
59
|
+
* never sign a malformed record).
|
|
60
|
+
*
|
|
61
|
+
* Content composition matches the legacy specialized writers exactly so
|
|
62
|
+
* the D099 default args_hash is byte-identical:
|
|
63
|
+
* annotates: content := { annotates: target, ...content }
|
|
64
|
+
* revises: content := { revises: target, ...content, reason }
|
|
65
|
+
* A caller-supplied content.annotates / content.revises / content.reason
|
|
66
|
+
* that contradicts `ref` is a refusal, not a silent overwrite.
|
|
67
|
+
*/
|
|
68
|
+
export declare function mapAttestInput(input: AttestInputT): MappedAttestInput | AttestMappingRefusal;
|
|
69
|
+
export declare function isAttestMappingRefusal(mapped: MappedAttestInput | AttestMappingRefusal): mapped is AttestMappingRefusal;
|