@wenrwa/marketplace-cli 0.4.1 → 0.4.3
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/__tests__/bridge-autostart.test.d.ts +1 -0
- package/dist/__tests__/bridge-autostart.test.js +68 -0
- package/dist/__tests__/bridge-server.test.js +15 -0
- package/dist/bridge/autostart.d.ts +35 -0
- package/dist/bridge/autostart.js +69 -0
- package/dist/bridge/server.js +17 -0
- package/dist/commands/bridge.js +43 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const autostart_1 = require("../bridge/autostart");
|
|
4
|
+
const HOME = '/Users/testuser';
|
|
5
|
+
const makeDeps = (platform = 'darwin', hasConfig = true) => {
|
|
6
|
+
const writes = [];
|
|
7
|
+
const removed = [];
|
|
8
|
+
const runs = [];
|
|
9
|
+
return {
|
|
10
|
+
writes, removed, runs,
|
|
11
|
+
deps: {
|
|
12
|
+
platform,
|
|
13
|
+
homedir: () => HOME,
|
|
14
|
+
hasBridgeConfig: () => hasConfig,
|
|
15
|
+
mkdir: (_p) => { },
|
|
16
|
+
writeFile: (path, content, mode) => { writes.push({ path, content, mode }); },
|
|
17
|
+
removeFile: (path) => { removed.push(path); },
|
|
18
|
+
run: async (cmd, args) => { runs.push([cmd, ...args]); return { stdout: '', code: 0 }; },
|
|
19
|
+
uid: () => 501,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
describe('launchAgentPlist', () => {
|
|
24
|
+
it('runs the bridge through a login shell (PATH-safe) with KeepAlive + RunAtLoad', () => {
|
|
25
|
+
const xml = (0, autostart_1.launchAgentPlist)({ logPath: `${HOME}/.wen-market/bridge.log` });
|
|
26
|
+
expect(xml).toContain(`<string>${autostart_1.AUTOSTART_LABEL}</string>`);
|
|
27
|
+
expect(xml).toContain('<string>/bin/zsh</string>');
|
|
28
|
+
expect(xml).toContain('npx -y @wenrwa/marketplace-cli bridge');
|
|
29
|
+
expect(xml).toContain('<key>RunAtLoad</key>');
|
|
30
|
+
expect(xml).toContain('<key>KeepAlive</key>');
|
|
31
|
+
expect(xml).toContain(`${HOME}/.wen-market/bridge.log`);
|
|
32
|
+
// The Connect Token must never be baked into the plist — the bridge
|
|
33
|
+
// reads it from its 0600 config at start.
|
|
34
|
+
expect(xml).not.toContain('wm_ct_');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('installAutostart', () => {
|
|
38
|
+
it('writes the LaunchAgent and bootstraps it via launchctl', async () => {
|
|
39
|
+
const { deps, writes, runs } = makeDeps();
|
|
40
|
+
const result = await (0, autostart_1.installAutostart)(deps);
|
|
41
|
+
expect(result.action).toBe('installed');
|
|
42
|
+
expect(writes).toHaveLength(1);
|
|
43
|
+
expect(writes[0].path).toBe(`${HOME}/Library/LaunchAgents/${autostart_1.AUTOSTART_LABEL}.plist`);
|
|
44
|
+
const flat = runs.map((r) => r.join(' ')).join('\n');
|
|
45
|
+
expect(flat).toContain('launchctl');
|
|
46
|
+
expect(flat).toContain(`gui/501/${autostart_1.AUTOSTART_LABEL}`);
|
|
47
|
+
});
|
|
48
|
+
it('refuses when no Connect Token is stored yet (bridge could never start)', async () => {
|
|
49
|
+
const { deps } = makeDeps('darwin', false);
|
|
50
|
+
const result = await (0, autostart_1.installAutostart)(deps);
|
|
51
|
+
expect(result.action).toBe('no-token');
|
|
52
|
+
});
|
|
53
|
+
it('reports unsupported on non-macOS platforms', async () => {
|
|
54
|
+
const { deps, writes } = makeDeps('linux');
|
|
55
|
+
const result = await (0, autostart_1.installAutostart)(deps);
|
|
56
|
+
expect(result.action).toBe('unsupported');
|
|
57
|
+
expect(writes).toHaveLength(0);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('uninstallAutostart', () => {
|
|
61
|
+
it('boots the agent out and removes the plist', async () => {
|
|
62
|
+
const { deps, removed, runs } = makeDeps();
|
|
63
|
+
const result = await (0, autostart_1.uninstallAutostart)(deps);
|
|
64
|
+
expect(result.action).toBe('uninstalled');
|
|
65
|
+
expect(removed[0]).toBe(`${HOME}/Library/LaunchAgents/${autostart_1.AUTOSTART_LABEL}.plist`);
|
|
66
|
+
expect(runs.map((r) => r.join(' ')).join('\n')).toContain('bootout');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -125,6 +125,21 @@ describe('bridge WebSocket server', () => {
|
|
|
125
125
|
expect(bad.status).toBe(403);
|
|
126
126
|
expect(bad.headers.get('access-control-allow-origin')).toBeNull();
|
|
127
127
|
});
|
|
128
|
+
it('answers the Chrome Private-Network-Access preflight for the arena origin', async () => {
|
|
129
|
+
const res = await fetch(`http://127.0.0.1:${handle.port}/discovery`, {
|
|
130
|
+
method: 'OPTIONS',
|
|
131
|
+
headers: { origin: ORIGIN, 'Access-Control-Request-Private-Network': 'true' },
|
|
132
|
+
});
|
|
133
|
+
expect(res.status).toBe(204);
|
|
134
|
+
expect(res.headers.get('access-control-allow-origin')).toBe(ORIGIN);
|
|
135
|
+
expect(res.headers.get('access-control-allow-private-network')).toBe('true');
|
|
136
|
+
expect(res.headers.get('access-control-allow-methods')).toContain('GET');
|
|
137
|
+
const bad = await fetch(`http://127.0.0.1:${handle.port}/discovery`, {
|
|
138
|
+
method: 'OPTIONS',
|
|
139
|
+
headers: { origin: 'https://evil.example' },
|
|
140
|
+
});
|
|
141
|
+
expect(bad.status).toBe(403);
|
|
142
|
+
});
|
|
128
143
|
it('unauthenticated frames are rejected', async () => {
|
|
129
144
|
const ws = connect(handle.port);
|
|
130
145
|
await new Promise((r) => ws.on('open', r));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge autostart (bct follow-up, 2026-07-30) — `wen-market bridge install`.
|
|
3
|
+
*
|
|
4
|
+
* Turns the one-liner into one-time-EVER setup: a macOS LaunchAgent starts
|
|
5
|
+
* the bridge at login and keeps it alive, so the Terminal pane always finds
|
|
6
|
+
* it. The plist runs through a login shell so the user's PATH (nvm/homebrew
|
|
7
|
+
* node) resolves; the Connect Token is NEVER baked into the plist — the
|
|
8
|
+
* bridge reads it from its 0600 config file at start.
|
|
9
|
+
*
|
|
10
|
+
* Windows/Linux: not yet supported — the command says so instead of
|
|
11
|
+
* guessing at Task Scheduler/systemd (add per real demand).
|
|
12
|
+
*/
|
|
13
|
+
export declare const AUTOSTART_LABEL = "com.wenrwa.bridge";
|
|
14
|
+
export interface AutostartDeps {
|
|
15
|
+
platform: string;
|
|
16
|
+
homedir: () => string;
|
|
17
|
+
hasBridgeConfig: () => boolean;
|
|
18
|
+
mkdir: (path: string) => void;
|
|
19
|
+
writeFile: (path: string, content: string, mode?: number) => void;
|
|
20
|
+
removeFile: (path: string) => void;
|
|
21
|
+
run: (cmd: string, args: string[]) => Promise<{
|
|
22
|
+
stdout: string;
|
|
23
|
+
code: number;
|
|
24
|
+
}>;
|
|
25
|
+
uid: () => number;
|
|
26
|
+
}
|
|
27
|
+
export interface AutostartResult {
|
|
28
|
+
action: 'installed' | 'uninstalled' | 'unsupported' | 'no-token';
|
|
29
|
+
plistPath?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function launchAgentPlist(opts: {
|
|
32
|
+
logPath: string;
|
|
33
|
+
}): string;
|
|
34
|
+
export declare function installAutostart(deps: AutostartDeps): Promise<AutostartResult>;
|
|
35
|
+
export declare function uninstallAutostart(deps: AutostartDeps): Promise<AutostartResult>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bridge autostart (bct follow-up, 2026-07-30) — `wen-market bridge install`.
|
|
4
|
+
*
|
|
5
|
+
* Turns the one-liner into one-time-EVER setup: a macOS LaunchAgent starts
|
|
6
|
+
* the bridge at login and keeps it alive, so the Terminal pane always finds
|
|
7
|
+
* it. The plist runs through a login shell so the user's PATH (nvm/homebrew
|
|
8
|
+
* node) resolves; the Connect Token is NEVER baked into the plist — the
|
|
9
|
+
* bridge reads it from its 0600 config file at start.
|
|
10
|
+
*
|
|
11
|
+
* Windows/Linux: not yet supported — the command says so instead of
|
|
12
|
+
* guessing at Task Scheduler/systemd (add per real demand).
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AUTOSTART_LABEL = void 0;
|
|
16
|
+
exports.launchAgentPlist = launchAgentPlist;
|
|
17
|
+
exports.installAutostart = installAutostart;
|
|
18
|
+
exports.uninstallAutostart = uninstallAutostart;
|
|
19
|
+
exports.AUTOSTART_LABEL = 'com.wenrwa.bridge';
|
|
20
|
+
function launchAgentPlist(opts) {
|
|
21
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
22
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
23
|
+
<plist version="1.0">
|
|
24
|
+
<dict>
|
|
25
|
+
<key>Label</key>
|
|
26
|
+
<string>${exports.AUTOSTART_LABEL}</string>
|
|
27
|
+
<key>ProgramArguments</key>
|
|
28
|
+
<array>
|
|
29
|
+
<string>/bin/zsh</string>
|
|
30
|
+
<string>-lc</string>
|
|
31
|
+
<string>exec npx -y @wenrwa/marketplace-cli bridge</string>
|
|
32
|
+
</array>
|
|
33
|
+
<key>RunAtLoad</key>
|
|
34
|
+
<true/>
|
|
35
|
+
<key>KeepAlive</key>
|
|
36
|
+
<true/>
|
|
37
|
+
<key>StandardOutPath</key>
|
|
38
|
+
<string>${opts.logPath}</string>
|
|
39
|
+
<key>StandardErrorPath</key>
|
|
40
|
+
<string>${opts.logPath}</string>
|
|
41
|
+
</dict>
|
|
42
|
+
</plist>
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
function plistPath(deps) {
|
|
46
|
+
return `${deps.homedir()}/Library/LaunchAgents/${exports.AUTOSTART_LABEL}.plist`;
|
|
47
|
+
}
|
|
48
|
+
async function installAutostart(deps) {
|
|
49
|
+
if (deps.platform !== 'darwin')
|
|
50
|
+
return { action: 'unsupported' };
|
|
51
|
+
if (!deps.hasBridgeConfig())
|
|
52
|
+
return { action: 'no-token' };
|
|
53
|
+
const path = plistPath(deps);
|
|
54
|
+
deps.mkdir(`${deps.homedir()}/Library/LaunchAgents`);
|
|
55
|
+
deps.writeFile(path, launchAgentPlist({ logPath: `${deps.homedir()}/.wen-market/bridge.log` }), 0o644);
|
|
56
|
+
const domain = `gui/${deps.uid()}`;
|
|
57
|
+
// Re-installs: bootout first (ignore failure when not loaded), then bootstrap.
|
|
58
|
+
await deps.run('launchctl', ['bootout', `${domain}/${exports.AUTOSTART_LABEL}`]).catch(() => { });
|
|
59
|
+
await deps.run('launchctl', ['bootstrap', domain, path]);
|
|
60
|
+
return { action: 'installed', plistPath: path };
|
|
61
|
+
}
|
|
62
|
+
async function uninstallAutostart(deps) {
|
|
63
|
+
if (deps.platform !== 'darwin')
|
|
64
|
+
return { action: 'unsupported' };
|
|
65
|
+
const path = plistPath(deps);
|
|
66
|
+
await deps.run('launchctl', ['bootout', `gui/${deps.uid()}/${exports.AUTOSTART_LABEL}`]).catch(() => { });
|
|
67
|
+
deps.removeFile(path);
|
|
68
|
+
return { action: 'uninstalled', plistPath: path };
|
|
69
|
+
}
|
package/dist/bridge/server.js
CHANGED
|
@@ -63,6 +63,23 @@ function startBridgeServer(opts) {
|
|
|
63
63
|
// read it. (Same-machine cross-user curl with a forged Origin remains
|
|
64
64
|
// possible; documented as out of scope for v1 in PROTOCOL.md.)
|
|
65
65
|
const httpServer = http.createServer((req, res) => {
|
|
66
|
+
// Chrome Private-Network-Access: a public origin (app.hiveop.io) calling a
|
|
67
|
+
// local address sends an OPTIONS preflight that MUST be answered with
|
|
68
|
+
// Access-Control-Allow-Private-Network, or the browser blocks discovery.
|
|
69
|
+
if (req.method === 'OPTIONS' && req.url === '/discovery') {
|
|
70
|
+
if (req.headers.origin !== opts.allowedOrigin) {
|
|
71
|
+
res.writeHead(403).end();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
res.writeHead(204, {
|
|
75
|
+
'access-control-allow-origin': opts.allowedOrigin,
|
|
76
|
+
'access-control-allow-private-network': 'true',
|
|
77
|
+
'access-control-allow-methods': 'GET, OPTIONS',
|
|
78
|
+
'access-control-max-age': '600',
|
|
79
|
+
});
|
|
80
|
+
res.end();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
66
83
|
if (req.method === 'GET' && req.url === '/discovery') {
|
|
67
84
|
if (req.headers.origin !== opts.allowedOrigin) {
|
|
68
85
|
res.writeHead(403).end();
|
package/dist/commands/bridge.js
CHANGED
|
@@ -47,6 +47,7 @@ exports.bridgeCommand = exports.DEFAULT_BRIDGE_PORT = void 0;
|
|
|
47
47
|
*/
|
|
48
48
|
const crypto = __importStar(require("crypto"));
|
|
49
49
|
const fs = __importStar(require("fs"));
|
|
50
|
+
const os = __importStar(require("os"));
|
|
50
51
|
const child_process_1 = require("child_process");
|
|
51
52
|
const commander_1 = require("commander");
|
|
52
53
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -55,6 +56,7 @@ const server_1 = require("../bridge/server");
|
|
|
55
56
|
const realPty_1 = require("../bridge/realPty");
|
|
56
57
|
const config_1 = require("../bridge/config");
|
|
57
58
|
const mcpRegister_1 = require("../bridge/mcpRegister");
|
|
59
|
+
const autostart_1 = require("../bridge/autostart");
|
|
58
60
|
const config_2 = require("../utils/config");
|
|
59
61
|
exports.DEFAULT_BRIDGE_PORT = 8377;
|
|
60
62
|
const DEFAULT_ORIGIN = 'https://app.hiveop.io';
|
|
@@ -72,6 +74,16 @@ const execRunner = (cmd, args) => new Promise((resolve, reject) => {
|
|
|
72
74
|
resolve({ stdout: stdout ?? '', code: 0 });
|
|
73
75
|
});
|
|
74
76
|
});
|
|
77
|
+
const realAutostartDeps = () => ({
|
|
78
|
+
platform: os.platform(),
|
|
79
|
+
homedir: os.homedir,
|
|
80
|
+
hasBridgeConfig: () => (0, config_1.loadBridgeConfig)() !== null,
|
|
81
|
+
mkdir: (p) => fs.mkdirSync(p, { recursive: true }),
|
|
82
|
+
writeFile: (p, content, mode) => fs.writeFileSync(p, content, mode !== undefined ? { mode } : {}),
|
|
83
|
+
removeFile: (p) => fs.rmSync(p, { force: true }),
|
|
84
|
+
run: execRunner,
|
|
85
|
+
uid: () => process.getuid?.() ?? 501,
|
|
86
|
+
});
|
|
75
87
|
exports.bridgeCommand = new commander_1.Command('bridge')
|
|
76
88
|
.description('Run the local Terminal Bridge for the arena Terminal Pane (BYO Claude Code)')
|
|
77
89
|
.option('--token <connectToken>', 'Connect Token from arena settings (stored on first run, never logged)')
|
|
@@ -119,4 +131,35 @@ exports.bridgeCommand = new commander_1.Command('bridge')
|
|
|
119
131
|
console.log(chalk_1.default.cyan(`Terminal Bridge listening on ${handle.address}:${handle.port} (origin: ${opts.origin})`));
|
|
120
132
|
console.log(chalk_1.default.dim('Open your arena workspace and add a Terminal pane — it will connect automatically.'));
|
|
121
133
|
console.log(chalk_1.default.dim('Ctrl+C stops the bridge (terminal sessions end with it).'));
|
|
134
|
+
console.log(chalk_1.default.dim('Tip: `wen-market bridge install` makes this start automatically at login.'));
|
|
135
|
+
});
|
|
136
|
+
exports.bridgeCommand
|
|
137
|
+
.command('install')
|
|
138
|
+
.description('Start the bridge automatically at login (macOS LaunchAgent)')
|
|
139
|
+
.action(async () => {
|
|
140
|
+
const result = await (0, autostart_1.installAutostart)(realAutostartDeps());
|
|
141
|
+
if (result.action === 'installed') {
|
|
142
|
+
console.log(chalk_1.default.green(`✓ Bridge installed as a login service (${result.plistPath})`));
|
|
143
|
+
console.log(chalk_1.default.dim('It is running now and will start at every login. `wen-market bridge uninstall` removes it.'));
|
|
144
|
+
}
|
|
145
|
+
else if (result.action === 'no-token') {
|
|
146
|
+
console.error(chalk_1.default.red('No Connect Token stored yet. Run once first: wen-market bridge --token <wm_ct_…>'));
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.error(chalk_1.default.yellow('Autostart is currently macOS-only — run `wen-market bridge` manually on this platform.'));
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
exports.bridgeCommand
|
|
155
|
+
.command('uninstall')
|
|
156
|
+
.description('Remove the login autostart service')
|
|
157
|
+
.action(async () => {
|
|
158
|
+
const result = await (0, autostart_1.uninstallAutostart)(realAutostartDeps());
|
|
159
|
+
if (result.action === 'uninstalled') {
|
|
160
|
+
console.log(chalk_1.default.green('✓ Bridge autostart removed.'));
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
console.error(chalk_1.default.yellow('Autostart is currently macOS-only — nothing to remove here.'));
|
|
164
|
+
}
|
|
122
165
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wenrwa/marketplace-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "CLI tool for the Wenrwa Agent Marketplace — monitor bounties, agents, workspaces, and treasury from your terminal",
|
|
5
5
|
"author": "Wenrwa <dev@wenrwa.com>",
|
|
6
6
|
"license": "MIT",
|