First vertical slice: Even client, bridge, contract v1, tests, docs
Client (apps/even-client): pure interaction reducer with generation-based stale-result rejection, HUD renderer, measured pagination, Even Hub SDK 0.0.16 adapter, bridge HTTP client, phone pairing/status/diagnostics page. Bridge (services/bridge): device pairing and revocable expiring credentials, turn engine with idempotent submit, cancel, deadlines and restart recovery, Hermes Runs API adapter, OpenAI-compatible STT adapter, operator CLI. Contract (packages/contracts): versioned schemas, types and error codes. Tests: 122 unit/integration (fakes), 6 simulator scenarios (Even Hub simulator 0.9.5), 9 scenarios against a real Hermes v0.23.1 gateway with a stub model. No real STT, real model or physical device has been exercised; see docs/test-evidence.md and docs/device-test-plan.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { ConfigError, loadConfig } from './config.ts';
|
||||
import { openDb } from './db.ts';
|
||||
import { Devices } from './devices.ts';
|
||||
import { loadEnvFile } from './env.ts';
|
||||
|
||||
/**
|
||||
* Operator CLI. It talks to the SQLite file directly, so there is no admin
|
||||
* surface on the network: whoever can run this on the bridge host is the owner.
|
||||
*/
|
||||
function usage(): never {
|
||||
console.error(
|
||||
[
|
||||
'Usage: npm run bridge:cli -- <command>',
|
||||
'',
|
||||
' pair Print a single-use pairing code for one new device',
|
||||
' devices List paired devices',
|
||||
' revoke <device-id> Revoke a device credential immediately',
|
||||
].join('\n'),
|
||||
);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
function main(): void {
|
||||
loadEnvFile();
|
||||
const config = loadConfig();
|
||||
const db = openDb(config.dbPath);
|
||||
const devices = new Devices(db, config);
|
||||
const [command, arg] = process.argv.slice(2);
|
||||
|
||||
switch (command) {
|
||||
case 'pair': {
|
||||
const { code, expiresAt } = devices.createPairingCode();
|
||||
const minutes = Math.round((expiresAt - Date.now()) / 60_000);
|
||||
console.log(`Pairing code: ${code}`);
|
||||
console.log(`Valid for ${minutes} minute(s), one device, one use. Any earlier unused code is now void.`);
|
||||
break;
|
||||
}
|
||||
case 'devices': {
|
||||
const rows = devices.list();
|
||||
if (!rows.length) console.log('No devices paired.');
|
||||
for (const d of rows) {
|
||||
const status = d.revoked_at
|
||||
? 'revoked'
|
||||
: d.pairing_expires_at <= Date.now()
|
||||
? 'pairing expired'
|
||||
: d.token_expires_at <= Date.now()
|
||||
? 'token expired'
|
||||
: 'active';
|
||||
const seen = d.last_seen_at ? new Date(d.last_seen_at).toISOString() : 'never';
|
||||
console.log(`${d.id} ${status.padEnd(15)} last seen ${seen} ${d.name}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'revoke': {
|
||||
if (!arg) usage();
|
||||
console.log(devices.revoke(arg) ? `Revoked ${arg}.` : `No active device ${arg}.`);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
|
||||
try {
|
||||
main();
|
||||
} catch (err) {
|
||||
console.error(err instanceof ConfigError ? `Configuration error: ${err.message}` : err);
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user