@kolisachint/hoocode-agent 0.4.61 → 0.4.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/cli/args.d.ts +5 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +22 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-frontmatter.d.ts +22 -0
- package/dist/core/agent-frontmatter.d.ts.map +1 -1
- package/dist/core/agent-frontmatter.js +60 -0
- package/dist/core/agent-frontmatter.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/dispatch-evaluator.d.ts +3 -2
- package/dist/core/dispatch-evaluator.d.ts.map +1 -1
- package/dist/core/dispatch-evaluator.js +9 -5
- package/dist/core/dispatch-evaluator.js.map +1 -1
- package/dist/core/sdk.d.ts +5 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +1 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +2 -0
- package/dist/core/settings-defaults.d.ts.map +1 -1
- package/dist/core/settings-defaults.js +2 -0
- package/dist/core/settings-defaults.js.map +1 -1
- package/dist/core/settings-manager.d.ts +6 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +10 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/subagent-depth.d.ts +67 -0
- package/dist/core/subagent-depth.d.ts.map +1 -0
- package/dist/core/subagent-depth.js +112 -0
- package/dist/core/subagent-depth.js.map +1 -0
- package/dist/core/subagent-pool-instance.d.ts.map +1 -1
- package/dist/core/subagent-pool-instance.js +11 -1
- package/dist/core/subagent-pool-instance.js.map +1 -1
- package/dist/core/subagent-pool.d.ts.map +1 -1
- package/dist/core/subagent-pool.js +47 -17
- package/dist/core/subagent-pool.js.map +1 -1
- package/dist/core/subagent-result.d.ts +31 -0
- package/dist/core/subagent-result.d.ts.map +1 -1
- package/dist/core/subagent-result.js +31 -0
- package/dist/core/subagent-result.js.map +1 -1
- package/dist/core/task-store.d.ts +11 -1
- package/dist/core/task-store.d.ts.map +1 -1
- package/dist/core/task-store.js +3 -0
- package/dist/core/task-store.js.map +1 -1
- package/dist/core/token-budget.d.ts.map +1 -1
- package/dist/core/token-budget.js +6 -9
- package/dist/core/token-budget.js.map +1 -1
- package/dist/core/tools/subagent.d.ts +8 -0
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +55 -2
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/init-templates.generated.d.ts.map +1 -1
- package/dist/init-templates.generated.js +3 -6
- package/dist/init-templates.generated.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +31 -3
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/task-panel.d.ts +12 -7
- package/dist/modes/interactive/components/task-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-panel.js +90 -57
- package/dist/modes/interactive/components/task-panel.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +8 -1
- package/dist/modes/print-mode.js.map +1 -1
- package/docs/routing.md +15 -10
- package/examples/agents/fork-reviewer.md +29 -0
- package/examples/agents/orchestrator.md +35 -0
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +4 -4
- package/templates/agents/explore.md +4 -5
- package/templates/agents/general-purpose.md +8 -7
- package/templates/agents/plan.md +39 -0
- package/templates/agents/doc.md +0 -37
- package/templates/agents/edit.md +0 -39
- package/templates/agents/review.md +0 -38
- package/templates/agents/test.md +0 -37
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-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AAC,KAAK,CAAC,CAAC;IAChD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1C,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QACvE,CAAC;IACF,CAAC;IAED,MAAM,QAAQ,GACb,OAAO,WAAW,CAAC,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,QAAQ,GAAG,CAAC;QAC7G,CAAC,CAAC,WAAW,CAAC,QAAQ;QACtB,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,UAA+B,CAAC;IACpC,IAAI,WAAW,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QAC1C,IAAI,OAAO,WAAW,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACjD,WAAW,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,sDAAsD,WAAW,CAAC,UAAU,qBAAmB;gBACxG,IAAI,EAAE,QAAQ;aACd,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,UAAU,GAAG,WAAW,CAAC,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QACjE,CAAC;IACF,CAAC;IAED,OAAO;QACN,KAAK,EAAE;YACN,IAAI;YACJ,WAAW;YACX,KAAK;YACL,KAAK;YACL,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE;YACnB,MAAM;YACN,QAAQ;YACR,QAAQ;YACR,UAAU;SACV;QACD,WAAW;KACX,CAAC;AAAA,CACF","sourcesContent":["/**\n * Agent frontmatter: schema, validation, and Claude Code compatibility shim.\n *\n * Agent definitions are Markdown files with YAML frontmatter, mirroring the\n * Claude Code subagent format so `.claude/agents/*.md` files import natively:\n *\n * ---\n * name: explore\n * description: When and why to use this agent (drives auto-delegation).\n * tools: Read, Grep, Glob, Bash # optional allowlist; omit = inherit all\n * model: sonnet # optional; sonnet|opus|haiku|inherit|pattern\n * ---\n * <system prompt body>\n *\n * The body becomes the subagent system prompt. Validation is non-fatal: we emit\n * diagnostics (warnings) and still load the agent when possible, matching the\n * behavior of skills.ts.\n */\n\nimport { basename } from \"path\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\n\n/** Max name length, aligned with skills. */\nconst MAX_NAME_LENGTH = 64;\n\n/** Max description length, aligned with skills. */\nconst MAX_DESCRIPTION_LENGTH = 1024;\n\n/** Where an agent definition came from. Used for precedence and diagnostics. */\nexport type AgentSource = \"builtin\" | \"user\" | \"project\" | \"claude-user\" | \"claude-project\";\n\n/** Sentinel meaning \"use the parent session's model\" (Claude Code `model: inherit`). */\nexport const MODEL_INHERIT = \"inherit\";\n\n/**\n * The seven built-in hoocode tools. An agent's `tools` allowlist is normalized\n * against this set; unknown tools are dropped with a diagnostic.\n */\nexport const HOOCODE_TOOL_NAMES: readonly string[] = [\"bash\", \"edit\", \"find\", \"grep\", \"ls\", \"read\", \"write\"];\n\n/**\n * D7 — Claude Code compatibility shim.\n *\n * Maps Claude Code tool names (case-insensitive) to their hoocode equivalents.\n * Claude tools without a hoocode counterpart (MultiEdit, Task, WebFetch,\n * WebSearch, TodoWrite, NotebookEdit, MCP tools, ...) are intentionally absent\n * and get dropped during normalization.\n */\nexport const CLAUDE_TOOL_ALIASES: Readonly<Record<string, string>> = {\n\tread: \"read\",\n\twrite: \"write\",\n\tedit: \"edit\",\n\tbash: \"bash\",\n\tgrep: \"grep\",\n\tglob: \"find\",\n\tfind: \"find\",\n\tls: \"ls\",\n};\n\n/** Raw frontmatter shape before validation/normalization. */\nexport interface AgentFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t/** Claude Code uses a comma-separated string; a YAML list is also accepted. */\n\ttools?: string | string[];\n\t/** sonnet | opus | haiku | inherit | a model id/pattern. */\n\tmodel?: string;\n\t/** hoocode extension (not part of the Claude Code format): turn cap. */\n\tmaxTurns?: number;\n\t/** Claude Code extension: run this agent detached (non-blocking) so the parent polls for its result. */\n\tbackground?: boolean;\n\t[key: string]: unknown;\n}\n\n/** A validated, normalized agent definition. */\nexport interface AgentDefinition {\n\tname: string;\n\tdescription: string;\n\t/**\n\t * Resolved hoocode tool allowlist. `undefined` means \"inherit all parent\n\t * tools\" (Claude Code behavior when `tools` is omitted).\n\t */\n\ttools?: string[];\n\t/**\n\t * Model alias/pattern, the `inherit` sentinel, or `undefined` for the\n\t * subagent default.\n\t */\n\tmodel?: string;\n\t/** System prompt body (frontmatter stripped). */\n\tprompt: string;\n\t/** Origin of this definition. */\n\tsource: AgentSource;\n\t/** Absolute path of the source file, when loaded from disk. */\n\tfilePath?: string;\n\t/** hoocode extension: optional per-agent turn cap. */\n\tmaxTurns?: number;\n\t/** When true, dispatch is non-blocking: the parent receives a handle and polls for the result. */\n\tbackground?: boolean;\n}\n\nconst KNOWN_MODEL_ALIASES = new Set([\"sonnet\", \"opus\", \"haiku\", \"inherit\"]);\n\n/** Validate an agent name. Returns warning messages (empty when valid). */\nfunction validateName(name: string): string[] {\n\tconst errors: string[] = [];\n\tif (!name) {\n\t\terrors.push(\"name is required\");\n\t\treturn errors;\n\t}\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\terrors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\t}\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(\"name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)\");\n\t}\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) {\n\t\terrors.push(\"name must not start or end with a hyphen\");\n\t}\n\tif (name.includes(\"--\")) {\n\t\terrors.push(\"name must not contain consecutive hyphens\");\n\t}\n\treturn errors;\n}\n\n/** Validate a description. Returns warning messages (empty when valid). */\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\treturn errors;\n}\n\nfunction validateModel(value: string): string[] {\n\tconst trimmed = value.trim();\n\tif (!trimmed) return [];\n\tif (KNOWN_MODEL_ALIASES.has(trimmed)) return [];\n\tif (/^claude-/.test(trimmed)) return [];\n\treturn [\n\t\t`model \"${trimmed}\" is not a recognized Claude alias (sonnet | opus | haiku | inherit) or full model ID (claude-*); the agent may not load correctly`,\n\t];\n}\n\n/** Split a `tools` frontmatter value (string or list) into raw token names. */\nfunction splitToolsValue(value: string | string[]): string[] {\n\tconst tokens = Array.isArray(value) ? value : value.split(\",\");\n\treturn tokens.map((t) => t.trim()).filter((t) => t.length > 0);\n}\n\n/**\n * Normalize a raw `tools` allowlist into hoocode tool names via the Claude Code\n * alias map. Returns the deduped, resolved list plus diagnostics for any tokens\n * that could not be mapped.\n *\n * Emits a warning when `value` is a YAML list rather than a comma-separated\n * string — the Claude Code standard format is `tools: read, bash` (string).\n */\nexport function normalizeTools(\n\tvalue: string | string[],\n\tfilePath?: string,\n): { tools: string[]; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\tif (Array.isArray(value)) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tmessage:\n\t\t\t\t'tools: use a comma-separated string (\"tools: read, bash\") instead of a YAML list for Claude Code compatibility',\n\t\t\tpath: filePath,\n\t\t});\n\t}\n\tconst resolved: string[] = [];\n\tfor (const raw of splitToolsValue(value)) {\n\t\tconst mapped = CLAUDE_TOOL_ALIASES[raw.toLowerCase()];\n\t\tif (!mapped) {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tmessage: `tool \"${raw}\" has no hoocode equivalent and was dropped from the allowlist`,\n\t\t\t\tpath: filePath,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (!resolved.includes(mapped)) {\n\t\t\tresolved.push(mapped);\n\t\t}\n\t}\n\treturn { tools: resolved, diagnostics };\n}\n\n/**\n * Normalize a `model` frontmatter value. `inherit` is preserved as a sentinel;\n * any other non-empty string is passed through to the model resolver as-is\n * (so Claude aliases like `sonnet`/`opus`/`haiku` resolve via pattern match).\n */\nexport function normalizeModel(value: string | undefined): string | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst trimmed = value.trim();\n\tif (!trimmed) return undefined;\n\treturn trimmed;\n}\n\n/**\n * Parse and validate a single agent definition from raw Markdown content.\n *\n * `fallbackName` is used when frontmatter omits `name` (e.g. the filename, or\n * the embedded-template key). Returns `agent: null` only when the definition\n * is unusable (missing description). Other problems surface as diagnostics.\n */\nexport function parseAgentDefinition(\n\trawContent: string,\n\toptions: { source: AgentSource; filePath?: string; fallbackName?: string },\n): { agent: AgentDefinition | null; diagnostics: ResourceDiagnostic[] } {\n\tconst { source, filePath } = options;\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\tlet frontmatter: AgentFrontmatter;\n\tlet body: string;\n\ttry {\n\t\tconst parsed = parseFrontmatter<AgentFrontmatter>(rawContent);\n\t\tfrontmatter = parsed.frontmatter;\n\t\tbody = parsed.body;\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse agent frontmatter\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { agent: null, diagnostics };\n\t}\n\n\tconst fallbackName = options.fallbackName ?? (filePath ? basename(filePath, \".md\") : \"\");\n\tconst name = (frontmatter.name ?? fallbackName).trim();\n\n\tfor (const error of validateName(name)) {\n\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t}\n\n\tconst description = typeof frontmatter.description === \"string\" ? frontmatter.description.trim() : \"\";\n\tfor (const error of validateDescription(description)) {\n\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t}\n\n\t// Description is mandatory: it drives delegation. Without it the agent is unusable.\n\tif (!description) {\n\t\treturn { agent: null, diagnostics };\n\t}\n\t// A usable name is required as the registry key.\n\tif (!name || !/^[a-z0-9-]+$/.test(name)) {\n\t\treturn { agent: null, diagnostics };\n\t}\n\n\tlet tools: string[] | undefined;\n\tif (frontmatter.tools !== undefined) {\n\t\tconst normalized = normalizeTools(frontmatter.tools, filePath);\n\t\tdiagnostics.push(...normalized.diagnostics);\n\t\ttools = normalized.tools;\n\t}\n\n\tconst model = normalizeModel(frontmatter.model);\n\tif (model !== undefined) {\n\t\tfor (const error of validateModel(model)) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t}\n\n\tconst maxTurns =\n\t\ttypeof frontmatter.maxTurns === \"number\" && Number.isInteger(frontmatter.maxTurns) && frontmatter.maxTurns > 0\n\t\t\t? frontmatter.maxTurns\n\t\t\t: undefined;\n\n\tlet background: boolean | undefined;\n\tif (frontmatter.background !== undefined) {\n\t\tif (typeof frontmatter.background !== \"boolean\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tmessage: `background must be a boolean (true or false), got \"${frontmatter.background}\" — field ignored`,\n\t\t\t\tpath: filePath,\n\t\t\t});\n\t\t} else {\n\t\t\tbackground = frontmatter.background === true ? true : undefined;\n\t\t}\n\t}\n\n\treturn {\n\t\tagent: {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\ttools,\n\t\t\tmodel,\n\t\t\tprompt: body.trim(),\n\t\t\tsource,\n\t\t\tfilePath,\n\t\t\tmaxTurns,\n\t\t\tbackground,\n\t\t},\n\t\tdiagnostics,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-frontmatter.js","sourceRoot":"","sources":["../../src/core/agent-frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;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AC,CAAC,CAAC;YACxC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtB,QAAQ,GAAG,IAAI,CAAC;gBAChB,UAAU,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACP,WAAW,CAAC,IAAI,CAAC;oBAChB,IAAI,EAAE,SAAS;oBACf,OAAO,EAAE,kBAAkB,KAAK,oDAAkD;oBAClF,IAAI,EAAE,QAAQ;iBACd,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;aAAM,CAAC;YACP,WAAW,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,6DAA6D,KAAK,qBAAmB;gBAC9F,IAAI,EAAE,QAAQ;aACd,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,OAAO;QACN,KAAK,EAAE;YACN,IAAI;YACJ,WAAW;YACX,KAAK;YACL,eAAe;YACf,KAAK;YACL,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE;YACnB,MAAM;YACN,QAAQ;YACR,QAAQ;YACR,UAAU;YACV,QAAQ;YACR,UAAU;YACV,IAAI;SACJ;QACD,WAAW;KACX,CAAC;AAAA,CACF","sourcesContent":["/**\n * Agent frontmatter: schema, validation, and Claude Code compatibility shim.\n *\n * Agent definitions are Markdown files with YAML frontmatter, mirroring the\n * Claude Code subagent format so `.claude/agents/*.md` files import natively:\n *\n * ---\n * name: explore\n * description: When and why to use this agent (drives auto-delegation).\n * tools: Read, Grep, Glob, Bash # optional allowlist; omit = inherit all\n * model: sonnet # optional; sonnet|opus|haiku|inherit|pattern\n * ---\n * <system prompt body>\n *\n * The body becomes the subagent system prompt. Validation is non-fatal: we emit\n * diagnostics (warnings) and still load the agent when possible, matching the\n * behavior of skills.ts.\n */\n\nimport { basename } from \"path\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\n\n/** Max name length, aligned with skills. */\nconst MAX_NAME_LENGTH = 64;\n\n/** Max description length, aligned with skills. */\nconst MAX_DESCRIPTION_LENGTH = 1024;\n\n/** Where an agent definition came from. Used for precedence and diagnostics. */\nexport type AgentSource = \"builtin\" | \"user\" | \"project\" | \"claude-user\" | \"claude-project\";\n\n/** Sentinel meaning \"use the parent session's model\" (Claude Code `model: inherit`). */\nexport const MODEL_INHERIT = \"inherit\";\n\n/**\n * The seven built-in hoocode tools. An agent's `tools` allowlist is normalized\n * against this set; unknown tools are dropped with a diagnostic.\n */\nexport const HOOCODE_TOOL_NAMES: readonly string[] = [\"bash\", \"edit\", \"find\", \"grep\", \"ls\", \"read\", \"write\"];\n\n/**\n * D7 — Claude Code compatibility shim.\n *\n * Maps Claude Code tool names (case-insensitive) to their hoocode equivalents.\n * Claude tools without a hoocode counterpart (MultiEdit, Task, WebFetch,\n * WebSearch, TodoWrite, NotebookEdit, MCP tools, ...) are intentionally absent\n * and get dropped during normalization.\n */\nexport const CLAUDE_TOOL_ALIASES: Readonly<Record<string, string>> = {\n\tread: \"read\",\n\twrite: \"write\",\n\tedit: \"edit\",\n\tbash: \"bash\",\n\tgrep: \"grep\",\n\tglob: \"find\",\n\tfind: \"find\",\n\tls: \"ls\",\n};\n\n/** Raw frontmatter shape before validation/normalization. */\nexport interface AgentFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t/** Claude Code uses a comma-separated string; a YAML list is also accepted. */\n\ttools?: string | string[];\n\t/** Tools to subtract from the agent's set (allow + deny), Claude Code compatible. */\n\tdisallowedTools?: string | string[];\n\t/** sonnet | opus | haiku | inherit | a model id/pattern. */\n\tmodel?: string;\n\t/** hoocode extension (not part of the Claude Code format): turn cap. */\n\tmaxTurns?: number;\n\t/** Claude Code extension: run this agent detached (non-blocking) so the parent polls for its result. */\n\tbackground?: boolean;\n\t/**\n\t * hoocode extension: opt a agent into delegating via the Task tool (subject to the\n\t * tree-wide nesting cap). `true` = any subagent type; a comma-separated string or\n\t * YAML list = only those types. Opt-in per agent so the deliberate \"Task is not a\n\t * normal tool\" boundary stays intact for everyone else.\n\t */\n\tdelegate?: boolean | string | string[];\n\t/**\n\t * When true, this agent inherits the parent's full conversation (a fork) instead\n\t * of starting from a fresh context, reusing the parent's prompt cache.\n\t */\n\tfork?: boolean;\n\t[key: string]: unknown;\n}\n\n/** A validated, normalized agent definition. */\nexport interface AgentDefinition {\n\tname: string;\n\tdescription: string;\n\t/**\n\t * Resolved hoocode tool allowlist. `undefined` means \"inherit all parent\n\t * tools\" (Claude Code behavior when `tools` is omitted).\n\t */\n\ttools?: string[];\n\t/** Resolved denylist subtracted from the agent's tool set. */\n\tdisallowedTools?: string[];\n\t/**\n\t * Model alias/pattern, the `inherit` sentinel, or `undefined` for the\n\t * subagent default.\n\t */\n\tmodel?: string;\n\t/** System prompt body (frontmatter stripped). */\n\tprompt: string;\n\t/** Origin of this definition. */\n\tsource: AgentSource;\n\t/** Absolute path of the source file, when loaded from disk. */\n\tfilePath?: string;\n\t/** hoocode extension: optional per-agent turn cap. */\n\tmaxTurns?: number;\n\t/** When true, dispatch is non-blocking: the parent receives a handle and polls for the result. */\n\tbackground?: boolean;\n\t/** When true, this agent may delegate via the Task tool, subject to the nesting cap. */\n\tdelegate?: boolean;\n\t/** Restricts delegation to these subagent types (undefined = any when `delegate` is true). */\n\tdelegateTo?: string[];\n\t/** When true, the agent inherits the parent's full conversation (a fork). */\n\tfork?: boolean;\n}\n\nconst KNOWN_MODEL_ALIASES = new Set([\"sonnet\", \"opus\", \"haiku\", \"inherit\"]);\n\n/** Validate an agent name. Returns warning messages (empty when valid). */\nfunction validateName(name: string): string[] {\n\tconst errors: string[] = [];\n\tif (!name) {\n\t\terrors.push(\"name is required\");\n\t\treturn errors;\n\t}\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\terrors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\t}\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(\"name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)\");\n\t}\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) {\n\t\terrors.push(\"name must not start or end with a hyphen\");\n\t}\n\tif (name.includes(\"--\")) {\n\t\terrors.push(\"name must not contain consecutive hyphens\");\n\t}\n\treturn errors;\n}\n\n/** Validate a description. Returns warning messages (empty when valid). */\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\treturn errors;\n}\n\nfunction validateModel(value: string): string[] {\n\tconst trimmed = value.trim();\n\tif (!trimmed) return [];\n\tif (KNOWN_MODEL_ALIASES.has(trimmed)) return [];\n\tif (/^claude-/.test(trimmed)) return [];\n\treturn [\n\t\t`model \"${trimmed}\" is not a recognized Claude alias (sonnet | opus | haiku | inherit) or full model ID (claude-*); the agent may not load correctly`,\n\t];\n}\n\n/** Split a `tools` frontmatter value (string or list) into raw token names. */\nfunction splitToolsValue(value: string | string[]): string[] {\n\tconst tokens = Array.isArray(value) ? value : value.split(\",\");\n\treturn tokens.map((t) => t.trim()).filter((t) => t.length > 0);\n}\n\n/**\n * Normalize a raw `tools` allowlist into hoocode tool names via the Claude Code\n * alias map. Returns the deduped, resolved list plus diagnostics for any tokens\n * that could not be mapped.\n *\n * Emits a warning when `value` is a YAML list rather than a comma-separated\n * string — the Claude Code standard format is `tools: read, bash` (string).\n */\nexport function normalizeTools(\n\tvalue: string | string[],\n\tfilePath?: string,\n): { tools: string[]; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\tif (Array.isArray(value)) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tmessage:\n\t\t\t\t'tools: use a comma-separated string (\"tools: read, bash\") instead of a YAML list for Claude Code compatibility',\n\t\t\tpath: filePath,\n\t\t});\n\t}\n\tconst resolved: string[] = [];\n\tfor (const raw of splitToolsValue(value)) {\n\t\tconst mapped = CLAUDE_TOOL_ALIASES[raw.toLowerCase()];\n\t\tif (!mapped) {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tmessage: `tool \"${raw}\" has no hoocode equivalent and was dropped from the allowlist`,\n\t\t\t\tpath: filePath,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (!resolved.includes(mapped)) {\n\t\t\tresolved.push(mapped);\n\t\t}\n\t}\n\treturn { tools: resolved, diagnostics };\n}\n\n/**\n * Normalize a `model` frontmatter value. `inherit` is preserved as a sentinel;\n * any other non-empty string is passed through to the model resolver as-is\n * (so Claude aliases like `sonnet`/`opus`/`haiku` resolve via pattern match).\n */\nexport function normalizeModel(value: string | undefined): string | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst trimmed = value.trim();\n\tif (!trimmed) return undefined;\n\treturn trimmed;\n}\n\n/**\n * Parse and validate a single agent definition from raw Markdown content.\n *\n * `fallbackName` is used when frontmatter omits `name` (e.g. the filename, or\n * the embedded-template key). Returns `agent: null` only when the definition\n * is unusable (missing description). Other problems surface as diagnostics.\n */\nexport function parseAgentDefinition(\n\trawContent: string,\n\toptions: { source: AgentSource; filePath?: string; fallbackName?: string },\n): { agent: AgentDefinition | null; diagnostics: ResourceDiagnostic[] } {\n\tconst { source, filePath } = options;\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\tlet frontmatter: AgentFrontmatter;\n\tlet body: string;\n\ttry {\n\t\tconst parsed = parseFrontmatter<AgentFrontmatter>(rawContent);\n\t\tfrontmatter = parsed.frontmatter;\n\t\tbody = parsed.body;\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse agent frontmatter\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { agent: null, diagnostics };\n\t}\n\n\tconst fallbackName = options.fallbackName ?? (filePath ? basename(filePath, \".md\") : \"\");\n\tconst name = (frontmatter.name ?? fallbackName).trim();\n\n\tfor (const error of validateName(name)) {\n\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t}\n\n\tconst description = typeof frontmatter.description === \"string\" ? frontmatter.description.trim() : \"\";\n\tfor (const error of validateDescription(description)) {\n\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t}\n\n\t// Description is mandatory: it drives delegation. Without it the agent is unusable.\n\tif (!description) {\n\t\treturn { agent: null, diagnostics };\n\t}\n\t// A usable name is required as the registry key.\n\tif (!name || !/^[a-z0-9-]+$/.test(name)) {\n\t\treturn { agent: null, diagnostics };\n\t}\n\n\tlet tools: string[] | undefined;\n\tif (frontmatter.tools !== undefined) {\n\t\tconst normalized = normalizeTools(frontmatter.tools, filePath);\n\t\tdiagnostics.push(...normalized.diagnostics);\n\t\ttools = normalized.tools;\n\t}\n\n\tlet disallowedTools: string[] | undefined;\n\tif (frontmatter.disallowedTools !== undefined) {\n\t\tconst normalized = normalizeTools(frontmatter.disallowedTools, filePath);\n\t\tdiagnostics.push(...normalized.diagnostics);\n\t\tdisallowedTools = normalized.tools.length > 0 ? normalized.tools : undefined;\n\t}\n\n\tconst model = normalizeModel(frontmatter.model);\n\tif (model !== undefined) {\n\t\tfor (const error of validateModel(model)) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\t}\n\n\tconst maxTurns =\n\t\ttypeof frontmatter.maxTurns === \"number\" && Number.isInteger(frontmatter.maxTurns) && frontmatter.maxTurns > 0\n\t\t\t? frontmatter.maxTurns\n\t\t\t: undefined;\n\n\tlet background: boolean | undefined;\n\tif (frontmatter.background !== undefined) {\n\t\tif (typeof frontmatter.background !== \"boolean\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tmessage: `background must be a boolean (true or false), got \"${frontmatter.background}\" — field ignored`,\n\t\t\t\tpath: filePath,\n\t\t\t});\n\t\t} else {\n\t\t\tbackground = frontmatter.background === true ? true : undefined;\n\t\t}\n\t}\n\n\t// `delegate` accepts a boolean (delegate to any agent) or a comma-separated\n\t// string / YAML list of agent type names (delegate only to those).\n\tlet fork: boolean | undefined;\n\tif (frontmatter.fork !== undefined) {\n\t\tif (typeof frontmatter.fork !== \"boolean\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tmessage: `fork must be a boolean (true or false), got \"${frontmatter.fork}\" — field ignored`,\n\t\t\t\tpath: filePath,\n\t\t\t});\n\t\t} else {\n\t\t\tfork = frontmatter.fork === true ? true : undefined;\n\t\t}\n\t}\n\n\tlet delegate: boolean | undefined;\n\tlet delegateTo: string[] | undefined;\n\tif (frontmatter.delegate !== undefined) {\n\t\tconst value = frontmatter.delegate;\n\t\tif (value === true) {\n\t\t\tdelegate = true;\n\t\t} else if (value === false) {\n\t\t\tdelegate = undefined;\n\t\t} else if (typeof value === \"string\" || Array.isArray(value)) {\n\t\t\tconst names = (Array.isArray(value) ? value.join(\",\") : value)\n\t\t\t\t.split(\",\")\n\t\t\t\t.map((s) => s.trim().toLowerCase())\n\t\t\t\t.filter((s) => /^[a-z0-9-]+$/.test(s));\n\t\t\tif (names.length > 0) {\n\t\t\t\tdelegate = true;\n\t\t\t\tdelegateTo = [...new Set(names)];\n\t\t\t} else {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\tmessage: `delegate list \"${value}\" contained no valid agent names — field ignored`,\n\t\t\t\t\tpath: filePath,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tmessage: `delegate must be a boolean or a list of agent names, got \"${value}\" — field ignored`,\n\t\t\t\tpath: filePath,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn {\n\t\tagent: {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\ttools,\n\t\t\tdisallowedTools,\n\t\t\tmodel,\n\t\t\tprompt: body.trim(),\n\t\t\tsource,\n\t\t\tfilePath,\n\t\t\tmaxTurns,\n\t\t\tbackground,\n\t\t\tdelegate,\n\t\t\tdelegateTo,\n\t\t\tfork,\n\t\t},\n\t\tdiagnostics,\n\t};\n}\n"]}
|
|
@@ -91,6 +91,8 @@ export interface AgentSessionConfig {
|
|
|
91
91
|
initialActiveToolNames?: string[];
|
|
92
92
|
/** Optional allowlist of tool names. When provided, only these tool names are exposed. */
|
|
93
93
|
allowedToolNames?: string[];
|
|
94
|
+
/** Optional denylist of tool names, subtracted from whatever set is otherwise enabled. */
|
|
95
|
+
disallowedToolNames?: string[];
|
|
94
96
|
/**
|
|
95
97
|
* Override base tools (useful for custom runtimes).
|
|
96
98
|
*
|
|
@@ -183,6 +185,7 @@ export declare class AgentSession {
|
|
|
183
185
|
private _extensionRunnerRef?;
|
|
184
186
|
private _initialActiveToolNames?;
|
|
185
187
|
private _allowedToolNames?;
|
|
188
|
+
private _disallowedToolNames?;
|
|
186
189
|
private _baseToolsOverride?;
|
|
187
190
|
private _sessionStartEvent;
|
|
188
191
|
private _extensionUIContext?;
|