refactor(shared): drop the headless task contract from tool manifests
The `task` spec (argv templates, access modes, output dialects) and the capability flags headlessTask, structuredProgress, resumable and liveWaggleDance described how a Waggle Room run drove a coding agent without its UI. Nothing runs tools headless any more, so built-in manifests, the third-party adapter loader and detection results no longer carry them. An adapter file that still declares `task` is rejected like any other unknown key.
This commit is contained in:
@@ -583,8 +583,6 @@ function withManifestMetadata(tool: DetectedTool, manifest: ToolManifest): Detec
|
||||
launchable: tool.launchable ?? manifest.launchable,
|
||||
builtin: manifest.builtin === true,
|
||||
acceptsInlinePrompt: Boolean(manifest.promptArgTemplate?.length),
|
||||
capabilities: manifest.capabilities,
|
||||
permissionModes: manifest.task?.permissionModes ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,84 +10,21 @@
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import type {
|
||||
ExternalToolAccess,
|
||||
ToolManifest,
|
||||
ToolTaskSpec,
|
||||
} from '@waggle/shared';
|
||||
import type { ToolManifest } from '@waggle/shared';
|
||||
|
||||
// No path separators — for ids and binary names (PATH lookup).
|
||||
const NAME_SAFE = /^[A-Za-z0-9._-]+$/;
|
||||
const TASK_PLACEHOLDERS = new Set([
|
||||
'prompt', 'workspacePath', 'workspaceId', 'runId', 'sessionId',
|
||||
'promptFile', 'agentId', 'timeoutSeconds', 'accessArgs',
|
||||
]);
|
||||
const GENERIC_OUTPUT_DIALECTS = new Set(['text', 'json', 'jsonl']);
|
||||
const ACCESS_MODES = new Set<ExternalToolAccess>(['read-only', 'workspace-write', 'native']);
|
||||
|
||||
function safeStr(v: unknown, max: number, re: RegExp): v is string {
|
||||
return typeof v === 'string' && v.length >= 1 && v.length <= max && re.test(v) && !v.includes('..');
|
||||
}
|
||||
|
||||
function validTemplate(value: unknown): value is string[] {
|
||||
if (!Array.isArray(value) || value.length < 1 || value.length > 40) return false;
|
||||
return value.every((part) => {
|
||||
if (typeof part !== 'string' || part.length > 512) return false;
|
||||
const placeholders = [...part.matchAll(/\{([^{}]+)\}/g)].map((match) => match[1]);
|
||||
return placeholders.every((name) => TASK_PLACEHOLDERS.has(name));
|
||||
});
|
||||
}
|
||||
|
||||
function validateTask(value: unknown): ToolTaskSpec | null {
|
||||
if (!value || typeof value !== 'object') return null;
|
||||
const task = value as Record<string, unknown>;
|
||||
const allowedKeys = new Set([
|
||||
'argvTemplate', 'resumeArgvTemplate', 'accessArgs', 'promptTransport',
|
||||
'outputDialect', 'workspaceBinding', 'permissionModes', 'resumable',
|
||||
]);
|
||||
if (Object.keys(task).some((key) => !allowedKeys.has(key))) return null;
|
||||
if (!validTemplate(task.argvTemplate)) return null;
|
||||
if (task.resumeArgvTemplate !== undefined && !validTemplate(task.resumeArgvTemplate)) return null;
|
||||
if (!['stdin', 'arg', 'temp-file'].includes(String(task.promptTransport))) return null;
|
||||
if (!GENERIC_OUTPUT_DIALECTS.has(String(task.outputDialect))) return null;
|
||||
if (!['cwd', 'flag'].includes(String(task.workspaceBinding))) return null;
|
||||
if (!Array.isArray(task.permissionModes) || task.permissionModes.length < 1 || task.permissionModes.length > 3) return null;
|
||||
const permissionModes = task.permissionModes as unknown[];
|
||||
if (!permissionModes.every((mode): mode is ExternalToolAccess => ACCESS_MODES.has(mode as ExternalToolAccess))) return null;
|
||||
if (new Set(permissionModes).size !== permissionModes.length) return null;
|
||||
if (typeof task.resumable !== 'boolean') return null;
|
||||
if (task.resumable && !task.resumeArgvTemplate) return null;
|
||||
if (!task.accessArgs || typeof task.accessArgs !== 'object' || Array.isArray(task.accessArgs)) return null;
|
||||
const rawAccess = task.accessArgs as Record<string, unknown>;
|
||||
if (Object.keys(rawAccess).some((mode) => !permissionModes.includes(mode as ExternalToolAccess))) return null;
|
||||
const accessArgs: Partial<Record<ExternalToolAccess, readonly string[]>> = {};
|
||||
for (const mode of permissionModes) {
|
||||
const args = rawAccess[mode];
|
||||
if (!Array.isArray(args) || args.length > 20) return null;
|
||||
if (!args.every((arg) => typeof arg === 'string' && arg.length <= 256 && !/[{}]/.test(arg))) return null;
|
||||
accessArgs[mode] = args as string[];
|
||||
}
|
||||
if (task.promptTransport === 'arg' && !task.argvTemplate.some((part) => part.includes('{prompt}'))) return null;
|
||||
if (task.promptTransport === 'temp-file' && !task.argvTemplate.some((part) => part.includes('{promptFile}'))) return null;
|
||||
|
||||
return {
|
||||
argvTemplate: task.argvTemplate,
|
||||
...(task.resumeArgvTemplate ? { resumeArgvTemplate: task.resumeArgvTemplate as string[] } : {}),
|
||||
accessArgs,
|
||||
promptTransport: task.promptTransport as ToolTaskSpec['promptTransport'],
|
||||
outputDialect: task.outputDialect as ToolTaskSpec['outputDialect'],
|
||||
workspaceBinding: task.workspaceBinding as ToolTaskSpec['workspaceBinding'],
|
||||
permissionModes,
|
||||
resumable: task.resumable,
|
||||
};
|
||||
}
|
||||
|
||||
/** Validate one parsed JSON object into a ToolManifest, or null if unsafe/malformed. */
|
||||
function validate(raw: unknown): ToolManifest | null {
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
const o = raw as Record<string, unknown>;
|
||||
const allowedKeys = new Set([
|
||||
'id', 'displayName', 'launchable', 'detect', 'promptArgTemplate', 'task',
|
||||
'id', 'displayName', 'launchable', 'detect', 'promptArgTemplate',
|
||||
]);
|
||||
if (Object.keys(o).some((key) => !allowedKeys.has(key))) return null;
|
||||
if (!safeStr(o.id, 64, NAME_SAFE)) return null;
|
||||
@@ -104,23 +41,12 @@ function validate(raw: unknown): ToolManifest | null {
|
||||
promptArgTemplate = o.promptArgTemplate as string[];
|
||||
}
|
||||
|
||||
const task = o.task === undefined ? undefined : validateTask(o.task);
|
||||
if (o.task !== undefined && !task) return null;
|
||||
|
||||
return {
|
||||
id: o.id as string,
|
||||
displayName: o.displayName,
|
||||
launchable: o.launchable,
|
||||
detect: { kind: 'path', binaryName: d.binaryName as string },
|
||||
...(promptArgTemplate ? { promptArgTemplate } : {}),
|
||||
capabilities: {
|
||||
interactiveLaunch: o.launchable,
|
||||
headlessTask: Boolean(task),
|
||||
structuredProgress: task?.outputDialect === 'json' || task?.outputDialect === 'jsonl',
|
||||
resumable: task?.resumable ?? false,
|
||||
liveWaggleDance: false,
|
||||
},
|
||||
...(task ? { task } : {}),
|
||||
builtin: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,18 +89,6 @@ describe('detectInstalledTools', () => {
|
||||
launchable: true,
|
||||
detect: { kind: 'path', binaryName: 'foo' },
|
||||
promptArgTemplate: ['--print', '{prompt}'],
|
||||
task: {
|
||||
argvTemplate: ['run', '{prompt}', '{accessArgs}'],
|
||||
accessArgs: {
|
||||
'read-only': ['--read-only'],
|
||||
'workspace-write': ['--workspace-write'],
|
||||
},
|
||||
promptTransport: 'arg',
|
||||
outputDialect: 'jsonl',
|
||||
workspaceBinding: 'cwd',
|
||||
permissionModes: ['read-only', 'workspace-write'],
|
||||
resumable: false,
|
||||
},
|
||||
}),
|
||||
},
|
||||
}));
|
||||
@@ -110,37 +98,18 @@ describe('detectInstalledTools', () => {
|
||||
expect(foo?.launchable).toBe(true);
|
||||
expect(foo?.builtin).toBe(false);
|
||||
expect(foo?.acceptsInlinePrompt).toBe(true);
|
||||
expect(foo?.capabilities).toEqual({
|
||||
interactiveLaunch: true,
|
||||
headlessTask: true,
|
||||
structuredProgress: true,
|
||||
resumable: false,
|
||||
liveWaggleDance: false,
|
||||
});
|
||||
expect(foo?.permissionModes).toEqual(['read-only', 'workspace-write']);
|
||||
expect(result.tools).toHaveLength(SUPPORTED_TOOLS.length + 1);
|
||||
});
|
||||
|
||||
it('carries canonical task capabilities and release status for built-ins', async () => {
|
||||
it('carries release status and launchability for built-ins', async () => {
|
||||
const result = await detectInstalledTools(makeDeps());
|
||||
const codex = result.tools.find((tool) => tool.id === 'codex');
|
||||
const cursor = result.tools.find((tool) => tool.id === 'cursor');
|
||||
const openclaw = result.tools.find((tool) => tool.id === 'openclaw');
|
||||
|
||||
expect(codex?.capabilities).toMatchObject({
|
||||
interactiveLaunch: true,
|
||||
headlessTask: true,
|
||||
structuredProgress: true,
|
||||
resumable: true,
|
||||
});
|
||||
expect(codex?.permissionModes).toEqual(['read-only', 'workspace-write', 'native']);
|
||||
expect(cursor?.capabilities).toMatchObject({
|
||||
interactiveLaunch: true,
|
||||
headlessTask: false,
|
||||
structuredProgress: false,
|
||||
resumable: false,
|
||||
});
|
||||
expect(cursor?.permissionModes).toEqual([]);
|
||||
expect(codex).toMatchObject({ launchable: true, builtin: true });
|
||||
expect(codex).not.toHaveProperty('capabilities');
|
||||
expect(codex).not.toHaveProperty('permissionModes');
|
||||
expect(cursor).toMatchObject({
|
||||
releaseStatus: 'roadmap',
|
||||
launchable: false,
|
||||
@@ -519,14 +488,12 @@ describe('extended-cohort detectors (Codex / Hermes / OpenClaw — Phase 4)', ()
|
||||
installedPath: cli,
|
||||
version: null,
|
||||
launchable: false,
|
||||
capabilities: { headlessTask: true },
|
||||
});
|
||||
expect(result.tools.find((tool) => tool.id === 'hermes-desktop')).toMatchObject({
|
||||
installed: true,
|
||||
installedPath: desktop,
|
||||
version: null,
|
||||
launchable: true,
|
||||
capabilities: { interactiveLaunch: true, headlessTask: false },
|
||||
});
|
||||
expect(versionProbes).toContain(cli);
|
||||
expect(versionProbes).not.toContain(desktop);
|
||||
|
||||
@@ -18,6 +18,16 @@ describe('loadThirdPartyManifests', () => {
|
||||
expect(out[0]).toMatchObject({ id: 'foo-cli', builtin: false, detect: { kind: 'path', binaryName: 'foo' } });
|
||||
});
|
||||
|
||||
it('rejects a headless task contract: captured Room tasks are not part of this edition', () => {
|
||||
const out = loadThirdPartyManifests(deps({
|
||||
'task.json': {
|
||||
id: 'task-cli', displayName: 'T', launchable: true, detect: { kind: 'path', binaryName: 'task' },
|
||||
task: { argvTemplate: ['run', '{prompt}'], promptTransport: 'arg' },
|
||||
},
|
||||
}));
|
||||
expect(out).toEqual([]);
|
||||
});
|
||||
|
||||
it('rejects detect.kind:candidates (code-only strategy)', () => {
|
||||
const out = loadThirdPartyManifests(deps({
|
||||
'bad.json': { id: 'bad', displayName: 'B', launchable: true, detect: { kind: 'candidates' } },
|
||||
|
||||
@@ -41,38 +41,6 @@ export type ToolDetectSpec =
|
||||
| { kind: 'path'; binaryName: string }
|
||||
| { kind: 'candidates' };
|
||||
|
||||
export type ExternalToolAccess = 'read-only' | 'workspace-write' | 'native';
|
||||
export type ToolPromptTransport = 'stdin' | 'arg' | 'temp-file';
|
||||
export type ToolOutputDialect =
|
||||
| 'claude-stream-json'
|
||||
| 'codex-jsonl'
|
||||
| 'hermes-text'
|
||||
| 'openclaw-json'
|
||||
| 'text'
|
||||
| 'json'
|
||||
| 'jsonl';
|
||||
export type ToolWorkspaceBinding = 'cwd' | 'flag' | 'managed-agent';
|
||||
|
||||
/** Declarative, shell-free contract for one capturable agent task. */
|
||||
export interface ToolTaskSpec {
|
||||
argvTemplate: readonly string[];
|
||||
resumeArgvTemplate?: readonly string[];
|
||||
accessArgs: Partial<Record<ExternalToolAccess, readonly string[]>>;
|
||||
promptTransport: ToolPromptTransport;
|
||||
outputDialect: ToolOutputDialect;
|
||||
workspaceBinding: ToolWorkspaceBinding;
|
||||
permissionModes: readonly ExternalToolAccess[];
|
||||
resumable: boolean;
|
||||
}
|
||||
|
||||
export interface ToolCapabilities {
|
||||
interactiveLaunch: boolean;
|
||||
headlessTask: boolean;
|
||||
structuredProgress: boolean;
|
||||
resumable: boolean;
|
||||
liveWaggleDance: boolean;
|
||||
}
|
||||
|
||||
export type ToolReleaseStatus = 'supported' | 'roadmap';
|
||||
|
||||
/**
|
||||
@@ -94,10 +62,6 @@ export interface ToolManifest {
|
||||
* launcher-prompt-args.ts. Captured in v1; application is a fast-follow.
|
||||
*/
|
||||
promptArgTemplate?: string[];
|
||||
/** Explicit capability split: opening an app is not the same as running a task. */
|
||||
capabilities?: ToolCapabilities;
|
||||
/** Present only when the adapter has a verified, capturable headless lane. */
|
||||
task?: ToolTaskSpec;
|
||||
/** true = first-party built-in; false/absent = loaded third-party. */
|
||||
builtin?: boolean;
|
||||
}
|
||||
@@ -112,76 +76,34 @@ export const BUILTIN_TOOL_MANIFESTS: readonly ToolManifest[] = [
|
||||
{
|
||||
id: 'claude-code', displayName: 'Claude Code', launchable: true,
|
||||
detect: { kind: 'path', binaryName: 'claude' }, builtin: true,
|
||||
capabilities: { interactiveLaunch: true, headlessTask: true, structuredProgress: true, resumable: true, liveWaggleDance: false },
|
||||
task: {
|
||||
argvTemplate: ['-p', '--safe-mode', '--disable-slash-commands', '--max-budget-usd', '1.00', '--input-format', 'text', '--output-format', 'stream-json', '--verbose', '{accessArgs}'],
|
||||
resumeArgvTemplate: ['-p', '--safe-mode', '--disable-slash-commands', '--resume', '{sessionId}', '--max-budget-usd', '1.00', '--input-format', 'text', '--output-format', 'stream-json', '--verbose', '{accessArgs}'],
|
||||
accessArgs: {
|
||||
'read-only': ['--permission-mode', 'plan'],
|
||||
'workspace-write': ['--permission-mode', 'acceptEdits'],
|
||||
native: [],
|
||||
},
|
||||
promptTransport: 'stdin', outputDialect: 'claude-stream-json', workspaceBinding: 'cwd',
|
||||
permissionModes: ['read-only', 'workspace-write', 'native'], resumable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'claude-desktop', displayName: 'Claude Desktop', launchable: true,
|
||||
detect: { kind: 'candidates' }, builtin: true,
|
||||
capabilities: { interactiveLaunch: true, headlessTask: false, structuredProgress: false, resumable: false, liveWaggleDance: false },
|
||||
},
|
||||
{
|
||||
id: 'cursor', displayName: 'Cursor', releaseStatus: 'roadmap', launchable: false,
|
||||
detect: { kind: 'candidates' }, builtin: true,
|
||||
capabilities: { interactiveLaunch: true, headlessTask: false, structuredProgress: false, resumable: false, liveWaggleDance: false },
|
||||
},
|
||||
{
|
||||
id: 'codex', displayName: 'Codex CLI', launchable: true,
|
||||
detect: { kind: 'path', binaryName: 'codex' }, builtin: true,
|
||||
capabilities: { interactiveLaunch: true, headlessTask: true, structuredProgress: true, resumable: true, liveWaggleDance: false },
|
||||
task: {
|
||||
argvTemplate: ['{accessArgs}', 'exec', '--ignore-user-config', '--ignore-rules', '--skip-git-repo-check', '--json', '--color', 'never', '-C', '{workspacePath}', '-'],
|
||||
resumeArgvTemplate: ['{accessArgs}', 'exec', '--ignore-user-config', '--ignore-rules', '--skip-git-repo-check', '--color', 'never', '-C', '{workspacePath}', 'resume', '--json', '{sessionId}', '-'],
|
||||
accessArgs: {
|
||||
'read-only': ['--ask-for-approval', 'never', '--sandbox', 'read-only'],
|
||||
'workspace-write': ['--ask-for-approval', 'never', '--sandbox', 'workspace-write'],
|
||||
native: [],
|
||||
},
|
||||
promptTransport: 'stdin', outputDialect: 'codex-jsonl', workspaceBinding: 'flag',
|
||||
permissionModes: ['read-only', 'workspace-write', 'native'], resumable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'codex-desktop', displayName: 'Codex Desktop', launchable: true,
|
||||
detect: { kind: 'candidates' }, builtin: true,
|
||||
capabilities: { interactiveLaunch: true, headlessTask: false, structuredProgress: false, resumable: false, liveWaggleDance: false },
|
||||
},
|
||||
{
|
||||
id: 'hermes', displayName: 'Hermes Agent CLI', launchable: true,
|
||||
detect: { kind: 'path', binaryName: 'hermes' }, builtin: true,
|
||||
capabilities: { interactiveLaunch: true, headlessTask: true, structuredProgress: false, resumable: true, liveWaggleDance: false },
|
||||
task: {
|
||||
argvTemplate: ['chat', '-q', '{prompt}', '-Q', '--source', 'tool', '--ignore-rules', '--max-turns', '12', '--checkpoints'],
|
||||
resumeArgvTemplate: ['chat', '--resume', '{sessionId}', '--no-restore-cwd', '-q', '{prompt}', '-Q', '--source', 'tool', '--ignore-rules', '--max-turns', '12', '--checkpoints'],
|
||||
accessArgs: { native: [] }, promptTransport: 'arg', outputDialect: 'hermes-text', workspaceBinding: 'cwd',
|
||||
permissionModes: ['native'], resumable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'hermes-desktop', displayName: 'Hermes Desktop', launchable: true,
|
||||
detect: { kind: 'candidates' }, builtin: true,
|
||||
capabilities: { interactiveLaunch: true, headlessTask: false, structuredProgress: false, resumable: false, liveWaggleDance: false },
|
||||
},
|
||||
{
|
||||
id: 'openclaw', displayName: 'OpenClaw', releaseStatus: 'roadmap', launchable: false,
|
||||
detect: { kind: 'path', binaryName: 'openclaw' }, builtin: true,
|
||||
capabilities: { interactiveLaunch: true, headlessTask: true, structuredProgress: true, resumable: true, liveWaggleDance: false },
|
||||
task: {
|
||||
argvTemplate: ['agent', '--agent', '{agentId}', '--session-key', 'agent:{agentId}:waggle:{runId}', '--message-file', '{promptFile}', '--json', '--timeout', '{timeoutSeconds}'],
|
||||
resumeArgvTemplate: ['agent', '--agent', '{agentId}', '--session-key', 'agent:{agentId}:waggle:{sessionId}', '--message-file', '{promptFile}', '--json', '--timeout', '{timeoutSeconds}'],
|
||||
accessArgs: { native: [] }, promptTransport: 'temp-file', outputDialect: 'openclaw-json', workspaceBinding: 'managed-agent',
|
||||
permissionModes: ['native'], resumable: true,
|
||||
},
|
||||
},
|
||||
] as const;
|
||||
|
||||
@@ -234,10 +156,6 @@ export interface DetectedTool {
|
||||
builtin?: boolean;
|
||||
/** True when the manifest can accept the launch prompt inline. */
|
||||
acceptsInlinePrompt?: boolean;
|
||||
/** Canonical split between opening the app and running a captured task. */
|
||||
capabilities?: ToolCapabilities;
|
||||
/** Access modes supported by the manifest's captured-task contract. */
|
||||
permissionModes?: readonly ExternalToolAccess[];
|
||||
installed: boolean;
|
||||
installedPath: string | null;
|
||||
version: string | null;
|
||||
|
||||
@@ -35,27 +35,19 @@ describe('BUILTIN_TOOL_MANIFESTS', () => {
|
||||
|
||||
expect(cli).toMatchObject({
|
||||
displayName: 'Hermes Agent CLI',
|
||||
capabilities: { interactiveLaunch: true, headlessTask: true },
|
||||
detect: { kind: 'path', binaryName: 'hermes' },
|
||||
launchable: true,
|
||||
});
|
||||
expect(desktop).toMatchObject({
|
||||
displayName: 'Hermes Desktop',
|
||||
detect: { kind: 'candidates' },
|
||||
capabilities: { interactiveLaunch: true, headlessTask: false, resumable: false },
|
||||
launchable: true,
|
||||
});
|
||||
expect(desktop.task).toBeUndefined();
|
||||
});
|
||||
it('claude-code detects by PATH binary "claude" (not its id)', () => {
|
||||
const cc = BUILTIN_TOOL_MANIFESTS.find((m) => m.id === 'claude-code')!;
|
||||
expect(cc.detect).toEqual({ kind: 'path', binaryName: 'claude' });
|
||||
});
|
||||
it('keeps resumable Codex tasks persistent instead of ephemeral', () => {
|
||||
const codex = BUILTIN_TOOL_MANIFESTS.find((m) => m.id === 'codex')!;
|
||||
|
||||
expect(codex.task?.resumable).toBe(true);
|
||||
expect(codex.task?.argvTemplate).not.toContain('--ephemeral');
|
||||
expect(codex.task?.resumeArgvTemplate).not.toContain('--ephemeral');
|
||||
expect(codex.task?.resumeArgvTemplate).toContain('{sessionId}');
|
||||
});
|
||||
});
|
||||
|
||||
describe('applyPromptArgTemplate (#5 fast-follow)', () => {
|
||||
|
||||
Reference in New Issue
Block a user