~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Kicker keeps its spaces in the host's site space type, and publishes itself

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:examples/kicker-site-space
examples/kicker/harness/e2e/flows.spec.mjs+1−1
@@ -190,7 +190,7 @@ const asAlice = async (lxm, params) => {
};
/// The URI of the note on the board whose words begin `text`.
const noteUri = async (text) => {
const space = `at://${world.place}/space/com.example.place.room/self`;
const space = `at://${world.place}/space/fyi.opensocial.siteSpace/room`;
const collection = 'com.example.place.note';
const { records } = await asAlice('fyi.opensocial.listSpaceRecords', { space, collection });
return records.find((r) => r.value.text.startsWith(text)).uri;
examples/kicker/harness/pds.mjs+3−2
@@ -140,8 +140,9 @@ for (const name of names) {
const path = join(dir, f);
return statSync(path).isDirectory() ? all(path) : f.endsWith('.json') ? [path] : [];
});
// The site's space types, and the group host's (its members space).
const spaces = [join(root, 'lexicons'), join(groupHost, 'lexicons')]
// The group host's space types, the one its sites keep records in
// (fyi.opensocial.siteSpace) among them.
const spaces = [join(groupHost, 'lexicons')]
.flatMap(all)
.map((f) => JSON.parse(readFileSync(f, 'utf8')))
.filter((doc) => doc.defs?.main?.type === 'space');
examples/kicker/harness/publish.mjsnew+37−0
@@ -0,0 +1,37 @@
// `just publish <handle>`: Kicker on a group host that is running for
// real, as the founder makes it with the `opensocial` command. The first
// time, the place itself, as seed.mjs makes it (`make`): the group
// `handle`, its host role, its room and calendar, and its label. Every
// time, the site as built (`publish`), in place of the one there. Nobody
// else is made, and nothing is written in its spaces: its members do that.
//
// The command signs in as OPENSOCIAL_AS (a handle) with OPENSOCIAL_PASSWORD
// at PDS_URL, on the host OPENSOCIAL_HOST, as it does anywhere
// (docs/reference/cli.md).
import { execFileSync } from 'node:child_process';
import { join } from 'node:path';
import { make, publish } from './seed.mjs';
import { groupHost } from './world.mjs';
const handle = process.argv[2];
const host = process.env.OPENSOCIAL_HOST;
if (!handle || !host) {
console.error(
'usage: OPENSOCIAL_HOST=… PDS_URL=… OPENSOCIAL_AS=… OPENSOCIAL_PASSWORD=… just publish <handle>'
);
process.exit(2);
}
const run = (...args) =>
execFileSync(join(groupHost, 'target/debug/opensocial'), args, {
stdio: ['ignore', 'inherit', 'inherit']
});
const found = await fetch(`${host}/xrpc/com.atproto.identity.resolveHandle?handle=${handle}`);
if (!found.ok) {
console.log(`→ making ${handle}`);
make(run, handle);
}
console.log(`→ publishing its site`);
publish(run, handle);
console.log(`\n${handle} is at https://${handle}`);
examples/kicker/harness/seed.mjs+67−53
@@ -21,6 +21,9 @@ import { portrait, poster } from './posters.mjs';
import { groupHost, root, serviceAuth } from './world.mjs';
const NS = 'com.example.place';
/// The host's space type for a group's site: the room and the calendar are
/// each a space of it, under their own key, so nothing needs publishing.
const SITE_SPACE = 'fyi.opensocial.siteSpace';
const DAY = 86_400_000;
/// `days` from now, at `hour` UTC on the hour.
@@ -30,35 +33,27 @@ const at = (days, hour) => {
return d.toISOString();
};
/// The kinds of record the site's pages write, each a space and a collection.
/// The kinds of record the site's pages write, each a space, by its type
/// and key, and a collection.
export const WRITES = [
`${NS}.room:${NS}.note`,
`${NS}.room:${NS}.rsvp`,
`${NS}.room:${NS}.card`,
`${NS}.room:${NS}.topic`,
`${NS}.room:${NS}.reply`,
`${NS}.calendar:${NS}.event`
`${SITE_SPACE}/room:${NS}.note`,
`${SITE_SPACE}/room:${NS}.rsvp`,
`${SITE_SPACE}/room:${NS}.card`,
`${SITE_SPACE}/room:${NS}.topic`,
`${SITE_SPACE}/room:${NS}.reply`,
`${SITE_SPACE}/calendar:${NS}.event`
];
/** Makes the place on `world`, with its site; its DID and handle. */
export async function seed(world, { handleDomain = '.groups.test' } = {}) {
const { net, host, did: hostDid } = world;
const who = Object.fromEntries(net.accounts.map((a) => [a.handle.split('.')[0], a]));
const opensocial = (account, ...args) =>
execFileSync(join(groupHost, 'target/debug/opensocial'), args, {
encoding: 'utf8',
env: {
...process.env,
OPENSOCIAL_HOST: host,
PDS_URL: net.pds,
OPENSOCIAL_HOST_DID: hostDid,
OPENSOCIAL_AS: account.handle,
OPENSOCIAL_PASSWORD: account.password
}
});
const handle = `kicker${handleDomain}`;
opensocial(
who.alice,
/**
* Makes the place `handle`, as `run` (the `opensocial` command, as its
* founder) makes it: the group, joined by approval; its host role, which
* admins give; its room and calendar, each a space of the site's type
* under its own key, every member reading each, any member writing in the
* room and hosts and admins in the calendar; and its own label, which the
* site shows folded behind a warning.
*/
export function make(run, handle) {
run(
'group',
'create',
handle,
@@ -69,14 +64,7 @@ export async function seed(world, { handleDomain = '.groups.test' } = {}) {
'--join-policy',
'approval'
);
const place = await fetch(`${host}/xrpc/com.atproto.identity.resolveHandle?handle=${handle}`)
.then((r) => r.json())
.then((r) => r.did);
const space = (kind) => `at://${place}/space/${NS}.${kind}/self`;
// The host role, which admins may give.
opensocial(
who.alice,
run(
'role',
'set',
handle,
@@ -86,24 +74,21 @@ export async function seed(world, { handleDomain = '.groups.test' } = {}) {
'--description',
'Hosts sessions and events.'
);
opensocial(who.alice, 'role', 'grant', handle, 'admin', '--assignable', 'host');
// Its spaces: every member reads each; any member writes in the room,
// hosts and admins in the calendar.
const read = (kind) => ({ role: 'member', scopes: [`space:${NS}.${kind}?action=read`] });
run('role', 'grant', handle, 'admin', '--assignable', 'host');
const read = (kind) => ({
role: 'member',
scopes: [`space:${SITE_SPACE}?skey=${kind}&action=read`]
});
for (const [kind, name, writableBy] of [
['room', 'Room', null],
['calendar', 'Calendar', ['host', 'admin']]
]) {
const access = { grants: [read(kind)] };
if (writableBy) access.writableBy = writableBy.map((role) => ({ role }));
const args = ['--access', JSON.stringify(access), '--name', name, '--skey', 'self'];
opensocial(who.alice, 'space', 'create', handle, `${NS}.${kind}`, ...args);
const args = ['--access', JSON.stringify(access), '--name', name, '--skey', kind];
run('space', 'create', handle, SITE_SPACE, ...args);
}
// Its own label, which the site shows folded behind a warning.
opensocial(
who.alice,
run(
'label',
'define',
handle,
@@ -119,14 +104,17 @@ export async function seed(world, { handleDomain = '.groups.test' } = {}) {
'--default-setting',
'warn'
);
}
// Its site: the app as built (site/dist, `npm run build` there), every
// room's address answered by its index.html; reading the group, its
// members, and its room and calendar whole (`os.records`), reporting
// what members see, and writing each kind of record in the visitor's
// own repo.
opensocial(
who.alice,
/**
* Publishes the site as built (site/dist, `npm run build` there) as the
* place `handle`'s, as `run` does it: every room's address answered by
* its index.html; reading the group, its members, and its room and
* calendar whole, reporting what members see, and writing each kind of
* record in the visitor's own repo.
*/
export function publish(run, handle) {
run(
'site',
'publish',
handle,
@@ -136,12 +124,38 @@ export async function seed(world, { handleDomain = '.groups.test' } = {}) {
'--reads',
'getGroup,listMembers,getSpaceBlob',
'--spaces',
`${NS}.room,${NS}.calendar`,
`${SITE_SPACE}/room,${SITE_SPACE}/calendar`,
'--acts',
'createReport',
'--writes',
WRITES.join(',')
);
}
/** Makes the place on `world`, with its site; its DID and handle. */
export async function seed(world, { handleDomain = '.groups.test' } = {}) {
const { net, host, did: hostDid } = world;
const who = Object.fromEntries(net.accounts.map((a) => [a.handle.split('.')[0], a]));
const opensocial = (account, ...args) =>
execFileSync(join(groupHost, 'target/debug/opensocial'), args, {
encoding: 'utf8',
env: {
...process.env,
OPENSOCIAL_HOST: host,
PDS_URL: net.pds,
OPENSOCIAL_HOST_DID: hostDid,
OPENSOCIAL_AS: account.handle,
OPENSOCIAL_PASSWORD: account.password
}
});
const handle = `kicker${handleDomain}`;
const asAlice = (...args) => opensocial(who.alice, ...args);
make(asAlice, handle);
publish(asAlice, handle);
const place = await fetch(`${host}/xrpc/com.atproto.identity.resolveHandle?handle=${handle}`)
.then((r) => r.json())
.then((r) => r.did);
const space = (kind) => `at://${place}/space/${SITE_SPACE}/${kind}`;
// Who is in it: bob, carol and dan let in, bob a host; erin asking.
const ask = async (account) => {
examples/kicker/lexicons/com/example/place/calendar.jsondeleted+0−15
@@ -1,15 +0,0 @@
{
"lexicon": 1,
"id": "com.example.place.calendar",
"defs": {
"main": {
"type": "space",
"key": "literal:self",
"name": "Place: calendar",
"description": "A place's events, each in the repo of the host who wrote it, written by its hosts and admins alone and read by its members.",
"collections": [
"com.example.place.event"
]
}
}
}
examples/kicker/lexicons/com/example/place/room.jsondeleted+0−17
@@ -1,17 +0,0 @@
{
"lexicon": 1,
"id": "com.example.place.room",
"defs": {
"main": {
"type": "space",
"key": "literal:self",
"name": "Place: room",
"description": "A place's room: what its members pin to the board, their answers to its events, and their cards, each in their own repo, read by members alone.",
"collections": [
"com.example.place.note",
"com.example.place.rsvp",
"com.example.place.card"
]
}
}
}
examples/kicker/site/src/lib/place.js+8−2
@@ -11,6 +11,12 @@ import { stamped } from './views.js';
/** The place's records, by collection, each in one of its spaces. */
export const NS = 'com.example.place';
/**
* The host's space type for a group's site: the room and the calendar are
* each a space of it, under their own key (harness/seed.mjs makes them).
*/
const SITE_SPACE = 'fyi.opensocial.siteSpace';
/** The host's `os`, which the page around the site answers. */
const os = () => window.os;
@@ -26,7 +32,7 @@ export const keyOf = (uri) => uri.split('/').at(-1);
export async function context() {
const group = await os().group();
const me = await os().me();
const space = (kind) => `at://${group.did}/space/${NS}.${kind}/self`;
const space = (kind) => `at://${group.did}/space/${SITE_SPACE}/${kind}`;
const base = {
group,
me,
@@ -106,7 +112,7 @@ export const handleOf = (ctx, did) => ctx.members.get(did)?.handle ?? did;
// ---- moderation, the group host's: reports in, labels out ----
/** The group's labels: its own records of this, in the space of what each is on. */
export const LABEL = 'com.atproto.label.label';
export const LABEL = 'com.atproto.label.record';
/** atproto's own labels, which every group applies: each hides, and says no more. */
const BUILT_IN = {
examples/kicker/site/src/lib/views.js+1−1
@@ -36,7 +36,7 @@ export const oldestFirst = (records) => [...records].sort(older);
export const newestFirst = (records) => [...records].sort((a, b) => older(b, a));
/** The labels `group` put on records, from its own label records: a Map of the URI labelled to its values. */
export function labelsOn(records, group, collection = 'com.atproto.label.label') {
export function labelsOn(records, group, collection = 'com.atproto.label.record') {
const on = new Map();
for (const r of ofCollection(records, collection)) {
if (r.repo !== group) continue;
examples/kicker/site/src/lib/views.test.js+1−1
@@ -33,7 +33,7 @@ const NOTE = 'com.example.place.note';
const TOPIC = 'com.example.place.topic';
const REPLY = 'com.example.place.reply';
const RSVP = 'com.example.place.rsvp';
const LABEL = 'com.atproto.label.label';
const LABEL = 'com.atproto.label.record';
const C = { topic: TOPIC, reply: REPLY };
test('notes newest first, ties by record key', () => {
examples/kicker/AGENTS.md+4−3
@@ -18,9 +18,10 @@ repository it sits in. `README.md` says how it works.
layers under `site/src/lib` (`node harness/layers.mjs`); the rooms
(`site/src/rooms`) fill the template. Sentence case; an empty list says
what is empty with `Empty.svelte`. Look with `just look` before pushing.
- The space types and records are `lexicons/com/example/place`. A new
space type is published to the reference PDS by `harness/pds.mjs`,
which a PDS needs to grant a scope for it.
- The site keeps its records in the host's `fyi.opensocial.siteSpace`
type, a space under each key (`room`, `calendar`), so it publishes no
space type of its own. Its records are `lexicons/com/example/place`,
which no PDS needs to read: a write's permission names its collection.
- The group host is this repository, built by `just host` before each
world; `harness/bootstrap.sh` builds the spaces alpha at the commit the
host's `harness/alpha.sh` names.
examples/kicker/Justfile+7−0
examples/kicker/README.md+13−10