refactor: launch external tools without Room credentials or hook settings
A Launcher launch still opens the tool in the active workspace's folder, tracks its process, streams observed output and stops it. What it no longer does: - set WAGGLE_SIGNAL_EMIT, WAGGLE_SIDECAR_URL, HIVE_MIND_DATA_DIR or the Room identity variables (WAGGLE_RUN_ID, WAGGLE_ROOM_ID, WAGGLE_DANCE_TEAM_ID, WAGGLE_SENDER_ID, WAGGLE_RUN_TOKEN). Only the removed coding-agent hooks and the WaggleDance CLI read them. The external-process allowlist now admits WAGGLE_WORKSPACE_ID alone; - issue a run credential. Run tokens existed for Room workers (the dance CLI and OpenClaw's model calls), so the registry's credential store, the middleware's run-token bearer on /v1/chat/completions and the proxy's per-run model scope go. While an agent run with a model is active, the proxy still serves only the session bearer. The run record that a launch creates in the agent-run registry stays: it backs cancel from the Room canvas, which this change does not remove.
This commit is contained in:
@@ -58,7 +58,6 @@ vi.mock('@waggle/agent', async (importOriginal) => {
|
||||
import { buildLocalServer } from '../src/local/index.js';
|
||||
import { injectWithAuth } from './test-utils.js';
|
||||
import { detectInstalledTools, launchTool } from '@waggle/agent';
|
||||
import { loopbackSidecarUrl } from '../src/local/routes/tools.js';
|
||||
import { resolveWorkspaceExecutionRoot } from '../src/local/workspace-execution-root.js';
|
||||
|
||||
function createTmpDir(prefix: string): string {
|
||||
@@ -131,10 +130,6 @@ describe('POST /api/tools/launch', () => {
|
||||
id: 'claude-code',
|
||||
installedPath: '/server-detected/claude-code',
|
||||
workspaceId,
|
||||
dataDir: tmpDir,
|
||||
runId: expect.stringMatching(/^run_/),
|
||||
roomId: expect.stringMatching(/^room_/),
|
||||
runToken: expect.any(String),
|
||||
}),
|
||||
);
|
||||
expect(body.roomId).toMatch(/^room_/);
|
||||
@@ -168,18 +163,15 @@ describe('POST /api/tools/launch', () => {
|
||||
},
|
||||
});
|
||||
const body = response.json() as { runId: string };
|
||||
const call = vi.mocked(launchTool).mock.calls[0][0] as { runToken?: string };
|
||||
expect(server.agentRunRegistry.authenticateCredential(call.runToken ?? '')?.id).toBe(body.runId);
|
||||
|
||||
for (const listener of exitListeners) listener(0);
|
||||
|
||||
expect(server.agentRunRegistry.get(body.runId)).toMatchObject({
|
||||
status: 'completed', result: { summary: 'Interactive tool process exited successfully' },
|
||||
});
|
||||
expect(server.agentRunRegistry.authenticateCredential(call.runToken ?? '')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('passes signalEmit:true so a dock launch lights the bus (#1)', async () => {
|
||||
it('passes no hook, Room or data-directory settings to the launched tool', async () => {
|
||||
vi.mocked(launchTool).mockClear();
|
||||
const res = await injectWithAuth(server, {
|
||||
method: 'POST',
|
||||
@@ -188,15 +180,9 @@ describe('POST /api/tools/launch', () => {
|
||||
payload: { id: 'claude-code', installedPath: '/usr/local/bin/claude' },
|
||||
});
|
||||
expect(res.statusCode).toBe(202);
|
||||
expect(launchTool).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ signalEmit: true }),
|
||||
);
|
||||
// sidecarUrl is derived from the loopback host fastify.inject used,
|
||||
// so it is either undefined (non-loopback authority) or an
|
||||
// http://<loopback> string — never a non-loopback origin.
|
||||
const callArg = vi.mocked(launchTool).mock.calls[0][0] as { sidecarUrl?: string };
|
||||
if (callArg.sidecarUrl !== undefined) {
|
||||
expect(callArg.sidecarUrl).toMatch(/^http:\/\/(127\.0\.0\.1|localhost|\[::1\]|::1)(:\d+)?$/i);
|
||||
const callArg = vi.mocked(launchTool).mock.calls[0][0] as unknown as Record<string, unknown>;
|
||||
for (const removed of ['signalEmit', 'sidecarUrl', 'dataDir', 'runId', 'roomId', 'runToken']) {
|
||||
expect(callArg, removed).not.toHaveProperty(removed);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -929,31 +915,6 @@ describe('POST /api/tools/hooks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ── loopbackSidecarUrl helper (#1) ──────────────────────────────────
|
||||
|
||||
describe('loopbackSidecarUrl', () => {
|
||||
it.each([
|
||||
['127.0.0.1:3333', 'http://127.0.0.1:3333'],
|
||||
['localhost', 'http://localhost'],
|
||||
['localhost:8080', 'http://localhost:8080'],
|
||||
['[::1]:3000', 'http://[::1]:3000'],
|
||||
])('maps loopback host %s → %s', (host, expected) => {
|
||||
expect(loopbackSidecarUrl(host)).toBe(expected);
|
||||
});
|
||||
|
||||
it.each([
|
||||
undefined,
|
||||
'',
|
||||
'evil.com',
|
||||
'10.0.0.5:3333',
|
||||
'example.com:80',
|
||||
'169.254.1.1',
|
||||
'::1', // bare (unbracketed) IPv6 → rejected; would be a malformed URL
|
||||
])('returns undefined for non-loopback / missing host %s', (host) => {
|
||||
expect(loopbackSidecarUrl(host as string | undefined)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ── persistence + reconcile across sidecar restart (#2) ─────────────
|
||||
|
||||
describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
@@ -989,7 +950,6 @@ describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
});
|
||||
expect(response.statusCode).toBe(202);
|
||||
const { runId } = response.json() as { runId: string };
|
||||
const runToken = (vi.mocked(launchTool).mock.calls[0][0] as { runToken: string }).runToken;
|
||||
expect(fs.existsSync(path.join(tmpDir, 'launched-processes.json'))).toBe(true);
|
||||
await server1.close();
|
||||
server1 = undefined;
|
||||
@@ -997,7 +957,6 @@ describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
server2 = await buildLocalServer({ dataDir: tmpDir });
|
||||
await server2.ready();
|
||||
expect(server2.agentRunRegistry.get(runId)?.status).toBe('running');
|
||||
expect(server2.agentRunRegistry.authenticateCredential(runToken)).toBeUndefined();
|
||||
expect(server2.toolProcessTracker?.list().some((process) => process.pid === child.pid)).toBe(true);
|
||||
|
||||
const launchCallsBeforeCompeting = vi.mocked(launchTool).mock.calls.length;
|
||||
@@ -1146,7 +1105,6 @@ describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
payload: { id: 'claude-code', installedPath: '/x', workspaceId },
|
||||
});
|
||||
const { runId } = response.json() as { runId: string };
|
||||
const runToken = (vi.mocked(launchTool).mock.calls[0][0] as { runToken: string }).runToken;
|
||||
await server1.close();
|
||||
server1 = undefined;
|
||||
await stopChild(child);
|
||||
@@ -1157,7 +1115,6 @@ describe('POST /api/tools/launch — persistence + reconcile', () => {
|
||||
status: 'interrupted',
|
||||
result: { error: 'External process was not running when Waggle restarted' },
|
||||
});
|
||||
expect(server2.agentRunRegistry.authenticateCredential(runToken)).toBeUndefined();
|
||||
expect(server2.toolProcessTracker?.list().some((process) => process.pid === child.pid)).toBe(false);
|
||||
} finally {
|
||||
if (server1) await server1.close();
|
||||
|
||||
Reference in New Issue
Block a user