@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
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI argument parsing
|
|
3
|
+
*/
|
|
4
|
+
import type { ParsedArgs } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Parses command line arguments to extract router options.
|
|
7
|
+
*
|
|
8
|
+
* Supported flags:
|
|
9
|
+
* - --agent=<name>: Run in agent mode for SubagentStart hook
|
|
10
|
+
* - --enforce: Run PreToolUse enforcement check
|
|
11
|
+
* - --subagent-start: Register session as a subagent (SubagentStart hook)
|
|
12
|
+
* - --subagent-stop: Remove session from subagent registry (SubagentStop hook)
|
|
13
|
+
*
|
|
14
|
+
* @param argv - The process.argv array (or similar)
|
|
15
|
+
* @returns Parsed arguments object
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseArgs(argv: string[]): ParsedArgs;
|
|
18
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CA6BpD"}
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI argument parsing
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parses command line arguments to extract router options.
|
|
6
|
+
*
|
|
7
|
+
* Supported flags:
|
|
8
|
+
* - --agent=<name>: Run in agent mode for SubagentStart hook
|
|
9
|
+
* - --enforce: Run PreToolUse enforcement check
|
|
10
|
+
* - --subagent-start: Register session as a subagent (SubagentStart hook)
|
|
11
|
+
* - --subagent-stop: Remove session from subagent registry (SubagentStop hook)
|
|
12
|
+
*
|
|
13
|
+
* @param argv - The process.argv array (or similar)
|
|
14
|
+
* @returns Parsed arguments object
|
|
15
|
+
*/
|
|
16
|
+
export function parseArgs(argv) {
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const arg of argv) {
|
|
19
|
+
// Handle --agent=<name> format
|
|
20
|
+
if (arg.startsWith('--agent=')) {
|
|
21
|
+
const value = arg.slice('--agent='.length);
|
|
22
|
+
if (value) {
|
|
23
|
+
result.agent = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (arg === '--enforce')
|
|
27
|
+
result.enforce = true;
|
|
28
|
+
if (arg === '--subagent-start')
|
|
29
|
+
result.subagentStart = true;
|
|
30
|
+
if (arg === '--subagent-stop')
|
|
31
|
+
result.subagentStop = true;
|
|
32
|
+
}
|
|
33
|
+
// Handle --agent <name> format (space-separated)
|
|
34
|
+
for (let i = 0; i < argv.length; i++) {
|
|
35
|
+
if (argv[i] === '--agent' && i + 1 < argv.length) {
|
|
36
|
+
const nextArg = argv[i + 1];
|
|
37
|
+
// Only use as value if it doesn't start with --
|
|
38
|
+
if (nextArg && !nextArg.startsWith('--')) {
|
|
39
|
+
result.agent = nextArg;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=args.js.map
|
package/dist/args.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,SAAS,CAAC,IAAc;IACtC,MAAM,MAAM,GAAe,EAAE,CAAC;IAE9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,+BAA+B;QAC/B,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAC3C,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;YACvB,CAAC;QACH,CAAC;QAED,IAAI,GAAG,KAAK,WAAW;YAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QAC/C,IAAI,GAAG,KAAK,kBAAkB;YAAE,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5D,IAAI,GAAG,KAAK,iBAAiB;YAAE,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC;IAC5D,CAAC;IAED,iDAAiD;IACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YACjD,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5B,gDAAgD;YAChD,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzC,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent enforcement logic for PreToolUse blocking and subagent session registry.
|
|
3
|
+
*/
|
|
4
|
+
import type { EnforceResult, PreToolUseInput, SubagentHookInput } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Pure, testable enforcement check.
|
|
7
|
+
* Returns allow if the tool use should proceed, block with agent names if it should be denied.
|
|
8
|
+
*/
|
|
9
|
+
export declare function evaluateEnforce(input: PreToolUseInput, manifestPath: string, registryPath: string): EnforceResult;
|
|
10
|
+
/**
|
|
11
|
+
* Entry point for --enforce flag (PreToolUse hook).
|
|
12
|
+
* Calls evaluateEnforce, writes block message to stdout, and exits.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runEnforce(input: PreToolUseInput): void;
|
|
15
|
+
/**
|
|
16
|
+
* Registers the current session as a subagent (SubagentStart hook).
|
|
17
|
+
* Idempotent — will not add duplicate session IDs.
|
|
18
|
+
*/
|
|
19
|
+
export declare function runSubagentStart(input: SubagentHookInput, registryPath?: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Removes the current session from the subagent registry (SubagentStop hook).
|
|
22
|
+
* No-op if the session ID or registry file is absent.
|
|
23
|
+
*/
|
|
24
|
+
export declare function runSubagentStop(input: SubagentHookInput, registryPath?: string): void;
|
|
25
|
+
//# sourceMappingURL=enforce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce.d.ts","sourceRoot":"","sources":["../src/enforce.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAgCpF;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,eAAe,EACtB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,aAAa,CA4Df;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAuBvD;AAMD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAWtF;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,iBAAiB,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAYrF"}
|
package/dist/enforce.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent enforcement logic for PreToolUse blocking and subagent session registry.
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
5
|
+
import { basename, dirname, join, matchesGlob } from 'node:path';
|
|
6
|
+
import { loadManifest } from './manifest.js';
|
|
7
|
+
const DEFAULT_REGISTRY_PATH = '.claude/hooks/.grimoire-subagents.json';
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Registry helpers
|
|
10
|
+
// =============================================================================
|
|
11
|
+
function readRegistry(registryPath) {
|
|
12
|
+
if (!existsSync(registryPath))
|
|
13
|
+
return [];
|
|
14
|
+
try {
|
|
15
|
+
const data = JSON.parse(readFileSync(registryPath, 'utf-8'));
|
|
16
|
+
if (data && typeof data === 'object' && 'sessions' in data && Array.isArray(data.sessions)) {
|
|
17
|
+
return data.sessions.filter((s) => typeof s === 'string');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Ignore parse errors — treat as empty
|
|
22
|
+
}
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
function writeRegistry(registryPath, sessions) {
|
|
26
|
+
const dir = dirname(registryPath);
|
|
27
|
+
mkdirSync(dir, { recursive: true });
|
|
28
|
+
writeFileSync(registryPath, JSON.stringify({ sessions }, null, 2) + '\n');
|
|
29
|
+
}
|
|
30
|
+
// =============================================================================
|
|
31
|
+
// Core enforcement logic
|
|
32
|
+
// =============================================================================
|
|
33
|
+
/**
|
|
34
|
+
* Pure, testable enforcement check.
|
|
35
|
+
* Returns allow if the tool use should proceed, block with agent names if it should be denied.
|
|
36
|
+
*/
|
|
37
|
+
export function evaluateEnforce(input, manifestPath, registryPath) {
|
|
38
|
+
// Only block file-editing tools
|
|
39
|
+
if (!['Edit', 'Write', 'MultiEdit'].includes(input.tool_name)) {
|
|
40
|
+
return { action: 'allow' };
|
|
41
|
+
}
|
|
42
|
+
// Subagent bypass: specialist agents are allowed to edit their own files
|
|
43
|
+
const sessions = readRegistry(registryPath);
|
|
44
|
+
if (sessions.includes(input.session_id)) {
|
|
45
|
+
return { action: 'allow' };
|
|
46
|
+
}
|
|
47
|
+
// Load manifest
|
|
48
|
+
let manifest;
|
|
49
|
+
try {
|
|
50
|
+
manifest = loadManifest(manifestPath);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// If manifest is missing or invalid, don't block
|
|
54
|
+
return { action: 'allow' };
|
|
55
|
+
}
|
|
56
|
+
if (!manifest.agents)
|
|
57
|
+
return { action: 'allow' };
|
|
58
|
+
// Collect enforced agents that have file_patterns
|
|
59
|
+
const enforced = Object.entries(manifest.agents).filter(([, entry]) => entry.enforce === true &&
|
|
60
|
+
Array.isArray(entry.file_patterns) &&
|
|
61
|
+
entry.file_patterns.length > 0);
|
|
62
|
+
if (enforced.length === 0)
|
|
63
|
+
return { action: 'allow' };
|
|
64
|
+
// Resolve file path from tool input
|
|
65
|
+
const filePath = typeof input.tool_input['file_path'] === 'string' ? input.tool_input['file_path'] : '';
|
|
66
|
+
if (!filePath)
|
|
67
|
+
return { action: 'allow' };
|
|
68
|
+
const base = basename(filePath);
|
|
69
|
+
const absPath = filePath.startsWith('/') ? filePath : join(process.cwd(), filePath);
|
|
70
|
+
// Check each enforced agent's patterns against both full path and basename
|
|
71
|
+
const matchingAgents = [];
|
|
72
|
+
for (const [agentName, entry] of enforced) {
|
|
73
|
+
const patterns = entry.file_patterns ?? [];
|
|
74
|
+
const matches = patterns.some((pattern) => matchesGlob(absPath, pattern) ||
|
|
75
|
+
matchesGlob(base, pattern) ||
|
|
76
|
+
matchesGlob(filePath, pattern));
|
|
77
|
+
if (matches) {
|
|
78
|
+
matchingAgents.push(agentName);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (matchingAgents.length === 0)
|
|
82
|
+
return { action: 'allow' };
|
|
83
|
+
return { action: 'block', agents: matchingAgents, filePath };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Entry point for --enforce flag (PreToolUse hook).
|
|
87
|
+
* Calls evaluateEnforce, writes block message to stdout, and exits.
|
|
88
|
+
*/
|
|
89
|
+
export function runEnforce(input) {
|
|
90
|
+
const projectDir = process.env['CLAUDE_PROJECT_DIR'] ?? process.cwd();
|
|
91
|
+
const manifestPath = join(projectDir, '.claude', 'skills-manifest.json');
|
|
92
|
+
const registryPath = join(projectDir, DEFAULT_REGISTRY_PATH);
|
|
93
|
+
const result = evaluateEnforce(input, manifestPath, registryPath);
|
|
94
|
+
if (result.action === 'block') {
|
|
95
|
+
const agentList = result.agents.join(', ');
|
|
96
|
+
const message = [
|
|
97
|
+
`Agent enforcement: cannot edit ${result.filePath} directly.`,
|
|
98
|
+
``,
|
|
99
|
+
`This file is owned by: ${agentList}`,
|
|
100
|
+
``,
|
|
101
|
+
`Use the Task tool to delegate this work:`,
|
|
102
|
+
` subagent_type: "${result.agents[0]}"`,
|
|
103
|
+
].join('\n');
|
|
104
|
+
process.stdout.write(message);
|
|
105
|
+
process.exit(2);
|
|
106
|
+
}
|
|
107
|
+
process.exit(0);
|
|
108
|
+
}
|
|
109
|
+
// =============================================================================
|
|
110
|
+
// Subagent session registry
|
|
111
|
+
// =============================================================================
|
|
112
|
+
/**
|
|
113
|
+
* Registers the current session as a subagent (SubagentStart hook).
|
|
114
|
+
* Idempotent — will not add duplicate session IDs.
|
|
115
|
+
*/
|
|
116
|
+
export function runSubagentStart(input, registryPath) {
|
|
117
|
+
const projectDir = process.env['CLAUDE_PROJECT_DIR'] ?? process.cwd();
|
|
118
|
+
const resolvedPath = registryPath ?? join(projectDir, DEFAULT_REGISTRY_PATH);
|
|
119
|
+
const sessions = readRegistry(resolvedPath);
|
|
120
|
+
if (!sessions.includes(input.session_id)) {
|
|
121
|
+
sessions.push(input.session_id);
|
|
122
|
+
writeRegistry(resolvedPath, sessions);
|
|
123
|
+
}
|
|
124
|
+
process.exit(0);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Removes the current session from the subagent registry (SubagentStop hook).
|
|
128
|
+
* No-op if the session ID or registry file is absent.
|
|
129
|
+
*/
|
|
130
|
+
export function runSubagentStop(input, registryPath) {
|
|
131
|
+
const projectDir = process.env['CLAUDE_PROJECT_DIR'] ?? process.cwd();
|
|
132
|
+
const resolvedPath = registryPath ?? join(projectDir, DEFAULT_REGISTRY_PATH);
|
|
133
|
+
const sessions = readRegistry(resolvedPath);
|
|
134
|
+
const updated = sessions.filter((s) => s !== input.session_id);
|
|
135
|
+
if (updated.length !== sessions.length) {
|
|
136
|
+
writeRegistry(resolvedPath, updated);
|
|
137
|
+
}
|
|
138
|
+
process.exit(0);
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=enforce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce.js","sourceRoot":"","sources":["../src/enforce.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,qBAAqB,GAAG,wCAAwC,CAAC;AAEvE,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF,SAAS,YAAY,CAAC,YAAoB;IACxC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;QAAE,OAAO,EAAE,CAAC;IACzC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAY,CAAC;QACxE,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,UAAU,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAE,IAA8B,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtH,OAAQ,IAA+B,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;QACxF,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,uCAAuC;IACzC,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,aAAa,CAAC,YAAoB,EAAE,QAAkB;IAC7D,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY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C,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACtE,MAAM,YAAY,GAAG,YAAY,IAAI,IAAI,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC;IAE7E,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC5C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;QACzC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAChC,aAAa,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAwB,EAAE,YAAqB;IAC7E,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACtE,MAAM,YAAY,GAAG,YAAY,IAAI,IAAI,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC;IAE7E,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,UAAU,CAAC,CAAC;IAE/D,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;QACvC,aAAa,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filtering and sorting functions for skill results
|
|
3
|
+
*/
|
|
4
|
+
import type { SkillScoreResult } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Filters skill results to only those meeting the activation threshold.
|
|
7
|
+
*
|
|
8
|
+
* @param results - Array of skill score results
|
|
9
|
+
* @param threshold - Minimum score required for activation
|
|
10
|
+
* @returns New array with only results where score >= threshold
|
|
11
|
+
*/
|
|
12
|
+
export declare function filterByThreshold(results: SkillScoreResult[], threshold: number): SkillScoreResult[];
|
|
13
|
+
/**
|
|
14
|
+
* Sorts skill results by score descending, with name as tiebreaker.
|
|
15
|
+
*
|
|
16
|
+
* @param results - Array of skill score results
|
|
17
|
+
* @returns New array sorted by score descending, then name ascending
|
|
18
|
+
*/
|
|
19
|
+
export declare function sortDescendingByScore(results: SkillScoreResult[]): SkillScoreResult[];
|
|
20
|
+
//# sourceMappingURL=filtering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../src/filtering.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,gBAAgB,EAAE,EAC3B,SAAS,EAAE,MAAM,GAChB,gBAAgB,EAAE,CAEpB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,gBAAgB,EAAE,CASpB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filtering and sorting functions for skill results
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Filters skill results to only those meeting the activation threshold.
|
|
6
|
+
*
|
|
7
|
+
* @param results - Array of skill score results
|
|
8
|
+
* @param threshold - Minimum score required for activation
|
|
9
|
+
* @returns New array with only results where score >= threshold
|
|
10
|
+
*/
|
|
11
|
+
export function filterByThreshold(results, threshold) {
|
|
12
|
+
return results.filter((result) => result.score >= threshold);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Sorts skill results by score descending, with name as tiebreaker.
|
|
16
|
+
*
|
|
17
|
+
* @param results - Array of skill score results
|
|
18
|
+
* @returns New array sorted by score descending, then name ascending
|
|
19
|
+
*/
|
|
20
|
+
export function sortDescendingByScore(results) {
|
|
21
|
+
return [...results].sort((a, b) => {
|
|
22
|
+
// Primary sort: score descending
|
|
23
|
+
if (b.score !== a.score) {
|
|
24
|
+
return b.score - a.score;
|
|
25
|
+
}
|
|
26
|
+
// Secondary sort: name ascending (alphabetical)
|
|
27
|
+
return a.skill.name.localeCompare(b.skill.name);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=filtering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering.js","sourceRoot":"","sources":["../src/filtering.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAA2B,EAC3B,SAAiB;IAEjB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAA2B;IAE3B,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAChC,iCAAiC;QACjC,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC;YACxB,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;QAC3B,CAAC;QACD,gDAAgD;QAChD,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formatting functions
|
|
3
|
+
*/
|
|
4
|
+
import type { MatchedSignal, SkillScoreResult } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Summarizes matched signals into a human-readable string.
|
|
7
|
+
*
|
|
8
|
+
* Format: keywords[a, b], extensions[.pdf], patterns[2 matched], paths[invoices/]
|
|
9
|
+
*
|
|
10
|
+
* @param signals - Array of matched signals
|
|
11
|
+
* @returns Formatted summary string
|
|
12
|
+
*/
|
|
13
|
+
export declare function summarizeSignals(signals: MatchedSignal[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Formats matched skills into context injection message.
|
|
16
|
+
* When skill content is provided, injects the SKILL.md body directly.
|
|
17
|
+
*
|
|
18
|
+
* @param matchedSkills - Array of skill score results
|
|
19
|
+
* @param skillContents - Optional map of skill path to SKILL.md body content
|
|
20
|
+
* @returns Formatted context string for LLM injection
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatContext(matchedSkills: SkillScoreResult[], skillContents?: Map<string, string>): string;
|
|
23
|
+
//# sourceMappingURL=formatting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,MAAM,CAsCjE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,aAAa,EAAE,gBAAgB,EAAE,EACjC,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,MAAM,CAiDR"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formatting functions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Summarizes matched signals into a human-readable string.
|
|
6
|
+
*
|
|
7
|
+
* Format: keywords[a, b], extensions[.pdf], patterns[2 matched], paths[invoices/]
|
|
8
|
+
*
|
|
9
|
+
* @param signals - Array of matched signals
|
|
10
|
+
* @returns Formatted summary string
|
|
11
|
+
*/
|
|
12
|
+
export function summarizeSignals(signals) {
|
|
13
|
+
if (signals.length === 0) {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
// Group signals by type
|
|
17
|
+
const groups = {};
|
|
18
|
+
for (const signal of signals) {
|
|
19
|
+
if (!groups[signal.type]) {
|
|
20
|
+
groups[signal.type] = [];
|
|
21
|
+
}
|
|
22
|
+
groups[signal.type].push(signal.value);
|
|
23
|
+
}
|
|
24
|
+
const parts = [];
|
|
25
|
+
// Keywords
|
|
26
|
+
if (groups['keyword']) {
|
|
27
|
+
parts.push(`keywords[${groups['keyword'].join(', ')}]`);
|
|
28
|
+
}
|
|
29
|
+
// Extensions
|
|
30
|
+
if (groups['extension']) {
|
|
31
|
+
parts.push(`extensions[${groups['extension'].join(', ')}]`);
|
|
32
|
+
}
|
|
33
|
+
// Patterns (show count, not values)
|
|
34
|
+
if (groups['pattern']) {
|
|
35
|
+
parts.push(`patterns[${groups['pattern'].length} matched]`);
|
|
36
|
+
}
|
|
37
|
+
// Paths
|
|
38
|
+
if (groups['path']) {
|
|
39
|
+
parts.push(`paths[${groups['path'].join(', ')}]`);
|
|
40
|
+
}
|
|
41
|
+
return parts.join(', ');
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Formats matched skills into context injection message.
|
|
45
|
+
* When skill content is provided, injects the SKILL.md body directly.
|
|
46
|
+
*
|
|
47
|
+
* @param matchedSkills - Array of skill score results
|
|
48
|
+
* @param skillContents - Optional map of skill path to SKILL.md body content
|
|
49
|
+
* @returns Formatted context string for LLM injection
|
|
50
|
+
*/
|
|
51
|
+
export function formatContext(matchedSkills, skillContents) {
|
|
52
|
+
const lines = [];
|
|
53
|
+
lines.push('[Skill Router] The following skills are relevant to this request:');
|
|
54
|
+
lines.push('');
|
|
55
|
+
for (const result of matchedSkills) {
|
|
56
|
+
const skillLine = `• ${result.skill.name} (${result.skill.path}/SKILL.md)` +
|
|
57
|
+
` — score: ${result.score.toFixed(1)}`;
|
|
58
|
+
lines.push(skillLine);
|
|
59
|
+
// Add matched signals as sub-item
|
|
60
|
+
const signalSummary = summarizeSignals(result.matchedSignals);
|
|
61
|
+
if (signalSummary) {
|
|
62
|
+
lines.push(` Matched: ${signalSummary}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Inject skill content if available
|
|
66
|
+
const injectedAny = skillContents != null && skillContents.size > 0 &&
|
|
67
|
+
matchedSkills.some((r) => skillContents.has(r.skill.path));
|
|
68
|
+
if (injectedAny) {
|
|
69
|
+
for (const result of matchedSkills) {
|
|
70
|
+
const content = skillContents.get(result.skill.path);
|
|
71
|
+
if (content) {
|
|
72
|
+
lines.push('');
|
|
73
|
+
lines.push('---');
|
|
74
|
+
lines.push(`### ${result.skill.name} (${result.skill.path}/SKILL.md)`);
|
|
75
|
+
lines.push('');
|
|
76
|
+
lines.push(content);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
lines.push('');
|
|
80
|
+
lines.push('Follow the skill instructions above. Read referenced files within skills as needed.');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
lines.push('');
|
|
84
|
+
lines.push('Please read the SKILL.md file(s) listed above using the view tool before proceeding with the task.');
|
|
85
|
+
}
|
|
86
|
+
return lines.join('\n');
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=formatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAwB;IACvD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,wBAAwB;IACxB,MAAM,MAAM,GAA6B,EAA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,CAAC;gBACf,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CACR,qFAAqF,CACtF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CACR,oGAAoG,CACrG,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @grimoire-cc/router
|
|
3
|
+
*
|
|
4
|
+
* Hook runtime for Grimoire — skill auto-activation and agent enforcement.
|
|
5
|
+
* Matches user prompts against configured skill triggers
|
|
6
|
+
* and injects relevant skill references into LLM context.
|
|
7
|
+
*/
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export * from './normalize.js';
|
|
10
|
+
export * from './signals.js';
|
|
11
|
+
export * from './scoring.js';
|
|
12
|
+
export * from './matching.js';
|
|
13
|
+
export * from './filtering.js';
|
|
14
|
+
export * from './formatting.js';
|
|
15
|
+
export * from './manifest.js';
|
|
16
|
+
export * from './input.js';
|
|
17
|
+
export * from './logging.js';
|
|
18
|
+
export * from './output.js';
|
|
19
|
+
export * from './args.js';
|
|
20
|
+
export * from './tool-input.js';
|
|
21
|
+
export * from './tool-formatting.js';
|
|
22
|
+
export * from './tool-output.js';
|
|
23
|
+
export * from './main.js';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @grimoire-cc/router
|
|
3
|
+
*
|
|
4
|
+
* Hook runtime for Grimoire — skill auto-activation and agent enforcement.
|
|
5
|
+
* Matches user prompts against configured skill triggers
|
|
6
|
+
* and injects relevant skill references into LLM context.
|
|
7
|
+
*/
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export * from './normalize.js';
|
|
10
|
+
export * from './signals.js';
|
|
11
|
+
export * from './scoring.js';
|
|
12
|
+
export * from './matching.js';
|
|
13
|
+
export * from './filtering.js';
|
|
14
|
+
export * from './formatting.js';
|
|
15
|
+
export * from './manifest.js';
|
|
16
|
+
export * from './input.js';
|
|
17
|
+
export * from './logging.js';
|
|
18
|
+
export * from './output.js';
|
|
19
|
+
export * from './args.js';
|
|
20
|
+
export * from './tool-input.js';
|
|
21
|
+
export * from './tool-formatting.js';
|
|
22
|
+
export * from './tool-output.js';
|
|
23
|
+
export * from './main.js';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
|
package/dist/input.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook input parsing
|
|
3
|
+
*/
|
|
4
|
+
import type { HookInput, PreToolUseInput } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Discriminated union for stdin input types
|
|
7
|
+
*/
|
|
8
|
+
export type StdinInput = {
|
|
9
|
+
kind: 'prompt';
|
|
10
|
+
input: HookInput;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'tooluse';
|
|
13
|
+
input: PreToolUseInput;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Parses stdin JSON and dispatches to the appropriate parser based on shape.
|
|
17
|
+
*
|
|
18
|
+
* If the data contains a `tool_name` field, it's treated as PreToolUse input.
|
|
19
|
+
* Otherwise, it's treated as a prompt-based hook input (UserPromptSubmit/SubagentStart).
|
|
20
|
+
*
|
|
21
|
+
* @param jsonString - Raw JSON string from stdin
|
|
22
|
+
* @returns Discriminated StdinInput union
|
|
23
|
+
* @throws Error if input is empty, invalid JSON, or validation fails
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseStdinInput(jsonString: string): StdinInput;
|
|
26
|
+
/**
|
|
27
|
+
* Parses hook input from JSON string.
|
|
28
|
+
*
|
|
29
|
+
* @param jsonString - Raw JSON string from stdin
|
|
30
|
+
* @returns Validated HookInput
|
|
31
|
+
* @throws Error if input is empty, invalid JSON, or missing required fields
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseHookInput(jsonString: string): HookInput;
|
|
34
|
+
/**
|
|
35
|
+
* Reads input from stdin synchronously.
|
|
36
|
+
*
|
|
37
|
+
* @returns Raw string from stdin
|
|
38
|
+
*/
|
|
39
|
+
export declare function readStdin(): string;
|
|
40
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7D;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAmB9D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAwC5D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAMlC"}
|
package/dist/input.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook input parsing
|
|
3
|
+
*/
|
|
4
|
+
import { readFileSync } from 'fs';
|
|
5
|
+
import { isPreToolUseInput, parsePreToolUseInput } from './tool-input.js';
|
|
6
|
+
/**
|
|
7
|
+
* Parses stdin JSON and dispatches to the appropriate parser based on shape.
|
|
8
|
+
*
|
|
9
|
+
* If the data contains a `tool_name` field, it's treated as PreToolUse input.
|
|
10
|
+
* Otherwise, it's treated as a prompt-based hook input (UserPromptSubmit/SubagentStart).
|
|
11
|
+
*
|
|
12
|
+
* @param jsonString - Raw JSON string from stdin
|
|
13
|
+
* @returns Discriminated StdinInput union
|
|
14
|
+
* @throws Error if input is empty, invalid JSON, or validation fails
|
|
15
|
+
*/
|
|
16
|
+
export function parseStdinInput(jsonString) {
|
|
17
|
+
if (!jsonString || !jsonString.trim()) {
|
|
18
|
+
throw new Error('Hook input is empty');
|
|
19
|
+
}
|
|
20
|
+
// Peek at the parsed data to determine type
|
|
21
|
+
let data;
|
|
22
|
+
try {
|
|
23
|
+
data = JSON.parse(jsonString);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
27
|
+
throw new Error(`Failed to parse hook input JSON: ${message}`);
|
|
28
|
+
}
|
|
29
|
+
if (isPreToolUseInput(data)) {
|
|
30
|
+
return { kind: 'tooluse', input: parsePreToolUseInput(jsonString) };
|
|
31
|
+
}
|
|
32
|
+
return { kind: 'prompt', input: parseHookInput(jsonString) };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parses hook input from JSON string.
|
|
36
|
+
*
|
|
37
|
+
* @param jsonString - Raw JSON string from stdin
|
|
38
|
+
* @returns Validated HookInput
|
|
39
|
+
* @throws Error if input is empty, invalid JSON, or missing required fields
|
|
40
|
+
*/
|
|
41
|
+
export function parseHookInput(jsonString) {
|
|
42
|
+
// Check for empty input
|
|
43
|
+
if (!jsonString || !jsonString.trim()) {
|
|
44
|
+
throw new Error('Hook input is empty');
|
|
45
|
+
}
|
|
46
|
+
// Parse JSON
|
|
47
|
+
let data;
|
|
48
|
+
try {
|
|
49
|
+
data = JSON.parse(jsonString);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
+
throw new Error(`Failed to parse hook input JSON: ${message}`);
|
|
54
|
+
}
|
|
55
|
+
if (!data || typeof data !== 'object') {
|
|
56
|
+
throw new Error('Hook input must be an object');
|
|
57
|
+
}
|
|
58
|
+
const input = data;
|
|
59
|
+
// Validate prompt (required)
|
|
60
|
+
if (input['prompt'] === undefined || input['prompt'] === null) {
|
|
61
|
+
throw new Error('Hook input must have a prompt field');
|
|
62
|
+
}
|
|
63
|
+
if (typeof input['prompt'] !== 'string') {
|
|
64
|
+
throw new Error('Hook input prompt must be a string');
|
|
65
|
+
}
|
|
66
|
+
// Apply defaults for optional fields
|
|
67
|
+
return {
|
|
68
|
+
prompt: input['prompt'],
|
|
69
|
+
session_id: typeof input['session_id'] === 'string' ? input['session_id'] : 'unknown',
|
|
70
|
+
timestamp: typeof input['timestamp'] === 'string'
|
|
71
|
+
? input['timestamp']
|
|
72
|
+
: new Date().toISOString(),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Reads input from stdin synchronously.
|
|
77
|
+
*
|
|
78
|
+
* @returns Raw string from stdin
|
|
79
|
+
*/
|
|
80
|
+
export function readStdin() {
|
|
81
|
+
try {
|
|
82
|
+
return readFileSync(0, 'utf-8');
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=input.js.map
|