@trillboards/edge-sdk 0.2.193 → 0.2.196
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.
- package/deploy/detector/pyproject.toml +1 -1
- package/deploy/detector/tests/test_loader.py +1 -1
- package/deploy/detector/tests/test_vehicle_end.py +215 -0
- package/deploy/detector/trillboards_detector/_version.py +2 -2
- package/deploy/detector/trillboards_detector/loader.py +6 -0
- package/deploy/detector/trillboards_detector/registry.py +30 -1
- package/deploy/detector/trillboards_detector/server.py +39 -0
- package/deploy/detector/trillboards_detector/tasks.py +8 -1
- package/deploy/detector/trillboards_detector/vehicle_end.py +154 -0
- package/deploy/macos/apply-update.sh +254 -104
- package/deploy/macos/ci/connector-stand-in.js +42 -0
- package/deploy/macos/ci/helper-stand-in.sh +23 -0
- package/deploy/macos/ci/launchd-matrix.js +39 -0
- package/deploy/macos/ci/lib.sh +339 -0
- package/deploy/macos/ci/test-field-self-update.sh +153 -0
- package/deploy/macos/ci/test-update-launchd-boundary.sh +260 -0
- package/deploy/systemd/trillboards-detector.service +10 -3
- package/dist/DetectorFields.d.ts +121 -1
- package/dist/DetectorFields.d.ts.map +1 -1
- package/dist/DetectorFields.js +123 -3
- package/dist/DetectorFields.js.map +1 -1
- package/dist/EdgeAgent.js +1 -1
- package/dist/LocalDetectorClient.d.ts +21 -0
- package/dist/LocalDetectorClient.d.ts.map +1 -1
- package/dist/LocalDetectorClient.js +44 -0
- package/dist/LocalDetectorClient.js.map +1 -1
- package/dist/PhoneHeldInHand.d.ts +38 -3
- package/dist/PhoneHeldInHand.d.ts.map +1 -1
- package/dist/PhoneHeldInHand.js +33 -6
- package/dist/PhoneHeldInHand.js.map +1 -1
- package/dist/ScopedVlmReview.d.ts +19 -4
- package/dist/ScopedVlmReview.d.ts.map +1 -1
- package/dist/ScopedVlmReview.js +88 -22
- package/dist/ScopedVlmReview.js.map +1 -1
- package/dist/SensingProfileClient.d.ts.map +1 -1
- package/dist/SensingProfileClient.js +2 -0
- package/dist/SensingProfileClient.js.map +1 -1
- package/dist/connectorUpdate.d.ts.map +1 -1
- package/dist/connectorUpdate.js +19 -0
- package/dist/connectorUpdate.js.map +1 -1
- package/dist/diagnose.d.ts +1 -1
- package/dist/diagnose.js +1 -1
- package/dist/localSensing.d.ts +4 -1
- package/dist/localSensing.d.ts.map +1 -1
- package/dist/localSensing.js +13 -9
- package/dist/localSensing.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# test-update-launchd-boundary.sh — does the connector's own hand-off start the
|
|
4
|
+
# macOS update helper from inside its LaunchAgent, does the helper verify a
|
|
5
|
+
# published package with tools a customer Mac has, and does it outlive the
|
|
6
|
+
# connector it replaces?
|
|
7
|
+
#
|
|
8
|
+
# Every arm runs the REAL code from INSIDE com.trillboards.edge in the gui
|
|
9
|
+
# domain, on a runner whose developer tools are moved aside and proven absent,
|
|
10
|
+
# against a published, signed, notarized code-only package:
|
|
11
|
+
#
|
|
12
|
+
# 1 record how launchd treats the ways a LaunchAgent can start a helper,
|
|
13
|
+
# across the job's clean exit and a bootout of the job.
|
|
14
|
+
# 2 control the hand-off and helper every connector through 0.2.193 ships
|
|
15
|
+
# (published 0.2.140): the stage must NOT complete and must leave
|
|
16
|
+
# NO outcome. That is the field defect (run 41934336173); if it
|
|
17
|
+
# does not reproduce, this rig cannot prove the fix and says so.
|
|
18
|
+
# 3 subject the compiled connectorUpdateApplyMac.ts and this checkout's
|
|
19
|
+
# apply-update.sh: the stage verifies and completes.
|
|
20
|
+
# 4 subject a refused stage (wrong hash) and a lock left by a killed helper:
|
|
21
|
+
# the refusal is recorded in outcome.json, the stale lock is cleared.
|
|
22
|
+
# 5 subject the commit: the stand-in exits 0 like requestExit(); the helper
|
|
23
|
+
# outlives it and its own bootout of com.trillboards.edge, runs
|
|
24
|
+
# Installer, rolls back (this runner has no local AI, so the
|
|
25
|
+
# package's postinstall refuses), records why, and relaunches the
|
|
26
|
+
# LaunchAgent. The successful swap is test-field-self-update.sh.
|
|
27
|
+
# 6 subject a commit the helper refuses (staged version mismatch): recorded,
|
|
28
|
+
# and com.trillboards.edge comes back on the current version.
|
|
29
|
+
#
|
|
30
|
+
# Execute only on a fresh GitHub-hosted macOS runner.
|
|
31
|
+
set -u
|
|
32
|
+
if [ "${GITHUB_ACTIONS:-}" != true ] || [ "${RUNNER_OS:-}" != macOS ] || [ "${RUNNER_ENVIRONMENT:-}" != github-hosted ]; then
|
|
33
|
+
echo 'The launchd-boundary qualification registers LaunchAgents and moves Xcode; run it only on a fresh GitHub-hosted macOS runner' >&2
|
|
34
|
+
exit 2
|
|
35
|
+
fi
|
|
36
|
+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
37
|
+
PKGROOT="$(cd "$HERE/../../.." && pwd)"
|
|
38
|
+
# shellcheck source=deploy/macos/ci/lib.sh
|
|
39
|
+
. "$HERE/lib.sh"
|
|
40
|
+
rig_init update-launchd-boundary
|
|
41
|
+
# Leave the machine as it was found: the field proof runs next in this job and
|
|
42
|
+
# must start from a Mac that has never had a connector.
|
|
43
|
+
boundary_cleanup() {
|
|
44
|
+
launchctl bootout "$EDGE_SERVICE" >/dev/null 2>&1 || true
|
|
45
|
+
pkill -f 'share/apply-update.sh' 2>/dev/null || true
|
|
46
|
+
rm -rf "$EDGE" "$UPD" "$HOME/Library/Trillboards/edge.previous" "$EDGE_PLIST"
|
|
47
|
+
rig_teardown
|
|
48
|
+
}
|
|
49
|
+
trap 'boundary_cleanup' EXIT
|
|
50
|
+
TYPESCRIPT="$PKGROOT/../../node_modules/typescript"
|
|
51
|
+
[ -d "$TYPESCRIPT" ] || { echo 'Run npm ci in trillboards-edge-sdk first: the subject arms compile connectorUpdateApplyMac.ts' >&2; exit 2; }
|
|
52
|
+
|
|
53
|
+
FAILURES=0
|
|
54
|
+
pass() { note "PASS - $*"; }
|
|
55
|
+
bad() { note "FAIL - $*"; FAILURES=$((FAILURES + 1)); }
|
|
56
|
+
record() { note "RECORD - $*"; }
|
|
57
|
+
|
|
58
|
+
# The released build every Mac in the field runs (0.2.140, 2026-09-17) and a
|
|
59
|
+
# published, notarized package to stage — both immutable, both pinned.
|
|
60
|
+
RELEASED_COMMIT='98629a19a90bad6d9af7f588d2249aee36dbe0e8'
|
|
61
|
+
RELEASED_SHA='264a9fcbd4038b253ba622339bf3ad4d9292dcc9cd1d3ca66276844d4bee04bb'
|
|
62
|
+
TARGET_VERSION='0.2.193'
|
|
63
|
+
TARGET_URL='https://screen.trillboards.com/connector/updates/c5f87bbdd536ce05699f5a7cbe6ebdd2cb6c80c4/trillboards-connector-macos-update.pkg'
|
|
64
|
+
TARGET_SHA='021f1aa63affc2e3da0051c595b33873d2d0b4fbbbe17deccb769414afeede25'
|
|
65
|
+
TARGET_SIZE='72778110'
|
|
66
|
+
|
|
67
|
+
curl -fsS --retry 3 -o "$OUT/released.pkg" "$ORIGIN/connector/updates/$RELEASED_COMMIT/trillboards-connector-macos-update.pkg"
|
|
68
|
+
[ "$(sha256_of "$OUT/released.pkg")" = "$RELEASED_SHA" ] || { bad 'the released 0.2.140 package does not match its pinned hash'; exit 1; }
|
|
69
|
+
/usr/sbin/pkgutil --expand-full "$OUT/released.pkg" "$OUT/released" >/dev/null
|
|
70
|
+
RELEASED_TREE="$(find "$OUT/released" -path '*Payload/Library/Trillboards/edge' -type d | head -1)"
|
|
71
|
+
[ -n "$RELEASED_TREE" ] || { bad 'could not expand the released package'; exit 1; }
|
|
72
|
+
|
|
73
|
+
# The subject: this checkout's applier, compiled with the repo's TypeScript.
|
|
74
|
+
mkdir -p "$OUT/subject"
|
|
75
|
+
node -e '
|
|
76
|
+
const ts = require(process.argv[1]); const fs = require("fs"); const path = require("path");
|
|
77
|
+
for (const name of ["connectorUpdateApply", "connectorUpdateApplyMac"]) {
|
|
78
|
+
const out = ts.transpileModule(fs.readFileSync(path.join(process.argv[2], name + ".ts"), "utf8"),
|
|
79
|
+
{ compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020, esModuleInterop: true } });
|
|
80
|
+
fs.writeFileSync(path.join(process.argv[3], name + ".js"), out.outputText);
|
|
81
|
+
}' "$TYPESCRIPT" "$PKGROOT/src" "$OUT/subject" || { bad 'could not compile the applier'; exit 1; }
|
|
82
|
+
|
|
83
|
+
# --- 0: what the released trust check needed (record, developer tools present)
|
|
84
|
+
curl -fsS --retry 3 -o "$OUT/target.pkg" "$ORIGIN/${TARGET_URL#https://screen.trillboards.com/}"
|
|
85
|
+
[ "$(sha256_of "$OUT/target.pkg")" = "$TARGET_SHA" ] || { bad 'the pinned target package does not match its hash'; exit 1; }
|
|
86
|
+
cp "$OUT/target.pkg" "$OUT/target.pkg.download"
|
|
87
|
+
for f in target.pkg target.pkg.download; do
|
|
88
|
+
out="$(run_bounded 60 /usr/bin/xcrun stapler validate "$OUT/$f" 2>&1)"; rc=$?
|
|
89
|
+
record "0: with Xcode, xcrun stapler validate $f -> exit $rc: $(printf '%s' "$out" | tr '\n' ' ' | cut -c1-200)"
|
|
90
|
+
done
|
|
91
|
+
rm -f "$OUT/target.pkg.download"
|
|
92
|
+
|
|
93
|
+
hide_developer_tools
|
|
94
|
+
prove_developer_tools_hidden || { bad 'developer tools are still reachable; this is not a customer Mac'; exit 1; }
|
|
95
|
+
out="$(run_bounded 60 /usr/bin/xcrun stapler validate "$OUT/target.pkg" 2>&1)"; rc=$?
|
|
96
|
+
record "0: without developer tools, xcrun stapler validate target.pkg -> exit $rc: $(printf '%s' "$out" | head -1)"
|
|
97
|
+
for tool in "/usr/sbin/pkgutil --check-signature" "/usr/sbin/spctl --assess --type install -vv"; do
|
|
98
|
+
out="$($tool "$OUT/target.pkg" 2>&1)"; rc=$?
|
|
99
|
+
record "0: without developer tools, $tool -> exit $rc: $(printf '%s' "$out" | grep -E 'Status:|Notarization:|1\. |accepted|rejected|source=|origin=' | tr '\n' '|' | cut -c1-400)"
|
|
100
|
+
done
|
|
101
|
+
|
|
102
|
+
# An install tree at the one path the helper accepts. $1 = helper script.
|
|
103
|
+
lay_down_install() {
|
|
104
|
+
launchctl bootout "$EDGE_SERVICE" >/dev/null 2>&1 || true
|
|
105
|
+
launchctl bootout "gui/$(id -u)/com.trillboards.edge.update" >/dev/null 2>&1 || true
|
|
106
|
+
rm -rf "$EDGE" "$UPD" "$HOME/Library/Trillboards/edge.previous"
|
|
107
|
+
mkdir -p "$(dirname "$EDGE")"
|
|
108
|
+
/usr/bin/ditto "$RELEASED_TREE" "$EDGE"
|
|
109
|
+
cp "$1" "$EDGE/share/apply-update.sh"
|
|
110
|
+
}
|
|
111
|
+
# com.trillboards.edge running the stand-in under the shipped node, with the
|
|
112
|
+
# LaunchAgent shape pairing installs (KeepAlive only on an unsuccessful exit).
|
|
113
|
+
start_stand_in() { # dir applier.js phase sha
|
|
114
|
+
mkdir -p "$1"
|
|
115
|
+
rm -f "$1/connector.ran"
|
|
116
|
+
cat > "$EDGE_PLIST" <<PLIST
|
|
117
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
118
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
119
|
+
<plist version="1.0"><dict>
|
|
120
|
+
<key>Label</key><string>com.trillboards.edge</string>
|
|
121
|
+
<key>ProgramArguments</key><array><string>$EDGE/bin/node</string><string>$HERE/connector-stand-in.js</string><string>$1</string><string>$2</string><string>$EDGE</string><string>$3</string><string>$TARGET_VERSION</string><string>$TARGET_URL</string><string>$4</string><string>$TARGET_SIZE</string><string>0.2.140</string></array>
|
|
122
|
+
<key>RunAtLoad</key><true/>
|
|
123
|
+
<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>
|
|
124
|
+
<key>ThrottleInterval</key><integer>10</integer>
|
|
125
|
+
<key>ProcessType</key><string>Background</string>
|
|
126
|
+
<key>StandardOutPath</key><string>$1/agent.out.log</string>
|
|
127
|
+
<key>StandardErrorPath</key><string>$1/agent.err.log</string>
|
|
128
|
+
</dict></plist>
|
|
129
|
+
PLIST
|
|
130
|
+
launchctl bootstrap "gui/$(id -u)" "$EDGE_PLIST"
|
|
131
|
+
}
|
|
132
|
+
helper_running() { ps -axo command | grep -v grep | grep -q 'share/apply-update.sh'; }
|
|
133
|
+
wait_for() { # seconds condition...
|
|
134
|
+
local deadline=$(( $(date +%s) + $1 )); shift
|
|
135
|
+
while [ "$(date +%s)" -lt "$deadline" ]; do "$@" && return 0; sleep 2; done
|
|
136
|
+
"$@"
|
|
137
|
+
}
|
|
138
|
+
has_staged() { [ -f "$UPD/staged.json" ]; }
|
|
139
|
+
has_outcome() { [ -f "$UPD/outcome.json" ]; }
|
|
140
|
+
relaunched() { grep -q RELAUNCHED "$1/connector.log" 2>/dev/null; }
|
|
141
|
+
helper_lines() { /usr/bin/log show --start "$1" --style compact --predicate 'process == "logger" AND eventMessage CONTAINS "apply-update"' 2>/dev/null | grep apply-update | sed 's/^.*apply-update: / /'; }
|
|
142
|
+
|
|
143
|
+
# --- 1: launchd lifecycle (record) -------------------------------------------
|
|
144
|
+
matrix() { # name selfBootout
|
|
145
|
+
local d="$OUT/matrix-$1" label="com.trillboards.boundary.$1" f age
|
|
146
|
+
mkdir -p "$d"
|
|
147
|
+
cat > "$HOME/Library/LaunchAgents/$label.plist" <<PLIST
|
|
148
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
149
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
150
|
+
<plist version="1.0"><dict>
|
|
151
|
+
<key>Label</key><string>$label</string>
|
|
152
|
+
<key>ProgramArguments</key><array><string>$(command -v node)</string><string>$HERE/launchd-matrix.js</string><string>$d</string><string>$HERE/helper-stand-in.sh</string><string>$(id -u)</string><string>$label</string><string>$2</string></array>
|
|
153
|
+
<key>RunAtLoad</key><true/>
|
|
154
|
+
<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>
|
|
155
|
+
<key>ProcessType</key><string>Background</string>
|
|
156
|
+
</dict></plist>
|
|
157
|
+
PLIST
|
|
158
|
+
launchctl bootstrap "gui/$(id -u)" "$HOME/Library/LaunchAgents/$label.plist"
|
|
159
|
+
sleep 32
|
|
160
|
+
[ "$2" = 1 ] || launchctl bootout "gui/$(id -u)/$label" >/dev/null 2>&1
|
|
161
|
+
sleep 6
|
|
162
|
+
for f in "$d"/*.hb; do
|
|
163
|
+
[ -f "$f" ] || continue
|
|
164
|
+
age=$(( $(date +%s) - $(stat -f %m "$f") ))
|
|
165
|
+
record "1 [$1]: helper started $(basename "$f" .hb): $( [ "$age" -le 4 ] && echo 'alive after' || echo "DEAD ${age}s before the end of" ) the job's exit at 8 s and $( [ "$2" = 1 ] && echo 'its own bootout of the job at 20 s' || echo 'a bootout of the job at 32 s' )"
|
|
166
|
+
done
|
|
167
|
+
for f in "$d"/*.log; do record "1 [$1]: $(basename "$f"): $(tr '\n' '|' < "$f" | cut -c1-300)"; done
|
|
168
|
+
launchctl bootout "gui/$(id -u)/$label" >/dev/null 2>&1 || true
|
|
169
|
+
launchctl bootout "gui/$(id -u)/$label.helper" >/dev/null 2>&1 || true
|
|
170
|
+
pkill -f "helper-stand-in.sh $d" 2>/dev/null || true
|
|
171
|
+
}
|
|
172
|
+
matrix outside 0
|
|
173
|
+
matrix self 1
|
|
174
|
+
|
|
175
|
+
# --- 2: the released hand-off and helper (control) ----------------------------
|
|
176
|
+
lay_down_install "$RELEASED_TREE/share/apply-update.sh"
|
|
177
|
+
since="$(date '+%Y-%m-%d %H:%M:%S')"
|
|
178
|
+
start_stand_in "$OUT/control" "$EDGE/lib/edge-sdk/dist/connectorUpdateApplyMac.js" stage "$TARGET_SHA"
|
|
179
|
+
wait_for 30 helper_running && record '2: the released hand-off started apply-update.sh from inside com.trillboards.edge'
|
|
180
|
+
wait_for 180 has_staged
|
|
181
|
+
sleep 5
|
|
182
|
+
record "2: helper said:"; helper_lines "$since" | while read -r l; do record " $l"; done
|
|
183
|
+
if ! has_staged && ! has_outcome && ! helper_running; then
|
|
184
|
+
pass '2 control: the released helper never staged a published notarized package on a stock Mac and left no outcome (the field defect, reproduced)'
|
|
185
|
+
else
|
|
186
|
+
bad "2 control: the released helper staged=$(has_staged && echo yes || echo no) outcome=$(has_outcome && echo yes || echo no) here, so this rig cannot reproduce the field defect"
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
# --- 3: the compiled hand-off and this checkout's helper (subject, stage) ----
|
|
190
|
+
lay_down_install "$PKGROOT/deploy/macos/apply-update.sh"
|
|
191
|
+
start_stand_in "$OUT/stage" "$OUT/subject/connectorUpdateApplyMac.js" stage "$TARGET_SHA"
|
|
192
|
+
if wait_for 300 has_staged; then
|
|
193
|
+
pass "3: staged on a stock Mac: $(cat "$UPD/staged.json")"
|
|
194
|
+
grep -q 'Notarization: trusted by the Apple notary service' "$UPD/signature.txt" && grep -q '^source=Notarized Developer ID' "$UPD/signature.txt" \
|
|
195
|
+
&& pass '3: pkgutil and spctl both report a notarized Aethercorp Developer ID package' || bad '3: signature.txt lacks the notarization verdicts'
|
|
196
|
+
else
|
|
197
|
+
bad "3: the subject did not stage within 300 s (outcome: $(cat "$UPD/outcome.json" 2>/dev/null))"
|
|
198
|
+
fi
|
|
199
|
+
record "3: helper log: $(tr '\n' '|' < "$UPD/apply-update.log" 2>/dev/null | cut -c1-600)"
|
|
200
|
+
grep -q 'start: --stage .*started from com.trillboards.edge' "$UPD/apply-update.log" 2>/dev/null \
|
|
201
|
+
&& pass '3: the connector hand-off started the helper from inside com.trillboards.edge' \
|
|
202
|
+
|| bad '3: the helper log does not show a stage started from inside com.trillboards.edge'
|
|
203
|
+
|
|
204
|
+
# --- 4: refusal and a stale lock (subject) -----------------------------------
|
|
205
|
+
lay_down_install "$PKGROOT/deploy/macos/apply-update.sh"
|
|
206
|
+
mkdir -p "$UPD/lock" # what a killed helper leaves: no live holder
|
|
207
|
+
start_stand_in "$OUT/refusal" "$OUT/subject/connectorUpdateApplyMac.js" stage "$(printf 'f%.0s' $(seq 1 64))"
|
|
208
|
+
if wait_for 300 has_outcome && grep -q '"result":"rejected"' "$UPD/outcome.json" && grep -q 'SHA-256 mismatch' "$UPD/outcome.json"; then
|
|
209
|
+
pass "4: a refused stage is recorded: $(cat "$UPD/outcome.json")"
|
|
210
|
+
else
|
|
211
|
+
bad "4: no rejected outcome for a wrong hash (outcome: $(cat "$UPD/outcome.json" 2>/dev/null))"
|
|
212
|
+
fi
|
|
213
|
+
grep -q 'clearing a stale update lock' "$UPD/apply-update.log" 2>/dev/null \
|
|
214
|
+
&& pass '4: a lock with no live holder was cleared instead of refusing every later update' \
|
|
215
|
+
|| bad '4: the stale lock was not cleared'
|
|
216
|
+
has_staged && bad '4: a refused package was staged'
|
|
217
|
+
|
|
218
|
+
# --- 5: the commit (subject) -------------------------------------------------
|
|
219
|
+
lay_down_install "$PKGROOT/deploy/macos/apply-update.sh"
|
|
220
|
+
start_stand_in "$OUT/commit" "$OUT/subject/connectorUpdateApplyMac.js" full "$TARGET_SHA"
|
|
221
|
+
wait_for 300 grep -q 'commit() -> true' "$OUT/commit/connector.log" || bad "5: the stand-in never handed over: $(tail -3 "$OUT/commit/connector.log" 2>/dev/null)"
|
|
222
|
+
if wait_for 900 relaunched "$OUT/commit"; then
|
|
223
|
+
pass '5: com.trillboards.edge was relaunched after the hand-off'
|
|
224
|
+
else
|
|
225
|
+
bad '5: com.trillboards.edge was not relaunched within 15 minutes of the hand-off'
|
|
226
|
+
fi
|
|
227
|
+
wait_for 60 has_outcome
|
|
228
|
+
record "5: helper log: $(tr '\n' '|' < "$UPD/apply-update.log" 2>/dev/null | cut -c1-1200)"
|
|
229
|
+
if has_outcome && grep -q '"result":"failed"' "$UPD/outcome.json" && grep -q 'previous version 0.2.140 restored' "$UPD/outcome.json"; then
|
|
230
|
+
pass "5: the helper outlived the connector and its bootout, rolled back and recorded why: $(cat "$UPD/outcome.json")"
|
|
231
|
+
else
|
|
232
|
+
bad "5: unexpected commit outcome: $(cat "$UPD/outcome.json" 2>/dev/null)"
|
|
233
|
+
fi
|
|
234
|
+
[ "$(installed_version)" = '0.2.140' ] && pass '5: the previous install is back in place' || bad "5: installed $(installed_version) after rollback"
|
|
235
|
+
|
|
236
|
+
# --- 6: a commit the helper refuses still brings the connector back (subject) --
|
|
237
|
+
# The connector exits 0 when it hands over, and launchd restarts only an
|
|
238
|
+
# unsuccessful exit; a refusal that does not restart it stops sensing until the
|
|
239
|
+
# next login. The released helper did exactly that on every refusal path.
|
|
240
|
+
lay_down_install "$PKGROOT/deploy/macos/apply-update.sh"
|
|
241
|
+
mkdir -p "$UPD"
|
|
242
|
+
printf '{"version":"9.9.9","currentVersion":"0.2.140","sha256":"%s","sizeBytes":%s}\n' "$TARGET_SHA" "$TARGET_SIZE" > "$UPD/staged.json"
|
|
243
|
+
cp "$OUT/target.pkg" "$UPD/connector-update.pkg"
|
|
244
|
+
start_stand_in "$OUT/refused-commit" "$OUT/subject/connectorUpdateApplyMac.js" commit-staged "$TARGET_SHA"
|
|
245
|
+
if wait_for 300 relaunched "$OUT/refused-commit"; then
|
|
246
|
+
pass '6: after a refused commit com.trillboards.edge was relaunched on the current version'
|
|
247
|
+
else
|
|
248
|
+
bad "6: com.trillboards.edge stayed down after a refused commit ($(launchctl print "$EDGE_SERVICE" 2>&1 | grep -E 'state =' | head -1))"
|
|
249
|
+
fi
|
|
250
|
+
if has_outcome && grep -q '"result":"rejected"' "$UPD/outcome.json"; then
|
|
251
|
+
pass "6: the refusal is recorded: $(cat "$UPD/outcome.json")"
|
|
252
|
+
else
|
|
253
|
+
bad "6: no rejected outcome for a mismatched staged version: $(cat "$UPD/outcome.json" 2>/dev/null)"
|
|
254
|
+
fi
|
|
255
|
+
[ "$(installed_version)" = '0.2.140' ] || bad "6: the install changed on a refused commit ($(installed_version))"
|
|
256
|
+
|
|
257
|
+
collect_evidence
|
|
258
|
+
cp -R "$OUT"/control "$OUT"/stage "$OUT"/refusal "$OUT"/commit "$OUT"/refused-commit "$OUT/evidence/" 2>/dev/null || true
|
|
259
|
+
if [ "$FAILURES" -gt 0 ]; then note "$FAILURES launchd-boundary assertion(s) failed"; exit 1; fi
|
|
260
|
+
note 'PASS: the released helper fails silently on a stock Mac; the fixed hand-off stages, refuses loudly, and outlives the connector it replaces'
|
|
@@ -30,10 +30,17 @@ SyslogIdentifier=trillboards-detector
|
|
|
30
30
|
# render nodes (`docs/runbooks/cctv-detector-tier.md` §6 — the DirectML/ROCm path
|
|
31
31
|
# was never exercised and the decision is CPU-only), and it needs no model store
|
|
32
32
|
# of its own beyond the connector's data dir.
|
|
33
|
+
#
|
|
34
|
+
# /var/lib/trillboards is WRITABLE here (it is TRILLBOARDS_DATA_DIR below): the
|
|
35
|
+
# detector keeps its actor-tracking journal at
|
|
36
|
+
# <data dir>/actor-tracking/tracks.sqlite3 (cli.py, since #15587). Read-only, its
|
|
37
|
+
# mkdir failed and the service crash-looped on every fresh Linux install. The
|
|
38
|
+
# path must EXIST before this unit is installed, or systemd refuses to start it
|
|
39
|
+
# (226/NAMESPACE): install.sh creates and chowns it before it copies this file.
|
|
33
40
|
NoNewPrivileges=true
|
|
34
41
|
ProtectSystem=strict
|
|
35
42
|
ProtectHome=false
|
|
36
|
-
ReadWritePaths=/opt/trillboards
|
|
43
|
+
ReadWritePaths=/opt/trillboards /var/lib/trillboards
|
|
37
44
|
PrivateTmp=true
|
|
38
45
|
PrivateDevices=true
|
|
39
46
|
|
|
@@ -54,8 +61,8 @@ Environment=HOME=/opt/trillboards
|
|
|
54
61
|
# not an option: the connector is the process that WRITES the artifact, and its
|
|
55
62
|
# unit is sandboxed to /var/lib/trillboards.
|
|
56
63
|
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
64
|
+
# The connector still owns every write to models/; this service only opens the
|
|
65
|
+
# .onnx there. Its one write is the actor-tracking journal (ReadWritePaths above).
|
|
59
66
|
Environment=TRILLBOARDS_DATA_DIR=/var/lib/trillboards
|
|
60
67
|
EnvironmentFile=-/etc/trillboards/env
|
|
61
68
|
|
package/dist/DetectorFields.d.ts
CHANGED
|
@@ -23,6 +23,13 @@ import { type NormalizedPoint } from './zoneContainment';
|
|
|
23
23
|
* only when a vehicle has newly stopped (or one left while the answer was
|
|
24
24
|
* yes) and reused otherwise: 109 questions in 12 store hours of parking-lot
|
|
25
25
|
* video instead of one on every reviewed frame.
|
|
26
|
+
* vehicle_orientation_gate_v1 the same gate, but the box decides: each
|
|
27
|
+
* newly stopped vehicle is looked at by the detector service's pinned
|
|
28
|
+
* vehicle-end task (SigLIP 2 ViT-L/16 zero-shot, back-vs-front on the
|
|
29
|
+
* vehicle's BUILDING END, which the server names per camera), 10 s apart,
|
|
30
|
+
* and is reversed when 2 of 3 looks score >= 0.012 (two that agree decide).
|
|
31
|
+
* Section 5c: 16 of 16 reverse-parked arrivals over 4 store days (48 h, 378
|
|
32
|
+
* forward arrivals), 0 forward flagged, on the retained 640x480 frames.
|
|
26
33
|
*/
|
|
27
34
|
declare const RF_SHA = "8e8197112112b79d7cc5d0a94ecef659c05317a658aadc7c7643374c539d7615";
|
|
28
35
|
type Box = {
|
|
@@ -61,7 +68,36 @@ export interface VehicleArrivalGateMethod {
|
|
|
61
68
|
minStationaryMs: 10000;
|
|
62
69
|
maxGapMs: 120000;
|
|
63
70
|
}
|
|
64
|
-
|
|
71
|
+
/** The detector service's `vehicle_end.PREPROCESSING`: the client refuses an answer made any other way. */
|
|
72
|
+
export declare const VEHICLE_END_PREPROCESSING = "siglip2_rgb_bicubic256_unit_mean0.5_std0.5_building_end_crop_v1";
|
|
73
|
+
declare const VEHICLE_END: {
|
|
74
|
+
readonly modelId: "siglip2_l16_vehicle_end_v1";
|
|
75
|
+
readonly format: "onnx";
|
|
76
|
+
readonly sha256: "682c4b3255f94bc82dda6f47ae10d73082f40fa33c3535b7b7f7e87d3cab20a8";
|
|
77
|
+
};
|
|
78
|
+
export type BuildingSide = 'left' | 'right' | 'top' | 'bottom';
|
|
79
|
+
export declare const BUILDING_SIDES: readonly BuildingSide[];
|
|
80
|
+
export interface VehicleOrientationGateMethod {
|
|
81
|
+
field: string;
|
|
82
|
+
method: 'vehicle_orientation_gate_v1';
|
|
83
|
+
vehicleLabels: ['bus', 'car', 'motorcycle', 'truck'];
|
|
84
|
+
minConfidence: 0.5;
|
|
85
|
+
minArea: 0.04;
|
|
86
|
+
sameVehicleIou: 0.6;
|
|
87
|
+
stationaryIou: 0.8;
|
|
88
|
+
minStationaryMs: 10000;
|
|
89
|
+
maxGapMs: 120000;
|
|
90
|
+
/** The camera's geometry (`buildingSide`) is the one value set per camera; the rest is the measurement. */
|
|
91
|
+
orientation: {
|
|
92
|
+
model: typeof VEHICLE_END;
|
|
93
|
+
buildingSide: BuildingSide;
|
|
94
|
+
threshold: 0.012;
|
|
95
|
+
lookIntervalMs: 10000;
|
|
96
|
+
majorityOf: 3;
|
|
97
|
+
inheritIou: 0.3;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export type DetectorFieldMethod = UnattendedCustomerMethod | DetectedLabelsMethod | VehicleArrivalGateMethod | VehicleOrientationGateMethod;
|
|
65
101
|
export interface DetectorFieldsPolicy {
|
|
66
102
|
version: 1;
|
|
67
103
|
detector: {
|
|
@@ -71,6 +107,13 @@ export interface DetectorFieldsPolicy {
|
|
|
71
107
|
};
|
|
72
108
|
fields: DetectorFieldMethod[];
|
|
73
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Every method this build implements, sent with each profile request
|
|
112
|
+
* (SensingProfileClient: `X-Detector-Field-Methods`). The parser refuses any other
|
|
113
|
+
* method, so the server sends a method added after a connector shipped only to a
|
|
114
|
+
* connector that names it; 0.2.193 and 0.2.194 send no list and keep the methods they had.
|
|
115
|
+
*/
|
|
116
|
+
export declare const DETECTOR_FIELD_METHODS: readonly string[];
|
|
74
117
|
/** Only the exact pinned methods; anything else is refused, never adapted. */
|
|
75
118
|
export declare function parseDetectorFields(value: unknown): DetectorFieldsPolicy | undefined;
|
|
76
119
|
/** One detector call serves every detector-answered question of the frame. */
|
|
@@ -209,5 +252,82 @@ export declare function planVehicleGate(input: {
|
|
|
209
252
|
capturedAtMs: number;
|
|
210
253
|
memory?: VehicleGateMemory;
|
|
211
254
|
}): VehicleGatePlan;
|
|
255
|
+
/** Per camera, in memory only; losing it costs extra looks, never a wrong answer. */
|
|
256
|
+
export interface VehicleOrientationMemory {
|
|
257
|
+
version: 2;
|
|
258
|
+
lastAtMs: number;
|
|
259
|
+
tracks: Array<{
|
|
260
|
+
box: Box;
|
|
261
|
+
firstSeenAtMs: number;
|
|
262
|
+
}>;
|
|
263
|
+
/** Reversed once 2 of its looks agree (a third settles a split); null until then. */
|
|
264
|
+
parked: Array<{
|
|
265
|
+
box: Box;
|
|
266
|
+
lastSeenAtMs: number;
|
|
267
|
+
looks: Array<{
|
|
268
|
+
atMs: number;
|
|
269
|
+
score: number;
|
|
270
|
+
}>;
|
|
271
|
+
reversed: boolean | null;
|
|
272
|
+
}>;
|
|
273
|
+
}
|
|
274
|
+
export interface VehicleOrientationTrace {
|
|
275
|
+
method: 'vehicle_orientation_gate_v1';
|
|
276
|
+
imageSha256: string;
|
|
277
|
+
policySha256: string;
|
|
278
|
+
buildingSide: BuildingSide;
|
|
279
|
+
action: 'no_vehicle' | 'no_parked_vehicle' | 'look' | 'reuse';
|
|
280
|
+
vehicles: number;
|
|
281
|
+
stationary: number;
|
|
282
|
+
parked: number;
|
|
283
|
+
arrivals: number;
|
|
284
|
+
departures: number;
|
|
285
|
+
inherited: number;
|
|
286
|
+
looks: Array<{
|
|
287
|
+
box: Box;
|
|
288
|
+
look: 1 | 2 | 3;
|
|
289
|
+
}>;
|
|
290
|
+
decided: Array<{
|
|
291
|
+
box: Box;
|
|
292
|
+
scores: number[];
|
|
293
|
+
reversed: boolean;
|
|
294
|
+
}>;
|
|
295
|
+
reversedParked: number;
|
|
296
|
+
}
|
|
297
|
+
export interface VehicleOrientationPlan {
|
|
298
|
+
/** Boxes the vehicle-end task must score on THIS frame (first looks, then due later looks). */
|
|
299
|
+
looks: Box[];
|
|
300
|
+
/** The answer, the next memory and the full trace, given the task's score for each look. */
|
|
301
|
+
commit: (scores: number[]) => {
|
|
302
|
+
value: boolean;
|
|
303
|
+
memory: VehicleOrientationMemory;
|
|
304
|
+
trace: VehicleOrientationTrace;
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* The parked-vehicle gate decided by the box: every vehicle that has newly
|
|
309
|
+
* stopped is looked at by the pinned vehicle-end task on arrival and again at
|
|
310
|
+
* least lookIntervalMs later while it is still there. Two looks that agree
|
|
311
|
+
* decide it; a split takes a third, and the majority stands (a single look is
|
|
312
|
+
* not enough either way: section 5c).
|
|
313
|
+
* A backed-in vehicle stays parked while unseen for up to 3 x minStationaryMs,
|
|
314
|
+
* so a box that changed under it (a door, a person, a pole) inherits its answer
|
|
315
|
+
* instead of letting the answer drop and the alert fire again; only a reversed
|
|
316
|
+
* answer is inherited, so a car parking where another left is looked at afresh.
|
|
317
|
+
* The answer is whether any parked vehicle is reversed; an undecided one does
|
|
318
|
+
* not count yet.
|
|
319
|
+
*/
|
|
320
|
+
export declare function planVehicleOrientation(input: {
|
|
321
|
+
jpeg: Buffer;
|
|
322
|
+
policy: DetectorFieldsPolicy;
|
|
323
|
+
method: VehicleOrientationGateMethod;
|
|
324
|
+
frame: {
|
|
325
|
+
width: number;
|
|
326
|
+
height: number;
|
|
327
|
+
};
|
|
328
|
+
detections: ReadonlyArray<Detection>;
|
|
329
|
+
capturedAtMs: number;
|
|
330
|
+
memory?: VehicleOrientationMemory | VehicleGateMemory;
|
|
331
|
+
}): VehicleOrientationPlan;
|
|
212
332
|
export {};
|
|
213
333
|
//# sourceMappingURL=DetectorFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DetectorFields.d.ts","sourceRoot":"","sources":["../src/DetectorFields.ts"],"names":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A,MAAM,EAAC,MAAM,EAAE,CAAC;QAAA,QAAQ,EAAC,OAAO,CAAA;KAAC,CAAC,CAAC;IAC1D,cAAc,EAAC,MAAM,CAAC;CACvB;AACD,MAAM,WAAW,sBAAsB;IACrC,+FAA+F;IAC/F,KAAK,EAAC,GAAG,EAAE,CAAC;IACZ,4FAA4F;IAC5F,MAAM,EAAC,CAAC,MAAM,EAAC,MAAM,EAAE,KAAG;QAAC,KAAK,EAAC,OAAO,CAAC;QAAA,MAAM,EAAC,wBAAwB,CAAC;QAAA,KAAK,EAAC,uBAAuB,CAAA;KAAC,CAAC;CACzG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAC;IAAC,IAAI,EAAC,MAAM,CAAC;IAAA,MAAM,EAAC,oBAAoB,CAAC;IAAA,MAAM,EAAC,4BAA4B,CAAC;IACxH,KAAK,EAAC;QAAC,KAAK,EAAC,MAAM,CAAC;QAAA,MAAM,EAAC,MAAM,CAAA;KAAC,CAAC;IAAA,UAAU,EAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAAA,YAAY,EAAC,MAAM,CAAC;IAC3F,MAAM,CAAC,EAAC,wBAAwB,GAAC,iBAAiB,CAAA;CAAC,GAAE,sBAAsB,CA0D5E"}
|
package/dist/DetectorFields.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.policySha256 = void 0;
|
|
3
|
+
exports.policySha256 = exports.DETECTOR_FIELD_METHODS = exports.BUILDING_SIDES = exports.VEHICLE_END_PREPROCESSING = void 0;
|
|
4
4
|
exports.parseDetectorFields = parseDetectorFields;
|
|
5
5
|
exports.detectorFieldsRequest = detectorFieldsRequest;
|
|
6
6
|
exports.decideUnattendedCustomer = decideUnattendedCustomer;
|
|
7
7
|
exports.decideDetectedLabels = decideDetectedLabels;
|
|
8
8
|
exports.planVehicleGate = planVehicleGate;
|
|
9
|
+
exports.planVehicleOrientation = planVehicleOrientation;
|
|
9
10
|
const crypto_1 = require("crypto");
|
|
10
11
|
const zoneContainment_1 = require("./zoneContainment");
|
|
11
12
|
/**
|
|
@@ -30,8 +31,20 @@ const zoneContainment_1 = require("./zoneContainment");
|
|
|
30
31
|
* only when a vehicle has newly stopped (or one left while the answer was
|
|
31
32
|
* yes) and reused otherwise: 109 questions in 12 store hours of parking-lot
|
|
32
33
|
* video instead of one on every reviewed frame.
|
|
34
|
+
* vehicle_orientation_gate_v1 the same gate, but the box decides: each
|
|
35
|
+
* newly stopped vehicle is looked at by the detector service's pinned
|
|
36
|
+
* vehicle-end task (SigLIP 2 ViT-L/16 zero-shot, back-vs-front on the
|
|
37
|
+
* vehicle's BUILDING END, which the server names per camera), 10 s apart,
|
|
38
|
+
* and is reversed when 2 of 3 looks score >= 0.012 (two that agree decide).
|
|
39
|
+
* Section 5c: 16 of 16 reverse-parked arrivals over 4 store days (48 h, 378
|
|
40
|
+
* forward arrivals), 0 forward flagged, on the retained 640x480 frames.
|
|
33
41
|
*/
|
|
34
42
|
const RF_SHA = '8e8197112112b79d7cc5d0a94ecef659c05317a658aadc7c7643374c539d7615';
|
|
43
|
+
/** The detector service's `vehicle_end.PREPROCESSING`: the client refuses an answer made any other way. */
|
|
44
|
+
exports.VEHICLE_END_PREPROCESSING = 'siglip2_rgb_bicubic256_unit_mean0.5_std0.5_building_end_crop_v1';
|
|
45
|
+
const VEHICLE_END = { modelId: 'siglip2_l16_vehicle_end_v1', format: 'onnx',
|
|
46
|
+
sha256: '682c4b3255f94bc82dda6f47ae10d73082f40fa33c3535b7b7f7e87d3cab20a8' };
|
|
47
|
+
exports.BUILDING_SIDES = Object.freeze(['left', 'right', 'top', 'bottom']);
|
|
35
48
|
const keys = (v, want) => !!v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).sort().join(',') === want;
|
|
36
49
|
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
37
50
|
const hash = (v) => (0, crypto_1.createHash)('sha256').update(v).digest('hex');
|
|
@@ -42,6 +55,25 @@ const PINNED = {
|
|
|
42
55
|
detected_labels_v1: { minConfidence: 0.5 },
|
|
43
56
|
vehicle_arrival_gate_v1: { vehicleLabels: ['bus', 'car', 'motorcycle', 'truck'], minConfidence: 0.5, minArea: 0.04,
|
|
44
57
|
sameVehicleIou: 0.6, stationaryIou: 0.8, minStationaryMs: 10000, maxGapMs: 120000 },
|
|
58
|
+
vehicle_orientation_gate_v1: { vehicleLabels: ['bus', 'car', 'motorcycle', 'truck'], minConfidence: 0.5, minArea: 0.04,
|
|
59
|
+
sameVehicleIou: 0.6, stationaryIou: 0.8, minStationaryMs: 10000, maxGapMs: 120000,
|
|
60
|
+
orientation: { model: VEHICLE_END, buildingSide: '*', threshold: 0.012, lookIntervalMs: 10000, majorityOf: 3, inheritIou: 0.3 } },
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Every method this build implements, sent with each profile request
|
|
64
|
+
* (SensingProfileClient: `X-Detector-Field-Methods`). The parser refuses any other
|
|
65
|
+
* method, so the server sends a method added after a connector shipped only to a
|
|
66
|
+
* connector that names it; 0.2.193 and 0.2.194 send no list and keep the methods they had.
|
|
67
|
+
*/
|
|
68
|
+
exports.DETECTOR_FIELD_METHODS = Object.freeze(Object.keys(PINNED));
|
|
69
|
+
/** The per-camera value inside an otherwise pinned method: validated, never compared. */
|
|
70
|
+
const perCamera = (method, rest) => {
|
|
71
|
+
if (method !== 'vehicle_orientation_gate_v1')
|
|
72
|
+
return rest;
|
|
73
|
+
const o = rest.orientation;
|
|
74
|
+
if (!o || typeof o !== 'object' || !exports.BUILDING_SIDES.includes(o.buildingSide))
|
|
75
|
+
return { ...rest, orientation: null };
|
|
76
|
+
return { ...rest, orientation: { ...o, buildingSide: '*' } };
|
|
45
77
|
};
|
|
46
78
|
/** Only the exact pinned methods; anything else is refused, never adapted. */
|
|
47
79
|
function parseDetectorFields(value) {
|
|
@@ -58,7 +90,8 @@ function parseDetectorFields(value) {
|
|
|
58
90
|
const pinned = PINNED[f?.method];
|
|
59
91
|
if (!pinned || typeof f.field !== 'string' || !FIELD.test(f.field) || seen.has(f.field))
|
|
60
92
|
fail();
|
|
61
|
-
const { field: _field, method: _method, ...
|
|
93
|
+
const { field: _field, method: _method, ...raw } = f;
|
|
94
|
+
const rest = perCamera(f.method, raw);
|
|
62
95
|
if (!same(Object.keys(rest).sort(), Object.keys(pinned).sort())
|
|
63
96
|
|| Object.keys(pinned).some(k => !same(rest[k], pinned[k])))
|
|
64
97
|
fail();
|
|
@@ -72,7 +105,8 @@ function detectorFieldsRequest(policy) {
|
|
|
72
105
|
// The raw object list is every class; otherwise only the classes a rule reads.
|
|
73
106
|
const all = p.fields.some(f => f.method === 'detected_labels_v1');
|
|
74
107
|
const classes = all ? [] : [...new Set(p.fields.flatMap(f => f.method === 'unattended_customer_v1'
|
|
75
|
-
? ['person', ...f.screenLabels] : f.method === 'vehicle_arrival_gate_v1'
|
|
108
|
+
? ['person', ...f.screenLabels] : f.method === 'vehicle_arrival_gate_v1' || f.method === 'vehicle_orientation_gate_v1'
|
|
109
|
+
? f.vehicleLabels : []))].sort();
|
|
76
110
|
const unattended = p.fields.find((f) => f.method === 'unattended_customer_v1');
|
|
77
111
|
return { classes, minConfidence: Math.min(...p.fields.map(f => f.method === 'unattended_customer_v1'
|
|
78
112
|
? f.minPersonConfidence : f.minConfidence)), expectedModel: { modelId: p.detector.modelId, sha256: p.detector.sha256 },
|
|
@@ -202,4 +236,90 @@ function planVehicleGate(input) {
|
|
|
202
236
|
const answer = prior.answer;
|
|
203
237
|
return { ask: false, value: answer, trace: trace('reuse', prior.answerFrom), commit: () => memory(kept, answer, prior.answerFrom) };
|
|
204
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* The parked-vehicle gate decided by the box: every vehicle that has newly
|
|
241
|
+
* stopped is looked at by the pinned vehicle-end task on arrival and again at
|
|
242
|
+
* least lookIntervalMs later while it is still there. Two looks that agree
|
|
243
|
+
* decide it; a split takes a third, and the majority stands (a single look is
|
|
244
|
+
* not enough either way: section 5c).
|
|
245
|
+
* A backed-in vehicle stays parked while unseen for up to 3 x minStationaryMs,
|
|
246
|
+
* so a box that changed under it (a door, a person, a pole) inherits its answer
|
|
247
|
+
* instead of letting the answer drop and the alert fire again; only a reversed
|
|
248
|
+
* answer is inherited, so a car parking where another left is looked at afresh.
|
|
249
|
+
* The answer is whether any parked vehicle is reversed; an undecided one does
|
|
250
|
+
* not count yet.
|
|
251
|
+
*/
|
|
252
|
+
function planVehicleOrientation(input) {
|
|
253
|
+
const m = input.method, o = m.orientation, { width, height } = input.frame, t = input.capturedAtMs;
|
|
254
|
+
if (!(width > 1 && height > 1) || !Number.isSafeInteger(t))
|
|
255
|
+
throw Error('Vehicle gate needs a frame and its capture time');
|
|
256
|
+
const imageSha256 = hash(input.jpeg), pSha = (0, exports.policySha256)(input.policy);
|
|
257
|
+
const candidates = input.detections.filter(d => m.vehicleLabels.includes(d.label)
|
|
258
|
+
&& d.confidence >= m.minConfidence && area(d.box) >= m.minArea * width * height)
|
|
259
|
+
.sort((a, b) => b.confidence - a.confidence);
|
|
260
|
+
const vehicles = [];
|
|
261
|
+
for (const d of candidates)
|
|
262
|
+
if (vehicles.every(v => iou(v, d.box) < m.sameVehicleIou))
|
|
263
|
+
vehicles.push({ ...d.box });
|
|
264
|
+
const memory = input.memory && input.memory.version === 2 ? input.memory : undefined;
|
|
265
|
+
const prior = memory && t > memory.lastAtMs && t - memory.lastAtMs <= m.maxGapMs ? memory : undefined;
|
|
266
|
+
const tracks = vehicles.map(box => {
|
|
267
|
+
const was = prior?.tracks.find(tr => iou(tr.box, box) >= m.stationaryIou);
|
|
268
|
+
return { box, firstSeenAtMs: was ? was.firstSeenAtMs : t };
|
|
269
|
+
});
|
|
270
|
+
const stationary = tracks.filter(tr => t - tr.firstSeenAtMs >= m.minStationaryMs).map(tr => tr.box);
|
|
271
|
+
const parked = [];
|
|
272
|
+
let departures = 0;
|
|
273
|
+
for (const p of prior?.parked ?? []) {
|
|
274
|
+
const now = vehicles.find(v => iou(v, p.box) >= m.sameVehicleIou);
|
|
275
|
+
if (now)
|
|
276
|
+
parked.push({ ...p, box: now, lastSeenAtMs: t, seen: true });
|
|
277
|
+
else if (t - p.lastSeenAtMs < (p.reversed === true ? 3 * m.minStationaryMs : m.minStationaryMs))
|
|
278
|
+
parked.push({ ...p, seen: false });
|
|
279
|
+
else
|
|
280
|
+
departures++;
|
|
281
|
+
}
|
|
282
|
+
let arrivals = 0, inherited = 0;
|
|
283
|
+
for (const s of stationary) {
|
|
284
|
+
if (parked.some(p => p.seen && iou(p.box, s) >= m.sameVehicleIou))
|
|
285
|
+
continue;
|
|
286
|
+
arrivals++;
|
|
287
|
+
const same = parked.find(p => !p.seen && p.reversed === true && iou(p.box, s) >= o.inheritIou);
|
|
288
|
+
if (same) {
|
|
289
|
+
same.box = { ...s };
|
|
290
|
+
same.lastSeenAtMs = t;
|
|
291
|
+
same.seen = true;
|
|
292
|
+
inherited++;
|
|
293
|
+
}
|
|
294
|
+
else
|
|
295
|
+
parked.push({ box: { ...s }, lastSeenAtMs: t, looks: [], reversed: null, seen: true });
|
|
296
|
+
}
|
|
297
|
+
const due = parked.filter(p => p.seen && p.reversed === null && (p.looks.length === 0
|
|
298
|
+
|| p.looks.length < o.majorityOf && t - p.looks[p.looks.length - 1].atMs >= o.lookIntervalMs)).slice(0, 8);
|
|
299
|
+
const base = (action) => ({
|
|
300
|
+
method: 'vehicle_orientation_gate_v1', imageSha256, policySha256: pSha, buildingSide: o.buildingSide, action,
|
|
301
|
+
vehicles: vehicles.length, stationary: stationary.length, parked: parked.length, arrivals, departures, inherited,
|
|
302
|
+
looks: due.map(p => ({ box: { ...p.box }, look: (p.looks.length + 1) }))
|
|
303
|
+
});
|
|
304
|
+
const action = !vehicles.length && !parked.length ? 'no_vehicle'
|
|
305
|
+
: !parked.length ? 'no_parked_vehicle' : due.length ? 'look' : 'reuse';
|
|
306
|
+
return { looks: due.map(p => ({ ...p.box })), commit: (scores) => {
|
|
307
|
+
if (!Array.isArray(scores) || scores.length !== due.length
|
|
308
|
+
|| scores.some(v => typeof v !== 'number' || !Number.isFinite(v) || Math.abs(v) > 2))
|
|
309
|
+
throw Error('Vehicle orientation needs one score per look');
|
|
310
|
+
const decided = [];
|
|
311
|
+
due.forEach((p, i) => {
|
|
312
|
+
p.looks = [...p.looks, { atMs: t, score: scores[i] }];
|
|
313
|
+
const yes = p.looks.filter(l => l.score >= o.threshold).length, no = p.looks.length - yes, need = Math.floor(o.majorityOf / 2) + 1;
|
|
314
|
+
if (yes >= need || no >= need) {
|
|
315
|
+
p.reversed = yes >= need;
|
|
316
|
+
decided.push({ box: { ...p.box }, scores: p.looks.map(l => l.score), reversed: p.reversed });
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
const kept = parked.map(({ seen: _seen, ...p }) => p);
|
|
320
|
+
const reversedParked = kept.filter(p => p.reversed === true).length;
|
|
321
|
+
return { value: reversedParked > 0, memory: { version: 2, lastAtMs: t, tracks, parked: kept },
|
|
322
|
+
trace: { ...base(action), decided, reversedParked } };
|
|
323
|
+
} };
|
|
324
|
+
}
|
|
205
325
|
//# sourceMappingURL=DetectorFields.js.map
|