Implement Studio root and placement capabilities on the replica graph (WI-10)

This commit is contained in:
Timothy J. Aveni
2026-09-21 16:37:00 -07:00
parent 2cf53280e4
commit e1ad15c620
9 changed files with 103 additions and 19 deletions
+5 -1
View File
@@ -1,3 +1,4 @@
import { portableReflectionValue } from "./reflection.js";
import type {
BoundDependency,
DependencyBinding,
@@ -152,7 +153,10 @@ export function compileExecutionGroups(
const target = bound.binding,
port = entry.dependencyPorts.find((p) => p.id === bound.portId)!;
if ("via" in target && target.via) storage(target.via.edgeTypeId);
if (target.kind === "state") storage(target.slotId);
if (target.kind === "reflection") {
for (const selector of target.selectors)
remember("reflection:" + selector, portableReflectionValue(workspace, selector));
} else if (target.kind === "state") storage(target.slotId);
else if (target.kind === "edge") storage(target.edgeTypeId);
else if (target.kind === "query") query(target.packageRevisionId, target.queryId);
else if (target.kind === "interface" && port.requirement.kind === "interface") {
+15
View File
@@ -1,3 +1,4 @@
import { portableReflectionType, portableReflectionValue } from "./reflection.js";
import type {
ValueType,
InitializationField,
@@ -119,6 +120,20 @@ export function compileKernelProgram(plan: ExecutionPlan): unknown {
const requirement = entry.dependencyPorts.find((p) => p.id === dependency.portId)!.requirement;
const bound = dependency.binding;
const common = { id: dependency.portId, ...via(bound) };
if (bound.kind === "reflection" && requirement.kind === "reflection")
return {
...common,
kind: "reflection",
values: Object.fromEntries(
bound.selectors.map((selector) => [
selector,
{
schema: portableValueSchema(portableReflectionType(selector)),
value: portableReflectionValue(workspace, selector),
},
]),
),
};
if (bound.kind === "state" && requirement.kind === "state")
return {
...common,
+4 -1
View File
@@ -2,6 +2,7 @@
* operation/port schema by the coordinator, not trusted because this header parsed. */
export const transactionPortAbi = "quixos-transaction-ports-v1";
export type PortAction =
| { kind: "reflection"; selector: string }
| { kind: "state"; primitive: "read" | "write" | "edit" }
| { kind: "edge"; primitive: "resolve" | "disconnect" }
| { kind: "edge"; primitive: "connect"; key: string }
@@ -75,7 +76,9 @@ export function checkPortInvocation(value: unknown): PortInvocation {
identifier(action.operationId)
: action.kind === "creation"
? exact(["kind", "key"]) && identifier(action.key)
: action.kind === "query" && exact(["kind"]);
: action.kind === "reflection"
? exact(["kind", "selector"]) && identifier(action.selector)
: action.kind === "query" && exact(["kind"]);
if (!valid) throw new Error("Invalid port action");
return { ...fields, action: { ...action } } as unknown as PortInvocation;
}
+28
View File
@@ -0,0 +1,28 @@
import type { ValueType, WorkspaceRevision } from "../capability-model/types.js";
import { ExecutionPlanError } from "./plan.js";
const string: ValueType = { kind: "scalar", name: "string" };
/** Narrow immutable installation metadata. No graph enumeration or live reflection. */
export function portableReflectionType(selector: string): ValueType {
if (selector !== "presentations")
throw new ExecutionPlanError(
"UNSUPPORTED_PORTABLE_REFLECTION",
selector,
"Only checked presentation metadata is portable",
);
return {
kind: "list",
value: { kind: "record", fields: { id: string, subject: string, atoms: { kind: "list", value: string } } },
};
}
export function portableReflectionValue(workspace: WorkspaceRevision, selector: string) {
portableReflectionType(selector);
return (workspace.presentations ?? [])
.map((p) => ({
id: p.id,
subject: p.subject,
atoms: [
...new Set(workspace.conformances.filter((c) => c.interfaceRevisionId === p.subject).map((c) => c.atomId)),
].sort(),
}))
.sort((a, b) => a.id.localeCompare(b.id));
}