@stage-labs/metro 0.1.0-beta.243 → 0.1.0-beta.244

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.243",
3
+ "version": "0.1.0-beta.244",
4
4
  "description": "The metro command line: run your agent on this machine, relaying its chat channels and connectors to Claude Code.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.1.0-beta.243",
3
+ "version": "0.1.0-beta.244",
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",
@@ -0,0 +1,42 @@
1
+ import { chmodSync, lstatSync, readdirSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { isAbsolute, join, relative, sep } from 'node:path';
4
+ import { errMsg, log } from '@metro-labs/core/log';
5
+
6
+ const CLI_PREFIX = '.npm-global';
7
+ const OPEN_BITS = 0o077;
8
+
9
+ function entryHolding(home: string, path: string): string | null {
10
+ const rel = relative(home, path);
11
+ if (rel === '' || rel.startsWith('..') || isAbsolute(rel)) return null;
12
+ return rel.split(sep)[0] ?? null;
13
+ }
14
+
15
+ function sharedEntries(home: string, env: NodeJS.ProcessEnv = process.env): Set<string> {
16
+ const cli = env.METRO_CLI_BIN?.trim() ?? '';
17
+ const holding = cli === '' ? null : entryHolding(home, cli);
18
+ return new Set(holding === null ? [CLI_PREFIX] : [CLI_PREFIX, holding]);
19
+ }
20
+
21
+ function closeEntry(path: string): boolean {
22
+ const stat = lstatSync(path);
23
+ if (stat.isSymbolicLink() || (stat.mode & OPEN_BITS) === 0) return false;
24
+ chmodSync(path, stat.mode & 0o700);
25
+ return true;
26
+ }
27
+
28
+ export function closeMetroHome(home = homedir(), env: NodeJS.ProcessEnv = process.env): string[] {
29
+ chmodSync(home, 0o711);
30
+ const shared = sharedEntries(home, env);
31
+ const closed: string[] = [];
32
+ for (const name of readdirSync(home)) {
33
+ if (shared.has(name)) continue;
34
+ try {
35
+ if (closeEntry(join(home, name))) closed.push(name);
36
+ } catch (err) {
37
+ log.warn({ entry: name, err: errMsg(err) }, 'agent-user: could not close an entry of the metro home');
38
+ }
39
+ }
40
+ if (closed.length > 0) log.info({ closed }, 'agent-user: closed entries of the metro home so the agent user cannot read them');
41
+ return closed;
42
+ }
@@ -7,6 +7,7 @@ import { errMsg, log } from '@metro-labs/core/log';
7
7
  import { copyIntoHome } from './home-fs.js';
8
8
  import { AGENT_NAME, agentMarketplaceDir, agentUser, agentUserExpected, asUser, claudeBin, forgetAgentUser, type AgentUser } from './user.js';
9
9
  import { watchAgentView } from './view.js';
10
+ import { closeMetroHome } from './metro-home.js';
10
11
  import { mustHelper } from '../metro-user/privilege.js';
11
12
  import { stagedPluginVersion } from '../claude/plugin-install.js';
12
13
 
@@ -22,7 +23,7 @@ function run(file: string, args: string[]): void {
22
23
  }
23
24
 
24
25
  function openMetroHome(): void {
25
- chmodSync(homedir(), 0o711);
26
+ closeMetroHome();
26
27
  chmodSync(join(homedir(), '.metro'), 0o700);
27
28
  }
28
29
 
@@ -4,6 +4,7 @@ import { errMsg, log } from '@metro-labs/core/log';
4
4
  import { isRecord } from '@metro-labs/core/is-record';
5
5
  import { agentsDir } from '../agents/files.js';
6
6
  import { removeHome, writeHomeText } from './home-fs.js';
7
+ import { closeMetroHome } from './metro-home.js';
7
8
  import { agentUser, agentViewDir, type AgentUser } from './user.js';
8
9
 
9
10
  const COPIED = ['policy.json', 'claude-setup.json', 'system-prompt.md'] as const;
@@ -80,6 +81,11 @@ export function watchAgentView(everyMs = SYNC_MS): void {
80
81
  } catch (err) {
81
82
  log.warn({ err: errMsg(err) }, 'agent-user: could not refresh the Metro files the agent may read');
82
83
  }
84
+ try {
85
+ closeMetroHome();
86
+ } catch (err) {
87
+ log.warn({ err: errMsg(err) }, 'agent-user: could not close the metro home');
88
+ }
83
89
  };
84
90
  tick();
85
91
  timer = setInterval(tick, everyMs);
@@ -138,11 +138,20 @@ async function loadStations(): Promise<ScopedAccounts> {
138
138
  return { accounts, unavailable };
139
139
  }
140
140
 
141
+ const URL_SECRETS = new Set(['endpoint', 'callback']);
142
+
143
+ function withoutUrlSecrets(acc: unknown): unknown {
144
+ const rec = asRecord(acc);
145
+ if (rec === undefined) return acc;
146
+ return Object.fromEntries(Object.entries(rec).filter(([key]) => !URL_SECRETS.has(key)));
147
+ }
148
+
141
149
  export async function gatherAccounts(
142
150
  allowedAgents?: Set<string>,
143
151
  ): Promise<Record<string, unknown[]>> {
144
152
  const { accounts } = await loadStations();
145
- return allowedAgents ? scopeAccountsByAgent(accounts, allowedAgents) : accounts;
153
+ const scoped = allowedAgents ? scopeAccountsByAgent(accounts, allowedAgents) : accounts;
154
+ return Object.fromEntries(Object.entries(scoped).map(([station, rows]) => [station, rows.map(withoutUrlSecrets)]));
146
155
  }
147
156
 
148
157
  export async function gatherAccountsForAgents(
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.1.0-beta.243"
2
+ "version": "0.1.0-beta.244"
3
3
  }