@agentsignalnet/claude-plugin 0.2.84 → 0.2.85

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agentsignal",
3
3
  "displayName": "AgentSignal",
4
- "version": "0.2.84",
4
+ "version": "0.2.85",
5
5
  "description": "Page a human from inside Claude Code, or become an addressable agent that other agents can reach.",
6
6
  "author": {
7
7
  "name": "Data Group AI",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentsignalnet/claude-plugin",
3
- "version": "0.2.84",
3
+ "version": "0.2.85",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -338,6 +338,17 @@ async function pollOne(identity) {
338
338
  options: m.options,
339
339
  created_at: m.created_at,
340
340
  urgency: urgency(m.priority),
341
+ /*
342
+ WHEN IT LANDED HERE, which is the only clock that can be trusted for
343
+ the measurement this exists for.
344
+
345
+ `created_at` is the SERVER's clock and this is the machine's, so the
346
+ difference between them carries whatever skew there is between the two
347
+ and is a rough figure at best. spooled_at -> surfaced_at is measured by
348
+ one clock against itself, and that is the leg nobody could see: the gap
349
+ between a message being available locally and a session acting on it.
350
+ */
351
+ spooled_at: new Date().toISOString(),
341
352
  }));
342
353
 
343
354
  if (arrived.length === 0) return;
@@ -37,7 +37,9 @@
37
37
  * one file would make the two race, and the direction it loses in is the one
38
38
  * that matters -- a dropped interrupt looks exactly like no message.
39
39
  */
40
- import { readFileSync, writeFileSync, renameSync, mkdirSync, existsSync } from 'node:fs';
40
+ import {
41
+ readFileSync, writeFileSync, renameSync, mkdirSync, existsSync, appendFileSync,
42
+ } from 'node:fs';
41
43
  import { dirname, join } from 'node:path';
42
44
  import { fileURLToPath } from 'node:url';
43
45
  import { stateDirs, writeDir } from './state.mjs';
@@ -89,6 +91,59 @@ function waiting(urgency) {
89
91
  .sort((a, b) => (a.created_at < b.created_at ? -1 : 1));
90
92
  }
91
93
 
94
+ /**
95
+ * HOW LONG A MESSAGE WAITED, written down so the answer can be measured.
96
+ *
97
+ * The question this exists for is which part of the delivery path is worth
98
+ * optimising, and the honest answer was that nobody knew. From outside, the
99
+ * visible costs are the API round trip (~170ms) and the daemon poll (0-2s) --
100
+ * which is what everybody reaches for first. The part nobody could see is this
101
+ * one: a message already ON this machine, in the spool, waiting for the session
102
+ * to reach a point where a hook can run.
103
+ *
104
+ * TWO LEGS, and only one of them is trustworthy:
105
+ *
106
+ * sent -> spooled crosses the server's clock and this machine's, so it
107
+ * carries whatever skew is between them. Indicative only.
108
+ * spooled -> surfaced one clock measured against itself. This is the number.
109
+ *
110
+ * RECORDED AT BOTH SURFACING SITES, because they are different questions. The
111
+ * `check` path runs between tool calls and answers "how stale was it when the
112
+ * model next looked". The `watch` path is the interrupt and answers "how long
113
+ * did an urgent message take to stop somebody" -- which is the one the product
114
+ * actually promises, and it carries its own 1s poll on top.
115
+ *
116
+ * JSONL, appended, ids and timings only -- never a title or a body. A latency
117
+ * log that quietly accumulates the contents of everybody's messages is a
118
+ * different kind of file, and this must not become one.
119
+ *
120
+ * Best effort. Measuring must never be why a message failed to surface.
121
+ */
122
+ function recordLatency(messages, surfacedAt) {
123
+ try {
124
+ const lines = messages.map((m) => {
125
+ const spooled = m.spooled_at ? Date.parse(m.spooled_at) : null;
126
+ const created = m.created_at ? Date.parse(m.created_at) : null;
127
+ return JSON.stringify({
128
+ at: new Date(surfacedAt).toISOString(),
129
+ delivery_id: m.delivery_id,
130
+ mode,
131
+ urgency: m.urgency,
132
+ // Null rather than absent for a message that predates the stamp, so a
133
+ // reader can tell "not measured" from "measured as zero".
134
+ spool_to_surface_ms: spooled === null ? null : surfacedAt - spooled,
135
+ sent_to_spool_ms: spooled === null || created === null ? null : spooled - created,
136
+ sent_to_surface_ms: created === null ? null : surfacedAt - created,
137
+ });
138
+ });
139
+ if (lines.length) {
140
+ appendFileSync(join(writeDir(), 'latency.jsonl'), lines.join('\n') + '\n', { mode: 0o600 });
141
+ }
142
+ } catch {
143
+ /* the measurement is not the job */
144
+ }
145
+ }
146
+
92
147
  function markHandled(messages) {
93
148
  const handled = readJson(handledPath, { delivery_ids: [] });
94
149
  const ids = new Set(handled.delivery_ids ?? []);
@@ -138,6 +193,9 @@ if (mode === 'check' || mode === 'finish') {
138
193
  // call is a hook somebody turns off.
139
194
  if (messages.length === 0) process.exit(0);
140
195
 
196
+ // BEFORE markHandled, so the stamp is the moment the model is told rather
197
+ // than the moment bookkeeping finished.
198
+ recordLatency(messages, Date.now());
141
199
  markHandled(messages);
142
200
 
143
201
  if (mode === 'check') {
@@ -177,6 +235,7 @@ if (mode === 'watch') {
177
235
  const poll = () => {
178
236
  const messages = waiting('interrupt');
179
237
  if (messages.length > 0) {
238
+ recordLatency(messages, Date.now());
180
239
  markHandled(messages);
181
240
  console.log(
182
241
  render(