@codemieai/code 0.0.30 → 0.0.32
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/dist/agents/codemie-code/agent.d.ts +6 -0
- package/dist/agents/codemie-code/agent.d.ts.map +1 -1
- package/dist/agents/codemie-code/agent.js +239 -3
- package/dist/agents/codemie-code/agent.js.map +1 -1
- package/dist/agents/codemie-code/config.d.ts.map +1 -1
- package/dist/agents/codemie-code/config.js +3 -1
- package/dist/agents/codemie-code/config.js.map +1 -1
- package/dist/agents/codemie-code/types.d.ts +13 -0
- package/dist/agents/codemie-code/types.d.ts.map +1 -1
- package/dist/agents/codemie-code/types.js.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts +9 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.js +11 -0
- package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
- package/dist/agents/core/types.d.ts +74 -0
- package/dist/agents/core/types.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.js +18 -0
- package/dist/agents/plugins/claude/claude.plugin.js.map +1 -1
- package/dist/agents/plugins/claude/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/code-review-agent-template.md.template +466 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/solution-architect-agent.md.template +487 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/unit-tester-agent.md.template +805 -0
- package/dist/agents/plugins/claude/plugin/commands/codemie-commit.md +31 -0
- package/dist/agents/plugins/claude/plugin/commands/codemie-init.md +1 -1
- package/dist/agents/plugins/claude/plugin/commands/codemie-pr.md +25 -0
- package/dist/agents/plugins/claude/plugin/commands/codemie-subagents.md +616 -0
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.d.ts.map +1 -1
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js +8 -0
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js.map +1 -1
- package/dist/agents/plugins/gemini/gemini.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/gemini/gemini.plugin.js +14 -0
- package/dist/agents/plugins/gemini/gemini.plugin.js.map +1 -1
- package/dist/cli/commands/hook.d.ts.map +1 -1
- package/dist/cli/commands/hook.js +15 -1
- package/dist/cli/commands/hook.js.map +1 -1
- package/dist/env/types.d.ts +2 -0
- package/dist/env/types.d.ts.map +1 -1
- package/dist/env/types.js.map +1 -1
- package/dist/hooks/decision.d.ts +53 -0
- package/dist/hooks/decision.d.ts.map +1 -0
- package/dist/hooks/decision.js +201 -0
- package/dist/hooks/decision.js.map +1 -0
- package/dist/hooks/executor.d.ts +154 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +415 -0
- package/dist/hooks/executor.js.map +1 -0
- package/dist/hooks/matcher.d.ts +41 -0
- package/dist/hooks/matcher.d.ts.map +1 -0
- package/dist/hooks/matcher.js +93 -0
- package/dist/hooks/matcher.js.map +1 -0
- package/dist/hooks/prompt-executor.d.ts +57 -0
- package/dist/hooks/prompt-executor.d.ts.map +1 -0
- package/dist/hooks/prompt-executor.js +141 -0
- package/dist/hooks/prompt-executor.js.map +1 -0
- package/dist/hooks/types.d.ts +153 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +9 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.d.ts +3 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.d.ts.map +1 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.js +14 -2
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.js.map +1 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-types.d.ts +8 -0
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-types.d.ts.map +1 -1
- package/dist/utils/config.d.ts +5 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +73 -0
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/mcp-config.d.ts +25 -0
- package/dist/utils/mcp-config.d.ts.map +1 -0
- package/dist/utils/mcp-config.js +197 -0
- package/dist/utils/mcp-config.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook Decision Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses and validates hook output (JSON decisions) and merges results
|
|
5
|
+
* from multiple hooks according to priority rules.
|
|
6
|
+
*/
|
|
7
|
+
import { logger } from '../utils/logger.js';
|
|
8
|
+
export class DecisionParser {
|
|
9
|
+
/**
|
|
10
|
+
* Parse JSON output from hook
|
|
11
|
+
*
|
|
12
|
+
* @param stdout - Standard output from hook (should be JSON)
|
|
13
|
+
* @param stderr - Standard error from hook (for logging)
|
|
14
|
+
* @param exitCode - Exit code from hook process
|
|
15
|
+
* @returns Parsed hook result or default allow decision
|
|
16
|
+
*/
|
|
17
|
+
static parse(stdout, stderr, exitCode) {
|
|
18
|
+
// Handle exit code 2 (blocking error - requires agent retry)
|
|
19
|
+
if (exitCode === 2) {
|
|
20
|
+
// Extract feedback from both stderr and stdout for agent to process
|
|
21
|
+
const feedback = [stderr, stdout.trim()].filter(Boolean).join('\n\n');
|
|
22
|
+
return {
|
|
23
|
+
decision: 'block',
|
|
24
|
+
reason: stderr || 'Hook returned blocking error (exit code 2)',
|
|
25
|
+
additionalContext: feedback || undefined,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// Handle non-zero exit codes (non-blocking errors - informational)
|
|
29
|
+
if (exitCode !== 0) {
|
|
30
|
+
logger.warn(`Hook failed with exit code ${exitCode}: ${stderr}`);
|
|
31
|
+
// Include output as informational feedback for agent
|
|
32
|
+
const feedback = [stderr, stdout.trim()].filter(Boolean).join('\n\n');
|
|
33
|
+
return {
|
|
34
|
+
decision: 'allow',
|
|
35
|
+
reason: `Hook failed but execution continues (exit code ${exitCode})`,
|
|
36
|
+
additionalContext: feedback || undefined,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Try to parse JSON output
|
|
40
|
+
const trimmedOutput = stdout.trim();
|
|
41
|
+
if (!trimmedOutput) {
|
|
42
|
+
// Empty output means allow
|
|
43
|
+
return { decision: 'allow' };
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const result = JSON.parse(trimmedOutput);
|
|
47
|
+
return this.validateResult(result);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// Not valid JSON - treat as informational output
|
|
51
|
+
logger.debug(`Hook returned non-JSON output, treating as informational`);
|
|
52
|
+
return {
|
|
53
|
+
decision: 'allow',
|
|
54
|
+
additionalContext: trimmedOutput,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Validate hook result structure
|
|
60
|
+
*
|
|
61
|
+
* @param result - Parsed hook result
|
|
62
|
+
* @returns Validated result (with defaults filled in)
|
|
63
|
+
*/
|
|
64
|
+
static validateResult(result) {
|
|
65
|
+
// Validate decision field
|
|
66
|
+
if (result.decision) {
|
|
67
|
+
const validDecisions = ['allow', 'deny', 'block', 'approve'];
|
|
68
|
+
if (!validDecisions.includes(result.decision)) {
|
|
69
|
+
logger.warn(`Invalid decision value "${result.decision}", defaulting to allow`);
|
|
70
|
+
result.decision = 'allow';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// Default to allow if no decision specified
|
|
75
|
+
result.decision = 'allow';
|
|
76
|
+
}
|
|
77
|
+
// Validate reason field
|
|
78
|
+
if (result.reason && typeof result.reason !== 'string') {
|
|
79
|
+
logger.warn('Invalid reason field (not a string), removing');
|
|
80
|
+
delete result.reason;
|
|
81
|
+
}
|
|
82
|
+
// Validate suppressOutput field
|
|
83
|
+
if (result.suppressOutput !== undefined && typeof result.suppressOutput !== 'boolean') {
|
|
84
|
+
logger.warn('Invalid suppressOutput field (not a boolean), removing');
|
|
85
|
+
delete result.suppressOutput;
|
|
86
|
+
}
|
|
87
|
+
// Validate updatedInput field
|
|
88
|
+
if (result.updatedInput !== undefined && typeof result.updatedInput !== 'object') {
|
|
89
|
+
logger.warn('Invalid updatedInput field (not an object), removing');
|
|
90
|
+
delete result.updatedInput;
|
|
91
|
+
}
|
|
92
|
+
// Validate additionalContext field
|
|
93
|
+
if (result.additionalContext !== undefined && typeof result.additionalContext !== 'string') {
|
|
94
|
+
logger.warn('Invalid additionalContext field (not a string), removing');
|
|
95
|
+
delete result.additionalContext;
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Merge results from multiple hooks according to priority rules
|
|
101
|
+
*
|
|
102
|
+
* Priority order (highest to lowest):
|
|
103
|
+
* 1. block - Prevents execution completely
|
|
104
|
+
* 2. deny - Denies current operation
|
|
105
|
+
* 3. approve - Explicitly approves
|
|
106
|
+
* 4. allow - Default, allows execution
|
|
107
|
+
*
|
|
108
|
+
* @param results - Array of hook results (from Promise.allSettled)
|
|
109
|
+
* @returns Aggregated result with highest-priority decision
|
|
110
|
+
*/
|
|
111
|
+
static merge(results) {
|
|
112
|
+
const aggregated = {
|
|
113
|
+
decision: 'allow',
|
|
114
|
+
hooksExecuted: results.length,
|
|
115
|
+
hooksSucceeded: 0,
|
|
116
|
+
hooksFailed: 0,
|
|
117
|
+
errors: [],
|
|
118
|
+
};
|
|
119
|
+
// Collect all successful results and errors
|
|
120
|
+
const successfulResults = [];
|
|
121
|
+
for (const result of results) {
|
|
122
|
+
if (result.status === 'fulfilled') {
|
|
123
|
+
successfulResults.push(result.value);
|
|
124
|
+
aggregated.hooksSucceeded++;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
aggregated.hooksFailed++;
|
|
128
|
+
aggregated.errors?.push({
|
|
129
|
+
hook: 'unknown',
|
|
130
|
+
error: result.reason?.message || String(result.reason),
|
|
131
|
+
});
|
|
132
|
+
logger.error(`Hook execution failed: ${result.reason}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// If all hooks failed, return allow (fail open)
|
|
136
|
+
if (successfulResults.length === 0) {
|
|
137
|
+
return aggregated;
|
|
138
|
+
}
|
|
139
|
+
// Apply priority rules to determine final decision
|
|
140
|
+
// Priority: block > deny > approve > allow
|
|
141
|
+
const priorities = {
|
|
142
|
+
block: 4,
|
|
143
|
+
deny: 3,
|
|
144
|
+
approve: 2,
|
|
145
|
+
allow: 1,
|
|
146
|
+
};
|
|
147
|
+
let highestPriority = 0;
|
|
148
|
+
let finalResult = { decision: 'allow' };
|
|
149
|
+
for (const result of successfulResults) {
|
|
150
|
+
const priority = priorities[result.decision || 'allow'];
|
|
151
|
+
if (priority > highestPriority) {
|
|
152
|
+
highestPriority = priority;
|
|
153
|
+
finalResult = result;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Merge final result into aggregated
|
|
157
|
+
Object.assign(aggregated, finalResult);
|
|
158
|
+
// Collect all additional context from successful hooks
|
|
159
|
+
const contexts = successfulResults
|
|
160
|
+
.map((r) => r.additionalContext)
|
|
161
|
+
.filter((c) => !!c);
|
|
162
|
+
if (contexts.length > 0) {
|
|
163
|
+
aggregated.additionalContext = contexts.join('\n\n');
|
|
164
|
+
}
|
|
165
|
+
// Merge updatedInput from all hooks (later hooks override earlier)
|
|
166
|
+
const updatedInputs = successfulResults
|
|
167
|
+
.map((r) => r.updatedInput)
|
|
168
|
+
.filter((u) => !!u);
|
|
169
|
+
if (updatedInputs.length > 0) {
|
|
170
|
+
aggregated.updatedInput = Object.assign({}, ...updatedInputs);
|
|
171
|
+
}
|
|
172
|
+
// Collect reasons from blocking/denying hooks
|
|
173
|
+
const blockingReasons = successfulResults
|
|
174
|
+
.filter((r) => r.decision === 'block' || r.decision === 'deny')
|
|
175
|
+
.map((r) => r.reason)
|
|
176
|
+
.filter((r) => !!r);
|
|
177
|
+
if (blockingReasons.length > 0 && !aggregated.reason) {
|
|
178
|
+
aggregated.reason = blockingReasons.join('; ');
|
|
179
|
+
}
|
|
180
|
+
return aggregated;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Check if a result is blocking (prevents execution)
|
|
184
|
+
*
|
|
185
|
+
* @param result - Hook result to check
|
|
186
|
+
* @returns true if result blocks execution
|
|
187
|
+
*/
|
|
188
|
+
static isBlocking(result) {
|
|
189
|
+
return result.decision === 'block' || result.decision === 'deny';
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Check if an aggregated result is blocking
|
|
193
|
+
*
|
|
194
|
+
* @param result - Aggregated hook result
|
|
195
|
+
* @returns true if any hook blocked execution
|
|
196
|
+
*/
|
|
197
|
+
static isAggregatedBlocking(result) {
|
|
198
|
+
return this.isBlocking(result);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=decision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision.js","sourceRoot":"","sources":["../../src/hooks/decision.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,MAAM,OAAO,cAAc;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,MAAc,EAAE,MAAc,EAAE,QAAgB;QAC5D,6DAA6D;QAC7D,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;YACpB,oEAAoE;YACpE,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAEtE,OAAO;gBACN,QAAQ,EAAE,OAAO;gBACjB,MAAM,EAAE,MAAM,IAAI,4CAA4C;gBAC9D,iBAAiB,EAAE,QAAQ,IAAI,SAAS;aACxC,CAAC;QACH,C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AAC,UAAU,CAAC,MAAM,EAAE,CAAC;YACtD,UAAU,CAAC,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,MAAkB;QACnC,OAAO,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,oBAAoB,CAAC,MAA4B;QACvD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACD"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook Executor
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates execution of hooks at various lifecycle points.
|
|
5
|
+
* Handles pattern matching, deduplication, parallel execution, and timeout management.
|
|
6
|
+
*/
|
|
7
|
+
import type { HooksConfiguration, AggregatedHookResult, HookExecutionContext } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* LLM configuration for prompt hooks
|
|
10
|
+
*/
|
|
11
|
+
export interface PromptHookLLMConfig {
|
|
12
|
+
apiKey: string;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Hook execution engine
|
|
20
|
+
* Manages lifecycle hook execution with pattern matching, deduplication, and aggregation
|
|
21
|
+
*/
|
|
22
|
+
export declare class HookExecutor {
|
|
23
|
+
/** Hooks configuration */
|
|
24
|
+
private config;
|
|
25
|
+
/** Execution context (session ID, working directory, etc.) */
|
|
26
|
+
private context;
|
|
27
|
+
/** Cache of executed hooks (for deduplication) */
|
|
28
|
+
private executedHooks;
|
|
29
|
+
/** Prompt hook executor (for LLM-based hooks) */
|
|
30
|
+
private promptExecutor;
|
|
31
|
+
constructor(config: HooksConfiguration, context: HookExecutionContext, llmConfig?: PromptHookLLMConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Execute PreToolUse hooks
|
|
34
|
+
* Runs before tool execution, can block or modify tool input
|
|
35
|
+
*
|
|
36
|
+
* @param toolName - Name of tool being executed
|
|
37
|
+
* @param toolInput - Tool input arguments
|
|
38
|
+
* @param toolUseId - Unique identifier for this tool use
|
|
39
|
+
* @returns Aggregated result from all matching hooks
|
|
40
|
+
*/
|
|
41
|
+
executePreToolUse(toolName: string, toolInput: Record<string, unknown>, toolUseId?: string): Promise<AggregatedHookResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Execute PostToolUse hooks
|
|
44
|
+
* Runs after tool completes, informational only (cannot block)
|
|
45
|
+
*
|
|
46
|
+
* @param toolName - Name of tool that was executed
|
|
47
|
+
* @param toolInput - Tool input arguments
|
|
48
|
+
* @param toolOutput - Tool output/result
|
|
49
|
+
* @param toolMetadata - Additional tool metadata
|
|
50
|
+
* @returns Aggregated result from all matching hooks
|
|
51
|
+
*/
|
|
52
|
+
executePostToolUse(toolName: string, toolInput: Record<string, unknown>, toolOutput: string, toolMetadata?: Record<string, unknown>): Promise<AggregatedHookResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Execute UserPromptSubmit hooks
|
|
55
|
+
* Runs before processing user input, can block or add context
|
|
56
|
+
*
|
|
57
|
+
* @param prompt - User's prompt text
|
|
58
|
+
* @returns Aggregated result from all hooks
|
|
59
|
+
*/
|
|
60
|
+
executeUserPromptSubmit(prompt: string): Promise<AggregatedHookResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Execute Stop hooks
|
|
63
|
+
* Runs when agent completes, can prevent stopping and continue execution
|
|
64
|
+
*
|
|
65
|
+
* @param executionSteps - Optional array of execution steps with tool history
|
|
66
|
+
* @param stats - Optional execution statistics
|
|
67
|
+
* @returns Aggregated result from all hooks
|
|
68
|
+
*/
|
|
69
|
+
executeStop(executionSteps?: Array<any>, stats?: {
|
|
70
|
+
toolCalls: number;
|
|
71
|
+
successfulTools: number;
|
|
72
|
+
failedTools: number;
|
|
73
|
+
}): Promise<AggregatedHookResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Execute SessionStart hooks
|
|
76
|
+
* Runs at the beginning of a session, can block session start and inject context
|
|
77
|
+
*
|
|
78
|
+
* @returns Aggregated result from all hooks
|
|
79
|
+
*/
|
|
80
|
+
executeSessionStart(): Promise<AggregatedHookResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Find hooks that match a tool name
|
|
83
|
+
*
|
|
84
|
+
* @param matchers - Array of hook matchers with patterns
|
|
85
|
+
* @param toolName - Tool name to match against
|
|
86
|
+
* @returns Array of matching hook configurations
|
|
87
|
+
*/
|
|
88
|
+
private findMatchingHooks;
|
|
89
|
+
/**
|
|
90
|
+
* Execute multiple hooks in parallel with deduplication
|
|
91
|
+
*
|
|
92
|
+
* @param hooks - Hooks to execute
|
|
93
|
+
* @param input - Input data to pass to hooks
|
|
94
|
+
* @returns Aggregated result from all hooks
|
|
95
|
+
*/
|
|
96
|
+
private executeHooks;
|
|
97
|
+
/**
|
|
98
|
+
* Deduplicate hooks by computing hash of configuration
|
|
99
|
+
* Identical hooks (same command/prompt/timeout) run only once per event
|
|
100
|
+
*
|
|
101
|
+
* @param hooks - Hooks to deduplicate
|
|
102
|
+
* @returns Unique hooks
|
|
103
|
+
*/
|
|
104
|
+
private deduplicateHooks;
|
|
105
|
+
/**
|
|
106
|
+
* Compute hash of hook configuration for deduplication
|
|
107
|
+
*
|
|
108
|
+
* @param hook - Hook configuration
|
|
109
|
+
* @returns SHA-256 hash of hook config
|
|
110
|
+
*/
|
|
111
|
+
private hashHook;
|
|
112
|
+
/**
|
|
113
|
+
* Execute a single hook (command or prompt)
|
|
114
|
+
*
|
|
115
|
+
* @param hook - Hook configuration
|
|
116
|
+
* @param input - Input data for hook
|
|
117
|
+
* @returns Hook result
|
|
118
|
+
*/
|
|
119
|
+
private executeSingleHook;
|
|
120
|
+
/**
|
|
121
|
+
* Execute a command hook (shell script)
|
|
122
|
+
*
|
|
123
|
+
* @param hook - Hook configuration
|
|
124
|
+
* @param input - Input data (passed as JSON via stdin)
|
|
125
|
+
* @returns Hook result parsed from stdout
|
|
126
|
+
*/
|
|
127
|
+
private executeCommandHook;
|
|
128
|
+
/**
|
|
129
|
+
* Execute a prompt hook (LLM-based)
|
|
130
|
+
*
|
|
131
|
+
* @param hook - Hook configuration
|
|
132
|
+
* @param input - Input data
|
|
133
|
+
* @returns Hook result
|
|
134
|
+
*/
|
|
135
|
+
private executePromptHook;
|
|
136
|
+
/**
|
|
137
|
+
* Build environment variables for hook execution
|
|
138
|
+
*
|
|
139
|
+
* @param input - Hook input data
|
|
140
|
+
* @returns Environment variables object
|
|
141
|
+
*/
|
|
142
|
+
private buildEnvironment;
|
|
143
|
+
/**
|
|
144
|
+
* Create empty result (no hooks executed)
|
|
145
|
+
*
|
|
146
|
+
* @returns Empty aggregated result
|
|
147
|
+
*/
|
|
148
|
+
private createEmptyResult;
|
|
149
|
+
/**
|
|
150
|
+
* Clear executed hooks cache (for new event cycle)
|
|
151
|
+
*/
|
|
152
|
+
clearCache(): void;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/hooks/executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,KAAK,EACX,kBAAkB,EAKlB,oBAAoB,EACpB,oBAAoB,EACpB,MAAM,YAAY,CAAC;AAOpB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,Y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