-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·150 lines (129 loc) · 4.52 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·150 lines (129 loc) · 4.52 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/zsh
set -euo pipefail
ROOT="${0:A:h}"
APP_NAME="Codex Beacon.app"
APP_SOURCE="$ROOT/dist/$APP_NAME"
if [[ ! -d "$APP_SOURCE" ]]; then
APP_SOURCE="$ROOT/$APP_NAME"
fi
APP_DEST="/Applications/$APP_NAME"
WIDGET_DEST="$APP_DEST/Contents/PlugIns/CodexBeaconWidget.appex"
WIDGET_SOURCE="$APP_SOURCE/Contents/PlugIns/CodexBeaconWidget.appex"
WIDGET_ID="com.codexbeacon.native.widget"
HOOKS_FILE="$HOME/.codex/hooks.json"
HELPER="$APP_DEST/Contents/Resources/helper/notify.sh"
safe_rm_app_dest() {
[[ "$APP_DEST" == "/Applications/Codex Beacon.app" ]] || { echo "Refusing to remove unexpected path: $APP_DEST"; exit 1; }
[[ -e "$APP_DEST" || -L "$APP_DEST" ]] || return 0
/bin/rm -rf "$APP_DEST"
}
if [[ "${1:-}" == "--check" ]]; then
[[ -d "$APP_SOURCE" ]] || { echo "Missing app: $APP_SOURCE"; exit 1; }
[[ -x "$APP_SOURCE/Contents/Resources/helper/notify.sh" ]] || { echo "Missing helper in app bundle"; exit 1; }
/usr/bin/plutil -lint "$APP_SOURCE/Contents/Info.plist" >/dev/null
if [[ -f "$HOOKS_FILE" ]]; then
/usr/bin/osascript -l JavaScript - "$HOOKS_FILE" <<'JXA' >/dev/null
function run(argv) {
ObjC.import("Foundation");
const text = $.NSString.stringWithContentsOfFileEncodingError(argv[0], $.NSUTF8StringEncoding, null);
JSON.parse(ObjC.unwrap(text));
}
JXA
fi
echo "Codex Beacon is ready to install."
exit 0
fi
[[ -d "$APP_SOURCE" ]] || { echo "Missing app: $APP_SOURCE"; exit 1; }
[[ -x "$APP_SOURCE/Contents/Resources/helper/notify.sh" ]] || { echo "Missing helper in app bundle"; exit 1; }
/usr/bin/osascript -e 'quit application "Codex Beacon"' >/dev/null 2>&1 || true
safe_rm_app_dest
/usr/bin/ditto "$APP_SOURCE" "$APP_DEST"
/bin/chmod +x "$HELPER"
if [[ -d "$WIDGET_DEST" ]]; then
if [[ -d "$WIDGET_SOURCE" && "$WIDGET_SOURCE" != "$WIDGET_DEST" ]]; then
/usr/bin/pluginkit -r "$WIDGET_SOURCE" >/dev/null 2>&1 || true
fi
/usr/bin/pluginkit -a "$WIDGET_DEST" >/dev/null 2>&1 || true
/usr/bin/pluginkit -e use -i "$WIDGET_ID" >/dev/null 2>&1 || true
/usr/bin/killall chronod >/dev/null 2>&1 || true
fi
/bin/mkdir -p "$HOME/.codex"
if [[ -f "$HOOKS_FILE" ]]; then
/bin/cp "$HOOKS_FILE" "$HOOKS_FILE.codex-beacon-backup"
fi
/usr/bin/osascript -l JavaScript - "$HOOKS_FILE" "$HELPER" <<'JXA'
function run(argv) {
ObjC.import("Foundation");
const hooksPath = argv[0];
const helper = argv[1];
const commandHelper = `'${helper.replace(/'/g, "'\\''")}'`;
function fileExists(path) {
return $.NSFileManager.defaultManager.fileExistsAtPath(path);
}
function readText(path) {
const text = $.NSString.stringWithContentsOfFileEncodingError(path, $.NSUTF8StringEncoding, null);
return text ? ObjC.unwrap(text) : "";
}
function writeText(path, text) {
const value = $.NSString.alloc.initWithUTF8String(text);
value.writeToFileAtomicallyEncodingError(path, true, $.NSUTF8StringEncoding, null);
}
let root = { hooks: {} };
if (fileExists(hooksPath)) {
root = JSON.parse(readText(hooksPath));
}
if (!root || typeof root !== "object" || Array.isArray(root)) {
root = { hooks: {} };
}
if (!root.hooks || typeof root.hooks !== "object" || Array.isArray(root.hooks)) {
root.hooks = {};
}
const ownedFragments = [
"codex-beacon-native/notify.sh",
"Codex Beacon.app/Contents/Resources/helper/notify.sh",
"codex-beacon/run.sh",
"codex-mac-attention"
];
function cleanHooks(items) {
if (!Array.isArray(items)) return [];
return items
.map((entry) => {
if (!entry || typeof entry !== "object") return entry;
const hooks = Array.isArray(entry.hooks) ? entry.hooks : [];
const nextHooks = hooks.filter((hook) => {
const command = typeof hook?.command === "string" ? hook.command : "";
return !ownedFragments.some((fragment) => command.includes(fragment));
});
return { ...entry, hooks: nextHooks };
})
.filter((entry) => !Array.isArray(entry?.hooks) || entry.hooks.length > 0);
}
root.hooks.PermissionRequest = cleanHooks(root.hooks.PermissionRequest);
root.hooks.Stop = cleanHooks(root.hooks.Stop);
root.hooks.PermissionRequest.push({
matcher: "*",
hooks: [
{
type: "command",
command: `${commandHelper} permission_request`,
timeout: 3,
statusMessage: "Signaling Codex Beacon"
}
]
});
root.hooks.Stop.push({
hooks: [
{
type: "command",
command: `${commandHelper} turn_done`,
timeout: 3,
statusMessage: "Signaling Codex Beacon"
}
]
});
writeText(hooksPath, JSON.stringify(root, null, 2) + "\n");
}
JXA
/usr/bin/open "$APP_DEST"
echo "Installed Codex Beacon."
echo "Restart Codex, then trust the updated hooks."