glasspane-mcp 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,44 @@ export interface LateArrivalOutcome {
33
33
  /** The trail generation in force at the moment of the decision. */
34
34
  generationAtWrite: number;
35
35
  }
36
+ /**
37
+ * How an id got into this trail, per id, in the words a renderer can put beside
38
+ * it. The three values are not adjectives of confidence: they name which
39
+ * mechanism wrote the id, and each one is a fact the session itself observes.
40
+ *
41
+ * - `in-order`: written by a call whose own request held a trail turn, answered
42
+ * by a frame that echoed that request's id. This is the only entry the trail
43
+ * may describe as verified.
44
+ * - `late`: written from a reply that landed after its caller had already been
45
+ * answered, so it had no turn left to write at and took the position
46
+ * {@link recordLateArrival} gives it — behind whatever is still outstanding.
47
+ * The *operation* is the daemon's own; only its place in request order is
48
+ * arranged by arrival.
49
+ * - `late-inferred`: that same late write, for a frame that echoed **no request
50
+ * id** (R10-中2). Which request it answers is then a guess from the daemon's
51
+ * in-order scheduling, not a match, and an id pulled out of it can be filed
52
+ * under the wrong operation. The trail still records it — dropping it would
53
+ * claim "no such operation ran", which is the more dangerous lie for an agent
54
+ * deciding whether to click again — but it must not read as verified, and
55
+ * `gp_recent_reports` has to say so from here rather than from the log line.
56
+ *
57
+ * Producers: `EngineJsonRpcClient`'s `LateReply.attribution` decides between the
58
+ * last two (`echoed-id` -> `late`, `arrival-order` -> `late-inferred`); a caller
59
+ * that passes nothing gets `late`, which is everything this session can see on
60
+ * its own.
61
+ */
62
+ export type TrailProvenance = "in-order" | "late" | "late-inferred";
63
+ /**
64
+ * The attribution a late arrival carries: the same two literals
65
+ * `engine-client.ts`'s `FrameAttribution` produces, and `unknown` for a caller
66
+ * that cannot say (a wiring that has not read the field yet).
67
+ */
68
+ export type LateArrivalAttribution = "echoed-id" | "arrival-order" | "unknown";
69
+ /**
70
+ * The sentence the surface that shows the trail puts beside one id. Written here
71
+ * because this is the layer that knows the mechanism; the tool layer renders it.
72
+ */
73
+ export declare const TRAIL_PROVENANCE_NOTES: Readonly<Record<TrailProvenance, string>>;
36
74
  export declare class EvidenceAuditSession {
37
75
  private ids;
38
76
  private epoch;
@@ -46,8 +84,44 @@ export declare class EvidenceAuditSession {
46
84
  * order the turn machinery exists to remove.
47
85
  */
48
86
  private openGates;
49
- /** Record every operationId/evidenceId found in an engine result frame. */
87
+ /**
88
+ * How each id in {@link ids} got here. Keyed by the id, because that is what a
89
+ * reader holds; the map is trimmed with the list and cleared when the trail
90
+ * restarts, so an id can never outlive the provenance that describes it.
91
+ */
92
+ private readonly provenance;
93
+ /**
94
+ * Non-null while {@link recordLateArrival} holds the trail, and says how the
95
+ * frame being written was attributed. This is what lets a plain
96
+ * `trail.record(result)` inside that callback be filed as a late arrival without
97
+ * the caller having to remember to say so: the write happens inside a window only
98
+ * that method opens, so the mechanism is visible here rather than being a claim
99
+ * somebody must repeat at every call site.
100
+ */
101
+ private lateWindow;
102
+ /**
103
+ * Record every operationId/evidenceId found in an engine result frame, tagged
104
+ * with the provenance of the path that is recording it (see
105
+ * {@link TrailProvenance}): `in-order` from a call that held its own trail turn,
106
+ * `late`/`late-inferred` from inside {@link recordLateArrival}.
107
+ */
50
108
  record(result: unknown): void;
109
+ /**
110
+ * How one id in this trail got recorded, or null when the trail does not hold
111
+ * it — never recorded, evicted past {@link AUDIT_HISTORY_LIMIT}, or cleared by a
112
+ * {@link restart}. A reader that lists ids for an agent renders
113
+ * {@link TRAIL_PROVENANCE_NOTES} for anything that is not `in-order`: an id
114
+ * pulled from a frame this shell only *guessed* an owner for must not appear
115
+ * beside one it matched by id (R10-中2).
116
+ *
117
+ * Read off the map alone, so the map *is* the record of what the trail holds: an
118
+ * id whose provenance outlives its own entry would come back labelled as if it
119
+ * were still listed, and the eviction and the restart are the two places that
120
+ * would have to remember to delete. `test/engine-client.test.mjs` pins both.
121
+ */
122
+ provenanceOf(id: string): TrailProvenance | null;
123
+ /** The ids currently filed as inferred; see {@link TrailProvenance}. */
124
+ inferredIds(): string[];
51
125
  /**
52
126
  * The trail's generation number. Every {@link restart} bumps it.
53
127
  *
@@ -109,8 +183,17 @@ export declare class EvidenceAuditSession {
109
183
  * decides whether that is acceptable; this method refuses it by default, because
110
184
  * "we do not know which attach this belongs to" is not a reason to write into
111
185
  * somebody else's trail.
186
+ *
187
+ * `attribution` is how the transport matched that frame to a request, and it is
188
+ * the difference between `late` and `late-inferred` below: a frame that echoed
189
+ * the id the client sent is confirmed, one with no id is filed against the
190
+ * oldest tracked request by the daemon's in-order scheduling (R10-中2). Anything
191
+ * this method writes is a late arrival by construction, so the window opens
192
+ * whether or not the caller can say more — the default `unknown` is what the
193
+ * session can see on its own, and it is *not* `in-order`: an unconfirmed
194
+ * attribution must not read as a verified one.
112
195
  */
113
- recordLateArrival(apply: (session: EvidenceAuditSession) => void, admittedUnderGeneration?: number): Promise<LateArrivalOutcome>;
196
+ recordLateArrival(apply: (session: EvidenceAuditSession) => void, admittedUnderGeneration?: number, attribution?: LateArrivalAttribution): Promise<LateArrivalOutcome>;
114
197
  /**
115
198
  * Claim the next position in this session's trail request order, so that
116
199
  * overlapping calls mutate and read `ids` in the order they were admitted
@@ -26,7 +26,7 @@ export declare const MCP_PROTOCOL_VERSION: "2025-06-18";
26
26
  export declare const SUPPORTED_PROTOCOL_VERSIONS: readonly string[];
27
27
  export declare const SERVER_INFO: {
28
28
  readonly name: "glasspane-mcp";
29
- readonly version: "1.3.0";
29
+ readonly version: "1.3.1";
30
30
  };
31
31
  export declare const PARSE_ERROR = -32700;
32
32
  export declare const INVALID_REQUEST = -32600;
@@ -76,8 +76,10 @@ export declare const ENGINE_TIMEOUT_MS = 10000;
76
76
  * `GP_E_ENGINE_TIMEOUT` and the no-replay remedy, and the request stays
77
77
  * registered, so the reply that arrives later is still attributed and written
78
78
  * to the log (`onDeadline` -> `reportLateReply`). Nothing is discarded by
79
- * answering early, which is what makes the multi-minute deadlines above safe to
80
- * cap: they describe the daemon, not the caller's wait.
79
+ * answering early — the only thing that ends that registration is the transport
80
+ * going away, and `teardown` logs the tracked requests it drops when it does —
81
+ * which is what makes the multi-minute deadlines above safe to cap: they
82
+ * describe the daemon, not the caller's wait.
81
83
  */
82
84
  export declare const CALLER_VISIBLE_CEILING_MS = 50000;
83
85
  /**
@@ -126,6 +128,17 @@ export declare const ENGINE_DEADLINES_MS: {
126
128
  };
127
129
  /** Fixed part of an ffwd restore deadline (per-step cost is `act` above). */
128
130
  export declare const RESTORE_BASE_DEADLINE_MS = 30000;
131
+ /**
132
+ * The single answer to "will re-issuing this method perform a change the daemon may
133
+ * already have carried out?". Exported because two other layers have to ask it —
134
+ * `tools.ts` when it rewrites an oversized reply, `http-gateway.ts` when it answers
135
+ * a curl caller — and a membership list copied into each of them is how the advice
136
+ * for one tool drifts back into "just retry the click". A caller that wants the
137
+ * *reason* per method owns that text; membership comes from here.
138
+ */
139
+ export declare function isReplayUnsafeMethod(method: string): boolean;
140
+ /** The non-replayable methods, for gates that must see the set change on purpose. */
141
+ export declare const REPLAY_UNSAFE_METHOD_NAMES: readonly string[];
129
142
  /** Deadline for one request; `restore` scales with its replayed step count. */
130
143
  export declare function engineDeadlineMs(method: string, params?: Record<string, unknown>): number;
131
144
  /** When the caller gets its answer for `method`: its deadline, capped. */
@@ -209,15 +222,42 @@ export type ShellSurface = "mcp" | "http";
209
222
  export declare function lateReplyRoute(surface: ShellSurface): string;
210
223
  /**
211
224
  * Remedy for a deadline overrun: wait and measure, never restart on a probe that
212
- * merely went unanswered, and never replay a user-visible action.
225
+ * merely went unanswered, and never replay a request whose re-issue has a side
226
+ * effect.
213
227
  */
214
228
  export declare function slowEngineRemedy(method: string, surface?: ShellSurface): string;
229
+ /** Log ceiling for a frame body; excess is marked, never silently cut. */
230
+ export declare const LOG_BODY_CHARS: number;
231
+ /**
232
+ * How a reply frame was matched to the request it is reported for.
233
+ *
234
+ * `echoed-id` is the frame carrying the request id this client sent and the
235
+ * lookup hitting; that is the only attribution this transport can *confirm*.
236
+ * `arrival-order` is the daemon's id-less answer (it loses the id on the paths
237
+ * that could not parse or could not serialize the frame), matched to the oldest
238
+ * request still tracked because the daemon answers in the order it received
239
+ * them — an inference from scheduling, never a confirmation, so anything written
240
+ * from it into an evidence trail has to carry that caveat with it
241
+ * (`EvidenceAuditSession.provenanceOf`).
242
+ *
243
+ * Spelled as the same two literals `audit-session.ts` accepts for the same
244
+ * reason: the transport is the only thing that sees the frame, and the session is
245
+ * the only thing that decides what the trail claims about an id.
246
+ */
247
+ export type FrameAttribution = "echoed-id" | "arrival-order";
215
248
  /** One late engine reply, as handed to {@link EngineJsonRpcClient.onLateReply}. */
216
249
  export interface LateReply {
217
250
  method: string;
218
251
  result: unknown;
219
252
  /** Whatever `call()` was given; see {@link Pending.correlation}. */
220
253
  correlation?: number;
254
+ /**
255
+ * Whether this reply's *request* was confirmed by an echoed id or inferred
256
+ * from arrival order; see {@link FrameAttribution}. A sink that records this
257
+ * body into a trail must not present an `arrival-order` frame as a confirmed
258
+ * one, because the method it is filed under is a guess.
259
+ */
260
+ attribution: FrameAttribution;
221
261
  }
222
262
  /**
223
263
  * Request/response association over a line transport. Kept independent of
@@ -237,11 +277,27 @@ export declare class EngineJsonRpcClient {
237
277
  private readonly callerCeilingMs;
238
278
  /** Whom a timeout's remedy is being written for; see {@link ShellSurface}. */
239
279
  private readonly surface;
240
- private nextId;
241
- private closed;
280
+ /**
281
+ * Every mutable piece of this client's state, in one object that is *never*
282
+ * reassigned through `this`.
283
+ *
284
+ * That is not a style choice (R10-中4). `tools.ts` hands one tool an engine view
285
+ * built with `Object.create(engine)`, which puts the real client on the shadow's
286
+ * prototype chain so the shadow shares its map, its sinks and its transport — and
287
+ * any method that runs with the *shadow* as `this` then writes its field on the
288
+ * shadow, because assigning a property that exists only on the prototype creates
289
+ * an own property instead of touching the prototype's. `pending` survived that
290
+ * only because it is a `Map` that gets mutated rather than reassigned. A
291
+ * `this.closed = true` did not: it marked the shadow closed and left the client
292
+ * sending requests on a transport it had been told to end. Reading state out of
293
+ * this box still resolves through the chain, and writing a property of it mutates
294
+ * the one box the client itself holds.
295
+ *
296
+ * `test/engine-client.test.mjs` closes the *shadow* and asserts the client behind
297
+ * it is closed, which is the observable form of the whole rule.
298
+ */
299
+ private readonly state;
242
300
  private readonly pending;
243
- private noteHandler;
244
- private lateReplyHandler;
245
301
  constructor(io: LineIo, timeoutMs?: number | undefined, identity?: EngineIdentityExpectation | null,
246
302
  /**
247
303
  * Ceiling on the caller's wait (B-02). Injectable because a test cannot
@@ -271,6 +327,13 @@ export declare class EngineJsonRpcClient {
271
327
  * the eviction note says when something fell outside it.
272
328
  */
273
329
  onLateReply(handler: (reply: LateReply) => void): void;
330
+ /**
331
+ * Whether {@link close} has ended this client. Public because the answer has to
332
+ * be readable *through* the `Object.create` shadow the tool layer builds: a
333
+ * shadow that was closed has to report the client behind it closed, otherwise
334
+ * "closed" is a property of whichever object happened to receive the call.
335
+ */
336
+ isClosed(): boolean;
274
337
  /**
275
338
  * Send a request and await its matching response frame. `correlation` is
276
339
  * echoed to {@link onLateReply} if this request is answered after its caller
@@ -293,14 +356,31 @@ export declare class EngineJsonRpcClient {
293
356
  private settleFromFrame;
294
357
  /**
295
358
  * A frame over the cap: attribute it to the request it belonged to — from
296
- * the retained head when the daemon echoed an id, else by arrival order —
297
- * and fail that one call only.
359
+ * the retained head when the daemon echoed an id, else by arrival order, which
360
+ * is the oldest *tracked* request for the same reason the id-less frame path
361
+ * uses it (R9-高1) — and fail that one call only.
298
362
  */
299
363
  private failOversizedReply;
300
364
  private engineError;
301
- /** Oldest request the caller is still waiting on (daemon FIFO order). */
302
- private oldestOpen;
365
+ /**
366
+ * Oldest request this client still tracks, settled ones included: that is the
367
+ * request the daemon's arrival-ordered answer belongs to. `Map` iteration is
368
+ * insertion order, which is the order the requests went out.
369
+ */
370
+ private oldestTracked;
371
+ /**
372
+ * Route the reply that lands after its caller was already answered. `inferred`
373
+ * marks an attribution made by arrival order rather than by a matching id, and
374
+ * says so in the note — and hands the same distinction to the sink, which is
375
+ * the only place the caveat can travel with the body it records (R10-中2: an
376
+ * id-less result is a *guess about which request this is the answer to*, and a
377
+ * trail that files it without that note presents a guessed frame as a verified
378
+ * one). What the transport may not do is claim the sink recorded anything: it
379
+ * cannot see whether the trail accepted the frame or refused it for belonging to
380
+ * a superseded attach.
381
+ */
303
382
  private reportLateReply;
383
+ private reportSinkFailure;
304
384
  private resolve;
305
385
  private reject;
306
386
  /**
@@ -309,7 +389,17 @@ export declare class EngineJsonRpcClient {
309
389
  * longer answer it, and keep it after a timeout for the late reply.
310
390
  */
311
391
  private complete;
312
- /** Reject everything outstanding and drop every handle. */
392
+ /**
393
+ * Reject everything outstanding and drop every handle. The settled entries go
394
+ * too, and that has to be reported: each of them was answered with "the
395
+ * request stays registered" (`onDeadline`) and with {@link lateReplyRoute}'s
396
+ * promise that its reply is attributed when it lands. This map is what that
397
+ * promise was standing on, so clearing it silently leaves an agent reading the
398
+ * log for an operation that really ran, finding nothing, and unable to tell
399
+ * "this shell stopped tracking it" from "it never happened" — the difference
400
+ * that decides whether it re-performs an `act` on the user's screen (R9-中1).
401
+ * The reverse mutation is to delete this note and keep the silent clear.
402
+ */
313
403
  private teardown;
314
404
  private report;
315
405
  /**
@@ -321,6 +411,7 @@ export declare class EngineJsonRpcClient {
321
411
  private handshake;
322
412
  private verifyIdentity;
323
413
  }
414
+ export declare function truncate(text: string): string;
324
415
  /** How a transport stream is opened; injectable so tests need no socket. */
325
416
  export type EngineTransportOpener = (socketPath: string) => Duplex;
326
417
  /**