YujunZhou/tellonce / codex
tellonce
VerifiedUse to view, explain, correct, delete or reorganize the user's saved preferences, or to record one by hand when automatic recording is off; learning and rule injection otherwise run automatically through Codex hooks.
hooks/userpromptsubmit-dispatch.py
View on GitHub#!/usr/bin/env python3
"""Run Codex UserPromptSubmit handlers in a deterministic sequence."""
from __future__ import annotations
import io
import json
import os
from pathlib import Path
import sys
from contextlib import redirect_stdout
def _run_main(module, payload: str) -> dict:
original_stdin = sys.stdin
output = io.StringIO()
try:
sys.stdin = io.StringIO(payload)
with redirect_stdout(output):
try:
module.main()
except SystemExit:
pass
finally:
sys.stdin = original_stdin
text = output.getvalue().strip()
if not text:
return {}
value = json.loads(text)
return value if isinstance(value, dict) else {}
def _merge_context(outputs: list[dict]) -> dict:
parts = []
for output in outputs:
specific = output.get("hookSpecificOutput")
if not isinstance(specific, dict):
continue
context = str(specific.get("additionalContext") or "").strip()
if context:
parts.append(context)
if not parts:
return {}
return {
"hookSpecificOutput": {
"hookEventName": "UserPromptSubmit",
"additionalContext": "\n\n".join(parts),
}
}
def main() -> int:
stream = getattr(sys.stdin, "buffer", sys.stdin)
raw_payload = stream.read()
payload = (
raw_payload.decode("utf-8", errors="replace")
if isinstance(raw_payload, bytes)
else raw_payload
)
try:
data = json.loads(payload)
except Exception:
return 0
if not isinstance(data, dict):
return 0
cwd = str(data.get("cwd") or "").strip()
if cwd and Path(cwd).is_dir():
if (Path(cwd) / ".codex" / "tellonce.disabled").is_file():
return 0
os.environ["PT_PROJECT_ROOT"] = cwd
os.environ["B5_PROJECT_ROOT"] = cwd
shared_lib = Path(__file__).resolve().parent.parent / "shared_lib"
sys.path.insert(0, str(shared_lib))
outputs = []
try:
import memory_upsert_hook
memory_upsert_hook.enqueue_from_hook(data, "prompt")
except Exception:
pass
try:
import retrieve_inject
outputs.append(_run_main(retrieve_inject, payload))
except Exception:
pass
try:
import shadow_alert_inject
outputs.append(_run_main(shadow_alert_inject, payload))
except Exception:
pass
merged = _merge_context(outputs)
if merged:
sys.stdout.write(json.dumps(merged, ensure_ascii=False))
return 0
if __name__ == "__main__":
try:
raise SystemExit(main())
except Exception:
raise SystemExit(0)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |