@sharedcontext/sdk 0.0.0-stage → 0.2.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-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +8 -0
- package/README.md +84 -2
- package/dist/canonical.d.ts +47 -0
- package/dist/canonical.js +257 -0
- package/dist/client.d.ts +96 -0
- package/dist/client.js +205 -0
- package/dist/constants.d.ts +19 -0
- package/dist/constants.js +21 -0
- package/dist/event.d.ts +104 -0
- package/dist/event.js +173 -0
- package/dist/generated/content.d.ts +588 -0
- package/dist/generated/content.js +3 -0
- package/dist/generated/schemas.d.ts +5 -0
- package/dist/generated/schemas.js +15 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/reasons.d.ts +14 -0
- package/dist/reasons.js +142 -0
- package/dist/schema.d.ts +29 -0
- package/dist/schema.js +265 -0
- package/dist/types.d.ts +230 -0
- package/dist/types.js +3 -0
- package/package.json +44 -4
- package/schemas/sharedcontext-1/changes.schema.json +128 -0
- package/schemas/sharedcontext-1/content.schema.json +2076 -0
- package/schemas/sharedcontext-1/context.schema.json +218 -0
- package/schemas/sharedcontext-1/event.schema.json +55 -0
- package/schemas/sharedcontext-1/execution.schema.json +342 -0
- package/schemas/sharedcontext-1/history/content-1.0.schema.json +1915 -0
- package/schemas/sharedcontext-1/lineage.schema.json +753 -0
- package/schemas/sharedcontext-1/mcp-tools.schema.json +1357 -0
- package/schemas/sharedcontext-1/stored-event.schema.json +14 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import type { Json } from "./canonical.js";
|
|
2
|
+
import type { SignedEvent } from "./event.js";
|
|
3
|
+
/** A tool as `tools/list` answers it. */
|
|
4
|
+
export interface ToolInfo {
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
inputSchema?: {
|
|
8
|
+
[key: string]: Json;
|
|
9
|
+
};
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
/** What a write answers (`Appended`). */
|
|
13
|
+
export interface Appended {
|
|
14
|
+
seq: number;
|
|
15
|
+
id: string;
|
|
16
|
+
/** True when the event was already in the log (an exact resend). */
|
|
17
|
+
duplicate: boolean;
|
|
18
|
+
/** Events the service appended with it (new events only). */
|
|
19
|
+
reactions?: Array<{
|
|
20
|
+
seq: number;
|
|
21
|
+
w: string | null;
|
|
22
|
+
node: string | null;
|
|
23
|
+
id: string;
|
|
24
|
+
}>;
|
|
25
|
+
/** The node after the write. */
|
|
26
|
+
node?: {
|
|
27
|
+
id: string;
|
|
28
|
+
state: string;
|
|
29
|
+
claim?: unknown;
|
|
30
|
+
closed?: unknown;
|
|
31
|
+
covers?: unknown[];
|
|
32
|
+
gate?: unknown;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
/** A refused call's structured error (`Refusal`). */
|
|
38
|
+
export interface Refusal {
|
|
39
|
+
reason: string;
|
|
40
|
+
detail?: unknown;
|
|
41
|
+
hint?: string;
|
|
42
|
+
}
|
|
43
|
+
/** The unsigned body `draft` and `claim_next` answer (`Unsigned`): sign it and send it to `submit`. */
|
|
44
|
+
export interface Unsigned {
|
|
45
|
+
pubkey: string;
|
|
46
|
+
created_at: number;
|
|
47
|
+
kind: 7411;
|
|
48
|
+
tags: string[][];
|
|
49
|
+
content: string;
|
|
50
|
+
}
|
|
51
|
+
/** A `claim_next` reservation (`Reservation`). */
|
|
52
|
+
export interface Reservation {
|
|
53
|
+
node: string;
|
|
54
|
+
pubkey: string;
|
|
55
|
+
until_ms: number;
|
|
56
|
+
}
|
|
57
|
+
/** `next` and `ready` (`NextArgs`). */
|
|
58
|
+
export interface NextArgs {
|
|
59
|
+
kind?: string | null;
|
|
60
|
+
/** Default 10. */
|
|
61
|
+
limit?: number | null;
|
|
62
|
+
/** The caller's pubkey. */
|
|
63
|
+
viewer?: string | null;
|
|
64
|
+
}
|
|
65
|
+
/** One claimable node of `next`. */
|
|
66
|
+
export interface NextEntry {
|
|
67
|
+
node: string;
|
|
68
|
+
kind: string;
|
|
69
|
+
title?: string | null;
|
|
70
|
+
severity?: string | null;
|
|
71
|
+
state: string;
|
|
72
|
+
covers?: number;
|
|
73
|
+
handoff?: unknown;
|
|
74
|
+
blocks?: string[];
|
|
75
|
+
goal_weight?: unknown;
|
|
76
|
+
unblock_count?: unknown;
|
|
77
|
+
goals?: unknown[];
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
/** What `next` answers (`NextResult`). */
|
|
81
|
+
export interface NextResult {
|
|
82
|
+
now: number;
|
|
83
|
+
swept: Array<{
|
|
84
|
+
seq: number;
|
|
85
|
+
w: string | null;
|
|
86
|
+
node: string | null;
|
|
87
|
+
}>;
|
|
88
|
+
next: NextEntry[];
|
|
89
|
+
alias_of?: "next";
|
|
90
|
+
}
|
|
91
|
+
/** `claim_next` (the claim fields of `WriteArgs`). */
|
|
92
|
+
export interface ClaimNextArgs {
|
|
93
|
+
/** A signed `claim.taken`: one call. */
|
|
94
|
+
event?: SignedEvent | string;
|
|
95
|
+
/** Without `event`: the claimant's x-only pubkey, for a reservation and its unsigned claim. */
|
|
96
|
+
pubkey?: string | null;
|
|
97
|
+
/** fix · triage · review · verify (default fix). */
|
|
98
|
+
intent?: string | null;
|
|
99
|
+
/** Only these node kinds. */
|
|
100
|
+
kinds?: string[] | null;
|
|
101
|
+
/** Labels the node must carry. */
|
|
102
|
+
labels?: string[] | null;
|
|
103
|
+
[key: string]: unknown;
|
|
104
|
+
}
|
|
105
|
+
/** What `claim_next` answers (`ClaimNextResult`). */
|
|
106
|
+
export type ClaimNextResult = (Appended & {
|
|
107
|
+
claimed: string;
|
|
108
|
+
}) | {
|
|
109
|
+
claimed: null;
|
|
110
|
+
hint?: string;
|
|
111
|
+
} | {
|
|
112
|
+
reserved: Reservation;
|
|
113
|
+
unsigned: Unsigned;
|
|
114
|
+
hint?: string;
|
|
115
|
+
} | {
|
|
116
|
+
reserved: null;
|
|
117
|
+
hint?: string;
|
|
118
|
+
};
|
|
119
|
+
/** What `draft` answers (`DraftResult`). */
|
|
120
|
+
export interface DraftResult {
|
|
121
|
+
tool: string;
|
|
122
|
+
unsigned: Unsigned;
|
|
123
|
+
hint?: string;
|
|
124
|
+
}
|
|
125
|
+
/** What `close` answers when the rule holds (`CloseResult`). */
|
|
126
|
+
export interface CloseResult {
|
|
127
|
+
evidence: unknown;
|
|
128
|
+
appended: Appended;
|
|
129
|
+
}
|
|
130
|
+
/** `subscribe` (`SubscribeArgs`). */
|
|
131
|
+
export interface SubscribeArgs {
|
|
132
|
+
after_seq: number;
|
|
133
|
+
node?: string | null;
|
|
134
|
+
/** Default 100. */
|
|
135
|
+
limit?: number | null;
|
|
136
|
+
}
|
|
137
|
+
/** One event of a `subscribe` page. */
|
|
138
|
+
export interface StreamEvent {
|
|
139
|
+
seq: number;
|
|
140
|
+
received_at: number;
|
|
141
|
+
w: string | null;
|
|
142
|
+
node: string | null;
|
|
143
|
+
id: string;
|
|
144
|
+
pubkey: string;
|
|
145
|
+
/** The content parsed as JSON, or null. */
|
|
146
|
+
content: {
|
|
147
|
+
[key: string]: Json;
|
|
148
|
+
} | null;
|
|
149
|
+
}
|
|
150
|
+
/** What `subscribe` answers (`SubscribeResult`). */
|
|
151
|
+
export interface SubscribeResult {
|
|
152
|
+
after_seq: number;
|
|
153
|
+
head_seq: number;
|
|
154
|
+
/** The seq to send as the next `after_seq`. The service sends it; the schema does not yet pin it. */
|
|
155
|
+
next_after_seq?: number;
|
|
156
|
+
events: StreamEvent[];
|
|
157
|
+
}
|
|
158
|
+
/** A change feed cursor: opaque, sent back as `after`. */
|
|
159
|
+
export type Cursor = string;
|
|
160
|
+
/** `changes` (`ChangesArgs`, closed). */
|
|
161
|
+
export interface ChangesArgs {
|
|
162
|
+
after?: Cursor | null;
|
|
163
|
+
/** 1 to 1000; default 100. */
|
|
164
|
+
limit?: number | null;
|
|
165
|
+
/** Only these kinds (at most 32). */
|
|
166
|
+
kinds?: string[] | null;
|
|
167
|
+
}
|
|
168
|
+
/** One change of a change feed page. */
|
|
169
|
+
export interface Change {
|
|
170
|
+
cursor: Cursor;
|
|
171
|
+
at: number;
|
|
172
|
+
kind: string;
|
|
173
|
+
subject: string;
|
|
174
|
+
ref: string;
|
|
175
|
+
[key: string]: unknown;
|
|
176
|
+
}
|
|
177
|
+
/** What `changes` answers (`ChangesPage`). */
|
|
178
|
+
export interface ChangesPage {
|
|
179
|
+
store: "work" | "directory" | "jobs";
|
|
180
|
+
changes: Change[];
|
|
181
|
+
next_cursor: Cursor;
|
|
182
|
+
head_cursor: Cursor;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A folded node (`state`) or a context bundle (`context`). The contract does not pin it field by
|
|
186
|
+
* field yet; these are the fields a node view has.
|
|
187
|
+
*/
|
|
188
|
+
export interface FoldedView {
|
|
189
|
+
id?: string;
|
|
190
|
+
kind?: string;
|
|
191
|
+
title?: string | null;
|
|
192
|
+
state?: string;
|
|
193
|
+
parent?: string | null;
|
|
194
|
+
children?: string[];
|
|
195
|
+
labels?: string[];
|
|
196
|
+
claim?: {
|
|
197
|
+
holder: string;
|
|
198
|
+
intent: string;
|
|
199
|
+
lease_until: number;
|
|
200
|
+
progress?: string | null;
|
|
201
|
+
[key: string]: unknown;
|
|
202
|
+
} | null;
|
|
203
|
+
gate?: {
|
|
204
|
+
kind: string;
|
|
205
|
+
ref: string;
|
|
206
|
+
[key: string]: unknown;
|
|
207
|
+
} | null;
|
|
208
|
+
closed?: {
|
|
209
|
+
outcome?: string;
|
|
210
|
+
[key: string]: unknown;
|
|
211
|
+
} | null;
|
|
212
|
+
[key: string]: unknown;
|
|
213
|
+
}
|
|
214
|
+
/** What `stats` answers (`StatsResult`). */
|
|
215
|
+
export interface StatsResult {
|
|
216
|
+
events: number;
|
|
217
|
+
nodes: number;
|
|
218
|
+
rejects: number;
|
|
219
|
+
skipped: number;
|
|
220
|
+
registry_versions: number;
|
|
221
|
+
now: number;
|
|
222
|
+
project: string | null;
|
|
223
|
+
insecure_spike: boolean;
|
|
224
|
+
reject_tail: Array<{
|
|
225
|
+
reason: string;
|
|
226
|
+
detail?: unknown;
|
|
227
|
+
w?: unknown;
|
|
228
|
+
}>;
|
|
229
|
+
[key: string]: unknown;
|
|
230
|
+
}
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharedcontext/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
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
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT OR Apache-2.0",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/cogniumhq/sharedcontext"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/cogniumhq/sharedcontext",
|
|
14
|
+
"keywords": ["nostr", "event-sourcing", "agents", "mcp", "work-tracking"],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./schemas/*": "./schemas/sharedcontext-1/*",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist/",
|
|
29
|
+
"schemas/",
|
|
30
|
+
"README.md",
|
|
31
|
+
"NOTICE",
|
|
32
|
+
"LICENSE-MIT",
|
|
33
|
+
"LICENSE-APACHE"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=20"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "node scripts/generate.mjs && tsc -p tsconfig.json",
|
|
40
|
+
"test": "node --test test/*.test.mjs && tsc -p test/consumer/tsconfig.json",
|
|
41
|
+
"prepublishOnly": "npm run build && npm test"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "5.9.3"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "sharedcontext/1 change feed page, changes@1",
|
|
4
|
+
"$comment": "The change feed's page. One way to follow a store's changes after a cursor: the page a follower reads, whichever store answers it. The work log (sharedcontext/1) serves it as the read-only MCP tool `changes` (mcp-tools.schema.json `tool.changes`, its arguments `ChangesArgs`); other stores, such as a directory or a job API, can answer the same page for their own feeds, through the same tool or `GET <base>/changes?after=&limit=&kind=`. A change names what changed and points at it; it never carries the body: a follower reads the body through the store's own read (for the log: `subscribe` or `state`). Additive to sharedcontext/1: no event type, content or existing tool changes, and the v tag stays \"1\". Source: crates/sharedcontext/src/mcp/mod.rs (fn changes_page, fn parse_cursor, the changes tool) and crates/sharedcontext/tests/mcp/changes.rs; served only with `feed.changes` on, off by default. Cases: cases/changes.cases.jsonl.",
|
|
5
|
+
"$defs": {
|
|
6
|
+
"Cursor": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"minLength": 1,
|
|
9
|
+
"maxLength": 128,
|
|
10
|
+
"pattern": "^[A-Za-z0-9._:-]+$",
|
|
11
|
+
"$comment": "Opaque to a follower, defined by the store that issues it; a follower stores it and sends it back, never parses it, never compares cursors of two stores. Exclusive: `after` = c answers the changes after c. The work log's cursor is the decimal seq (`\"0\"` = before the first event). In the code: mcp/mod.rs fn parse_cursor (the seq as a decimal string, no sign, no leading zero; anything else is cursor_invalid)."
|
|
12
|
+
},
|
|
13
|
+
"Store": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"enum": [
|
|
16
|
+
"work",
|
|
17
|
+
"directory",
|
|
18
|
+
"jobs"
|
|
19
|
+
],
|
|
20
|
+
"$comment": "which store's feed answered: work = the work log (sharedcontext/1), directory = an identity service's directory, jobs = a job API. A follower that reads several feeds keeps one cursor per store."
|
|
21
|
+
},
|
|
22
|
+
"Change": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"additionalProperties": false,
|
|
25
|
+
"required": [
|
|
26
|
+
"cursor",
|
|
27
|
+
"at",
|
|
28
|
+
"kind",
|
|
29
|
+
"subject",
|
|
30
|
+
"ref"
|
|
31
|
+
],
|
|
32
|
+
"properties": {
|
|
33
|
+
"cursor": {
|
|
34
|
+
"$ref": "#/$defs/Cursor",
|
|
35
|
+
"$comment": "this change's own position; a follower that stops after it resumes with after = this"
|
|
36
|
+
},
|
|
37
|
+
"at": {
|
|
38
|
+
"type": "integer",
|
|
39
|
+
"minimum": 0,
|
|
40
|
+
"$comment": "unix seconds the store took the change (the log: received_at)"
|
|
41
|
+
},
|
|
42
|
+
"kind": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"minLength": 1,
|
|
45
|
+
"maxLength": 64,
|
|
46
|
+
"$comment": "the store's own vocabulary. work: the event type (e.g. claim.taken); directory: e.g. member.updated; jobs: the job state it entered"
|
|
47
|
+
},
|
|
48
|
+
"subject": {
|
|
49
|
+
"type": "string",
|
|
50
|
+
"minLength": 1,
|
|
51
|
+
"maxLength": 256,
|
|
52
|
+
"$comment": "what changed: work: the node id (the project id for project.* events); directory: the member, team or org id; jobs: the job id"
|
|
53
|
+
},
|
|
54
|
+
"ref": {
|
|
55
|
+
"type": "string",
|
|
56
|
+
"minLength": 1,
|
|
57
|
+
"maxLength": 256,
|
|
58
|
+
"$comment": "where the body is: work: the event id (64 hex); directory: the record's version; jobs: the job id again or its status digest"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"$comment": "lib.rs fn changes_page: cursor = seq, at = received_at_ms / 1000, kind = the event type (tag w), subject = the node id (tag n) or, for an event without one, the project id (tag j), ref = the event id"
|
|
62
|
+
},
|
|
63
|
+
"ChangesPage": {
|
|
64
|
+
"type": "object",
|
|
65
|
+
"additionalProperties": false,
|
|
66
|
+
"required": [
|
|
67
|
+
"store",
|
|
68
|
+
"changes",
|
|
69
|
+
"next_cursor",
|
|
70
|
+
"head_cursor"
|
|
71
|
+
],
|
|
72
|
+
"properties": {
|
|
73
|
+
"store": {
|
|
74
|
+
"$ref": "#/$defs/Store"
|
|
75
|
+
},
|
|
76
|
+
"changes": {
|
|
77
|
+
"type": "array",
|
|
78
|
+
"items": {
|
|
79
|
+
"$ref": "#/$defs/Change"
|
|
80
|
+
},
|
|
81
|
+
"maxItems": 1000
|
|
82
|
+
},
|
|
83
|
+
"next_cursor": {
|
|
84
|
+
"$ref": "#/$defs/Cursor",
|
|
85
|
+
"$comment": "send it as the next `after`; the last position the store scanned: the last change's cursor, or past it when `kinds` left later changes out, or the request's `after` (or the store's start) when nothing is after it"
|
|
86
|
+
},
|
|
87
|
+
"head_cursor": {
|
|
88
|
+
"$ref": "#/$defs/Cursor",
|
|
89
|
+
"$comment": "the store's newest position now; next_cursor = head_cursor means caught up"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"$comment": "lib.rs fn changes_page: store is always work there; next_cursor = the store's next_after_seq (never before after); head_cursor = the head seq (never before next_cursor). Sent as the tool's structured result"
|
|
93
|
+
},
|
|
94
|
+
"ChangesRefusal": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"additionalProperties": false,
|
|
97
|
+
"required": [
|
|
98
|
+
"refused",
|
|
99
|
+
"reason"
|
|
100
|
+
],
|
|
101
|
+
"properties": {
|
|
102
|
+
"refused": {
|
|
103
|
+
"type": "string",
|
|
104
|
+
"enum": [
|
|
105
|
+
"feed_off",
|
|
106
|
+
"cursor_invalid",
|
|
107
|
+
"cursor_ahead",
|
|
108
|
+
"cursor_gone"
|
|
109
|
+
],
|
|
110
|
+
"$comment": "feed_off: the store does not serve the feed (its switch is off; on an MCP binding the tool is simply not listed, so this is the GET binding's answer). cursor_invalid: not a cursor this store issued. cursor_ahead: after is past the head (another store, or a store restored from an older copy: the follower stops). cursor_gone: history before oldest_cursor is no longer kept; the follower rebuilds from the store's own snapshot read, then follows from oldest_cursor (the work log never answers it in 1.x: it is append-only)."
|
|
111
|
+
},
|
|
112
|
+
"reason": {
|
|
113
|
+
"type": "string",
|
|
114
|
+
"maxLength": 512
|
|
115
|
+
},
|
|
116
|
+
"oldest_cursor": {
|
|
117
|
+
"$ref": "#/$defs/Cursor",
|
|
118
|
+
"$comment": "with cursor_gone only"
|
|
119
|
+
},
|
|
120
|
+
"head_cursor": {
|
|
121
|
+
"$ref": "#/$defs/Cursor",
|
|
122
|
+
"$comment": "with cursor_ahead only"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"$comment": "lib.rs fn changes_page: cursor_invalid and cursor_ahead (with head_cursor), sent as a structured error result. The work log never answers cursor_gone (append-only) and never feed_off on MCP (off, the tool is not listed: an unknown tool). A kinds list over the limits is refused with mcp-tools.schema.json's Refusal shape ({reason: invalid_args, detail}), not this one"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|