Persist invite and session authority
This commit is contained in:
parent
ab39d8cdac
commit
26971eadbc
7 changed files with 95 additions and 20 deletions
|
|
@ -16,7 +16,9 @@ use ghostlight_dungeon::{
|
|||
surface::player_surface,
|
||||
vault::VoidBotMcpVault,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
net::SocketAddr,
|
||||
|
|
@ -31,13 +33,25 @@ use tracing_subscriber::EnvFilter;
|
|||
struct AppState {
|
||||
kernel: WorldKernel,
|
||||
store: CampaignStore,
|
||||
invites: Arc<Mutex<BTreeSet<String>>>,
|
||||
sessions: Arc<Mutex<BTreeSet<String>>>,
|
||||
auth: Arc<Mutex<AuthOwner>>,
|
||||
deepseek_status: String,
|
||||
compiler: Option<Arc<WorldCompiler>>,
|
||||
compile_previews: Arc<Mutex<BTreeMap<String, WorldCompilePreview>>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
struct AuthState {
|
||||
schema: String,
|
||||
unused_invite_hashes: BTreeSet<String>,
|
||||
session_hashes: BTreeSet<String>,
|
||||
}
|
||||
|
||||
struct AuthOwner {
|
||||
store: CampaignStore,
|
||||
row: cultcache_rs::CultCacheEnvelope,
|
||||
state: AuthState,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt()
|
||||
|
|
@ -74,6 +88,28 @@ async fn main() -> anyhow::Result<()> {
|
|||
"GhostlightDungeon requires exactly two unused invite tokens"
|
||||
));
|
||||
}
|
||||
std::fs::create_dir_all(runtime_root.join("service"))?;
|
||||
let auth_store = CampaignStore::open(runtime_root.join("service/auth.cc"))?;
|
||||
let (auth_row, auth_state) = match auth_store.load::<AuthState>("auth_state.v1", "primary")? {
|
||||
Some(existing) => existing,
|
||||
None => {
|
||||
let state = AuthState {
|
||||
schema: "ghostlight.auth_state.v1".into(),
|
||||
unused_invite_hashes: invite_tokens
|
||||
.iter()
|
||||
.map(|token| secret_hash(token))
|
||||
.collect(),
|
||||
session_hashes: BTreeSet::new(),
|
||||
};
|
||||
let row = auth_store.insert(
|
||||
"auth_state.v1",
|
||||
"ghostlight.auth_state.v1",
|
||||
"primary",
|
||||
&state,
|
||||
)?;
|
||||
(row, state)
|
||||
}
|
||||
};
|
||||
let secret_path = runtime_root.join("secrets/deepseek.dpapi");
|
||||
let (deepseek_status, compiler) = if secret_path.is_file() {
|
||||
let provider: Arc<dyn ModelPort> =
|
||||
|
|
@ -104,8 +140,11 @@ async fn main() -> anyhow::Result<()> {
|
|||
let state = AppState {
|
||||
kernel,
|
||||
store,
|
||||
invites: Arc::new(Mutex::new(invite_tokens)),
|
||||
sessions: Arc::new(Mutex::new(BTreeSet::new())),
|
||||
auth: Arc::new(Mutex::new(AuthOwner {
|
||||
store: auth_store,
|
||||
row: auth_row,
|
||||
state: auth_state,
|
||||
})),
|
||||
deepseek_status,
|
||||
compiler,
|
||||
compile_previews: Arc::new(Mutex::new(BTreeMap::new())),
|
||||
|
|
@ -128,7 +167,9 @@ async fn main() -> anyhow::Result<()> {
|
|||
.route("/api/command", post(command))
|
||||
.fallback_service(ServeDir::new(web_root).append_index_html_on_directories(true))
|
||||
.with_state(state);
|
||||
let address: SocketAddr = "0.0.0.0:8831".parse()?;
|
||||
let address: SocketAddr = std::env::var("GHOSTLIGHT_DUNGEON_BIND")
|
||||
.unwrap_or_else(|_| "0.0.0.0:8831".into())
|
||||
.parse()?;
|
||||
let listener = tokio::net::TcpListener::bind(address).await?;
|
||||
tracing::info!(%address, "GhostlightDungeon listening");
|
||||
axum::serve(listener, app).await?;
|
||||
|
|
@ -142,11 +183,23 @@ async fn health(State(state): State<AppState>) -> Json<serde_json::Value> {
|
|||
}
|
||||
|
||||
async fn invite(Path(token): Path<String>, State(state): State<AppState>) -> Response {
|
||||
if !state.invites.lock().await.remove(&token) {
|
||||
let mut auth = state.auth.lock().await;
|
||||
if !auth.state.unused_invite_hashes.remove(&secret_hash(&token)) {
|
||||
return (StatusCode::UNAUTHORIZED, "invalid or consumed invite").into_response();
|
||||
}
|
||||
let session = uuid::Uuid::new_v4().to_string();
|
||||
state.sessions.lock().await.insert(session.clone());
|
||||
auth.state.session_hashes.insert(secret_hash(&session));
|
||||
let next = match auth
|
||||
.store
|
||||
.replace(&auth.row, "ghostlight.auth_state.v1", &auth.state)
|
||||
{
|
||||
Ok(row) => row,
|
||||
Err(error) => {
|
||||
return (StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response();
|
||||
}
|
||||
};
|
||||
auth.row = next;
|
||||
drop(auth);
|
||||
let mut response = Redirect::to("/").into_response();
|
||||
response.headers_mut().insert(
|
||||
header::SET_COOKIE,
|
||||
|
|
@ -351,11 +404,21 @@ async fn authorized(headers: &HeaderMap, state: &AppState) -> bool {
|
|||
.find_map(|cookie| cookie.strip_prefix("ghostlight_session="))
|
||||
});
|
||||
match session {
|
||||
Some(id) => state.sessions.lock().await.contains(id),
|
||||
Some(id) => state
|
||||
.auth
|
||||
.lock()
|
||||
.await
|
||||
.state
|
||||
.session_hashes
|
||||
.contains(&secret_hash(id)),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn secret_hash(value: &str) -> String {
|
||||
format!("sha256:{:x}", Sha256::digest(value.as_bytes()))
|
||||
}
|
||||
|
||||
fn load_campaign(store: &CampaignStore) -> anyhow::Result<Campaign> {
|
||||
let id = store
|
||||
.keys("campaign.v1")?
|
||||
|
|
|
|||
|
|
@ -40,6 +40,14 @@ retrieval beyond bounded source context, on-demand destination compilation,
|
|||
explicit gaps, and branch assumptions. It remained an uncommitted revision-0
|
||||
preview with `requires_approval: true`.
|
||||
|
||||
The invite/session authority is persisted separately in `service/auth.cc`.
|
||||
Only hashes of invite and session tokens enter CultCache. Consuming an invite
|
||||
atomically replaces that auth row, so daemon restart neither resurrects a used
|
||||
invite nor invalidates an established session. A disposable HTTP acceptance
|
||||
run verified unauthenticated `401`, pre-approval compiler surface, explicit
|
||||
approval, campaign/evidence persistence, session survival across restart, and
|
||||
`401` on consumed-invite reuse.
|
||||
|
||||
## Body and faculty map
|
||||
|
||||
| Faculty | Owner | Body | Authority |
|
||||
|
|
|
|||
|
|
@ -39,11 +39,12 @@ distinct openings and roles, compiles approval-gated custom starts, rejects
|
|||
invalid topology, and atomically admits campaign plus evidence only on
|
||||
approval. The browser now exposes generated opening/role selection and custom
|
||||
starts. A live DeepSeek plus VoidBot custom compilation passed with 30 witnessed
|
||||
source chunks and remained an uncommitted approval preview. Next, prove browser
|
||||
session/invite flow plus approval persistence against a disposable campaign
|
||||
store, then add material-gap decisions, on-demand destination compilation, and
|
||||
canon-candidate persistence. Existing Ghostlight fixtures remain regression
|
||||
evidence.
|
||||
source chunks and remained an uncommitted approval preview. A disposable HTTP
|
||||
run then proved approval persistence, authenticated-session survival across
|
||||
restart, and rejection of consumed invite reuse using hashed auth state in a
|
||||
separate `.cc`. Next, add material-gap decisions, on-demand destination
|
||||
compilation, and canon-candidate persistence. Existing Ghostlight fixtures
|
||||
remain regression evidence.
|
||||
|
||||
## Prior research pipeline focus
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@ The active implementation cut is the world compiler. The first Rust seam now
|
|||
owns Vault witness conversion, distinct opening and role proposals,
|
||||
approval-gated custom compilation, deterministic seed validation, atomic
|
||||
campaign-plus-evidence admission, and the browser opening/role/custom flow. A
|
||||
live DeepSeek plus VoidBot custom compilation passed without committing. Prove
|
||||
invite/session plus approval persistence against a disposable campaign store,
|
||||
then implement material-gap decisions, on-demand destination compilation, and
|
||||
canon-candidate persistence before moving to the action/Persona loop.
|
||||
live DeepSeek plus VoidBot custom compilation passed without committing. A
|
||||
disposable HTTP run proved approval persistence and durable hashed invite and
|
||||
session state across restart. Implement material-gap decisions, on-demand
|
||||
destination compilation, and canon-candidate persistence before moving to the
|
||||
action/Persona loop.
|
||||
|
||||
## Prior research-program phase
|
||||
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
{"note": "Epiphany extraction map grounded in persona_turn.rs, persona_executor.rs, persona-service, conversation, and Discord crossing: shared orchestration moves to Ghostlight; Epiphany Mind/state/mouth stay; narrow slicer, transport, receipt, schema, and permit ports split; strict v1 removes second-channel state from Persona turn.", "status": "accepted", "ts": "2026-08-16T14:28:19+00:00", "type": "architecture"}
|
||||
{"note": "DeepSeek credential validated and migrated from plaintext ops ingress to machine-scoped DPAPI at the runtime root; native Rust DPAPI loading and live deepseek-v4-flash startup probe passed without persisting or displaying secret or reasoning content. Service ACL and protected invite generation remain in the elevated ops install.", "status": "ok", "ts": "2026-08-16T14:46:04+00:00", "type": "verification"}
|
||||
{"note": "GhostlightDungeon MVP deployed on Starfire as a normal detached operator process, not a Windows service. Exact release 747b27e9 listens on 8831, DeepSeek DPAPI startup inference is ready, unauthenticated surface access returns 401, PID/executable/log witnesses are recorded, and the obsolete stopped service was deleted.", "status": "ok", "ts": "2026-08-16T15:00:31+00:00", "type": "deployment"}
|
||||
{"ts": "2026-08-16T18:12:28+00:00", "type": "implementation", "status": "ok", "note": "World compiler live acceptance passed on 2026-08-16: DeepSeek v4 Pro consumed 30 hashed VoidBot witnesses across three receipts, emitted three locations, three actors, two institutions, two clocks, explicit gaps and branch assumptions, and remained an uncommitted revision-0 approval preview. Deterministic tests reject dangling routes and malformed typed seeds."}
|
||||
{"note": "World compiler live acceptance passed on 2026-08-16: DeepSeek v4 Pro consumed 30 hashed VoidBot witnesses across three receipts, emitted three locations, three actors, two institutions, two clocks, explicit gaps and branch assumptions, and remained an uncommitted revision-0 approval preview. Deterministic tests reject dangling routes and malformed typed seeds.", "status": "ok", "ts": "2026-08-16T18:12:28+00:00", "type": "implementation"}
|
||||
{"ts": "2026-08-16T18:17:14+00:00", "type": "verification", "status": "ok", "note": "Disposable HTTP acceptance proved unauthenticated 401, compiler-only surface before approval, explicit campaign admission with three evidence receipts, campaign reload after daemon restart, authenticated session survival after restart, and 401 on consumed-invite reuse. Auth CultCache stores token/session hashes rather than plaintext."}
|
||||
|
|
|
|||
|
|
@ -72,3 +72,4 @@
|
|||
{"key": "2026-08-16T144604Z0000-0070-b7d6330d1d5c", "payload": "eyJub3RlIjogIkRlZXBTZWVrIGNyZWRlbnRpYWwgdmFsaWRhdGVkIGFuZCBtaWdyYXRlZCBmcm9tIHBsYWludGV4dCBvcHMgaW5ncmVzcyB0byBtYWNoaW5lLXNjb3BlZCBEUEFQSSBhdCB0aGUgcnVudGltZSByb290OyBuYXRpdmUgUnVzdCBEUEFQSSBsb2FkaW5nIGFuZCBsaXZlIGRlZXBzZWVrLXY0LWZsYXNoIHN0YXJ0dXAgcHJvYmUgcGFzc2VkIHdpdGhvdXQgcGVyc2lzdGluZyBvciBkaXNwbGF5aW5nIHNlY3JldCBvciByZWFzb25pbmcgY29udGVudC4gU2VydmljZSBBQ0wgYW5kIHByb3RlY3RlZCBpbnZpdGUgZ2VuZXJhdGlvbiByZW1haW4gaW4gdGhlIGVsZXZhdGVkIG9wcyBpbnN0YWxsLiIsICJzdGF0dXMiOiAib2siLCAidHMiOiAiMjAyNi0wOC0xNlQxNDo0NjowNCswMDowMCIsICJ0eXBlIjogInZlcmlmaWNhdGlvbiJ9", "stored_at": "2026-08-16T14:46:04.295343+00:00", "type": "ghostlight.evidence_record.v0"}
|
||||
{"key": "2026-08-16T150031Z0000-0071-f1b3502e505f", "payload": "eyJub3RlIjogIkdob3N0bGlnaHREdW5nZW9uIE1WUCBkZXBsb3llZCBvbiBTdGFyZmlyZSBhcyBhIG5vcm1hbCBkZXRhY2hlZCBvcGVyYXRvciBwcm9jZXNzLCBub3QgYSBXaW5kb3dzIHNlcnZpY2UuIEV4YWN0IHJlbGVhc2UgNzQ3YjI3ZTkgbGlzdGVucyBvbiA4ODMxLCBEZWVwU2VlayBEUEFQSSBzdGFydHVwIGluZmVyZW5jZSBpcyByZWFkeSwgdW5hdXRoZW50aWNhdGVkIHN1cmZhY2UgYWNjZXNzIHJldHVybnMgNDAxLCBQSUQvZXhlY3V0YWJsZS9sb2cgd2l0bmVzc2VzIGFyZSByZWNvcmRlZCwgYW5kIHRoZSBvYnNvbGV0ZSBzdG9wcGVkIHNlcnZpY2Ugd2FzIGRlbGV0ZWQuIiwgInN0YXR1cyI6ICJvayIsICJ0cyI6ICIyMDI2LTA4LTE2VDE1OjAwOjMxKzAwOjAwIiwgInR5cGUiOiAiZGVwbG95bWVudCJ9", "stored_at": "2026-08-16T15:00:31.447772+00:00", "type": "ghostlight.evidence_record.v0"}
|
||||
{"key": "2026-08-16T181228Z0000-0072-4445afe2af66", "payload": "eyJub3RlIjogIldvcmxkIGNvbXBpbGVyIGxpdmUgYWNjZXB0YW5jZSBwYXNzZWQgb24gMjAyNi0wOC0xNjogRGVlcFNlZWsgdjQgUHJvIGNvbnN1bWVkIDMwIGhhc2hlZCBWb2lkQm90IHdpdG5lc3NlcyBhY3Jvc3MgdGhyZWUgcmVjZWlwdHMsIGVtaXR0ZWQgdGhyZWUgbG9jYXRpb25zLCB0aHJlZSBhY3RvcnMsIHR3byBpbnN0aXR1dGlvbnMsIHR3byBjbG9ja3MsIGV4cGxpY2l0IGdhcHMgYW5kIGJyYW5jaCBhc3N1bXB0aW9ucywgYW5kIHJlbWFpbmVkIGFuIHVuY29tbWl0dGVkIHJldmlzaW9uLTAgYXBwcm92YWwgcHJldmlldy4gRGV0ZXJtaW5pc3RpYyB0ZXN0cyByZWplY3QgZGFuZ2xpbmcgcm91dGVzIGFuZCBtYWxmb3JtZWQgdHlwZWQgc2VlZHMuIiwgInN0YXR1cyI6ICJvayIsICJ0cyI6ICIyMDI2LTA4LTE2VDE4OjEyOjI4KzAwOjAwIiwgInR5cGUiOiAiaW1wbGVtZW50YXRpb24ifQ==", "stored_at": "2026-08-16T18:12:28.266343+00:00", "type": "ghostlight.evidence_record.v0"}
|
||||
{"key": "2026-08-16T181714Z0000-0073-fbac9b66b666", "payload": "eyJub3RlIjogIkRpc3Bvc2FibGUgSFRUUCBhY2NlcHRhbmNlIHByb3ZlZCB1bmF1dGhlbnRpY2F0ZWQgNDAxLCBjb21waWxlci1vbmx5IHN1cmZhY2UgYmVmb3JlIGFwcHJvdmFsLCBleHBsaWNpdCBjYW1wYWlnbiBhZG1pc3Npb24gd2l0aCB0aHJlZSBldmlkZW5jZSByZWNlaXB0cywgY2FtcGFpZ24gcmVsb2FkIGFmdGVyIGRhZW1vbiByZXN0YXJ0LCBhdXRoZW50aWNhdGVkIHNlc3Npb24gc3Vydml2YWwgYWZ0ZXIgcmVzdGFydCwgYW5kIDQwMSBvbiBjb25zdW1lZC1pbnZpdGUgcmV1c2UuIEF1dGggQ3VsdENhY2hlIHN0b3JlcyB0b2tlbi9zZXNzaW9uIGhhc2hlcyByYXRoZXIgdGhhbiBwbGFpbnRleHQuIiwgInN0YXR1cyI6ICJvayIsICJ0cyI6ICIyMDI2LTA4LTE2VDE4OjE3OjE0KzAwOjAwIiwgInR5cGUiOiAidmVyaWZpY2F0aW9uIn0=", "stored_at": "2026-08-16T18:17:14.919779+00:00", "type": "ghostlight.evidence_record.v0"}
|
||||
|
|
|
|||
|
|
@ -254,5 +254,5 @@ data_flow:
|
|||
- If state grows faster than understanding, cut it back.
|
||||
|
||||
current_status:
|
||||
summary: GhostlightDungeon is the active MVP program. The world-compiler seam retrieves hashed VoidBot witnesses, generates distinct openings and roles, compiles approval-gated custom starts, rejects invalid typed topology, and admits campaign plus evidence through the WorldKernel only after approval. Its browser flow is built and a live DeepSeek plus VoidBot custom compilation passed with 30 witnessed chunks while remaining uncommitted. The broader hosted MVP remains incomplete.
|
||||
next_action: Prove invite/session and approval persistence through the HTTP harness against a disposable campaign store, then implement material-gap decisions, on-demand destination compilation, and canon-candidate persistence before moving to the action and Persona loop.
|
||||
summary: GhostlightDungeon is the active MVP program. The world-compiler seam retrieves hashed VoidBot witnesses, generates distinct openings and roles, compiles approval-gated custom starts, rejects invalid typed topology, and admits campaign plus evidence through the WorldKernel only after approval. Its browser flow is built; live DeepSeek plus VoidBot compilation passed with 30 witnessed chunks; disposable HTTP acceptance proved approval, campaign, hashed session, and consumed-invite persistence across restart. The broader hosted MVP remains incomplete.
|
||||
next_action: Implement material-gap decisions, on-demand destination compilation, and canon-candidate persistence before moving to the action and Persona loop.
|
||||
|
|
|
|||
Loading…
Reference in a new issue