forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast-dev-bundle.sh
More file actions
executable file
·166 lines (146 loc) · 5.48 KB
/
Copy pathfast-dev-bundle.sh
File metadata and controls
executable file
·166 lines (146 loc) · 5.48 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env bash
# Side-effect-free helpers for run.sh's incremental development bundle lane.
# A successful full bundle records this fingerprint outside the app bundle. A
# later launch may reuse that bundle only when every packaged input and launch
# configuration still matches.
# shellcheck source=scripts/agent-runtime-payload.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/agent-runtime-payload.sh"
omi_fast_bundle_fingerprint() {
local macos_dir="$1"
shift
python3 - "$macos_dir" "$@" <<'PY'
import hashlib
import os
import stat
import sys
root = os.path.abspath(sys.argv[1])
config = sys.argv[2:]
digest = hashlib.sha256()
def record(value: str) -> None:
digest.update(value.encode("utf-8"))
digest.update(b"\0")
def record_file(relative: str, include_content: bool = True) -> None:
path = os.path.join(root, relative)
if not os.path.lexists(path):
record(f"missing:{relative}")
return
mode = os.lstat(path).st_mode
if stat.S_ISLNK(mode):
record(f"link:{relative}:{os.readlink(path)}")
return
if not stat.S_ISREG(mode):
record(f"unsupported:{relative}:{mode:o}")
return
details = os.stat(path)
record(f"file:{relative}:{mode & 0o7777:o}:{details.st_size}")
if include_content:
with open(path, "rb") as handle:
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
digest.update(chunk)
else:
# The universal Node executable is large and generated by the agent
# preparation step. Its size/mtime detects a changed staged runtime;
# agent source/package changes are already content-hashed below.
record(f"metadata:{details.st_size}:{details.st_mtime_ns}")
def record_tree(relative: str, *, exclude_names=None) -> None:
path = os.path.join(root, relative)
if not os.path.lexists(path):
record(f"missing-tree:{relative}")
return
if not os.path.isdir(path) or os.path.islink(path):
record_file(relative)
return
exclude_names = exclude_names or set()
record(f"tree:{relative}")
for current, dirs, files in os.walk(path, followlinks=False):
dirs[:] = sorted(name for name in dirs if name not in exclude_names)
files.sort()
for name in files:
nested = os.path.relpath(os.path.join(current, name), root)
record_file(nested)
for name in dirs:
nested = os.path.relpath(os.path.join(current, name), root)
if os.path.islink(os.path.join(current, name)):
record_file(nested)
record("schema:1")
for value in config:
record(f"config:{value}")
for path in [
"run.sh",
"omi_icon.icns",
"Desktop/Package.swift",
"Desktop/Package.resolved",
"Desktop/Info.plist",
"Desktop/Omi.entitlements",
"Desktop/Node.entitlements",
"Desktop/Omi-Release.entitlements",
"Desktop/Sources/GoogleService-Info.plist",
"Desktop/Sources/GoogleService-Info-Dev.plist",
"Desktop/Sources/GoogleService-Info-Local.plist",
"scripts/app-config.sh",
"scripts/prepare-agent-runtime.sh",
"scripts/agent-runtime-cache.sh",
"scripts/prepare-desktop-bundle-native-deps.sh",
"scripts/prepare-local-dev-entitlements.sh",
"scripts/audit-desktop-bundle-deps.sh",
"agent/package.json",
"agent/package-lock.json",
"agent/tsconfig.json",
"pi-mono-extension/package.json",
"pi-mono-extension/package-lock.json",
"pi-mono-extension/index.ts",
]:
record_file(path)
for path, excluded in [
("Desktop/CWebP", set()),
("Desktop/ObjCExceptionCatcher", set()),
("Desktop/Sources/Resources", {"node"}),
("agent/src", set()),
("agent/scripts", set()),
]:
record_tree(path, exclude_names=excluded)
record_file("Desktop/Sources/Resources/node", include_content=False)
print(digest.hexdigest())
PY
}
omi_fast_bundle_stamp_matches() {
local stamp="$1"
local expected_fingerprint="$2"
[ -f "$stamp" ] || return 1
[ "$(sed -n 's/^fingerprint=//p' "$stamp" | head -1)" = "$expected_fingerprint" ]
}
# Emit one stable eligibility reason. Callers can safely surface this to agents
# without attempting a full package build merely to discover why reuse failed.
#
# The fingerprint answers "are the packaged *inputs* unchanged"; it says nothing
# about whether the installed bundle still *contains* what those inputs produced.
# An interrupted install (`rm -rf "$APP_PATH"` then `ditto`), a hand-edited
# bundle, or any partial write leaves a stale stamp pointing at a bundle whose
# agent runtime is gone — which the fast lane would happily patch and relaunch,
# producing an app that accepts every chat turn and fails all of them. Verify the
# installed payload, not just the source fingerprint.
omi_fast_bundle_eligibility_reason() {
local app_path="$1"
local stamp="$2"
local expected_fingerprint="$3"
if [ ! -d "$app_path/Contents" ]; then
printf '%s\n' "no_installed_bundle"
elif [ ! -f "$stamp" ]; then
printf '%s\n' "missing_fast_fingerprint"
elif ! omi_fast_bundle_stamp_matches "$stamp" "$expected_fingerprint"; then
printf '%s\n' "fast_fingerprint_mismatch"
elif ! omi_agent_runtime_payload_complete "$app_path"; then
printf '%s\n' "incomplete_runtime_payload"
else
printf '%s\n' "reusable"
fi
}
omi_fast_bundle_write_stamp() {
local stamp="$1"
local fingerprint="$2"
local temp
mkdir -p "$(dirname "$stamp")"
temp="$(mktemp "${stamp}.tmp.XXXXXX")"
printf 'version=1\nfingerprint=%s\n' "$fingerprint" > "$temp"
mv -f "$temp" "$stamp"
}