@stage-labs/metro 0.1.0-beta.143 → 0.1.0-beta.145

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.143",
3
+ "version": "0.1.0-beta.145",
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.143",
3
+ "version": "0.1.0-beta.145",
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",
@@ -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 {
@@ -9,6 +9,7 @@ import { errMsg, log } from '@metro-labs/core/log';
9
9
  export interface RelayApiDeps {
10
10
  target: (connectorId: string, force: boolean) => Promise<RelayTarget>;
11
11
  identify: (req: IncomingMessage) => AgentIdentity | null;
12
+ signedOut: (connectorId: string) => void;
12
13
  }
13
14
 
14
15
  const ID_PATH_RE = /^\/relay\/([A-Za-z0-9][A-Za-z0-9_-]{10})$/;
@@ -242,6 +243,7 @@ async function relayExchange(
242
243
  }
243
244
  if (out.kind === 'signin') {
244
245
  noteHealth(connectorId, false, 'the sign-in has expired, connect it again');
246
+ deps.signedOut(connectorId);
245
247
  signinAnswer(res, connectorId);
246
248
  return;
247
249
  }
@@ -201,10 +201,19 @@ export async function localReconnectConnector(
201
201
  return replace(dir, { ...row, config: { ...row.config, auth, verified, oauth: true } });
202
202
  }
203
203
 
204
+ const signedOut = (row: LocalConnectorRow): LocalConnectorRow => ({ ...row, config: { ...row.config, auth: { kind: 'none' }, oauth: true } });
205
+
204
206
  export async function localDisconnectConnector(subject: string, id: string, dir = agentsDir()): Promise<Connector> {
205
207
  const row = rowOrThrow(subject, id, dir);
206
208
  if (row.config.auth.kind !== 'oauth') throw new ConnectorError('that connector is not signed in', 400);
207
- return Promise.resolve(replace(dir, { ...row, config: { ...row.config, auth: { kind: 'none' }, oauth: true } }));
209
+ return Promise.resolve(replace(dir, signedOut(row)));
210
+ }
211
+
212
+ export function localMarkSignedOut(id: string, dir = agentsDir()): void {
213
+ const row = readLocalConnectors(dir).find((r) => r.id === id);
214
+ if (row?.config.auth.kind !== 'oauth') return;
215
+ log.info({ id, name: row.name }, 'local relay: the vendor refused the token after a refresh; the connector is signed out');
216
+ replace(dir, signedOut(row));
208
217
  }
209
218
 
210
219
  async function freshAuth(auth: ConnectorAuth, resource: string): Promise<ConnectorAuth> {
@@ -27,6 +27,7 @@ import {
27
27
  localRelayTarget,
28
28
  localRenameConnector,
29
29
  localVerifyConnector,
30
+ localMarkSignedOut,
30
31
  localConnectorTools,
31
32
  } from '../connectors/store.js';
32
33
  import {
@@ -142,6 +143,9 @@ const relayApi: RelayApiDeps = {
142
143
  const who = authenticate(req);
143
144
  return who?.kind === 'agent' ? { subject: 'agent-key', agentId: who.agentId } : null;
144
145
  },
146
+ signedOut: (id) => {
147
+ localMarkSignedOut(id);
148
+ },
145
149
  };
146
150
 
147
151
 
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.1.0-beta.143"
2
+ "version": "0.1.0-beta.145"
3
3
  }