Add ESLint: typescript-eslint strict-type-checked + stylistic formatting

Flat config with two layers. Correctness (type-checked): the headline
rules for this codebase are no-floating-promises / no-misused-promises
(a lost promise in the agent loop is our primary bug class),
switch-exhaustiveness-check (we switch over merge-extensible unions
everywhere), no-unnecessary-condition, require-await, and
no-explicit-any. Style (@stylistic): 2-space, no semicolons, single
quotes, trailing commas, max-len 140 — the existing house style, now
enforced instead of drifting between agents. vendor/ is excluded
(vendored source keeps upstream style); tests relax the rules that
fight test ergonomics (non-null assertions after expects, async mock
signatures, non-Error throws).

Code adjusted to pass: registry disposers wrap ctx.effect's
promise-returning disposer behind a sync () => void (our public API),
BlockAssembler gains an invariant-checking mustGet instead of non-null
assertions, lastTurnNumber uses findLast, waterfall tails return
Promise.resolve instead of async-without-await arrows, and the two
deliberate suppressions (non-exhaustive derivation switch, unbound
execute pass-through) carry justification comments.

yarn lint / yarn lint:fix added.
This commit is contained in:
Tianyi Cui
2026-06-11 14:17:58 +08:00
parent d2fb352f3e
commit cb6bee3d03
17 changed files with 993 additions and 49 deletions

View File

@@ -97,6 +97,10 @@ export class Session {
deriveMessages(): Message[] {
const messages: Message[] = []
for (const event of this.log) {
// Intentionally non-exhaustive: only message-producing events derive
// history; turn/step boundaries, chunks, usage, and errors are
// trace/replay data.
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (event.type) {
case 'user/message': {
messages.push({ role: 'user', content: event.data.content })
@@ -155,7 +159,7 @@ export class SessionStore extends Service {
if (this.store.has(id)) throw new Error(`session "${id}" already exists`)
const session = new Session(id, seed)
this.ctx.effect(() => {
session.onAppend = (event) => this.ctx.emit('session/event', session, event)
session.onAppend = (event) => { this.ctx.emit('session/event', session, event) }
this.store.set(id, session)
this.ctx.emit('session/created', session)
return () => {