@sharedcontext/sdk 0.2.0 → 0.3.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/README.md +19 -9
- package/dist/generated/content.js +1 -1
- package/dist/generated/schemas.d.ts +5 -0
- package/dist/generated/schemas.js +8 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/schema.d.ts +24 -8
- package/dist/schema.js +32 -12
- package/package.json +4 -2
- package/schemas/sharedcontext-directory-1/members.schema.json +52 -0
- package/schemas/sharedcontext-directory-1/memberships.schema.json +32 -0
package/README.md
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
# sharedcontext
|
|
1
|
+
# @sharedcontext/sdk
|
|
2
2
|
|
|
3
3
|
The `sharedcontext/1` work contract for JavaScript and TypeScript: what a client of a sharedcontext
|
|
4
4
|
service needs to write and read work items without holding the logic twice.
|
|
5
5
|
|
|
6
|
-
- **The contract's JSON Schemas**, shipped as files (
|
|
6
|
+
- **The contract's JSON Schemas**, shipped as files (`@sharedcontext/sdk/schemas/<file>`), and a
|
|
7
7
|
`validate(schema, value)` that checks a value against any of them (draft 2020-12, only the
|
|
8
|
-
keywords the contract uses).
|
|
8
|
+
keywords the contract uses). It throws for a schema file or fragment the package does not have.
|
|
9
|
+
- **The directory contract's JSON Schemas** (`sharedcontext-directory/1`, a directory's two HTTP
|
|
10
|
+
pages: `@sharedcontext/sdk/schemas/directory/<file>`), so a directory server written in
|
|
11
|
+
JavaScript can check what it serves:
|
|
12
|
+
`validate("sharedcontext-directory-1/members.schema.json", page)`.
|
|
9
13
|
- **TypeScript types** for the content of every event type (generated from
|
|
10
14
|
`content.schema.json`), for the signed envelope and for the MCP tools' arguments and results.
|
|
11
15
|
- **Event helpers**: the core's canonical JSON, the unsigned event template, the NIP-01 id, and the
|
|
12
16
|
core's envelope check. Signing goes through a `SharedcontextSigner` port: the package never holds
|
|
13
17
|
a key.
|
|
14
18
|
- **A small MCP client** for the service's `/mcp` (streamable HTTP, stateless JSON): `submit` and
|
|
15
|
-
`write`, `state`, `context`, `subscribe`, `changes`, `next`, `
|
|
16
|
-
`stats`, and `call` for any other tool.
|
|
19
|
+
`write`, `state`, `context`, `subscribe`, `changes`, `next`, `claimNext`, `draft`, `close`,
|
|
20
|
+
`stats`, `listTools`, `nodeEvents`, and `call` for any other tool.
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
Workers: hashing is Web Crypto, the schemas are embedded (no file system),
|
|
20
|
-
neither DOM nor Node typings.
|
|
22
|
+
An ES module (`import`) with no runtime dependencies. It runs on Node 20 and later, in browsers,
|
|
23
|
+
Deno, Bun and Cloudflare Workers: hashing is Web Crypto, the schemas are embedded (no file system),
|
|
24
|
+
and the types need neither DOM nor Node typings.
|
|
21
25
|
|
|
22
26
|
## Use
|
|
23
27
|
|
|
@@ -61,6 +65,10 @@ await verifyEvent(event, { receivedAt }); // the core's stateless check, without
|
|
|
61
65
|
await checkEvent(event); // the contract's shape: envelope, id, canonical content, content by type
|
|
62
66
|
```
|
|
63
67
|
|
|
68
|
+
`checkEvent` checks an event you are about to write. A stored event written under a newer minor of
|
|
69
|
+
the contract (an unknown type, or content fields this contract does not define) fails it even
|
|
70
|
+
though the log accepted it.
|
|
71
|
+
|
|
64
72
|
## Agreement with the core
|
|
65
73
|
|
|
66
74
|
The Rust crate `sharedcontext` is the reference. This package's tests run in the core's tree and
|
|
@@ -71,7 +79,9 @@ check, against the core's own fixture log (every event written and signed by the
|
|
|
71
79
|
- the validator's answer, error for error, against the repository's own contract check, over every
|
|
72
80
|
case of the contract's cases files and every fixture line;
|
|
73
81
|
- the constants and reason lists, read from the core's source;
|
|
74
|
-
- the shipped schemas, byte for byte with the contract's
|
|
82
|
+
- the shipped schemas, byte for byte with the contract's (the directory contract's with the
|
|
83
|
+
crate's `contracts/sharedcontext-directory-1/`), and every example of the directory contract
|
|
84
|
+
valid.
|
|
75
85
|
|
|
76
86
|
What the package does not do: verify BIP-340 signatures (use any NIP-01 library; the service
|
|
77
87
|
verifies every event), and decide what the log's state and policy decide (claims, gates,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
// Generated by scripts/generate.mjs from schemas
|
|
1
|
+
// Generated by scripts/generate.mjs from schemas/. Do not edit.
|
|
2
2
|
/** The event types of content.schema.json, in its order. */
|
|
3
3
|
export const EVENT_TYPES = ["project.created", "project.policy_set", "node.created", "node.updated", "node.moved", "node.linked", "node.unlinked", "node.split", "node.merged", "node.closed", "node.reopened", "note.added", "context.pinned", "claim.taken", "claim.renewed", "claim.released", "claim.expired", "state.transitioned", "gate.cleared", "evidence.attached", "findings.seen", "ref.set", "adapter.synced", "change.external_event", "external.state_changed", "goal.measures_set", "measure.observed", "actor.enrolled", "project.profile_set", "project.budget_set", "project.rule_set", "project.budget_incident", "cost.recorded", "gate.approved", "project.repo_set"];
|
|
@@ -3,3 +3,8 @@ export declare const SCHEMA_FILES: readonly ["changes.schema.json", "content.sch
|
|
|
3
3
|
export type SchemaFile = (typeof SCHEMA_FILES)[number];
|
|
4
4
|
/** Each schema file's exact text. */
|
|
5
5
|
export declare const SCHEMA_TEXT: Readonly<Record<SchemaFile, string>>;
|
|
6
|
+
/** The schema files of the directory contract sharedcontext-directory/1 (a directory's HTTP pages). */
|
|
7
|
+
export declare const DIRECTORY_SCHEMA_FILES: readonly ["sharedcontext-directory-1/members.schema.json", "sharedcontext-directory-1/memberships.schema.json"];
|
|
8
|
+
export type DirectorySchemaFile = (typeof DIRECTORY_SCHEMA_FILES)[number];
|
|
9
|
+
/** Each directory schema file's exact text. */
|
|
10
|
+
export declare const DIRECTORY_SCHEMA_TEXT: Readonly<Record<DirectorySchemaFile, string>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by scripts/generate.mjs from schemas
|
|
1
|
+
// Generated by scripts/generate.mjs from schemas/. Do not edit.
|
|
2
2
|
/** The schema files of sharedcontext/1, by their path in the contract's folder. */
|
|
3
3
|
export const SCHEMA_FILES = ["changes.schema.json", "content.schema.json", "context.schema.json", "event.schema.json", "execution.schema.json", "history/content-1.0.schema.json", "lineage.schema.json", "mcp-tools.schema.json", "stored-event.schema.json"];
|
|
4
4
|
/** Each schema file's exact text. */
|
|
@@ -13,3 +13,10 @@ export const SCHEMA_TEXT = {
|
|
|
13
13
|
"mcp-tools.schema.json": "{\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"title\": \"sharedcontext/1 MCP tools\",\n \"description\": \"The work items contract's MCP tools, with their argument and result shapes: \\\"#/$defs/tool.<name>\\\" names the tool's arguments and result; \\\"#/$defs/<Shape>\\\" are the shapes themselves. Write tools take a pre-signed event and return Appended; a refused call returns a structured error result shaped as Refusal (close: {unmet}). The tools are served by ticket-mcp over stdio and by the store-backed service at /mcp. changes (the change feed, changes@1) is served only where the deployment turns it on (feed.changes, off by default). emit and advance_time are test and demo tools, outside the contract.\",\n \"$comment\": \"Source: crates/sharedcontext/src/mcp/mod.rs (#[tool] functions, the argument structs, fn shape, Service::describe and the result json! literals). Tools (25): next, ready, claim_next, draft, claim, release, renew, context, split, merge, note, pin, link, move, gate_clear, close, goal_create, goal_measures, goal_close, subscribe, submit, state, stats, emit, advance_time; and changes (26), the change feed (struct ChangesArgs, fn changes, fn changes_page), its page in changes.schema.json. Arguments are not strict: the structs do not deny unknown fields; the one exception is ChangesArgs, which the contract closes (changes@1; its own $comment). No recorded MCP transcript yet: contract-check.mjs runs cases/changes-args.cases.jsonl against this file and compares it with the tools and argument structs it reads statically from the source; the tools' results are not checked against a transcript (open point).\",\n \"$defs\": {\n \"WriteArgs\": {\n \"type\": \"object\",\n \"properties\": {\n \"event\": {\n \"$comment\": \"a complete, signed NIP-01 event (object or JSON string) of this tool's type, as drafted by draft: sharedcontext/1 event.schema.json\",\n \"anyOf\": [\n {\n \"type\": \"object\"\n },\n {\n \"type\": \"string\"\n }\n ]\n },\n \"actor\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"INSECURE-SPIKE ONLY: the pubkey the server stamps as signer; never the contract\"\n },\n \"node\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"intent\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"claim: fix · triage · review · verify (claim_next: default fix)\"\n },\n \"pubkey\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"claim_next / claim without a node: the claimant's x-only pubkey\"\n },\n \"kinds\": {\n \"type\": [\n \"array\",\n \"null\"\n ],\n \"items\": {\n \"type\": \"string\"\n },\n \"$comment\": \"claim_next filter: node kinds\"\n },\n \"labels\": {\n \"type\": [\n \"array\",\n \"null\"\n ],\n \"items\": {\n \"type\": \"string\"\n },\n \"$comment\": \"claim_next filter: labels the node must all carry\"\n },\n \"goal\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"claim_next filter: a goal the node must serve\"\n },\n \"session\": {\n \"$comment\": \"optional agent session reference {agent_cli?, session_id}\"\n },\n \"lease_s\": {\n \"type\": [\n \"integer\",\n \"null\"\n ],\n \"minimum\": 0\n },\n \"on_sha\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"reason\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"release: done · blocked · handoff · abandoned · needs_input; also move, gate_clear, goal_measures, goal_close\"\n },\n \"to\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"release{handoff}: target pubkey; link: target node; gate_clear: the gate ref\"\n },\n \"progress\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"layer\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"note: pinned · working · summary\"\n },\n \"text\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"supersedes\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"edge\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"from\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"move: the current state\"\n },\n \"to_state\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"move: the target state\"\n },\n \"gate\": {\n \"$comment\": \"move{to_state: blocked}: {kind, ref}\"\n },\n \"parts\": {\n \"type\": [\n \"array\",\n \"null\"\n ],\n \"$comment\": \"split: [{title, covers[], severity?}]\"\n },\n \"into\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"title\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"body\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"owner\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"horizon\": {\n \"$comment\": \"goal_create: {from, to} unix seconds\"\n },\n \"weight\": {\n \"type\": [\n \"integer\",\n \"null\"\n ]\n },\n \"measures\": {\n \"type\": [\n \"array\",\n \"null\"\n ],\n \"$comment\": \"[{name, target, unit, source, direction?}]\"\n },\n \"outcome\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"goal_close: done · cancelled\"\n },\n \"client_id\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"idempotency id (c tag); generated when absent\"\n }\n },\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct WriteArgs: every write tool takes a pre-signed event (the contract); the other fields are the insecure-spike form and draft's args\"\n },\n \"NextArgs\": {\n \"type\": \"object\",\n \"properties\": {\n \"kind\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"limit\": {\n \"type\": [\n \"integer\",\n \"null\"\n ],\n \"minimum\": 0,\n \"$comment\": \"default 10\"\n },\n \"viewer\": {\n \"type\": [\n \"string\",\n \"null\"\n ],\n \"$comment\": \"the caller's pubkey\"\n }\n },\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct NextArgs\"\n },\n \"DraftArgs\": {\n \"type\": \"object\",\n \"properties\": {\n \"tool\": {\n \"type\": \"string\",\n \"$comment\": \"claim · release · renew · split · merge · note · pin · link · move · gate_clear · goal_create · goal_measures · goal_close\"\n },\n \"pubkey\": {\n \"type\": \"string\"\n },\n \"args\": {\n \"type\": \"object\",\n \"$comment\": \"the write tool's arguments (WriteArgs names)\"\n }\n },\n \"required\": [\n \"tool\",\n \"pubkey\",\n \"args\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct DraftArgs\"\n },\n \"NodeArg\": {\n \"type\": \"object\",\n \"properties\": {\n \"node\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"node\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct NodeArg\"\n },\n \"CloseArgs\": {\n \"type\": \"object\",\n \"properties\": {\n \"node\": {\n \"type\": \"string\"\n },\n \"run_id\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n }\n },\n \"required\": [\n \"node\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct CloseArgs\"\n },\n \"SubscribeArgs\": {\n \"type\": \"object\",\n \"properties\": {\n \"after_seq\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"node\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"limit\": {\n \"type\": [\n \"integer\",\n \"null\"\n ],\n \"minimum\": 0,\n \"$comment\": \"default 100\"\n }\n },\n \"required\": [\n \"after_seq\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct SubscribeArgs\"\n },\n \"ChangesArgs\": {\n \"type\": \"object\",\n \"additionalProperties\": false,\n \"properties\": {\n \"after\": {\n \"anyOf\": [\n {\n \"$ref\": \"changes.schema.json#/$defs/Cursor\"\n },\n {\n \"type\": \"null\"\n }\n ],\n \"$comment\": \"absent or null: from the start of the store's retained history\"\n },\n \"limit\": {\n \"type\": [\n \"integer\",\n \"null\"\n ],\n \"minimum\": 1,\n \"maximum\": 1000,\n \"$comment\": \"Default 100, at most 1000 (as subscribe)\"\n },\n \"kinds\": {\n \"type\": [\n \"array\",\n \"null\"\n ],\n \"items\": {\n \"type\": \"string\",\n \"minLength\": 1,\n \"maxLength\": 64\n },\n \"maxItems\": 32,\n \"$comment\": \"only these kinds; the cursor still moves past the others, so a filtered follower never re-reads them\"\n }\n },\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct ChangesArgs. Closed by the contract (changes@1): a caller sends only these. As built the struct, like the others here, does not deny unknown fields, and limit outside 1–1000 is clamped rather than refused\"\n },\n \"SubmitArgs\": {\n \"type\": \"object\",\n \"properties\": {\n \"event\": {\n \"anyOf\": [\n {\n \"type\": \"object\"\n },\n {\n \"type\": \"string\"\n }\n ],\n \"$comment\": \"a complete, signed NIP-01 event\"\n }\n },\n \"required\": [\n \"event\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct SubmitArgs\"\n },\n \"EmitArgs\": {\n \"type\": \"object\",\n \"properties\": {\n \"actor\": {\n \"type\": \"string\"\n },\n \"type\": {\n \"type\": \"string\"\n },\n \"node\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"content\": {\n \"$comment\": \"any JSON value\"\n },\n \"tags\": {\n \"type\": [\n \"array\",\n \"null\"\n ],\n \"items\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n }\n },\n \"client_id\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n }\n },\n \"required\": [\n \"actor\",\n \"type\",\n \"content\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct EmitArgs (INSECURE-SPIKE ONLY)\"\n },\n \"AdvanceArgs\": {\n \"type\": \"object\",\n \"properties\": {\n \"seconds\": {\n \"type\": \"integer\",\n \"minimum\": 0\n }\n },\n \"required\": [\n \"seconds\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs struct AdvanceArgs\"\n },\n \"NoArgs\": {\n \"type\": \"object\",\n \"properties\": {},\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs stats takes no arguments\"\n },\n \"Appended\": {\n \"type\": \"object\",\n \"properties\": {\n \"seq\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"id\": {\n \"type\": \"string\"\n },\n \"duplicate\": {\n \"type\": \"boolean\"\n },\n \"reactions\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"seq\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"w\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"node\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"id\": {\n \"type\": \"string\"\n }\n }\n },\n \"$comment\": \"service reactions appended with it (new events only)\"\n },\n \"node\": {\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": \"string\"\n },\n \"state\": {\n \"type\": \"string\"\n },\n \"claim\": {\n \"$comment\": \"the live claim or null\"\n },\n \"closed\": {\n \"$comment\": \"the close record or null\"\n },\n \"covers\": {\n \"type\": \"array\"\n },\n \"gate\": {\n \"$comment\": \"{kind, ref} or null\"\n }\n }\n }\n },\n \"required\": [\n \"seq\",\n \"id\",\n \"duplicate\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs Service::describe\"\n },\n \"Refusal\": {\n \"type\": \"object\",\n \"properties\": {\n \"reason\": {\n \"type\": \"string\",\n \"$comment\": \"snake_case RejectReason of the log, or a tool-level reason: wrong_tool_for_type, unsigned_write, missing_argument, unknown_tool, bad_arguments, project_not_created, node_not_found\"\n },\n \"detail\": {\n \"$comment\": \"any JSON value\"\n },\n \"hint\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"reason\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs Service::append (log refusals {reason, detail}) and the tool-level errors; sent as a structured error result\"\n },\n \"Unsigned\": {\n \"type\": \"object\",\n \"properties\": {\n \"pubkey\": {\n \"type\": \"string\"\n },\n \"created_at\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"kind\": {\n \"const\": 7411\n },\n \"tags\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n }\n },\n \"content\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"pubkey\",\n \"created_at\",\n \"kind\",\n \"tags\",\n \"content\"\n ],\n \"$comment\": \"crates/sharedcontext/src/signed/event.rs UnsignedEvent, as Service::draft returns it\"\n },\n \"Reservation\": {\n \"type\": \"object\",\n \"properties\": {\n \"node\": {\n \"type\": \"string\"\n },\n \"pubkey\": {\n \"type\": \"string\"\n },\n \"until_ms\": {\n \"type\": \"integer\",\n \"minimum\": 0\n }\n },\n \"required\": [\n \"node\",\n \"pubkey\",\n \"until_ms\"\n ],\n \"$comment\": \"crates/sharedcontext/src/work/claim_next.rs Reservation\"\n },\n \"NextResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"now\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"swept\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"seq\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"w\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"node\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n }\n }\n }\n },\n \"next\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"node\": {\n \"type\": \"string\"\n },\n \"kind\": {\n \"type\": \"string\"\n },\n \"title\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"severity\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"state\": {\n \"type\": \"string\"\n },\n \"covers\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"handoff\": {},\n \"blocks\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n },\n \"goal_weight\": {},\n \"unblock_count\": {},\n \"goals\": {\n \"type\": \"array\"\n }\n },\n \"$comment\": \"crates/sharedcontext/src/work/log.rs Log::next entries\"\n }\n },\n \"alias_of\": {\n \"const\": \"next\"\n }\n },\n \"required\": [\n \"now\",\n \"swept\",\n \"next\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs next_view\"\n },\n \"ClaimNextResult\": {\n \"anyOf\": [\n {\n \"allOf\": [\n {\n \"$ref\": \"#/$defs/Appended\"\n },\n {\n \"type\": \"object\",\n \"properties\": {\n \"claimed\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"claimed\"\n ]\n }\n ],\n \"$comment\": \"one call: this server holds the caller's key\"\n },\n {\n \"type\": \"object\",\n \"properties\": {\n \"claimed\": {\n \"type\": \"null\"\n },\n \"hint\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"claimed\"\n ],\n \"$comment\": \"nothing claimable\"\n },\n {\n \"type\": \"object\",\n \"properties\": {\n \"reserved\": {\n \"$ref\": \"#/$defs/Reservation\"\n },\n \"unsigned\": {\n \"$ref\": \"#/$defs/Unsigned\"\n },\n \"hint\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"reserved\",\n \"unsigned\"\n ],\n \"$comment\": \"two-phase: sign unsigned and send it to claim before until_ms\"\n },\n {\n \"type\": \"object\",\n \"properties\": {\n \"reserved\": {\n \"type\": \"null\"\n },\n \"hint\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"reserved\"\n ],\n \"$comment\": \"nothing claimable\"\n }\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs fn claim_next; claim without event and node adds alias_of: claim_next\"\n },\n \"DraftResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"tool\": {\n \"type\": \"string\"\n },\n \"unsigned\": {\n \"$ref\": \"#/$defs/Unsigned\"\n },\n \"hint\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"tool\",\n \"unsigned\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs tool draft\"\n },\n \"CloseResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"evidence\": {\n \"$comment\": \"any JSON value\"\n },\n \"appended\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n },\n \"required\": [\n \"evidence\",\n \"appended\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs tool close: when the rule does not hold the result is a structured error {unmet}\"\n },\n \"SubscribeResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"after_seq\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"head_seq\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"events\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"seq\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"received_at\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"w\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"node\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"id\": {\n \"type\": \"string\"\n },\n \"pubkey\": {\n \"type\": \"string\"\n },\n \"content\": {\n \"$comment\": \"the content parsed as JSON (sharedcontext/1 content.schema.json by w), or null\"\n }\n },\n \"required\": [\n \"seq\",\n \"received_at\",\n \"w\",\n \"node\",\n \"id\",\n \"pubkey\",\n \"content\"\n ]\n }\n }\n },\n \"required\": [\n \"after_seq\",\n \"head_seq\",\n \"events\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs tool subscribe\"\n },\n \"FoldedView\": {\n \"type\": \"object\",\n \"$comment\": \"the folded node view with derived fields, or the context bundle (crates/sharedcontext/src/work/log.rs context_at, node_view_at); its node fields follow the canonical snapshot form in crates/sharedcontext/fixtures/README.md. Not pinned field by field in sharedcontext/1 (open point)\"\n },\n \"StatsResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"events\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"nodes\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"rejects\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"skipped\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"registry_versions\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"now\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"project\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"insecure_spike\": {\n \"type\": \"boolean\"\n },\n \"reject_tail\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"reason\": {\n \"type\": \"string\"\n },\n \"detail\": {\n \"$comment\": \"any JSON value\"\n },\n \"w\": {\n \"$comment\": \"any JSON value\"\n }\n }\n }\n }\n },\n \"required\": [\n \"events\",\n \"nodes\",\n \"rejects\",\n \"skipped\",\n \"registry_versions\",\n \"now\",\n \"project\",\n \"insecure_spike\",\n \"reject_tail\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs tool stats\"\n },\n \"AdvanceResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"now\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"virtual\": {\n \"type\": \"boolean\"\n },\n \"swept\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"seq\": {\n \"type\": \"integer\",\n \"minimum\": 0\n },\n \"w\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n },\n \"node\": {\n \"type\": [\n \"string\",\n \"null\"\n ]\n }\n }\n }\n }\n },\n \"required\": [\n \"now\",\n \"virtual\",\n \"swept\"\n ],\n \"$comment\": \"crates/sharedcontext/src/mcp/mod.rs tool advance_time\"\n },\n \"tool.next\": {\n \"type\": \"object\",\n \"$comment\": \"claimable nodes for viewer in next() order; read only\",\n \"properties\": {\n \"name\": {\n \"const\": \"next\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/NextArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/NextResult\"\n }\n }\n },\n \"tool.ready\": {\n \"type\": \"object\",\n \"$comment\": \"alias of next\",\n \"properties\": {\n \"name\": {\n \"const\": \"ready\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/NextArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/NextResult\"\n }\n }\n },\n \"tool.claim_next\": {\n \"type\": \"object\",\n \"$comment\": \"atomic best ready node: one call with the caller's key, else a 5 s reservation and the draft\",\n \"properties\": {\n \"name\": {\n \"const\": \"claim_next\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/ClaimNextResult\"\n }\n }\n },\n \"tool.draft\": {\n \"type\": \"object\",\n \"$comment\": \"the unsigned body for a write tool; read only\",\n \"properties\": {\n \"name\": {\n \"const\": \"draft\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/DraftArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/DraftResult\"\n }\n }\n },\n \"tool.claim\": {\n \"type\": \"object\",\n \"$comment\": \"claim.taken; without event and node it is claim_next\",\n \"properties\": {\n \"name\": {\n \"const\": \"claim\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.release\": {\n \"type\": \"object\",\n \"$comment\": \"claim.released\",\n \"properties\": {\n \"name\": {\n \"const\": \"release\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.renew\": {\n \"type\": \"object\",\n \"$comment\": \"claim.renewed (e tag → the claim)\",\n \"properties\": {\n \"name\": {\n \"const\": \"renew\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.context\": {\n \"type\": \"object\",\n \"$comment\": \"the context bundle; read only\",\n \"properties\": {\n \"name\": {\n \"const\": \"context\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/NodeArg\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/FoldedView\"\n }\n }\n },\n \"tool.split\": {\n \"type\": \"object\",\n \"$comment\": \"node.split\",\n \"properties\": {\n \"name\": {\n \"const\": \"split\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.merge\": {\n \"type\": \"object\",\n \"$comment\": \"node.merged\",\n \"properties\": {\n \"name\": {\n \"const\": \"merge\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.note\": {\n \"type\": \"object\",\n \"$comment\": \"note.added\",\n \"properties\": {\n \"name\": {\n \"const\": \"note\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.pin\": {\n \"type\": \"object\",\n \"$comment\": \"context.pinned\",\n \"properties\": {\n \"name\": {\n \"const\": \"pin\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.link\": {\n \"type\": \"object\",\n \"$comment\": \"node.linked\",\n \"properties\": {\n \"name\": {\n \"const\": \"link\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.move\": {\n \"type\": \"object\",\n \"$comment\": \"state.transitioned\",\n \"properties\": {\n \"name\": {\n \"const\": \"move\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.gate_clear\": {\n \"type\": \"object\",\n \"$comment\": \"gate.cleared\",\n \"properties\": {\n \"name\": {\n \"const\": \"gate_clear\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.close\": {\n \"type\": \"object\",\n \"$comment\": \"evaluate the close policy now\",\n \"properties\": {\n \"name\": {\n \"const\": \"close\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/CloseArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/CloseResult\"\n }\n }\n },\n \"tool.goal_create\": {\n \"type\": \"object\",\n \"$comment\": \"node.created{kind: goal}\",\n \"properties\": {\n \"name\": {\n \"const\": \"goal_create\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.goal_measures\": {\n \"type\": \"object\",\n \"$comment\": \"goal.measures_set\",\n \"properties\": {\n \"name\": {\n \"const\": \"goal_measures\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.goal_close\": {\n \"type\": \"object\",\n \"$comment\": \"node.closed on a goal\",\n \"properties\": {\n \"name\": {\n \"const\": \"goal_close\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/WriteArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.subscribe\": {\n \"type\": \"object\",\n \"$comment\": \"events after a seq (a page; poll to follow); read only\",\n \"properties\": {\n \"name\": {\n \"const\": \"subscribe\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/SubscribeArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/SubscribeResult\"\n }\n }\n },\n \"tool.changes\": {\n \"type\": \"object\",\n \"$comment\": \"the change feed, changes@1: what changed after a cursor, without the body; read only, the same read scope as subscribe. Served only with feed.changes on (off by default): off, the tool is not listed and a call is an unknown tool. A refused call returns a ChangesRefusal (cursor_invalid, cursor_ahead) as a structured error result\",\n \"properties\": {\n \"name\": {\n \"const\": \"changes\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/ChangesArgs\"\n },\n \"result\": {\n \"$ref\": \"changes.schema.json#/$defs/ChangesPage\"\n }\n }\n },\n \"tool.submit\": {\n \"type\": \"object\",\n \"$comment\": \"append any pre-signed event (the generic write path)\",\n \"properties\": {\n \"name\": {\n \"const\": \"submit\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/SubmitArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.state\": {\n \"type\": \"object\",\n \"$comment\": \"folded view of one node; read only\",\n \"properties\": {\n \"name\": {\n \"const\": \"state\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/NodeArg\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/FoldedView\"\n }\n }\n },\n \"tool.stats\": {\n \"type\": \"object\",\n \"$comment\": \"log statistics and the reject journal tail; read only\",\n \"properties\": {\n \"name\": {\n \"const\": \"stats\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/NoArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/StatsResult\"\n }\n }\n },\n \"tool.emit\": {\n \"type\": \"object\",\n \"$comment\": \"INSECURE-SPIKE ONLY, not part of the contract\",\n \"properties\": {\n \"name\": {\n \"const\": \"emit\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/EmitArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/Appended\"\n }\n }\n },\n \"tool.advance_time\": {\n \"type\": \"object\",\n \"$comment\": \"virtual clock only; test and demo\",\n \"properties\": {\n \"name\": {\n \"const\": \"advance_time\"\n },\n \"arguments\": {\n \"$ref\": \"#/$defs/AdvanceArgs\"\n },\n \"result\": {\n \"$ref\": \"#/$defs/AdvanceResult\"\n }\n }\n }\n }\n}\n",
|
|
14
14
|
"stored-event.schema.json": "{\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"title\": \"sharedcontext/1 stored event\",\n \"description\": \"An event as the log stores and serves it: the signed event plus the server-side fields, which are never hashed or signed. seq is the one fold order; received_at (unix seconds) is the lease clock; policy_version is the hash of the policy version the log checked the event against. One line of the fixture log after its header.\",\n \"$comment\": \"Source: crates/sharedcontext/src/signed/event.rs struct StoredEvent {seq, received_at, policy_version (optional: absent only for events stored before the log recorded policy versions), event}; fixture line format {seq, received_at, policy_version, event} (crates/sharedcontext/fixtures/README.md).\",\n \"type\": \"object\",\n \"required\": [\"seq\", \"received_at\", \"event\"],\n \"properties\": {\n \"seq\": { \"type\": \"integer\", \"minimum\": 1 },\n \"received_at\": { \"type\": \"integer\", \"minimum\": 0 },\n \"policy_version\": { \"type\": \"string\", \"pattern\": \"^sha256:[0-9a-f]{64}$\", \"$comment\": \"crates/sharedcontext/src/work/org.rs policy_version\" },\n \"event\": { \"$ref\": \"event.schema.json\" }\n }\n}\n",
|
|
15
15
|
};
|
|
16
|
+
/** The schema files of the directory contract sharedcontext-directory/1 (a directory's HTTP pages). */
|
|
17
|
+
export const DIRECTORY_SCHEMA_FILES = ["sharedcontext-directory-1/members.schema.json", "sharedcontext-directory-1/memberships.schema.json"];
|
|
18
|
+
/** Each directory schema file's exact text. */
|
|
19
|
+
export const DIRECTORY_SCHEMA_TEXT = {
|
|
20
|
+
"sharedcontext-directory-1/members.schema.json": "{\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"$id\": \"urn:sharedcontext-directory:1:members\",\n \"title\": \"sharedcontext-directory/1 member page\",\n \"$comment\": \"The 200 body of GET {base}/orgs/{org_id}/members?limit={n}[&cursor={c}] (required route). A client follows next_cursor until it is null, empty or absent; a repeated cursor is an error. The pages together are the org's complete listing, or the server answers an error: never a silently partial listing (a member missing from it reads as gone from the org). Fields not named here are ignored by a client (additive changes stay v1; a breaking change is v2). Contract: docs/directory-http.md. Client: src/directory/http.rs.\",\n \"type\": \"object\",\n \"required\": [\"members\"],\n \"properties\": {\n \"members\": {\n \"type\": \"array\",\n \"items\": { \"$ref\": \"#/$defs/Member\" }\n },\n \"next_cursor\": { \"$ref\": \"#/$defs/NextCursor\" }\n },\n \"$defs\": {\n \"NextCursor\": {\n \"type\": [\"string\", \"null\"],\n \"maxLength\": 1024,\n \"$comment\": \"Opaque to the client, which sends it back as ?cursor= (percent-encoded) with the same org and limit, and never parses it. null, empty or absent: this is the last page. A server may answer a cursor issued for another org 400.\"\n },\n \"Id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 256 },\n \"Member\": {\n \"type\": \"object\",\n \"required\": [\"member_id\", \"org_id\", \"user_id\", \"kind\", \"role\", \"lifecycle\", \"teams\", \"keys\"],\n \"properties\": {\n \"member_id\": { \"$ref\": \"#/$defs/Id\", \"description\": \"The member's id in the directory; stable for the member's life.\" },\n \"org_id\": { \"$ref\": \"#/$defs/Id\", \"description\": \"Always the org of the request: a member of another org fails the whole read.\" },\n \"user_id\": { \"type\": \"string\", \"maxLength\": 256, \"description\": \"The user behind a person member; may be empty for an agent.\" },\n \"kind\": { \"enum\": [\"person\", \"agent\"] },\n \"role\": { \"type\": \"string\", \"maxLength\": 128, \"description\": \"The org role (owner, admin, member or a custom role), or several comma-separated; may be empty (read as member).\" },\n \"title\": { \"type\": [\"string\", \"null\"], \"maxLength\": 256 },\n \"lifecycle\": { \"enum\": [\"active\", \"paused\", \"retired\"] },\n \"sponsor_member_id\": { \"type\": [\"string\", \"null\"], \"maxLength\": 256, \"description\": \"Agents: the sponsoring member (a person of the same org).\" },\n \"teams\": { \"type\": \"array\", \"items\": { \"$ref\": \"#/$defs/Id\" }, \"description\": \"Team ids.\" },\n \"keys\": { \"type\": \"array\", \"items\": { \"$ref\": \"#/$defs/Key\" }, \"description\": \"The member's Nostr keys, revoked ones included (with revoked_at); at most one unrevoked.\" },\n \"sponsor_active\": { \"type\": [\"boolean\", \"null\"], \"description\": \"Agents: the directory's own view of whether the sponsor is active (read for drift only).\" }\n },\n \"if\": { \"required\": [\"kind\"], \"properties\": { \"kind\": { \"const\": \"agent\" } } },\n \"then\": { \"required\": [\"sponsor_member_id\"], \"properties\": { \"sponsor_member_id\": { \"type\": \"string\", \"minLength\": 1 } } },\n \"$comment\": \"Optional fields (title, sponsor_member_id, sponsor_active, a key's revoked_at) are best omitted; a client accepts null too. An agent always carries its sponsor_member_id.\"\n },\n \"Key\": {\n \"type\": \"object\",\n \"required\": [\"pubkey\", \"custody\"],\n \"properties\": {\n \"pubkey\": { \"type\": \"string\", \"pattern\": \"^[0-9a-f]{64}$\", \"description\": \"x-only public key, 64 lowercase hex.\" },\n \"custody\": { \"enum\": [\"self\", \"directory\"], \"description\": \"self: the member holds it (a person); directory: the directory holds it and signs with it (an agent's minted key).\" },\n \"revoked_at\": { \"type\": [\"string\", \"null\"], \"maxLength\": 64, \"description\": \"Set when the key was revoked (RFC 3339); a revoked key maps to nothing.\" }\n }\n }\n }\n}\n",
|
|
21
|
+
"sharedcontext-directory-1/memberships.schema.json": "{\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"$id\": \"urn:sharedcontext-directory:1:memberships\",\n \"title\": \"sharedcontext-directory/1 membership page\",\n \"$comment\": \"The 200 body of GET {base}/users/{user_id}/memberships?limit={n}[&cursor={c}] (optional route: 404 or 501 means the directory does not offer it). Paged like the member listing (members.schema.json), with the same complete-or-error rule. Fields not named here are ignored by a client. Contract: docs/directory-http.md. Client: src/directory/http.rs.\",\n \"type\": \"object\",\n \"required\": [\"memberships\"],\n \"properties\": {\n \"memberships\": {\n \"type\": \"array\",\n \"items\": { \"$ref\": \"#/$defs/Membership\" }\n },\n \"next_cursor\": {\n \"type\": [\"string\", \"null\"],\n \"maxLength\": 1024,\n \"$comment\": \"As in members.schema.json: opaque; null, empty or absent on the last page.\"\n }\n },\n \"$defs\": {\n \"Membership\": {\n \"type\": \"object\",\n \"required\": [\"org_id\", \"member_id\", \"kind\", \"role\", \"lifecycle\"],\n \"properties\": {\n \"org_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 256 },\n \"member_id\": { \"type\": \"string\", \"minLength\": 1, \"maxLength\": 256 },\n \"kind\": { \"enum\": [\"person\", \"agent\"] },\n \"role\": { \"type\": \"string\", \"maxLength\": 128 },\n \"lifecycle\": { \"enum\": [\"active\", \"paused\", \"retired\"] }\n }\n }\n }\n}\n",
|
|
22
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { CLIENT_ID_MAX, CONTRACT, FUTURE_SKEW_S, MAX_BODY_BYTES, MAX_CONTENT_DEP
|
|
|
2
2
|
export { CanonicalJsonError, canonicalContent, canonicalJson, compareUtf8, formatFloat, isCanonicalContent, isWellFormed, utf8, utf8Length, type Json, type JsonInput, } from "./canonical.js";
|
|
3
3
|
export { TemplateError, eventId, eventTemplate, nodeTagOptional, serializeNip01, sha256Hex, signEvent, verifyEvent, verifyShape, type EventTemplate, type SharedcontextSigner, type SignedEvent, type StoredEvent, type TemplateInput, } from "./event.js";
|
|
4
4
|
export { AUTH_REASONS, ENVELOPE_REASONS, KNOWN_REASONS, REJECT_REASONS, TOOL_REASONS, knownCode, type EnvelopeReason, type RejectReason, } from "./reasons.js";
|
|
5
|
-
export { SCHEMA_FILES, checkEvent, checkStoredEvent, contentTypes, schemaDocument, schemaText, validate, type SchemaFile, type ValidationResult, } from "./schema.js";
|
|
5
|
+
export { DIRECTORY_SCHEMA_FILES, SCHEMA_FILES, checkEvent, checkStoredEvent, contentTypes, schemaDocument, schemaText, validate, type DirectorySchemaFile, type SchemaFile, type ValidationResult, } from "./schema.js";
|
|
6
6
|
export { DEFAULT_TIMEOUT_MS, SharedcontextClient, SharedcontextRefused, SharedcontextUnavailable, type FetchLike, type FetchResponseLike, type SharedcontextClientOptions, } from "./client.js";
|
|
7
7
|
export type * from "./types.js";
|
|
8
8
|
export * from "./generated/content.js";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// sharedcontext: the sharedcontext/1 work contract for JavaScript and TypeScript.
|
|
1
|
+
// @sharedcontext/sdk: the sharedcontext/1 work contract for JavaScript and TypeScript.
|
|
2
2
|
export { CLIENT_ID_MAX, CONTRACT, FUTURE_SKEW_S, MAX_BODY_BYTES, MAX_CONTENT_DEPTH, SCHEMA_MAJOR, TICKET_KIND, TYPE_TAG, } from "./constants.js";
|
|
3
3
|
export { CanonicalJsonError, canonicalContent, canonicalJson, compareUtf8, formatFloat, isCanonicalContent, isWellFormed, utf8, utf8Length, } from "./canonical.js";
|
|
4
4
|
export { TemplateError, eventId, eventTemplate, nodeTagOptional, serializeNip01, sha256Hex, signEvent, verifyEvent, verifyShape, } from "./event.js";
|
|
5
5
|
export { AUTH_REASONS, ENVELOPE_REASONS, KNOWN_REASONS, REJECT_REASONS, TOOL_REASONS, knownCode, } from "./reasons.js";
|
|
6
|
-
export { SCHEMA_FILES, checkEvent, checkStoredEvent, contentTypes, schemaDocument, schemaText, validate, } from "./schema.js";
|
|
6
|
+
export { DIRECTORY_SCHEMA_FILES, SCHEMA_FILES, checkEvent, checkStoredEvent, contentTypes, schemaDocument, schemaText, validate, } from "./schema.js";
|
|
7
7
|
export { DEFAULT_TIMEOUT_MS, SharedcontextClient, SharedcontextRefused, SharedcontextUnavailable, } from "./client.js";
|
|
8
8
|
export * from "./generated/content.js";
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import { SCHEMA_FILES, type SchemaFile } from "./generated/schemas.js";
|
|
2
|
-
export { SCHEMA_FILES, type SchemaFile };
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { DIRECTORY_SCHEMA_FILES, SCHEMA_FILES, type DirectorySchemaFile, type SchemaFile } from "./generated/schemas.js";
|
|
2
|
+
export { DIRECTORY_SCHEMA_FILES, SCHEMA_FILES, type DirectorySchemaFile, type SchemaFile };
|
|
3
|
+
/**
|
|
4
|
+
* A schema file, parsed: one of the work contract's (for example `event.schema.json`,
|
|
5
|
+
* `history/content-1.0.schema.json`) or of the directory contract's
|
|
6
|
+
* (`sharedcontext-directory-1/members.schema.json`). Throws for a file the package does not have.
|
|
7
|
+
*/
|
|
8
|
+
export declare function schemaDocument(file: SchemaFile | DirectorySchemaFile): unknown;
|
|
9
|
+
/**
|
|
10
|
+
* The exact text of a schema file, as shipped in `schemas/`: a work contract file is importable as
|
|
11
|
+
* `@sharedcontext/sdk/schemas/<file>`, a directory contract file
|
|
12
|
+
* (`sharedcontext-directory-1/<file>`) as `@sharedcontext/sdk/schemas/directory/<file>`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function schemaText(file: SchemaFile | DirectorySchemaFile): string;
|
|
7
15
|
/** The JSON type of a value as JSON Schema names it (`integer` for a whole number). */
|
|
8
16
|
export declare const typeOf: (v: unknown) => string;
|
|
9
17
|
/** What `validate` answers: `errors` lists each failure as `path: message`. */
|
|
@@ -12,15 +20,23 @@ export interface ValidationResult {
|
|
|
12
20
|
errors: string[];
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
|
-
* Validate `value` against a schema
|
|
23
|
+
* Validate `value` against a schema this package ships: a file (`event.schema.json`,
|
|
24
|
+
* `sharedcontext-directory-1/members.schema.json`) or a place in one
|
|
16
25
|
* (`content.schema.json#/$defs/node.created`, `mcp-tools.schema.json#/$defs/SubscribeArgs`).
|
|
17
26
|
* `path` names the value in the messages (default `$`).
|
|
27
|
+
*
|
|
28
|
+
* Throws (it does not answer `valid: false`) for a schema file or fragment the package does not
|
|
29
|
+
* have, so a misspelt name never reads as a refused value.
|
|
18
30
|
*/
|
|
19
|
-
export declare function validate(schema: string
|
|
31
|
+
export declare function validate(schema: SchemaFile | DirectorySchemaFile | `${SchemaFile | DirectorySchemaFile}#${string}`, value: unknown, path?: string): ValidationResult;
|
|
20
32
|
/**
|
|
21
33
|
* Every refusal the contract's shape gives a work event: the envelope schema, the NIP-01 id,
|
|
22
34
|
* canonical content, and the content by its `w` tag (`content.schema.json`; a type it does not
|
|
23
35
|
* define is `unknown_type`). An empty list when the shape passes. The signature is not checked.
|
|
36
|
+
*
|
|
37
|
+
* This is the check for an event you are about to write. A stored event written under a newer
|
|
38
|
+
* minor of the contract (an unknown type, or content fields this contract does not define) fails
|
|
39
|
+
* it even though the log accepted it.
|
|
24
40
|
*/
|
|
25
41
|
export declare function checkEvent(event: unknown): Promise<string[]>;
|
|
26
42
|
/** A stored event (`{seq, received_at, policy_version, event}`): the stored shape around the event, then `checkEvent`. */
|
package/dist/schema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// A small JSON Schema (draft 2020-12) validator for the
|
|
1
|
+
// A small JSON Schema (draft 2020-12) validator for the schemas this package ships (the work
|
|
2
|
+
// contract sharedcontext/1 and the directory contract sharedcontext-directory/1),
|
|
2
3
|
// and the contract's checks of a work event that go beyond the schema (NIP-01 id, canonical
|
|
3
4
|
// content, content by the `w` tag).
|
|
4
5
|
//
|
|
@@ -10,22 +11,33 @@
|
|
|
10
11
|
// fixture log). Signatures are not verified.
|
|
11
12
|
import { compareUtf8, isCanonicalContent } from "./canonical.js";
|
|
12
13
|
import { eventId } from "./event.js";
|
|
13
|
-
import { SCHEMA_FILES, SCHEMA_TEXT } from "./generated/schemas.js";
|
|
14
|
-
export { SCHEMA_FILES };
|
|
15
|
-
|
|
14
|
+
import { DIRECTORY_SCHEMA_FILES, DIRECTORY_SCHEMA_TEXT, SCHEMA_FILES, SCHEMA_TEXT } from "./generated/schemas.js";
|
|
15
|
+
export { DIRECTORY_SCHEMA_FILES, SCHEMA_FILES };
|
|
16
|
+
/** Every schema file `validate` knows: the work contract's, then the directory contract's. */
|
|
17
|
+
const ALL_FILES = [...SCHEMA_FILES, ...DIRECTORY_SCHEMA_FILES];
|
|
18
|
+
const ALL_TEXT = { ...SCHEMA_TEXT, ...DIRECTORY_SCHEMA_TEXT };
|
|
19
|
+
const ANNOTATIONS = new Set(["$schema", "$id", "$comment", "title", "description", "format", "examples", "default", "deprecated", "readOnly", "writeOnly", "contentMediaType"]);
|
|
16
20
|
const docs = new Map();
|
|
17
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* A schema file, parsed: one of the work contract's (for example `event.schema.json`,
|
|
23
|
+
* `history/content-1.0.schema.json`) or of the directory contract's
|
|
24
|
+
* (`sharedcontext-directory-1/members.schema.json`). Throws for a file the package does not have.
|
|
25
|
+
*/
|
|
18
26
|
export function schemaDocument(file) {
|
|
19
|
-
if (!
|
|
20
|
-
throw new Error(`no schema file ${file} in
|
|
27
|
+
if (!ALL_FILES.includes(file))
|
|
28
|
+
throw new Error(`no schema file ${file} in this package`);
|
|
21
29
|
if (!docs.has(file))
|
|
22
|
-
docs.set(file, JSON.parse(
|
|
30
|
+
docs.set(file, JSON.parse(ALL_TEXT[file]));
|
|
23
31
|
return docs.get(file);
|
|
24
32
|
}
|
|
25
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The exact text of a schema file, as shipped in `schemas/`: a work contract file is importable as
|
|
35
|
+
* `@sharedcontext/sdk/schemas/<file>`, a directory contract file
|
|
36
|
+
* (`sharedcontext-directory-1/<file>`) as `@sharedcontext/sdk/schemas/directory/<file>`.
|
|
37
|
+
*/
|
|
26
38
|
export function schemaText(file) {
|
|
27
39
|
schemaDocument(file);
|
|
28
|
-
return
|
|
40
|
+
return ALL_TEXT[file];
|
|
29
41
|
}
|
|
30
42
|
function pointer(doc, frag, where) {
|
|
31
43
|
if (!frag)
|
|
@@ -55,7 +67,7 @@ function resolvePath(from, path) {
|
|
|
55
67
|
function resolveRef(ref, file) {
|
|
56
68
|
const [path, frag] = ref.split("#");
|
|
57
69
|
const target = path ? resolvePath(file, path) : file;
|
|
58
|
-
if (!
|
|
70
|
+
if (!ALL_FILES.includes(target))
|
|
59
71
|
throw new Error(`${file}: $ref to a missing file ${ref}`);
|
|
60
72
|
return { schema: pointer(schemaDocument(target), frag ?? "", `${file} $ref ${ref}`), file: target };
|
|
61
73
|
}
|
|
@@ -213,9 +225,13 @@ function check(value, schema, file, path) {
|
|
|
213
225
|
return errs;
|
|
214
226
|
}
|
|
215
227
|
/**
|
|
216
|
-
* Validate `value` against a schema
|
|
228
|
+
* Validate `value` against a schema this package ships: a file (`event.schema.json`,
|
|
229
|
+
* `sharedcontext-directory-1/members.schema.json`) or a place in one
|
|
217
230
|
* (`content.schema.json#/$defs/node.created`, `mcp-tools.schema.json#/$defs/SubscribeArgs`).
|
|
218
231
|
* `path` names the value in the messages (default `$`).
|
|
232
|
+
*
|
|
233
|
+
* Throws (it does not answer `valid: false`) for a schema file or fragment the package does not
|
|
234
|
+
* have, so a misspelt name never reads as a refused value.
|
|
219
235
|
*/
|
|
220
236
|
export function validate(schema, value, path = "$") {
|
|
221
237
|
const { schema: s, file } = resolveRef(schema.includes("#") ? schema : `${schema}#`, "");
|
|
@@ -227,6 +243,10 @@ const SHAPE_TYPES = /^[a-z_]+\.[a-z_]+$/;
|
|
|
227
243
|
* Every refusal the contract's shape gives a work event: the envelope schema, the NIP-01 id,
|
|
228
244
|
* canonical content, and the content by its `w` tag (`content.schema.json`; a type it does not
|
|
229
245
|
* define is `unknown_type`). An empty list when the shape passes. The signature is not checked.
|
|
246
|
+
*
|
|
247
|
+
* This is the check for an event you are about to write. A stored event written under a newer
|
|
248
|
+
* minor of the contract (an unknown type, or content fields this contract does not define) fails
|
|
249
|
+
* it even though the log accepted it.
|
|
230
250
|
*/
|
|
231
251
|
export async function checkEvent(event) {
|
|
232
252
|
const errs = check(event, schemaDocument("event.schema.json"), "event.schema.json", "event");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharedcontext/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The sharedcontext/1 work contract for JavaScript and TypeScript: its JSON Schemas and a validator, event templates, canonical JSON and NIP-01 ids, and a small client for the service's MCP tools",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"license": "MIT OR Apache-2.0",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/cogniumhq/sharedcontext"
|
|
11
|
+
"url": "https://github.com/cogniumhq/sharedcontext",
|
|
12
|
+
"directory": "js"
|
|
12
13
|
},
|
|
13
14
|
"homepage": "https://github.com/cogniumhq/sharedcontext",
|
|
14
15
|
"keywords": ["nostr", "event-sourcing", "agents", "mcp", "work-tracking"],
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"types": "./dist/index.d.ts",
|
|
22
23
|
"default": "./dist/index.js"
|
|
23
24
|
},
|
|
25
|
+
"./schemas/directory/*": "./schemas/sharedcontext-directory-1/*",
|
|
24
26
|
"./schemas/*": "./schemas/sharedcontext-1/*",
|
|
25
27
|
"./package.json": "./package.json"
|
|
26
28
|
},
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "urn:sharedcontext-directory:1:members",
|
|
4
|
+
"title": "sharedcontext-directory/1 member page",
|
|
5
|
+
"$comment": "The 200 body of GET {base}/orgs/{org_id}/members?limit={n}[&cursor={c}] (required route). A client follows next_cursor until it is null, empty or absent; a repeated cursor is an error. The pages together are the org's complete listing, or the server answers an error: never a silently partial listing (a member missing from it reads as gone from the org). Fields not named here are ignored by a client (additive changes stay v1; a breaking change is v2). Contract: docs/directory-http.md. Client: src/directory/http.rs.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["members"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"members": {
|
|
10
|
+
"type": "array",
|
|
11
|
+
"items": { "$ref": "#/$defs/Member" }
|
|
12
|
+
},
|
|
13
|
+
"next_cursor": { "$ref": "#/$defs/NextCursor" }
|
|
14
|
+
},
|
|
15
|
+
"$defs": {
|
|
16
|
+
"NextCursor": {
|
|
17
|
+
"type": ["string", "null"],
|
|
18
|
+
"maxLength": 1024,
|
|
19
|
+
"$comment": "Opaque to the client, which sends it back as ?cursor= (percent-encoded) with the same org and limit, and never parses it. null, empty or absent: this is the last page. A server may answer a cursor issued for another org 400."
|
|
20
|
+
},
|
|
21
|
+
"Id": { "type": "string", "minLength": 1, "maxLength": 256 },
|
|
22
|
+
"Member": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"required": ["member_id", "org_id", "user_id", "kind", "role", "lifecycle", "teams", "keys"],
|
|
25
|
+
"properties": {
|
|
26
|
+
"member_id": { "$ref": "#/$defs/Id", "description": "The member's id in the directory; stable for the member's life." },
|
|
27
|
+
"org_id": { "$ref": "#/$defs/Id", "description": "Always the org of the request: a member of another org fails the whole read." },
|
|
28
|
+
"user_id": { "type": "string", "maxLength": 256, "description": "The user behind a person member; may be empty for an agent." },
|
|
29
|
+
"kind": { "enum": ["person", "agent"] },
|
|
30
|
+
"role": { "type": "string", "maxLength": 128, "description": "The org role (owner, admin, member or a custom role), or several comma-separated; may be empty (read as member)." },
|
|
31
|
+
"title": { "type": ["string", "null"], "maxLength": 256 },
|
|
32
|
+
"lifecycle": { "enum": ["active", "paused", "retired"] },
|
|
33
|
+
"sponsor_member_id": { "type": ["string", "null"], "maxLength": 256, "description": "Agents: the sponsoring member (a person of the same org)." },
|
|
34
|
+
"teams": { "type": "array", "items": { "$ref": "#/$defs/Id" }, "description": "Team ids." },
|
|
35
|
+
"keys": { "type": "array", "items": { "$ref": "#/$defs/Key" }, "description": "The member's Nostr keys, revoked ones included (with revoked_at); at most one unrevoked." },
|
|
36
|
+
"sponsor_active": { "type": ["boolean", "null"], "description": "Agents: the directory's own view of whether the sponsor is active (read for drift only)." }
|
|
37
|
+
},
|
|
38
|
+
"if": { "required": ["kind"], "properties": { "kind": { "const": "agent" } } },
|
|
39
|
+
"then": { "required": ["sponsor_member_id"], "properties": { "sponsor_member_id": { "type": "string", "minLength": 1 } } },
|
|
40
|
+
"$comment": "Optional fields (title, sponsor_member_id, sponsor_active, a key's revoked_at) are best omitted; a client accepts null too. An agent always carries its sponsor_member_id."
|
|
41
|
+
},
|
|
42
|
+
"Key": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"required": ["pubkey", "custody"],
|
|
45
|
+
"properties": {
|
|
46
|
+
"pubkey": { "type": "string", "pattern": "^[0-9a-f]{64}$", "description": "x-only public key, 64 lowercase hex." },
|
|
47
|
+
"custody": { "enum": ["self", "directory"], "description": "self: the member holds it (a person); directory: the directory holds it and signs with it (an agent's minted key)." },
|
|
48
|
+
"revoked_at": { "type": ["string", "null"], "maxLength": 64, "description": "Set when the key was revoked (RFC 3339); a revoked key maps to nothing." }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "urn:sharedcontext-directory:1:memberships",
|
|
4
|
+
"title": "sharedcontext-directory/1 membership page",
|
|
5
|
+
"$comment": "The 200 body of GET {base}/users/{user_id}/memberships?limit={n}[&cursor={c}] (optional route: 404 or 501 means the directory does not offer it). Paged like the member listing (members.schema.json), with the same complete-or-error rule. Fields not named here are ignored by a client. Contract: docs/directory-http.md. Client: src/directory/http.rs.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["memberships"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"memberships": {
|
|
10
|
+
"type": "array",
|
|
11
|
+
"items": { "$ref": "#/$defs/Membership" }
|
|
12
|
+
},
|
|
13
|
+
"next_cursor": {
|
|
14
|
+
"type": ["string", "null"],
|
|
15
|
+
"maxLength": 1024,
|
|
16
|
+
"$comment": "As in members.schema.json: opaque; null, empty or absent on the last page."
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"$defs": {
|
|
20
|
+
"Membership": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"required": ["org_id", "member_id", "kind", "role", "lifecycle"],
|
|
23
|
+
"properties": {
|
|
24
|
+
"org_id": { "type": "string", "minLength": 1, "maxLength": 256 },
|
|
25
|
+
"member_id": { "type": "string", "minLength": 1, "maxLength": 256 },
|
|
26
|
+
"kind": { "enum": ["person", "agent"] },
|
|
27
|
+
"role": { "type": "string", "maxLength": 128 },
|
|
28
|
+
"lifecycle": { "enum": ["active", "paused", "retired"] }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|