@stage-labs/metro 0.1.0-beta.144 → 0.1.0-beta.146

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.144",
3
+ "version": "0.1.0-beta.146",
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.144",
3
+ "version": "0.1.0-beta.146",
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",
@@ -24,10 +24,6 @@ export interface OwnedAgent {
24
24
 
25
25
  export type DeletedAgent = OwnedAgent;
26
26
 
27
- export interface ResetAgentKey extends OwnedAgent {
28
- key: string;
29
- }
30
-
31
27
  export function normalizeAgentName(raw: unknown): string {
32
28
  const name = typeof raw === 'string' ? raw.trim() : '';
33
29
  if (!AGENT_NAME_RE.test(name))
@@ -19,7 +19,6 @@ import {
19
19
  import {
20
20
  type AgentSummary,
21
21
  type DeletedAgent,
22
- type ResetAgentKey,
23
22
  } from './admin.js';
24
23
 
25
24
  const PREFIX = '/api/agents';
@@ -30,10 +29,6 @@ export interface AgentApiDeps extends AccountApiDeps {
30
29
  subject: string,
31
30
  id: string,
32
31
  ) => Promise<DeletedAgent>;
33
- resetKey: (
34
- subject: string,
35
- id: string,
36
- ) => Promise<ResetAgentKey>;
37
32
  gatherAccounts: (allowed: Set<string>) => Promise<{
38
33
  accounts: Record<string, unknown[]>;
39
34
  unavailable: string[];
@@ -47,14 +42,12 @@ export interface AgentApiDeps extends AccountApiDeps {
47
42
  type Routable =
48
43
  | { kind: 'collection' }
49
44
  | { kind: 'agent'; id: string }
50
- | { kind: 'key'; id: string }
51
45
  | { kind: 'accounts'; id: string; route: AccountRoute };
52
46
 
53
47
  type Target = Routable | { kind: 'unknown' } | null;
54
48
 
55
49
  function subTarget(id: string, rest: string[]): Target {
56
50
  if (rest.length === 0) return { kind: 'agent', id };
57
- if (rest.length === 1 && rest[0] === 'key') return { kind: 'key', id };
58
51
  if (rest[0] !== 'accounts') return { kind: 'unknown' };
59
52
  const route = accountRoute(rest.slice(1));
60
53
  return route === null ? { kind: 'unknown' } : { kind: 'accounts', id, route };
@@ -145,26 +138,6 @@ async function handleList(
145
138
  sendJson(req, res, 200, { ...base, accounts, unavailable });
146
139
  }
147
140
 
148
- async function handleResetKey(
149
- req: IncomingMessage,
150
- res: ServerResponse,
151
- deps: AgentApiDeps,
152
- session: ApiSession,
153
- id: string,
154
- ): Promise<void> {
155
- const reset = await deps.resetKey(session.subject, id);
156
- log.info(
157
- { agent: reset.name, id: reset.id, owner: session.subject },
158
- 'agent-api: reset agent key',
159
- );
160
- sendJson(req, res, 200, {
161
- id: reset.id,
162
- name: reset.name,
163
- reset: true,
164
- ...credentials(reset.key),
165
- });
166
- }
167
-
168
141
  async function handleDelete(
169
142
  req: IncomingMessage,
170
143
  res: ServerResponse,
@@ -190,11 +163,10 @@ async function routeAgent(
190
163
  tgt: AgentTarget,
191
164
  ): Promise<void> {
192
165
  try {
193
- if (tgt.kind !== 'collection') requireAdmin(session);
194
- if (tgt.kind === 'key') await handleResetKey(req, res, deps, session, tgt.id);
195
- else if (tgt.kind === 'agent')
166
+ if (tgt.kind === 'agent') {
167
+ requireAdmin(session);
196
168
  await handleDelete(req, res, deps, session, tgt.id);
197
- else await handleList(req, res, deps, session);
169
+ } else await handleList(req, res, deps, session);
198
170
  } catch (err) {
199
171
  apiFailure(req, res, err);
200
172
  }
@@ -203,7 +175,6 @@ async function routeAgent(
203
175
  const ALLOWED: Record<AgentTarget['kind'], string[]> = {
204
176
  collection: ['GET'],
205
177
  agent: ['DELETE'],
206
- key: ['POST'],
207
178
  };
208
179
 
209
180
  function methodAllowed(tgt: Routable, method: string | undefined): boolean {
@@ -4,14 +4,13 @@ import { ApiError } from '@metro-labs/http/api-error';
4
4
  import { isOrganizationId } from '@metro-labs/http/workos-token';
5
5
  import { ensureSecureDir, writeSecure } from '@metro-labs/core/secure-fs';
6
6
  import {
7
- AgentAdminError,
8
7
  newApiKey,
8
+ AgentAdminError,
9
9
  normalizeAgentName,
10
10
  type AgentSummary,
11
11
  type CreatedAgent,
12
12
  type DeletedAgent,
13
13
  type OwnedAgent,
14
- type ResetAgentKey,
15
14
  } from './admin.js';
16
15
  import type { AccountRef } from './account-attach.js';
17
16
  import {
@@ -24,7 +23,7 @@ import {
24
23
  type AgentFile,
25
24
  } from './files.js';
26
25
  import { newId } from '@metro-labs/core/ids';
27
- import { registerKey, rotateAgentKey, unregisterAgentKey } from './keys.js';
26
+ import { registerKey, unregisterAgentKey } from './keys.js';
28
27
  import { MOVABLE_STATIONS, type LoadedAgent } from '../stations/materialize.js';
29
28
  import type { StationName } from '@metro-labs/core/station-names';
30
29
  import { normalizeAddress } from '@metro-labs/core/address';
@@ -144,19 +143,6 @@ export async function ensureLocalAgent(dir = agentsDir()): Promise<Ensured> {
144
143
  return 'created';
145
144
  }
146
145
 
147
- export async function localResetAgentKey(
148
- subject: string,
149
- id: string,
150
- dir = agentsDir(),
151
- ): Promise<ResetAgentKey> {
152
- const stored = ownedOrThrow(subject, id, dir);
153
- const key = newApiKey();
154
- stored.file.key = key;
155
- save(stored);
156
- rotateAgentKey(id, key);
157
- return Promise.resolve({ id, name: stored.file.name, key });
158
- }
159
-
160
146
  export async function localDeleteAgent(
161
147
  subject: string,
162
148
  id: string,
@@ -30,11 +30,6 @@ export function unregisterAgentKey(agentId: string): void {
30
30
  if (id === agentId) agentIdByKeyHash.delete(hash);
31
31
  }
32
32
 
33
- export function rotateAgentKey(agentId: string, key: string | null): void {
34
- unregisterAgentKey(agentId);
35
- if (key !== null) registerKey(key, agentId);
36
- }
37
-
38
33
  export function agentIdForKey(token: string): string | undefined {
39
34
  if (token === '') return undefined;
40
35
  return agentIdByKeyHash.get(digest(token));
@@ -23,7 +23,7 @@ import { agentsDir, fileSource } from '../agents/files.js';
23
23
  import { syncPluginServers } from '../connectors/plugin-sync.js';
24
24
  import { readLocalConnectors } from '../connectors/store.js';
25
25
  import { ensureMetroPlugin } from '../claude/plugin-install.js';
26
- import { sessionRunning, stopSession, unwatchSession, watchSession } from '../claude/session.js';
26
+ import { unwatchSession, watchSession } from '../claude/session.js';
27
27
  import { tryClaudeSetup } from '../claude/setup.js';
28
28
  import { applyLocalOwner } from './local-owner.js';
29
29
  import { installBearerSessions } from '../routes/bearer.js';
@@ -34,7 +34,6 @@ import { localSessionApis } from '../routes/local-mode.js';
34
34
  import type { SessionApis } from '../routes/session-apis.js';
35
35
  import {
36
36
  agentLiveness,
37
- closeAgentSession,
38
37
  createMetroMcp,
39
38
  } from '../mcp/index.js';
40
39
  import { metroCall } from '../mcp/ctx.js';
@@ -116,12 +115,6 @@ function sessionApis(): SessionApis {
116
115
  exitCode = HOLD_EXIT;
117
116
  onShutdown();
118
117
  },
119
- closeAgentSession,
120
- restartClaudeSession: () => {
121
- if (!sessionRunning()) return false;
122
- stopSession();
123
- return true;
124
- },
125
118
  gatherAccounts: gatherAccountsForAgents,
126
119
  capabilities: accountStationCapabilities,
127
120
  liveness: agentLiveness,
@@ -9,7 +9,6 @@ import {
9
9
  deleteClaudeSkill,
10
10
  listClaudeSkills,
11
11
  readClaudeSkill,
12
- skillHomes,
13
12
  writeClaudeSkill,
14
13
  } from './skills.js';
15
14
  import {
@@ -93,10 +92,7 @@ const COLLECTIONS: Record<string, Handler> = {
93
92
  sessions: (query, dir) => ({ sessions: listClaudeSessions(projectOf(query), dir) }),
94
93
  memory: (query, dir) => listMemory(projectOf(query), dir),
95
94
  settings: (_query, dir) => ({ files: listClaudeSettings(dir) }),
96
- skills: (_query, dir) => ({
97
- skills: listClaudeSkills(dir),
98
- places: skillHomes(dir).map((home) => ({ id: home.prefix, scope: home.scope, where: home.where })),
99
- }),
95
+ skills: (_query, dir) => ({ skills: listClaudeSkills(dir) }),
100
96
  };
101
97
 
102
98
  const ITEMS: Record<string, Handler> = {
@@ -143,8 +139,7 @@ async function created(req: IncomingMessage, path: string, dir: string): Promise
143
139
  if (rest.length !== 1 || rest[0] !== 'skills') throw new ApiError('method not allowed', 405);
144
140
  const body = await readJsonBody(req, BODY_MAX);
145
141
  if (!isRecord(body) || typeof body.name !== 'string') throw new ApiError('name is required', 400);
146
- const scope = typeof body.scope === 'string' ? body.scope : undefined;
147
- return createClaudeSkill(body.name, scope, typeof body.text === 'string' ? body.text : undefined, dir);
142
+ return createClaudeSkill(body.name, typeof body.text === 'string' ? body.text : undefined, dir);
148
143
  }
149
144
 
150
145
  const ADMIN_ONLY = /^\/(login|session|version|setup)(\/|$)/;
@@ -1,24 +1,19 @@
1
1
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
2
2
  import { basename, dirname, join } from 'node:path';
3
3
  import { ApiError } from '@metro-labs/http/api-error';
4
- import { claudeDir, listClaudeProjects } from './files.js';
4
+ import { claudeDir } from './files.js';
5
5
 
6
6
  export const SKILL_MAX = 256 * 1024;
7
7
  export const SKILL_NAME_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
8
- const USER_SCOPE = 'user';
9
8
  const FILE = 'SKILL.md';
10
9
  const DEFAULT_MODE = 0o644;
11
10
  const SUMMARY_MAX = 300;
12
11
 
13
- export type SkillScope = 'user' | 'project';
14
-
15
12
  export interface ClaudeSkill {
16
13
  id: string;
17
14
  name: string;
18
15
  title: string;
19
16
  description: string;
20
- scope: SkillScope;
21
- where: string;
22
17
  path: string;
23
18
  editable: boolean;
24
19
  updatedAt: string | null;
@@ -33,55 +28,32 @@ const frontmatterField = (text: string, field: string): string => {
33
28
  return '';
34
29
  };
35
30
 
36
- function entryOf(id: string, name: string, scope: SkillScope, where: string, path: string): ClaudeSkill {
31
+ function entryOf(name: string, path: string): ClaudeSkill {
37
32
  const stat = statSync(path);
38
33
  const editable = stat.size <= SKILL_MAX;
39
34
  const text = editable ? readFileSync(path, 'utf8') : '';
40
35
  return {
41
- id,
36
+ id: `user:${name}`,
42
37
  name,
43
38
  title: frontmatterField(text, 'name') || name,
44
39
  description: frontmatterField(text, 'description'),
45
- scope,
46
- where,
47
40
  path,
48
41
  editable,
49
42
  updatedAt: stat.mtime.toISOString(),
50
43
  };
51
44
  }
52
45
 
53
- function skillsIn(root: string, prefix: string, scope: SkillScope, where: string): ClaudeSkill[] {
46
+ export const userSkillsRoot = (dir: string): string => join(dir, 'skills');
47
+
48
+ export function listClaudeSkills(dir = claudeDir()): ClaudeSkill[] {
49
+ const root = userSkillsRoot(dir);
54
50
  if (!existsSync(root)) return [];
55
51
  const out: ClaudeSkill[] = [];
56
52
  for (const entry of readdirSync(root, { withFileTypes: true })) {
57
53
  if (!entry.isDirectory() || !SKILL_NAME_RE.test(entry.name)) continue;
58
54
  const path = join(root, entry.name, FILE);
59
- if (existsSync(path)) out.push(entryOf(`${prefix}:${entry.name}`, entry.name, scope, where, path));
60
- }
61
- return out;
62
- }
63
-
64
- export const userSkillsRoot = (dir: string): string => join(dir, 'skills');
65
-
66
- export interface SkillHome {
67
- prefix: string;
68
- scope: SkillScope;
69
- where: string;
70
- root: string;
71
- }
72
-
73
- export function skillHomes(dir = claudeDir()): SkillHome[] {
74
- const homes: SkillHome[] = [{ prefix: USER_SCOPE, scope: USER_SCOPE, where: 'This machine', root: userSkillsRoot(dir) }];
75
- for (const project of listClaudeProjects(dir)) {
76
- const cwd = project.cwd;
77
- if (cwd === null || !existsSync(cwd)) continue;
78
- homes.push({ prefix: project.id, scope: 'project', where: cwd, root: join(cwd, '.claude', 'skills') });
55
+ if (existsSync(path)) out.push(entryOf(entry.name, path));
79
56
  }
80
- return homes;
81
- }
82
-
83
- export function listClaudeSkills(dir = claudeDir()): ClaudeSkill[] {
84
- const out = skillHomes(dir).flatMap((home) => skillsIn(home.root, home.prefix, home.scope, home.where));
85
57
  return out.sort((a, b) => (b.updatedAt ?? '').localeCompare(a.updatedAt ?? '') || a.name.localeCompare(b.name));
86
58
  }
87
59
 
@@ -120,29 +92,21 @@ export function writeClaudeSkill(
120
92
  if (seenAt !== undefined && seenAt !== skill.updatedAt)
121
93
  throw new ApiError('that skill changed on disk since you opened it; reload it before saving', 409);
122
94
  writeAtomic(skill.path, text);
123
- return entryOf(skill.id, skill.name, skill.scope, skill.where, skill.path);
95
+ return entryOf(skill.name, skill.path);
124
96
  }
125
97
 
126
98
  export const skillTemplate = (name: string): string =>
127
99
  ['---', `name: ${name}`, 'description: what this skill does, and when Claude should reach for it', '---', '', `# ${name}`, '', 'Write the instructions here.', ''].join('\n');
128
100
 
129
- export function createClaudeSkill(
130
- name: string,
131
- scope: string | undefined,
132
- text: string | undefined,
133
- dir = claudeDir(),
134
- ): ClaudeSkill {
101
+ export function createClaudeSkill(name: string, text: string | undefined, dir = claudeDir()): ClaudeSkill {
135
102
  if (typeof name !== 'string' || !SKILL_NAME_RE.test(name))
136
103
  throw new ApiError('a skill name is lowercase letters, digits and dashes, up to 64 characters', 400);
137
- const prefix = scope === undefined || scope === '' ? USER_SCOPE : scope;
138
- const home = skillHomes(dir).find((h) => h.prefix === prefix);
139
- if (home === undefined) throw new ApiError('no such place to keep a skill', 404);
140
- const path = join(home.root, name, FILE);
104
+ const path = join(userSkillsRoot(dir), name, FILE);
141
105
  if (existsSync(path)) throw new ApiError('a skill by that name already lives there', 409);
142
106
  const body = text === undefined || text.trim() === '' ? skillTemplate(name) : text;
143
107
  assertText(body);
144
108
  writeAtomic(path, body);
145
- return entryOf(`${home.prefix}:${name}`, name, home.scope, home.where, path);
109
+ return entryOf(name, path);
146
110
  }
147
111
 
148
112
  export function deleteClaudeSkill(id: string, dir = claudeDir()): string {
@@ -138,11 +138,6 @@ export function agentLiveness(): Map<string, AgentLiveness> {
138
138
  return activeRegistry?.liveness() ?? new Map<string, AgentLiveness>();
139
139
  }
140
140
 
141
- export async function closeAgentSession(agentId: string): Promise<boolean> {
142
- const scopeKey = sessionScopeKey({ kind: 'agent', agentId });
143
- return (await activeRegistry?.closeScope(scopeKey)) ?? false;
144
- }
145
-
146
141
  export async function createMetroMcp(): Promise<{
147
142
  httpHandler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
148
143
  startInbound: () => void;
@@ -43,7 +43,6 @@ import {
43
43
  localListAgents,
44
44
  localOwnedAgentOrThrow,
45
45
  localOwner,
46
- localResetAgentKey,
47
46
  readLocalAgentFile,
48
47
  } from '../agents/file-admin.js';
49
48
  import { readModelConfig } from '../gateway/model-config.js';
@@ -54,8 +53,6 @@ export interface LocalModeDeps {
54
53
  reloadAgents: () => Promise<void>;
55
54
  restart: () => void;
56
55
  stop: () => void;
57
- closeAgentSession: (id: string) => Promise<boolean>;
58
- restartClaudeSession: () => boolean;
59
56
  gatherAccounts: AgentApiDeps['gatherAccounts'];
60
57
  capabilities: AgentApiDeps['capabilities'];
61
58
  liveness: AgentApiDeps['liveness'];
@@ -89,13 +86,6 @@ function agentApi(deps: LocalModeDeps): AgentApiDeps {
89
86
  attachSessions: attachSessions(deps),
90
87
  listAgents: localListAgents,
91
88
  deleteAgent: localDeleteAgent,
92
- resetKey: async (subject, id) => {
93
- const reset = await localResetAgentKey(subject, id);
94
- const closed = await deps.closeAgentSession(id);
95
- const restarted = deps.restartClaudeSession();
96
- log.info({ agent: reset.name, id, sessionClosed: closed, claudeRestarted: restarted }, 'local: key rotated');
97
- return reset;
98
- },
99
89
  gatherAccounts: deps.gatherAccounts,
100
90
  capabilities: deps.capabilities,
101
91
  attachable: ATTACHABLE.filter((s) => s !== 'webhook'),
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.1.0-beta.144"
2
+ "version": "0.1.0-beta.146"
3
3
  }