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' } },
|
||||
|
||||
Reference in New Issue
Block a user