* Executes a skill in a forked sub-agent context. * This runs the skill prompt in an isolated agent with its own token budget.
(
command: Command & { type: 'prompt' },
commandName: string,
args: string | undefined,
context: ToolUseContext,
canUseTool: CanUseToolFn,
parentMessage: AssistantMessage,
onProgress?: ToolCallProgress<Progress>,
)
| 120 | * This runs the skill prompt in an isolated agent with its own token budget. |
| 121 | */ |
| 122 | async function executeForkedSkill( |
| 123 | command: Command & { type: 'prompt' }, |
| 124 | commandName: string, |
| 125 | args: string | undefined, |
| 126 | context: ToolUseContext, |
| 127 | canUseTool: CanUseToolFn, |
| 128 | parentMessage: AssistantMessage, |
| 129 | onProgress?: ToolCallProgress<Progress>, |
| 130 | ): Promise<ToolResult<Output>> { |
| 131 | const startTime = Date.now() |
| 132 | const agentId = createAgentId() |
| 133 | const isBuiltIn = builtInCommandNames().has(commandName) |
| 134 | const isOfficialSkill = isOfficialMarketplaceSkill(command) |
| 135 | const isBundled = command.source === 'bundled' |
| 136 | const forkedSanitizedName = |
| 137 | isBuiltIn || isBundled || isOfficialSkill ? commandName : 'custom' |
| 138 | |
| 139 | const wasDiscoveredField = |
| 140 | feature('EXPERIMENTAL_SKILL_SEARCH') && |
| 141 | remoteSkillModules!.isSkillSearchEnabled() |
| 142 | ? { |
| 143 | was_discovered: |
| 144 | context.discoveredSkillNames?.has(commandName) ?? false, |
| 145 | } |
| 146 | : {} |
| 147 | const pluginMarketplace = command.pluginInfo |
| 148 | ? parsePluginIdentifier(command.pluginInfo.repository).marketplace |
| 149 | : undefined |
| 150 | const queryDepth = context.queryTracking?.depth ?? 0 |
| 151 | const parentAgentId = getAgentContext()?.agentId |
| 152 | logEvent('tengu_skill_tool_invocation', { |
| 153 | command_name: |
| 154 | forkedSanitizedName as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 155 | // _PROTO_skill_name routes to the privileged skill_name BQ column |
| 156 | // (unredacted, all users); command_name stays in additional_metadata as |
| 157 | // the redacted variant for general-access dashboards. |
| 158 | _PROTO_skill_name: |
| 159 | commandName as AnalyticsMetadata_I_VERIFIED_THIS_IS_PII_TAGGED, |
| 160 | execution_context: |
| 161 | 'fork' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 162 | invocation_trigger: (queryDepth > 0 |
| 163 | ? 'nested-skill' |
| 164 | : 'claude-proactive') as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 165 | query_depth: queryDepth, |
| 166 | ...(parentAgentId && { |
| 167 | parent_agent_id: |
| 168 | parentAgentId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 169 | }), |
| 170 | ...wasDiscoveredField, |
| 171 | ...(process.env.USER_TYPE === 'ant' && { |
| 172 | skill_name: |
| 173 | commandName as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 174 | skill_source: |
| 175 | command.source as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 176 | ...(command.loadedFrom && { |
| 177 | skill_loaded_from: |
| 178 | command.loadedFrom as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 179 | }), |
no test coverage detected