Commit graph

80 commits

Author SHA1 Message Date
유창욱
34dcf557e9 Merge feat/p1f-online-setup: one-command online Pi install + resilient camera startup
setup_online.sh sets up an internet-connected Pi in a single command; the daemon now
skips a camera that fails to construct so an unseated CSI camera never crash-loops the
service. Adversarial review clean after the fix.
2026-07-13 23:47:20 +09:00
유창욱
e8b75d5366 feat(deploy): one-command online installer for an internet-connected Pi
deploy/setup_online.sh installs system packages (picamera2, hailo-all best-effort),
builds the venv + pip deps, fetches the MoveNet model, writes /etc/move-detect/edge.env
(prompting or from env vars), installs the systemd unit and starts the service — one
command, no offline bundle. Starts on CPU MoveNet; drop in a HEF for Hailo. numpy left
to the system to avoid shadowing picamera2's build. Air-gapped path (deploy/bundle/*)
unchanged.
2026-07-13 23:47:20 +09:00
유창욱
c385be017c fix(edge): resilient multi-camera startup — skip a camera that fails to construct
build_runtimes() builds each camera's source+runtime in a try/except: a camera that
raises at construction (e.g. an unseated/absent CSI camera whose Picamera2(...) throws)
is logged and skipped so the working cameras still run, instead of an unguarded
exception crash-looping the whole daemon (Restart=always). Raises only if no camera
comes up. Closes the eager-construction gap the review flagged.
2026-07-13 23:47:20 +09:00
유창욱
db376a756c Merge feat/p1e-multicam: run multiple cameras in one edge daemon
CSI + USB (or any mix) at once: one PipelineRuntime per camera with its own
camera_id, sharing the pose adapter (Hailo round-robin), offline queue, and cloud
sync; zones routed per camera. run_loop generalized to N cameras with per-camera
error isolation; single-camera path unchanged. Adversarial review clean.
2026-07-12 23:01:40 +09:00
유창욱
5072f7be0f docs(deploy): document CAMERAS multi-camera env 2026-07-12 23:01:40 +09:00
유창욱
1a40649d2f feat(edge): multi-camera daemon — run_loop steps N cameras with per-camera zone routing
run_loop now accepts a single runtime or a list; it steps every camera each tick
(one shared clock read), isolates a per-camera step exception, runs the periodic
sync/heartbeat/flush once, and routes zones per camera via a zones_for(cfg, rt)
callback. parse_cameras() reads CAMERAS='backend:device:camera_id,...' (single-camera
fallback when unset) and refuses to yield zero cameras. zones_from_config() gains a
camera_id filter; PipelineRuntime exposes camera_id. Single-camera behavior unchanged.
2026-07-12 23:01:40 +09:00
유창욱
d9d149d4a1 Merge feat/p1d-hailo-csi: CSI camera + Hailo hardware path
Implement the Pi5 + Hailo-8 HAT + CSI camera premise: real PiCameraSource
(picamera2), CAMERA_BACKEND=csi|uvc switch, and an offline install that exposes the
Pi system packages (HailoRT, picamera2) to the venv via --system-site-packages, with
Hailo/CSI prerequisites documented. Adversarial review clean.
2026-07-12 22:36:39 +09:00
유창욱
c488b74af4 feat(deploy): enable Hailo/CSI system packages for the offline install
Create the venv with --system-site-packages so it can import the Pi system packages
that are not pip wheels (hailo_platform via hailo-all, picamera2 via python3-picamera2).
Add CAMERA_BACKEND/CSI_DEVICE to the env template and document the Hailo-8 + CSI
prerequisites and air-gap handling in deploy/README.
2026-07-12 22:36:05 +09:00
유창욱
88ec0ba1d4 feat(edge): CSI camera source (picamera2) + CAMERA_BACKEND switch
Replace the PiCameraSource NotImplementedError stub with a working picamera2 CSI
source (SourcePort read()->(ok,frame), RGB888->BGR to match the pose adapters;
picamera2 lazy-imported as a system package, injected fake in tests). daemon.main()
gains CAMERA_BACKEND (csi|uvc) selecting PiCameraSource or UvcSource.
2026-07-12 22:36:05 +09:00
유창욱
2335faa568 Merge feat/p1c-deploy-hailo: air-gapped edge deploy + real Hailo pose adapter
(a) Offline-installable bundle (wheelhouse + model + source) + systemd unit for
the air-gapped Pi 5 edge daemon (--no-index install, zero network fetches).
(b) Real HailoRT yolov8s_pose adapter (host DFL box + keypoint decode + NMS,
COCO-17), replacing the stub, selectable via POSE_BACKEND; device-validated on
bringup. Adversarial review clean on the decode/API; three confirmed deploy-config
defects (systemd inline-comment crash, non-idempotent install, unpinned wheel ABI)
fixed.
2026-07-12 18:36:09 +09:00
유창욱
fd279a378d chore: enforce LF for shell/systemd deploy scripts via .gitattributes 2026-07-12 17:52:39 +09:00
유창욱
2ffa74b639 feat(deploy): air-gapped offline bundle + systemd unit for edge daemon
Offline-installable bundle (wheelhouse + model + source) built on a machine with
internet and installed on the air-gapped Pi with --no-index (zero fetches), plus a
systemd unit (auto-restart, device access, hardening) and env template. Runs the
package from source via python -m edge (no offline build backend). Drift-guard test
keeps the env template in sync with what the daemon reads and rejects inline comments
that systemd EnvironmentFile= would fold into values.
2026-07-12 17:51:45 +09:00
유창욱
6c8fd9318f feat(edge): real HailoRT yolov8s_pose adapter (host DFL+NMS decode) + POSE_BACKEND switch
Replace the NotImplementedError stub with a working HailoPoseAdapter for Pi5 +
Hailo-8. yolov8s_pose has no on-chip NMS, so the adapter does host-side DFL box
decode + keypoint decode + greedy NMS + letterbox un-map + COCO-17 assembly
(numpy decode ported from Hailo's MIT PoseEstPostProcessing, locked by a synthetic
9-tensor unit test; the HailoRT device wiring is gated + device-validated on bringup).
daemon.main() gains a POSE_BACKEND switch (hailo|movenet).
2026-07-12 17:51:45 +09:00
유창욱
d270baa450 Merge feat/p1-pilot-integration: P1 pilot end-to-end wiring (T1-T8)
Wire the already-merged P1-A (edge detection) and P1-B (cloud) together into a
laptop-webcam end-to-end pilot: real frames -> CPU MoveNet pose -> detection ->
HMAC-signed POST -> cloud -> admin sees snapshot, hears alert, acknowledges.
Adds the edge daemon loop, CloudClient config-poll/heartbeat, zone reverse-loop,
MoveNet ONNX adapter, cloud incident detail view, and desk Web Audio alerting.
2026-07-12 11:59:22 +09:00
유창욱
a946d0bee1 docs: pilot runbook + gated MoveNet smoke test 2026-07-12 11:49:07 +09:00
유창욱
b0d1241da1 feat(cloud): dashboard rows link to detail + desk Web Audio on critical 2026-07-12 11:49:07 +09:00
유창욱
55d99602ce feat(cloud): incident detail view renders snapshot images 2026-07-12 11:48:55 +09:00
유창욱
d67513fc0e feat(edge): MoveNet ONNX CPU pose adapter (COCO-17 remap) 2026-07-12 11:13:28 +09:00
유창욱
581f337021 fix(edge): daemon periodic ops (sync/heartbeat/flush) can't crash the loop
Wrap sync_config, send_heartbeat, and queue.flush operations in separate
try/except to ensure daemon survives periodic operation exceptions. Critical
for unattended 24/7 pilot devices where a locked database or disk error would
otherwise kill the entire loop. Per-frame step() handling unchanged.
2026-07-12 11:07:27 +09:00
유창욱
6f54706476 feat(edge): runnable daemon loop (step + periodic sync/heartbeat/flush) 2026-07-12 11:00:08 +09:00
유창욱
92eb97c078 feat(edge): PipelineRuntime assembles components + hot-swaps zones 2026-07-12 10:54:16 +09:00
유창욱
2eb8d81e81 fix(edge): zones_from_config skips malformed rows without raising (IndexError/non-list guard) 2026-07-12 10:49:46 +09:00
유창욱
3cf702e440 feat(edge): parse cloud config zones/thresholds into Zone objects 2026-07-12 10:45:11 +09:00
유창욱
316d80e696 feat(edge): CloudClient for config poll + heartbeat (HMAC-signed) 2026-07-12 10:38:54 +09:00
유창욱
e1f9f91110 docs: P1 pilot integration plan (wire edge daemon + CPU pose + detail view)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ne4rU4FToTLHcBUMUvUnT1
2026-07-12 10:35:21 +09:00
유창욱
171ef3e1c5 fix(cloud): add nonce-replay + timestamp-window checks to config/heartbeat (M2)
ConfigController::get and HeartbeatController::post verified HMAC but never
checked nonce replay or timestamp freshness, so a captured signed request
(e.g. a replayed heartbeat) could be replayed forever, masking a dead
device. Inject NonceRepository (+Config) into both and add the same
timestamp-window + nonce-remember checks IngestController already applies,
after HMAC verification and before the response/side effect.
2026-07-12 09:19:32 +09:00
유창욱
3405c1e2cc fix(cloud): enforce CSRF on authenticated state-changing POSTs (M1)
Only SameSite=Lax protected the acknowledge and zone save/delete endpoints,
even though a Csrf helper and mintable token already existed. Add
GET /api/csrf (CsrfController::token) to mint/return a per-session token,
check it (auth -> rbac -> csrf -> mutate) in EventDetailController::acknowledge
and ZoneConfigController::save/delete, and wire app.js/zone-draw.js to fetch
the token on load and send it as X-Csrf-Token on every POST.
2026-07-12 09:16:38 +09:00
유창욱
238b932c86 fix(cloud): add per-IP rate limit to /login before Argon2id verify (H2)
Every login attempt, including unknown users (via DUMMY_HASH), forces a full
Argon2id verify with no rate limit, letting a flood take down the login
endpoint / shared host via hashing-cost amplification. Add a pre-auth
per-IP limiter (RateLimiterRepository, default 20/min) as the first check
in AuthController::login, before any user lookup or password hashing.
2026-07-12 09:11:47 +09:00
유창욱
7828f9c419 fix(cloud): move ingest per-device rate limit post-auth, add pre-auth IP limit (H1)
An unauthenticated attacker could guess a real device_id and 429-lock that
camera by hammering /api/events before HMAC verification ran, dropping its
accident events. Add a cheap pre-auth per-IP limiter (Config::ingestIpRateLimitPerMin,
default 300/min) that fires before any device-secret lookup, and move the
existing per-device limiter to run only after HMAC + timestamp + nonce checks
succeed, so only authenticated requests consume a device's own quota.
2026-07-12 09:09:31 +09:00
유창욱
c1fb22ee16 fix(cloud): deterministic event ordering + zone concurrent-delete detection
Self-review (Task 16) follow-up fixes:
- PdoEventRepository::recent(): add event_id DESC as a secondary sort key
  after occurred_at DESC so ties (equal device-reported timestamps) resolve
  deterministically, matching InMemoryEventRepository's insertion-order
  tie-break.
- PdoZoneRepository::updateOwned(): after the ownership-scoped UPDATE,
  disambiguate a 0-rowCount() result (MySQL reports "changed" rows, not
  "matched" rows) with a targeted existence check, so a genuine no-op
  resubmit (identical level/polygon) still succeeds while a zone deleted
  concurrently between the ownership check and the UPDATE now throws
  instead of save() silently reporting success for a zone that no longer
  exists.

Full suite still green: 59 tests, 114 assertions, 4 skipped, 0 failures,
0 warnings/deprecations.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ne4rU4FToTLHcBUMUvUnT1
2026-07-12 02:06:32 +09:00
유창욱
9aa7f44ea4 feat(cloud): PDO repositories + schema + Cafe24 deploy doc
Implements Task 16 (final, P1-B): App\Db\Database::connect(Config): PDO
factory and the 9 App\Repository\Pdo\Pdo*Repository classes backing the
repository interfaces consumed by controllers since T1-T15, all-prepared
statements, plus cloud/schema.sql (MySQL 8 DDL) and cloud/docs/cloud-deploy.md.

Security hardening incorporated per accumulated task reviews:
- PdoNonceRepository: nonces.nonce is PK; duplicate remember() throws instead
  of racing seen() (closes T7 TOCTOU).
- PdoRateLimiterRepository::hit(): atomic INSERT ... ON DUPLICATE KEY UPDATE
  upsert on (rate_key, window_start), no read-modify-write race.
- PdoSnapshotRepository::pathByUuid(): validates 32-hex uuid before building
  any filesystem path (closes T12 path-traversal risk).
- PdoZoneRepository::save(): update path is ownership-scoped by
  (zone_id, device_id, camera_id); throws on mismatch instead of silently
  overwriting an unrelated zone (closes T13 cross-tenant overwrite risk).
- Database::connect(): ERRMODE_EXCEPTION, EMULATE_PREPARES=false, FETCH_ASSOC.

cloud/tests/PdoIntegrationTest.php round-trips Nonce/Event/Zone against a
real sqlite :memory: DB, gated via markTestSkipped when pdo_sqlite is
unavailable (this host has pdo_mysql only, no pdo_sqlite) -- suite stays
green with 4 tests skipped.

Full suite: 59 tests, 114 assertions, 4 skipped, 0 failures, 0
warnings/deprecations. php -l passes on all new files and on
cloud/public/index.php (T15), which references all new FQCNs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ne4rU4FToTLHcBUMUvUnT1
2026-07-12 01:58:05 +09:00
유창욱
81eae5d045 fix(cloud): login form submits via fetch (redirect on success, show error) 2026-07-12 01:39:06 +09:00
유창욱
81e8e81b72 feat(cloud): front controller wiring + views + zone-draw UI 2026-07-12 01:24:42 +09:00
유창욱
5135c08e18 feat(cloud): device config + heartbeat sync API (HMAC) 2026-07-12 01:13:02 +09:00
유창욱
92c630bf58 feat(cloud): polygon validation + zone config controller (RBAC) 2026-07-12 01:02:37 +09:00
유창욱
90d3016b17 feat(cloud): dashboard list/detail/ack + auth-gated snapshot proxy 2026-07-12 00:56:43 +09:00
유창욱
430758c3b7 feat(cloud): path-param router + dispatch 2026-07-12 00:49:52 +09:00
유창욱
f7a0a3740e test(cloud): cover unknown-username 401 parity + logout session clear 2026-07-12 00:46:39 +09:00
유창욱
902bbe93c8 fix(cloud): reset lockout on window expiry + constant-time unknown-user path (anti-enumeration) 2026-07-12 00:39:19 +09:00
유창욱
450c88978f fix(cloud): session-id regeneration on login (fixation) + pristine test output 2026-07-12 00:35:41 +09:00
유창욱
b345a89788 feat(cloud): session store + auth controller with lockout 2026-07-12 00:28:18 +09:00
유창욱
9983bc8fe3 feat(cloud): RBAC permission matrix 2026-07-12 00:19:47 +09:00
유창욱
76ea1b4ecf feat(cloud): argon2id password + CSRF token helpers 2026-07-12 00:11:20 +09:00
유창욱
185629a4c4 fix(cloud): unify ingest auth errors (anti-enumeration) + guard snapshot write 2026-07-12 00:07:42 +09:00
유창욱
57cfc64548 feat(cloud): ingest controller (HMAC+nonce+ratelimit+reencode+persist) 2026-07-12 00:01:05 +09:00
유창욱
a0db1e06ca feat(cloud): Http Request/Response primitives 2026-07-11 23:54:58 +09:00
유창욱
7246e12c4a feat(cloud): gd image re-encode (strip payload, uuid, hash) 2026-07-11 23:50:08 +09:00
유창욱
2f88355071 fix(cloud): type-guard EventValidator fields against malformed input 2026-07-11 23:46:38 +09:00
유창욱
b5388b2a68 feat(cloud): event payload validator with enum whitelist 2026-07-11 23:40:53 +09:00
유창욱
4bbd28f95f fix(cloud): centralize test-double autoloading via composer files
Move InMemoryRepositories.php from require_once workaround to composer
files-autoload. Enables PSR-4 autoloading of test-double classes and
scales for 5+ future test files. All 8 tests pass with require_once removed.
2026-07-11 23:38:01 +09:00