# Changelog

All notable changes to `@edgeai/edge-client-ts` are documented here.
The format follows [Keep a Changelog](https://keepachangelog.com/) and the
project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Added
- (placeholder for next iteration)

## [1.1.0] - 2026-07-14

### Security (4-review audit cycle: F-1..F-22, G-1..G-11, H-1..H-9, I-1)

Closed 36+ findings across four security reviews. Key features:

- **Buffer encryption** (F-1): fail-closed AES-256-GCM with explicit error.
- **TLS guard** (F-5, F-6): centralized `decideTlsFromEnv` in `cli/http-helpers.ts`. CLI subcommands refuse plaintext `ws://` in production.
- **AGT-03 cmd-gate** (F-12, G-3, G-9, H-7): evaluates every `tool_execution_start` against `allowlist` / `always_approve` / `denylist`; emits `cmd_gate_denied` / `extension_ui_request` / `fail_fast_*` synthetic events with `operator_id` attribution. Events now wired to relay via `sessionManager.onPiEvent → ws.send` (G-3 fix).
- **AGT-02 fail-fast layer 2** (F-11, G-6): command-side blocklist (`rm -rf /`, `dd if=/dev/zero`, `mkfs`, `shutdown`, `bcdedit /set`, `sudo su -`, etc.). Opt-in via `EDGE_FAIL_FAST_COMMAND_BLOCKLIST=1`.
- **HMAC sidecar** (F-22, G-2, G-4, H-3): `sessions.json.sig` HMAC-SHA256 keyed off `device_secret`. Constant-time compare. Canonical JSON format matches Rust. **Auto-migrates pre-G-4 tab/newline sidecars** (H-3).
- **SSRF guard** (F-7, G-8): `browser_fetch` URL is checked against RFC1918 / loopback / link-local before fetch.
- **URL redaction** (F-9, G-5, H-1, I-1): two-pass parser + regex, covers query strings AND URL fragments. All error messages run through `redactUrl`.
- **Inbound rate-limit** (F-17): token bucket on inbound WS frames (50/sec capacity, drops silently).
- **`device_secret_issued` handler** (F-2): relay-issued per-device credentials are now persisted + chmod'd + used on reconnect (was empty `break;` before).
- **Edge-client.env file** (F-3): operator's `opk_` key lives in a separate chmod-0600 file, NOT in the device_secret slot. Added `envFilePath`, `writeOwnerOperatorEnv`, `loadOperatorApiKey` helpers.

### Fixed (wire-protocol alignment)

- **F-16 / G-1**: enroll now posts to `/api/operators/oauth-sync` with `X-Api-Key` header + `{oauth_sub, display_name, api_key_plain}` body. The earlier `X-Admin-Api-Key` header + wrong body fields were wire-level broken vs the relay.
- **H-2**: WS upgrade emits BOTH `?edge_token=` AND `?auth_token=` with the same value. The relay's `extractAuthToken` reads `?auth_token=`; removing the dual-param in F-14 broke WS auth end-to-end. Restored.
- **F-14**: `?auth_token=` is the v1 wire format (always read by the relay); `?edge_token=` is the v2 wire format (read by `validateEdgeToken` after `extractAuthToken`). Both emitted for forward-compat.
- **H-4**: when re-enrolling with the same key, the relay returns `403 KEY_FOR_EXISTING_OPERATOR`. The TS client now parses this code and surfaces an actionable hint.
- **G-2**: HMAC sidecar verification uses `constantTimeHexEquals` (timingSafeEqual), not `===`.
- **G-4**: HMAC scheme uses canonical JSON (`JSON.stringify([["k","v"]])`) matching Rust's `serde_json::to_vec(&Vec<(&String, &String)>)`. Rust↔TS interop works.
- **F-19**: `runDaemon` now refuses to start with empty `machine_id` + no `EDGE_AUTH_TOKEN` (calls existing `enforceHostnameOrToken`).
- **F-15**: `dump_dir` default is platform-appropriate (`~/.local/share/...` on Linux, etc.) instead of relative `./buffer-dump`.
- **F-18**: `whoami` hint derived from key's structural shape (`opk_<seg>_`) instead of leaking first/last 4 bytes of secret.
- **F-11**: deny list now has 24 patterns matching Rust (was 9; added `rm -fr /`, `dd if=/dev/urandom`, `sudo -i`, Windows-specific).
- **G-11**: `cmd-gate collectStringArgs` bounded depth (32) + size cap (1 MiB) + regex-based scan (no memory doubling).

### Added (operations)

- **`EDGE_ADMIN_API_KEY` env var** is now documented as required for `ec-ts enroll` (Q-1 from the security parity plan).
- **Re-enroll** section in README documents the `403 KEY_FOR_EXISTING_OPERATOR` workflow.
- **Security parity** table in README summarizing the 36+ closed findings.

### Known limitations (deferred; parity with Rust)

- **G-7**: `device_secret_issued` accepts arbitrary values (no relay signature). Requires key-management redesign.
- **G-8**: SSRF guard has DNS-rebinding TOCTOU window. Requires custom DNS resolver.
- **G-10**: Windows ACL for `edge-client.env` is a no-op (use `icacls` for hardening).
- **I-2**: H-2 fix is v1-only. Operators planning the v2 cutover (`EDGEAI_AUTH_MODEL=v2`) will need a TS client update with opaque-token subprotocol support.

## [1.0.2] - 2026-07-13

### Changed
- Re-published under the canonical scoped name `@edgeai/edge-client-ts`
  after the npm registry finished propagating the org scope. The
  unscoped `edge-ai-client-ts@1.0.1` is now **deprecated** — please
  switch to the scoped name:
  ```bash
  npm uninstall -g edge-ai-client-ts
  npm install -g @edgeai/edge-client-ts
  ```

## [1.0.1] - 2026-07-13

### Fixed
- `ec-ts --version` now reads from `package.json` dynamically (was
  hardcoded to `7.0.0` from a pre-publish iteration).

## [1.0.0] - 2026-07-13

**First public release** of `@edgeai/edge-client-ts` on npm. The package
ships a complete, byte-compatible TypeScript re-implementation of the Rust
`ec` binary — same wire protocol, same security model, same CLI surface,
shipped via `npm install -g`.

### Added
- Full TypeScript (Model 1) parallel client mirroring the Rust
  `edge-client` byte-for-byte on the wire protocol. See
  `docs/PROTOCOL.md` for the full spec and `e2e-smoke/README.md` for the
  end-to-end smoke test.
- 17-byte binary shell frame codec (`session/shell-frame.ts`) — byte-exact
  with Rust `ShellFrame::encode/decode`.
- AES-256-GCM disk-backed offline buffer queue (`buffer/disk-queue.ts`).
- AGT-02 fail-fast policy (`session/fail-fast.ts`).
- Disk-backed session persistence (`session/persistence.ts`).
- `EdgeWsClient` with register / heartbeat / ACK / `get_config` RPC /
  reconnect supervisor.
- All six CLI subcommands (`run`, `enroll`, `whoami`, `status`, `devices`,
  `messages`) with commander `exitOverride()` for embeddability.
- `ServiceManager` for per-OS service install: systemd --user (Linux),
  LaunchAgent (macOS), schtasks / LeastPrivilege (Windows).
- TLS SPKI fingerprint pinning via the Node built-in `tls` module.
- Comprehensive documentation under `docs/`:
  - `INSTALLATION.md`
  - `CONFIGURATION.md`
  - `TROUBLESHOOTING.md`
  - `PROTOCOL.md`
- GitHub Actions workflow for CI + automated npm publish.

### Fixed
- Subprotocol header is now a 2-element array `["edgeai-v2", "<token>"]`
  (was a single comma-containing string that `ws@8` rejects).
- `socket.on('error')` defensive null-error handler (was propagating
  `null` → `Error("null")`).
- `session/shell.ts` stub `FrameCodec` replaced with the byte-exact real
  codec from `session/shell-frame.ts` (was producing DIFFERENT wire bytes
  than the Rust side via a hex-string interpretation).

### Changed
- Renamed the package version series from the pre-publish `7.0.0` line to
  `1.0.0` to mark the first public npm release (no API/semantic break —
  internal only).
- Removed duplicate `FrameType` / `FrameCodec` stub from
  `session/shell.ts` in favor of `session/shell-frame.ts` as the single
  source of truth.

### Security
- `prepublishOnly` runs `typecheck`, `test`, and `build` to prevent
  shipping a broken / unverified package.
- No secrets are stored in source. All credentials are loaded from
  environment variables (`EDGE_AUTH_TOKEN`, `EDGE_BUFFER_KEY`,
  `EDGE_RELAY_FINGERPRINT`, …) — see `docs/CONFIGURATION.md`.

### Known issues
- See `docs/TROUBLESHOOTING.md` for a curated list of operator-facing
  workarounds (no known critical issues at v1.0.0).

[Unreleased]: https://github.com/baphuongna/edge-ai-agent/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/baphuongna/edge-ai-agent/releases/tag/v1.0.0