Files
solon/scripts/add-member.ts
T
CatoandClaude Opus 5.5 7985d5a5bb feat(governance): each organization sets its own humans-only categories (#368)
* feat(governance): each organization sets its own humans-only categories

Which decision categories only people may vote on is now each
organization's own rule, not a platform rule (owner's decision,
2026-11-01).

- organizations.humans_only_categories (text[], not null) defaults to
  exactly the four categories that were hard-coded, so every existing
  and new organization decides as before. A check constraint keeps it
  to real DecisionCategory values. Migration 0019 also adds the
  ELECTORATE_CHANGED audit event type.
- DEFAULT_HUMANS_ONLY_CATEGORIES in config/governance.ts is the one
  default list; CATEGORY_ELECTORATE is gone, DEFAULT_CATEGORY_ELECTORATE
  is derived from the list.
- electorateFor(category, humansOnlyCategories) reads the organization's
  list; openSession passes it and still snapshots the electorate, so no
  past or open vote changes.
- New `humans_only` effect, paired with GOVERNANCE_RULES and applied on
  approval with an ELECTORATE_CHANGED audit event.
- Generic pages describe the default and say each organization can
  change it; the org page, /ecosystem and the proposal form use the
  organization's own list. Home copy updated in all five languages.
- Tests: default equals today's four, empty list opens GOVERNANCE_RULES
  to agents, a larger list blocks agents on the added category, effect
  schema and pairing, and the list changing only by decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtfd1xjdH3XtnyNjXr

* docs: humans-only categories are each organization's own rule

The owner overrode "red lines, not defaults to tune" on 2026-11-01.
Update .claude/CLAUDE.md, AGENTS.md, README, ROADMAP and the
whitepaper to say the four categories are the default every
organization starts with, changed by a GOVERNANCE_RULES decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtfd1xjdH3XtnyNjXr

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-01 10:11:33 +01:00

134 lines
4.6 KiB
TypeScript

/**
* Operator bootstrap: register a member (human or agent) in an organization.
*
* Membership changes are humans-only by default, but the genesis
* roster has to come from somewhere — this script is that documented,
* operator-run bootstrap. It runs on the box with DATABASE_URL set and writes
* a MEMBER_ADDED audit event like every other roster change.
*
* Usage:
* pnpm exec tsx scripts/add-member.ts --org orangecat --name "George" \
* --type HUMAN --address <bitcoin-address> [--pubkey <hex>] \
* [--system orangecat:cat] [--weight 1] [--mint-key] \
* [--oc-actor <orangecat-actor-uuid>]
*
* --oc-actor (humans only) links the member to an OrangeCat identity so
* "Sign in with OrangeCat" recognizes them. The actor id is shown on
* /account after the person signs in — recognition only; voting authority
* stays with the Bitcoin key regardless.
*
* --mint-key (agents only) generates a transport API key, stores its sha256,
* and prints the plaintext ONCE — it is never stored or shown again.
*/
import { parseArgs } from "node:util";
import { randomBytes } from "node:crypto";
import { and, eq } from "drizzle-orm";
import { db } from "../src/lib/db/client";
import { agentApiKeys, auditEvents, members, organizations } from "../src/lib/db/schema";
import { sha256Hex } from "../src/lib/domain/canonical";
const { values } = parseArgs({
options: {
org: { type: "string" },
name: { type: "string" },
type: { type: "string" },
address: { type: "string" },
pubkey: { type: "string" },
system: { type: "string" },
weight: { type: "string", default: "1" },
"mint-key": { type: "boolean", default: false },
"oc-actor": { type: "string" },
},
});
async function main() {
const { org, name, type, address } = values;
if (!org || !name || !type || !address) {
console.error("required: --org --name --type HUMAN|AGENT --address");
process.exit(1);
}
if (type !== "HUMAN" && type !== "AGENT") {
console.error(`--type must be HUMAN or AGENT, got ${type}`);
process.exit(1);
}
if (type === "AGENT" && !values.system) {
console.error(
"agents need --system (e.g. orangecat:cat) — which system attests this member's votes",
);
process.exit(1);
}
if (type === "AGENT" && values["oc-actor"]) {
console.error(
"--oc-actor is for HUMAN members only — agents are recognized by their API key, not a login",
);
process.exit(1);
}
const organization = await db.query.organizations.findFirst({
where: eq(organizations.slug, org),
});
if (!organization) {
console.error(`organization "${org}" not found`);
process.exit(1);
}
const existing = await db.query.members.findFirst({
where: and(eq(members.organizationId, organization.id), eq(members.bitcoinAddress, address)),
});
if (existing) {
console.log(`member already registered: ${existing.id} (${existing.displayName})`);
process.exit(0);
}
const member = await db.transaction(async (tx) => {
const [m] = await tx
.insert(members)
.values({
organizationId: organization.id,
displayName: name,
memberType: type,
// Humans hold their own keys; an agent's key lives in its system's env.
keyCustody: type === "HUMAN" ? "SELF" : "SERVICE",
bitcoinAddress: address,
publicKeyHex: values.pubkey ?? null,
votingWeight: values.weight,
system: values.system ?? null,
ocActorId: values["oc-actor"] ?? null,
})
.returning();
await tx.insert(auditEvents).values({
organizationId: organization.id,
eventType: "MEMBER_ADDED",
subjectType: "member",
subjectId: m.id,
payload: {
displayName: name,
memberType: type,
bitcoinAddress: address,
...(values.system ? { system: values.system } : {}),
...(values["oc-actor"] ? { ocActorId: values["oc-actor"] } : {}),
note: "operator bootstrap — roster changes after genesis go through MEMBERSHIP votes",
},
});
return m;
});
console.log(`member created: ${member.id} (${member.displayName}, ${member.memberType})`);
if (values["mint-key"]) {
if (type !== "AGENT") {
console.error("--mint-key is for AGENT members only");
process.exit(1);
}
const plaintext = `sk_solon_${randomBytes(24).toString("hex")}`;
await db.insert(agentApiKeys).values({ memberId: member.id, keyHash: sha256Hex(plaintext) });
console.log(`API key (shown once, store it in the agent's env now):\n${plaintext}`);
}
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(() => db.$client.end());