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>
58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
import { LOG_REDACT, createBridge } from './app.ts';
|
|
import { ConfigError, loadConfig } from './config.ts';
|
|
import { StateDirectoryError } from './db.ts';
|
|
import { loadEnvFile } from './env.ts';
|
|
import { BuiltinWhisperStt } from './stt/builtinWhisper.ts';
|
|
|
|
async function main(): Promise<void> {
|
|
loadEnvFile();
|
|
const config = loadConfig();
|
|
const bridge = await createBridge(config, {
|
|
logger: { level: config.logLevel, redact: { paths: LOG_REDACT, censor: '[redacted]' } },
|
|
});
|
|
await bridge.app.listen({ host: config.host, port: config.port });
|
|
|
|
// Verify and load the built-in speech model in the background so the first spoken question
|
|
// is not slowed by it. Nothing is downloaded here: the files must already be in the model
|
|
// store (`bridge:cli fetch-model`) and must match their pinned hashes.
|
|
const stt = bridge.stt;
|
|
if (stt instanceof BuiltinWhisperStt) {
|
|
const started = Date.now();
|
|
const pin = { model: config.stt.manifest!.model, revision: config.stt.manifest!.revision };
|
|
bridge.app.log.info(pin, 'stt.loading');
|
|
stt.warm().then(
|
|
() => bridge.app.log.info({ ...pin, load_ms: Date.now() - started }, 'stt.ready'),
|
|
() =>
|
|
bridge.app.log.error(
|
|
{
|
|
...pin,
|
|
reason: stt.lastLoadFailure,
|
|
hint: stt.lastLoadFailure === 'missing' ? 'run: npm run bridge:cli -- fetch-model' : undefined,
|
|
},
|
|
'stt.load_failed',
|
|
),
|
|
);
|
|
}
|
|
|
|
let closing = false;
|
|
const stop = (signal: string) => {
|
|
if (closing) return;
|
|
closing = true;
|
|
bridge.app.log.info({ signal }, 'bridge.stopping');
|
|
bridge.close().then(
|
|
() => process.exit(0),
|
|
() => process.exit(1),
|
|
);
|
|
};
|
|
process.on('SIGINT', () => stop('SIGINT'));
|
|
process.on('SIGTERM', () => stop('SIGTERM'));
|
|
}
|
|
|
|
main().catch((err: unknown) => {
|
|
// Configuration problems are operator-facing; never print the environment.
|
|
if (err instanceof ConfigError) console.error(`Configuration error: ${err.message}`);
|
|
else if (err instanceof StateDirectoryError) console.error(`Cannot start: ${err.message}`);
|
|
else console.error(err);
|
|
process.exit(1);
|
|
});
|