55 lines
1.3 KiB
Python
55 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Claude SessionStart additionalContext producer for P6 observation."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
BLOCK = "\n".join(
|
|
[
|
|
"GATE0_CLAUDE_ATOMIC_BEGIN",
|
|
"segment-01=alpha-2d11",
|
|
"segment-02=middle-8e22",
|
|
"segment-03=omega-4f33",
|
|
"GATE0_CLAUDE_ATOMIC_END",
|
|
]
|
|
)
|
|
|
|
|
|
def starttime(pid: int) -> int:
|
|
text = Path(f"/proc/{pid}/stat").read_text()
|
|
return int(text[text.rfind(")") + 2 :].split()[19])
|
|
|
|
|
|
def main() -> None:
|
|
hook_input = json.load(sys.stdin)
|
|
log = Path(os.environ["GATE0_CLAUDE_HOOK_LOG"])
|
|
record = {
|
|
"hook_event_name": hook_input.get("hook_event_name"),
|
|
"pid": os.getpid(),
|
|
"ppid": os.getppid(),
|
|
"starttime_ticks": starttime(os.getpid()),
|
|
"block_length": len(BLOCK.encode()),
|
|
"block_sha256": hashlib.sha256(BLOCK.encode()).hexdigest(),
|
|
"emission": "one hookSpecificOutput.additionalContext string field",
|
|
}
|
|
log.write_text(json.dumps(record, sort_keys=True) + "\n")
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"hookSpecificOutput": {
|
|
"hookEventName": "SessionStart",
|
|
"additionalContext": BLOCK,
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|