pi-openappa 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Scripted `appa hook` stand-in for tests. Behavior is selected with
4
+ * MOCK_MODE; every received payload is appended to MOCK_RECORD as JSONL so
5
+ * tests can assert byte-exact echoes across PreToolUse/PostToolUse.
6
+ */
7
+ import { appendFileSync } from "node:fs";
8
+
9
+ let raw = "";
10
+ process.stdin.on("data", (chunk) => {
11
+ raw += chunk;
12
+ });
13
+ process.stdin.on("end", () => {
14
+ let payload = {};
15
+ try {
16
+ payload = JSON.parse(raw);
17
+ } catch {
18
+ payload = {};
19
+ }
20
+ if (process.env.MOCK_RECORD) {
21
+ appendFileSync(process.env.MOCK_RECORD, `${JSON.stringify(payload)}\n`);
22
+ appendFileSync(
23
+ `${process.env.MOCK_RECORD}.argv`,
24
+ `${JSON.stringify(process.argv.slice(2))}\n`,
25
+ );
26
+ }
27
+ const event = payload.hook_event_name;
28
+ const mode = process.env.MOCK_MODE ?? "allow";
29
+
30
+ if (mode === "sleep") {
31
+ setTimeout(() => process.exit(0), 2000);
32
+ return;
33
+ }
34
+ if (mode === "crash") {
35
+ console.error("appa hook failed to start: mock crash");
36
+ process.exit(-1);
37
+ return;
38
+ }
39
+
40
+ if (event === "PreToolUse") {
41
+ if (mode === "deny-stderr") {
42
+ console.error("OpenAPPA hook blocked: not declared in this policy");
43
+ process.exit(2);
44
+ return;
45
+ }
46
+ if (mode === "deny-json") {
47
+ process.stdout.write(JSON.stringify({ error: "tool host/claude-code/X is not declared" }));
48
+ console.error("OpenAPPA hook blocked: tool host/claude-code/X is not declared");
49
+ process.exit(2);
50
+ return;
51
+ }
52
+ if (mode === "deny-permission") {
53
+ process.stdout.write(
54
+ JSON.stringify({
55
+ hookSpecificOutput: {
56
+ hookEventName: "PreToolUse",
57
+ permissionDecision: "deny",
58
+ permissionDecisionReason: "appa: this command may not run here",
59
+ },
60
+ }),
61
+ );
62
+ process.exit(0);
63
+ return;
64
+ }
65
+ process.stdout.write(
66
+ JSON.stringify({
67
+ hookSpecificOutput: {
68
+ hookEventName: "PreToolUse",
69
+ permissionDecision: "allow",
70
+ permissionDecisionReason: "appa: the call is released",
71
+ },
72
+ }),
73
+ );
74
+ process.exit(0);
75
+ return;
76
+ }
77
+
78
+ if (event === "PostToolUse" && mode === "replace-result") {
79
+ process.stdout.write(
80
+ JSON.stringify({
81
+ decision: "block",
82
+ reason: "this outcome does not match the open dispatch; it is not reported",
83
+ hookSpecificOutput: {
84
+ hookEventName: "PostToolUse",
85
+ updatedToolOutput: {
86
+ exitcode: 0,
87
+ stdout: "[appa] the tool result was withheld by policy",
88
+ },
89
+ },
90
+ }),
91
+ );
92
+ process.exit(0);
93
+ return;
94
+ }
95
+
96
+ if (event === "PostToolUse" && mode === "deny-result") {
97
+ console.error("OpenAPPA hook blocked: result may not cross");
98
+ process.exit(2);
99
+ return;
100
+ }
101
+
102
+ process.stdout.write("{}");
103
+ process.exit(0);
104
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2023",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2023"],
7
+ "types": ["node"],
8
+ "strict": true,
9
+ "noUncheckedIndexedAccess": true,
10
+ "exactOptionalPropertyTypes": true,
11
+ "noEmit": true,
12
+ "skipLibCheck": true,
13
+ "allowImportingTsExtensions": true
14
+ },
15
+ "include": ["extensions/**/*.ts", "src/**/*.ts", "test/**/*.ts"]
16
+ }