pi-mono/apps/p2/plugins/dev-tools/worker.ts
Mario Zechner 43bb1900ce feat(p2): port off variants to grantable members
Every remote contract declares one shape: members only some callers get are
grantable(...), and its provider grants them per principal through admit
(grantBy in src/runtime/chord.ts; notGranted/ungranted for a factory branch's
members its principal never gets). Call sites read grants instead of variant
names: live/liveWith/kept/keptWith/withGranted/expectGranted (src/runtime/refs.ts)
replace liveIn/keptIn/withHeld(ref, variant)/expectVariant; useObject has no
variant option.

Old contract versions are refused (Chord slice 15): every remote contract is a
new history base with its version bumped; the variant-era histories and accepts
of Sessions, SessionTree, Envs, Projects, Views, Mcp, Discord, Search,
SessionStatus and Subagents collapse into one declaration each, so pages, TUIs
and workers loaded before the deploy get contract_mismatch and reload once.
Catalog (local) keeps its history. Tests: holdWith/boundWith, stubs take the
grants, contract-versions tests Catalog and the refusal.
2026-11-25 19:42:02 +00:00

32 lines
1.1 KiB
TypeScript

// `reload_plugins` in every session's worker, reaching the server's `PluginReload` in roots of the worker's own.
import { relative, resolve, sep } from "node:path";
import { contribute, defineFacet } from "@p2/app/v1";
import { Extensions, workerOf } from "@p2/app/v1/worker";
import { PluginReload } from "./contract.ts";
import { createReloadExtension } from "./tool.ts";
const inside = (parent: string, child: string) => {
const path = relative(parent, child);
return path !== ".." && !path.startsWith(`..${sep}`);
};
export default defineFacet((host) => {
contribute(host, "p2.dev-tools", (self) => {
const worker = workerOf(self);
const extension = createReloadExtension(
(plugins, context) =>
worker().root(
async (ctx) => (await ctx.get(PluginReload, {})).reload(plugins ? { plugins: [...plugins] } : {}, ctx),
context,
),
() => {
const location = worker().location.value;
if (location.env) return false;
const cwd = resolve(location.cwd);
const project = worker().init.app;
return inside(project, cwd) || inside(cwd, project);
},
);
self.contribute(Extensions, { [extension.name]: extension });
});
});