@kolisachint/hoocode-agent 0.4.21 → 0.4.24
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 +21 -0
- package/dist/cli/args.d.ts +1 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +5 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/config.d.ts +2 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -9
- package/dist/config.js.map +1 -1
- package/dist/core/agent-frontmatter.d.ts +3 -0
- package/dist/core/agent-frontmatter.d.ts.map +1 -1
- package/dist/core/agent-frontmatter.js +41 -1
- package/dist/core/agent-frontmatter.js.map +1 -1
- package/dist/core/agent-manifest-paths.d.ts +17 -0
- package/dist/core/agent-manifest-paths.d.ts.map +1 -0
- package/dist/core/agent-manifest-paths.js +27 -0
- package/dist/core/agent-manifest-paths.js.map +1 -0
- package/dist/core/agent-registry.d.ts +14 -7
- package/dist/core/agent-registry.d.ts.map +1 -1
- package/dist/core/agent-registry.js +114 -8
- package/dist/core/agent-registry.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +23 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +1 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +26 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +8 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +2 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/package-manager.d.ts +2 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +38 -9
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/provider-health.d.ts +36 -0
- package/dist/core/provider-health.d.ts.map +1 -0
- package/dist/core/provider-health.js +54 -0
- package/dist/core/provider-health.js.map +1 -0
- package/dist/core/resource-loader.d.ts +14 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +12 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/skills.d.ts +9 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +32 -1
- package/dist/core/skills.js.map +1 -1
- package/dist/core/source-info.d.ts +1 -1
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/subagent-pool-instance.d.ts +7 -0
- package/dist/core/subagent-pool-instance.d.ts.map +1 -1
- package/dist/core/subagent-pool-instance.js +14 -1
- package/dist/core/subagent-pool-instance.js.map +1 -1
- package/dist/core/subagent-pool.d.ts +16 -0
- package/dist/core/subagent-pool.d.ts.map +1 -1
- package/dist/core/subagent-pool.js +42 -2
- package/dist/core/subagent-pool.js.map +1 -1
- package/dist/core/subagent-result.d.ts.map +1 -1
- package/dist/core/subagent-result.js +32 -2
- package/dist/core/subagent-result.js.map +1 -1
- package/dist/core/system-prompt.d.ts +7 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +15 -3
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +10 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +34 -0
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +26 -0
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/extensions/core/hoo-core.d.ts +10 -3
- package/dist/extensions/core/hoo-core.d.ts.map +1 -1
- package/dist/extensions/core/hoo-core.js +254 -13
- package/dist/extensions/core/hoo-core.js.map +1 -1
- package/dist/init-templates.generated.d.ts.map +1 -1
- package/dist/init-templates.generated.js +5 -4
- package/dist/init-templates.generated.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +6 -2
- package/dist/init.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/ask-options.d.ts +44 -0
- package/dist/modes/interactive/components/ask-options.d.ts.map +1 -0
- package/dist/modes/interactive/components/ask-options.js +202 -0
- package/dist/modes/interactive/components/ask-options.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/task-panel.d.ts +15 -4
- package/dist/modes/interactive/components/task-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-panel.js +178 -63
- package/dist/modes/interactive/components/task-panel.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +10 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +50 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +26 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- 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/examples/sdk/12-full-control.ts +2 -0
- package/package.json +4 -4
- package/templates/agents/doc.md +1 -1
- package/templates/agents/edit.md +1 -0
- package/templates/agents/explore.md +3 -3
- package/templates/agents/general-purpose.md +37 -0
- package/templates/agents/review.md +2 -2
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GACvB,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAE9G,gEAAgE;AAChE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;AAkBnD,SAAS,qBAAqB,CAC7B,WAAkC,EAClC,aAAqC,EACjB;IACpB,IAAI,CAAC,aAAa;QAAE,OAAO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C,WAAW,EAAE,EAAE,WAAW,CAAC,CAAC;AAAA,CACxC;AAED,gCAAgC;AAChC,MAAM,UAAU,eAAe,GAAW;IACzC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,eAAe,CAAC,CAAC;AAAA,CAC5C;AAED,kCAAkC;AAClC,MAAM,UAAU,WAAW,GAAW;IACrC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;AAAA,CACpC;AAED,sDAAsD;AACtD,MAAM,UAAU,SAAS,GAAW;IACnC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,CAAC;AAAA,CAClC;AAED,6CAA6C;AAC7C,MAAM,UAAU,aAAa,GAAW;IACvC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,SAAS,CAAC,CAAC;AAAA,CACtC;AAED,qCAAqC;AACrC,MAAM,UAAU,cAAc,GAAW;IACxC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,UAAU,CAAC,CAAC;AAAA,CACvC;AAED,iCAAiC;AACjC,MAAM,UAAU,eAAe,GAAW;IACzC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,GAAG,QAAQ,YAAY,CAAC,CAAC;AAAA,CACpD","sourcesContent":["import { spawnSync } from \"child_process\";\nimport { accessSync, constants, existsSync, readFileSync, realpathSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { basename, dirname, join, resolve, sep, win32 } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { shouldUseWindowsShell } from \"./utils/child-process.js\";\n\n// =============================================================================\n// Package Detection\n// =============================================================================\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\n/**\n * Detect if we're running as a Bun compiled binary.\n * Bun binaries have import.meta.url containing \"$bunfs\", \"~BUN\", or \"%7EBUN\" (Bun's virtual filesystem path)\n */\nexport const isBunBinary =\n\timport.meta.url.includes(\"$bunfs\") || import.meta.url.includes(\"~BUN\") || import.meta.url.includes(\"%7EBUN\");\n\n/** Detect if Bun is the runtime (compiled binary or bun run) */\nexport const isBunRuntime = !!process.versions.bun;\n\n// =============================================================================\n// Install Method Detection\n// =============================================================================\n\nexport type InstallMethod = \"bun-binary\" | \"npm\" | \"pnpm\" | \"yarn\" | \"bun\" | \"unknown\";\n\ninterface SelfUpdateCommandStep {\n\tcommand: string;\n\targs: string[];\n\tdisplay: string;\n}\n\nexport interface SelfUpdateCommand extends SelfUpdateCommandStep {\n\tsteps?: SelfUpdateCommandStep[];\n}\n\nfunction makeSelfUpdateCommand(\n\tinstallStep: SelfUpdateCommandStep,\n\tuninstallStep?: SelfUpdateCommandStep,\n): SelfUpdateCommand {\n\tif (!uninstallStep) return installStep;\n\treturn {\n\t\t...installStep,\n\t\tdisplay: `${uninstallStep.display} && ${installStep.display}`,\n\t\tsteps: [uninstallStep, installStep],\n\t};\n}\n\nfunction makeSelfUpdateCommandStep(command: string, args: string[]): SelfUpdateCommandStep {\n\treturn {\n\t\tcommand,\n\t\targs,\n\t\tdisplay: [command, ...args].map((arg) => (/\\s/.test(arg) ? `\"${arg}\"` : arg)).join(\" \"),\n\t};\n}\n\nexport function detectInstallMethod(): InstallMethod {\n\tif (isBunBinary) {\n\t\treturn \"bun-binary\";\n\t}\n\n\tconst resolvedPath = `${__dirname}\\0${process.execPath || \"\"}`.toLowerCase().replace(/\\\\/g, \"/\");\n\n\tif (resolvedPath.includes(\"/pnpm/\") || resolvedPath.includes(\"/.pnpm/\")) {\n\t\treturn \"pnpm\";\n\t}\n\tif (resolvedPath.includes(\"/yarn/\") || resolvedPath.includes(\"/.yarn/\")) {\n\t\treturn \"yarn\";\n\t}\n\tif (isBunRuntime || resolvedPath.includes(\"/install/global/node_modules/\")) {\n\t\treturn \"bun\";\n\t}\n\tif (resolvedPath.includes(\"/npm/\") || resolvedPath.includes(\"/node_modules/\")) {\n\t\treturn \"npm\";\n\t}\n\n\treturn \"unknown\";\n}\n\nfunction getInferredNpmInstall(): { root: string; prefix: string } | undefined {\n\tconst packageDir = getPackageDir();\n\tconst path = process.platform === \"win32\" || packageDir.includes(\"\\\\\") ? win32 : { basename, dirname };\n\tconst parent = path.dirname(packageDir);\n\tlet root: string | undefined;\n\tif (path.basename(parent).startsWith(\"@\") && path.basename(path.dirname(parent)) === \"node_modules\") {\n\t\troot = path.dirname(parent);\n\t} else if (path.basename(parent) === \"node_modules\") {\n\t\troot = parent;\n\t}\n\tif (!root) return undefined;\n\tconst rootParent = path.dirname(root);\n\tif (path.basename(rootParent) === \"lib\") return { root, prefix: path.dirname(rootParent) };\n\t// Windows global npm prefixes use `<prefix>\\\\node_modules`, which is\n\t// indistinguishable from local project installs by path shape alone. Do not\n\t// infer unsupported Windows custom prefixes without `npm root -g` evidence.\n\treturn undefined;\n}\n\nfunction getSelfUpdateCommandForMethod(\n\tmethod: InstallMethod,\n\tinstalledPackageName: string,\n\tupdatePackageName = installedPackageName,\n\tnpmCommand?: string[],\n): SelfUpdateCommand | undefined {\n\tswitch (method) {\n\t\tcase \"bun-binary\":\n\t\t\treturn undefined;\n\t\tcase \"pnpm\":\n\t\t\treturn makeSelfUpdateCommand(\n\t\t\t\tmakeSelfUpdateCommandStep(\"pnpm\", [\"install\", \"-g\", updatePackageName]),\n\t\t\t\tupdatePackageName === installedPackageName\n\t\t\t\t\t? undefined\n\t\t\t\t\t: makeSelfUpdateCommandStep(\"pnpm\", [\"remove\", \"-g\", installedPackageName]),\n\t\t\t);\n\t\tcase \"yarn\":\n\t\t\treturn makeSelfUpdateCommand(\n\t\t\t\tmakeSelfUpdateCommandStep(\"yarn\", [\"global\", \"add\", updatePackageName]),\n\t\t\t\tupdatePackageName === installedPackageName\n\t\t\t\t\t? undefined\n\t\t\t\t\t: makeSelfUpdateCommandStep(\"yarn\", [\"global\", \"remove\", installedPackageName]),\n\t\t\t);\n\t\tcase \"bun\":\n\t\t\treturn makeSelfUpdateCommand(\n\t\t\t\tmakeSelfUpdateCommandStep(\"bun\", [\"install\", \"-g\", updatePackageName]),\n\t\t\t\tupdatePackageName === installedPackageName\n\t\t\t\t\t? undefined\n\t\t\t\t\t: makeSelfUpdateCommandStep(\"bun\", [\"uninstall\", \"-g\", installedPackageName]),\n\t\t\t);\n\t\tcase \"npm\": {\n\t\t\tconst [command = \"npm\", ...npmArgs] = npmCommand ?? [];\n\t\t\tconst inferred = npmCommand?.length ? undefined : getInferredNpmInstall();\n\t\t\tconst prefixArgs = [...npmArgs, ...(inferred ? [\"--prefix\", inferred.prefix] : [])];\n\t\t\tconst installStep = makeSelfUpdateCommandStep(command, [...prefixArgs, \"install\", \"-g\", updatePackageName]);\n\t\t\tconst uninstallStep =\n\t\t\t\tupdatePackageName === installedPackageName\n\t\t\t\t\t? undefined\n\t\t\t\t\t: makeSelfUpdateCommandStep(command, [...prefixArgs, \"uninstall\", \"-g\", installedPackageName]);\n\t\t\treturn makeSelfUpdateCommand(installStep, uninstallStep);\n\t\t}\n\t\tcase \"unknown\":\n\t\t\treturn undefined;\n\t}\n}\n\nfunction readCommandOutput(\n\tcommand: string,\n\targs: string[],\n\toptions: { requireSuccess?: boolean } = {},\n): string | undefined {\n\tconst result = spawnSync(command, args, {\n\t\tencoding: \"utf-8\",\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\tshell: shouldUseWindowsShell(command),\n\t});\n\tif (result.status === 0) return result.stdout.trim() || undefined;\n\tif (options.requireSuccess) {\n\t\tconst reason = result.error?.message || result.stderr.trim() || `exit code ${result.status ?? \"unknown\"}`;\n\t\tthrow new Error(`Failed to run ${[command, ...args].join(\" \")}: ${reason}`);\n\t}\n\treturn undefined;\n}\n\nfunction getGlobalPackageRoots(method: InstallMethod, _packageName: string, npmCommand?: string[]): string[] {\n\tswitch (method) {\n\t\tcase \"npm\": {\n\t\t\tconst configured = !!npmCommand?.length;\n\t\t\tconst [command = \"npm\", ...npmArgs] = npmCommand ?? [];\n\t\t\tif (configured && command === \"bun\") {\n\t\t\t\tconst bunBin = readCommandOutput(command, [...npmArgs, \"pm\", \"bin\", \"-g\"], {\n\t\t\t\t\trequireSuccess: true,\n\t\t\t\t});\n\t\t\t\tconst roots = [join(homedir(), \".bun\", \"install\", \"global\", \"node_modules\")];\n\t\t\t\tif (bunBin) {\n\t\t\t\t\troots.push(join(dirname(bunBin), \"install\", \"global\", \"node_modules\"));\n\t\t\t\t}\n\t\t\t\treturn roots;\n\t\t\t}\n\t\t\tconst root = readCommandOutput(command, [...npmArgs, \"root\", \"-g\"], {\n\t\t\t\trequireSuccess: configured,\n\t\t\t});\n\t\t\tconst inferred = configured ? undefined : getInferredNpmInstall();\n\t\t\treturn [root, inferred?.root].filter((x): x is string => !!x);\n\t\t}\n\t\tcase \"pnpm\": {\n\t\t\tconst root = readCommandOutput(\"pnpm\", [\"root\", \"-g\"]);\n\t\t\treturn root ? [root, dirname(root)] : [];\n\t\t}\n\t\tcase \"yarn\": {\n\t\t\tconst dir = readCommandOutput(\"yarn\", [\"global\", \"dir\"]);\n\t\t\treturn dir ? [dir, join(dir, \"node_modules\")] : [];\n\t\t}\n\t\tcase \"bun\": {\n\t\t\tconst bunBin = readCommandOutput(\"bun\", [\"pm\", \"bin\", \"-g\"]);\n\t\t\tconst roots = [join(homedir(), \".bun\", \"install\", \"global\", \"node_modules\")];\n\t\t\tif (bunBin) {\n\t\t\t\troots.push(join(dirname(bunBin), \"install\", \"global\", \"node_modules\"));\n\t\t\t}\n\t\t\treturn roots;\n\t\t}\n\t\tcase \"bun-binary\":\n\t\tcase \"unknown\":\n\t\t\treturn [];\n\t}\n}\n\nfunction normalizeExistingPathForComparison(path: string): string | undefined {\n\tconst resolvedPath = resolve(path);\n\tif (!existsSync(resolvedPath)) {\n\t\treturn undefined;\n\t}\n\tlet normalizedPath: string;\n\ttry {\n\t\tnormalizedPath = realpathSync(resolvedPath);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (process.platform === \"win32\") {\n\t\tnormalizedPath = normalizedPath.toLowerCase();\n\t}\n\treturn normalizedPath;\n}\n\nfunction isSelfUpdatePathWritable(): boolean {\n\tconst packageDir = getPackageDir();\n\ttry {\n\t\taccessSync(packageDir, constants.W_OK);\n\t\taccessSync(dirname(packageDir), constants.W_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction isManagedByGlobalPackageManager(method: InstallMethod, packageName: string, npmCommand?: string[]): boolean {\n\tconst packageDir = normalizeExistingPathForComparison(getPackageDir());\n\treturn (\n\t\t!!packageDir &&\n\t\tgetGlobalPackageRoots(method, packageName, npmCommand).some((root) => {\n\t\t\tconst normalizedRoot = normalizeExistingPathForComparison(root);\n\t\t\treturn (\n\t\t\t\t!!normalizedRoot &&\n\t\t\t\tpackageDir.startsWith(normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`)\n\t\t\t);\n\t\t})\n\t);\n}\n\nexport function getSelfUpdateCommand(\n\tpackageName: string,\n\tnpmCommand?: string[],\n\tupdatePackageName = packageName,\n): SelfUpdateCommand | undefined {\n\tconst method = detectInstallMethod();\n\tconst command = getSelfUpdateCommandForMethod(method, packageName, updatePackageName, npmCommand);\n\tif (!command || !isManagedByGlobalPackageManager(method, packageName, npmCommand) || !isSelfUpdatePathWritable()) {\n\t\treturn undefined;\n\t}\n\treturn command;\n}\n\nexport function getSelfUpdateUnavailableInstruction(\n\tpackageName: string,\n\tnpmCommand?: string[],\n\tupdatePackageName = packageName,\n): string {\n\tconst method = detectInstallMethod();\n\tif (method === \"bun-binary\") {\n\t\treturn `Download from: https://github.com/kolisachint/hoocode/releases/latest`;\n\t}\n\tconst command = getSelfUpdateCommandForMethod(method, packageName, updatePackageName, npmCommand);\n\tif (command) {\n\t\tif (isManagedByGlobalPackageManager(method, packageName, npmCommand) && !isSelfUpdatePathWritable()) {\n\t\t\treturn `This installation is managed by a global ${method} install, but the install path is not writable. Update it yourself with: ${command.display}`;\n\t\t}\n\t\treturn `This installation is not managed by a global ${method} install. Update it with the package manager, wrapper, or source checkout that provides it.`;\n\t}\n\treturn `Update ${updatePackageName} using the package manager, wrapper, or source checkout that provides this installation.`;\n}\n\nexport function getUpdateInstruction(packageName: string): string {\n\tconst method = detectInstallMethod();\n\tconst command = getSelfUpdateCommandForMethod(method, packageName);\n\tif (command) {\n\t\treturn `Run: ${command.display}`;\n\t}\n\treturn getSelfUpdateUnavailableInstruction(packageName);\n}\n\n// =============================================================================\n// Package Asset Paths (shipped with executable)\n// =============================================================================\n\n/**\n * Get the base directory for resolving package assets (themes, package.json, README.md, CHANGELOG.md).\n * - For Bun binary: returns the directory containing the executable\n * - For Node.js (dist/): returns __dirname (the dist/ directory)\n * - For tsx (src/): returns parent directory (the package root)\n */\nexport function getPackageDir(): string {\n\t// Allow override via environment variable (useful for Nix/Guix where store paths tokenize poorly)\n\tconst envDir = process.env.HOOCODE_PACKAGE_DIR ?? process.env.PI_PACKAGE_DIR;\n\tif (envDir) {\n\t\tif (envDir === \"~\") return homedir();\n\t\tif (envDir.startsWith(\"~/\")) return homedir() + envDir.slice(1);\n\t\treturn envDir;\n\t}\n\n\tif (isBunBinary) {\n\t\t// Bun binary: process.execPath points to the compiled executable\n\t\treturn dirname(process.execPath);\n\t}\n\t// Node.js: walk up from __dirname until we find package.json\n\tlet dir = __dirname;\n\twhile (dir !== dirname(dir)) {\n\t\tif (existsSync(join(dir, \"package.json\"))) {\n\t\t\treturn dir;\n\t\t}\n\t\tdir = dirname(dir);\n\t}\n\t// Fallback (shouldn't happen)\n\treturn __dirname;\n}\n\n/**\n * Get path to built-in themes directory (shipped with package)\n * - For Bun binary: theme/ next to executable\n * - For Node.js (dist/): dist/modes/interactive/theme/\n * - For tsx (src/): src/modes/interactive/theme/\n */\nexport function getThemesDir(): string {\n\tif (isBunBinary) {\n\t\treturn join(getPackageDir(), \"theme\");\n\t}\n\t// Theme is in modes/interactive/theme/ relative to src/ or dist/\n\tconst packageDir = getPackageDir();\n\tconst srcOrDist = existsSync(join(packageDir, \"src\")) ? \"src\" : \"dist\";\n\treturn join(packageDir, srcOrDist, \"modes\", \"interactive\", \"theme\");\n}\n\n/**\n * Get path to HTML export template directory (shipped with package)\n * - For Bun binary: export-html/ next to executable\n * - For Node.js (dist/): dist/core/export-html/\n * - For tsx (src/): src/core/export-html/\n */\nexport function getExportTemplateDir(): string {\n\tif (isBunBinary) {\n\t\treturn join(getPackageDir(), \"export-html\");\n\t}\n\tconst packageDir = getPackageDir();\n\tconst srcOrDist = existsSync(join(packageDir, \"src\")) ? \"src\" : \"dist\";\n\treturn join(packageDir, srcOrDist, \"core\", \"export-html\");\n}\n\n/** Get path to package.json */\nexport function getPackageJsonPath(): string {\n\treturn join(getPackageDir(), \"package.json\");\n}\n\n/** Get path to README.md */\nexport function getReadmePath(): string {\n\treturn resolve(join(getPackageDir(), \"README.md\"));\n}\n\n/** Get path to docs directory */\nexport function getDocsPath(): string {\n\treturn resolve(join(getPackageDir(), \"docs\"));\n}\n\n/** Get path to examples directory */\nexport function getExamplesPath(): string {\n\treturn resolve(join(getPackageDir(), \"examples\"));\n}\n\n/** Get path to CHANGELOG.md */\nexport function getChangelogPath(): string {\n\treturn resolve(join(getPackageDir(), \"CHANGELOG.md\"));\n}\n\n/**\n * Get path to built-in interactive assets directory.\n * - For Bun binary: assets/ next to executable\n * - For Node.js (dist/): dist/modes/interactive/assets/\n * - For tsx (src/): src/modes/interactive/assets/\n */\nexport function getInteractiveAssetsDir(): string {\n\tif (isBunBinary) {\n\t\treturn join(getPackageDir(), \"assets\");\n\t}\n\tconst packageDir = getPackageDir();\n\tconst srcOrDist = existsSync(join(packageDir, \"src\")) ? \"src\" : \"dist\";\n\treturn join(packageDir, srcOrDist, \"modes\", \"interactive\", \"assets\");\n}\n\n/** Get path to a bundled interactive asset */\nexport function getBundledInteractiveAssetPath(name: string): string {\n\treturn join(getInteractiveAssetsDir(), name);\n}\n\n/**\n * Resolve the command used to spawn a hoocode subagent child process by\n * re-running the current process.\n *\n * - Bun binary: the compiled executable spawns itself (argv[1] is not a script).\n * - Node.js / tsx: spawn the current runtime (process.execPath) replaying the\n * runtime flags (process.execArgv, e.g. tsx's `--import`) and the entry script\n * that launched this process (process.argv[1]).\n *\n * This mirrors exactly how the parent was started, so it works whether running\n * from dist/, from source via tsx, or as a packaged binary.\n */\nexport function getSubagentSpawnCommand(): { executable: string; prefixArgs: string[] } {\n\tif (isBunBinary) {\n\t\treturn { executable: process.execPath, prefixArgs: [] };\n\t}\n\tconst entry = process.argv[1];\n\tconst prefixArgs = [...process.execArgv];\n\tif (entry) prefixArgs.push(entry);\n\treturn { executable: process.execPath, prefixArgs };\n}\n\n/**\n * Get path to bundled init templates (default modes/profiles seeded into HOOCODE_DIR on first run).\n * - For Bun binary: templates/ next to executable\n * - For Node.js (dist/) and tsx (src/): templates/ at the package root\n */\nexport function getTemplatesDir(): string {\n\treturn join(getPackageDir(), \"templates\");\n}\n\n// =============================================================================\n// App Config (from package.json hoocodeConfig — accepts legacy piConfig)\n// =============================================================================\n\ninterface AppConfigBlock {\n\tname?: string;\n\tconfigDir?: string;\n}\n\ninterface PackageJson {\n\tname?: string;\n\tversion?: string;\n\thoocodeConfig?: AppConfigBlock;\n\tpiConfig?: AppConfigBlock;\n}\n\nconst pkg = JSON.parse(readFileSync(getPackageJsonPath(), \"utf-8\")) as PackageJson;\n\nconst appConfig: AppConfigBlock = pkg.hoocodeConfig ?? pkg.piConfig ?? {};\nconst appConfigName: string | undefined = appConfig.name;\nexport const PACKAGE_NAME: string = pkg.name || \"@kolisachint/hoocode-agent\";\nexport const APP_NAME: string = appConfigName || \"hoocode\";\nexport const APP_TITLE: string = appConfigName ? APP_NAME : \"HooCode\";\nexport const CONFIG_DIR_NAME: string = appConfig.configDir || \".hoocode\";\nexport const VERSION: string = pkg.version || \"0.0.0\";\n\n// e.g., HOOCODE_CODING_AGENT_DIR\nexport const ENV_AGENT_DIR = `${APP_NAME.toUpperCase()}_CODING_AGENT_DIR`;\nexport const ENV_SESSION_DIR = `${APP_NAME.toUpperCase()}_CODING_AGENT_SESSION_DIR`;\n\nexport function expandTildePath(path: string): string {\n\tif (path === \"~\") return homedir();\n\tif (path.startsWith(\"~/\")) return homedir() + path.slice(1);\n\treturn path;\n}\n\nconst DEFAULT_SHARE_VIEWER_URL = \"https://hoocode.dev/session/\";\n\n/** Get the share viewer URL for a gist ID */\nexport function getShareViewerUrl(gistId: string): string {\n\tconst baseUrl =\n\t\t(process.env.HOOCODE_SHARE_VIEWER_URL ?? process.env.PI_SHARE_VIEWER_URL) || DEFAULT_SHARE_VIEWER_URL;\n\treturn `${baseUrl}#${gistId}`;\n}\n\n// =============================================================================\n// User Config Paths (~/.hoocode/agent/*)\n// =============================================================================\n\n/** Get the agent config directory (e.g., ~/.hoocode/agent/) */\nexport function getAgentDir(): string {\n\tconst envDir = process.env[ENV_AGENT_DIR];\n\tif (envDir) {\n\t\treturn expandTildePath(envDir);\n\t}\n\treturn join(homedir(), CONFIG_DIR_NAME, \"agent\");\n}\n\n/** Subdirectory under the project config dir holding subagent runtime state\n * (result.json, output.json, dispatch-log.json, budget.json) per dispatch.\n * Kept separate from the `agents/` directory, which holds agent definitions. */\nexport const DISPATCH_DIR_NAME = \"dispatch\";\n\n/** Root directory for subagent runtime state within a project. */\nexport function getDispatchRoot(cwd: string): string {\n\treturn join(cwd, CONFIG_DIR_NAME, DISPATCH_DIR_NAME);\n}\n\n/** Per-task runtime directory for a single subagent dispatch. */\nexport function getDispatchTaskDir(cwd: string, taskId: string): string {\n\treturn join(getDispatchRoot(cwd), taskId);\n}\n\n/** Get the hoocode config root directory (parent of agent dir).\n * Returns parent of getAgentDir(), e.g.:\n * HOOCODE_CODING_AGENT_DIR=/custom/agent -> /custom\n * (no env var) -> ~/.hoocode\n */\nexport function getHooCodeDir(): string {\n\treturn dirname(getAgentDir());\n}\n\n/** Get path to user's custom themes directory */\nexport function getCustomThemesDir(): string {\n\treturn join(getAgentDir(), \"themes\");\n}\n\n/** Get path to models.json */\nexport function getModelsPath(): string {\n\treturn join(getAgentDir(), \"models.json\");\n}\n\n/** Get path to auth.json */\nexport function getAuthPath(): string {\n\treturn join(getAgentDir(), \"auth.json\");\n}\n\n/** Get path to settings.json */\nexport function getSettingsPath(): string {\n\treturn join(getAgentDir(), \"settings.json\");\n}\n\n/** Get path to tools directory */\nexport function getToolsDir(): string {\n\treturn join(getAgentDir(), \"tools\");\n}\n\n/** Get path to managed binaries directory (fd, rg) */\nexport function getBinDir(): string {\n\treturn join(getAgentDir(), \"bin\");\n}\n\n/** Get path to prompt templates directory */\nexport function getPromptsDir(): string {\n\treturn join(getAgentDir(), \"prompts\");\n}\n\n/** Get path to sessions directory */\nexport function getSessionsDir(): string {\n\treturn join(getAgentDir(), \"sessions\");\n}\n\n/** Get path to debug log file */\nexport function getDebugLogPath(): string {\n\treturn join(getAgentDir(), `${APP_NAME}-debug.log`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GACvB,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CA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iD;AACjD,MAAM,UAAU,kBAAkB,GAAW;IAC5C,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;AAAA,CACrC;AAED,8BAA8B;AAC9B,MAAM,UAAU,aAAa,GAAW;IACvC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,aAAa,CAAC,CAAC;AAAA,CAC1C;AAED,4BAA4B;AAC5B,MAAM,UAAU,WAAW,GAAW;IACrC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,CAAC;AAAA,CACxC;AAED,gCAAgC;AAChC,MAAM,UAAU,eAAe,GAAW;IACzC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,eAAe,CAAC,CAAC;AAAA,CAC5C;AAED,kCAAkC;AAClC,MAAM,UAAU,WAAW,GAAW;IACrC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;AAAA,CACpC;AAED,sDAAsD;AACtD,MAAM,UAAU,SAAS,GAAW;IACnC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,CAAC;AAAA,CAClC;AAED,6CAA6C;AAC7C,MAAM,UAAU,aAAa,GAAW;IACvC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,SAAS,CAAC,CAAC;AAAA,CACtC;AAED,qCAAqC;AACrC,MAAM,UAAU,cAAc,GAAW;IACxC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,UAAU,CAAC,CAAC;AAAA,CACvC;AAED,iCAAiC;AACjC,MAAM,UAAU,eAAe,GAAW;IACzC,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,GAAG,QAAQ,YAAY,CAAC,CAAC;AAAA,CACpD","sourcesContent":["import { spawnSync } from \"child_process\";\nimport { accessSync, constants, existsSync, readFileSync, realpathSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { basename, dirname, join, resolve, sep, win32 } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { shouldUseWindowsShell } from \"./utils/child-process.js\";\n\n// =============================================================================\n// Package Detection\n// =============================================================================\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\n/**\n * Detect if we're running as a Bun compiled binary.\n * Bun binaries have import.meta.url containing \"$bunfs\", \"~BUN\", or \"%7EBUN\" (Bun's virtual filesystem path)\n */\nexport const isBunBinary =\n\timport.meta.url.includes(\"$bunfs\") || import.meta.url.includes(\"~BUN\") || import.meta.url.includes(\"%7EBUN\");\n\n/** Detect if Bun is the runtime (compiled binary or bun run) */\nexport const isBunRuntime = !!process.versions.bun;\n\n// =============================================================================\n// Install Method Detection\n// =============================================================================\n\nexport type InstallMethod = \"bun-binary\" | \"npm\" | \"pnpm\" | \"yarn\" | \"bun\" | \"unknown\";\n\ninterface SelfUpdateCommandStep {\n\tcommand: string;\n\targs: string[];\n\tdisplay: string;\n}\n\nexport interface SelfUpdateCommand extends SelfUpdateCommandStep {\n\tsteps?: SelfUpdateCommandStep[];\n}\n\nfunction makeSelfUpdateCommand(\n\tinstallStep: SelfUpdateCommandStep,\n\tuninstallStep?: SelfUpdateCommandStep,\n): SelfUpdateCommand {\n\tif (!uninstallStep) return installStep;\n\treturn {\n\t\t...installStep,\n\t\tdisplay: `${uninstallStep.display} && ${installStep.display}`,\n\t\tsteps: [uninstallStep, installStep],\n\t};\n}\n\nfunction makeSelfUpdateCommandStep(command: string, args: string[]): SelfUpdateCommandStep {\n\treturn {\n\t\tcommand,\n\t\targs,\n\t\tdisplay: [command, ...args].map((arg) => (/\\s/.test(arg) ? `\"${arg}\"` : arg)).join(\" \"),\n\t};\n}\n\nexport function detectInstallMethod(): InstallMethod {\n\tif (isBunBinary) {\n\t\treturn \"bun-binary\";\n\t}\n\n\tconst resolvedPath = `${__dirname}\\0${process.execPath || \"\"}`.toLowerCase().replace(/\\\\/g, \"/\");\n\n\tif (resolvedPath.includes(\"/pnpm/\") || resolvedPath.includes(\"/.pnpm/\")) {\n\t\treturn \"pnpm\";\n\t}\n\tif (resolvedPath.includes(\"/yarn/\") || resolvedPath.includes(\"/.yarn/\")) {\n\t\treturn \"yarn\";\n\t}\n\tif (isBunRuntime || resolvedPath.includes(\"/install/global/node_modules/\")) {\n\t\treturn \"bun\";\n\t}\n\tif (resolvedPath.includes(\"/npm/\") || resolvedPath.includes(\"/node_modules/\")) {\n\t\treturn \"npm\";\n\t}\n\n\treturn \"unknown\";\n}\n\nfunction getInferredNpmInstall(): { root: string; prefix: string } | undefined {\n\tconst packageDir = getPackageDir();\n\tconst path = process.platform === \"win32\" || packageDir.includes(\"\\\\\") ? win32 : { basename, dirname };\n\tconst parent = path.dirname(packageDir);\n\tlet root: string | undefined;\n\tif (path.basename(parent).startsWith(\"@\") && path.basename(path.dirname(parent)) === \"node_modules\") {\n\t\troot = path.dirname(parent);\n\t} else if (path.basename(parent) === \"node_modules\") {\n\t\troot = parent;\n\t}\n\tif (!root) return undefined;\n\tconst rootParent = path.dirname(root);\n\tif (path.basename(rootParent) === \"lib\") return { root, prefix: path.dirname(rootParent) };\n\t// Windows global npm prefixes use `<prefix>\\\\node_modules`, which is\n\t// indistinguishable from local project installs by path shape alone. Do not\n\t// infer unsupported Windows custom prefixes without `npm root -g` evidence.\n\treturn undefined;\n}\n\nfunction getSelfUpdateCommandForMethod(\n\tmethod: InstallMethod,\n\tinstalledPackageName: string,\n\tupdatePackageName = installedPackageName,\n\tnpmCommand?: string[],\n): SelfUpdateCommand | undefined {\n\tswitch (method) {\n\t\tcase \"bun-binary\":\n\t\t\treturn undefined;\n\t\tcase \"pnpm\":\n\t\t\treturn makeSelfUpdateCommand(\n\t\t\t\tmakeSelfUpdateCommandStep(\"pnpm\", [\"install\", \"-g\", updatePackageName]),\n\t\t\t\tupdatePackageName === installedPackageName\n\t\t\t\t\t? undefined\n\t\t\t\t\t: makeSelfUpdateCommandStep(\"pnpm\", [\"remove\", \"-g\", installedPackageName]),\n\t\t\t);\n\t\tcase \"yarn\":\n\t\t\treturn makeSelfUpdateCommand(\n\t\t\t\tmakeSelfUpdateCommandStep(\"yarn\", [\"global\", \"add\", updatePackageName]),\n\t\t\t\tupdatePackageName === installedPackageName\n\t\t\t\t\t? undefined\n\t\t\t\t\t: makeSelfUpdateCommandStep(\"yarn\", [\"global\", \"remove\", installedPackageName]),\n\t\t\t);\n\t\tcase \"bun\":\n\t\t\treturn makeSelfUpdateCommand(\n\t\t\t\tmakeSelfUpdateCommandStep(\"bun\", [\"install\", \"-g\", updatePackageName]),\n\t\t\t\tupdatePackageName === installedPackageName\n\t\t\t\t\t? undefined\n\t\t\t\t\t: makeSelfUpdateCommandStep(\"bun\", [\"uninstall\", \"-g\", installedPackageName]),\n\t\t\t);\n\t\tcase \"npm\": {\n\t\t\tconst [command = \"npm\", ...npmArgs] = npmCommand ?? [];\n\t\t\tconst inferred = npmCommand?.length ? undefined : getInferredNpmInstall();\n\t\t\tconst prefixArgs = [...npmArgs, ...(inferred ? [\"--prefix\", inferred.prefix] : [])];\n\t\t\tconst installStep = makeSelfUpdateCommandStep(command, [...prefixArgs, \"install\", \"-g\", updatePackageName]);\n\t\t\tconst uninstallStep =\n\t\t\t\tupdatePackageName === installedPackageName\n\t\t\t\t\t? undefined\n\t\t\t\t\t: makeSelfUpdateCommandStep(command, [...prefixArgs, \"uninstall\", \"-g\", installedPackageName]);\n\t\t\treturn makeSelfUpdateCommand(installStep, uninstallStep);\n\t\t}\n\t\tcase \"unknown\":\n\t\t\treturn undefined;\n\t}\n}\n\nfunction readCommandOutput(\n\tcommand: string,\n\targs: string[],\n\toptions: { requireSuccess?: boolean } = {},\n): string | undefined {\n\tconst result = spawnSync(command, args, {\n\t\tencoding: \"utf-8\",\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\tshell: shouldUseWindowsShell(command),\n\t});\n\tif (result.status === 0) return result.stdout.trim() || undefined;\n\tif (options.requireSuccess) {\n\t\tconst reason = result.error?.message || result.stderr.trim() || `exit code ${result.status ?? \"unknown\"}`;\n\t\tthrow new Error(`Failed to run ${[command, ...args].join(\" \")}: ${reason}`);\n\t}\n\treturn undefined;\n}\n\nfunction getGlobalPackageRoots(method: InstallMethod, _packageName: string, npmCommand?: string[]): string[] {\n\tswitch (method) {\n\t\tcase \"npm\": {\n\t\t\tconst configured = !!npmCommand?.length;\n\t\t\tconst [command = \"npm\", ...npmArgs] = npmCommand ?? [];\n\t\t\tif (configured && command === \"bun\") {\n\t\t\t\tconst bunBin = readCommandOutput(command, [...npmArgs, \"pm\", \"bin\", \"-g\"], {\n\t\t\t\t\trequireSuccess: true,\n\t\t\t\t});\n\t\t\t\tconst roots = [join(homedir(), \".bun\", \"install\", \"global\", \"node_modules\")];\n\t\t\t\tif (bunBin) {\n\t\t\t\t\troots.push(join(dirname(bunBin), \"install\", \"global\", \"node_modules\"));\n\t\t\t\t}\n\t\t\t\treturn roots;\n\t\t\t}\n\t\t\tconst root = readCommandOutput(command, [...npmArgs, \"root\", \"-g\"], {\n\t\t\t\trequireSuccess: configured,\n\t\t\t});\n\t\t\tconst inferred = configured ? undefined : getInferredNpmInstall();\n\t\t\treturn [root, inferred?.root].filter((x): x is string => !!x);\n\t\t}\n\t\tcase \"pnpm\": {\n\t\t\tconst root = readCommandOutput(\"pnpm\", [\"root\", \"-g\"]);\n\t\t\treturn root ? [root, dirname(root)] : [];\n\t\t}\n\t\tcase \"yarn\": {\n\t\t\tconst dir = readCommandOutput(\"yarn\", [\"global\", \"dir\"]);\n\t\t\treturn dir ? [dir, join(dir, \"node_modules\")] : [];\n\t\t}\n\t\tcase \"bun\": {\n\t\t\tconst bunBin = readCommandOutput(\"bun\", [\"pm\", \"bin\", \"-g\"]);\n\t\t\tconst roots = [join(homedir(), \".bun\", \"install\", \"global\", \"node_modules\")];\n\t\t\tif (bunBin) {\n\t\t\t\troots.push(join(dirname(bunBin), \"install\", \"global\", \"node_modules\"));\n\t\t\t}\n\t\t\treturn roots;\n\t\t}\n\t\tcase \"bun-binary\":\n\t\tcase \"unknown\":\n\t\t\treturn [];\n\t}\n}\n\nfunction normalizeExistingPathForComparison(path: string): string | undefined {\n\tconst resolvedPath = resolve(path);\n\tif (!existsSync(resolvedPath)) {\n\t\treturn undefined;\n\t}\n\tlet normalizedPath: string;\n\ttry {\n\t\tnormalizedPath = realpathSync(resolvedPath);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (process.platform === \"win32\") {\n\t\tnormalizedPath = normalizedPath.toLowerCase();\n\t}\n\treturn normalizedPath;\n}\n\nfunction isSelfUpdatePathWritable(): boolean {\n\tconst packageDir = getPackageDir();\n\ttry {\n\t\taccessSync(packageDir, constants.W_OK);\n\t\taccessSync(dirname(packageDir), constants.W_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction isManagedByGlobalPackageManager(method: InstallMethod, packageName: string, npmCommand?: string[]): boolean {\n\tconst packageDir = normalizeExistingPathForComparison(getPackageDir());\n\treturn (\n\t\t!!packageDir &&\n\t\tgetGlobalPackageRoots(method, packageName, npmCommand).some((root) => {\n\t\t\tconst normalizedRoot = normalizeExistingPathForComparison(root);\n\t\t\treturn (\n\t\t\t\t!!normalizedRoot &&\n\t\t\t\tpackageDir.startsWith(normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`)\n\t\t\t);\n\t\t})\n\t);\n}\n\nexport function getSelfUpdateCommand(\n\tpackageName: string,\n\tnpmCommand?: string[],\n\tupdatePackageName = packageName,\n): SelfUpdateCommand | undefined {\n\tconst method = detectInstallMethod();\n\tconst command = getSelfUpdateCommandForMethod(method, packageName, updatePackageName, npmCommand);\n\tif (!command || !isManagedByGlobalPackageManager(method, packageName, npmCommand) || !isSelfUpdatePathWritable()) {\n\t\treturn undefined;\n\t}\n\treturn command;\n}\n\nexport function getSelfUpdateUnavailableInstruction(\n\tpackageName: string,\n\tnpmCommand?: string[],\n\tupdatePackageName = packageName,\n): string {\n\tconst method = detectInstallMethod();\n\tif (method === \"bun-binary\") {\n\t\treturn `Download from: https://github.com/kolisachint/hoocode/releases/latest`;\n\t}\n\tconst command = getSelfUpdateCommandForMethod(method, packageName, updatePackageName, npmCommand);\n\tif (command) {\n\t\tif (isManagedByGlobalPackageManager(method, packageName, npmCommand) && !isSelfUpdatePathWritable()) {\n\t\t\treturn `This installation is managed by a global ${method} install, but the install path is not writable. Update it yourself with: ${command.display}`;\n\t\t}\n\t\treturn `This installation is not managed by a global ${method} install. Update it with the package manager, wrapper, or source checkout that provides it.`;\n\t}\n\treturn `Update ${updatePackageName} using the package manager, wrapper, or source checkout that provides this installation.`;\n}\n\nexport function getUpdateInstruction(packageName: string): string {\n\tconst method = detectInstallMethod();\n\tconst command = getSelfUpdateCommandForMethod(method, packageName);\n\tif (command) {\n\t\treturn `Run: ${command.display}`;\n\t}\n\treturn getSelfUpdateUnavailableInstruction(packageName);\n}\n\n// =============================================================================\n// Package Asset Paths (shipped with executable)\n// =============================================================================\n\n/**\n * Get the base directory for resolving package assets (themes, package.json, README.md, CHANGELOG.md).\n * - For Bun binary: returns the directory containing the executable\n * - For Node.js (dist/): returns __dirname (the dist/ directory)\n * - For tsx (src/): returns parent directory (the package root)\n */\nexport function getPackageDir(): string {\n\t// Allow override via environment variable (useful for Nix/Guix where store paths tokenize poorly)\n\tconst envDir = process.env.HOOCODE_PACKAGE_DIR ?? process.env.PI_PACKAGE_DIR;\n\tif (envDir) {\n\t\tif (envDir === \"~\") return homedir();\n\t\tif (envDir.startsWith(\"~/\")) return homedir() + envDir.slice(1);\n\t\treturn envDir;\n\t}\n\n\tif (isBunBinary) {\n\t\t// Bun binary: process.execPath points to the compiled executable\n\t\treturn dirname(process.execPath);\n\t}\n\t// Node.js: walk up from __dirname until we find package.json\n\tlet dir = __dirname;\n\twhile (dir !== dirname(dir)) {\n\t\tif (existsSync(join(dir, \"package.json\"))) {\n\t\t\treturn dir;\n\t\t}\n\t\tdir = dirname(dir);\n\t}\n\t// Fallback (shouldn't happen)\n\treturn __dirname;\n}\n\n/**\n * Get path to built-in themes directory (shipped with package)\n * - For Bun binary: theme/ next to executable\n * - For Node.js (dist/): dist/modes/interactive/theme/\n * - For tsx (src/): src/modes/interactive/theme/\n */\nexport function getThemesDir(): string {\n\tif (isBunBinary) {\n\t\treturn join(getPackageDir(), \"theme\");\n\t}\n\t// Theme is in modes/interactive/theme/ relative to src/ or dist/\n\tconst packageDir = getPackageDir();\n\tconst srcOrDist = existsSync(join(packageDir, \"src\")) ? \"src\" : \"dist\";\n\treturn join(packageDir, srcOrDist, \"modes\", \"interactive\", \"theme\");\n}\n\n/**\n * Get path to HTML export template directory (shipped with package)\n * - For Bun binary: export-html/ next to executable\n * - For Node.js (dist/): dist/core/export-html/\n * - For tsx (src/): src/core/export-html/\n */\nexport function getExportTemplateDir(): string {\n\tif (isBunBinary) {\n\t\treturn join(getPackageDir(), \"export-html\");\n\t}\n\tconst packageDir = getPackageDir();\n\tconst srcOrDist = existsSync(join(packageDir, \"src\")) ? \"src\" : \"dist\";\n\treturn join(packageDir, srcOrDist, \"core\", \"export-html\");\n}\n\n/** Get path to package.json */\nexport function getPackageJsonPath(): string {\n\treturn join(getPackageDir(), \"package.json\");\n}\n\n/** Get path to README.md */\nexport function getReadmePath(): string {\n\treturn resolve(join(getPackageDir(), \"README.md\"));\n}\n\n/** Get path to docs directory */\nexport function getDocsPath(): string {\n\treturn resolve(join(getPackageDir(), \"docs\"));\n}\n\n/** Get path to examples directory */\nexport function getExamplesPath(): string {\n\treturn resolve(join(getPackageDir(), \"examples\"));\n}\n\n/** Get path to CHANGELOG.md */\nexport function getChangelogPath(): string {\n\treturn resolve(join(getPackageDir(), \"CHANGELOG.md\"));\n}\n\n/**\n * Get path to built-in interactive assets directory.\n * - For Bun binary: assets/ next to executable\n * - For Node.js (dist/): dist/modes/interactive/assets/\n * - For tsx (src/): src/modes/interactive/assets/\n */\nexport function getInteractiveAssetsDir(): string {\n\tif (isBunBinary) {\n\t\treturn join(getPackageDir(), \"assets\");\n\t}\n\tconst packageDir = getPackageDir();\n\tconst srcOrDist = existsSync(join(packageDir, \"src\")) ? \"src\" : \"dist\";\n\treturn join(packageDir, srcOrDist, \"modes\", \"interactive\", \"assets\");\n}\n\n/** Get path to a bundled interactive asset */\nexport function getBundledInteractiveAssetPath(name: string): string {\n\treturn join(getInteractiveAssetsDir(), name);\n}\n\n/**\n * Resolve the command used to spawn a hoocode subagent child process by\n * re-running the current process.\n *\n * - Bun binary: the compiled executable spawns itself (argv[1] is not a script).\n * - Node.js / tsx: spawn the current runtime (process.execPath) replaying the\n * runtime flags (process.execArgv, e.g. tsx's `--import`) and the entry script\n * that launched this process (process.argv[1]).\n *\n * This mirrors exactly how the parent was started, so it works whether running\n * from dist/, from source via tsx, or as a packaged binary.\n */\nexport function getSubagentSpawnCommand(): { executable: string; prefixArgs: string[] } {\n\tif (isBunBinary) {\n\t\treturn { executable: process.execPath, prefixArgs: [] };\n\t}\n\tconst entry = process.argv[1];\n\tconst prefixArgs = [...process.execArgv];\n\tif (entry) prefixArgs.push(entry);\n\treturn { executable: process.execPath, prefixArgs };\n}\n\n/**\n * Get path to bundled init templates (default modes/profiles seeded into HOOCODE_DIR on first run).\n * - For Bun binary: templates/ next to executable\n * - For Node.js (dist/) and tsx (src/): templates/ at the package root\n */\nexport function getTemplatesDir(): string {\n\treturn join(getPackageDir(), \"templates\");\n}\n\n// =============================================================================\n// App Config (from package.json hoocodeConfig — accepts legacy piConfig)\n// =============================================================================\n\ninterface AppConfigBlock {\n\tname?: string;\n\tconfigDir?: string;\n}\n\ninterface PackageJson {\n\tname?: string;\n\tversion?: string;\n\thoocodeConfig?: AppConfigBlock;\n\tpiConfig?: AppConfigBlock;\n}\n\nconst pkg = JSON.parse(readFileSync(getPackageJsonPath(), \"utf-8\")) as PackageJson;\n\nconst appConfig: AppConfigBlock = pkg.hoocodeConfig ?? pkg.piConfig ?? {};\nconst appConfigName: string | undefined = appConfig.name;\nexport const PACKAGE_NAME: string = pkg.name || \"@kolisachint/hoocode-agent\";\nexport const APP_NAME: string = appConfigName || \"hoocode\";\nexport const APP_TITLE: string = appConfigName ? APP_NAME : \"HooCode\";\nexport const CONFIG_DIR_NAME: string = appConfig.configDir || \".hoocode\";\nexport const VERSION: string = pkg.version || \"0.0.0\";\n\n// e.g., HOOCODE_CODING_AGENT_DIR\nexport const ENV_AGENT_DIR = `${APP_NAME.toUpperCase()}_CODING_AGENT_DIR`;\nexport const ENV_SESSION_DIR = `${APP_NAME.toUpperCase()}_CODING_AGENT_SESSION_DIR`;\n\nexport function expandTildePath(path: string): string {\n\tif (path === \"~\") return homedir();\n\tif (path.startsWith(\"~/\")) return homedir() + path.slice(1);\n\treturn path;\n}\n\nconst DEFAULT_SHARE_VIEWER_URL = \"https://hoocode.dev/session/\";\n\n/** Get the share viewer URL for a gist ID */\nexport function getShareViewerUrl(gistId: string): string {\n\tconst baseUrl =\n\t\t(process.env.HOOCODE_SHARE_VIEWER_URL ?? process.env.PI_SHARE_VIEWER_URL) || DEFAULT_SHARE_VIEWER_URL;\n\treturn `${baseUrl}#${gistId}`;\n}\n\n// =============================================================================\n// User Config Paths (~/.hoocode/*)\n// =============================================================================\n\n/** Get the agent config directory (e.g., ~/.hoocode/) */\nexport function getAgentDir(): string {\n\tconst envDir = process.env[ENV_AGENT_DIR];\n\tif (envDir) {\n\t\treturn expandTildePath(envDir);\n\t}\n\treturn join(homedir(), CONFIG_DIR_NAME);\n}\n\n/** Subdirectory under the project config dir holding subagent runtime state\n * (result.json, output.json, dispatch-log.json, budget.json) per dispatch.\n * Kept separate from the `agents/` directory, which holds agent definitions. */\nexport const DISPATCH_DIR_NAME = \"dispatch\";\n\n/** Root directory for subagent runtime state within a project. */\nexport function getDispatchRoot(cwd: string): string {\n\treturn join(cwd, CONFIG_DIR_NAME, DISPATCH_DIR_NAME);\n}\n\n/** Per-task runtime directory for a single subagent dispatch. */\nexport function getDispatchTaskDir(cwd: string, taskId: string): string {\n\treturn join(getDispatchRoot(cwd), taskId);\n}\n\n/** Get the hoocode config root directory (e.g., ~/.hoocode/). Equivalent to getAgentDir(). */\nexport function getHooCodeDir(): string {\n\treturn getAgentDir();\n}\n\n/** Get path to user's custom themes directory */\nexport function getCustomThemesDir(): string {\n\treturn join(getAgentDir(), \"themes\");\n}\n\n/** Get path to models.json */\nexport function getModelsPath(): string {\n\treturn join(getAgentDir(), \"models.json\");\n}\n\n/** Get path to auth.json */\nexport function getAuthPath(): string {\n\treturn join(getAgentDir(), \"auth.json\");\n}\n\n/** Get path to settings.json */\nexport function getSettingsPath(): string {\n\treturn join(getAgentDir(), \"settings.json\");\n}\n\n/** Get path to tools directory */\nexport function getToolsDir(): string {\n\treturn join(getAgentDir(), \"tools\");\n}\n\n/** Get path to managed binaries directory (fd, rg) */\nexport function getBinDir(): string {\n\treturn join(getAgentDir(), \"bin\");\n}\n\n/** Get path to prompt templates directory */\nexport function getPromptsDir(): string {\n\treturn join(getAgentDir(), \"prompts\");\n}\n\n/** Get path to sessions directory */\nexport function getSessionsDir(): string {\n\treturn join(getAgentDir(), \"sessions\");\n}\n\n/** Get path to debug log file */\nexport function getDebugLogPath(): string {\n\treturn join(getAgentDir(), `${APP_NAME}-debug.log`);\n}\n"]}
|
|
@@ -78,6 +78,9 @@ export interface AgentDefinition {
|
|
|
78
78
|
* Normalize a raw `tools` allowlist into hoocode tool names via the Claude Code
|
|
79
79
|
* alias map. Returns the deduped, resolved list plus diagnostics for any tokens
|
|
80
80
|
* that could not be mapped.
|
|
81
|
+
*
|
|
82
|
+
* Emits a warning when `value` is a YAML list rather than a comma-separated
|
|
83
|
+
* string — the Claude Code standard format is `tools: read, bash` (string).
|
|
81
84
|
*/
|
|
82
85
|
export declare function normalizeTools(value: string | string[], filePath?: string): {
|
|
83
86
|
tools: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-frontmatter.d.ts","sourceRoot":"","sources":["../../src/core/agent-frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBA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c,CAC7B,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EACxB,QAAQ,CAAC,EAAE,MAAM,GACf;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAkBxD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAK5E;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACxE;IAAE,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAmEtE","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\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\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 */\nexport function normalizeTools(\n\tvalue: string | string[],\n\tfilePath?: string,\n): { tools: string[]; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\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\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\tconst background = frontmatter.background === true ? true : undefined;\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.d.ts","sourceRoot":"","sources":["../../src/core/agent-frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAQ3D,gFAAgF;AAChF,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,aAAa,GAAG,gBAAgB,CAAC;AAE5F,wFAAwF;AACxF,eAAO,MAAM,aAAa,YAAY,CA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0BxD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAK5E;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACxE;IAAE,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAmFtE","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"]}
|
|
@@ -47,6 +47,7 @@ export const CLAUDE_TOOL_ALIASES = {
|
|
|
47
47
|
find: "find",
|
|
48
48
|
ls: "ls",
|
|
49
49
|
};
|
|
50
|
+
const KNOWN_MODEL_ALIASES = new Set(["sonnet", "opus", "haiku", "inherit"]);
|
|
50
51
|
/** Validate an agent name. Returns warning messages (empty when valid). */
|
|
51
52
|
function validateName(name) {
|
|
52
53
|
const errors = [];
|
|
@@ -79,6 +80,18 @@ function validateDescription(description) {
|
|
|
79
80
|
}
|
|
80
81
|
return errors;
|
|
81
82
|
}
|
|
83
|
+
function validateModel(value) {
|
|
84
|
+
const trimmed = value.trim();
|
|
85
|
+
if (!trimmed)
|
|
86
|
+
return [];
|
|
87
|
+
if (KNOWN_MODEL_ALIASES.has(trimmed))
|
|
88
|
+
return [];
|
|
89
|
+
if (/^claude-/.test(trimmed))
|
|
90
|
+
return [];
|
|
91
|
+
return [
|
|
92
|
+
`model "${trimmed}" is not a recognized Claude alias (sonnet | opus | haiku | inherit) or full model ID (claude-*); the agent may not load correctly`,
|
|
93
|
+
];
|
|
94
|
+
}
|
|
82
95
|
/** Split a `tools` frontmatter value (string or list) into raw token names. */
|
|
83
96
|
function splitToolsValue(value) {
|
|
84
97
|
const tokens = Array.isArray(value) ? value : value.split(",");
|
|
@@ -88,9 +101,19 @@ function splitToolsValue(value) {
|
|
|
88
101
|
* Normalize a raw `tools` allowlist into hoocode tool names via the Claude Code
|
|
89
102
|
* alias map. Returns the deduped, resolved list plus diagnostics for any tokens
|
|
90
103
|
* that could not be mapped.
|
|
104
|
+
*
|
|
105
|
+
* Emits a warning when `value` is a YAML list rather than a comma-separated
|
|
106
|
+
* string — the Claude Code standard format is `tools: read, bash` (string).
|
|
91
107
|
*/
|
|
92
108
|
export function normalizeTools(value, filePath) {
|
|
93
109
|
const diagnostics = [];
|
|
110
|
+
if (Array.isArray(value)) {
|
|
111
|
+
diagnostics.push({
|
|
112
|
+
type: "warning",
|
|
113
|
+
message: 'tools: use a comma-separated string ("tools: read, bash") instead of a YAML list for Claude Code compatibility',
|
|
114
|
+
path: filePath,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
94
117
|
const resolved = [];
|
|
95
118
|
for (const raw of splitToolsValue(value)) {
|
|
96
119
|
const mapped = CLAUDE_TOOL_ALIASES[raw.toLowerCase()];
|
|
@@ -167,10 +190,27 @@ export function parseAgentDefinition(rawContent, options) {
|
|
|
167
190
|
tools = normalized.tools;
|
|
168
191
|
}
|
|
169
192
|
const model = normalizeModel(frontmatter.model);
|
|
193
|
+
if (model !== undefined) {
|
|
194
|
+
for (const error of validateModel(model)) {
|
|
195
|
+
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
170
198
|
const maxTurns = typeof frontmatter.maxTurns === "number" && Number.isInteger(frontmatter.maxTurns) && frontmatter.maxTurns > 0
|
|
171
199
|
? frontmatter.maxTurns
|
|
172
200
|
: undefined;
|
|
173
|
-
|
|
201
|
+
let background;
|
|
202
|
+
if (frontmatter.background !== undefined) {
|
|
203
|
+
if (typeof frontmatter.background !== "boolean") {
|
|
204
|
+
diagnostics.push({
|
|
205
|
+
type: "warning",
|
|
206
|
+
message: `background must be a boolean (true or false), got "${frontmatter.background}" — field ignored`,
|
|
207
|
+
path: filePath,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
background = frontmatter.background === true ? true : undefined;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
174
214
|
return {
|
|
175
215
|
agent: {
|
|
176
216
|
name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-frontmatter.js","sourceRoot":"","sources":["../../src/core/agent-frontmatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,4CAA4C;AAC5C,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,mDAAmD;AACnD,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAKpC,wFAAwF;AACxF,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7G;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAqC;IACpE,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,IAAI;CACR,CAAC;AA2CF,2EAA2E;AAC3E,SAAS,YAAY,CAAC,IAAY,EAAY;IAC7C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC;IACf,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;QACnC,MAAM,CAAC,IAAI,CAAC,gBAAgB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;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\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\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 */\nexport function normalizeTools(\n\tvalue: string | string[],\n\tfilePath?: string,\n): { tools: string[]; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\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\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\tconst background = frontmatter.background === true ? true : undefined;\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;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,4CAA4C;AAC5C,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,mDAAmD;AACnD,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAKpC,wFAAwF;AACxF,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7G;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAqC;IACpE,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,IAAI;CACR,CAAC;AA2CF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,CA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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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-level stores for agent paths:
|
|
3
|
+
*
|
|
4
|
+
* manifestPaths — agents declared via `hoocode.agents` in package.json,
|
|
5
|
+
* refreshed on every DefaultResourceLoader.reload().
|
|
6
|
+
* cliPaths — agents injected via `--agent <path>` at startup,
|
|
7
|
+
* set once and never cleared across reloads.
|
|
8
|
+
*/
|
|
9
|
+
/** Replace the stored manifest paths (called by DefaultResourceLoader.reload). */
|
|
10
|
+
export declare function setAgentManifestPaths(paths: string[]): void;
|
|
11
|
+
/** Return the current manifest paths. */
|
|
12
|
+
export declare function getAgentManifestPaths(): string[];
|
|
13
|
+
/** Set CLI-injected agent paths (called once at startup from main). */
|
|
14
|
+
export declare function setAgentCliPaths(paths: string[]): void;
|
|
15
|
+
/** Return the CLI-injected agent paths. */
|
|
16
|
+
export declare function getAgentCliPaths(): string[];
|
|
17
|
+
//# sourceMappingURL=agent-manifest-paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-manifest-paths.d.ts","sourceRoot":"","sources":["../../src/core/agent-manifest-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAE3D;AAED,yCAAyC;AACzC,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD;AAED,uEAAuE;AACvE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAEtD;AAED,2CAA2C;AAC3C,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C","sourcesContent":["/**\n * Module-level stores for agent paths:\n *\n * manifestPaths — agents declared via `hoocode.agents` in package.json,\n * refreshed on every DefaultResourceLoader.reload().\n * cliPaths — agents injected via `--agent <path>` at startup,\n * set once and never cleared across reloads.\n */\n\nlet manifestPaths: string[] = [];\nlet cliPaths: string[] = [];\n\n/** Replace the stored manifest paths (called by DefaultResourceLoader.reload). */\nexport function setAgentManifestPaths(paths: string[]): void {\n\tmanifestPaths = [...paths];\n}\n\n/** Return the current manifest paths. */\nexport function getAgentManifestPaths(): string[] {\n\treturn [...manifestPaths];\n}\n\n/** Set CLI-injected agent paths (called once at startup from main). */\nexport function setAgentCliPaths(paths: string[]): void {\n\tcliPaths = [...paths];\n}\n\n/** Return the CLI-injected agent paths. */\nexport function getAgentCliPaths(): string[] {\n\treturn [...cliPaths];\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-level stores for agent paths:
|
|
3
|
+
*
|
|
4
|
+
* manifestPaths — agents declared via `hoocode.agents` in package.json,
|
|
5
|
+
* refreshed on every DefaultResourceLoader.reload().
|
|
6
|
+
* cliPaths — agents injected via `--agent <path>` at startup,
|
|
7
|
+
* set once and never cleared across reloads.
|
|
8
|
+
*/
|
|
9
|
+
let manifestPaths = [];
|
|
10
|
+
let cliPaths = [];
|
|
11
|
+
/** Replace the stored manifest paths (called by DefaultResourceLoader.reload). */
|
|
12
|
+
export function setAgentManifestPaths(paths) {
|
|
13
|
+
manifestPaths = [...paths];
|
|
14
|
+
}
|
|
15
|
+
/** Return the current manifest paths. */
|
|
16
|
+
export function getAgentManifestPaths() {
|
|
17
|
+
return [...manifestPaths];
|
|
18
|
+
}
|
|
19
|
+
/** Set CLI-injected agent paths (called once at startup from main). */
|
|
20
|
+
export function setAgentCliPaths(paths) {
|
|
21
|
+
cliPaths = [...paths];
|
|
22
|
+
}
|
|
23
|
+
/** Return the CLI-injected agent paths. */
|
|
24
|
+
export function getAgentCliPaths() {
|
|
25
|
+
return [...cliPaths];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=agent-manifest-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-manifest-paths.js","sourceRoot":"","sources":["../../src/core/agent-manifest-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,IAAI,aAAa,GAAa,EAAE,CAAC;AACjC,IAAI,QAAQ,GAAa,EAAE,CAAC;AAE5B,kFAAkF;AAClF,MAAM,UAAU,qBAAqB,CAAC,KAAe,EAAQ;IAC5D,aAAa,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;AAAA,CAC3B;AAED,yCAAyC;AACzC,MAAM,UAAU,qBAAqB,GAAa;IACjD,OAAO,CAAC,GAAG,aAAa,CAAC,CAAC;AAAA,CAC1B;AAED,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAAC,KAAe,EAAQ;IACvD,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;AAAA,CACtB;AAED,2CAA2C;AAC3C,MAAM,UAAU,gBAAgB,GAAa;IAC5C,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;AAAA,CACrB","sourcesContent":["/**\n * Module-level stores for agent paths:\n *\n * manifestPaths — agents declared via `hoocode.agents` in package.json,\n * refreshed on every DefaultResourceLoader.reload().\n * cliPaths — agents injected via `--agent <path>` at startup,\n * set once and never cleared across reloads.\n */\n\nlet manifestPaths: string[] = [];\nlet cliPaths: string[] = [];\n\n/** Replace the stored manifest paths (called by DefaultResourceLoader.reload). */\nexport function setAgentManifestPaths(paths: string[]): void {\n\tmanifestPaths = [...paths];\n}\n\n/** Return the current manifest paths. */\nexport function getAgentManifestPaths(): string[] {\n\treturn [...manifestPaths];\n}\n\n/** Set CLI-injected agent paths (called once at startup from main). */\nexport function setAgentCliPaths(paths: string[]): void {\n\tcliPaths = [...paths];\n}\n\n/** Return the CLI-injected agent paths. */\nexport function getAgentCliPaths(): string[] {\n\treturn [...cliPaths];\n}\n"]}
|
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
* increasing order of precedence:
|
|
7
7
|
*
|
|
8
8
|
* 1. builtin embedded templates (EMBEDDED_AGENT_PROMPTS)
|
|
9
|
-
* 2.
|
|
10
|
-
* 3. user
|
|
11
|
-
* 4.
|
|
12
|
-
* 5.
|
|
9
|
+
* 2. package-manifest paths from hoocode.agents in package.json
|
|
10
|
+
* 3. claude-user ~/.claude/agents/*.md (D7 native import)
|
|
11
|
+
* 4. user ~/.hoocode/agents/*.md
|
|
12
|
+
* 5. ancestor-walk <git-root..cwd>/.agents/agents/*.md
|
|
13
|
+
* 6. claude-project <cwd>/.claude/agents/*.md (D7 native import)
|
|
14
|
+
* 7. project <cwd>/.hoocode/agents/*.md
|
|
15
|
+
* 8. cli paths injected via --agent <path>
|
|
13
16
|
*
|
|
14
17
|
* Higher-precedence sources override lower ones by name. Overrides are recorded
|
|
15
18
|
* as collision diagnostics. Loading never throws; problems surface as
|
|
@@ -38,15 +41,19 @@ export declare class AgentRegistry {
|
|
|
38
41
|
export interface LoadAgentRegistryOptions {
|
|
39
42
|
/** Working directory for project-local agents. */
|
|
40
43
|
cwd: string;
|
|
41
|
-
/** User agent config directory (
|
|
44
|
+
/** User agent config directory (contains `agents/` subdir). Defaults to getAgentDir(). */
|
|
42
45
|
agentDir?: string;
|
|
43
46
|
/** Include embedded built-in agents. Defaults to true. */
|
|
44
47
|
includeBuiltins?: boolean;
|
|
45
48
|
/** Discover `.claude/agents/` directories for native Claude Code import (D7). Defaults to true. */
|
|
46
49
|
includeClaude?: boolean;
|
|
47
50
|
}
|
|
51
|
+
/** Build an AgentRegistry from all configured locations, applying precedence. */
|
|
52
|
+
export declare function loadAgentRegistry(options: LoadAgentRegistryOptions): AgentRegistry;
|
|
48
53
|
/**
|
|
49
|
-
*
|
|
54
|
+
* Format a list of agent definitions as an XML block for inclusion in a system
|
|
55
|
+
* prompt, mirroring the `<available_skills>` format used by formatSkillsForPrompt.
|
|
56
|
+
* Only intended for display when the Task tool is active.
|
|
50
57
|
*/
|
|
51
|
-
export declare function
|
|
58
|
+
export declare function formatAgentsForPrompt(agents: AgentDefinition[]): string;
|
|
52
59
|
//# sourceMappingURL=agent-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-registry.d.ts","sourceRoot":"","sources":["../../src/core/agent-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,OAAO,EAAE,KAAK,eAAe,EAA0C,MAAM,wBAAwB,CAAC;AACtG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,mDAAmD;AACnD,qBAAa,aAAa;IACzB,OAAO,CAAC,MAAM,CAAsC;IACpD,OAAO,CAAC,WAAW,CAA4B;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAkBnC;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAE7C;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzB;IAED,IAAI,IAAI,eAAe,EAAE,CAExB;IAED,2DAA2D;IAC3D,cAAc,IAAI,kBAAkB,EAAE,CAErC;IAED,uEAAuE;IACvE,cAAc,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAEtD;CACD;AAqCD,MAAM,WAAW,wBAAwB;IACxC,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mGAAmG;IACnG,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa,CAmBlF","sourcesContent":["/**\n * Agent registry: data-driven loading of subagent definitions.\n *\n * Replaces the hardcoded `SubagentMode` enum + `MODE_TOOLS` map with frontmatter\n * `.md` files (see agent-frontmatter.ts). Definitions are discovered from, in\n * increasing order of precedence:\n *\n * 1. builtin embedded templates (EMBEDDED_AGENT_PROMPTS)\n * 2. claude-user ~/.claude/agents/*.md (D7 native import)\n * 3. user ~/.hoocode/agent/agents/*.md\n * 4. claude-project <cwd>/.claude/agents/*.md (D7 native import)\n * 5. project <cwd>/.hoocode/agents/*.md\n *\n * Higher-precedence sources override lower ones by name. Overrides are recorded\n * as collision diagnostics. Loading never throws; problems surface as\n * diagnostics, matching skills.ts.\n */\n\nimport { existsSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { join, resolve } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../config.js\";\nimport { EMBEDDED_AGENT_PROMPTS } from \"../init-templates.generated.js\";\nimport { type AgentDefinition, type AgentSource, parseAgentDefinition } from \"./agent-frontmatter.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\n\n/** Registry of agent definitions keyed by name. */\nexport class AgentRegistry {\n\tprivate agents = new Map<string, AgentDefinition>();\n\tprivate diagnostics: ResourceDiagnostic[] = [];\n\n\t/**\n\t * Add or override a definition. Later registrations win (used both by the\n\t * loader for precedence and as an escape hatch for programmatic agents).\n\t * Overriding an existing name records a collision diagnostic.\n\t */\n\tregister(def: AgentDefinition): void {\n\t\tconst existing = this.agents.get(def.name);\n\t\tif (existing) {\n\t\t\tthis.diagnostics.push({\n\t\t\t\ttype: \"collision\",\n\t\t\t\tmessage: `agent \"${def.name}\" from ${def.source} overrides ${existing.source}`,\n\t\t\t\tpath: def.filePath,\n\t\t\t\tcollision: {\n\t\t\t\t\tresourceType: \"skill\",\n\t\t\t\t\tname: def.name,\n\t\t\t\t\twinnerPath: def.filePath ?? `<${def.source}>`,\n\t\t\t\t\tloserPath: existing.filePath ?? `<${existing.source}>`,\n\t\t\t\t\twinnerSource: def.source,\n\t\t\t\t\tloserSource: existing.source,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tthis.agents.set(def.name, def);\n\t}\n\n\tget(name: string): AgentDefinition | undefined {\n\t\treturn this.agents.get(name);\n\t}\n\n\thas(name: string): boolean {\n\t\treturn this.agents.has(name);\n\t}\n\n\tlist(): AgentDefinition[] {\n\t\treturn Array.from(this.agents.values());\n\t}\n\n\t/** Diagnostics accumulated during loading/registration. */\n\tgetDiagnostics(): ResourceDiagnostic[] {\n\t\treturn this.diagnostics;\n\t}\n\n\t/** Append externally-produced diagnostics (e.g. from a parse step). */\n\taddDiagnostics(diagnostics: ResourceDiagnostic[]): void {\n\t\tthis.diagnostics.push(...diagnostics);\n\t}\n}\n\n/** Load and register every built-in (embedded) agent definition. */\nfunction registerBuiltins(registry: AgentRegistry): void {\n\tfor (const [key, raw] of Object.entries(EMBEDDED_AGENT_PROMPTS)) {\n\t\tconst { agent, diagnostics } = parseAgentDefinition(raw, { source: \"builtin\", fallbackName: key });\n\t\tregistry.addDiagnostics(diagnostics);\n\t\tif (agent) registry.register(agent);\n\t}\n}\n\n/** Load flat `*.md` agent files from a directory. Non-`.md` entries and\n * subdirectories are skipped (so runtime dispatch dirs are ignored). */\nfunction registerDir(registry: AgentRegistry, dir: string, source: AgentSource): void {\n\tif (!existsSync(dir)) return;\n\tlet entries: string[];\n\ttry {\n\t\tentries = readdirSync(dir);\n\t} catch {\n\t\treturn;\n\t}\n\tfor (const entry of entries) {\n\t\tif (entry.startsWith(\".\") || !entry.endsWith(\".md\")) continue;\n\t\tconst filePath = join(dir, entry);\n\t\ttry {\n\t\t\tif (!statSync(filePath).isFile()) continue;\n\t\t\tconst raw = readFileSync(filePath, \"utf-8\");\n\t\t\tconst { agent, diagnostics } = parseAgentDefinition(raw, { source, filePath });\n\t\t\tregistry.addDiagnostics(diagnostics);\n\t\t\tif (agent) registry.register(agent);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read agent file\";\n\t\t\tregistry.addDiagnostics([{ type: \"warning\", message, path: filePath }]);\n\t\t}\n\t}\n}\n\nexport interface LoadAgentRegistryOptions {\n\t/** Working directory for project-local agents. */\n\tcwd: string;\n\t/** User agent config directory (parent of `agents/`). Defaults to getAgentDir(). */\n\tagentDir?: string;\n\t/** Include embedded built-in agents. Defaults to true. */\n\tincludeBuiltins?: boolean;\n\t/** Discover `.claude/agents/` directories for native Claude Code import (D7). Defaults to true. */\n\tincludeClaude?: boolean;\n}\n\n/**\n * Build an AgentRegistry from all configured locations, applying precedence.\n */\nexport function loadAgentRegistry(options: LoadAgentRegistryOptions): AgentRegistry {\n\tconst { cwd, includeBuiltins = true, includeClaude = true } = options;\n\tconst userAgentDir = options.agentDir ?? getAgentDir();\n\tconst registry = new AgentRegistry();\n\n\t// Lowest precedence first; later sources override earlier ones by name.\n\tif (includeBuiltins) {\n\t\tregisterBuiltins(registry);\n\t}\n\tif (includeClaude) {\n\t\tregisterDir(registry, join(homedir(), \".claude\", \"agents\"), \"claude-user\");\n\t}\n\tregisterDir(registry, join(userAgentDir, \"agents\"), \"user\");\n\tif (includeClaude) {\n\t\tregisterDir(registry, resolve(cwd, \".claude\", \"agents\"), \"claude-project\");\n\t}\n\tregisterDir(registry, resolve(cwd, CONFIG_DIR_NAME, \"agents\"), \"project\");\n\n\treturn registry;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-registry.d.ts","sourceRoot":"","sources":["../../src/core/agent-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAOH,OAAO,EAAE,KAAK,eAAe,EAA0C,MAAM,wBAAwB,CAAC;AAEtG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,mDAAmD;AACnD,qBAAa,aAAa;IACzB,OAAO,CAAC,MAAM,CAAsC;IACpD,OAAO,CAAC,WAAW,CAA4B;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAkBnC;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAE7C;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzB;IAED,IAAI,IAAI,eAAe,EAAE,CAExB;IAED,2DAA2D;IAC3D,cAAc,IAAI,kBAAkB,EAAE,CAErC;IAED,uEAAuE;IACvE,cAAc,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAEtD;CACD;AA8ED,MAAM,WAAW,wBAAwB;IACxC,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,0FAA0F;IAC1F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mGAAmG;IACnG,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa,CA4ClF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CA0BvE","sourcesContent":["/**\n * Agent registry: data-driven loading of subagent definitions.\n *\n * Replaces the hardcoded `SubagentMode` enum + `MODE_TOOLS` map with frontmatter\n * `.md` files (see agent-frontmatter.ts). Definitions are discovered from, in\n * increasing order of precedence:\n *\n * 1. builtin embedded templates (EMBEDDED_AGENT_PROMPTS)\n * 2. package-manifest paths from hoocode.agents in package.json\n * 3. claude-user ~/.claude/agents/*.md (D7 native import)\n * 4. user ~/.hoocode/agents/*.md\n * 5. ancestor-walk <git-root..cwd>/.agents/agents/*.md\n * 6. claude-project <cwd>/.claude/agents/*.md (D7 native import)\n * 7. project <cwd>/.hoocode/agents/*.md\n * 8. cli paths injected via --agent <path>\n *\n * Higher-precedence sources override lower ones by name. Overrides are recorded\n * as collision diagnostics. Loading never throws; problems surface as\n * diagnostics, matching skills.ts.\n */\n\nimport { existsSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { dirname, join, resolve } from \"path\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../config.js\";\nimport { EMBEDDED_AGENT_PROMPTS } from \"../init-templates.generated.js\";\nimport { type AgentDefinition, type AgentSource, parseAgentDefinition } from \"./agent-frontmatter.js\";\nimport { getAgentCliPaths, getAgentManifestPaths } from \"./agent-manifest-paths.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\n\n/** Registry of agent definitions keyed by name. */\nexport class AgentRegistry {\n\tprivate agents = new Map<string, AgentDefinition>();\n\tprivate diagnostics: ResourceDiagnostic[] = [];\n\n\t/**\n\t * Add or override a definition. Later registrations win (used both by the\n\t * loader for precedence and as an escape hatch for programmatic agents).\n\t * Overriding an existing name records a collision diagnostic.\n\t */\n\tregister(def: AgentDefinition): void {\n\t\tconst existing = this.agents.get(def.name);\n\t\tif (existing) {\n\t\t\tthis.diagnostics.push({\n\t\t\t\ttype: \"collision\",\n\t\t\t\tmessage: `agent \"${def.name}\" from ${def.source} overrides ${existing.source}`,\n\t\t\t\tpath: def.filePath,\n\t\t\t\tcollision: {\n\t\t\t\t\tresourceType: \"skill\",\n\t\t\t\t\tname: def.name,\n\t\t\t\t\twinnerPath: def.filePath ?? `<${def.source}>`,\n\t\t\t\t\tloserPath: existing.filePath ?? `<${existing.source}>`,\n\t\t\t\t\twinnerSource: def.source,\n\t\t\t\t\tloserSource: existing.source,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tthis.agents.set(def.name, def);\n\t}\n\n\tget(name: string): AgentDefinition | undefined {\n\t\treturn this.agents.get(name);\n\t}\n\n\thas(name: string): boolean {\n\t\treturn this.agents.has(name);\n\t}\n\n\tlist(): AgentDefinition[] {\n\t\treturn Array.from(this.agents.values());\n\t}\n\n\t/** Diagnostics accumulated during loading/registration. */\n\tgetDiagnostics(): ResourceDiagnostic[] {\n\t\treturn this.diagnostics;\n\t}\n\n\t/** Append externally-produced diagnostics (e.g. from a parse step). */\n\taddDiagnostics(diagnostics: ResourceDiagnostic[]): void {\n\t\tthis.diagnostics.push(...diagnostics);\n\t}\n}\n\n/** Load and register every built-in (embedded) agent definition. */\nfunction registerBuiltins(registry: AgentRegistry): void {\n\tfor (const [key, raw] of Object.entries(EMBEDDED_AGENT_PROMPTS)) {\n\t\tconst { agent, diagnostics } = parseAgentDefinition(raw, { source: \"builtin\", fallbackName: key });\n\t\tregistry.addDiagnostics(diagnostics);\n\t\tif (agent) registry.register(agent);\n\t}\n}\n\n/** Load flat `*.md` agent files from a directory. Non-`.md` entries and\n * subdirectories are skipped (so runtime dispatch dirs are ignored). */\nfunction registerDir(registry: AgentRegistry, dir: string, source: AgentSource): void {\n\tif (!existsSync(dir)) return;\n\tlet entries: string[];\n\ttry {\n\t\tentries = readdirSync(dir);\n\t} catch {\n\t\treturn;\n\t}\n\tfor (const entry of entries) {\n\t\tif (entry.startsWith(\".\") || !entry.endsWith(\".md\")) continue;\n\t\tconst filePath = join(dir, entry);\n\t\ttry {\n\t\t\tif (!statSync(filePath).isFile()) continue;\n\t\t\tconst raw = readFileSync(filePath, \"utf-8\");\n\t\t\tconst { agent, diagnostics } = parseAgentDefinition(raw, { source, filePath });\n\t\t\tregistry.addDiagnostics(diagnostics);\n\t\t\tif (agent) registry.register(agent);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read agent file\";\n\t\t\tregistry.addDiagnostics([{ type: \"warning\", message, path: filePath }]);\n\t\t}\n\t}\n}\n\nfunction findGitRepoRoot(startDir: string): string | null {\n\tlet dir = resolve(startDir);\n\twhile (true) {\n\t\tif (existsSync(join(dir, \".git\"))) return dir;\n\t\tconst parent = dirname(dir);\n\t\tif (parent === dir) return null;\n\t\tdir = parent;\n\t}\n}\n\n/** Collect `.agents/agents/` dirs from cwd up to the git root (cwd-first order). */\nfunction collectAncestorAgentsDirs(startDir: string): string[] {\n\tconst dirs: string[] = [];\n\tconst resolvedStart = resolve(startDir);\n\tconst gitRoot = findGitRepoRoot(resolvedStart);\n\tlet dir = resolvedStart;\n\twhile (true) {\n\t\tdirs.push(join(dir, \".agents\", \"agents\"));\n\t\tif (gitRoot && dir === gitRoot) break;\n\t\tconst parent = dirname(dir);\n\t\tif (parent === dir) break;\n\t\tdir = parent;\n\t}\n\treturn dirs;\n}\n\n/** Register a single file as an agent. */\nfunction registerFile(registry: AgentRegistry, filePath: string, source: AgentSource): void {\n\tif (!existsSync(filePath)) return;\n\ttry {\n\t\tif (!statSync(filePath).isFile()) return;\n\t\tconst raw = readFileSync(filePath, \"utf-8\");\n\t\tconst { agent, diagnostics } = parseAgentDefinition(raw, { source, filePath });\n\t\tregistry.addDiagnostics(diagnostics);\n\t\tif (agent) registry.register(agent);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to read agent file\";\n\t\tregistry.addDiagnostics([{ type: \"warning\", message, path: filePath }]);\n\t}\n}\n\nexport interface LoadAgentRegistryOptions {\n\t/** Working directory for project-local agents. */\n\tcwd: string;\n\t/** User agent config directory (contains `agents/` subdir). Defaults to getAgentDir(). */\n\tagentDir?: string;\n\t/** Include embedded built-in agents. Defaults to true. */\n\tincludeBuiltins?: boolean;\n\t/** Discover `.claude/agents/` directories for native Claude Code import (D7). Defaults to true. */\n\tincludeClaude?: boolean;\n}\n\n/** Build an AgentRegistry from all configured locations, applying precedence. */\nexport function loadAgentRegistry(options: LoadAgentRegistryOptions): AgentRegistry {\n\tconst { cwd, includeBuiltins = true, includeClaude = true } = options;\n\tconst userAgentDir = options.agentDir ?? getAgentDir();\n\tconst registry = new AgentRegistry();\n\n\t// Lowest precedence first; later sources override earlier ones by name.\n\tif (includeBuiltins) {\n\t\tregisterBuiltins(registry);\n\t}\n\n\t// Package-manifest agents (declared via `hoocode.agents` in package.json).\n\tfor (const filePath of getAgentManifestPaths()) {\n\t\tregisterFile(registry, filePath, \"user\");\n\t}\n\n\tif (includeClaude) {\n\t\tregisterDir(registry, join(homedir(), \".claude\", \"agents\"), \"claude-user\");\n\t}\n\tregisterDir(registry, join(userAgentDir, \"agents\"), \"user\");\n\n\t// Ancestor-walk .agents/agents/ dirs (git-root first so cwd-level overrides ancestors).\n\tfor (const dir of collectAncestorAgentsDirs(cwd).reverse()) {\n\t\tregisterDir(registry, dir, \"project\");\n\t}\n\n\tif (includeClaude) {\n\t\tregisterDir(registry, resolve(cwd, \".claude\", \"agents\"), \"claude-project\");\n\t}\n\tregisterDir(registry, resolve(cwd, CONFIG_DIR_NAME, \"agents\"), \"project\");\n\n\t// CLI-injected paths have highest precedence (support both files and dirs).\n\tfor (const p of getAgentCliPaths()) {\n\t\tif (!existsSync(p)) {\n\t\t\tregistry.addDiagnostics([{ type: \"warning\", message: `Agent path does not exist: ${p}`, path: p }]);\n\t\t\tcontinue;\n\t\t}\n\t\tif (statSync(p).isDirectory()) {\n\t\t\tregisterDir(registry, p, \"user\");\n\t\t} else {\n\t\t\tregisterFile(registry, p, \"user\");\n\t\t}\n\t}\n\n\treturn registry;\n}\n\n/**\n * Format a list of agent definitions as an XML block for inclusion in a system\n * prompt, mirroring the `<available_skills>` format used by formatSkillsForPrompt.\n * Only intended for display when the Task tool is active.\n */\nexport function formatAgentsForPrompt(agents: AgentDefinition[]): string {\n\tif (agents.length === 0) return \"\";\n\n\tconst lines = [\n\t\t\"\\n\\nThe following specialized agents are available for delegation via the Task tool.\",\n\t\t\"Choose the agent whose description best matches the task and pass it as `subagent_type`.\",\n\t\t\"\",\n\t\t\"<available_agents>\",\n\t];\n\n\tfor (const agent of agents) {\n\t\tlines.push(\" <agent>\");\n\t\tlines.push(` <name>${escapeXml(agent.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(agent.description)}</description>`);\n\t\tif (agent.tools && agent.tools.length > 0) {\n\t\t\tlines.push(` <tools>${escapeXml(agent.tools.join(\", \"))}</tools>`);\n\t\t}\n\t\tif (agent.model) {\n\t\t\tlines.push(` <model>${escapeXml(agent.model)}</model>`);\n\t\t}\n\t\tlines.push(\" </agent>\");\n\t}\n\n\tlines.push(\"</available_agents>\");\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction escapeXml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\")\n\t\t.replace(/'/g, \"'\");\n}\n"]}
|