- web: Gitea OAuth2 login, signed session cookie, everything behind login; inbox with answers, project board (goals → tasks), task page with OpenSpec artifacts, questions and session controls; new project form; auto-refresh, light/dark, mobile - users + projects.owner_id; tokens AES-256-GCM encrypted; owner-only access - provisionProject (runner): new or existing Gitea repo, peppa-bot collaborator, template + openspec init, push, rollback; used by web and peppa project create (replaces scripts/bootstrap-project.sh) - peppa web login-link, peppa project owner; Gitea OAuth app script - bins/template resolved via PEPPA_ROOT (works inside the Next build) - testkit: mock-gitea + 10 tests (42 e2e total, all green) - OpenSpec: pep-1-web-platform archived into specs web-auth, project-provisioning, web-workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { loadEnv, peppaHome, peppaRoot } from "@peppa/shared";
|
|
|
|
const CACHE = join(peppaHome(), "rules.md");
|
|
const LOCAL = () => join(peppaRoot(resolve(dirname(fileURLToPath(import.meta.url)), "../../..")), "template/RULES.md");
|
|
|
|
export interface SharedRules {
|
|
text: string;
|
|
source: "gitea" | "cache" | "local";
|
|
}
|
|
|
|
/**
|
|
* The shared agent rules (RULES.md in the template repo). Gitea is the source of truth;
|
|
* the last fetched copy is cached so sessions still start when Gitea is unreachable.
|
|
*/
|
|
export async function loadSharedRules(env = loadEnv()): Promise<SharedRules> {
|
|
try {
|
|
const res = await fetch(`${env.GITEA_URL}/api/v1/repos/${env.GITEA_TEMPLATE_REPO}/raw/RULES.md`, {
|
|
headers: env.GITEA_TOKEN ? { Authorization: `token ${env.GITEA_TOKEN}` } : {},
|
|
signal: AbortSignal.timeout(5000),
|
|
});
|
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
const text = await res.text();
|
|
mkdirSync(dirname(CACHE), { recursive: true });
|
|
writeFileSync(CACHE, text);
|
|
return { text, source: "gitea" };
|
|
} catch {
|
|
if (existsSync(CACHE)) return { text: readFileSync(CACHE, "utf8"), source: "cache" };
|
|
return { text: readFileSync(LOCAL(), "utf8"), source: "local" };
|
|
}
|
|
}
|