memo: optional note-gate hook beside the store

A host may place an executable note-gate next to the memory directory to
classify or refuse notes before they are written. The gate records accepted
notes itself by calling memo with MEMO_UNGATED=1, so the check never recurses.
This commit is contained in:
w1n5t0n 2026-09-27 12:20:39 +03:00
parent 1fb164cf39
commit 112d66d5ae

7
memo
View file

@ -838,6 +838,13 @@ def main():
print("No such command: %s\n" % cmd, file=sys.stderr)
print(usage, file=sys.stderr)
sys.exit(1)
if cmd == "note" and not os.environ.get("MEMO_UNGATED"):
# An optional host hook beside the store may classify or refuse a note
# before it is written. It records accepted notes itself by calling
# back with MEMO_UNGATED=1, so this check never recurses.
gate = os.path.join(os.path.dirname(memory_dir()), "note-gate")
if os.access(gate, os.X_OK):
os.execv(gate, [gate] + sys.argv[2:])
try:
# `init` is the only command that may run without an existing memory:
# it is the one that creates it. Every other command refuses, so a