@volcengine/tls-observer-cursor 0.0.4

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.
@@ -0,0 +1,6 @@
1
+ import type { SessionState, ToolObservation, TracingState } from './types';
2
+ export declare function loadState(stateFilePath: string): TracingState;
3
+ export declare function getSessionState(state: TracingState, sessionId: string): SessionState;
4
+ export declare function atomicUpdateState(stateFilePath: string, fn: (state: TracingState) => TracingState): Promise<void>;
5
+ export declare function pruneOldSessions(state: TracingState, now?: number): TracingState;
6
+ export declare function putToolObservation(session: SessionState, observation: ToolObservation): SessionState;
@@ -0,0 +1 @@
1
+ export declare function readStdinJson<T>(): Promise<T>;
@@ -0,0 +1,12 @@
1
+ export interface TlsProducerConfig {
2
+ endpoint: string;
3
+ region: string;
4
+ traceTopicId: string;
5
+ apiKey?: string;
6
+ ak?: string;
7
+ sk?: string;
8
+ timeoutMs?: number;
9
+ }
10
+ export declare function normalizeProducerEndpoint(endpoint: string): string;
11
+ export declare function sendTlsLogRecords(config: TlsProducerConfig, records: Array<Record<string, string>>, fileName: string): Promise<void>;
12
+ export declare function closeTraceLogProducers(): Promise<void>;
@@ -0,0 +1,42 @@
1
+ import type { Config } from './config';
2
+ import type { CompactHookInput, HookInput, SessionState, StopHookInput, TraceModel, TraceSpan, Turn } from './types';
3
+ export declare function toTraceId(value: string): string;
4
+ export declare function toSpanId(...parts: unknown[]): string;
5
+ export declare function buildTraceFromTurn(options: {
6
+ input: StopHookInput;
7
+ turn: Turn;
8
+ turnIndex: number;
9
+ sessionState: SessionState;
10
+ config: Config;
11
+ turnEndTimeMs?: number;
12
+ source?: string;
13
+ traceSeedSuffix?: string;
14
+ extraAttributes?: Record<string, unknown>;
15
+ }): TraceModel;
16
+ export declare function buildTraceFromHookState(options: {
17
+ input: StopHookInput;
18
+ sessionState: SessionState;
19
+ config: Config;
20
+ turnIndex: number;
21
+ stopTimeMs?: number;
22
+ source?: string;
23
+ traceSeedSuffix?: string;
24
+ extraAttributes?: Record<string, unknown>;
25
+ }): TraceModel | undefined;
26
+ export declare function buildEventTrace(options: {
27
+ input: HookInput;
28
+ config: Config;
29
+ eventName: string;
30
+ spanName?: string;
31
+ startMs?: number;
32
+ endMs?: number;
33
+ attributes?: Record<string, unknown>;
34
+ inputPayload?: unknown;
35
+ outputPayload?: unknown;
36
+ status?: TraceSpan['status'];
37
+ }): TraceModel;
38
+ export declare function buildCompactTrace(options: {
39
+ input: CompactHookInput;
40
+ sessionState: SessionState;
41
+ config: Config;
42
+ }): TraceModel;
@@ -0,0 +1,17 @@
1
+ import type { CursorTranscriptEntry, Turn } from './types';
2
+ export declare function readTranscript(filePath: string, afterLine?: number, afterOffset?: number, options?: {
3
+ lookBehindBytes?: number;
4
+ }): {
5
+ messages: CursorTranscriptEntry[];
6
+ lastLine: number;
7
+ lastOffset: number;
8
+ };
9
+ export declare function getTranscriptEndPosition(filePath: string): {
10
+ lastLine: number;
11
+ lastOffset: number;
12
+ };
13
+ export declare function groupIntoTurns(messages: CursorTranscriptEntry[], options?: {
14
+ fallbackStartMs?: number;
15
+ fallbackModel?: string;
16
+ }): Turn[];
17
+ export declare function toolObservationMatchKey(toolName?: string, toolInput?: unknown): string | undefined;
@@ -0,0 +1,228 @@
1
+ export interface HookInputBase {
2
+ hook_event_name?: string;
3
+ event_name?: string;
4
+ session_id?: string;
5
+ conversation_id?: string;
6
+ generation_id?: string;
7
+ session_name?: string;
8
+ transcript_path?: string | null;
9
+ cwd?: string;
10
+ cursor_version?: string;
11
+ version?: string;
12
+ user_email?: string;
13
+ workspace_roots?: string[];
14
+ workspace?: {
15
+ current_dir?: string;
16
+ project_dir?: string;
17
+ added_dirs?: string[];
18
+ };
19
+ model?: string | {
20
+ id?: string;
21
+ display_name?: string;
22
+ [key: string]: unknown;
23
+ };
24
+ model_id?: string;
25
+ model_params?: Array<{
26
+ id?: string;
27
+ value?: string;
28
+ }>;
29
+ [key: string]: unknown;
30
+ }
31
+ export interface UserPromptSubmitHookInput extends HookInputBase {
32
+ hook_event_name: 'beforeSubmitPrompt' | 'UserPromptSubmit';
33
+ prompt?: string;
34
+ user_prompt?: string;
35
+ query?: string;
36
+ }
37
+ export interface ToolHookInput extends HookInputBase {
38
+ hook_event_name: 'preToolUse' | 'postToolUse' | 'postToolUseFailure' | 'PreToolUse' | 'PostToolUse' | 'PostToolUseFailure';
39
+ tool_use_id?: string;
40
+ tool_call_id?: string;
41
+ tool_name?: string;
42
+ tool_input?: unknown;
43
+ tool_output?: unknown;
44
+ error_message?: string;
45
+ failure_type?: string;
46
+ duration?: number | string;
47
+ is_interrupt?: boolean;
48
+ agent_message?: string;
49
+ tool_response?: unknown;
50
+ output?: unknown;
51
+ result?: unknown;
52
+ error?: unknown;
53
+ }
54
+ export interface StopHookInput extends HookInputBase {
55
+ hook_event_name: 'stop' | 'Stop' | 'sessionEnd' | 'SessionEnd';
56
+ stop_hook_active?: boolean;
57
+ last_assistant_message?: string;
58
+ reason?: string;
59
+ }
60
+ export interface SubagentHookInput extends HookInputBase {
61
+ hook_event_name: 'subagentStart' | 'subagentStop' | 'SubagentStart' | 'SubagentStop';
62
+ agent_id?: string;
63
+ agent_type?: string;
64
+ subagent_id?: string;
65
+ subagent_type?: string;
66
+ agent_transcript_path?: string;
67
+ transcript_path?: string | null;
68
+ }
69
+ export interface CompactHookInput extends HookInputBase {
70
+ hook_event_name: 'preCompact' | 'PreCompact';
71
+ trigger?: 'manual' | 'auto' | string;
72
+ custom_instructions?: string;
73
+ }
74
+ export type HookInput = UserPromptSubmitHookInput | ToolHookInput | StopHookInput | SubagentHookInput | CompactHookInput | HookInputBase;
75
+ export interface TextBlock {
76
+ type: 'text';
77
+ text: string;
78
+ }
79
+ export interface ThinkingBlock {
80
+ type: 'thinking' | 'reasoning';
81
+ thinking?: string;
82
+ text?: string;
83
+ }
84
+ export interface ToolUseBlock {
85
+ type: 'tool_use';
86
+ id: string;
87
+ name: string;
88
+ input: Record<string, unknown>;
89
+ }
90
+ export interface ToolResultBlock {
91
+ type: 'tool_result';
92
+ tool_use_id?: string;
93
+ content?: unknown;
94
+ is_error?: boolean;
95
+ }
96
+ export type ContentBlock = TextBlock | ThinkingBlock | ToolUseBlock;
97
+ export interface Usage {
98
+ input_tokens?: number;
99
+ output_tokens?: number;
100
+ reasoning_output_tokens?: number;
101
+ cache_read_input_tokens?: number;
102
+ cache_creation_input_tokens?: number;
103
+ }
104
+ export interface CursorTranscriptEntry {
105
+ role?: 'user' | 'assistant' | string;
106
+ type?: string;
107
+ status?: string;
108
+ timestamp?: string;
109
+ message?: {
110
+ id?: string;
111
+ role?: string;
112
+ model?: string;
113
+ content?: unknown;
114
+ usage?: Usage;
115
+ stop_reason?: string | null;
116
+ };
117
+ promptId?: string;
118
+ __line?: number;
119
+ __startOffset?: number;
120
+ __endOffset?: number;
121
+ }
122
+ export interface ToolCall {
123
+ tool_use: ToolUseBlock;
124
+ result?: {
125
+ content: string;
126
+ timestamp: string;
127
+ is_error?: boolean;
128
+ };
129
+ }
130
+ export interface LlmCall {
131
+ content: ContentBlock[];
132
+ model: string;
133
+ usage: Usage;
134
+ startTime: string;
135
+ endTime: string;
136
+ toolCalls: ToolCall[];
137
+ stopReason?: string | null;
138
+ synthetic?: boolean;
139
+ }
140
+ export interface Turn {
141
+ userContent: string | Array<Record<string, unknown>>;
142
+ userTimestamp: string;
143
+ promptId?: string;
144
+ llmCalls: LlmCall[];
145
+ isComplete: boolean;
146
+ startOffset?: number;
147
+ endOffset?: number;
148
+ }
149
+ export interface ToolObservation {
150
+ tool_use_id: string;
151
+ tool_call_id?: string;
152
+ tool_name?: string;
153
+ tool_input?: unknown;
154
+ tool_response?: unknown;
155
+ error_type?: string;
156
+ is_interrupt?: boolean;
157
+ start_time_ms?: number;
158
+ end_time_ms?: number;
159
+ status?: 'ok' | 'error';
160
+ match_key?: string;
161
+ event_name?: string;
162
+ sequence?: number;
163
+ }
164
+ export interface PendingSubagentTrace {
165
+ agent_id?: string;
166
+ agent_type?: string;
167
+ agent_transcript_path: string;
168
+ session_id?: string;
169
+ }
170
+ export interface SessionState {
171
+ last_line: number;
172
+ last_offset?: number;
173
+ turn_count: number;
174
+ updated: string;
175
+ current_turn_id?: string;
176
+ current_turn_start_ms?: number;
177
+ current_prompt?: string;
178
+ tool_start_times?: Record<string, number>;
179
+ tool_observations?: Record<string, ToolObservation>;
180
+ tool_observation_order?: string[];
181
+ pending_subagent_traces?: PendingSubagentTrace[];
182
+ subagent_turn_count?: number;
183
+ compaction_start_time_ms?: number;
184
+ compaction_trigger?: string;
185
+ compaction_custom_instructions?: string;
186
+ }
187
+ export interface TracingState {
188
+ [sessionId: string]: SessionState;
189
+ }
190
+ export interface TraceSpan {
191
+ trace_id: string;
192
+ span_id: string;
193
+ parent_span_id?: string | null;
194
+ name: string;
195
+ type: 'entry' | 'model' | 'tool' | 'event';
196
+ span_kind: 'SERVER' | 'CLIENT' | 'INTERNAL';
197
+ start_time: string;
198
+ end_time: string;
199
+ start_time_unix_ms: number;
200
+ end_time_unix_ms: number;
201
+ duration_ms: number;
202
+ attributes: Record<string, unknown>;
203
+ input?: unknown;
204
+ output?: unknown;
205
+ status?: {
206
+ code?: 'UNSET' | 'OK' | 'ERROR';
207
+ message?: string;
208
+ };
209
+ }
210
+ export interface TraceModel {
211
+ schema_url: string;
212
+ source: string;
213
+ trace_id: string;
214
+ resource: Record<string, unknown>;
215
+ spans: TraceSpan[];
216
+ }
217
+ export interface ExportResult {
218
+ status: 'success' | 'failed' | 'skipped';
219
+ reason?: string;
220
+ message?: string;
221
+ trace_id?: string;
222
+ span_count?: number;
223
+ payload_bytes?: number;
224
+ attempts?: number;
225
+ duration_ms?: number;
226
+ endpoint_host?: string;
227
+ endpoint_path?: string;
228
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "version": 1,
3
+ "description": "TLS Observer hooks for Cursor agent traces.",
4
+ "hooks": {
5
+ "beforeSubmitPrompt": [
6
+ {
7
+ "command": "node \"${CURSOR_TLS_OBSERVER_ROOT}/dist/index.js\"",
8
+ "timeout": 30
9
+ }
10
+ ],
11
+ "stop": [
12
+ {
13
+ "command": "node \"${CURSOR_TLS_OBSERVER_ROOT}/dist/index.js\"",
14
+ "timeout": 120
15
+ }
16
+ ],
17
+ "sessionEnd": [
18
+ {
19
+ "command": "node \"${CURSOR_TLS_OBSERVER_ROOT}/dist/index.js\"",
20
+ "timeout": 30
21
+ }
22
+ ]
23
+ }
24
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@volcengine/tls-observer-cursor",
3
+ "version": "0.0.4",
4
+ "description": "Export Cursor hook telemetry and agent transcripts to Volcengine TLS with OTLP traces.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "types": "./dist/index.d.ts",
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
17
+ "keywords": [
18
+ "cursor",
19
+ "hooks",
20
+ "observability",
21
+ "opentelemetry",
22
+ "tls"
23
+ ],
24
+ "dependencies": {
25
+ "@volcengine/openapi": "^1.36.1"
26
+ }
27
+ }