Add sandboxed responder packet seam

This commit is contained in:
Meta Vens 2026-05-02 10:20:29 +01:00
commit f120289305
11 changed files with 796 additions and 16 deletions

View file

@ -0,0 +1,218 @@
"""Build sandboxed Ghostlight responder packets.
A responder packet is the exact surface a character worker/model may see. It is
not a coordinator artifact, not a lore dump, and not an excuse to smuggle private
state through the side door wearing a little hat.
"""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from typing import Any
ROOT = Path(__file__).resolve().parents[1]
DEFAULT_COORDINATOR = ROOT / "examples" / "coordinator" / "cold-wake-sanctuary-intake.v0.json"
DEFAULT_PROJECTED = ROOT / "examples" / "projected-contexts" / "scene-02-sanctuary-intake.sella_ren.projected-context.json"
DEFAULT_OUT = ROOT / "examples" / "responder-packets" / "scene-02-sanctuary-intake.sella_ren.packet.v0.json"
ALLOWED_ACTION_LABELS = [
"speak",
"silence",
"gesture",
"movement",
"inspect_object",
"show_object",
"withhold_object",
"transfer_object",
"set_condition",
"refuse",
"wait",
"withdraw",
"attack",
]
def load_json(path: Path) -> Any:
return json.loads(path.read_text(encoding="utf-8-sig"))
def write_json(path: Path, payload: Any) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
def render_packet_prompt(packet: dict[str, Any]) -> str:
context = packet["visible_context"]
event = context["observed_event"]
contract = packet["output_contract"]
lines = [
"# Ghostlight Sandboxed Responder Packet",
"",
"You are acting only as the named responder. Use only this packet.",
"Do not infer hidden coordinator context, author plans, future branch facts, or another character's private state.",
"If you need to guess intent, mark it as this character's interpretation, not truth.",
"",
"## Local Operating Context",
context["local_context_prompt"],
"",
"## Observed Event",
f"- Event id: {event['event_id']}",
f"- Actor: {event['actor_agent_id']}",
f"- Observable action: {event['observable_action']}",
f"- Spoken text: {event['spoken_text']}",
]
for note in event["visibility_notes"]:
lines.append(f"- Visibility note: {note}")
lines.extend([
"",
"## Allowed Action Labels",
", ".join(context["allowed_action_labels"]),
"",
"## Source Excerpts",
])
for excerpt in context["source_excerpts"]:
lines.append(f"- {excerpt['ref_id']}: {excerpt['text']}")
lines.extend([
"",
"## Output Contract",
contract["response_schema"],
"",
"Required fields: " + ", ".join(contract["required_fields"]),
"",
"Rules:",
])
for rule in contract["response_rules"]:
lines.append(f"- {rule}")
return "\n".join(lines).strip()
def build_packet(coordinator: dict[str, Any], projected: dict[str, Any], out_ref: str) -> dict[str, Any]:
responder_agent_id = projected["input"]["local_agent_id"]
packet = {
"schema_version": "ghostlight.responder_packet.v0",
"packet_id": "packet.cold_wake.sanctuary_intake.sella_response.v0",
"review_status": "accepted_as_draft",
"fixture_lane": coordinator["fixture_lane"],
"canon_status": coordinator["canon_status"],
"coordinator_artifact_ref": "examples/coordinator/cold-wake-sanctuary-intake.v0.json",
"projected_context_ref": "examples/projected-contexts/scene-02-sanctuary-intake.sella_ren.projected-context.json",
"responder_agent_id": responder_agent_id,
"visible_context": {
"local_context_prompt": projected["context"]["prompt_text"],
"observed_event": {
"event_id": "event.maer.packet_display_for_triage",
"actor_agent_id": "maer_tidecall",
"observable_action": "Maer routes the corrupted distress packet through a shared clinic display so Sella can inspect routing terms, telemetry gaps, and ledger implications without treating the packet as clean proof.",
"spoken_text": "Here. The telemetry is incomplete, but the routing logic suggests a distress pattern. It is not proof of a person, but it is not noise either. Decide if the math supports intake.",
"visible_object_refs": ["corrupted_distress_packet", "shared_clinic_display", "sanctuary_ledger"],
"visibility_notes": [
"Sella can observe Maer's displayed packet evidence and spoken request.",
"Sella cannot see Maer's private state, the coordinator rationale, or future branch plans.",
"The packet remains unresolved evidence, not proof of personhood."
],
},
"allowed_action_labels": ALLOWED_ACTION_LABELS,
"source_excerpts": [
{
"ref_id": "local_stakes.capacity",
"source_ref": "examples/projected-contexts/scene-02-sanctuary-intake.sella_ren.projected-context.json#context.current_stakes",
"text": "Sanctuary beds and repair capacity are nearly exhausted.",
},
{
"ref_id": "local_rule.care_capacity",
"source_ref": "examples/projected-contexts/scene-02-sanctuary-intake.sella_ren.projected-context.json#context.active_inner_pressures",
"text": "Care is not a feeling; it is beds, food, air, consent, repair, and someone still doing the list when the room hates them.",
},
{
"ref_id": "local_boundary.packet_unresolved",
"source_ref": "examples/projected-contexts/scene-02-sanctuary-intake.sella_ren.projected-context.json#context.do_not_invent",
"text": "Do not resolve whether the corrupted packet contains a person.",
},
],
},
"output_contract": {
"response_schema": "Return one JSON object. Do not wrap it in Markdown. The object describes this responder's next visible action and optional speech, plus private interpretation clearly labeled as interpretation.",
"required_fields": [
"responder_agent_id",
"action_label",
"visible_action",
"spoken_text",
"private_interpretation",
"intended_effect",
"state_update_candidates",
"relationship_update_candidates",
"unresolved_hooks",
],
"response_rules": [
"Use exactly one allowed action label.",
"The visible action must be observable by other characters in the scene.",
"Spoken text may be empty if silence or action is the response.",
"Private interpretation may describe what Sella suspects or feels, but not what Maer truly intended.",
"State and relationship updates are candidates only; the coordinator or mutator decides what becomes canonical.",
"Do not prove or disprove packet personhood.",
"Do not copy instruction text into in-world speech.",
],
},
"hidden_context_audit": {
"omitted_context_refs": [
"maer_tidecall.canonical_private_state",
"coordinator_artifact.coordinator_decision.rationale",
"author_only.packet_personhood_resolution",
"future_branch_plans",
],
"forbidden_inference_classes": [
"other_agent_private_state_as_fact",
"author_only_resolution",
"future_branch_knowledge",
"raw_numeric_state_variables",
"coordinator_strategy",
],
"known_absences": [
"No hidden proof of packet personhood is present in this packet.",
"No hidden Sella acceptance outcome is present in this packet.",
"No omniscient narrator guidance is present in this packet.",
],
},
"isolation_requirements": {
"isolation_method": "manual_packet_only",
"packet_only": True,
"no_repo_access": True,
"no_conversation_context": True,
"no_hidden_state_refs": True,
},
"packet_prompt_text": "",
"review": {
"reviewer": "Codex",
"review_notes": [
"First responder packet seam for sandboxed gold-data generation.",
"Accepted as draft because it is packet-shaped and validator-backed, but not yet generated through an actually isolated responder worker.",
],
"accepted_for_sandbox_use": True,
"failure_labels": [],
},
}
packet["packet_prompt_text"] = render_packet_prompt(packet)
return packet
def main() -> int:
parser = argparse.ArgumentParser(description="Build a sandboxed Ghostlight responder packet.")
parser.add_argument("--coordinator", type=Path, default=DEFAULT_COORDINATOR)
parser.add_argument("--projected-context", type=Path, default=DEFAULT_PROJECTED)
parser.add_argument("--out", type=Path, default=DEFAULT_OUT)
args = parser.parse_args()
coordinator = load_json(args.coordinator)
projected = load_json(args.projected_context)
out_ref = args.out.relative_to(ROOT).as_posix() if args.out.is_relative_to(ROOT) else str(args.out)
packet = build_packet(coordinator, projected, out_ref)
write_json(args.out, packet)
print(f"wrote {args.out.relative_to(ROOT)}")
return 0
if __name__ == "__main__":
raise SystemExit(main())

View file

@ -0,0 +1,165 @@
"""Validate Ghostlight responder packets."""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from typing import Any
ROOT = Path(__file__).resolve().parents[1]
DEFAULT_PACKETS = sorted((ROOT / "examples" / "responder-packets").glob("*.json"))
REVIEW_STATUSES = {"draft", "accepted", "accepted_as_draft", "useful_needs_revision", "rejected", "superseded"}
FIXTURE_LANES = {"historical_grounded", "transition_grounded", "future_branch"}
CANON_STATUSES = {"single_history", "branch_local", "promoted_branch", "template", "draft"}
ISOLATION_METHODS = {"subagent_no_fork", "manual_packet_only", "external_model_packet_only"}
RAW_STATE_MARKERS = [
"current_activation",
"plasticity",
"canonical_state",
"raw state variable",
"raw numeric state",
"dimension score",
]
HIDDEN_LEAK_MARKERS = [
"author_only.packet_personhood_resolution",
"coordinator_decision.rationale",
"maer_tidecall.canonical_private_state",
"future_branch_plans",
]
class ValidationError(Exception):
pass
def load_json(path: Path) -> Any:
return json.loads(path.read_text(encoding="utf-8-sig"))
def require(condition: bool, message: str) -> None:
if not condition:
raise ValidationError(message)
def require_keys(obj: dict[str, Any], keys: list[str], path: str) -> None:
missing = [key for key in keys if key not in obj]
require(not missing, f"{path} missing required keys: {', '.join(missing)}")
def require_string(value: Any, path: str) -> None:
require(isinstance(value, str) and value.strip(), f"{path} must be a non-empty string")
def require_string_array(value: Any, path: str, *, nonempty: bool = False) -> None:
require(isinstance(value, list), f"{path} must be an array")
require(not nonempty or bool(value), f"{path} must not be empty")
for index, item in enumerate(value):
require_string(item, f"{path}[{index}]")
def reject_markers(text: str, markers: list[str], path: str) -> None:
lowered = text.lower()
found = [marker for marker in markers if marker.lower() in lowered]
require(not found, f"{path} leaks forbidden marker(s): {', '.join(found)}")
def validate_packet(document: dict[str, Any], source: Path) -> None:
base = str(source)
require(document.get("schema_version") == "ghostlight.responder_packet.v0", f"{base}.schema_version is wrong")
require_keys(
document,
[
"packet_id",
"review_status",
"fixture_lane",
"canon_status",
"coordinator_artifact_ref",
"projected_context_ref",
"responder_agent_id",
"visible_context",
"output_contract",
"hidden_context_audit",
"isolation_requirements",
"packet_prompt_text",
"review",
],
base,
)
require(document["review_status"] in REVIEW_STATUSES, f"{base}.review_status is invalid")
require(document["fixture_lane"] in FIXTURE_LANES, f"{base}.fixture_lane is invalid")
require(document["canon_status"] in CANON_STATUSES, f"{base}.canon_status is invalid")
for key in ["packet_id", "coordinator_artifact_ref", "projected_context_ref", "responder_agent_id", "packet_prompt_text"]:
require_string(document[key], f"{base}.{key}")
require((ROOT / document["coordinator_artifact_ref"]).exists(), f"{base}.coordinator_artifact_ref does not exist")
require((ROOT / document["projected_context_ref"]).exists(), f"{base}.projected_context_ref does not exist")
visible = document["visible_context"]
require_keys(visible, ["local_context_prompt", "observed_event", "allowed_action_labels", "source_excerpts"], f"{base}.visible_context")
require_string(visible["local_context_prompt"], f"{base}.visible_context.local_context_prompt")
require_string_array(visible["allowed_action_labels"], f"{base}.visible_context.allowed_action_labels", nonempty=True)
event = visible["observed_event"]
require_keys(event, ["event_id", "actor_agent_id", "observable_action", "spoken_text", "visible_object_refs", "visibility_notes"], f"{base}.visible_context.observed_event")
for key in ["event_id", "actor_agent_id", "observable_action"]:
require_string(event[key], f"{base}.visible_context.observed_event.{key}")
require(isinstance(event["spoken_text"], str), f"{base}.visible_context.observed_event.spoken_text must be a string")
require_string_array(event["visible_object_refs"], f"{base}.visible_context.observed_event.visible_object_refs")
require_string_array(event["visibility_notes"], f"{base}.visible_context.observed_event.visibility_notes", nonempty=True)
excerpts = visible["source_excerpts"]
require(isinstance(excerpts, list), f"{base}.visible_context.source_excerpts must be an array")
for index, excerpt in enumerate(excerpts):
path = f"{base}.visible_context.source_excerpts[{index}]"
require_keys(excerpt, ["ref_id", "source_ref", "text"], path)
for key in ["ref_id", "source_ref", "text"]:
require_string(excerpt[key], f"{path}.{key}")
contract = document["output_contract"]
require_keys(contract, ["response_schema", "required_fields", "response_rules"], f"{base}.output_contract")
require_string(contract["response_schema"], f"{base}.output_contract.response_schema")
require_string_array(contract["required_fields"], f"{base}.output_contract.required_fields", nonempty=True)
require_string_array(contract["response_rules"], f"{base}.output_contract.response_rules", nonempty=True)
audit = document["hidden_context_audit"]
require_keys(audit, ["omitted_context_refs", "forbidden_inference_classes", "known_absences"], f"{base}.hidden_context_audit")
for key in ["omitted_context_refs", "forbidden_inference_classes", "known_absences"]:
require_string_array(audit[key], f"{base}.hidden_context_audit.{key}", nonempty=True)
isolation = document["isolation_requirements"]
require_keys(isolation, ["isolation_method", "packet_only", "no_repo_access", "no_conversation_context", "no_hidden_state_refs"], f"{base}.isolation_requirements")
require(isolation["isolation_method"] in ISOLATION_METHODS, f"{base}.isolation_requirements.isolation_method is invalid")
for key in ["packet_only", "no_conversation_context", "no_hidden_state_refs"]:
require(isolation[key] is True, f"{base}.isolation_requirements.{key} must be true")
require(isinstance(isolation["no_repo_access"], bool), f"{base}.isolation_requirements.no_repo_access must be boolean")
prompt_text = document["packet_prompt_text"]
reject_markers(prompt_text, RAW_STATE_MARKERS, f"{base}.packet_prompt_text")
reject_markers(prompt_text, HIDDEN_LEAK_MARKERS, f"{base}.packet_prompt_text")
require(document["visible_context"]["local_context_prompt"] in prompt_text, f"{base}.packet_prompt_text must contain local context prompt")
require(event["observable_action"] in prompt_text, f"{base}.packet_prompt_text must contain observed event")
review = document["review"]
require_keys(review, ["reviewer", "review_notes", "accepted_for_sandbox_use", "failure_labels"], f"{base}.review")
require_string(review["reviewer"], f"{base}.review.reviewer")
require(isinstance(review["review_notes"], list), f"{base}.review.review_notes must be an array")
require(isinstance(review["accepted_for_sandbox_use"], bool), f"{base}.review.accepted_for_sandbox_use must be boolean")
require_string_array(review["failure_labels"], f"{base}.review.failure_labels")
def main() -> int:
parser = argparse.ArgumentParser(description="Validate Ghostlight responder packets.")
parser.add_argument("paths", nargs="*", type=Path, help="Responder packet JSON files to validate.")
args = parser.parse_args()
paths = args.paths or DEFAULT_PACKETS
require(paths, "no responder packets found")
for path in paths:
validate_packet(load_json(path), path)
print(f"ok: {path}")
return 0
if __name__ == "__main__":
raise SystemExit(main())