1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- A PreToolUse hook, end to end: take the payload, decide, write the envelope.
--
-- The host passes this directory as an argument, so nothing here is spelled as a path that is
-- true only on the machine the example was built on.
local here = arg
-- The stdin dance below is scaffolding, and it is the one place this example is not what you
-- would ship. A real hook's first line is `local payload = airsstack.hook.payload()` and there is
-- no second one, because the host always has a document to hand it.
--
-- `payload()` reads *this process's own* stdin, and there is no seam to inject anything else
-- through -- so read unconditionally and the example blocks forever on a terminal, waiting for a
-- person to type JSON. Asking `isatty` first is what avoids that: a terminal means nobody piped
-- anything in, so there is nothing to read. Under `cargo make examples` stdin is not a tty but is
-- already at end of stream, and `payload()` answers an empty table rather than raising, because
-- no payload is not a parse failure (src/modules/hook.rs:90).
--
-- Both of those fall through to the bundled `payload.json`, so the terminal run and the CI run
-- print the same bytes -- and piping that same file in takes the `payload()` path and prints them
-- a third time, because it is the same document.
local payload =
if not airsstack..
if next == nil
local event = payload.
local input = payload. or
local file = input. or ""
-- Every line this script prints goes through `airsstack.stdio`, never Lua's own `print`. Not for
-- ordering -- both flush per line, so they interleave correctly -- but because `print` appends a
-- newline and cannot be told not to. On this stream the bytes are the interface, and a writer that
-- adds one of its own is the wrong tool whatever it is being asked to write.
airsstack..
if airsstack.. == "lua"
-- `emit` imposes no shape at all -- it is the escape hatch for whatever `context` does not model.
airsstack..
airsstack..
airsstack..
-- Nothing here exits, and nothing here can. Only the process's exit status blocks the tool call a
-- PreToolUse hook fired on; a message on stdout or stderr never does. That status belongs to the
-- host and its FailurePolicy, which is why a hook that disagrees with a tool call still returns
-- normally and says so in the envelope.