diff --git a/crates/ghostlight-dungeon/src/main.rs b/crates/ghostlight-dungeon/src/main.rs index 537409f..114a2f7 100644 --- a/crates/ghostlight-dungeon/src/main.rs +++ b/crates/ghostlight-dungeon/src/main.rs @@ -1,6 +1,6 @@ use axum::{ Json, Router, - extract::{Path, State}, + extract::{ConnectInfo, Path, State}, http::{HeaderMap, HeaderValue, StatusCode, header}, response::{IntoResponse, Redirect, Response}, routing::{get, post}, @@ -292,7 +292,11 @@ async fn main() -> anyhow::Result<()> { .parse()?; let listener = tokio::net::TcpListener::bind(address).await?; tracing::info!(%address, "GhostlightDungeon listening"); - axum::serve(listener, app).await?; + axum::serve( + listener, + app.into_make_service_with_connect_info::(), + ) + .await?; Ok(()) } @@ -1770,10 +1774,14 @@ async fn export_canon_candidates_markdown( } async fn set_provider_parallelism( + ConnectInfo(peer): ConnectInfo, headers: HeaderMap, State(state): State, Json(request): Json, ) -> Response { + if !operator_peer_allowed(peer) { + return StatusCode::FORBIDDEN.into_response(); + } let session = match authenticated_session(&headers, &state).await { Some(value) => value, None => return StatusCode::UNAUTHORIZED.into_response(), @@ -1810,7 +1818,14 @@ async fn set_provider_parallelism( } } -async fn operator_inspector(headers: HeaderMap, State(state): State) -> Response { +async fn operator_inspector( + ConnectInfo(peer): ConnectInfo, + headers: HeaderMap, + State(state): State, +) -> Response { + if !operator_peer_allowed(peer) { + return StatusCode::FORBIDDEN.into_response(); + } let session = match authenticated_session(&headers, &state).await { Some(value) => value, None => return StatusCode::UNAUTHORIZED.into_response(), @@ -1836,6 +1851,10 @@ async fn operator_inspector(headers: HeaderMap, State(state): State) - } } +fn operator_peer_allowed(peer: SocketAddr) -> bool { + peer.ip().is_loopback() +} + async fn process_due_ticks( state: &AppState, runtime: &CampaignRuntime, @@ -2404,6 +2423,16 @@ mod tests { )); } + #[test] + fn operator_http_boundary_is_loopback_only() { + assert!(operator_peer_allowed("127.0.0.1:8831".parse().unwrap())); + assert!(operator_peer_allowed("[::1]:8831".parse().unwrap())); + assert!(!operator_peer_allowed( + "192.168.178.158:55000".parse().unwrap() + )); + assert!(!operator_peer_allowed("10.77.0.4:55000".parse().unwrap())); + } + #[test] fn npc_reactions_receive_player_speech_not_private_effect_scaffolding() { let command = WorldCommand::Speak { diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index dde1f36..bb81292 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -828,6 +828,13 @@ rejects `ReplaceResolutionPins`. Fission candidates are restricted to active population leaves at the player's canonical current location; remote population names remain in the operator surface. +The operator surface now has a real HTTP boundary. Axum carries the direct TCP +peer address into the operator inspector and provider-parallelism handlers; +only loopback plus a valid campaign session is admitted. LAN/WireGuard tester +peers receive `403`, and the browser hides the operator panel away from +loopback. Do not replace this with trusted forwarded headers unless a named +reverse proxy becomes the actual connection owner. + ## Warnings - Keep persistent state small. Git history and artifacts own chronology. diff --git a/notes/ghostlight-current-system-map.md b/notes/ghostlight-current-system-map.md index 231d257..41e5a89 100644 --- a/notes/ghostlight-current-system-map.md +++ b/notes/ghostlight-current-system-map.md @@ -335,6 +335,14 @@ It likewise exposes only the number of operator pins and local active population leaves eligible for a fission preview. Pin bodies, remote population names, and `ReplaceResolutionPins` remain outside the player boundary. +HTTP operator inspection and provider-parallelism mutation require both an +authenticated campaign session and an actual loopback TCP peer. The daemon uses +Axum connection metadata from its direct listener; forwarded address headers do +not grant authority. LAN and WireGuard peers receive `403` before spoiler state +or controls are read. The browser operator panel is present only when loaded +from `127.0.0.1`, `localhost`, or `::1`; this mirrors the server boundary and is +not itself treated as security. + Global strategic context has a separate non-causal lane. Two stable broad Vault queries run alongside local retrieval, and a Flash extraction stage proposes at most 32 remote institution names with one short durable mandate each. Local code diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 36b8ebc..a0ea583 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -103,4 +103,5 @@ {"ts":"2026-08-18T19:33:00Z","type":"deployment","status":"ok","branch":"codex/ghostlight-dungeon-mvp","note":"Starfire activated immutable release c4a3d6f38bc6f95a94404a52cbb3401f24a89aab with executable SHA-256 7a6fe39503cf62b9e6a496cda4e92f1d552f6c7f79a91e2b69e41c9d729ada61 and rollback 5e198dfa872a710d31e581dcf2cd0851bef01966. Typed health, manifest, active junction, PID 12164, four persisted campaigns, and DeepSeek readiness agree. Publication did not rotate or consume invitations."} {"ts":"2026-08-18T19:37:00Z","type":"security","status":"ok","branch":"codex/ghostlight-dungeon-mvp","note":"Restored resolution-control ownership at the player membrane. Players retain active_cell_budget control; ReplaceResolutionPins is rejected by the player HTTP boundary, the browser pin editor is deleted, and player projection exposes only pin_count rather than operator pin subjects/reasons. Player fission targets now contain only active population leaves at the canonical current location. Regressions prove remote pin bodies and a secret remote population name are absent while a local population remains available."} {"ts":"2026-08-18T19:41:00Z","type":"deployment","status":"ok","branch":"codex/ghostlight-dungeon-mvp","note":"Starfire activated immutable release c509d2a95bb7683b10561abad7d4857aeab6277d with executable SHA-256 041b85ed31e58f73cbd2e75d054cac32a5ad06a5944e1e129d39df5fb5e8df8e and rollback c4a3d6f38bc6f95a94404a52cbb3401f24a89aab. Typed health, manifest, active junction, PID 27396, four persisted campaigns, DeepSeek readiness, and served asset index-CXe_foJ-.js agree. Publication did not rotate or consume invitations."} +{"ts":"2026-08-18T19:45:00Z","type":"security","status":"ok","branch":"codex/ghostlight-dungeon-mvp","note":"Established a real operator HTTP boundary: the inspector and provider-parallelism mutation now require an authenticated session from an actual loopback TCP peer supplied by Axum ConnectInfo. LAN and WireGuard peers are denied before private state access; forwarded headers grant nothing. The browser operator panel is hidden unless loaded from loopback, mirroring but not replacing server authority. IPv4/IPv6 loopback and LAN/WireGuard negative unit cases plus the production web build pass."} {"ts":"2026-08-18T18:52:00Z","type":"verification","status":"ok","branch":"codex/ghostlight-dungeon-mvp","note":"Exact release 7916ab04936ba962720cfbf4af1b83f9aa8d8b24 made every selected named member exception a mandatory Projector perspective owner, closing the seam where aggregation could erase an actionable individual before Persona choice. The strict provider-backed budget-one golden placed 24 rivals in one arena, attributed migration to member:mira-venn, moved her between depth-two population lineages, produced nine sustained material consequences including seven typed outcomes across six other background subjects, preserved her delta and the player, and automatically promoted the same Mira on return with zero rejected pulses. Witness: F:\\GameCult\\GhostlightDungeon\\acceptance\\gestalt-dynamics-7916ab0-strict\\result.json."} diff --git a/web/dist/assets/index-CXe_foJ-.js b/web/dist/assets/index-lsoqjre5.js similarity index 82% rename from web/dist/assets/index-CXe_foJ-.js rename to web/dist/assets/index-lsoqjre5.js index 182acd6..9af5a66 100644 --- a/web/dist/assets/index-CXe_foJ-.js +++ b/web/dist/assets/index-lsoqjre5.js @@ -150,4 +150,4 @@ void main() { YBXA - `}function En(e,t=document.body){const n=Me(e),i=document.documentElement.style;Tn(n.assets.fontCss);for(const[c,r]of Object.entries(an))i.setProperty(c,r);const o={colorBackground:"--bg",colorBackgroundTop:"--bg-top",colorBackgroundMid:"--bg-mid",colorBackgroundBottom:"--bg-bottom",colorShellSurfaceTop:"--shell-top",colorShellSurfaceBottom:"--shell-bottom",colorPanel:"--panel",colorPanelAlt:"--panel-2",colorPanelBorder:"--line",colorPanelBorderDeep:"--line-deep",colorText:"--text",colorTextBright:"--text-bright",colorMuted:"--quiet",colorAccent:"--accent",colorAccentStrong:"--accent-strong",colorCornerAccent:"--corner-accent",colorLink:"--cyan",colorShadow:"--shadow",colorPixelGrid:"--pixel-grid"};for(const[c,r]of Object.entries(o)){const d=n.tokens[c];d!==void 0&&i.setProperty(r,String(d))}const a=n.tokens.fontBody,l=n.tokens.fontDisplay,s=n.tokens.fontTitle,f=n.tokens.fontMono;a&&i.setProperty("--font-body",fe(String(a))),l&&i.setProperty("--font-title",fe(String(l))),s&&i.setProperty("--font-title",fe(String(s))),f&&i.setProperty("--font-mono",fe(String(f))),n.tokens.borderWidthPx&&i.setProperty("--border-width",`${n.tokens.borderWidthPx}px`),n.tokens.borderBottomWidthPx&&i.setProperty("--border-bottom-width",`${n.tokens.borderBottomWidthPx}px`),n.tokens.cornerAccentPx&&i.setProperty("--corner-accent-size",`${n.tokens.cornerAccentPx}px`),t.dataset.pixelArt=n.tokens.pixelArt||n.tokens.imageRendering==="pixelated"?"true":"false",t.dataset.scanlines=n.tokens.scanlineOverlay?"true":"false"}function ae(e,t={},n=G){const i=x(t.action),o=n.provider?.providerId||oe?.providerId||"surface unknown",a=n.activeSurfaceId||oe?.surface?.id||n.provider?.surfaces?.[0]?.surfaceId||o,l=An(n,a),s=p(l.commandBoundary,t.commandBoundary,i.commandBoundary,i.target),f=p(l.receiptSchema,t.receiptSchema,i.receiptSchema),c={type:"surface-command",schema:"gamecult.eve.command_invocation.v1",providerId:o,surfaceId:a,command:e||g(i.type,"invoke"),payload:{...i,transport:t.transport??null},issuedAt:new Date().toISOString(),clientId:n.clientId||"eve.browser"};return s&&(c.commandBoundary=s),f&&(c.receiptSchema=f),c}function An(e,t){const n=[...e.provider?.surfaces||[],...e.provider?.localAdvertisement?.surfaces||[]];return n.find(i=>i.surfaceId===t&&i.worldInteraction)?.worldInteraction||n.find(i=>i.worldInteraction)?.worldInteraction||{}}function He(e,t){const n=x(e.action);return g(e.command,g(e.commandId,g(n.command,g(n.target,g(n.type,t?.commandId||"")))))}function J(e){const t=m("section","pane");return t.append(m("h2","","No Surface")),t.append(m("div","detail",e)),t}function Ve(e,t,n,i,o){e.dataset.commandId=n,e.tabIndex=e instanceof HTMLButtonElement?e.tabIndex:0;const a=()=>{const l=ae(n,i,o);o.commandSink?.(l,t)};e.addEventListener("click",a),e.addEventListener("keydown",l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),a())})}function In(e,t,n){const i=Cn(e,t),o=x(i.find(u=>u.kind==="control.box")?.props),a=i.filter(u=>u.kind==="control.part"),l=Number(e.min??0),s=Number(e.max??1),f=m("div","cultui-slider");f.dataset.skin=g(e.skin,"default"),f.dataset.bind=g(e.bind,""),Rn(f,o);const c=m("div","cultui-slider-visual"),r=m("input","cultui-slider-input");r.type="range",r.min=String(l),r.max=String(s),r.step=String(e.step??.01),r.setAttribute("aria-label",g(e.bind,"slider"));for(const u of a){const h=x(u.props),y=m("span",`cultui-slider-part ${g(h.name,"part")}`);Fn(y,h),c.append(y)}return a.some(u=>x(u.props).name==="track")||c.append(m("span","cultui-slider-part track")),a.some(u=>x(u.props).name==="fill")||c.append(m("span","cultui-slider-part fill")),a.some(u=>x(u.props).name==="thumb")||c.append(m("span","cultui-slider-part thumb")),f.append(c,r),(u=>{const h=Number(u??l),y=Math.max(l,Math.min(s,Number.isFinite(h)?h:l)),b=s===l?0:(y-l)/(s-l)*100;r.value=String(y),f.style.setProperty("--cultui-slider-value",`${b}%`),f.dataset.value=String(y)})(e.value??l),r.addEventListener("input",()=>{const u=ae(g(e.command,"control.slider.input"),{...e,action:{...x(e.action),value:Number(r.value)},value:Number(r.value)},n);n.commandSink?.(u,{kind:"control.slider",props:e})}),f}function Cn(e,t){const n=typeof e.skin=="string"?e.skin:"",o=[...n?it.controlSkins[n]?.children||[]:[],...t];return o.length?o:[{kind:"control.box",props:{height:18,overflow:"visible"}},{kind:"control.part",props:{name:"track",anchor:"center",size:["100%",6],radius:2,fill:"color.panelInset"}},{kind:"control.part",props:{name:"fill",anchor:["left","center"],size:["value%",6],radius:2,fill:"color.accent"}},{kind:"control.part",props:{name:"thumb",anchor:["value","center"],size:[12,12],bleed:3,radius:999,fill:"color.accent"}}]}function Me(e){if(Array.isArray(e)){const t={},n={};for(const i of e)i?.name&&(i.name==="font.web.google"&&typeof i.value=="string"?n.fontCss=i.value:t[i.name]=i.value);return{tokens:t,assets:n,controlSkins:{}}}return{tokens:x(e?.tokens),assets:x(e?.assets),controlSkins:x(e?.controlSkins)}}function re(e){if(!e)return"";const t=G.assetUrlResolver;return t?t(e,oe):/^(https?:|data:|blob:)/i.test(e)?e:G.assetBaseUrl&&e.startsWith("/")?`${G.assetBaseUrl.replace(/\/+$/,"")}${e}`:e}function Tn(e){const t=typeof e=="string"?e.trim():"";if(le?.dataset.href===t||(le?.remove(),le=void 0,!t))return;const n=document.createElement("link");n.rel="preconnect",n.href="https://fonts.gstatic.com",n.crossOrigin="anonymous",document.head.append(n);const i=document.createElement("link");i.rel="stylesheet",i.href=t,i.dataset.href=t,document.head.append(i),le=i}function kn(e,t,n){const i=[];return(e==="text.title"||t.role==="title")&&i.push("cultui-title","eve-text-title"),e==="text.subtitle"&&i.push("eve-text-subtitle"),e==="label"&&i.push("cultui-label"),t.role==="mono"&&i.push("detail","mono"),i.length===0&&i.push("detail","eve-text"),i.join(" ")}function Rn(e,t){t.height!==void 0&&(e.style.minHeight=R(t.height)),t.width!==void 0&&(e.style.width=R(t.width)),typeof t.overflow=="string"&&(e.style.overflow=t.overflow)}function Fn(e,t){const n=Array.isArray(t.size)?t.size:[t.size,void 0];n[0]!==void 0&&n[0]!=="value%"&&(e.style.width=R(n[0])),n[1]!==void 0&&(e.style.height=R(n[1])),t.radius!==void 0&&(e.style.borderRadius=R(t.radius)),t.fill!==void 0&&(e.style.background=pe(String(t.fill))),t.bleed!==void 0&&e.style.setProperty("--part-bleed",R(t.bleed)),(Array.isArray(t.anchor)?t.anchor:[t.anchor]).includes("value")&&(e.dataset.anchorValue="true")}function ue(e,t){t.gap!==void 0&&(e.style.gap=R(t.gap)),t.padding!==void 0&&(e.style.padding=R(t.padding)),t.size!==void 0&&(e.style.flex=Pn(t.size)),t.min!==void 0&&(e.style.minWidth=R(t.min)),t.max!==void 0&&(e.style.maxWidth=R(t.max)),t.align!==void 0&&(e.style.alignItems=t.align==="end"?"flex-end":String(t.align)),(t.clip==="true"||t.clip===!0)&&(e.style.overflow="hidden"),t.scroll==="y"&&(e.style.overflowY="auto"),t.scroll==="x"&&(e.style.overflowX="auto")}function Pn(e){return typeof e=="string"&&e.endsWith("fr")?`${Number(e.slice(0,-2))||1} 1 0`:e==="auto"||e==="content"?"0 0 auto":`0 0 ${R(e)}`}function R(e){return Array.isArray(e)?e.map(R).join(" "):typeof e=="number"?`${e}px`:typeof e=="string"&&/^-?\d+(\.\d+)?$/.test(e)?`${e}px`:String(e??"")}function pe(e){return{"color.accent":"var(--accent)","color.panelInset":"rgba(0, 0, 0, 0.34)","color.panel":"var(--panel)","color.text":"var(--text)"}[e]||e}function fe(e){return e.includes("Zen Kaku Gothic New")||e.includes("M PLUS 1")?e:e.includes("Montserrat")?`${e}, "Zen Kaku Gothic New", "M PLUS 1", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif`:e.includes("Ubuntu")?`${e}, "M PLUS 1", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif`:`${e}, "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif`}function S(e,t){t.id&&(e.id=t.id),t.id&&(e.dataset.eveNodeId=t.id),t.kind&&(e.dataset.eveKind=t.kind)}function x(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function $n(e){return Array.isArray(e)?e:[]}function Ln(e){return $n(e).map((t,n)=>at({kind:"list.item",props:x(t)}))}function g(e,t){return e==null?t:String(e)}function p(...e){for(const t of e){if(typeof t=="string"&&t.trim())return t;if(typeof t=="number"&&Number.isFinite(t))return String(t)}return""}function Ne(e){return typeof e=="boolean"?e:typeof e=="number"?e!==0:typeof e=="string"?["1","true","yes","on"].includes(e.trim().toLowerCase()):!1}function U(e,t){const n=Number(e);return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Mn(e){const t=e.toLowerCase();return t.includes("sensor")?"S":t.includes("thermal")?"T":t.includes("fuel")?"F":t.includes("cargo")?"C":t.includes("weapon")?"W":e.trim().slice(0,1).toUpperCase()||"?"}function Nn(e){const t=e.trim().split(/\s+/).filter(Boolean);return t.length&&t.slice(0,2).map(n=>n[0]?.toUpperCase()||"").join("")||"?"}function Je(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(100,t)):0}function m(e,t="",n=""){const i=document.createElement(e);return t&&(i.className=t),n&&(i.textContent=n),i}const ye=document.querySelector("#surface"),N=document.querySelector("#status"),q=document.querySelector("#receipt"),dt=document.querySelector("#compiler"),De=document.querySelector("#composer"),be=document.querySelector("#destination-form"),ut=document.querySelector("#compiler-results"),ft=document.querySelector("#campaign-lab"),Dn=document.querySelector("#campaign-list");let ve=0,Fe="",Pe=0,mt=0,Ee=!1;const Ae=new Set;async function Be(e){if(Ee)throw new Error("A Ghostlight request is already in progress.");Ee=!0,document.body.setAttribute("aria-busy","true");for(const t of document.querySelectorAll("button, input, textarea, select"))t.disabled||(t.disabled=!0,Ae.add(t));try{return await e()}finally{for(const t of Ae)t.disabled=!1;Ae.clear(),document.body.removeAttribute("aria-busy"),Ee=!1}}function v(e,t,n){const i=document.createElement(e);return t!==void 0&&(i.textContent=t),n&&(i.className=n),i}function V(e,t){const n=[v("h3",e)];for(const i of t.filter(Boolean))n.push(v("p",i));q.replaceChildren(...n),q.hidden=!1}function Bn(e){if(e?.kind==="assessed"){const t=e.assessment,n=[v("h3",t.admissible?"Action assessment":"That attempt is not possible")];if(t.admissible){n.push(v("p",`DC ${t.dc} · modifier ${t.modifier_total>=0?"+":""}${t.modifier_total}`));const i=v("ul");for(const o of t.modifiers??[])i.append(v("li",`${o.label}: ${o.value>=0?"+":""}${o.value}`));n.push(i),n.push(v("p",`Strong/success: ${t.success_stake}`)),n.push(v("p",`Mixed: ${t.mixed_stake}`)),n.push(v("p",`Failure: ${t.failure_stake}`)),n.push(v("p",`Effect ceiling: ${t.effect_ceiling}`,"quiet"))}else{n.push(v("p",t.missing_permission??"The attempt has no admissible path from current state."));for(const i of t.bargains??[])n.push(v("p",`Possible bargain: ${i}`))}q.replaceChildren(...n),q.hidden=!1;return}if(e?.kind==="committed"){const t=e.receipt?.roll;if(t){const n=String(t.outcome).replaceAll("_"," ");V(n.charAt(0).toUpperCase()+n.slice(1),[`d20 ${t.d20} ${t.modifier_total>=0?"+":"−"} ${Math.abs(t.modifier_total)} = ${t.total} against DC ${t.dc}`])}else V("World advanced",[`Revision ${e.revision}`]);return}if(e?.kind==="resolution_updated"){V("World resolution updated",[`Resolution epoch ${e.receipt?.resolution_epoch??"advanced"}`]);return}V("Command result",[e?.error??"The world returned no player-facing detail."])}function Un(){const e="This laboratory requires an unused invite link.";N.textContent=e,dt.hidden=!0,De.hidden=!0,be.hidden=!0,ft.hidden=!0,q.hidden=!0,ye.hidden=!1;const t=v("article",void 0,"card");t.append(v("h2","Private campaign laboratory"),v("p",e),v("p","Open one of the two single-use tester invitations on this device. The resulting session stays separate from the other player's campaigns.","quiet")),ye.replaceChildren(t)}async function W(){const e=await fetch("/api/surface");if(e.status===401){Un();return}const t=await e.json(),n=t.surface_id==="ghostlight.compiler";if(dt.hidden=!n,De.hidden=n,be.hidden=n,ye.hidden=n,ft.hidden=n,n){N.textContent="No campaign exists. Retrieve the Vault and approve a world seed.";return}if(ve=Number(t.world_revision??t.version??0),Fe=String(t.player_actor_id??""),!Fe)throw new Error("Campaign surface omitted its canonical player actor ID.");const i=String(t.player_location_id??"");if(!i)throw new Error("Campaign surface omitted its canonical player location ID.");document.querySelector("#destination-origin").value=i,Pe=Number(t.resolution?.policy?.resolution_epoch??0),mt=Number(t.resolution?.policy?.provider_configuration_epoch??0);const o=Number(t.resolution?.policy?.active_cell_budget??8),a=document.querySelector("#active-cell-budget");a.value=String(o),document.querySelector("#active-cell-budget-value").value=String(o),document.querySelector("#resolution-status").textContent=`${t.resolution?.effective_budget??o} effective cells · ${t.resolution?.mandatory_overage??0} temporary overage · epoch ${Pe}`;const l=Number(t.resolution?.policy?.provider_parallelism??8);document.querySelector("#provider-parallelism").value=String(l),document.querySelector("#provider-parallelism-value").value=String(l);const s=document.querySelector("#fission-parent");s.replaceChildren(...(t.resolution?.fission_targets??[]).map(c=>{const r=v("option",`${c.name} · ${c.id}`);return r.value=c.id,r})),document.querySelector("#fission-form").hidden=s.options.length===0,rt(t,ye,{body:document.body,clientId:"ghostlight.browser",statusElement:N});const f=await fetch("/api/campaigns").then(c=>c.json());Dn.replaceChildren(...f.campaigns.map(c=>{const r=v("button",`${c.selected?"●":"○"} ${c.name} · revision ${c.revision}`);return r.type="button",r.disabled=!!c.selected,c.selected||r.addEventListener("click",async()=>{await B(`/api/campaigns/select/${c.id}`,{}),await W()}),r}))}async function B(e,t){return Be(async()=>{N.textContent="Retrieving evidence and compiling…";const n=await fetch(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}),i=n.headers.get("content-type")?.includes("json")?await n.json():await n.text();if(!n.ok)throw N.textContent=typeof i=="string"?i:String(i?.error??"Compilation failed"),new Error(N.textContent);return i})}function Ze(e,t,n){const i=v("div",void 0,"cards");e.forEach((o,a)=>{const l=v("article",void 0,"card");l.append(v("h3",o.title??o.name),v("p",o.player_hook??o.premise)),o.era&&l.append(v("p",`${o.era} · ${o.place} · ${o.pressure}`));const s=v("button",t);s.type="button",s.addEventListener("click",()=>n(e[a])),l.append(s),i.append(l)}),ut.replaceChildren(i)}function O(e,t,n){const i=v("details");i.append(v("summary",t));const o=v("ul");for(const a of n)o.append(v("li",a));n.length===0&&o.append(v("li","None declared.")),i.append(o),e.append(i)}document.querySelector("#suggest-form").addEventListener("submit",async e=>{e.preventDefault();const t=await B("/api/compiler/openings",{setting:document.querySelector("#setting").value,constraints:[]});Ze(t.openings,"Choose opening",async n=>{const i=await B("/api/compiler/roles",n);Ze(i.roles,"Choose role",async o=>pt(await B("/api/compiler/selected",{campaign_name:n.title,opening:n,role:o})))})});document.querySelector("#custom-form").addEventListener("submit",async e=>{e.preventDefault(),await pt(await B("/api/compiler/custom",Object.fromEntries(new FormData(e.currentTarget))))});async function pt(e){const t=e.preview,n=Array.isArray(t.evidence_coverage)?t.evidence_coverage:[],i=n.reduce((s,f)=>{const c=String(f?.lane??"excluded");return s[c]=(s[c]??0)+1,s},{}),o=v("article",void 0,"card");o.append(v("h3",t.title),v("p",t.opening??""),v("p",`${t.locations?.length??0} locations · ${(t.cast?.length??0)+1} actors · ${t.institutions?.length??0} institutions`),v("p",t.gaps.length?`Material gaps: ${t.gaps.join("; ")}`:"No declared material gaps.","warning"),v("p",`Branch assumptions: ${t.branch_assumptions.join("; ")||"none"}`),v("p",n.length?`Evidence use: ${i.direct_seed??0} direct · ${i.setting_background??0} background · ${i.excluded??0} excluded`:"Evidence use: no retrieved sources were admitted to this seed.","quiet"));const a=t.player_role??{};O(o,`Player role · ${a.name??"unnamed"}`,[`Starts at ${a.location_id??"an unspecified location"}`,...(a.capabilities??[]).map(s=>`Capability: ${s}`),...(a.equipment??[]).map(s=>`Equipment: ${s}`),...(a.conditions??[]).map(s=>`Condition: ${s}`),...(a.obligations??[]).map(s=>`Obligation: ${s}`)]),O(o,`Initial topology · ${t.locations?.length??0} locations`,(t.locations??[]).map(s=>{const f=Object.keys(s.routes??{});return`${s.name} · ${s.id}${s.container_id?` · inside ${s.container_id}`:""}${f.length?` · routes to ${f.join(", ")}`:" · no compiled route"}`})),O(o,`Present cast · ${t.cast?.length??0}`,(t.cast??[]).map(s=>`${s.name} · ${s.id} · at ${s.location_id}`)),O(o,`Institutions · ${t.institutions?.length??0}`,(t.institutions??[]).map(s=>`${s.name} · ${s.id}`)),O(o,`Populations · ${t.populations?.length??0}`,(t.populations??[]).map(s=>`${s.name} · ${s.id} · at ${s.home_location_id}`)),O(o,`World clocks · ${t.clocks?.length??0}`,(t.clocks??[]).map(s=>`${s.name} · ${s.progress}/${s.threshold} · ${s.trigger}`)),O(o,`Evidence coverage · ${n.length}`,n.map(s=>`${s.source_id} · ${String(s.lane).replaceAll("_"," ")} · ${s.rationale}`));const l=v("button","Approve and enter");l.type="button",l.addEventListener("click",async()=>{await B(`/api/compiler/approve/${e.preview_id}`,{}),await W()}),o.append(l),ut.replaceChildren(o),N.textContent="Preview compiled. Nothing has entered world state yet."}async function we(e){return Be(async()=>{N.textContent="The world is considering the command…";const t=await fetch("/api/command",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)}),n=await t.json();return Bn(n),t.ok?(await W(),n):(N.textContent=n.error??"The command was refused.",await W(),n)})}function ht(e){if(e?.kind!=="assessed")return;const t=document.createElement("button");t.type="button",t.textContent=e.assessment.admissible?"Confirm server roll":"Revise attempt",t.addEventListener("click",async()=>{if(!e.assessment.admissible){document.querySelector("#attempt").focus();return}const n=await we({type:"attempt",assessment_digest:e.assessment.digest});ht(n)}),q.append(t)}De.addEventListener("submit",async e=>{e.preventDefault();const t=document.querySelector("#attempt").value.trim(),n=document.querySelector("#intended-effect").value.trim();!t||!n||ht(await we({type:"assess",expected_revision:ve,intent:{actor_id:Fe,description:t,intended_effect:n}}))});document.querySelector("#wait").addEventListener("click",()=>{we({type:"wait",expected_revision:ve,minutes:60})});document.querySelector("#active-cell-budget").addEventListener("input",e=>{document.querySelector("#active-cell-budget-value").value=e.currentTarget.value});document.querySelector("#resolution-form").addEventListener("submit",async e=>{e.preventDefault(),await we({type:"set_resolution_budget",expected_revision:ve,expected_resolution_epoch:Pe,active_cell_budget:Number(document.querySelector("#active-cell-budget").value)})});document.querySelector("#provider-parallelism").addEventListener("input",e=>{document.querySelector("#provider-parallelism-value").value=e.currentTarget.value});document.querySelector("#provider-parallelism-form").addEventListener("submit",async e=>{e.preventDefault(),await Be(async()=>{N.textContent="Applying the provider concurrency limit…";const t=await fetch("/api/operator/provider-parallelism",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({expected_provider_configuration_epoch:mt,provider_parallelism:Number(document.querySelector("#provider-parallelism").value)})}),n=await t.json();V(t.ok?"Provider concurrency updated":"Provider concurrency refused",[t.ok?`Parallel requests: ${n.receipt?.provider_parallelism??n.provider_parallelism??"updated"}`:n.error??"The operator limit was refused."]),t.ok||(N.textContent=n.error??"The operator limit was refused."),await W()})});be.addEventListener("submit",async e=>{e.preventDefault();const t=await B("/api/compiler/destination",Object.fromEntries(new FormData(be))),n=t.preview;V("Destination preview",(n.gaps??[]).map(o=>`Material gap: ${o}`)),O(q,`Compiled topology · ${n.locations?.length??0} locations`,(n.locations??[]).map(o=>{const a=Object.keys(o.routes??{}),l=[...o.persistent_features??[]];return`${o.name} · ${o.id}${o.container_id?` · inside ${o.container_id}`:""}${a.length?` · routes to ${a.join(", ")}`:" · no compiled route"}${l.length?` · ${l.join(", ")}`:""}`})),N.textContent="Destination preview compiled; topology is unchanged until approval.";const i=v("button","Approve destination");i.type="button",i.addEventListener("click",async()=>{await B(`/api/compiler/destination/approve/${t.preview_id}`,{}),i.remove(),await W()}),q.append(i)});document.querySelector("#fission-form").addEventListener("submit",async e=>{e.preventDefault();const t=new FormData(e.currentTarget),n=await B("/api/compiler/gestalt/fission",{parent_gestalt_id:t.get("parent_gestalt_id"),partition_axis:t.get("partition_axis"),requested_partition_values:String(t.get("requested_partition_values")??"").split(",").map(o=>o.trim()).filter(Boolean),reason:t.get("reason")});V("Population fission preview",[...(n.preview?.gaps??[]).map(o=>`Material gap: ${o}`)]),O(q,`Canonical child leaves · ${n.preview?.children?.length??0}`,(n.preview?.children??[]).map(o=>`${o.name} · ${o.id} · ${o.partition_value??"other/unknown"} · at ${o.home_location_id}`)),N.textContent="Fission preview compiled. Canonical leaves are unchanged until approval.";const i=document.createElement("button");i.type="button",i.textContent="Approve population fission",i.addEventListener("click",async()=>{await B(`/api/compiler/gestalt/fission/approve/${n.preview_id}`,{}),i.remove(),await W()}),q.append(i)});document.querySelector("#fork-form").addEventListener("submit",async e=>{e.preventDefault(),await B("/api/campaigns/fork",Object.fromEntries(new FormData(e.currentTarget))),await W()});document.querySelector("#reset-form").addEventListener("submit",async e=>{e.preventDefault(),await B("/api/campaigns/reset",Object.fromEntries(new FormData(e.currentTarget))),await W()});document.querySelector("#load-operator").addEventListener("click",async()=>{const t=await(await fetch("/api/operator")).json();rt(t,document.querySelector("#operator-output"),{body:document.body,clientId:"ghostlight.operator",statusElement:N})});W(); + `}function En(e,t=document.body){const n=Me(e),i=document.documentElement.style;Tn(n.assets.fontCss);for(const[c,r]of Object.entries(an))i.setProperty(c,r);const o={colorBackground:"--bg",colorBackgroundTop:"--bg-top",colorBackgroundMid:"--bg-mid",colorBackgroundBottom:"--bg-bottom",colorShellSurfaceTop:"--shell-top",colorShellSurfaceBottom:"--shell-bottom",colorPanel:"--panel",colorPanelAlt:"--panel-2",colorPanelBorder:"--line",colorPanelBorderDeep:"--line-deep",colorText:"--text",colorTextBright:"--text-bright",colorMuted:"--quiet",colorAccent:"--accent",colorAccentStrong:"--accent-strong",colorCornerAccent:"--corner-accent",colorLink:"--cyan",colorShadow:"--shadow",colorPixelGrid:"--pixel-grid"};for(const[c,r]of Object.entries(o)){const d=n.tokens[c];d!==void 0&&i.setProperty(r,String(d))}const a=n.tokens.fontBody,l=n.tokens.fontDisplay,s=n.tokens.fontTitle,f=n.tokens.fontMono;a&&i.setProperty("--font-body",fe(String(a))),l&&i.setProperty("--font-title",fe(String(l))),s&&i.setProperty("--font-title",fe(String(s))),f&&i.setProperty("--font-mono",fe(String(f))),n.tokens.borderWidthPx&&i.setProperty("--border-width",`${n.tokens.borderWidthPx}px`),n.tokens.borderBottomWidthPx&&i.setProperty("--border-bottom-width",`${n.tokens.borderBottomWidthPx}px`),n.tokens.cornerAccentPx&&i.setProperty("--corner-accent-size",`${n.tokens.cornerAccentPx}px`),t.dataset.pixelArt=n.tokens.pixelArt||n.tokens.imageRendering==="pixelated"?"true":"false",t.dataset.scanlines=n.tokens.scanlineOverlay?"true":"false"}function ae(e,t={},n=G){const i=x(t.action),o=n.provider?.providerId||oe?.providerId||"surface unknown",a=n.activeSurfaceId||oe?.surface?.id||n.provider?.surfaces?.[0]?.surfaceId||o,l=An(n,a),s=p(l.commandBoundary,t.commandBoundary,i.commandBoundary,i.target),f=p(l.receiptSchema,t.receiptSchema,i.receiptSchema),c={type:"surface-command",schema:"gamecult.eve.command_invocation.v1",providerId:o,surfaceId:a,command:e||g(i.type,"invoke"),payload:{...i,transport:t.transport??null},issuedAt:new Date().toISOString(),clientId:n.clientId||"eve.browser"};return s&&(c.commandBoundary=s),f&&(c.receiptSchema=f),c}function An(e,t){const n=[...e.provider?.surfaces||[],...e.provider?.localAdvertisement?.surfaces||[]];return n.find(i=>i.surfaceId===t&&i.worldInteraction)?.worldInteraction||n.find(i=>i.worldInteraction)?.worldInteraction||{}}function He(e,t){const n=x(e.action);return g(e.command,g(e.commandId,g(n.command,g(n.target,g(n.type,t?.commandId||"")))))}function J(e){const t=m("section","pane");return t.append(m("h2","","No Surface")),t.append(m("div","detail",e)),t}function Ve(e,t,n,i,o){e.dataset.commandId=n,e.tabIndex=e instanceof HTMLButtonElement?e.tabIndex:0;const a=()=>{const l=ae(n,i,o);o.commandSink?.(l,t)};e.addEventListener("click",a),e.addEventListener("keydown",l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),a())})}function In(e,t,n){const i=Cn(e,t),o=x(i.find(u=>u.kind==="control.box")?.props),a=i.filter(u=>u.kind==="control.part"),l=Number(e.min??0),s=Number(e.max??1),f=m("div","cultui-slider");f.dataset.skin=g(e.skin,"default"),f.dataset.bind=g(e.bind,""),Rn(f,o);const c=m("div","cultui-slider-visual"),r=m("input","cultui-slider-input");r.type="range",r.min=String(l),r.max=String(s),r.step=String(e.step??.01),r.setAttribute("aria-label",g(e.bind,"slider"));for(const u of a){const h=x(u.props),y=m("span",`cultui-slider-part ${g(h.name,"part")}`);Fn(y,h),c.append(y)}return a.some(u=>x(u.props).name==="track")||c.append(m("span","cultui-slider-part track")),a.some(u=>x(u.props).name==="fill")||c.append(m("span","cultui-slider-part fill")),a.some(u=>x(u.props).name==="thumb")||c.append(m("span","cultui-slider-part thumb")),f.append(c,r),(u=>{const h=Number(u??l),y=Math.max(l,Math.min(s,Number.isFinite(h)?h:l)),b=s===l?0:(y-l)/(s-l)*100;r.value=String(y),f.style.setProperty("--cultui-slider-value",`${b}%`),f.dataset.value=String(y)})(e.value??l),r.addEventListener("input",()=>{const u=ae(g(e.command,"control.slider.input"),{...e,action:{...x(e.action),value:Number(r.value)},value:Number(r.value)},n);n.commandSink?.(u,{kind:"control.slider",props:e})}),f}function Cn(e,t){const n=typeof e.skin=="string"?e.skin:"",o=[...n?it.controlSkins[n]?.children||[]:[],...t];return o.length?o:[{kind:"control.box",props:{height:18,overflow:"visible"}},{kind:"control.part",props:{name:"track",anchor:"center",size:["100%",6],radius:2,fill:"color.panelInset"}},{kind:"control.part",props:{name:"fill",anchor:["left","center"],size:["value%",6],radius:2,fill:"color.accent"}},{kind:"control.part",props:{name:"thumb",anchor:["value","center"],size:[12,12],bleed:3,radius:999,fill:"color.accent"}}]}function Me(e){if(Array.isArray(e)){const t={},n={};for(const i of e)i?.name&&(i.name==="font.web.google"&&typeof i.value=="string"?n.fontCss=i.value:t[i.name]=i.value);return{tokens:t,assets:n,controlSkins:{}}}return{tokens:x(e?.tokens),assets:x(e?.assets),controlSkins:x(e?.controlSkins)}}function re(e){if(!e)return"";const t=G.assetUrlResolver;return t?t(e,oe):/^(https?:|data:|blob:)/i.test(e)?e:G.assetBaseUrl&&e.startsWith("/")?`${G.assetBaseUrl.replace(/\/+$/,"")}${e}`:e}function Tn(e){const t=typeof e=="string"?e.trim():"";if(le?.dataset.href===t||(le?.remove(),le=void 0,!t))return;const n=document.createElement("link");n.rel="preconnect",n.href="https://fonts.gstatic.com",n.crossOrigin="anonymous",document.head.append(n);const i=document.createElement("link");i.rel="stylesheet",i.href=t,i.dataset.href=t,document.head.append(i),le=i}function kn(e,t,n){const i=[];return(e==="text.title"||t.role==="title")&&i.push("cultui-title","eve-text-title"),e==="text.subtitle"&&i.push("eve-text-subtitle"),e==="label"&&i.push("cultui-label"),t.role==="mono"&&i.push("detail","mono"),i.length===0&&i.push("detail","eve-text"),i.join(" ")}function Rn(e,t){t.height!==void 0&&(e.style.minHeight=R(t.height)),t.width!==void 0&&(e.style.width=R(t.width)),typeof t.overflow=="string"&&(e.style.overflow=t.overflow)}function Fn(e,t){const n=Array.isArray(t.size)?t.size:[t.size,void 0];n[0]!==void 0&&n[0]!=="value%"&&(e.style.width=R(n[0])),n[1]!==void 0&&(e.style.height=R(n[1])),t.radius!==void 0&&(e.style.borderRadius=R(t.radius)),t.fill!==void 0&&(e.style.background=pe(String(t.fill))),t.bleed!==void 0&&e.style.setProperty("--part-bleed",R(t.bleed)),(Array.isArray(t.anchor)?t.anchor:[t.anchor]).includes("value")&&(e.dataset.anchorValue="true")}function ue(e,t){t.gap!==void 0&&(e.style.gap=R(t.gap)),t.padding!==void 0&&(e.style.padding=R(t.padding)),t.size!==void 0&&(e.style.flex=Pn(t.size)),t.min!==void 0&&(e.style.minWidth=R(t.min)),t.max!==void 0&&(e.style.maxWidth=R(t.max)),t.align!==void 0&&(e.style.alignItems=t.align==="end"?"flex-end":String(t.align)),(t.clip==="true"||t.clip===!0)&&(e.style.overflow="hidden"),t.scroll==="y"&&(e.style.overflowY="auto"),t.scroll==="x"&&(e.style.overflowX="auto")}function Pn(e){return typeof e=="string"&&e.endsWith("fr")?`${Number(e.slice(0,-2))||1} 1 0`:e==="auto"||e==="content"?"0 0 auto":`0 0 ${R(e)}`}function R(e){return Array.isArray(e)?e.map(R).join(" "):typeof e=="number"?`${e}px`:typeof e=="string"&&/^-?\d+(\.\d+)?$/.test(e)?`${e}px`:String(e??"")}function pe(e){return{"color.accent":"var(--accent)","color.panelInset":"rgba(0, 0, 0, 0.34)","color.panel":"var(--panel)","color.text":"var(--text)"}[e]||e}function fe(e){return e.includes("Zen Kaku Gothic New")||e.includes("M PLUS 1")?e:e.includes("Montserrat")?`${e}, "Zen Kaku Gothic New", "M PLUS 1", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif`:e.includes("Ubuntu")?`${e}, "M PLUS 1", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif`:`${e}, "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif`}function S(e,t){t.id&&(e.id=t.id),t.id&&(e.dataset.eveNodeId=t.id),t.kind&&(e.dataset.eveKind=t.kind)}function x(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function $n(e){return Array.isArray(e)?e:[]}function Ln(e){return $n(e).map((t,n)=>at({kind:"list.item",props:x(t)}))}function g(e,t){return e==null?t:String(e)}function p(...e){for(const t of e){if(typeof t=="string"&&t.trim())return t;if(typeof t=="number"&&Number.isFinite(t))return String(t)}return""}function Ne(e){return typeof e=="boolean"?e:typeof e=="number"?e!==0:typeof e=="string"?["1","true","yes","on"].includes(e.trim().toLowerCase()):!1}function U(e,t){const n=Number(e);return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Mn(e){const t=e.toLowerCase();return t.includes("sensor")?"S":t.includes("thermal")?"T":t.includes("fuel")?"F":t.includes("cargo")?"C":t.includes("weapon")?"W":e.trim().slice(0,1).toUpperCase()||"?"}function Nn(e){const t=e.trim().split(/\s+/).filter(Boolean);return t.length&&t.slice(0,2).map(n=>n[0]?.toUpperCase()||"").join("")||"?"}function Je(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(100,t)):0}function m(e,t="",n=""){const i=document.createElement(e);return t&&(i.className=t),n&&(i.textContent=n),i}const ye=document.querySelector("#surface"),N=document.querySelector("#status"),q=document.querySelector("#receipt"),dt=document.querySelector("#compiler"),De=document.querySelector("#composer"),be=document.querySelector("#destination-form"),ut=document.querySelector("#compiler-results"),ft=document.querySelector("#campaign-lab"),Dn=document.querySelector("#campaign-list"),Bn=document.querySelector("#operator-lab");Bn.hidden=!["127.0.0.1","localhost","::1"].includes(window.location.hostname);let ve=0,Fe="",Pe=0,mt=0,Ee=!1;const Ae=new Set;async function Be(e){if(Ee)throw new Error("A Ghostlight request is already in progress.");Ee=!0,document.body.setAttribute("aria-busy","true");for(const t of document.querySelectorAll("button, input, textarea, select"))t.disabled||(t.disabled=!0,Ae.add(t));try{return await e()}finally{for(const t of Ae)t.disabled=!1;Ae.clear(),document.body.removeAttribute("aria-busy"),Ee=!1}}function v(e,t,n){const i=document.createElement(e);return t!==void 0&&(i.textContent=t),n&&(i.className=n),i}function V(e,t){const n=[v("h3",e)];for(const i of t.filter(Boolean))n.push(v("p",i));q.replaceChildren(...n),q.hidden=!1}function Un(e){if(e?.kind==="assessed"){const t=e.assessment,n=[v("h3",t.admissible?"Action assessment":"That attempt is not possible")];if(t.admissible){n.push(v("p",`DC ${t.dc} · modifier ${t.modifier_total>=0?"+":""}${t.modifier_total}`));const i=v("ul");for(const o of t.modifiers??[])i.append(v("li",`${o.label}: ${o.value>=0?"+":""}${o.value}`));n.push(i),n.push(v("p",`Strong/success: ${t.success_stake}`)),n.push(v("p",`Mixed: ${t.mixed_stake}`)),n.push(v("p",`Failure: ${t.failure_stake}`)),n.push(v("p",`Effect ceiling: ${t.effect_ceiling}`,"quiet"))}else{n.push(v("p",t.missing_permission??"The attempt has no admissible path from current state."));for(const i of t.bargains??[])n.push(v("p",`Possible bargain: ${i}`))}q.replaceChildren(...n),q.hidden=!1;return}if(e?.kind==="committed"){const t=e.receipt?.roll;if(t){const n=String(t.outcome).replaceAll("_"," ");V(n.charAt(0).toUpperCase()+n.slice(1),[`d20 ${t.d20} ${t.modifier_total>=0?"+":"−"} ${Math.abs(t.modifier_total)} = ${t.total} against DC ${t.dc}`])}else V("World advanced",[`Revision ${e.revision}`]);return}if(e?.kind==="resolution_updated"){V("World resolution updated",[`Resolution epoch ${e.receipt?.resolution_epoch??"advanced"}`]);return}V("Command result",[e?.error??"The world returned no player-facing detail."])}function qn(){const e="This laboratory requires an unused invite link.";N.textContent=e,dt.hidden=!0,De.hidden=!0,be.hidden=!0,ft.hidden=!0,q.hidden=!0,ye.hidden=!1;const t=v("article",void 0,"card");t.append(v("h2","Private campaign laboratory"),v("p",e),v("p","Open one of the two single-use tester invitations on this device. The resulting session stays separate from the other player's campaigns.","quiet")),ye.replaceChildren(t)}async function W(){const e=await fetch("/api/surface");if(e.status===401){qn();return}const t=await e.json(),n=t.surface_id==="ghostlight.compiler";if(dt.hidden=!n,De.hidden=n,be.hidden=n,ye.hidden=n,ft.hidden=n,n){N.textContent="No campaign exists. Retrieve the Vault and approve a world seed.";return}if(ve=Number(t.world_revision??t.version??0),Fe=String(t.player_actor_id??""),!Fe)throw new Error("Campaign surface omitted its canonical player actor ID.");const i=String(t.player_location_id??"");if(!i)throw new Error("Campaign surface omitted its canonical player location ID.");document.querySelector("#destination-origin").value=i,Pe=Number(t.resolution?.policy?.resolution_epoch??0),mt=Number(t.resolution?.policy?.provider_configuration_epoch??0);const o=Number(t.resolution?.policy?.active_cell_budget??8),a=document.querySelector("#active-cell-budget");a.value=String(o),document.querySelector("#active-cell-budget-value").value=String(o),document.querySelector("#resolution-status").textContent=`${t.resolution?.effective_budget??o} effective cells · ${t.resolution?.mandatory_overage??0} temporary overage · epoch ${Pe}`;const l=Number(t.resolution?.policy?.provider_parallelism??8);document.querySelector("#provider-parallelism").value=String(l),document.querySelector("#provider-parallelism-value").value=String(l);const s=document.querySelector("#fission-parent");s.replaceChildren(...(t.resolution?.fission_targets??[]).map(c=>{const r=v("option",`${c.name} · ${c.id}`);return r.value=c.id,r})),document.querySelector("#fission-form").hidden=s.options.length===0,rt(t,ye,{body:document.body,clientId:"ghostlight.browser",statusElement:N});const f=await fetch("/api/campaigns").then(c=>c.json());Dn.replaceChildren(...f.campaigns.map(c=>{const r=v("button",`${c.selected?"●":"○"} ${c.name} · revision ${c.revision}`);return r.type="button",r.disabled=!!c.selected,c.selected||r.addEventListener("click",async()=>{await B(`/api/campaigns/select/${c.id}`,{}),await W()}),r}))}async function B(e,t){return Be(async()=>{N.textContent="Retrieving evidence and compiling…";const n=await fetch(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}),i=n.headers.get("content-type")?.includes("json")?await n.json():await n.text();if(!n.ok)throw N.textContent=typeof i=="string"?i:String(i?.error??"Compilation failed"),new Error(N.textContent);return i})}function Ze(e,t,n){const i=v("div",void 0,"cards");e.forEach((o,a)=>{const l=v("article",void 0,"card");l.append(v("h3",o.title??o.name),v("p",o.player_hook??o.premise)),o.era&&l.append(v("p",`${o.era} · ${o.place} · ${o.pressure}`));const s=v("button",t);s.type="button",s.addEventListener("click",()=>n(e[a])),l.append(s),i.append(l)}),ut.replaceChildren(i)}function O(e,t,n){const i=v("details");i.append(v("summary",t));const o=v("ul");for(const a of n)o.append(v("li",a));n.length===0&&o.append(v("li","None declared.")),i.append(o),e.append(i)}document.querySelector("#suggest-form").addEventListener("submit",async e=>{e.preventDefault();const t=await B("/api/compiler/openings",{setting:document.querySelector("#setting").value,constraints:[]});Ze(t.openings,"Choose opening",async n=>{const i=await B("/api/compiler/roles",n);Ze(i.roles,"Choose role",async o=>pt(await B("/api/compiler/selected",{campaign_name:n.title,opening:n,role:o})))})});document.querySelector("#custom-form").addEventListener("submit",async e=>{e.preventDefault(),await pt(await B("/api/compiler/custom",Object.fromEntries(new FormData(e.currentTarget))))});async function pt(e){const t=e.preview,n=Array.isArray(t.evidence_coverage)?t.evidence_coverage:[],i=n.reduce((s,f)=>{const c=String(f?.lane??"excluded");return s[c]=(s[c]??0)+1,s},{}),o=v("article",void 0,"card");o.append(v("h3",t.title),v("p",t.opening??""),v("p",`${t.locations?.length??0} locations · ${(t.cast?.length??0)+1} actors · ${t.institutions?.length??0} institutions`),v("p",t.gaps.length?`Material gaps: ${t.gaps.join("; ")}`:"No declared material gaps.","warning"),v("p",`Branch assumptions: ${t.branch_assumptions.join("; ")||"none"}`),v("p",n.length?`Evidence use: ${i.direct_seed??0} direct · ${i.setting_background??0} background · ${i.excluded??0} excluded`:"Evidence use: no retrieved sources were admitted to this seed.","quiet"));const a=t.player_role??{};O(o,`Player role · ${a.name??"unnamed"}`,[`Starts at ${a.location_id??"an unspecified location"}`,...(a.capabilities??[]).map(s=>`Capability: ${s}`),...(a.equipment??[]).map(s=>`Equipment: ${s}`),...(a.conditions??[]).map(s=>`Condition: ${s}`),...(a.obligations??[]).map(s=>`Obligation: ${s}`)]),O(o,`Initial topology · ${t.locations?.length??0} locations`,(t.locations??[]).map(s=>{const f=Object.keys(s.routes??{});return`${s.name} · ${s.id}${s.container_id?` · inside ${s.container_id}`:""}${f.length?` · routes to ${f.join(", ")}`:" · no compiled route"}`})),O(o,`Present cast · ${t.cast?.length??0}`,(t.cast??[]).map(s=>`${s.name} · ${s.id} · at ${s.location_id}`)),O(o,`Institutions · ${t.institutions?.length??0}`,(t.institutions??[]).map(s=>`${s.name} · ${s.id}`)),O(o,`Populations · ${t.populations?.length??0}`,(t.populations??[]).map(s=>`${s.name} · ${s.id} · at ${s.home_location_id}`)),O(o,`World clocks · ${t.clocks?.length??0}`,(t.clocks??[]).map(s=>`${s.name} · ${s.progress}/${s.threshold} · ${s.trigger}`)),O(o,`Evidence coverage · ${n.length}`,n.map(s=>`${s.source_id} · ${String(s.lane).replaceAll("_"," ")} · ${s.rationale}`));const l=v("button","Approve and enter");l.type="button",l.addEventListener("click",async()=>{await B(`/api/compiler/approve/${e.preview_id}`,{}),await W()}),o.append(l),ut.replaceChildren(o),N.textContent="Preview compiled. Nothing has entered world state yet."}async function we(e){return Be(async()=>{N.textContent="The world is considering the command…";const t=await fetch("/api/command",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)}),n=await t.json();return Un(n),t.ok?(await W(),n):(N.textContent=n.error??"The command was refused.",await W(),n)})}function ht(e){if(e?.kind!=="assessed")return;const t=document.createElement("button");t.type="button",t.textContent=e.assessment.admissible?"Confirm server roll":"Revise attempt",t.addEventListener("click",async()=>{if(!e.assessment.admissible){document.querySelector("#attempt").focus();return}const n=await we({type:"attempt",assessment_digest:e.assessment.digest});ht(n)}),q.append(t)}De.addEventListener("submit",async e=>{e.preventDefault();const t=document.querySelector("#attempt").value.trim(),n=document.querySelector("#intended-effect").value.trim();!t||!n||ht(await we({type:"assess",expected_revision:ve,intent:{actor_id:Fe,description:t,intended_effect:n}}))});document.querySelector("#wait").addEventListener("click",()=>{we({type:"wait",expected_revision:ve,minutes:60})});document.querySelector("#active-cell-budget").addEventListener("input",e=>{document.querySelector("#active-cell-budget-value").value=e.currentTarget.value});document.querySelector("#resolution-form").addEventListener("submit",async e=>{e.preventDefault(),await we({type:"set_resolution_budget",expected_revision:ve,expected_resolution_epoch:Pe,active_cell_budget:Number(document.querySelector("#active-cell-budget").value)})});document.querySelector("#provider-parallelism").addEventListener("input",e=>{document.querySelector("#provider-parallelism-value").value=e.currentTarget.value});document.querySelector("#provider-parallelism-form").addEventListener("submit",async e=>{e.preventDefault(),await Be(async()=>{N.textContent="Applying the provider concurrency limit…";const t=await fetch("/api/operator/provider-parallelism",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({expected_provider_configuration_epoch:mt,provider_parallelism:Number(document.querySelector("#provider-parallelism").value)})}),n=await t.json();V(t.ok?"Provider concurrency updated":"Provider concurrency refused",[t.ok?`Parallel requests: ${n.receipt?.provider_parallelism??n.provider_parallelism??"updated"}`:n.error??"The operator limit was refused."]),t.ok||(N.textContent=n.error??"The operator limit was refused."),await W()})});be.addEventListener("submit",async e=>{e.preventDefault();const t=await B("/api/compiler/destination",Object.fromEntries(new FormData(be))),n=t.preview;V("Destination preview",(n.gaps??[]).map(o=>`Material gap: ${o}`)),O(q,`Compiled topology · ${n.locations?.length??0} locations`,(n.locations??[]).map(o=>{const a=Object.keys(o.routes??{}),l=[...o.persistent_features??[]];return`${o.name} · ${o.id}${o.container_id?` · inside ${o.container_id}`:""}${a.length?` · routes to ${a.join(", ")}`:" · no compiled route"}${l.length?` · ${l.join(", ")}`:""}`})),N.textContent="Destination preview compiled; topology is unchanged until approval.";const i=v("button","Approve destination");i.type="button",i.addEventListener("click",async()=>{await B(`/api/compiler/destination/approve/${t.preview_id}`,{}),i.remove(),await W()}),q.append(i)});document.querySelector("#fission-form").addEventListener("submit",async e=>{e.preventDefault();const t=new FormData(e.currentTarget),n=await B("/api/compiler/gestalt/fission",{parent_gestalt_id:t.get("parent_gestalt_id"),partition_axis:t.get("partition_axis"),requested_partition_values:String(t.get("requested_partition_values")??"").split(",").map(o=>o.trim()).filter(Boolean),reason:t.get("reason")});V("Population fission preview",[...(n.preview?.gaps??[]).map(o=>`Material gap: ${o}`)]),O(q,`Canonical child leaves · ${n.preview?.children?.length??0}`,(n.preview?.children??[]).map(o=>`${o.name} · ${o.id} · ${o.partition_value??"other/unknown"} · at ${o.home_location_id}`)),N.textContent="Fission preview compiled. Canonical leaves are unchanged until approval.";const i=document.createElement("button");i.type="button",i.textContent="Approve population fission",i.addEventListener("click",async()=>{await B(`/api/compiler/gestalt/fission/approve/${n.preview_id}`,{}),i.remove(),await W()}),q.append(i)});document.querySelector("#fork-form").addEventListener("submit",async e=>{e.preventDefault(),await B("/api/campaigns/fork",Object.fromEntries(new FormData(e.currentTarget))),await W()});document.querySelector("#reset-form").addEventListener("submit",async e=>{e.preventDefault(),await B("/api/campaigns/reset",Object.fromEntries(new FormData(e.currentTarget))),await W()});document.querySelector("#load-operator").addEventListener("click",async()=>{const t=await(await fetch("/api/operator")).json();rt(t,document.querySelector("#operator-output"),{body:document.body,clientId:"ghostlight.operator",statusElement:N})});W(); diff --git a/web/dist/index.html b/web/dist/index.html index 90deeff..1c95e81 100644 --- a/web/dist/index.html +++ b/web/dist/index.html @@ -1,5 +1,5 @@ -GhostlightDungeon +GhostlightDungeon

STARFIRE / PRIVATE VERSE

GhostlightDungeon

Reading the world…

@@ -12,5 +12,5 @@ +
Export selected CultCache .cc Export canon candidates Markdown
diff --git a/web/index.html b/web/index.html index 73d3b1f..23741e3 100644 --- a/web/index.html +++ b/web/index.html @@ -10,5 +10,5 @@ +
Export selected CultCache .cc Export canon candidates Markdown diff --git a/web/src/main.ts b/web/src/main.ts index 888b827..2ce95f1 100644 --- a/web/src/main.ts +++ b/web/src/main.ts @@ -11,6 +11,8 @@ const destinationForm = document.querySelector("#destination-fo const compilerResults = document.querySelector("#compiler-results")!; const campaignLab = document.querySelector("#campaign-lab")!; const campaignList = document.querySelector("#campaign-list")!; +const operatorLab = document.querySelector("#operator-lab")!; +operatorLab.hidden = !["127.0.0.1", "localhost", "::1"].includes(window.location.hostname); let revision = 0; let playerActorId = ""; let resolutionEpoch = 0;