@pennyfarthing/cyclist 9.4.0 → 10.0.1
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/LICENSE +14 -0
- package/dist/api/hook-request.d.ts +11 -0
- package/dist/api/hook-request.d.ts.map +1 -1
- package/dist/api/hook-request.js +126 -28
- package/dist/api/hook-request.js.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/permissions.d.ts +16 -0
- package/dist/api/permissions.d.ts.map +1 -0
- package/dist/api/permissions.js +67 -0
- package/dist/api/permissions.js.map +1 -0
- package/dist/api/theme-agents.d.ts +4 -0
- package/dist/api/theme-agents.d.ts.map +1 -1
- package/dist/api/theme-agents.js +3 -0
- package/dist/api/theme-agents.js.map +1 -1
- package/dist/approval-gate.d.ts +3 -75
- package/dist/approval-gate.d.ts.map +1 -1
- package/dist/approval-gate.js +4 -121
- package/dist/approval-gate.js.map +1 -1
- package/dist/hooks/cyclist-pretooluse-hook.d.ts +60 -0
- package/dist/hooks/cyclist-pretooluse-hook.d.ts.map +1 -0
- package/dist/hooks/cyclist-pretooluse-hook.js +57 -0
- package/dist/hooks/cyclist-pretooluse-hook.js.map +1 -0
- package/dist/hooks/pretooluse-hook.d.ts +89 -0
- package/dist/hooks/pretooluse-hook.d.ts.map +1 -0
- package/dist/hooks/pretooluse-hook.js +235 -0
- package/dist/hooks/pretooluse-hook.js.map +1 -0
- package/dist/main.d.ts +1 -134
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +42 -373
- package/dist/main.js.map +1 -1
- package/dist/menu-builder.d.ts +7 -1
- package/dist/menu-builder.d.ts.map +1 -1
- package/dist/menu-builder.js +36 -1
- package/dist/menu-builder.js.map +1 -1
- package/dist/otlp-receiver.d.ts.map +1 -1
- package/dist/otlp-receiver.js +6 -0
- package/dist/otlp-receiver.js.map +1 -1
- package/dist/public/css/react.css +1 -1
- package/dist/public/js/react/react.js +41 -41
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +14 -3
- package/dist/server.js.map +1 -1
- package/dist/settings-store.d.ts +3 -1
- package/dist/settings-store.d.ts.map +1 -1
- package/dist/settings-store.js +18 -9
- package/dist/settings-store.js.map +1 -1
- package/dist/websocket.d.ts +1 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +48 -5
- package/dist/websocket.js.map +1 -1
- package/dist/workflow-presets.d.ts +72 -0
- package/dist/workflow-presets.d.ts.map +1 -0
- package/dist/workflow-presets.js +93 -0
- package/dist/workflow-presets.js.map +1 -0
- package/package.json +31 -32
- package/src/public/App.tsx +59 -1
- package/src/public/components/ApprovalModal/index.tsx +31 -1
- package/src/public/components/AskUserQuestionBlock.tsx +162 -0
- package/src/public/components/ControlBar.tsx +18 -19
- package/src/public/components/DockviewWorkspace.tsx +35 -5
- package/src/public/components/Message.tsx +58 -2
- package/src/public/components/MessageView.tsx +47 -3
- package/src/public/components/PersonaHeader.tsx +3 -1
- package/src/public/components/panels/BackgroundPanel.tsx +1 -1
- package/src/public/components/panels/MessagePanel.tsx +66 -4
- package/src/public/components/panels/SettingsPanel.tsx +3 -28
- package/src/public/components/panels/WorkflowPanel.tsx +25 -3
- package/src/public/contexts/ClaudeContext.tsx +16 -1
- package/src/public/hooks/useColorScheme.ts +27 -0
- package/src/public/hooks/usePlanModeExit.ts +105 -0
- package/src/public/styles/dockview-theme.css +31 -33
- package/src/public/styles/tailwind.css +199 -18
- package/src/public/types/message.ts +2 -1
- package/src/public/utils/askUserQuestion.ts +21 -0
- package/src/public/utils/markdown.ts +2 -2
package/dist/approval-gate.js
CHANGED
|
@@ -1,114 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Approval Gate for Tool Permissions (Story
|
|
2
|
+
* Approval Gate for Tool Permissions (Story 33-3)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* in the renderer process via IPC.
|
|
7
|
-
*
|
|
8
|
-
* Flow:
|
|
9
|
-
* 1. Claude emits tool_use message (Bash, WebFetch, Edit, Write, etc.)
|
|
10
|
-
* 2. This module intercepts and checks settings
|
|
11
|
-
* 3. If gate enabled and not allowlisted, request approval via IPC
|
|
12
|
-
* 4. Wait for user response (approve/reject/always-allow)
|
|
13
|
-
* 5. Continue execution or inject rejection error
|
|
14
|
-
*
|
|
15
|
-
* Story 33-3: Added generic interceptToolUse for any tool type.
|
|
16
|
-
*/
|
|
17
|
-
import { getBashApprovalGate, isAllowlisted, addToAllowlist, extractPattern, addGrant, checkGrant } from './settings-store.js';
|
|
18
|
-
/**
|
|
19
|
-
* Pending approval requests, keyed by tool_id
|
|
20
|
-
* Each entry holds the resolve function for the approval promise
|
|
21
|
-
*/
|
|
22
|
-
const pendingApprovals = new Map();
|
|
23
|
-
/**
|
|
24
|
-
* Request approval for a Bash command
|
|
25
|
-
* Returns a promise that resolves when the user approves or rejects
|
|
26
|
-
*
|
|
27
|
-
* @param command - The Bash command to approve
|
|
28
|
-
* @param toolId - The tool_use_id from Claude
|
|
29
|
-
* @returns Promise<boolean> - true if approved, false if rejected
|
|
30
|
-
*/
|
|
31
|
-
export function requestApproval(command, toolId) {
|
|
32
|
-
return new Promise((resolve) => {
|
|
33
|
-
pendingApprovals.set(toolId, { resolve, command });
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Resolve a pending approval request
|
|
38
|
-
* Called by IPC handler when user responds to approval modal
|
|
39
|
-
*
|
|
40
|
-
* @param toolId - The tool_use_id to resolve
|
|
41
|
-
* @param approved - true if approved, false if rejected
|
|
42
|
-
* @param grantScope - Grant scope: 'once', 'session', or 'always'
|
|
4
|
+
* Intercepts tool_use messages and checks whether they need
|
|
5
|
+
* user approval based on settings, allowlists, and grants.
|
|
43
6
|
*/
|
|
44
|
-
|
|
45
|
-
const pending = pendingApprovals.get(toolId);
|
|
46
|
-
if (pending) {
|
|
47
|
-
// Add grant based on scope
|
|
48
|
-
if (approved && grantScope) {
|
|
49
|
-
const pattern = extractPattern(pending.command);
|
|
50
|
-
addGrant({
|
|
51
|
-
tool: 'Bash',
|
|
52
|
-
scope: pattern,
|
|
53
|
-
grant_type: grantScope,
|
|
54
|
-
granted_at: new Date().toISOString(),
|
|
55
|
-
});
|
|
56
|
-
// For backwards compatibility, also add to allowlist for 'always' grants
|
|
57
|
-
if (grantScope === 'always') {
|
|
58
|
-
addToAllowlist(pattern);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
pending.resolve(approved);
|
|
62
|
-
pendingApprovals.delete(toolId);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Create a tool_result error message for rejected commands
|
|
67
|
-
*
|
|
68
|
-
* @param toolId - The tool_use_id that was rejected
|
|
69
|
-
* @returns SDKToolResultError message to inject into the conversation
|
|
70
|
-
*/
|
|
71
|
-
export function createRejectionError(toolId) {
|
|
72
|
-
return {
|
|
73
|
-
type: 'tool_result',
|
|
74
|
-
tool_id: toolId,
|
|
75
|
-
output: 'Command rejected by user. The user declined to execute this command.',
|
|
76
|
-
is_error: true,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Check if a tool_use message is a Bash command that needs approval
|
|
81
|
-
*
|
|
82
|
-
* @param message - The SDK message to check
|
|
83
|
-
* @returns Object with shouldApprove boolean, command string, and toolId
|
|
84
|
-
*/
|
|
85
|
-
export function interceptBashToolUse(message) {
|
|
86
|
-
const result = { shouldApprove: false, command: '', toolId: '' };
|
|
87
|
-
// Check if this is a Bash tool_use
|
|
88
|
-
if (message.type !== 'tool_use' || message.tool_name !== 'Bash') {
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
const command = message.input?.command || '';
|
|
92
|
-
const toolId = message.tool_id || '';
|
|
93
|
-
// Check if approval gate is enabled
|
|
94
|
-
if (!getBashApprovalGate()) {
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
// Check if command is allowlisted
|
|
98
|
-
if (isAllowlisted(command)) {
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
// Check if command matches an existing grant (this also auto-revokes 'once' grants)
|
|
102
|
-
if (checkGrant('Bash', command)) {
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
// Need approval
|
|
106
|
-
return {
|
|
107
|
-
shouldApprove: true,
|
|
108
|
-
command,
|
|
109
|
-
toolId,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
7
|
+
import { getBashApprovalGate, isAllowlisted, checkGrant } from './settings-store.js';
|
|
112
8
|
/**
|
|
113
9
|
* Check if a tool_use message needs approval (Story 33-3)
|
|
114
10
|
* Works with any tool type, not just Bash.
|
|
@@ -173,17 +69,4 @@ function getToolScope(toolName, input) {
|
|
|
173
69
|
return JSON.stringify(input);
|
|
174
70
|
}
|
|
175
71
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Get the number of pending approval requests
|
|
178
|
-
* Useful for testing and debugging
|
|
179
|
-
*/
|
|
180
|
-
export function getQueueLength() {
|
|
181
|
-
return pendingApprovals.size;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Clear all pending approvals (for testing)
|
|
185
|
-
*/
|
|
186
|
-
export function clearPendingApprovals() {
|
|
187
|
-
pendingApprovals.clear();
|
|
188
|
-
}
|
|
189
72
|
//# sourceMappingURL=approval-gate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-gate.js","sourceRoot":"","sources":["../src/approval-gate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"approval-gate.js","sourceRoot":"","sources":["../src/approval-gate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAsBrF;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OA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;AACH,SAAS,YAAY,CAAC,QAAgB,EAAE,KAA8B;IACpE,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,MAAM;YACT,OAAQ,KAAK,CAAC,OAAkB,IAAI,EAAE,CAAC;QACzC,KAAK,UAAU;YACb,OAAQ,KAAK,CAAC,GAAc,IAAI,EAAE,CAAC;QACrC,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO,CAAC;QACb,KAAK,MAAM;YACT,OAAQ,KAAK,CAAC,SAAoB,IAAI,EAAE,CAAC;QAC3C;YACE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cyclist PreToolUse Hook - Core Logic
|
|
3
|
+
*
|
|
4
|
+
* Testable module containing all hook logic. Invoked via cyclist-pretooluse-hook.sh
|
|
5
|
+
* which calls `npx tsx` on this file, matching the .sh wrapper pattern used by
|
|
6
|
+
* all other hooks in .claude/settings.local.json.
|
|
7
|
+
*
|
|
8
|
+
* Flow:
|
|
9
|
+
* 1. Claude Code calls cyclist-pretooluse-hook.sh with tool info via stdin (JSON)
|
|
10
|
+
* 2. Shell wrapper invokes this module via npx tsx
|
|
11
|
+
* 3. Script reads port from .cyclist-port in project directory
|
|
12
|
+
* 4. Script sends request to WheelHub's /api/hook-request endpoint
|
|
13
|
+
* 5. WheelHub checks grants / shows approval modal, user decides
|
|
14
|
+
* 6. Script receives response, outputs JSON decision to stdout
|
|
15
|
+
* 7. Claude Code proceeds or blocks based on decision
|
|
16
|
+
*
|
|
17
|
+
* Per ADR-0004: All communication converges through WheelHub.
|
|
18
|
+
*
|
|
19
|
+
* Story: MSSCI-14320 - Update and register PreToolUse hook
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_PORT = 7432;
|
|
22
|
+
export declare const HOST = "127.0.0.1";
|
|
23
|
+
export declare const TIMEOUT_MS = 120000;
|
|
24
|
+
export declare const PORT_FILE = ".cyclist-port";
|
|
25
|
+
export declare const LEGACY_PORT_FILE = ".cyclist-approval-port";
|
|
26
|
+
export declare const ENDPOINT = "/api/hook-request";
|
|
27
|
+
export interface ToolData {
|
|
28
|
+
tool_name: string;
|
|
29
|
+
tool_use_id: string;
|
|
30
|
+
tool_input: Record<string, unknown>;
|
|
31
|
+
session_id?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ApprovalRequest {
|
|
34
|
+
toolName: string;
|
|
35
|
+
toolId: string;
|
|
36
|
+
input: Record<string, unknown>;
|
|
37
|
+
sessionId?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ApprovalResponse {
|
|
40
|
+
decision: 'allow' | 'deny' | 'ask';
|
|
41
|
+
reason?: string;
|
|
42
|
+
data?: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
export interface HookOutput {
|
|
45
|
+
hookSpecificOutput: {
|
|
46
|
+
hookEventName: 'PreToolUse';
|
|
47
|
+
permissionDecision: string;
|
|
48
|
+
permissionDecisionReason: string;
|
|
49
|
+
updatedInput?: Record<string, unknown>;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export declare function findProjectRoot(startDir?: string): string | null;
|
|
53
|
+
export declare function getPort(projectRoot?: string | null): number;
|
|
54
|
+
export declare function readPortFile(filePath: string): number | null;
|
|
55
|
+
export declare function readStdin(): Promise<ToolData>;
|
|
56
|
+
export declare function requestApproval(toolData: ApprovalRequest, port?: number): Promise<ApprovalResponse>;
|
|
57
|
+
export declare function buildOutput(decision: string, reason: string, updatedInput?: Record<string, unknown> | null): HookOutput;
|
|
58
|
+
export declare function outputDecision(decision: string, reason: string, updatedInput?: Record<string, unknown> | null): void;
|
|
59
|
+
export declare function main(): Promise<void>;
|
|
60
|
+
//# sourceMappingURL=cyclist-pretooluse-hook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cyclist-pretooluse-hook.d.ts","sourceRoot":"","sources":["../../src/hooks/c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AAG,MAAM,CAE3D;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE5D;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,CAEnD;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,eAAe,EACzB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,gBAAgB,CAAC,CAE3B;AAED,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAC5C,UAAU,CAEZ;AAED,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAC5C,IAAI,CAEN;AAED,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1C"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cyclist PreToolUse Hook - Core Logic
|
|
3
|
+
*
|
|
4
|
+
* Testable module containing all hook logic. Invoked via cyclist-pretooluse-hook.sh
|
|
5
|
+
* which calls `npx tsx` on this file, matching the .sh wrapper pattern used by
|
|
6
|
+
* all other hooks in .claude/settings.local.json.
|
|
7
|
+
*
|
|
8
|
+
* Flow:
|
|
9
|
+
* 1. Claude Code calls cyclist-pretooluse-hook.sh with tool info via stdin (JSON)
|
|
10
|
+
* 2. Shell wrapper invokes this module via npx tsx
|
|
11
|
+
* 3. Script reads port from .cyclist-port in project directory
|
|
12
|
+
* 4. Script sends request to WheelHub's /api/hook-request endpoint
|
|
13
|
+
* 5. WheelHub checks grants / shows approval modal, user decides
|
|
14
|
+
* 6. Script receives response, outputs JSON decision to stdout
|
|
15
|
+
* 7. Claude Code proceeds or blocks based on decision
|
|
16
|
+
*
|
|
17
|
+
* Per ADR-0004: All communication converges through WheelHub.
|
|
18
|
+
*
|
|
19
|
+
* Story: MSSCI-14320 - Update and register PreToolUse hook
|
|
20
|
+
*/
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// Constants
|
|
23
|
+
// =============================================================================
|
|
24
|
+
export const DEFAULT_PORT = 7432;
|
|
25
|
+
export const HOST = '127.0.0.1';
|
|
26
|
+
export const TIMEOUT_MS = 120_000; // 2 minutes for user to decide
|
|
27
|
+
export const PORT_FILE = '.cyclist-port';
|
|
28
|
+
export const LEGACY_PORT_FILE = '.cyclist-approval-port';
|
|
29
|
+
export const ENDPOINT = '/api/hook-request';
|
|
30
|
+
// =============================================================================
|
|
31
|
+
// Stubs - Dev implements these to GREEN
|
|
32
|
+
// =============================================================================
|
|
33
|
+
export function findProjectRoot(startDir) {
|
|
34
|
+
throw new Error('findProjectRoot not implemented');
|
|
35
|
+
}
|
|
36
|
+
export function getPort(projectRoot) {
|
|
37
|
+
throw new Error('getPort not implemented');
|
|
38
|
+
}
|
|
39
|
+
export function readPortFile(filePath) {
|
|
40
|
+
throw new Error('readPortFile not implemented');
|
|
41
|
+
}
|
|
42
|
+
export async function readStdin() {
|
|
43
|
+
throw new Error('readStdin not implemented');
|
|
44
|
+
}
|
|
45
|
+
export async function requestApproval(toolData, port) {
|
|
46
|
+
throw new Error('requestApproval not implemented');
|
|
47
|
+
}
|
|
48
|
+
export function buildOutput(decision, reason, updatedInput) {
|
|
49
|
+
throw new Error('buildOutput not implemented');
|
|
50
|
+
}
|
|
51
|
+
export function outputDecision(decision, reason, updatedInput) {
|
|
52
|
+
throw new Error('outputDecision not implemented');
|
|
53
|
+
}
|
|
54
|
+
export async function main() {
|
|
55
|
+
throw new Error('main not implemented');
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=cyclist-pretooluse-hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cyclist-pretooluse-hook.js","sourceRoot":"","sources":["../../src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AAC;AACpD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI;IACxB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cyclist PreToolUse Hook - Core Logic
|
|
3
|
+
*
|
|
4
|
+
* Testable module containing all hook logic. The companion runner script
|
|
5
|
+
* (cyclist-pretooluse-hook.js) imports from the compiled output and invokes main().
|
|
6
|
+
*
|
|
7
|
+
* Flow:
|
|
8
|
+
* 1. Claude Code calls the runner script with tool info via stdin (JSON)
|
|
9
|
+
* 2. Script reads port from .cyclist-port in project directory
|
|
10
|
+
* 3. Script sends request to WheelHub's /api/hook-request endpoint
|
|
11
|
+
* 4. WheelHub checks grants / shows approval modal, user decides
|
|
12
|
+
* 5. Script receives response, outputs JSON decision to stdout
|
|
13
|
+
* 6. Claude Code proceeds or blocks based on decision
|
|
14
|
+
*
|
|
15
|
+
* Per ADR-0004: All communication converges through WheelHub.
|
|
16
|
+
*
|
|
17
|
+
* Story: MSSCI-14320 - Update and register PreToolUse hook
|
|
18
|
+
*/
|
|
19
|
+
export declare const DEFAULT_PORT = 7432;
|
|
20
|
+
export declare const HOST = "127.0.0.1";
|
|
21
|
+
export declare const TIMEOUT_MS = 120000;
|
|
22
|
+
export declare const PORT_FILE = ".cyclist-port";
|
|
23
|
+
export declare const LEGACY_PORT_FILE = ".cyclist-approval-port";
|
|
24
|
+
export declare const ENDPOINT = "/api/hook-request";
|
|
25
|
+
export interface ToolData {
|
|
26
|
+
tool_name: string;
|
|
27
|
+
tool_use_id: string;
|
|
28
|
+
tool_input: Record<string, unknown>;
|
|
29
|
+
session_id?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ApprovalRequest {
|
|
32
|
+
toolName: string;
|
|
33
|
+
toolId: string;
|
|
34
|
+
input: Record<string, unknown>;
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface ApprovalResponse {
|
|
38
|
+
decision: 'allow' | 'deny' | 'ask';
|
|
39
|
+
reason?: string;
|
|
40
|
+
data?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
export interface HookOutput {
|
|
43
|
+
hookSpecificOutput: {
|
|
44
|
+
hookEventName: 'PreToolUse';
|
|
45
|
+
permissionDecision: string;
|
|
46
|
+
permissionDecisionReason: string;
|
|
47
|
+
updatedInput?: Record<string, unknown>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Find the project root by looking for port files or .claude directory.
|
|
52
|
+
* Walks up from startDir (defaults to cwd) until found or reaches filesystem root.
|
|
53
|
+
*/
|
|
54
|
+
export declare function findProjectRoot(startDir?: string): string | null;
|
|
55
|
+
/**
|
|
56
|
+
* Read the WheelHub server port. Prefers .cyclist-port, falls back to
|
|
57
|
+
* .cyclist-approval-port for migration compatibility, then default port.
|
|
58
|
+
*
|
|
59
|
+
* Mirrors hooks.py:get_cyclist_port() behavior.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getPort(projectRoot?: string | null): number;
|
|
62
|
+
/**
|
|
63
|
+
* Read a port number from a file. Returns null if file doesn't exist or is invalid.
|
|
64
|
+
*/
|
|
65
|
+
export declare function readPortFile(filePath: string): number | null;
|
|
66
|
+
/**
|
|
67
|
+
* Read all stdin as JSON.
|
|
68
|
+
*/
|
|
69
|
+
export declare function readStdin(): Promise<ToolData>;
|
|
70
|
+
/**
|
|
71
|
+
* Send approval request to WheelHub and wait for response.
|
|
72
|
+
* Returns { decision: "ask" } when WheelHub is unreachable (ECONNREFUSED).
|
|
73
|
+
*/
|
|
74
|
+
export declare function requestApproval(toolData: ApprovalRequest, port?: number): Promise<ApprovalResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Build the Claude Code hook output object.
|
|
77
|
+
* MSSCI-11947: Supports updatedInput passthrough for interactive tools.
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildOutput(decision: string, reason: string, updatedInput?: Record<string, unknown> | null): HookOutput;
|
|
80
|
+
/**
|
|
81
|
+
* Output decision to stdout in Claude Code hook format.
|
|
82
|
+
*/
|
|
83
|
+
export declare function outputDecision(decision: string, reason: string, updatedInput?: Record<string, unknown> | null): void;
|
|
84
|
+
/**
|
|
85
|
+
* Main hook logic. Reads stdin, sends to WheelHub, outputs decision.
|
|
86
|
+
* MSSCI-11947: Handles data field passthrough for interactive tools.
|
|
87
|
+
*/
|
|
88
|
+
export declare function main(): Promise<void>;
|
|
89
|
+
//# sourceMappingURL=pretooluse-hook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pretooluse-hook.d.ts","sourceRoot":"","sources":["../../src/hooks/pretooluse-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAUH,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,IAAI,cAAc,CAAC;AAChC,eAAO,MAAM,UAAU,SAAU,CAAC;AAClC,eAAO,MAAM,SAAS,kBAAkB,CAAC;AACzC,eAAO,MAAM,gBAAgB,2BAA2B,CAAC;AACzD,eAAO,MAAM,QAAQ,sBAAsB,CAAC;AAM5C,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB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|
+
/**
|
|
2
|
+
* Cyclist PreToolUse Hook - Core Logic
|
|
3
|
+
*
|
|
4
|
+
* Testable module containing all hook logic. The companion runner script
|
|
5
|
+
* (cyclist-pretooluse-hook.js) imports from the compiled output and invokes main().
|
|
6
|
+
*
|
|
7
|
+
* Flow:
|
|
8
|
+
* 1. Claude Code calls the runner script with tool info via stdin (JSON)
|
|
9
|
+
* 2. Script reads port from .cyclist-port in project directory
|
|
10
|
+
* 3. Script sends request to WheelHub's /api/hook-request endpoint
|
|
11
|
+
* 4. WheelHub checks grants / shows approval modal, user decides
|
|
12
|
+
* 5. Script receives response, outputs JSON decision to stdout
|
|
13
|
+
* 6. Claude Code proceeds or blocks based on decision
|
|
14
|
+
*
|
|
15
|
+
* Per ADR-0004: All communication converges through WheelHub.
|
|
16
|
+
*
|
|
17
|
+
* Story: MSSCI-14320 - Update and register PreToolUse hook
|
|
18
|
+
*/
|
|
19
|
+
import http from 'node:http';
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// Constants
|
|
24
|
+
// =============================================================================
|
|
25
|
+
export const DEFAULT_PORT = 7432;
|
|
26
|
+
export const HOST = '127.0.0.1';
|
|
27
|
+
export const TIMEOUT_MS = 120_000; // 2 minutes for user to decide
|
|
28
|
+
export const PORT_FILE = '.cyclist-port';
|
|
29
|
+
export const LEGACY_PORT_FILE = '.cyclist-approval-port';
|
|
30
|
+
export const ENDPOINT = '/api/hook-request';
|
|
31
|
+
// =============================================================================
|
|
32
|
+
// Project Root Detection
|
|
33
|
+
// =============================================================================
|
|
34
|
+
/**
|
|
35
|
+
* Find the project root by looking for port files or .claude directory.
|
|
36
|
+
* Walks up from startDir (defaults to cwd) until found or reaches filesystem root.
|
|
37
|
+
*/
|
|
38
|
+
export function findProjectRoot(startDir) {
|
|
39
|
+
let dir = startDir ?? process.cwd();
|
|
40
|
+
const root = path.parse(dir).root;
|
|
41
|
+
while (dir !== root) {
|
|
42
|
+
if (fs.existsSync(path.join(dir, PORT_FILE))) {
|
|
43
|
+
return dir;
|
|
44
|
+
}
|
|
45
|
+
if (fs.existsSync(path.join(dir, LEGACY_PORT_FILE))) {
|
|
46
|
+
return dir;
|
|
47
|
+
}
|
|
48
|
+
if (fs.existsSync(path.join(dir, '.claude'))) {
|
|
49
|
+
return dir;
|
|
50
|
+
}
|
|
51
|
+
dir = path.dirname(dir);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
// =============================================================================
|
|
56
|
+
// Port Discovery
|
|
57
|
+
// =============================================================================
|
|
58
|
+
/**
|
|
59
|
+
* Read the WheelHub server port. Prefers .cyclist-port, falls back to
|
|
60
|
+
* .cyclist-approval-port for migration compatibility, then default port.
|
|
61
|
+
*
|
|
62
|
+
* Mirrors hooks.py:get_cyclist_port() behavior.
|
|
63
|
+
*/
|
|
64
|
+
export function getPort(projectRoot) {
|
|
65
|
+
const root = projectRoot ?? findProjectRoot();
|
|
66
|
+
if (!root) {
|
|
67
|
+
return DEFAULT_PORT;
|
|
68
|
+
}
|
|
69
|
+
// Try canonical port file first
|
|
70
|
+
const port = readPortFile(path.join(root, PORT_FILE));
|
|
71
|
+
if (port !== null) {
|
|
72
|
+
return port;
|
|
73
|
+
}
|
|
74
|
+
// Fall back to legacy port file
|
|
75
|
+
const legacyPort = readPortFile(path.join(root, LEGACY_PORT_FILE));
|
|
76
|
+
if (legacyPort !== null) {
|
|
77
|
+
return legacyPort;
|
|
78
|
+
}
|
|
79
|
+
return DEFAULT_PORT;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Read a port number from a file. Returns null if file doesn't exist or is invalid.
|
|
83
|
+
*/
|
|
84
|
+
export function readPortFile(filePath) {
|
|
85
|
+
if (!fs.existsSync(filePath)) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const content = fs.readFileSync(filePath, 'utf-8').trim();
|
|
90
|
+
const port = parseInt(content, 10);
|
|
91
|
+
if (!isNaN(port) && port > 0 && port < 65536) {
|
|
92
|
+
return port;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Fall through
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
// =============================================================================
|
|
101
|
+
// Stdin Reading
|
|
102
|
+
// =============================================================================
|
|
103
|
+
/**
|
|
104
|
+
* Read all stdin as JSON.
|
|
105
|
+
*/
|
|
106
|
+
export async function readStdin() {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
let data = '';
|
|
109
|
+
process.stdin.setEncoding('utf8');
|
|
110
|
+
process.stdin.on('data', (chunk) => { data += chunk; });
|
|
111
|
+
process.stdin.on('end', () => {
|
|
112
|
+
try {
|
|
113
|
+
resolve(JSON.parse(data));
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
reject(new Error(`Invalid JSON input: ${e.message}`));
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
process.stdin.on('error', reject);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// =============================================================================
|
|
123
|
+
// HTTP Request
|
|
124
|
+
// =============================================================================
|
|
125
|
+
/**
|
|
126
|
+
* Send approval request to WheelHub and wait for response.
|
|
127
|
+
* Returns { decision: "ask" } when WheelHub is unreachable (ECONNREFUSED).
|
|
128
|
+
*/
|
|
129
|
+
export async function requestApproval(toolData, port) {
|
|
130
|
+
const resolvedPort = port ?? getPort();
|
|
131
|
+
const postData = JSON.stringify(toolData);
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const options = {
|
|
134
|
+
hostname: HOST,
|
|
135
|
+
port: resolvedPort,
|
|
136
|
+
path: ENDPOINT,
|
|
137
|
+
method: 'POST',
|
|
138
|
+
headers: {
|
|
139
|
+
'Content-Type': 'application/json',
|
|
140
|
+
'Content-Length': Buffer.byteLength(postData),
|
|
141
|
+
},
|
|
142
|
+
timeout: TIMEOUT_MS,
|
|
143
|
+
};
|
|
144
|
+
const req = http.request(options, (res) => {
|
|
145
|
+
let data = '';
|
|
146
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
147
|
+
res.on('end', () => {
|
|
148
|
+
try {
|
|
149
|
+
resolve(JSON.parse(data));
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
reject(new Error(`Invalid response from WheelHub: ${e.message}`));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
req.on('error', (e) => {
|
|
157
|
+
if (e.code === 'ECONNREFUSED') {
|
|
158
|
+
resolve({ decision: 'ask', reason: 'WheelHub not running, deferring to Claude Code' });
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
reject(e);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
req.on('timeout', () => {
|
|
165
|
+
req.destroy();
|
|
166
|
+
reject(new Error('Approval request timed out'));
|
|
167
|
+
});
|
|
168
|
+
req.write(postData);
|
|
169
|
+
req.end();
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
// =============================================================================
|
|
173
|
+
// Output Formatting
|
|
174
|
+
// =============================================================================
|
|
175
|
+
/**
|
|
176
|
+
* Build the Claude Code hook output object.
|
|
177
|
+
* MSSCI-11947: Supports updatedInput passthrough for interactive tools.
|
|
178
|
+
*/
|
|
179
|
+
export function buildOutput(decision, reason, updatedInput) {
|
|
180
|
+
const output = {
|
|
181
|
+
hookSpecificOutput: {
|
|
182
|
+
hookEventName: 'PreToolUse',
|
|
183
|
+
permissionDecision: decision,
|
|
184
|
+
permissionDecisionReason: reason,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
if (updatedInput) {
|
|
188
|
+
output.hookSpecificOutput.updatedInput = updatedInput;
|
|
189
|
+
}
|
|
190
|
+
return output;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Output decision to stdout in Claude Code hook format.
|
|
194
|
+
*/
|
|
195
|
+
export function outputDecision(decision, reason, updatedInput) {
|
|
196
|
+
console.log(JSON.stringify(buildOutput(decision, reason, updatedInput)));
|
|
197
|
+
}
|
|
198
|
+
// =============================================================================
|
|
199
|
+
// Main Entry Point
|
|
200
|
+
// =============================================================================
|
|
201
|
+
/**
|
|
202
|
+
* Main hook logic. Reads stdin, sends to WheelHub, outputs decision.
|
|
203
|
+
* MSSCI-11947: Handles data field passthrough for interactive tools.
|
|
204
|
+
*/
|
|
205
|
+
export async function main() {
|
|
206
|
+
try {
|
|
207
|
+
const toolData = await readStdin();
|
|
208
|
+
const { tool_name, tool_input, tool_use_id, session_id } = toolData;
|
|
209
|
+
const response = await requestApproval({
|
|
210
|
+
toolName: tool_name,
|
|
211
|
+
toolId: tool_use_id,
|
|
212
|
+
input: tool_input,
|
|
213
|
+
sessionId: session_id,
|
|
214
|
+
});
|
|
215
|
+
if (response.decision === 'allow') {
|
|
216
|
+
outputDecision('allow', response.reason || 'Approved by user', response.data || null);
|
|
217
|
+
}
|
|
218
|
+
else if (response.decision === 'deny') {
|
|
219
|
+
outputDecision('deny', response.reason || 'Rejected by user', response.data || null);
|
|
220
|
+
}
|
|
221
|
+
else if (response.decision === 'ask') {
|
|
222
|
+
outputDecision('ask', response.reason || 'Deferred to Claude Code');
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
// Unknown decision - defer to Claude Code rather than silently allowing
|
|
226
|
+
outputDecision('ask', 'Unknown response from WheelHub');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
console.error(`[cyclist-hook] Error: ${error.message}`);
|
|
231
|
+
// Output ask so Claude Code shows its built-in dialog, don't silently allow
|
|
232
|
+
outputDecision('ask', 'Hook error, deferring to Claude Code');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=pretooluse-hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pretooluse-hook.js","sourceRoot":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