@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
50 lines • 2.28 kB
JavaScript
/**
* F13: one `loaded_surfaces_changed` per connection per inventory change, never one per session.
*
* The dedupe is transition-aware. Per connection it remembers, for every session, the digest that
* session was last announced at and the digest it arrived from. A session's change is told only when
* no OTHER session already announced the same transition (the same previous digest to the same new
* one): sessions moving together share one event, but a session that converges onto a digest the
* connection heard from a different starting point still announces its own change, because surface
* reads (`get_commands`, `get_loaded_surfaces`) are per session and one event names one session.
*/
export class SurfaceDigestDedupe {
constructor() {
/** Per connection, per session: the digest last announced and the one it arrived from. */
this.connections = new Map();
}
/**
* Record one session's move from `previous` to `digest` for a connection. Returns true when the
* connection must hear about it. `previous` is the session's real prior digest, never this
* connection's memory of it: a connection that attached after the session last moved has no
* memory, and judging from that would merge two different moves onto the same target.
*/
announce(connectionId, sessionId, previous, digest) {
let sessions = this.connections.get(connectionId);
if (sessions === undefined) {
sessions = new Map();
this.connections.set(connectionId, sessions);
}
if (previous === digest)
return false;
let tell = true;
for (const [other, announced] of sessions) {
if (other === sessionId || announced.last !== digest)
continue;
if (announced.previous === previous) {
tell = false;
break;
}
}
sessions.set(sessionId, { last: digest, previous });
return tell;
}
dropConnection(connectionId) {
this.connections.delete(connectionId);
}
forgetSession(sessionId) {
for (const sessions of this.connections.values())
sessions.delete(sessionId);
}
}
//# sourceMappingURL=session-surface-dedupe.js.map