@grimoire-cc/router 1.1.0
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/args.d.ts +18 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +45 -0
- package/dist/args.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +4 -0
- package/dist/bin.js.map +1 -0
- package/dist/enforce.d.ts +25 -0
- package/dist/enforce.d.ts.map +1 -0
- package/dist/enforce.js +140 -0
- package/dist/enforce.js.map +1 -0
- package/dist/filtering.d.ts +20 -0
- package/dist/filtering.d.ts.map +1 -0
- package/dist/filtering.js +30 -0
- package/dist/filtering.js.map +1 -0
- package/dist/formatting.d.ts +23 -0
- package/dist/formatting.d.ts.map +1 -0
- package/dist/formatting.js +88 -0
- package/dist/formatting.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +40 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +88 -0
- package/dist/input.js.map +1 -0
- package/dist/logging.d.ts +27 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +58 -0
- package/dist/logging.js.map +1 -0
- package/dist/main.d.ts +27 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +247 -0
- package/dist/main.js.map +1 -0
- package/dist/manifest.d.ts +13 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +127 -0
- package/dist/manifest.js.map +1 -0
- package/dist/matching.d.ts +47 -0
- package/dist/matching.d.ts.map +1 -0
- package/dist/matching.js +185 -0
- package/dist/matching.js.map +1 -0
- package/dist/normalize.d.ts +17 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +33 -0
- package/dist/normalize.js.map +1 -0
- package/dist/output.d.ts +13 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +19 -0
- package/dist/output.js.map +1 -0
- package/dist/scoring.d.ts +15 -0
- package/dist/scoring.d.ts.map +1 -0
- package/dist/scoring.js +106 -0
- package/dist/scoring.js.map +1 -0
- package/dist/signals.d.ts +17 -0
- package/dist/signals.d.ts.map +1 -0
- package/dist/signals.js +57 -0
- package/dist/signals.js.map +1 -0
- package/dist/skill-content.d.ts +12 -0
- package/dist/skill-content.d.ts.map +1 -0
- package/dist/skill-content.js +33 -0
- package/dist/skill-content.js.map +1 -0
- package/dist/tool-formatting.d.ts +13 -0
- package/dist/tool-formatting.d.ts.map +1 -0
- package/dist/tool-formatting.js +47 -0
- package/dist/tool-formatting.js.map +1 -0
- package/dist/tool-input.d.ts +26 -0
- package/dist/tool-input.d.ts.map +1 -0
- package/dist/tool-input.js +108 -0
- package/dist/tool-input.js.map +1 -0
- package/dist/tool-output.d.ts +13 -0
- package/dist/tool-output.d.ts.map +1 -0
- package/dist/tool-output.js +20 -0
- package/dist/tool-output.js.map +1 -0
- package/dist/types.d.ts +225 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PreToolUse input parsing and signal extraction
|
|
3
|
+
*/
|
|
4
|
+
import type { PreToolUseInput, ExtractedSignals } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Detects whether parsed JSON data is from a PreToolUse hook
|
|
7
|
+
* by checking for the presence of a string `tool_name` field.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPreToolUseInput(data: unknown): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Parses PreToolUse hook input from a JSON string.
|
|
12
|
+
*
|
|
13
|
+
* @param jsonString - Raw JSON string from stdin
|
|
14
|
+
* @returns Validated PreToolUseInput
|
|
15
|
+
* @throws Error if input is empty, invalid JSON, missing tool_name, or unsupported tool
|
|
16
|
+
*/
|
|
17
|
+
export declare function parsePreToolUseInput(jsonString: string): PreToolUseInput;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts file-path-based signals from tool_input.
|
|
20
|
+
*
|
|
21
|
+
* @param toolInput - The tool_input object from PreToolUse stdin
|
|
22
|
+
* @param projectDir - The project directory to strip from absolute paths
|
|
23
|
+
* @returns ExtractedSignals with words, extensions, and paths from the file path
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractToolSignals(toolInput: Record<string, unknown>, projectDir: string): ExtractedSignals;
|
|
26
|
+
//# sourceMappingURL=tool-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-input.d.ts","sourceRoot":"","sources":["../src/tool-input.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAY,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI9E;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAKxD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,CA2CxE;AAgBD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,UAAU,EAAE,MAAM,GACjB,gBAAgB,CAqClB"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PreToolUse input parsing and signal extraction
|
|
3
|
+
*/
|
|
4
|
+
const SUPPORTED_TOOLS = new Set(['Edit', 'Write']);
|
|
5
|
+
/**
|
|
6
|
+
* Detects whether parsed JSON data is from a PreToolUse hook
|
|
7
|
+
* by checking for the presence of a string `tool_name` field.
|
|
8
|
+
*/
|
|
9
|
+
export function isPreToolUseInput(data) {
|
|
10
|
+
if (!data || typeof data !== 'object') {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return typeof data['tool_name'] === 'string';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parses PreToolUse hook input from a JSON string.
|
|
17
|
+
*
|
|
18
|
+
* @param jsonString - Raw JSON string from stdin
|
|
19
|
+
* @returns Validated PreToolUseInput
|
|
20
|
+
* @throws Error if input is empty, invalid JSON, missing tool_name, or unsupported tool
|
|
21
|
+
*/
|
|
22
|
+
export function parsePreToolUseInput(jsonString) {
|
|
23
|
+
if (!jsonString || !jsonString.trim()) {
|
|
24
|
+
throw new Error('Hook input is empty');
|
|
25
|
+
}
|
|
26
|
+
let data;
|
|
27
|
+
try {
|
|
28
|
+
data = JSON.parse(jsonString);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
32
|
+
throw new Error(`Failed to parse hook input JSON: ${message}`);
|
|
33
|
+
}
|
|
34
|
+
if (!data || typeof data !== 'object') {
|
|
35
|
+
throw new Error('Hook input must be an object');
|
|
36
|
+
}
|
|
37
|
+
const input = data;
|
|
38
|
+
// Validate tool_name
|
|
39
|
+
if (typeof input['tool_name'] !== 'string') {
|
|
40
|
+
throw new Error('Hook input must have a tool_name string field');
|
|
41
|
+
}
|
|
42
|
+
const toolName = input['tool_name'];
|
|
43
|
+
if (!SUPPORTED_TOOLS.has(toolName)) {
|
|
44
|
+
throw new Error(`Unsupported tool: ${toolName}. Only Edit and Write are supported.`);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
session_id: typeof input['session_id'] === 'string' ? input['session_id'] : 'unknown',
|
|
48
|
+
hook_event_name: 'PreToolUse',
|
|
49
|
+
tool_name: toolName,
|
|
50
|
+
tool_use_id: typeof input['tool_use_id'] === 'string' ? input['tool_use_id'] : '',
|
|
51
|
+
tool_input: input['tool_input'] && typeof input['tool_input'] === 'object'
|
|
52
|
+
? input['tool_input']
|
|
53
|
+
: {},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Strips the project directory prefix from a file path.
|
|
58
|
+
*/
|
|
59
|
+
function stripProjectDir(filePath, projectDir) {
|
|
60
|
+
const normalizedDir = projectDir.endsWith('/')
|
|
61
|
+
? projectDir.slice(0, -1)
|
|
62
|
+
: projectDir;
|
|
63
|
+
if (filePath.startsWith(normalizedDir + '/')) {
|
|
64
|
+
return filePath.slice(normalizedDir.length + 1);
|
|
65
|
+
}
|
|
66
|
+
return filePath;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Extracts file-path-based signals from tool_input.
|
|
70
|
+
*
|
|
71
|
+
* @param toolInput - The tool_input object from PreToolUse stdin
|
|
72
|
+
* @param projectDir - The project directory to strip from absolute paths
|
|
73
|
+
* @returns ExtractedSignals with words, extensions, and paths from the file path
|
|
74
|
+
*/
|
|
75
|
+
export function extractToolSignals(toolInput, projectDir) {
|
|
76
|
+
const signals = {
|
|
77
|
+
words: new Set(),
|
|
78
|
+
extensions: new Set(),
|
|
79
|
+
paths: [],
|
|
80
|
+
};
|
|
81
|
+
const filePath = toolInput['file_path'];
|
|
82
|
+
if (typeof filePath !== 'string') {
|
|
83
|
+
return signals;
|
|
84
|
+
}
|
|
85
|
+
// Get relative path
|
|
86
|
+
const relativePath = stripProjectDir(filePath, projectDir);
|
|
87
|
+
signals.paths.push(relativePath.toLowerCase());
|
|
88
|
+
// Extract extension
|
|
89
|
+
const lastDot = relativePath.lastIndexOf('.');
|
|
90
|
+
const lastSlash = relativePath.lastIndexOf('/');
|
|
91
|
+
if (lastDot > lastSlash && lastDot < relativePath.length - 1) {
|
|
92
|
+
signals.extensions.add(relativePath.slice(lastDot).toLowerCase());
|
|
93
|
+
}
|
|
94
|
+
// Extract words from path segments
|
|
95
|
+
const segments = relativePath.split('/');
|
|
96
|
+
for (const segment of segments) {
|
|
97
|
+
// Split on dots to separate filename from extension
|
|
98
|
+
const parts = segment.split('.');
|
|
99
|
+
for (const part of parts) {
|
|
100
|
+
const word = part.toLowerCase();
|
|
101
|
+
if (word.length >= 2) {
|
|
102
|
+
signals.words.add(word);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return signals;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=tool-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-input.js","sourceRoot":"","sources":["../src/tool-input.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAExE;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAa;IAC7C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,OAAQ,IAAgC,CAAC,WAAW,CAAC,KAAK,QAAQ,CAAC;AAC5E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAAkB;IACrD,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,oCAAoC,OAAO,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,KAAK,GAAG,IAA+B,CAAC;I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AC,MAAM,IAAI,CAAC,EAAE,CAAC;gBACrB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PreToolUse output building
|
|
3
|
+
*/
|
|
4
|
+
import type { PreToolUseOutput } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Builds the PreToolUse hook output structure.
|
|
7
|
+
* Always non-blocking (permissionDecision: 'allow').
|
|
8
|
+
*
|
|
9
|
+
* @param additionalContext - Context string to inject
|
|
10
|
+
* @returns PreToolUseOutput ready for stdout
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildPreToolUseOutput(additionalContext: string): PreToolUseOutput;
|
|
13
|
+
//# sourceMappingURL=tool-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-output.d.ts","sourceRoot":"","sources":["../src/tool-output.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,iBAAiB,EAAE,MAAM,GACxB,gBAAgB,CAQlB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PreToolUse output building
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Builds the PreToolUse hook output structure.
|
|
6
|
+
* Always non-blocking (permissionDecision: 'allow').
|
|
7
|
+
*
|
|
8
|
+
* @param additionalContext - Context string to inject
|
|
9
|
+
* @returns PreToolUseOutput ready for stdout
|
|
10
|
+
*/
|
|
11
|
+
export function buildPreToolUseOutput(additionalContext) {
|
|
12
|
+
return {
|
|
13
|
+
hookSpecificOutput: {
|
|
14
|
+
hookEventName: 'PreToolUse',
|
|
15
|
+
additionalContext,
|
|
16
|
+
permissionDecision: 'allow',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=tool-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-output.js","sourceRoot":"","sources":["../src/tool-output.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,iBAAyB;IAEzB,OAAO;QACL,kBAAkB,EAAE;YAClB,aAAa,EAAE,YAAY;YAC3B,iBAAiB;YACjB,kBAAkB,EAAE,OAAO;SAC5B;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Skill Router
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Scoring weights for each signal type
|
|
6
|
+
*/
|
|
7
|
+
export interface SkillWeights {
|
|
8
|
+
keywords: number;
|
|
9
|
+
file_extensions: number;
|
|
10
|
+
patterns: number;
|
|
11
|
+
file_paths: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Global configuration settings
|
|
15
|
+
*/
|
|
16
|
+
export interface SkillConfig {
|
|
17
|
+
weights: SkillWeights;
|
|
18
|
+
activation_threshold: number;
|
|
19
|
+
pretooluse_threshold?: number;
|
|
20
|
+
log_path?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Trigger conditions for a skill
|
|
24
|
+
*/
|
|
25
|
+
export interface SkillTriggers {
|
|
26
|
+
keywords?: string[];
|
|
27
|
+
file_extensions?: string[];
|
|
28
|
+
patterns?: string[];
|
|
29
|
+
file_paths?: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A single skill definition in the manifest
|
|
33
|
+
*/
|
|
34
|
+
export interface SkillDefinition {
|
|
35
|
+
path: string;
|
|
36
|
+
name: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
triggers: SkillTriggers;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Per-agent entry in the manifest (file_patterns and enforce flag)
|
|
42
|
+
*/
|
|
43
|
+
export interface AgentEntry {
|
|
44
|
+
file_patterns?: string[];
|
|
45
|
+
enforce?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Complete skill manifest structure
|
|
49
|
+
*/
|
|
50
|
+
export interface SkillManifest {
|
|
51
|
+
version: string;
|
|
52
|
+
config: SkillConfig;
|
|
53
|
+
skills: SkillDefinition[];
|
|
54
|
+
/** Optional agent configurations */
|
|
55
|
+
agents?: Record<string, AgentEntry>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Input received from Claude Code hook system via stdin
|
|
59
|
+
*/
|
|
60
|
+
export interface HookInput {
|
|
61
|
+
prompt: string;
|
|
62
|
+
session_id: string;
|
|
63
|
+
timestamp: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Supported tool names for PreToolUse hook
|
|
67
|
+
*/
|
|
68
|
+
export type ToolName = 'Edit' | 'Write' | 'MultiEdit';
|
|
69
|
+
/**
|
|
70
|
+
* Input received from PreToolUse hook via stdin
|
|
71
|
+
*/
|
|
72
|
+
export interface PreToolUseInput {
|
|
73
|
+
session_id: string;
|
|
74
|
+
hook_event_name: 'PreToolUse';
|
|
75
|
+
tool_name: ToolName;
|
|
76
|
+
tool_use_id: string;
|
|
77
|
+
tool_input: Record<string, unknown>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Supported hook event types
|
|
81
|
+
*/
|
|
82
|
+
export type HookEventName = 'UserPromptSubmit' | 'SubagentStart' | 'PreToolUse';
|
|
83
|
+
/**
|
|
84
|
+
* Hook-specific output data
|
|
85
|
+
*/
|
|
86
|
+
export interface HookSpecificOutput {
|
|
87
|
+
hookEventName: HookEventName;
|
|
88
|
+
additionalContext: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Output written to stdout when skills are matched
|
|
92
|
+
*/
|
|
93
|
+
export interface HookOutput {
|
|
94
|
+
hookSpecificOutput: HookSpecificOutput;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* PreToolUse-specific output data (includes permissionDecision)
|
|
98
|
+
*/
|
|
99
|
+
export interface PreToolUseSpecificOutput {
|
|
100
|
+
hookEventName: 'PreToolUse';
|
|
101
|
+
additionalContext: string;
|
|
102
|
+
permissionDecision: 'allow';
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Output for PreToolUse hook
|
|
106
|
+
*/
|
|
107
|
+
export interface PreToolUseOutput {
|
|
108
|
+
hookSpecificOutput: PreToolUseSpecificOutput;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Signals extracted from normalized prompt
|
|
112
|
+
*/
|
|
113
|
+
export interface ExtractedSignals {
|
|
114
|
+
words: Set<string>;
|
|
115
|
+
extensions: Set<string>;
|
|
116
|
+
paths: string[];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Type of matched signal
|
|
120
|
+
*/
|
|
121
|
+
export type MatchedSignalType = 'keyword' | 'extension' | 'pattern' | 'path';
|
|
122
|
+
/**
|
|
123
|
+
* A single matched signal
|
|
124
|
+
*/
|
|
125
|
+
export interface MatchedSignal {
|
|
126
|
+
type: MatchedSignalType;
|
|
127
|
+
value: string;
|
|
128
|
+
matchQuality?: 'exact' | 'stem' | 'fuzzy';
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Reference to a skill (minimal info for results)
|
|
132
|
+
*/
|
|
133
|
+
export interface SkillReference {
|
|
134
|
+
path: string;
|
|
135
|
+
name: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Result of scoring a single skill
|
|
139
|
+
*/
|
|
140
|
+
export interface SkillScoreResult {
|
|
141
|
+
skill: SkillReference;
|
|
142
|
+
score: number;
|
|
143
|
+
matchedSignals: MatchedSignal[];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* CLI arguments parsed from process.argv
|
|
147
|
+
*/
|
|
148
|
+
export interface ParsedArgs {
|
|
149
|
+
/** Agent name if --agent flag is provided */
|
|
150
|
+
agent?: string;
|
|
151
|
+
/** Run enforcement check (PreToolUse) */
|
|
152
|
+
enforce?: boolean;
|
|
153
|
+
/** Register session as a subagent (SubagentStart) */
|
|
154
|
+
subagentStart?: boolean;
|
|
155
|
+
/** Remove session from subagent registry (SubagentStop) */
|
|
156
|
+
subagentStop?: boolean;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Result of evaluateEnforce — either allow or block with matching agent names
|
|
160
|
+
*/
|
|
161
|
+
export type EnforceResult = {
|
|
162
|
+
action: 'allow';
|
|
163
|
+
} | {
|
|
164
|
+
action: 'block';
|
|
165
|
+
agents: string[];
|
|
166
|
+
filePath: string;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Minimal input for SubagentStart/Stop hooks (only session_id needed)
|
|
170
|
+
*/
|
|
171
|
+
export interface SubagentHookInput {
|
|
172
|
+
session_id: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Summary of extracted signals for logging
|
|
176
|
+
*/
|
|
177
|
+
export interface SignalsExtractedSummary {
|
|
178
|
+
words_count: number;
|
|
179
|
+
extensions: string[];
|
|
180
|
+
paths: string[];
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Matched skill info for logging
|
|
184
|
+
*/
|
|
185
|
+
export interface MatchedSkillLogEntry {
|
|
186
|
+
name: string;
|
|
187
|
+
path: string;
|
|
188
|
+
score: number;
|
|
189
|
+
matched_signals: MatchedSignal[];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Outcome of skill router execution
|
|
193
|
+
*/
|
|
194
|
+
export type LogOutcome = 'activated' | 'no_match' | 'error';
|
|
195
|
+
/**
|
|
196
|
+
* Complete log entry structure
|
|
197
|
+
*/
|
|
198
|
+
export interface LogEntry {
|
|
199
|
+
timestamp: string;
|
|
200
|
+
session_id: string;
|
|
201
|
+
prompt_raw: string;
|
|
202
|
+
prompt_normalized: string;
|
|
203
|
+
signals_extracted: SignalsExtractedSummary;
|
|
204
|
+
skills_evaluated: number;
|
|
205
|
+
skills_matched: MatchedSkillLogEntry[];
|
|
206
|
+
threshold: number;
|
|
207
|
+
execution_time_ms: number;
|
|
208
|
+
outcome: LogOutcome;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Log level for error entries
|
|
212
|
+
*/
|
|
213
|
+
export type LogLevel = 'error' | 'warning' | 'info';
|
|
214
|
+
/**
|
|
215
|
+
* Error log entry structure
|
|
216
|
+
*/
|
|
217
|
+
export interface ErrorLogEntry {
|
|
218
|
+
timestamp: string;
|
|
219
|
+
level: LogLevel;
|
|
220
|
+
message: string;
|
|
221
|
+
error_type: string;
|
|
222
|
+
details: Record<string, unknown> | null;
|
|
223
|
+
stack_trace: string | null;
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,YAAY,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,EAAE,CAA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EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACxC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@grimoire-cc/router",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Hook runtime for Grimoire — skill auto-activation and agent enforcement",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"grimoire-router": "./dist/bin.js"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"test:watch": "vitest",
|
|
20
|
+
"test:coverage": "vitest run --coverage",
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"dev": "tsx src/index.ts",
|
|
23
|
+
"prepublishOnly": "pnpm test && pnpm build"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^22.0.0",
|
|
27
|
+
"@types/picomatch": "^4.0.2",
|
|
28
|
+
"tsx": "^4.19.0",
|
|
29
|
+
"typescript": "^5.7.0",
|
|
30
|
+
"vitest": "^3.0.0"
|
|
31
|
+
},
|
|
32
|
+
"files": ["dist/"],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/anton-kochev/grimoire",
|
|
36
|
+
"directory": "packages/router"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20.0.0"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"picomatch": "^4.0.3"
|
|
43
|
+
}
|
|
44
|
+
}
|