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:
shumeiko.it
2026-11-01 11:12:31 +01:00
parent 80db300485
commit 25f95c584b
12 changed files with 65 additions and 665 deletions

View File

@@ -27,12 +27,7 @@ const BASE_ENV_ALLOWLIST = new Set([
/** Explicit Waggle runtime metadata constructed by trusted launch code. */
const WAGGLE_ENV_ALLOWLIST = new Set([
'WAGGLE_WORKSPACE_ID', 'WAGGLE_WORKSPACE_PATH',
'WAGGLE_RUN_ID', 'WAGGLE_ROOM_ID', 'WAGGLE_SENDER_ID',
'WAGGLE_DANCE_TEAM_ID', 'WAGGLE_DANCE_URL', 'WAGGLE_RUN_TOKEN',
'WAGGLE_CLI_NODE_PATH', 'WAGGLE_CLI_ENTRY',
'WAGGLE_SIGNAL_EMIT', 'WAGGLE_SIDECAR_URL',
'HIVE_MIND_DATA_DIR', 'NO_COLOR',
'WAGGLE_WORKSPACE_ID',
]);
/**

View File

@@ -195,11 +195,7 @@ export interface LaunchOptions {
* detection is the source of truth for where the tool lives.
*/
installedPath: string;
/**
* Workspace id to inject as `WAGGLE_WORKSPACE_ID` in the spawned
* tool's environment. Hooks pick this up via workspace-resolver
* for context-aware capture.
*/
/** Workspace id to inject as `WAGGLE_WORKSPACE_ID` in the spawned tool's environment. */
workspaceId?: string;
/**
* Working directory for the spawned process. Defaults to the
@@ -208,29 +204,6 @@ export interface LaunchOptions {
cwd?: string;
/** Extra arguments to pass to the binary. */
args?: string[];
/**
* When true (default), inject `WAGGLE_SIGNAL_EMIT='1'` so the launched
* tool's hive-mind hook emits discovery signals back to the sidecar
* bus. This is what turns the detect→launch→hook→bus→UI pipeline on:
* without it a dock-launched tool saves memory but stays silent on the
* bus it was built to feed. Set `false` for a silent launch.
*/
signalEmit?: boolean;
/**
* Sidecar base URL injected as `WAGGLE_SIDECAR_URL` so the launched
* tool's hook posts signals to the right loopback port (the emitter's
* fallback is `http://127.0.0.1:3333`). Omit to let the hook use that
* default. Callers (the /launch route) derive this from the loopback
* address the UI itself reached.
*/
sidecarUrl?: string;
/** Canonical Waggle/Hive Mind data root for launched hook processes. */
dataDir?: string;
/** Canonical collaboration identity for authenticated hook signals. */
runId?: string;
roomId?: string;
/** Ephemeral credential accepted only by WaggleDance transport routes. */
runToken?: string;
/**
* When true, launch in OBSERVED mode (piped stdio) so stdout/stderr can be
* streamed to the dock. The process is tethered to the sidecar (dies on
@@ -300,24 +273,6 @@ export function launchTool(opts: LaunchOptions): LaunchResult {
if (opts.workspaceId) {
waggleEnv.WAGGLE_WORKSPACE_ID = opts.workspaceId;
}
// Self-enabling: light the SignalBus this pipeline was built to feed.
// Opt out with signalEmit:false for a silent launch.
if (opts.signalEmit !== false) {
waggleEnv.WAGGLE_SIGNAL_EMIT = '1';
}
if (opts.sidecarUrl) {
waggleEnv.WAGGLE_SIDECAR_URL = opts.sidecarUrl;
}
if (opts.dataDir) {
waggleEnv.HIVE_MIND_DATA_DIR = opts.dataDir;
}
if (opts.runId && opts.roomId && opts.runToken) {
waggleEnv.WAGGLE_RUN_ID = opts.runId;
waggleEnv.WAGGLE_ROOM_ID = opts.roomId;
waggleEnv.WAGGLE_DANCE_TEAM_ID = `room::${opts.roomId}`;
waggleEnv.WAGGLE_SENDER_ID = `run::${opts.runId}`;
waggleEnv.WAGGLE_RUN_TOKEN = opts.runToken;
}
const env = buildExternalProcessEnv(deps.baseEnv, waggleEnv, deps.platform);
// Observed mode: piped-stdio spawn that surfaces a live output handle.
// Tethered to the sidecar (not unref'd) and tracked in-memory only.

View File

@@ -69,9 +69,6 @@ describe('launchTool', () => {
id: 'claude-code',
installedPath: 'C:\\tools\\claude.exe',
workspaceId: 'ws-isolated',
runId: 'run-1',
roomId: 'room-1',
runToken: 'narrow-room-token',
deps: {
platform: 'win32',
baseEnv: {
@@ -108,13 +105,12 @@ describe('launchTool', () => {
HERMES_HOME: 'D:\\Hermes Data',
TERM: 'xterm-256color',
WAGGLE_WORKSPACE_ID: 'ws-isolated',
WAGGLE_RUN_TOKEN: 'narrow-room-token',
});
for (const name of [
'ANTHROPIC_API_KEY', 'OPENAI_API_KEY', 'OPENROUTER_API_KEY',
'GEMINI_API_KEY', 'STRIPE_SECRET_KEY', 'AWS_SECRET_ACCESS_KEY',
'DATABASE_URL', 'SSH_AUTH_SOCK', 'GIT_ASKPASS', 'HTTPS_PROXY',
'NODE_OPTIONS',
'NODE_OPTIONS', 'WAGGLE_RUN_TOKEN',
]) {
expect(calls[0].options.env?.[name], name).toBeUndefined();
}
@@ -237,69 +233,22 @@ describe('launchTool', () => {
});
});
// ── launchTool — self-enabling signal env (#1) ──────────────────────
// A dock launch should light the SignalBus it was built to feed: the
// launched tool's hive-mind hook only emits when WAGGLE_SIGNAL_EMIT is
// truthy, and it posts to WAGGLE_SIDECAR_URL. Without these the whole
// detect→launch→hook→bus→UI pipeline stays dark.
// ── launchTool — no hook or Room env ─────────────────────────────────
// The coding-agent hooks and Waggle Room are not part of the community
// edition, so a launch sets only the workspace id.
describe('launchTool — self-enabling signal env', () => {
it('injects WAGGLE_SIGNAL_EMIT=1 by default (lights the bus)', () => {
const { calls, spawnDetached } = captureSpawn();
launchTool({
id: 'claude-code',
installedPath: '/usr/local/bin/claude',
deps: { spawnDetached },
});
expect(calls[0].options.env?.WAGGLE_SIGNAL_EMIT).toBe('1');
});
it('omits WAGGLE_SIGNAL_EMIT when signalEmit:false (silent launch opt-out)', () => {
const { calls, spawnDetached } = captureSpawn();
launchTool({
id: 'claude-code',
installedPath: '/usr/local/bin/claude',
signalEmit: false,
deps: { spawnDetached },
});
expect(calls[0].options.env?.WAGGLE_SIGNAL_EMIT).toBeUndefined();
});
it('injects WAGGLE_SIDECAR_URL when provided', () => {
const { calls, spawnDetached } = captureSpawn();
launchTool({
id: 'claude-code',
installedPath: '/usr/local/bin/claude',
sidecarUrl: 'http://127.0.0.1:7777',
deps: { spawnDetached },
});
expect(calls[0].options.env?.WAGGLE_SIDECAR_URL).toBe('http://127.0.0.1:7777');
});
it('does not inject WAGGLE_SIDECAR_URL when absent', () => {
const { calls, spawnDetached } = captureSpawn();
launchTool({
id: 'claude-code',
installedPath: '/usr/local/bin/claude',
deps: { spawnDetached },
});
expect(calls[0].options.env?.WAGGLE_SIDECAR_URL).toBeUndefined();
});
it('injects signal env alongside WAGGLE_WORKSPACE_ID', () => {
describe('launchTool env', () => {
it('sets only WAGGLE_WORKSPACE_ID among Waggle variables', () => {
const { calls, spawnDetached } = captureSpawn();
launchTool({
id: 'claude-code',
installedPath: '/usr/local/bin/claude',
workspaceId: 'ws-1',
sidecarUrl: 'http://127.0.0.1:3333',
deps: { spawnDetached },
});
expect(calls[0].options.env).toMatchObject({
WAGGLE_WORKSPACE_ID: 'ws-1',
WAGGLE_SIGNAL_EMIT: '1',
WAGGLE_SIDECAR_URL: 'http://127.0.0.1:3333',
deps: { spawnDetached, baseEnv: { PATH: '/usr/bin' } },
});
const waggleVars = Object.keys(calls[0].options.env ?? {})
.filter((name) => name.startsWith('WAGGLE_') || name.startsWith('HIVE_MIND_'));
expect(waggleVars).toEqual(['WAGGLE_WORKSPACE_ID']);
});
});
@@ -403,36 +352,6 @@ describe('launchTool observe mode', () => {
});
});
describe('launchTool collaboration env', () => {
it('injects the canonical Waggle data root', () => {
const { calls, spawnDetached } = captureSpawn();
launchTool({
id: 'claude-code',
installedPath: '/usr/local/bin/claude',
dataDir: '/waggle-data',
deps: { spawnDetached },
});
expect(calls[0].options.env?.HIVE_MIND_DATA_DIR).toBe('/waggle-data');
});
it('injects only the narrow Room credential and canonical run identity', () => {
const { calls, spawnDetached } = captureSpawn();
launchTool({
id: 'claude-code', installedPath: '/usr/local/bin/claude',
runId: 'run-1', roomId: 'room-1', runToken: 'secret-run-token',
deps: { spawnDetached },
});
expect(calls[0].options.env).toMatchObject({
WAGGLE_RUN_ID: 'run-1',
WAGGLE_ROOM_ID: 'room-1',
WAGGLE_DANCE_TEAM_ID: 'room::room-1',
WAGGLE_SENDER_ID: 'run::run-1',
WAGGLE_RUN_TOKEN: 'secret-run-token',
});
expect(calls[0].options.env?.WAGGLE_SESSION_TOKEN).toBeUndefined();
});
});
describe('resolveSpawnInvocation', () => {
it('rejects unrecognized Windows batch shims instead of invoking cmd.exe', () => {
expect(() => resolveSpawnInvocation(