@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.
@@ -0,0 +1,312 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import { type LocalSubstrateCoordinatorTransport, type LocalSubstrateDegradationPolicy, type LocalSubstrateHarnessClass, type LocalSubstrateProducer, type LocalSubstrateWalJoin, type ProofBundle, type SubmissionQueue, type TryLocalSubstrateCoordinatorResult } from '@atrib/mcp';
4
+ import { type ResolvedKey } from './keys.js';
5
+ import { type RecordReferenceResolver } from './reference-resolution.js';
6
+ import { type AttestInputT } from './attest.js';
7
+ declare function keyResolveRetryMs(): number;
8
+ export declare function requiresExplicitContextId(env?: NodeJS.ProcessEnv): boolean;
9
+ declare const EmitInput: z.ZodObject<{
10
+ event_type: z.ZodString;
11
+ content: z.ZodRecord<z.ZodString, z.ZodUnknown>;
12
+ context_id: z.ZodOptional<z.ZodString>;
13
+ informed_by: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
+ allow_unresolved_informed_by: z.ZodOptional<z.ZodBoolean>;
15
+ chain_root: z.ZodOptional<z.ZodString>;
16
+ provenance_token: z.ZodOptional<z.ZodString>;
17
+ annotates: z.ZodOptional<z.ZodString>;
18
+ revises: z.ZodOptional<z.ZodString>;
19
+ tool_name: z.ZodOptional<z.ZodString>;
20
+ args_hash: z.ZodOptional<z.ZodString>;
21
+ result_hash: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strip>;
23
+ type EmitSignedOutput = {
24
+ signed: true;
25
+ record_hash: string;
26
+ log_index: number | null;
27
+ inclusion_proof: ProofBundle['inclusion_proof'] | null;
28
+ context_id: string;
29
+ receipt_id?: string;
30
+ warnings: string[];
31
+ };
32
+ type EmitRefusalOutput = {
33
+ signed: false;
34
+ context_id: string;
35
+ refusals: string[];
36
+ };
37
+ type EmitOutput = EmitSignedOutput | EmitRefusalOutput;
38
+ export interface EmitLocalSubstrateShadowAttempt {
39
+ result: TryLocalSubstrateCoordinatorResult;
40
+ expectedRecordHash: string;
41
+ responseRecordHash?: string;
42
+ recordHashMatches: boolean;
43
+ }
44
+ export interface EmitLocalSubstrateShadowOptions {
45
+ /** Coordinator transport. HTTP, Unix-socket adapters, and tests all plug in here. */
46
+ transport: LocalSubstrateCoordinatorTransport;
47
+ /**
48
+ * Producer envelope written outside the signed record bytes. Defaults to a
49
+ * long-lived-agent envelope for the current process and producer label.
50
+ */
51
+ producer?: LocalSubstrateProducer | undefined;
52
+ /** Per-call timeout for the shadow probe. Defaults to 500ms. */
53
+ timeoutMs?: number | undefined;
54
+ /** Degradation posture written into the coordinator request envelope. */
55
+ fallback?: LocalSubstrateDegradationPolicy | undefined;
56
+ /**
57
+ * Wait for the bounded shadow attempt before returning. Short-lived
58
+ * producers use this so the process does not exit before telemetry lands.
59
+ */
60
+ waitForAttempt?: boolean | undefined;
61
+ /** Observer hook for tests, telemetry, or rollout reports. Never blocks emit. */
62
+ onAttempt?: ((attempt: EmitLocalSubstrateShadowAttempt) => void | Promise<void>) | undefined;
63
+ /** Warning hook for mismatch or observer failures. Never affects emit. */
64
+ onWarning?: ((message: string, detail?: unknown) => void) | undefined;
65
+ }
66
+ export interface EmitLocalSubstrateCommitAttempt {
67
+ result: TryLocalSubstrateCoordinatorResult;
68
+ expectedRecordHash: string;
69
+ responseRecordHash?: string;
70
+ recordHashMatches: boolean;
71
+ }
72
+ export interface EmitLocalSubstrateWalCommitMetadata extends LocalSubstrateWalJoin {
73
+ join_back_target: string;
74
+ }
75
+ export interface EmitLocalSubstrateCommitOptions {
76
+ /** Coordinator transport. HTTP, Unix-socket adapters, and tests all plug in here. */
77
+ transport: LocalSubstrateCoordinatorTransport;
78
+ /** Producer envelope written outside the signed record bytes. */
79
+ producer?: LocalSubstrateProducer | undefined;
80
+ /** Per-call timeout for the commit request. Defaults to 500ms. */
81
+ timeoutMs?: number | undefined;
82
+ /** Degradation posture written into the coordinator request envelope. */
83
+ fallback?: LocalSubstrateDegradationPolicy | undefined;
84
+ /**
85
+ * WAL join-back metadata for watcher-WAL coordinator commits. Omit for a
86
+ * long-lived-agent `sign_record` commit.
87
+ */
88
+ wal?: EmitLocalSubstrateWalCommitMetadata | undefined;
89
+ /** Observer hook for tests, telemetry, or rollout reports. Never blocks fallback. */
90
+ onAttempt?: ((attempt: EmitLocalSubstrateCommitAttempt) => void | Promise<void>) | undefined;
91
+ /** Warning hook for mismatch or observer failures. Never affects emit. */
92
+ onWarning?: ((message: string, detail?: unknown) => void) | undefined;
93
+ }
94
+ export interface ResolveEmitLocalSubstrateShadowFromEnvOptions {
95
+ env?: NodeJS.ProcessEnv | undefined;
96
+ producer?: string | undefined;
97
+ harnessClass?: LocalSubstrateHarnessClass | undefined;
98
+ transport?: string | undefined;
99
+ waitForAttempt?: boolean | undefined;
100
+ fetch?: typeof fetch | undefined;
101
+ }
102
+ export interface ResolveEmitLocalSubstrateCommitFromEnvOptions {
103
+ env?: NodeJS.ProcessEnv | undefined;
104
+ producer?: string | undefined;
105
+ harnessClass?: LocalSubstrateHarnessClass | undefined;
106
+ transport?: string | undefined;
107
+ fetch?: typeof fetch | undefined;
108
+ }
109
+ export interface AtribEmitServer {
110
+ /** Underlying McpServer; expose for testing or composition. */
111
+ mcp: McpServer;
112
+ /** Drain pending submissions (for tests/shutdown). */
113
+ flush(): Promise<void>;
114
+ }
115
+ /** The write-verb server handle. Same shape as the legacy handle. */
116
+ export type AtribAttestServer = AtribEmitServer;
117
+ export interface CreateAtribEmitServerOptions {
118
+ /** Override the resolved key (primarily for testing). */
119
+ key?: ResolvedKey | null | undefined;
120
+ /** Override the log endpoint (defaults to env or @atrib/mcp default). */
121
+ logEndpoint?: string | undefined;
122
+ /** Override informed_by record lookup, primarily for tests and embedded hosts. */
123
+ recordReferenceResolver?: RecordReferenceResolver | undefined;
124
+ /**
125
+ * Optional long-lived-agent local substrate shadow probe. `undefined` reads
126
+ * opt-in env config; `false` disables env config for this server.
127
+ */
128
+ localSubstrate?: EmitLocalSubstrateShadowOptions | false | undefined;
129
+ /**
130
+ * Optional long-lived-agent coordinator commit. `undefined` reads
131
+ * ATRIB_LOCAL_SUBSTRATE_MODE=commit from env unless localSubstrate was set
132
+ * explicitly; `false` disables env commit mode for this server.
133
+ */
134
+ localSubstrateCommit?: EmitLocalSubstrateCommitOptions | false | undefined;
135
+ }
136
+ /** The write-verb options. Same shape as the legacy options. */
137
+ export type CreateAtribAttestServerOptions = CreateAtribEmitServerOptions;
138
+ /**
139
+ * Shared per-server wiring for the write tools: one key resolver + one
140
+ * submission queue per server process, whichever tool names are mounted.
141
+ */
142
+ export interface WriteToolDeps {
143
+ resolveServerKey: () => Promise<ResolvedKey | null>;
144
+ queue: SubmissionQueue;
145
+ logEndpoint: string | undefined;
146
+ options: CreateAtribAttestServerOptions;
147
+ }
148
+ /** Register the legacy `emit` tool (polymorphic event_type surface). */
149
+ export declare function registerEmitTool(mcp: McpServer, deps: WriteToolDeps): void;
150
+ /**
151
+ * Register the `attest` tool: the two-verb surface's write half. Maps the
152
+ * declared relationship (`ref`) onto the legacy EmitInput shape and
153
+ * delegates to the same handleEmit funnel, so attest-signed records are
154
+ * byte-identical in canonical form to legacy-name-signed records.
155
+ */
156
+ export declare function registerAttestTool(mcp: McpServer, deps: WriteToolDeps): void;
157
+ /**
158
+ * Wire up the write-verb union server: `attest` plus the three legacy
159
+ * write names, all dispatching to one handleEmit funnel over one shared
160
+ * key resolver + submission queue. This is what the `atrib-attest` binary
161
+ * serves and what the primitive runtime / daemon mount for writes.
162
+ */
163
+ export declare function createAtribAttestServer(options?: CreateAtribAttestServerOptions): Promise<AtribAttestServer>;
164
+ /**
165
+ * Wire up the legacy atrib-emit MCP server. Mounts `emit` plus `attest`
166
+ * (alias-window rule W1: every existing server also serves the new verb).
167
+ * Returns an AtribEmitServer handle whose `.mcp` is ready to attach to a
168
+ * transport (StdioServerTransport for the standalone binary; in-process
169
+ * transport for tests).
170
+ */
171
+ export declare function createAtribEmitServer(options?: CreateAtribEmitServerOptions): Promise<AtribEmitServer>;
172
+ declare function createServerKeyResolver(options: CreateAtribEmitServerOptions): () => Promise<ResolvedKey | null>;
173
+ interface HandleEmitInput {
174
+ input: z.infer<typeof EmitInput>;
175
+ key: ResolvedKey | null;
176
+ queue: SubmissionQueue;
177
+ /**
178
+ * Producer label written to the sidecar's `_local.producer` field for
179
+ * cross-source disambiguation in mirror queries. Defaults to
180
+ * `'atrib-emit'` for the bare server path; specialized wrappers
181
+ * (`@atrib/annotate`, `@atrib/revise`) pass their own identity so
182
+ * downstream consumers can tell which surface signed each record.
183
+ */
184
+ producer?: string;
185
+ logEndpoint?: string | undefined;
186
+ recordReferenceResolver?: RecordReferenceResolver | undefined;
187
+ localSubstrate?: EmitLocalSubstrateShadowOptions | undefined;
188
+ localSubstrateCommit?: EmitLocalSubstrateCommitOptions | undefined;
189
+ }
190
+ /**
191
+ * Build, sign, submit, mirror. Refused writes return `signed: false`;
192
+ * signed degradations stay `signed: true` and surface in `warnings`.
193
+ */
194
+ declare function handleEmit({ input, key, queue, producer, logEndpoint, recordReferenceResolver, localSubstrate, localSubstrateCommit, }: HandleEmitInput): Promise<EmitOutput>;
195
+ export declare function resolveEmitLocalSubstrateShadowFromEnv(options?: ResolveEmitLocalSubstrateShadowFromEnvOptions): EmitLocalSubstrateShadowOptions | undefined;
196
+ export declare function resolveEmitLocalSubstrateCommitFromEnv(options?: ResolveEmitLocalSubstrateCommitFromEnvOptions): EmitLocalSubstrateCommitOptions | undefined;
197
+ export interface EmitInProcessOptions {
198
+ /** Override the resolved key (primarily for testing). */
199
+ key?: ResolvedKey;
200
+ /** Override the log endpoint (defaults to ATRIB_LOG_ENDPOINT or @atrib/mcp default). */
201
+ logEndpoint?: string | undefined;
202
+ /**
203
+ * Producer label written to the sidecar's `_local.producer` field for
204
+ * cross-source disambiguation. Defaults to `'atrib-emit'`. Callers that
205
+ * represent a distinct surface should pass their own identifier (e.g.
206
+ * `'atrib-emit-cli'` for the CLI binary, `'atrib-annotate'` /
207
+ * `'atrib-revise'` for specialized cognitive primitives) so mirror
208
+ * consumers can bucket records by emitter without inspecting envelopes.
209
+ */
210
+ producer?: string;
211
+ /**
212
+ * Upper bound on the post-sign queue flush, in milliseconds. Default
213
+ * 5000ms. The submission queue itself has a 30s retry budget against an
214
+ * unreachable log (`MAX_WINDOW_MS` in `@atrib/mcp`); without this
215
+ * deadline, a network blip leaves a detached hook process blocked for
216
+ * up to 30s waiting on retries it cannot do anything about. Past the
217
+ * deadline emitInProcess returns the record with a `flush-deadline`
218
+ * warning attached: the record is signed, mirrored, and queued in
219
+ * memory for retry, but `log.atrib.dev` confirmation is not yet
220
+ * established. The hook's own mirror file holds the record either way.
221
+ * Set to a higher value for callers that can afford to wait (an
222
+ * interactive CLI, a service with its own backpressure).
223
+ */
224
+ flushDeadlineMs?: number;
225
+ /** Override informed_by record lookup, primarily for tests and embedded hosts. */
226
+ recordReferenceResolver?: RecordReferenceResolver | undefined;
227
+ /**
228
+ * Optional long-lived-agent local substrate shadow probe. `undefined` reads
229
+ * opt-in env config; `false` disables env config for this call.
230
+ */
231
+ localSubstrate?: EmitLocalSubstrateShadowOptions | false | undefined;
232
+ /**
233
+ * Optional coordinator commit. Without WAL metadata this sends a
234
+ * long-lived-agent `sign_record` commit. With WAL metadata it sends the
235
+ * watcher-WAL receipt join request. When accepted, emitInProcess mirrors the
236
+ * local sidecar but skips its own log submission queue because the
237
+ * coordinator owns that side effect. On rejection or timeout, the existing
238
+ * local queue path remains the fallback.
239
+ */
240
+ localSubstrateCommit?: EmitLocalSubstrateCommitOptions | false | undefined;
241
+ }
242
+ /**
243
+ * Emit one cognitive event in-process, without an MCP transport.
244
+ *
245
+ * This is the canonical in-process entrypoint for callers that already
246
+ * run inside a short-lived Node process (lifecycle/PostToolUse hooks,
247
+ * watchers, batch jobs) and should NOT pay the cost of spawning the
248
+ * atrib-emit binary and running an MCP stdio handshake just to sign one
249
+ * record. It packages the recipe the D079 public-helpers block below
250
+ * documents: resolve key, build a submission queue, call handleEmit,
251
+ * and additionally flushes the queue before returning, because a hook
252
+ * process exits immediately afterward and a still-pending submission
253
+ * would be lost with it.
254
+ *
255
+ * Records are byte-identical to MCP-server-signed and wrapper-signed
256
+ * records: this routes through the same handleEmit path createAtribEmitServer
257
+ * uses. Refused writes return `signed: false`; signed-but-degraded
258
+ * submissions surface in EmitOutput.warnings.
259
+ *
260
+ * The flush is bounded by `flushDeadlineMs` (default 5s). If the log is
261
+ * unreachable, the submission queue's internal retry will overrun the
262
+ * deadline; emitInProcess then returns the record with a `flush-deadline`
263
+ * warning rather than blocking up to 30s. The record is still signed and
264
+ * mirrored locally; only the log-side confirmation is uncertain.
265
+ */
266
+ export declare function emitInProcess(rawInput: unknown, options?: EmitInProcessOptions): Promise<EmitOutput>;
267
+ /** Signed attest output: the emit-family fields plus the mapped event_type. */
268
+ export type AttestOutput = (EmitSignedOutput & {
269
+ event_type: string;
270
+ }) | EmitRefusalOutput;
271
+ export interface HandleAttestInput {
272
+ input: AttestInputT;
273
+ key: ResolvedKey | null;
274
+ queue: SubmissionQueue;
275
+ /** Sidecar label; defaults to 'atrib-attest'. input.producer wins. */
276
+ producer?: string;
277
+ logEndpoint?: string | undefined;
278
+ recordReferenceResolver?: RecordReferenceResolver | undefined;
279
+ localSubstrate?: EmitLocalSubstrateShadowOptions | undefined;
280
+ localSubstrateCommit?: EmitLocalSubstrateCommitOptions | undefined;
281
+ }
282
+ /**
283
+ * The attest handler: map the declared relationship onto the legacy
284
+ * EmitInput shape, then delegate to handleEmit. Byte-identity with the
285
+ * legacy write names holds by construction (one funnel, one signer).
286
+ */
287
+ export declare function handleAttest(args: HandleAttestInput): Promise<AttestOutput>;
288
+ /**
289
+ * Attest one cognitive event in-process, without an MCP transport. The
290
+ * write-verb sibling of emitInProcess: same flush deadline, same
291
+ * degradation posture, same mirror conventions. Default sidecar producer
292
+ * label is 'atrib-attest' ('atrib-attest-cli' when spawned via the CLI
293
+ * binary); the input-level `producer` override wins per §5.9.3.
294
+ */
295
+ export declare function attestInProcess(rawInput: unknown, options?: EmitInProcessOptions): Promise<AttestOutput>;
296
+ export declare const __test_only__: {
297
+ createServerKeyResolver: typeof createServerKeyResolver;
298
+ handleEmit: typeof handleEmit;
299
+ keyResolveRetryMs: typeof keyResolveRetryMs;
300
+ };
301
+ export { handleEmit, EmitInput };
302
+ export type { EmitOutput };
303
+ export { resolveKey } from './keys.js';
304
+ export type { ResolvedKey } from './keys.js';
305
+ export { emitSessionCheckpoint } from './session-checkpoint.js';
306
+ export type { EmitSessionCheckpointOptions, EmitSessionCheckpointResult, } from './session-checkpoint.js';
307
+ export { AttestInput, AttestRef, mapAttestInput, isAttestMappingRefusal } from './attest.js';
308
+ export type { AttestInputT, MappedAttestInput, AttestMappingRefusal } from './attest.js';
309
+ export { AnnotateInput, Importance, createAtribAnnotateServer, registerAnnotateTool, } from './annotate.js';
310
+ export type { AtribAnnotateServer, CreateAtribAnnotateServerOptions } from './annotate.js';
311
+ export { ReviseInput, createAtribReviseServer, registerReviseTool, } from './revise.js';
312
+ export type { AtribReviseServer, CreateAtribReviseServerOptions } from './revise.js';