@blueshed/joined 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/joined/reference.md +12 -3
- package/.claude/skills/joined-door/SKILL.md +1 -1
- package/package.json +1 -1
- package/src/mcp.ts +29 -9
- package/src/server.ts +37 -8
- package/src/skill.ts +19 -10
- package/src/upload.ts +2 -1
|
@@ -444,11 +444,19 @@ export const routes = (read: Read) => ({ "/trip/:n": page, "/trip/:n/trip.ics":
|
|
|
444
444
|
- **An open route** (`export const open = (read) => ({ "/card/:id": (req) => … })`) is anyone's, never guarded by
|
|
445
445
|
the group: a link's preview (og:title, og:image), a card for a stranger. Its `read` is as nobody (member 0):
|
|
446
446
|
owns and sees apply, so a part only some see isn't there, but the group's door doesn't: a document any member
|
|
447
|
-
sees whole is whole. So an open route shows only what it picks, and what it picks is public.
|
|
447
|
+
sees whole is whole. So an open route shows only what it picks, and what it picks is public. One that checks a
|
|
448
|
+
secret of its own (a mail's intake, a webhook) takes the server's `write` and `whole` too
|
|
449
|
+
(`open = (read, write, whole) => …`): `whole(doc)` is every item, as the server holds it, for it to find what it
|
|
450
|
+
needs (whose address a mail came to); what it answers is still its own to pick (`tests/apart/board/routes.ts`).
|
|
448
451
|
- **Two apps answering one path** are refused at start, open routes too.
|
|
449
452
|
- **The server writes** with the `write` a routes function is given beside `read` (`routes(read, write)`):
|
|
450
453
|
a webhook, an import, a job on the app's own timer. `write(doc, ops)` is shaped by the stories (only what
|
|
451
454
|
a story does), never asked of roles or `trust.ts`, by nobody, and told as any write; it throws `Refused`.
|
|
455
|
+
`write(doc, ops, { member, via, why, file })` is a member's write in place of nobody's (a paper a mail brought,
|
|
456
|
+
its member's): asked of their grants, the app's trust and the group's, as an agent's is, a member still in the
|
|
457
|
+
group; its change says `via` (a page shows "Peter via mail"), and its `why`; a `file` (`{ bytes, name }`) is kept
|
|
458
|
+
first, as a page's is (where they may put one, apart where the kind keeps them so), `"$file"` in the ops standing
|
|
459
|
+
for its value; answered `{ done, version, ids, file }`.
|
|
452
460
|
Never the group's document, and never a document's content from files at start: that's its seed (§13).
|
|
453
461
|
- **What follows from a write** is a rule over values where a definition can say it (`takes`: an order
|
|
454
462
|
taking stock, in the database, undone as the write is), and otherwise
|
|
@@ -620,8 +628,9 @@ Working: `src/icons.ts`; the members panel and every example.
|
|
|
620
628
|
kind's take `key`; a window isn't one (read the document). The door carries its own skill, how any document is
|
|
621
629
|
read and written there (`.claude/skills/joined-door/SKILL.md`, the one text, `src/skill.ts`): by MCP's skills
|
|
622
630
|
extension (`io.modelcontextprotocol/skills`, declared in `server/discover`; `skills/list`, `skills/get`, the
|
|
623
|
-
resource `skill://joined-door/SKILL.md`), and
|
|
624
|
-
|
|
631
|
+
resource `skill://joined-door/SKILL.md`), and by `read_skill`, a tool, which every client loads. Its instructions
|
|
632
|
+
are a few lines to every client, so none cuts them off (`opening`): its documents, who the agent acts as (its
|
|
633
|
+
member's id, so a field linking members is read), and where the skills are; nothing a skill says. Beside it each app has a skill of its own, served the same way
|
|
625
634
|
(`skill://<app>/SKILL.md`, written by `skillOf`): its words, then what each of its documents holds (its fields' types,
|
|
626
635
|
what a link is an id of, what an add needs, its tools), from the compiled rules as the tools are. Its words are its
|
|
627
636
|
`routes.ts`'s `instructions` (`examples/trip/routes.ts`), what's its own alone (what its documents mean, its people,
|
|
@@ -9,7 +9,7 @@ An app on joined keeps its documents, and every page open on them, in step. Its
|
|
|
9
9
|
document your link may hold: `read_<doc>` and `write_<doc>` (a document you can't write has only its read). Their
|
|
10
10
|
descriptions say what each document holds and each op it takes: read them, they're written from the app's own rules.
|
|
11
11
|
A document that names files has `upload_<doc>` too. Each app has a skill of its own beside this one: its words, and
|
|
12
|
-
what each of its documents holds.
|
|
12
|
+
what each of its documents holds. Where your client doesn't load skills, `read_skill` reads any of them whole.
|
|
13
13
|
|
|
14
14
|
## Read first
|
|
15
15
|
|
package/package.json
CHANGED
package/src/mcp.ts
CHANGED
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
// as the grants allow; a kind's (trip:1) take the instance's key. A window isn't a tool's: a document is read as its
|
|
9
9
|
// member sees it, whole or one collection's items (some, by id). How any document is read and written here is the
|
|
10
10
|
// door's own skill (src/skill.ts), served by MCP's skills extension beside each app's own (its words, its routes.ts's
|
|
11
|
-
// `instructions`, and what its documents hold, from their rules), and
|
|
11
|
+
// `instructions`, and what its documents hold, from their rules), and by read_skill, a tool, to a client that doesn't
|
|
12
|
+
// load skills. A document that names files
|
|
12
13
|
// has upload_<doc> too: a link the server makes for the agent's member to send a file by (src/upload.ts), since the
|
|
13
14
|
// agent never sees its own key. It speaks both eras of MCP: the modern (2026-07-28), each request saying its
|
|
14
15
|
// version and the client's capabilities in its _meta, its headers checked against its body, server/discover in place
|
|
15
|
-
// of a handshake, and the skills extension declared; and the legacy, opened by initialize.
|
|
16
|
-
//
|
|
16
|
+
// of a handshake, and the skills extension declared; and the legacy, opened by initialize. Its instructions are a few
|
|
17
|
+
// lines to every client, so none is cut off: its documents, who the agent acts as, and where the skills are.
|
|
17
18
|
|
|
18
19
|
import { FORMS, SAID } from "./compile.ts";
|
|
19
|
-
import {
|
|
20
|
+
import { opening, skill, skillOf, SKILLS } from "./skill.ts";
|
|
20
21
|
import type { Made } from "./upload.ts";
|
|
21
22
|
import { schemeOf } from "./proxy.ts";
|
|
22
23
|
import type { Who } from "./members/group.ts";
|
|
@@ -224,7 +225,7 @@ export function door(d: Door) {
|
|
|
224
225
|
return rules.length ? [skillOf(a.app, a.words, rules)] : [];
|
|
225
226
|
});
|
|
226
227
|
const skills = [skill, ...apps],
|
|
227
|
-
|
|
228
|
+
docs = d.rules.map((r) => (r.kind ? `${r.doc}:<key>` : r.doc));
|
|
228
229
|
const skillAt = (uri: unknown) => skills.find((s) => s.uri === uri);
|
|
229
230
|
|
|
230
231
|
/** The tools for a member's agent: each document's read and, where pages write it, its write; a kind's take its key. */
|
|
@@ -235,7 +236,24 @@ export function door(d: Door) {
|
|
|
235
236
|
inputSchema: Schema;
|
|
236
237
|
annotations: Schema;
|
|
237
238
|
run(args: any): Promise<Result> | Result;
|
|
238
|
-
}[] = [
|
|
239
|
+
}[] = [
|
|
240
|
+
{
|
|
241
|
+
name: "read_skill",
|
|
242
|
+
description: `One of this door's skills, its SKILL.md whole, for a client that doesn't load skills itself: ${skill.name}, how any document here is read and written${apps.length ? `; ${apps.map((a) => a.name).join(", ")}, what each app's documents hold and mean` : ""}. Read them before a write.`,
|
|
243
|
+
inputSchema: {
|
|
244
|
+
type: "object",
|
|
245
|
+
properties: { name: { type: "string", enum: skills.map((s) => s.name) } },
|
|
246
|
+
required: ["name"],
|
|
247
|
+
},
|
|
248
|
+
annotations: { readOnlyHint: true },
|
|
249
|
+
run: (args) => {
|
|
250
|
+
const asked = skills.find((s) => s.name === args.name);
|
|
251
|
+
return asked
|
|
252
|
+
? { content: [{ type: "text", text: asked.text }] }
|
|
253
|
+
: refused(`name: one of ${skills.map((s) => s.name).join(", ")}`);
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
];
|
|
239
257
|
for (const r of d.rules) {
|
|
240
258
|
// the document a call names: a kind's instance by its key (trip:1), or the one
|
|
241
259
|
const name = (args: { key?: unknown }) => (r.kind ? `${r.doc}:${args.key}` : r.doc);
|
|
@@ -371,9 +389,11 @@ export function door(d: Door) {
|
|
|
371
389
|
m.id,
|
|
372
390
|
modern ? { resultType: "complete", ...result, ...(kept ? { ttlMs: 0, cacheScope: kept } : {}) } : result,
|
|
373
391
|
);
|
|
374
|
-
// to
|
|
375
|
-
const
|
|
376
|
-
|
|
392
|
+
// the same few lines to every client: who the agent acts as, its member by id, so a document naming members is read
|
|
393
|
+
const as = d.anyone
|
|
394
|
+
? "anyone, as a stranger's page does"
|
|
395
|
+
: `member ${who.member}, by the link called ${JSON.stringify(who.agent?.label)}`;
|
|
396
|
+
const instructions = opening(apps, docs, as);
|
|
377
397
|
if (modern && m.method === "server/discover")
|
|
378
398
|
return done(
|
|
379
399
|
{
|
package/src/server.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { doc as GROUP } from "./members/generated/rules.ts";
|
|
|
23
23
|
import { groupOf, say, type Data, type Who } from "./members/group.ts";
|
|
24
24
|
import { fromHere } from "./members/demo.ts";
|
|
25
25
|
import { door, type Written } from "./mcp.ts";
|
|
26
|
-
import { uploads, type Uploads } from "./upload.ts";
|
|
26
|
+
import { filled, uploads, type Uploads } from "./upload.ts";
|
|
27
27
|
import { bdflOf, type Asked, type Member } from "./members/trust.ts";
|
|
28
28
|
import {
|
|
29
29
|
attribute,
|
|
@@ -47,7 +47,7 @@ export { Refused };
|
|
|
47
47
|
export type { Reactions, Read, Trust };
|
|
48
48
|
import { upkeep, KEEP } from "./upkeep.ts";
|
|
49
49
|
import { folderOf } from "./file-value.ts";
|
|
50
|
-
import { filesAt, letGo, named, putsFile, routes as fileRoutes, type Files } from "./files.ts";
|
|
50
|
+
import { filesAt, keep, letGo, named, putsFile, routes as fileRoutes, type Files } from "./files.ts";
|
|
51
51
|
import { version } from "../package.json";
|
|
52
52
|
|
|
53
53
|
/** How many documents a page holds at once (each write views every one held): past it, one is let go first. */
|
|
@@ -148,8 +148,17 @@ const ICON = `${import.meta.dir}/icon.png`;
|
|
|
148
148
|
|
|
149
149
|
/** A write by the server itself, a route's or a job's: shaped as the stories say, but asked of no roles and no
|
|
150
150
|
* trust.ts, since it's the app's own; landed with what follows from it, and told. Its change, or Refused, once it
|
|
151
|
-
* has (await it). A route reads what it needs before it writes.
|
|
152
|
-
|
|
151
|
+
* has (await it). A route reads what it needs before it writes. Given `as`, it's a member's write in place of the
|
|
152
|
+
* server's (a paper a mail brought, its member's), made as an agent's is: under their grants, the app's trust and the
|
|
153
|
+
* group's, via the label it names, so every page says whose it is and how it came ("Peter via mail"); and with a file,
|
|
154
|
+
* the file kept first, as a page's is, where its member may put one, "$file" in the ops standing for it. Answered
|
|
155
|
+
* done, with its version, the ids it added, and the file's value; or Refused. */
|
|
156
|
+
export type Write = {
|
|
157
|
+
(doc: string, ops: Op[]): Promise<Change>;
|
|
158
|
+
(doc: string, ops: Op[], as: As): Promise<Written & { done: true; file?: string }>;
|
|
159
|
+
};
|
|
160
|
+
/** Whose a route's write is: a member of the group, via what (its label, as an agent's), why, and a file it brings. */
|
|
161
|
+
export type As = { member: number; via: string; why?: string; file?: { bytes: Uint8Array; name: string } };
|
|
153
162
|
/** A derived document (its app's derive.ts, exported from its routes.ts): what it is now, for a member (nobody, 0),
|
|
154
163
|
* read off the documents it's derived from. Read-only: its pages write the documents it's read from. */
|
|
155
164
|
export type Derive = (read: Read, member: number) => Record<string, { id: number }[]>;
|
|
@@ -188,8 +197,10 @@ type App = {
|
|
|
188
197
|
routes?: Routes | ((read: Read, write: Write) => Routes);
|
|
189
198
|
/** Routes anyone may ask, reading each document as nobody (member 0): owns and sees apply, so a part only some see
|
|
190
199
|
* isn't there, but the group's door doesn't, so a document any member sees whole is whole. An open route shows only
|
|
191
|
-
* what it picks, and what it picks is public.
|
|
192
|
-
|
|
200
|
+
* what it picks, and what it picks is public. One that checks a secret of its own (a mail's intake, a webhook) is
|
|
201
|
+
* given the server's write, and `whole`, each document as the server holds it, every item: what it answers is still
|
|
202
|
+
* its own to pick. */
|
|
203
|
+
open?: Open | ((read: Read, write: Write, whole: Read) => Open);
|
|
193
204
|
trust?: Trust;
|
|
194
205
|
reactions?: Reactions;
|
|
195
206
|
derive?: Derive;
|
|
@@ -462,7 +473,8 @@ export async function start({
|
|
|
462
473
|
const may = await asking;
|
|
463
474
|
if (fresh(ws, `may ${doc}`, JSON.stringify(may))) say(ws, { doc, may });
|
|
464
475
|
}
|
|
465
|
-
const write
|
|
476
|
+
const write = (async (doc: string, ops: Op[], as?: As) => {
|
|
477
|
+
if (as) return writeAs(doc, ops, as);
|
|
466
478
|
wrote();
|
|
467
479
|
if (docParts(doc).name === GROUP || !(await store.exists(doc))) throw new Refused(`the server can't write ${doc}`);
|
|
468
480
|
const why = await ungranted(doc, ops, null);
|
|
@@ -471,6 +483,23 @@ export async function start({
|
|
|
471
483
|
await tell(landed);
|
|
472
484
|
retime();
|
|
473
485
|
return landed.changes[0]!;
|
|
486
|
+
}) as Write;
|
|
487
|
+
/** A route's write as a member, via its label (Write's `as`): a member of the group still, the file kept first. */
|
|
488
|
+
const writeAs = async (doc: string, ops: Op[], as: As) => {
|
|
489
|
+
if (!members || !((await read(GROUP)).members as Member[]).some((m) => m.id === as.member))
|
|
490
|
+
throw new Refused(`member ${as.member} isn't in the group`);
|
|
491
|
+
const who: Who = { member: as.member, token: "", agent: { id: `via ${as.via}`, member: as.member, label: as.via } };
|
|
492
|
+
let file: string | undefined;
|
|
493
|
+
if (as.file) {
|
|
494
|
+
const no = await mayPutAs(doc, who);
|
|
495
|
+
if (no) throw new Refused(no);
|
|
496
|
+
const kept = await keep(filesKept, as.file.bytes, as.file.name, (await apart(doc)) ? folderOf(doc) : "");
|
|
497
|
+
if ("refused" in kept) throw new Refused(kept.refused);
|
|
498
|
+
file = kept.file;
|
|
499
|
+
}
|
|
500
|
+
const w = await written([{ doc, ops: file ? filled(ops, file) : ops, ...(as.why ? { why: as.why } : {}) }], who);
|
|
501
|
+
if ("why" in w) throw new Refused(w.why);
|
|
502
|
+
return file ? { ...w, file } : w;
|
|
474
503
|
};
|
|
475
504
|
/** A change undone: its inverse, guarded as delta's walk is (refused if a value it changed has been changed
|
|
476
505
|
* since), written as the server's own write, by whoever undoes it, and told as any change is; what the rules
|
|
@@ -698,7 +727,7 @@ export async function start({
|
|
|
698
727
|
// door doesn't), so each shows only what it picks
|
|
699
728
|
const nobody: Read = (doc) => now(doc, 0);
|
|
700
729
|
for (const { app, open: of = {} } of apps)
|
|
701
|
-
for (const [path, answer] of Object.entries(typeof of === "function" ? of(nobody) : of)) {
|
|
730
|
+
for (const [path, answer] of Object.entries(typeof of === "function" ? of(nobody, write, now) : of)) {
|
|
702
731
|
if (path in routes) throw new Error(`${app || "the root"} and another app both answer ${path}`);
|
|
703
732
|
routes[path] = typeof answer === "function" ? settled(answer) : answer;
|
|
704
733
|
}
|
package/src/skill.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// The door's skills, served as MCP's skills extension (SEP-2640, io.modelcontextprotocol/skills) says: each SKILL.md a
|
|
2
2
|
// resource at skill://<name>/SKILL.md, and its entry (its frontmatter as written, each file's sha256 digest and size)
|
|
3
3
|
// for skills/list and skills/get. The door's own (.claude/skills/joined-door): how any joined document is read and
|
|
4
|
-
// written, one text read from its file,
|
|
4
|
+
// written, one text read from its file, never kept apart from it. And each
|
|
5
5
|
// app's: what its documents hold and mean, its own words (its routes.ts's `instructions`) and its documents' shapes,
|
|
6
|
-
// written from their compiled rules as their tools are, so it says what the app holds and never another thing.
|
|
6
|
+
// written from their compiled rules as their tools are, so it says what the app holds and never another thing. What the
|
|
7
|
+
// door says as it opens says none of it: where they are, and who's acting.
|
|
7
8
|
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
9
10
|
import type { Rules } from "./write.ts";
|
|
@@ -47,13 +48,19 @@ function served(text: string) {
|
|
|
47
48
|
/** The door's own skill. */
|
|
48
49
|
export const skill = served(await Bun.file(new URL("../.claude/skills/joined-door/SKILL.md", import.meta.url)).text());
|
|
49
50
|
|
|
50
|
-
/** What
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
/** What the door says as it opens, to every client alike: short, so no client cuts it, and nothing a skill says, so
|
|
52
|
+
* each fact is in one place. Its documents, who's acting, and where the skills are: as the client loads skills, or by
|
|
53
|
+
* read_skill, a tool, which every client loads. */
|
|
54
|
+
export const opening = (apps: Skill[], docs: string[], as: string) =>
|
|
55
|
+
[
|
|
56
|
+
`This is a joined app's door: its documents are ${docs.join(", ") || "none"}. You act as ${as}.`,
|
|
57
|
+
`How any document here is read and written is the skill ${skill.name}${
|
|
58
|
+
apps.length
|
|
59
|
+
? `, and what each app's documents hold and mean is its own skill: ${apps.map((a) => a.name).join(", ")}`
|
|
60
|
+
: ""
|
|
61
|
+
}. Load ${apps.length ? "them" : "it"} before a write, as your client loads skills, or by read_skill.`,
|
|
62
|
+
"Read before you write; a write is made whole or not at all.",
|
|
63
|
+
].join(" ");
|
|
57
64
|
|
|
58
65
|
type Collection = Rules["collections"][string] & { needs?: readonly string[] };
|
|
59
66
|
|
|
@@ -63,7 +70,9 @@ const fieldsOf = (c: Collection) =>
|
|
|
63
70
|
.filter(([f]) => !(f in (c.fills ?? {})))
|
|
64
71
|
.map(([f, t]) => {
|
|
65
72
|
const to = c.links?.[f];
|
|
66
|
-
|
|
73
|
+
// the group's members are no document's collection: said as who they are (the door says which the agent's is)
|
|
74
|
+
const member = t === "ids" ? "members' ids, people in the group" : "a member's id, a person in the group";
|
|
75
|
+
const said = to === "members" ? member : to ? (t === "ids" ? `ids of ${to}` : `an id of ${to}`) : t;
|
|
67
76
|
return `${f} (${said}${c.needs?.includes(f) ? ", needed" : ""})`;
|
|
68
77
|
})
|
|
69
78
|
.join(", ");
|
package/src/upload.ts
CHANGED
|
@@ -34,7 +34,8 @@ type Link = { doc: string; who: Who | null; name: string; until: number; ops?: O
|
|
|
34
34
|
export type Made = { url: string; until: string } | { why: string };
|
|
35
35
|
|
|
36
36
|
/** A write's ops with the file's value where "$file" stood. */
|
|
37
|
-
const filled = (ops: Op[], file: string): Op[] =>
|
|
37
|
+
export const filled = (ops: Op[], file: string): Op[] =>
|
|
38
|
+
JSON.parse(JSON.stringify(ops), (_, v) => (v === FILE ? file : v));
|
|
38
39
|
|
|
39
40
|
const escaped = (s: string) =>
|
|
40
41
|
s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]!);
|