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