@stage-labs/metro 0.1.0-beta.144 → 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.
|
|
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.
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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.
|
|
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
|
|
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(
|
|
109
|
+
return entryOf(name, path);
|
|
146
110
|
}
|
|
147
111
|
|
|
148
112
|
export function deleteClaudeSkill(id: string, dir = claudeDir()): string {
|
package/runtime/runtime.json
CHANGED