@stage-labs/metro 0.1.0-beta.106 → 0.1.0-beta.107
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/dist/claude.js
CHANGED
|
@@ -6,10 +6,12 @@ import { localAgents, pickLocalAgent } from './local.js';
|
|
|
6
6
|
import { PROVIDER_FLAGS } from './provider-flags.js';
|
|
7
7
|
import { localPort, localUrl } from './runtime.js';
|
|
8
8
|
const CHANNEL_FLAGS = ['--dangerously-load-development-channels', 'server:metro'];
|
|
9
|
+
const PERMISSION_FLAGS = ['--permission-mode', 'auto'];
|
|
9
10
|
const KEY_HEADER = 'x-metro-key';
|
|
10
11
|
const PROBE_MS = 3_000;
|
|
11
12
|
export const claudeArgs = (extra, mcpConfig) => [
|
|
12
13
|
...CHANNEL_FLAGS,
|
|
14
|
+
...PERMISSION_FLAGS,
|
|
13
15
|
...(mcpConfig === undefined ? [] : ['--mcp-config', mcpConfig]),
|
|
14
16
|
...extra,
|
|
15
17
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stage-labs/metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.107",
|
|
4
4
|
"description": "The metro command line. Sign in once per machine, then hand your MCP connector list to Claude Code without the credentials touching disk, argv or shell history.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.107",
|
|
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, the standing rules loaded at each session start, and a refresh skill for when the daemon could not keep the server list current. No vendor credential ever sits in a config file.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bonustrack",
|
|
@@ -4,6 +4,7 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { errMsg, log } from '@metro-labs/core/log';
|
|
5
5
|
import { isRecord } from '@metro-labs/core/is-record';
|
|
6
6
|
import { readJson, writeJson } from '@metro-labs/core/secure-fs';
|
|
7
|
+
import { METRO_VERSION } from '@metro-labs/core/version';
|
|
7
8
|
import { agentsDir, listAgentFiles } from '../agents/files.js';
|
|
8
9
|
import { notReady, readModelConfig } from '../gateway/model-config.js';
|
|
9
10
|
import { claudeAccount, claudeInstalled } from './login.js';
|
|
@@ -26,6 +27,7 @@ export interface SessionDeps {
|
|
|
26
27
|
agents?: string;
|
|
27
28
|
signedIn?: () => boolean;
|
|
28
29
|
now?: () => number;
|
|
30
|
+
version?: string;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export interface SessionStatus {
|
|
@@ -48,13 +50,24 @@ const memory: Memory = { lastStartedAt: null, lastError: null, strikes: 0, pause
|
|
|
48
50
|
|
|
49
51
|
const statePath = (agents: string): string => join(agents, STATE_FILE);
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
function readState(agents: string): Record<string, unknown> {
|
|
52
54
|
const raw = readJson<unknown>(statePath(agents), null);
|
|
53
|
-
return
|
|
55
|
+
return isRecord(raw) ? raw : {};
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
const writeState = (agents: string, patch: Record<string, unknown>): void => {
|
|
59
|
+
writeJson(statePath(agents), { ...readState(agents), ...patch });
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const autostartEnabled = (agents = agentsDir()): boolean => readState(agents).autostart !== false;
|
|
63
|
+
|
|
56
64
|
export function setAutostart(enabled: boolean, agents = agentsDir()): void {
|
|
57
|
-
|
|
65
|
+
writeState(agents, { autostart: enabled });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function startedVersion(agents = agentsDir()): string | null {
|
|
69
|
+
const version = readState(agents).version;
|
|
70
|
+
return typeof version === 'string' ? version : null;
|
|
58
71
|
}
|
|
59
72
|
|
|
60
73
|
function tmuxOk(tmux: string, args: string[]): boolean {
|
|
@@ -108,6 +121,18 @@ function confirmChannels(tmux: string, until: number): void {
|
|
|
108
121
|
setTimeout(tick, CONFIRM_POLL_MS).unref();
|
|
109
122
|
}
|
|
110
123
|
|
|
124
|
+
function recordStart(deps: SessionDeps, tmux: string, now: number, run: { error?: Error; status: number | null; stderr: string }): void {
|
|
125
|
+
memory.lastStartedAt = now;
|
|
126
|
+
if (run.error !== undefined || run.status !== 0) {
|
|
127
|
+
memory.lastError = run.error === undefined ? `tmux new-session exited ${String(run.status)}: ${run.stderr.trim()}` : errMsg(run.error);
|
|
128
|
+
log.warn({ err: memory.lastError }, 'claude-session: tmux could not start');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
memory.lastError = null;
|
|
132
|
+
writeState(deps.agents ?? agentsDir(), { version: deps.version ?? METRO_VERSION });
|
|
133
|
+
confirmChannels(tmux, now + CONFIRM_WAIT_MS);
|
|
134
|
+
}
|
|
135
|
+
|
|
111
136
|
export function startSession(deps: SessionDeps = {}): SessionStatus {
|
|
112
137
|
const tmux = deps.tmux ?? 'tmux';
|
|
113
138
|
const home = deps.home ?? homedir();
|
|
@@ -115,15 +140,8 @@ export function startSession(deps: SessionDeps = {}): SessionStatus {
|
|
|
115
140
|
const trusted = trustFolder(home);
|
|
116
141
|
const [command = 'metro', ...args] = metroCommand(deps);
|
|
117
142
|
const run = spawnSync(tmux, ['new-session', '-d', '-s', SESSION_NAME, '-c', home, '-x', '200', '-y', '50', command, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], cwd: home });
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
memory.lastError = run.error === undefined ? `tmux new-session exited ${String(run.status)}: ${run.stderr.trim()}` : errMsg(run.error);
|
|
121
|
-
log.warn({ err: memory.lastError }, 'claude-session: tmux could not start');
|
|
122
|
-
} else {
|
|
123
|
-
memory.lastError = null;
|
|
124
|
-
log.info({ home, trusted, command: [command, ...args].join(' ') }, 'claude-session: started Claude Code in tmux');
|
|
125
|
-
confirmChannels(tmux, now + CONFIRM_WAIT_MS);
|
|
126
|
-
}
|
|
143
|
+
recordStart(deps, tmux, now, run);
|
|
144
|
+
if (memory.lastError === null) log.info({ home, trusted, command: [command, ...args].join(' ') }, 'claude-session: started Claude Code in tmux');
|
|
127
145
|
return sessionStatus(deps);
|
|
128
146
|
}
|
|
129
147
|
|
|
@@ -153,15 +171,46 @@ function strike(now: number): boolean {
|
|
|
153
171
|
return true;
|
|
154
172
|
}
|
|
155
173
|
|
|
156
|
-
export
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (sessionRunning(deps.tmux ?? 'tmux')) return 'running';
|
|
174
|
+
export type Ensured = 'started' | 'restarted' | 'running' | 'blocked' | 'off' | 'paused';
|
|
175
|
+
|
|
176
|
+
function holdsBack(deps: SessionDeps, now: number): Ensured | null {
|
|
160
177
|
if (now < memory.pausedUntil) return 'paused';
|
|
161
178
|
if (sessionBlocked(deps) !== null) return 'blocked';
|
|
162
|
-
|
|
179
|
+
return strike(now) ? 'paused' : null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
interface Resolved {
|
|
183
|
+
now: number;
|
|
184
|
+
agents: string;
|
|
185
|
+
version: string;
|
|
186
|
+
tmux: string;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const resolved = (deps: SessionDeps): Resolved => ({
|
|
190
|
+
now: (deps.now ?? Date.now)(),
|
|
191
|
+
agents: deps.agents ?? agentsDir(),
|
|
192
|
+
version: deps.version ?? METRO_VERSION,
|
|
193
|
+
tmux: deps.tmux ?? 'tmux',
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
function situation(r: Resolved): 'running' | 'stale' | 'absent' {
|
|
197
|
+
if (!sessionRunning(r.tmux)) return 'absent';
|
|
198
|
+
return startedVersion(r.agents) === r.version ? 'running' : 'stale';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function ensureSession(deps: SessionDeps = {}): Ensured {
|
|
202
|
+
const r = resolved(deps);
|
|
203
|
+
if (!autostartEnabled(r.agents)) return 'off';
|
|
204
|
+
const found = situation(r);
|
|
205
|
+
if (found === 'running') return 'running';
|
|
206
|
+
const held = holdsBack(deps, r.now);
|
|
207
|
+
if (held !== null) return held;
|
|
208
|
+
if (found === 'stale') {
|
|
209
|
+
log.info({ was: startedVersion(r.agents), now: r.version }, 'claude-session: restarting the session an older metro started, so the new plugin and flags load');
|
|
210
|
+
stopSession(deps);
|
|
211
|
+
}
|
|
163
212
|
startSession(deps);
|
|
164
|
-
return 'started';
|
|
213
|
+
return found === 'stale' ? 'restarted' : 'started';
|
|
165
214
|
}
|
|
166
215
|
|
|
167
216
|
let watcher: ReturnType<typeof setInterval> | null = null;
|
|
@@ -171,7 +220,7 @@ export function watchSession(deps: SessionDeps = {}, everyMs = WATCH_MS): void {
|
|
|
171
220
|
const tick = (): void => {
|
|
172
221
|
try {
|
|
173
222
|
const outcome = ensureSession(deps);
|
|
174
|
-
if (outcome === 'started') log.info('claude-session:
|
|
223
|
+
if (outcome === 'started' || outcome === 'restarted') log.info({ outcome }, 'claude-session: Claude Code is up');
|
|
175
224
|
} catch (err) {
|
|
176
225
|
log.warn({ err: errMsg(err) }, 'claude-session: check failed');
|
|
177
226
|
}
|
package/runtime/runtime.json
CHANGED