Address Cody review round 3: CODY-003 and CODY-006
CODY-003 Request identity is durable before submission. Storage results are
explicit at the DevicePort boundary (storageSet resolves true only
on the host's own timely confirmation; storageGet distinguishes
unknown from empty). A request is not sent until the phone has
confirmed storing its id; a timeout or refusal holds it back,
unsent and retryable under the same id. Unreadable storage at
start is not treated as unpaired; an unsaveable pairing is revoked.
CODY-006 The state directory is set to 0700 on every open, including when
it already existed, and the bridge refuses to start with an
operator-facing error if it cannot be. Deployment guide creates
it with install -d -m 0700.
Checks: typecheck clean; npm test 194 passed; client build ok;
test:real-stt 11 passed; test:real-hermes 9 passed; test:simulator 6
passed; git diff --check clean.
Not reviewed. No physical-device, droplet or production evidence.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
} from '@evenrealities/even_hub_sdk';
|
||||
import { BODY_BOX, HUD, STATUS_BOX, type HudFrame } from '../core/hud.ts';
|
||||
import { MENU_ITEM, normalizeEvent, type DeviceEvent, type RawEvenHubEvent } from './events.ts';
|
||||
import type { DevicePort } from './port.ts';
|
||||
import type { DevicePort, StorageRead } from './port.ts';
|
||||
|
||||
const BODY = { id: 1, name: 'body' } as const;
|
||||
const STATUS = { id: 2, name: 'status' } as const;
|
||||
@@ -192,11 +192,18 @@ export class EvenDevice implements DevicePort {
|
||||
await this.enqueue(() => this.bridge.shutDownPageContainer(1), false);
|
||||
}
|
||||
|
||||
storageGet(key: string): Promise<string> {
|
||||
return this.enqueue(() => this.bridge.getLocalStorage(key), '');
|
||||
async storageGet(key: string): Promise<StorageRead> {
|
||||
const read = await this.enqueueBounded<string | null>(() => this.bridge.getLocalStorage(key), null);
|
||||
// A timeout or a host error is "unknown", not "empty": the caller must not conclude that
|
||||
// nothing was stored.
|
||||
if (read.timedOut || typeof read.value !== 'string') return { ok: false };
|
||||
return { ok: true, value: read.value };
|
||||
}
|
||||
|
||||
async storageSet(key: string, value: string): Promise<void> {
|
||||
await this.enqueue(() => this.bridge.setLocalStorage(key, value), false);
|
||||
async storageSet(key: string, value: string): Promise<boolean> {
|
||||
const write = await this.enqueueBounded(() => this.bridge.setLocalStorage(key, value), false);
|
||||
// Only the host's own `true`, received in time, counts. If the caller's wait ran out the
|
||||
// host call is still pending in the queue and may complete later; that is not confirmation.
|
||||
return !write.timedOut && write.value === true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { HudFrame } from '../core/hud.ts';
|
||||
import type { DeviceEvent } from './events.ts';
|
||||
|
||||
export type StorageRead = { ok: true; value: string } | { ok: false };
|
||||
|
||||
/** Everything Hermeven needs from the glasses runtime. Implemented by the Even adapter and by test fakes. */
|
||||
export interface DevicePort {
|
||||
/** Create the HUD page. Resolves false when the host refused it. */
|
||||
@@ -14,6 +16,15 @@ export interface DevicePort {
|
||||
onConnection(listener: (connected: boolean) => void): () => void;
|
||||
/** Ask the OS to show its own exit confirmation. */
|
||||
requestExit(): Promise<void>;
|
||||
storageGet(key: string): Promise<string>;
|
||||
storageSet(key: string, value: string): Promise<void>;
|
||||
/**
|
||||
* Read a stored value. `{ ok: false }` means the host did not answer (or failed): the value
|
||||
* is UNKNOWN, which is different from "nothing stored" (`{ ok: true, value: '' }`).
|
||||
*/
|
||||
storageGet(key: string): Promise<StorageRead>;
|
||||
/**
|
||||
* Store a value. Resolves `true` ONLY when the host positively confirmed the write.
|
||||
* `false` covers a refusal, an error and a timeout; after a timeout the write may still
|
||||
* land later, so `false` is "not confirmed", never "not written" and never "written".
|
||||
*/
|
||||
storageSet(key: string, value: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { HudFrame } from '../core/hud.ts';
|
||||
import type { DeviceEvent } from './events.ts';
|
||||
import type { DevicePort } from './port.ts';
|
||||
import type { DevicePort, StorageRead } from './port.ts';
|
||||
|
||||
/**
|
||||
* Stand-in for the glasses when the page runs in a plain browser (no Even host).
|
||||
@@ -68,20 +68,21 @@ export class BrowserPreviewDevice implements DevicePort {
|
||||
|
||||
async requestExit(): Promise<void> {}
|
||||
|
||||
async storageGet(key: string): Promise<string> {
|
||||
async storageGet(key: string): Promise<StorageRead> {
|
||||
try {
|
||||
return localStorage.getItem(key) ?? '';
|
||||
return { ok: true, value: localStorage.getItem(key) ?? '' };
|
||||
} catch {
|
||||
return '';
|
||||
return { ok: false };
|
||||
}
|
||||
}
|
||||
|
||||
async storageSet(key: string, value: string): Promise<void> {
|
||||
async storageSet(key: string, value: string): Promise<boolean> {
|
||||
try {
|
||||
if (value) localStorage.setItem(key, value);
|
||||
else localStorage.removeItem(key);
|
||||
return true;
|
||||
} catch {
|
||||
/* preview only */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user