@stage-labs/metro 0.1.0-beta.267 → 0.1.0-beta.269

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stage-labs/metro",
3
- "version": "0.1.0-beta.267",
3
+ "version": "0.1.0-beta.269",
4
4
  "description": "The metro command line: run your agent on this machine, relaying its chat channels and connectors to Claude Code.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.1.0-beta.267",
3
+ "version": "0.1.0-beta.269",
4
4
  "description": "Metro for Claude Code, installed by the metro daemon on this machine: every connector the agent holds as its own MCP server relayed through the daemon, the orchestrator-only guard on the main thread, and the standing rules loaded at each session start. No vendor credential ever sits in a config file.",
5
5
  "author": {
6
6
  "name": "Bonustrack",
@@ -188,6 +188,7 @@ export class SharedCalls {
188
188
  private status(route: CallRoute, action: Action, status: SpeechStatus): void {
189
189
  if (this.terminal(action.status) || (status === 'started' && action.status === 'started')) return;
190
190
  action.status = status;
191
+ log.info({ actionId: action.actionId, status, at: Date.now() }, 'sdk-call: speech action');
191
192
  this.bridge?.notify({ type: 'speech', route, sourceId: action.sourceId, actionId: action.actionId, status });
192
193
  }
193
194
  }
@@ -12,17 +12,24 @@ const SPEECH_MS = 60_000;
12
12
  type Speech = Pick<Utterance, 'attach' | 'say' | 'end' | 'abort'>;
13
13
  type MakeSpeech = (failed: (reason: string) => void) => Speech;
14
14
 
15
- interface Playing {
15
+ interface Queued {
16
16
  action: SharedSpeechAction;
17
+ queuedAt: number;
18
+ }
19
+
20
+ interface Playing extends Queued {
17
21
  utterance: Speech | null;
18
22
  timer: ReturnType<typeof setTimeout>;
19
23
  synthesized: boolean;
20
24
  started: boolean;
25
+ synthesisStartedAt: number;
26
+ firstAudioAt: number | null;
27
+ markedFrameResolvedAt: number | null;
21
28
  }
22
29
 
23
30
  export class SpeechQueue {
24
31
  private readonly player: Player;
25
- private readonly waiting: SharedSpeechAction[] = [];
32
+ private readonly waiting: Queued[] = [];
26
33
  private current: Playing | null = null;
27
34
  private live = false;
28
35
  private closed = false;
@@ -45,6 +52,7 @@ export class SpeechQueue {
45
52
  const current = this.current;
46
53
  if (current === null || current.started) return;
47
54
  current.started = true;
55
+ current.markedFrameResolvedAt = Date.now();
48
56
  current.action.status('started');
49
57
  });
50
58
  this.player.whenIdle(() => {
@@ -66,7 +74,7 @@ export class SpeechQueue {
66
74
  enqueue(action: SharedSpeechAction): boolean {
67
75
  if (this.closed || action.text.trim() === '' || action.text.length > MAX_TEXT) return false;
68
76
  if (this.waiting.length + (this.current === null ? 0 : 1) >= MAX_QUEUED || !action.isValid()) return false;
69
- this.waiting.push(action);
77
+ this.waiting.push({ action, queuedAt: Date.now() });
70
78
  queueMicrotask(() => {
71
79
  this.next();
72
80
  });
@@ -83,7 +91,10 @@ export class SpeechQueue {
83
91
  cancel(): void {
84
92
  const waiting = this.waiting.splice(0);
85
93
  this.settle('interrupted');
86
- for (const action of waiting) action.status('interrupted');
94
+ for (const queued of waiting) {
95
+ this.report(queued, 'interrupted');
96
+ queued.action.status('interrupted');
97
+ }
87
98
  }
88
99
 
89
100
  close(): void {
@@ -96,15 +107,18 @@ export class SpeechQueue {
96
107
 
97
108
  private next(): void {
98
109
  if (!this.live || this.closed || this.current !== null) return;
99
- const action = this.waiting.shift();
100
- if (action === undefined) return;
110
+ const queued = this.waiting.shift();
111
+ if (queued === undefined) return;
112
+ const { action } = queued;
101
113
  if (!action.isValid()) {
114
+ this.report(queued, 'failed');
102
115
  action.status('failed');
103
116
  this.next();
104
117
  return;
105
118
  }
106
119
  const playing: Playing = {
107
- action, utterance: null, synthesized: false, started: false,
120
+ ...queued, utterance: null, synthesized: false, started: false,
121
+ synthesisStartedAt: Date.now(), firstAudioAt: null, markedFrameResolvedAt: null,
108
122
  timer: setTimeout(() => {
109
123
  if (this.current === playing) this.fail('speech timed out');
110
124
  }, this.timeoutMs),
@@ -121,7 +135,9 @@ export class SpeechQueue {
121
135
  playing.utterance = utterance;
122
136
  utterance.attach({
123
137
  audio: (pcm, chars) => {
124
- if (this.valid(playing)) this.player.push(pcm, chars);
138
+ if (this.current === playing && pcm.length > 0) playing.firstAudioAt ??= Date.now();
139
+ if (!this.valid(playing)) return;
140
+ this.player.push(pcm, chars);
125
141
  },
126
142
  done: () => {
127
143
  if (!this.valid(playing)) return;
@@ -157,6 +173,16 @@ export class SpeechQueue {
157
173
  this.onFailed();
158
174
  }
159
175
 
176
+ private report(queued: Queued, status: SpeechStatus, playing?: Playing): void {
177
+ log.info({
178
+ actionId: queued.action.actionId, status, queuedAt: queued.queuedAt,
179
+ synthesisStartedAt: playing?.synthesisStartedAt ?? null,
180
+ firstAudioAt: playing?.firstAudioAt ?? null,
181
+ markedFrameResolvedAt: playing?.markedFrameResolvedAt ?? null,
182
+ settledAt: Date.now(),
183
+ }, 'voice: speech timing');
184
+ }
185
+
160
186
  private settle(status: SpeechStatus): void {
161
187
  const current = this.current;
162
188
  this.current = null;
@@ -164,6 +190,7 @@ export class SpeechQueue {
164
190
  if (current !== null) {
165
191
  clearTimeout(current.timer);
166
192
  current.utterance?.abort();
193
+ this.report(current, status, current);
167
194
  current.action.status(status);
168
195
  }
169
196
  queueMicrotask(() => {
@@ -2,7 +2,7 @@ import type { Station, Verb } from '@metro-labs/core/stations/types';
2
2
  import { PROFILE_FIELDS, type ProfileField } from '@metro-labs/core/stations/profile';
3
3
  import { tokenFiles } from './token-store.js';
4
4
  import { nameFiles } from './names.js';
5
- import { historyFiles } from './history-state.js';
5
+ import { historyFiles } from './history-files.js';
6
6
 
7
7
  export const whatsappStation: Station = {
8
8
  name: 'whatsapp',
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.1.0-beta.267"
2
+ "version": "0.1.0-beta.269"
3
3
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.0-beta.267",
2
+ "version": "0.1.0-beta.269",
3
3
  "dependencies": {
4
4
  "@anthropic-ai/claude-agent-sdk": "0.3.287",
5
5
  "@modelcontextprotocol/sdk": "^1.29.0",
@@ -63,6 +63,6 @@ export class InputTiming {
63
63
 
64
64
  private note(input: RunnerInput): void {
65
65
  this.changed({ ...input });
66
- log.info({ input: input.id, kind: input.kind, state: input.state, queueAgeMs: (input.consumedAt ?? Date.now()) - input.acceptedAt }, 'sdk-runner: input lifecycle');
66
+ log.info({ input: input.id, kind: input.kind, state: input.state, acceptedAt: input.acceptedAt, dispatchedAt: input.dispatchedAt, consumedAt: input.consumedAt, firstOutputAt: input.firstOutputAt, completedAt: input.completedAt, queueAgeMs: (input.consumedAt ?? Date.now()) - input.acceptedAt }, 'sdk-runner: input lifecycle');
67
67
  }
68
68
  }
@@ -3,6 +3,7 @@ import type { CallRoute, CallSource } from '@metro-labs/core/call';
3
3
  export const FRONT_RULES = `You are the orchestrator of this agent's persistent Agent SDK session. Typed chat, live call words (<call> blocks), and background worker reports share this conversation.
4
4
  - Be fast. When you can answer a chat message at once, make the reaction and the answer one response of parallel tool calls (react, then send), with no typing signal. Use typing only when the answer will take a while.
5
5
  - Stay light: talk, decide and delegate. Real work goes to background workers (Agent tool, subagent_type "worker", run_in_background: true); keep answering while they run, and relay what they report.
6
+ - At the next safe tool boundary, answer pending live-call inputs before starting unrelated delegation or processing worker reports. Give a short, direct answer when possible; do not generate a long task prompt before replying to the caller. Never interrupt active writes or approvals, invent filler, or promise work is done before it is.
6
7
  - Plain assistant text is never spoken. Reply to a live <call> with mcp__metro__send using its exact line, text, and speech:{callId,generation,sourceId}. This sends speech only, not a chat post. Keep it short. Never paste a spoken reply or transcript into chat unless the owner explicitly requests a chat post.
7
8
  - Ordinary typed chat and worker results are never automatically spoken. For an explicit typed owner request to speak, use only that channel message's call_id, call_generation and call_source_id with its exact line as send speech:{callId:call_id,generation:call_generation,sourceId:call_source_id}. Without all three authorized live-call values, do not speak or guess a target. Do not reuse an earlier sourceId for a new reply.
8
9
  - A call ending invalidates its speech targets. Keep the chat session and background work running. Nothing is posted about a hangup unless requested. Speech status notifications are status only, never a request to speak.