@stage-labs/metro 0.1.0-beta.265 → 0.1.0-beta.266
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 +1 -1
- package/runtime/marketplace/plugin/.claude-plugin/plugin.json +1 -1
- package/runtime/runtime.json +1 -1
- package/runtime/sdk-runner/runner.json +1 -1
- package/runtime/sdk-runner/src/inbox.ts +4 -4
- package/runtime/sdk-runner/src/input-queue.ts +7 -2
- package/runtime/sdk-runner/src/runner.ts +6 -4
- package/runtime/sdk-runner/src/session-watch.ts +31 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.266",
|
|
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",
|
package/runtime/runtime.json
CHANGED
|
@@ -17,7 +17,7 @@ export interface Unanswered {
|
|
|
17
17
|
|
|
18
18
|
interface InboxHooks {
|
|
19
19
|
ready?(): boolean;
|
|
20
|
-
dispatch?(): void;
|
|
20
|
+
dispatch?(message: SDKUserMessage): void;
|
|
21
21
|
queue?(count: number, oldest: number | null): void;
|
|
22
22
|
input?: InputWatch;
|
|
23
23
|
}
|
|
@@ -94,8 +94,8 @@ export class Inbox implements AsyncIterable<SDKUserMessage> {
|
|
|
94
94
|
|
|
95
95
|
cancel(uuids: readonly string[]): void {
|
|
96
96
|
const ephemeral = uuids.filter((uuid) => this.kindOf(uuid) !== 'chat');
|
|
97
|
-
this.queue.cancel(new Set(ephemeral));
|
|
98
|
-
this.timing.finish(
|
|
97
|
+
const removed = this.queue.cancel(new Set(ephemeral));
|
|
98
|
+
this.timing.finish(removed, true);
|
|
99
99
|
this.notify();
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -121,7 +121,7 @@ export class Inbox implements AsyncIterable<SDKUserMessage> {
|
|
|
121
121
|
while (!this.closed) {
|
|
122
122
|
const next = (this.hooks.ready?.() ?? true) ? this.queue.take() : undefined;
|
|
123
123
|
if (next !== undefined) {
|
|
124
|
-
this.hooks.dispatch?.();
|
|
124
|
+
this.hooks.dispatch?.(next);
|
|
125
125
|
if (next.uuid !== undefined) this.timing.dispatch(next.uuid);
|
|
126
126
|
this.notify();
|
|
127
127
|
yield next;
|
|
@@ -55,11 +55,16 @@ export class InputQueue {
|
|
|
55
55
|
return undefined;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
cancel(uuids: ReadonlySet<string>):
|
|
58
|
+
cancel(uuids: ReadonlySet<string>): string[] {
|
|
59
|
+
const removed: string[] = [];
|
|
59
60
|
for (let index = this.items.length - 1; index >= 0; index -= 1) {
|
|
60
61
|
const uuid = this.items[index]?.message.uuid;
|
|
61
|
-
if (uuid !== undefined && uuids.has(uuid))
|
|
62
|
+
if (uuid !== undefined && uuids.has(uuid)) {
|
|
63
|
+
this.remove(index);
|
|
64
|
+
removed.push(uuid);
|
|
65
|
+
}
|
|
62
66
|
}
|
|
67
|
+
return removed;
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
private remove(index: number): Queued | undefined {
|
|
@@ -19,7 +19,9 @@ const MODEL_PINS: ReadonlySet<string> = new Set(['ANTHROPIC_MODEL', 'CLAUDE_CODE
|
|
|
19
19
|
|
|
20
20
|
export function runnerEnv(env: NodeJS.ProcessEnv): Record<string, string | undefined> {
|
|
21
21
|
const unpinned = Object.fromEntries(Object.entries(env).filter(([name]) => !MODEL_PINS.has(name)));
|
|
22
|
-
|
|
22
|
+
const terminals = new Set((env.CLAUDE_CODE_TERMINAL_MCP_TOOLS ?? '').split(',').map((name) => name.trim()).filter(Boolean));
|
|
23
|
+
terminals.add('mcp__metro__send');
|
|
24
|
+
return { [STARTUP_WAIT]: '0', ...unpinned, DISABLE_AUTOUPDATER: '1', CLAUDE_CODE_TERMINAL_MCP_TOOLS: [...terminals].join(',') };
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export type ModelSettings = Parameters<Query['applyFlagSettings']>[0];
|
|
@@ -97,8 +99,8 @@ export class Runner {
|
|
|
97
99
|
constructor(private readonly parts: RunnerParts) {
|
|
98
100
|
this.watch = new SessionWatch(parts.readOnly);
|
|
99
101
|
this.inbox = new Inbox((unanswered) => { this.keep(unanswered); }, {
|
|
100
|
-
ready: () => this.watch.
|
|
101
|
-
dispatch: () => { this.watch.dispatched(); },
|
|
102
|
+
ready: () => this.watch.admitting,
|
|
103
|
+
dispatch: (message) => { this.watch.dispatched(message.uuid); },
|
|
102
104
|
input: (input) => { parts.activity?.input(input); },
|
|
103
105
|
queue: (count, oldest) => { parts.activity?.pending(count, oldest); },
|
|
104
106
|
});
|
|
@@ -241,7 +243,7 @@ export class Runner {
|
|
|
241
243
|
}
|
|
242
244
|
|
|
243
245
|
private maybeCompact(resuming = false): void {
|
|
244
|
-
const busy = this.compactAsked !== null || !this.watch.safe || (!resuming && (this.calls.live || this.inbox.pending > 0));
|
|
246
|
+
const busy = this.compactAsked !== null || !this.watch.safe || !this.watch.admitting || (!resuming && (this.calls.live || this.inbox.pending > 0));
|
|
245
247
|
if (!compactDue({ context: this.watch.context, floor: this.compactFloor, limit: this.parts.compactAt ?? COMPACT_AT, busy })) return;
|
|
246
248
|
this.compactAsked = this.inbox.compact();
|
|
247
249
|
log.info({ context: this.watch.context, resuming }, 'sdk-runner: compacting at a safe idle boundary');
|
|
@@ -22,7 +22,6 @@ function toolResultIds(message: unknown): string[] {
|
|
|
22
22
|
return message.content.filter(isRecord).filter((b) => b.type === 'tool_result' && typeof b.tool_use_id === 'string').map((b) => String(b.tool_use_id));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
export class SessionWatch {
|
|
27
26
|
private readonly writes = new Set<string>();
|
|
28
27
|
private readonly idle: (() => void)[] = [];
|
|
@@ -30,6 +29,8 @@ export class SessionWatch {
|
|
|
30
29
|
private compactingNow = false;
|
|
31
30
|
private busy = false;
|
|
32
31
|
private sessionStateSeen = false;
|
|
32
|
+
private requiresAction = false;
|
|
33
|
+
private awaitingInput: string | null = null;
|
|
33
34
|
private lastContext = 0;
|
|
34
35
|
private streamUsage: Record<string, unknown> = {};
|
|
35
36
|
|
|
@@ -49,11 +50,20 @@ export class SessionWatch {
|
|
|
49
50
|
|
|
50
51
|
get safe(): boolean { return !this.busy && !this.writing && !this.compacting; }
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
get admitting(): boolean {
|
|
54
|
+
return this.awaitingInput === null && !this.requiresAction && !this.compacting;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
dispatched(uuid?: string): void {
|
|
58
|
+
this.busy = true;
|
|
59
|
+
this.awaitingInput = uuid ?? null;
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
restoreContext(context: number): void { this.lastContext = context; }
|
|
54
63
|
|
|
55
64
|
observe(m: Record<string, unknown>): void {
|
|
56
65
|
if (m.parent_tool_use_id !== null && m.parent_tool_use_id !== undefined) return;
|
|
66
|
+
this.acknowledge(m);
|
|
57
67
|
this.lifecycle(m);
|
|
58
68
|
if (m.type === 'assistant' && isRecord(m.message)) this.assistant(m.message);
|
|
59
69
|
else if (m.type === 'stream_event' && isRecord(m.event)) this.stream(m.event);
|
|
@@ -68,6 +78,11 @@ export class SessionWatch {
|
|
|
68
78
|
return this.compactingNow ? new Promise((resolve) => { this.compacted.push(resolve); }) : Promise.resolve();
|
|
69
79
|
}
|
|
70
80
|
|
|
81
|
+
private acknowledge(m: Record<string, unknown>): void {
|
|
82
|
+
if (this.awaitingInput === null) return;
|
|
83
|
+
if (startedCommand(m) === this.awaitingInput || uuidsOf(m)?.includes(this.awaitingInput)) this.awaitingInput = null;
|
|
84
|
+
}
|
|
85
|
+
|
|
71
86
|
private lifecycle(m: Record<string, unknown>): void {
|
|
72
87
|
if (m.type === 'system') this.system(m);
|
|
73
88
|
else if (m.type === 'result' && !this.sessionStateSeen) {
|
|
@@ -78,11 +93,8 @@ export class SessionWatch {
|
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
private system(m: Record<string, unknown>): void {
|
|
81
|
-
if (m.subtype === 'session_state_changed')
|
|
82
|
-
|
|
83
|
-
if (m.state === 'running' || m.state === 'requires_action') this.busy = true;
|
|
84
|
-
else if (m.state === 'idle') { this.busy = false; this.settle(); }
|
|
85
|
-
} else if (m.subtype === 'status') this.setCompacting(m.status === 'compacting');
|
|
96
|
+
if (m.subtype === 'session_state_changed') this.sessionState(m.state);
|
|
97
|
+
else if (m.subtype === 'status') this.setCompacting(m.status === 'compacting');
|
|
86
98
|
else if (m.subtype === 'compact_boundary') {
|
|
87
99
|
this.setCompacting(false);
|
|
88
100
|
this.lastContext = 0;
|
|
@@ -90,6 +102,18 @@ export class SessionWatch {
|
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
104
|
|
|
105
|
+
private sessionState(state: unknown): void {
|
|
106
|
+
this.sessionStateSeen = true;
|
|
107
|
+
if (state === 'running' || state === 'requires_action') {
|
|
108
|
+
this.busy = true;
|
|
109
|
+
this.requiresAction = state === 'requires_action';
|
|
110
|
+
} else if (state === 'idle') {
|
|
111
|
+
this.busy = false;
|
|
112
|
+
this.requiresAction = false;
|
|
113
|
+
this.settle();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
93
117
|
private stream(event: Record<string, unknown>): void {
|
|
94
118
|
if (event.type === 'message_start' && isRecord(event.message)) {
|
|
95
119
|
this.streamUsage = isRecord(event.message.usage) ? event.message.usage : {};
|