mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-03 19:57:06 +01:00
Every account but the founder's hit "Connect GitHub and the build carries
on" at the repository step of a kickoff: the server's org token was offered
only to accounts entitled to fleet infrastructure, so a person with an idea
and no GitHub account could plan but never build. Most people arriving at
Loki have no GitHub account and no wish to open one.
Now the org token creates and seeds the repository for every signed-in
account, and Loki keeps the code. The new user_projects.code_custody column
('loki' | 'own') is the safety boundary that lets it: a destructive
org-token write (archive on delete, make private on retire, rewire CD) is
allowed only on a row that says 'loki', and only the two paths that made
the repository with that token may write that value. A repository a person
linked by hand is theirs — their own token or nothing — so "Loki keeps your
code" cannot become a credential aimed at the org's other repositories.
scripts/test/github-org-token.ts pins the rule.
The code stays the person's. Once the site is live, a line beside the Live
link (and Project settings, always) offers to move it to their own GitHub:
POST /api/projects/[id]/handover transfers the repository to their login,
flips custody to 'own' and records the new address. Connecting GitHub is
asked for there and only there, because it is where the code goes.
Copy follows: the kickoff, provisioning, onboarding, the empty projects
list, the quickstart and /pricing say "Loki keeps the code for you, free"
instead of "creates a GitHub repository", and a link into the private org
repository is shown only to a viewer whose credential opens it.
Claude-Session: https://claude.ai/code/session_01CG9dupSVqoXCCqKfBCfd9B
Co-authored-by: Claude <noreply@anthropic.com>
52 lines
2.5 KiB
TypeScript
52 lines
2.5 KiB
TypeScript
/**
|
|
* Pins which token an org-scoped GitHub write uses, and who may use the
|
|
* server's org token.
|
|
* Run: npx tsx scripts/test/github-org-token.ts
|
|
*/
|
|
import { lokiKeepsCode, mayUseOrgToken, pickRepoWriteToken } from "@/lib/github-org-token";
|
|
|
|
const org = pickRepoWriteToken("org-tok", "user-tok");
|
|
if (!org || org.source !== "org" || org.token !== "org-tok") {
|
|
throw new Error("a configured org token must win over the person's token");
|
|
}
|
|
const user = pickRepoWriteToken(null, "user-tok");
|
|
if (!user || user.source !== "user" || user.token !== "user-tok") {
|
|
throw new Error("without an org token the person's token is used");
|
|
}
|
|
if (pickRepoWriteToken(null, null) !== null) throw new Error("no token → null, never a guess");
|
|
if (pickRepoWriteToken("", "user-tok")?.source !== "user") {
|
|
throw new Error("an empty org token is no org token");
|
|
}
|
|
|
|
// Who may use the org token. Entitled accounts always; anyone for code Loki
|
|
// keeps; nobody else on anything else — that last line is the one that keeps
|
|
// "Loki keeps your code" from being a credential aimed at the org.
|
|
if (!mayUseOrgToken(true)) throw new Error("an entitled account may always use the org token");
|
|
if (!mayUseOrgToken(false, { lokiKept: true })) {
|
|
throw new Error("creating or acting on code Loki keeps needs no GitHub account at all");
|
|
}
|
|
if (mayUseOrgToken(false)) {
|
|
throw new Error("an unentitled account gets the org token for nothing but Loki-kept code");
|
|
}
|
|
if (mayUseOrgToken(false, { lokiKept: false })) {
|
|
throw new Error("explicitly not Loki-kept is the same as not saying so");
|
|
}
|
|
|
|
// What counts as code Loki keeps: a project with no repository yet (the one
|
|
// about to be created is Loki's), or one whose custody says so. A linked
|
|
// repository with no custody recorded is the person's own — it was linked by
|
|
// hand, and nothing proves Loki made it.
|
|
if (!lokiKeepsCode(null)) throw new Error("no project row yet → the repo to create is Loki's");
|
|
if (!lokiKeepsCode({ gitUrl: null })) throw new Error("no repository yet → Loki's to create");
|
|
if (!lokiKeepsCode({ gitUrl: "https://github.com/bitbaum/x", codeCustody: "loki" })) {
|
|
throw new Error("custody loki → Loki keeps it");
|
|
}
|
|
if (lokiKeepsCode({ gitUrl: "https://github.com/bitbaum/orangecat", codeCustody: null })) {
|
|
throw new Error("a linked repo with no custody is the person's — never the org token");
|
|
}
|
|
if (lokiKeepsCode({ gitUrl: "https://github.com/me/x", codeCustody: "own" })) {
|
|
throw new Error("custody own → the person's token only");
|
|
}
|
|
|
|
console.log("✓ github org token");
|