@clinebot/core 0.0.21 → 0.0.23
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/ClineCore.d.ts +110 -0
- package/dist/ClineCore.d.ts.map +1 -0
- package/dist/account/cline-account-service.d.ts +2 -1
- package/dist/account/cline-account-service.d.ts.map +1 -1
- package/dist/account/index.d.ts +1 -1
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/rpc.d.ts +3 -1
- package/dist/account/rpc.d.ts.map +1 -1
- package/dist/account/types.d.ts +3 -0
- package/dist/account/types.d.ts.map +1 -1
- package/dist/agents/plugin-loader.d.ts.map +1 -1
- package/dist/agents/plugin-sandbox-bootstrap.js +17 -17
- package/dist/auth/client.d.ts +1 -1
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/cline.d.ts +1 -1
- package/dist/auth/cline.d.ts.map +1 -1
- package/dist/auth/codex.d.ts +1 -1
- package/dist/auth/codex.d.ts.map +1 -1
- package/dist/auth/oca.d.ts +1 -1
- package/dist/auth/oca.d.ts.map +1 -1
- package/dist/auth/utils.d.ts +2 -2
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/index.d.ts +50 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +949 -0
- package/dist/providers/local-provider-service.d.ts +4 -4
- package/dist/providers/local-provider-service.d.ts.map +1 -1
- package/dist/runtime/runtime-builder.d.ts +1 -0
- package/dist/runtime/runtime-builder.d.ts.map +1 -1
- package/dist/runtime/session-runtime.d.ts +2 -1
- package/dist/runtime/session-runtime.d.ts.map +1 -1
- package/dist/runtime/team-runtime-registry.d.ts +13 -0
- package/dist/runtime/team-runtime-registry.d.ts.map +1 -0
- package/dist/session/default-session-manager.d.ts +2 -2
- package/dist/session/default-session-manager.d.ts.map +1 -1
- package/dist/session/rpc-runtime-ensure.d.ts +53 -0
- package/dist/session/rpc-runtime-ensure.d.ts.map +1 -0
- package/dist/session/session-config-builder.d.ts +2 -3
- package/dist/session/session-config-builder.d.ts.map +1 -1
- package/dist/session/session-host.d.ts +8 -18
- package/dist/session/session-host.d.ts.map +1 -1
- package/dist/session/session-manager.d.ts +1 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manifest.d.ts +1 -2
- package/dist/session/session-manifest.d.ts.map +1 -1
- package/dist/session/unified-session-persistence-service.d.ts +2 -2
- package/dist/session/unified-session-persistence-service.d.ts.map +1 -1
- package/dist/session/utils/helpers.d.ts +1 -1
- package/dist/session/utils/helpers.d.ts.map +1 -1
- package/dist/session/utils/types.d.ts +1 -1
- package/dist/session/utils/types.d.ts.map +1 -1
- package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -1
- package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -1
- package/dist/telemetry/distinct-id.d.ts +2 -0
- package/dist/telemetry/distinct-id.d.ts.map +1 -0
- package/dist/telemetry/{opentelemetry.d.ts → index.d.ts} +1 -1
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +28 -0
- package/dist/tools/constants.d.ts +1 -1
- package/dist/tools/constants.d.ts.map +1 -1
- package/dist/tools/definitions.d.ts +3 -3
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/executors/apply-patch.d.ts +1 -1
- package/dist/tools/executors/apply-patch.d.ts.map +1 -1
- package/dist/tools/executors/bash.d.ts +1 -1
- package/dist/tools/executors/bash.d.ts.map +1 -1
- package/dist/tools/executors/editor.d.ts +1 -1
- package/dist/tools/executors/editor.d.ts.map +1 -1
- package/dist/tools/executors/file-read.d.ts +1 -1
- package/dist/tools/executors/file-read.d.ts.map +1 -1
- package/dist/tools/executors/index.d.ts +14 -14
- package/dist/tools/executors/index.d.ts.map +1 -1
- package/dist/tools/executors/search.d.ts +1 -1
- package/dist/tools/executors/search.d.ts.map +1 -1
- package/dist/tools/executors/web-fetch.d.ts +1 -1
- package/dist/tools/executors/web-fetch.d.ts.map +1 -1
- package/dist/tools/helpers.d.ts +1 -1
- package/dist/tools/helpers.d.ts.map +1 -1
- package/dist/tools/index.d.ts +10 -10
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/model-tool-routing.d.ts +1 -1
- package/dist/tools/model-tool-routing.d.ts.map +1 -1
- package/dist/tools/presets.d.ts +1 -1
- package/dist/tools/presets.d.ts.map +1 -1
- package/dist/types/common.d.ts +17 -8
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/config.d.ts +4 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/provider-settings.d.ts +1 -1
- package/dist/types/provider-settings.d.ts.map +1 -1
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +44 -38
- package/src/ClineCore.ts +137 -0
- package/src/account/cline-account-service.test.ts +101 -0
- package/src/account/cline-account-service.ts +300 -0
- package/src/account/featurebase-token.test.ts +175 -0
- package/src/account/index.ts +23 -0
- package/src/account/rpc.test.ts +63 -0
- package/src/account/rpc.ts +185 -0
- package/src/account/types.ts +102 -0
- package/src/agents/agent-config-loader.test.ts +236 -0
- package/src/agents/agent-config-loader.ts +108 -0
- package/src/agents/agent-config-parser.ts +198 -0
- package/src/agents/hooks-config-loader.test.ts +20 -0
- package/src/agents/hooks-config-loader.ts +118 -0
- package/src/agents/index.ts +85 -0
- package/src/agents/plugin-config-loader.test.ts +140 -0
- package/src/agents/plugin-config-loader.ts +97 -0
- package/src/agents/plugin-loader.test.ts +210 -0
- package/src/agents/plugin-loader.ts +175 -0
- package/src/agents/plugin-sandbox-bootstrap.ts +448 -0
- package/src/agents/plugin-sandbox.test.ts +296 -0
- package/src/agents/plugin-sandbox.ts +341 -0
- package/src/agents/unified-config-file-watcher.test.ts +196 -0
- package/src/agents/unified-config-file-watcher.ts +483 -0
- package/src/agents/user-instruction-config-loader.test.ts +158 -0
- package/src/agents/user-instruction-config-loader.ts +438 -0
- package/src/auth/client.test.ts +40 -0
- package/src/auth/client.ts +25 -0
- package/src/auth/cline.test.ts +130 -0
- package/src/auth/cline.ts +420 -0
- package/src/auth/codex.test.ts +170 -0
- package/src/auth/codex.ts +491 -0
- package/src/auth/oca.test.ts +215 -0
- package/src/auth/oca.ts +573 -0
- package/src/auth/server.ts +216 -0
- package/src/auth/types.ts +81 -0
- package/src/auth/utils.test.ts +128 -0
- package/src/auth/utils.ts +247 -0
- package/src/chat/chat-schema.ts +82 -0
- package/src/index.ts +479 -0
- package/src/input/file-indexer.d.ts +11 -0
- package/src/input/file-indexer.test.ts +127 -0
- package/src/input/file-indexer.ts +327 -0
- package/src/input/index.ts +7 -0
- package/src/input/mention-enricher.test.ts +85 -0
- package/src/input/mention-enricher.ts +122 -0
- package/src/mcp/config-loader.test.ts +238 -0
- package/src/mcp/config-loader.ts +219 -0
- package/src/mcp/index.ts +26 -0
- package/src/mcp/manager.test.ts +106 -0
- package/src/mcp/manager.ts +262 -0
- package/src/mcp/types.ts +88 -0
- package/src/providers/local-provider-registry.ts +232 -0
- package/src/providers/local-provider-service.test.ts +783 -0
- package/src/providers/local-provider-service.ts +471 -0
- package/src/runtime/commands.test.ts +98 -0
- package/src/runtime/commands.ts +83 -0
- package/src/runtime/hook-file-hooks.test.ts +237 -0
- package/src/runtime/hook-file-hooks.ts +859 -0
- package/src/runtime/index.ts +37 -0
- package/src/runtime/rules.ts +34 -0
- package/src/runtime/runtime-builder.team-persistence.test.ts +245 -0
- package/src/runtime/runtime-builder.test.ts +371 -0
- package/src/runtime/runtime-builder.ts +631 -0
- package/src/runtime/runtime-parity.test.ts +143 -0
- package/src/runtime/sandbox/subprocess-sandbox.ts +231 -0
- package/src/runtime/session-runtime.ts +49 -0
- package/src/runtime/skills.ts +44 -0
- package/src/runtime/team-runtime-registry.ts +46 -0
- package/src/runtime/tool-approval.ts +104 -0
- package/src/runtime/workflows.test.ts +119 -0
- package/src/runtime/workflows.ts +45 -0
- package/src/session/default-session-manager.e2e.test.ts +384 -0
- package/src/session/default-session-manager.test.ts +1931 -0
- package/src/session/default-session-manager.ts +1422 -0
- package/src/session/file-session-service.ts +280 -0
- package/src/session/index.ts +45 -0
- package/src/session/rpc-runtime-ensure.ts +521 -0
- package/src/session/rpc-session-service.ts +107 -0
- package/src/session/rpc-spawn-lease.test.ts +49 -0
- package/src/session/rpc-spawn-lease.ts +122 -0
- package/src/session/runtime-oauth-token-manager.test.ts +137 -0
- package/src/session/runtime-oauth-token-manager.ts +272 -0
- package/src/session/session-agent-events.ts +248 -0
- package/src/session/session-artifacts.ts +106 -0
- package/src/session/session-config-builder.ts +113 -0
- package/src/session/session-graph.ts +92 -0
- package/src/session/session-host.test.ts +89 -0
- package/src/session/session-host.ts +205 -0
- package/src/session/session-manager.ts +69 -0
- package/src/session/session-manifest.ts +29 -0
- package/src/session/session-service.team-persistence.test.ts +48 -0
- package/src/session/session-service.ts +673 -0
- package/src/session/session-team-coordination.ts +229 -0
- package/src/session/session-telemetry.ts +100 -0
- package/src/session/sqlite-rpc-session-backend.ts +303 -0
- package/src/session/unified-session-persistence-service.test.ts +85 -0
- package/src/session/unified-session-persistence-service.ts +994 -0
- package/src/session/utils/helpers.ts +139 -0
- package/src/session/utils/types.ts +57 -0
- package/src/session/utils/usage.ts +32 -0
- package/src/session/workspace-manager.ts +98 -0
- package/src/session/workspace-manifest.ts +100 -0
- package/src/storage/artifact-store.ts +1 -0
- package/src/storage/file-team-store.ts +257 -0
- package/src/storage/index.ts +11 -0
- package/src/storage/provider-settings-legacy-migration.test.ts +424 -0
- package/src/storage/provider-settings-legacy-migration.ts +826 -0
- package/src/storage/provider-settings-manager.test.ts +191 -0
- package/src/storage/provider-settings-manager.ts +152 -0
- package/src/storage/session-store.ts +1 -0
- package/src/storage/sqlite-session-store.ts +275 -0
- package/src/storage/sqlite-team-store.ts +454 -0
- package/src/storage/team-store.ts +40 -0
- package/src/team/index.ts +4 -0
- package/src/team/projections.ts +285 -0
- package/src/telemetry/ITelemetryAdapter.ts +94 -0
- package/src/telemetry/LoggerTelemetryAdapter.test.ts +42 -0
- package/src/telemetry/LoggerTelemetryAdapter.ts +114 -0
- package/src/telemetry/OpenTelemetryAdapter.test.ts +157 -0
- package/src/telemetry/OpenTelemetryAdapter.ts +348 -0
- package/src/telemetry/OpenTelemetryProvider.test.ts +113 -0
- package/src/telemetry/OpenTelemetryProvider.ts +325 -0
- package/src/telemetry/TelemetryService.test.ts +134 -0
- package/src/telemetry/TelemetryService.ts +141 -0
- package/src/telemetry/core-events.ts +400 -0
- package/src/telemetry/distinct-id.test.ts +57 -0
- package/src/telemetry/distinct-id.ts +58 -0
- package/src/telemetry/index.ts +20 -0
- package/src/tools/constants.ts +35 -0
- package/src/tools/definitions.test.ts +704 -0
- package/src/tools/definitions.ts +709 -0
- package/src/tools/executors/apply-patch-parser.ts +520 -0
- package/src/tools/executors/apply-patch.ts +359 -0
- package/src/tools/executors/bash.test.ts +87 -0
- package/src/tools/executors/bash.ts +207 -0
- package/src/tools/executors/editor.test.ts +35 -0
- package/src/tools/executors/editor.ts +219 -0
- package/src/tools/executors/file-read.test.ts +49 -0
- package/src/tools/executors/file-read.ts +110 -0
- package/src/tools/executors/index.ts +87 -0
- package/src/tools/executors/search.ts +278 -0
- package/src/tools/executors/web-fetch.ts +259 -0
- package/src/tools/helpers.ts +130 -0
- package/src/tools/index.ts +169 -0
- package/src/tools/model-tool-routing.test.ts +86 -0
- package/src/tools/model-tool-routing.ts +132 -0
- package/src/tools/presets.test.ts +62 -0
- package/src/tools/presets.ts +168 -0
- package/src/tools/schemas.ts +327 -0
- package/src/tools/types.ts +329 -0
- package/src/types/common.ts +26 -0
- package/src/types/config.ts +86 -0
- package/src/types/events.ts +74 -0
- package/src/types/index.ts +24 -0
- package/src/types/provider-settings.ts +43 -0
- package/src/types/sessions.ts +16 -0
- package/src/types/storage.ts +64 -0
- package/src/types/workspace.ts +7 -0
- package/src/types.ts +132 -0
- package/src/version.ts +3 -0
- package/dist/index.node.d.ts +0 -47
- package/dist/index.node.d.ts.map +0 -1
- package/dist/index.node.js +0 -948
- package/dist/telemetry/opentelemetry.d.ts.map +0 -1
- package/dist/telemetry/opentelemetry.js +0 -27
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import type { ITelemetryService, TelemetryProperties } from "@clinebot/shared";
|
|
2
|
+
|
|
3
|
+
const MAX_ERROR_MESSAGE_LENGTH = 500;
|
|
4
|
+
|
|
5
|
+
export type TelemetryAgentKind =
|
|
6
|
+
| "root"
|
|
7
|
+
| "subagent"
|
|
8
|
+
| "team_lead"
|
|
9
|
+
| "team_teammate";
|
|
10
|
+
|
|
11
|
+
export interface TelemetryAgentIdentityProperties {
|
|
12
|
+
agentId: string;
|
|
13
|
+
agentKind: TelemetryAgentKind;
|
|
14
|
+
conversationId?: string;
|
|
15
|
+
parentAgentId?: string;
|
|
16
|
+
createdByAgentId?: string;
|
|
17
|
+
isSubagent: boolean;
|
|
18
|
+
teamId?: string;
|
|
19
|
+
teamName?: string;
|
|
20
|
+
teamRole?: "lead" | "teammate";
|
|
21
|
+
teamAgentId?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const CORE_TELEMETRY_EVENTS = {
|
|
25
|
+
CLIENT: {
|
|
26
|
+
STARTED: "extension.activated",
|
|
27
|
+
},
|
|
28
|
+
SESSION: {
|
|
29
|
+
STARTED: "session.started",
|
|
30
|
+
ENDED: "session.ended",
|
|
31
|
+
},
|
|
32
|
+
USER: {
|
|
33
|
+
AUTH_STARTED: "user.auth_started",
|
|
34
|
+
AUTH_SUCCEEDED: "user.auth_succeeded",
|
|
35
|
+
AUTH_FAILED: "user.auth_failed",
|
|
36
|
+
AUTH_LOGGED_OUT: "user.auth_logged_out",
|
|
37
|
+
},
|
|
38
|
+
TASK: {
|
|
39
|
+
CREATED: "task.created",
|
|
40
|
+
RESTARTED: "task.restarted",
|
|
41
|
+
COMPLETED: "task.completed",
|
|
42
|
+
CONVERSATION_TURN: "task.conversation_turn",
|
|
43
|
+
TOKEN_USAGE: "task.tokens",
|
|
44
|
+
MODE_SWITCH: "task.mode",
|
|
45
|
+
TOOL_USED: "task.tool_used",
|
|
46
|
+
SKILL_USED: "task.skill_used",
|
|
47
|
+
DIFF_EDIT_FAILED: "task.diff_edit_failed",
|
|
48
|
+
PROVIDER_API_ERROR: "task.provider_api_error",
|
|
49
|
+
MENTION_USED: "task.mention_used",
|
|
50
|
+
MENTION_FAILED: "task.mention_failed",
|
|
51
|
+
MENTION_SEARCH_RESULTS: "task.mention_search_results",
|
|
52
|
+
AGENT_CREATED: "task.agent_created",
|
|
53
|
+
AGENT_TEAM_CREATED: "task.agent_team_created",
|
|
54
|
+
SUBAGENT_STARTED: "task.subagent_started",
|
|
55
|
+
SUBAGENT_COMPLETED: "task.subagent_completed",
|
|
56
|
+
},
|
|
57
|
+
HOOKS: {
|
|
58
|
+
DISCOVERY_COMPLETED: "hooks.discovery_completed",
|
|
59
|
+
},
|
|
60
|
+
} as const;
|
|
61
|
+
|
|
62
|
+
function emit(
|
|
63
|
+
telemetry: ITelemetryService | undefined,
|
|
64
|
+
event: string,
|
|
65
|
+
properties?: TelemetryProperties,
|
|
66
|
+
): void {
|
|
67
|
+
telemetry?.capture({ event, properties });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function truncateErrorMessage(errorMessage?: string): string | undefined {
|
|
71
|
+
if (!errorMessage) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return errorMessage.substring(0, MAX_ERROR_MESSAGE_LENGTH);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function captureAuthStarted(
|
|
78
|
+
telemetry: ITelemetryService | undefined,
|
|
79
|
+
provider?: string,
|
|
80
|
+
): void {
|
|
81
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.USER.AUTH_STARTED, { provider });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function captureAuthSucceeded(
|
|
85
|
+
telemetry: ITelemetryService | undefined,
|
|
86
|
+
provider?: string,
|
|
87
|
+
): void {
|
|
88
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.USER.AUTH_SUCCEEDED, { provider });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function captureAuthFailed(
|
|
92
|
+
telemetry: ITelemetryService | undefined,
|
|
93
|
+
provider?: string,
|
|
94
|
+
errorMessage?: string,
|
|
95
|
+
): void {
|
|
96
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.USER.AUTH_FAILED, {
|
|
97
|
+
provider,
|
|
98
|
+
errorMessage: truncateErrorMessage(errorMessage),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function captureAuthLoggedOut(
|
|
103
|
+
telemetry: ITelemetryService | undefined,
|
|
104
|
+
provider?: string,
|
|
105
|
+
reason?: string,
|
|
106
|
+
): void {
|
|
107
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.USER.AUTH_LOGGED_OUT, {
|
|
108
|
+
provider,
|
|
109
|
+
reason,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function identifyAccount(
|
|
114
|
+
telemetry: ITelemetryService | undefined,
|
|
115
|
+
account: {
|
|
116
|
+
id?: string;
|
|
117
|
+
email?: string;
|
|
118
|
+
provider?: string;
|
|
119
|
+
organizationId?: string;
|
|
120
|
+
organizationName?: string;
|
|
121
|
+
memberId?: string;
|
|
122
|
+
},
|
|
123
|
+
): void {
|
|
124
|
+
const distinctId = account.id?.trim();
|
|
125
|
+
if (distinctId) {
|
|
126
|
+
telemetry?.setDistinctId(distinctId);
|
|
127
|
+
}
|
|
128
|
+
telemetry?.updateCommonProperties({
|
|
129
|
+
account_id: account.id,
|
|
130
|
+
account_email: account.email,
|
|
131
|
+
provider: account.provider,
|
|
132
|
+
organization_id: account.organizationId,
|
|
133
|
+
organization_name: account.organizationName,
|
|
134
|
+
member_id: account.memberId,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function captureTaskCreated(
|
|
139
|
+
telemetry: ITelemetryService | undefined,
|
|
140
|
+
properties: {
|
|
141
|
+
ulid: string;
|
|
142
|
+
apiProvider?: string;
|
|
143
|
+
openAiCompatibleDomain?: string;
|
|
144
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
145
|
+
): void {
|
|
146
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.CREATED, properties);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function captureTaskRestarted(
|
|
150
|
+
telemetry: ITelemetryService | undefined,
|
|
151
|
+
properties: {
|
|
152
|
+
ulid: string;
|
|
153
|
+
apiProvider?: string;
|
|
154
|
+
openAiCompatibleDomain?: string;
|
|
155
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
156
|
+
): void {
|
|
157
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.RESTARTED, properties);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function captureTaskCompleted(
|
|
161
|
+
telemetry: ITelemetryService | undefined,
|
|
162
|
+
properties: {
|
|
163
|
+
ulid: string;
|
|
164
|
+
provider?: string;
|
|
165
|
+
modelId?: string;
|
|
166
|
+
mode?: string;
|
|
167
|
+
durationMs?: number;
|
|
168
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
169
|
+
): void {
|
|
170
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.COMPLETED, properties);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function captureConversationTurnEvent(
|
|
174
|
+
telemetry: ITelemetryService | undefined,
|
|
175
|
+
properties: {
|
|
176
|
+
ulid: string;
|
|
177
|
+
provider?: string;
|
|
178
|
+
model?: string;
|
|
179
|
+
source: "user" | "assistant";
|
|
180
|
+
mode?: string;
|
|
181
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
182
|
+
): void {
|
|
183
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.CONVERSATION_TURN, {
|
|
184
|
+
...properties,
|
|
185
|
+
timestamp: new Date().toISOString(),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function captureTokenUsage(
|
|
190
|
+
telemetry: ITelemetryService | undefined,
|
|
191
|
+
properties: {
|
|
192
|
+
ulid: string;
|
|
193
|
+
tokensIn: number;
|
|
194
|
+
tokensOut: number;
|
|
195
|
+
cacheWriteTokens?: number;
|
|
196
|
+
cacheReadTokens?: number;
|
|
197
|
+
totalCost?: number;
|
|
198
|
+
model: string;
|
|
199
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
200
|
+
): void {
|
|
201
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.TOKEN_USAGE, properties);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function captureModeSwitch(
|
|
205
|
+
telemetry: ITelemetryService | undefined,
|
|
206
|
+
ulid: string,
|
|
207
|
+
mode?: string,
|
|
208
|
+
): void {
|
|
209
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.MODE_SWITCH, { ulid, mode });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function captureToolUsage(
|
|
213
|
+
telemetry: ITelemetryService | undefined,
|
|
214
|
+
properties: {
|
|
215
|
+
ulid: string;
|
|
216
|
+
tool: string;
|
|
217
|
+
modelId?: string;
|
|
218
|
+
provider?: string;
|
|
219
|
+
autoApproved?: boolean;
|
|
220
|
+
success: boolean;
|
|
221
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
222
|
+
): void {
|
|
223
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.TOOL_USED, properties);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function captureSkillUsed(
|
|
227
|
+
telemetry: ITelemetryService | undefined,
|
|
228
|
+
properties: {
|
|
229
|
+
ulid: string;
|
|
230
|
+
skillName: string;
|
|
231
|
+
skillSource: "global" | "project";
|
|
232
|
+
skillsAvailableGlobal: number;
|
|
233
|
+
skillsAvailableProject: number;
|
|
234
|
+
provider?: string;
|
|
235
|
+
modelId?: string;
|
|
236
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
237
|
+
): void {
|
|
238
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.SKILL_USED, properties);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function captureDiffEditFailure(
|
|
242
|
+
telemetry: ITelemetryService | undefined,
|
|
243
|
+
properties: {
|
|
244
|
+
ulid: string;
|
|
245
|
+
modelId?: string;
|
|
246
|
+
provider?: string;
|
|
247
|
+
errorType?: string;
|
|
248
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
249
|
+
): void {
|
|
250
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.DIFF_EDIT_FAILED, properties);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function captureProviderApiError(
|
|
254
|
+
telemetry: ITelemetryService | undefined,
|
|
255
|
+
properties: {
|
|
256
|
+
ulid: string;
|
|
257
|
+
model: string;
|
|
258
|
+
errorMessage: string;
|
|
259
|
+
provider?: string;
|
|
260
|
+
errorStatus?: number;
|
|
261
|
+
requestId?: string;
|
|
262
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
263
|
+
): void {
|
|
264
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.PROVIDER_API_ERROR, {
|
|
265
|
+
...properties,
|
|
266
|
+
errorMessage: truncateErrorMessage(properties.errorMessage) ?? "unknown",
|
|
267
|
+
timestamp: new Date().toISOString(),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function captureMentionUsed(
|
|
272
|
+
telemetry: ITelemetryService | undefined,
|
|
273
|
+
mentionType:
|
|
274
|
+
| "file"
|
|
275
|
+
| "folder"
|
|
276
|
+
| "url"
|
|
277
|
+
| "problems"
|
|
278
|
+
| "terminal"
|
|
279
|
+
| "git-changes"
|
|
280
|
+
| "commit",
|
|
281
|
+
contentLength?: number,
|
|
282
|
+
): void {
|
|
283
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.MENTION_USED, {
|
|
284
|
+
mentionType,
|
|
285
|
+
contentLength,
|
|
286
|
+
timestamp: new Date().toISOString(),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function captureMentionFailed(
|
|
291
|
+
telemetry: ITelemetryService | undefined,
|
|
292
|
+
mentionType:
|
|
293
|
+
| "file"
|
|
294
|
+
| "folder"
|
|
295
|
+
| "url"
|
|
296
|
+
| "problems"
|
|
297
|
+
| "terminal"
|
|
298
|
+
| "git-changes"
|
|
299
|
+
| "commit",
|
|
300
|
+
errorType:
|
|
301
|
+
| "not_found"
|
|
302
|
+
| "permission_denied"
|
|
303
|
+
| "network_error"
|
|
304
|
+
| "parse_error"
|
|
305
|
+
| "unknown",
|
|
306
|
+
errorMessage?: string,
|
|
307
|
+
): void {
|
|
308
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.MENTION_FAILED, {
|
|
309
|
+
mentionType,
|
|
310
|
+
errorType,
|
|
311
|
+
errorMessage: truncateErrorMessage(errorMessage),
|
|
312
|
+
timestamp: new Date().toISOString(),
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function captureMentionSearchResults(
|
|
317
|
+
telemetry: ITelemetryService | undefined,
|
|
318
|
+
query: string,
|
|
319
|
+
resultCount: number,
|
|
320
|
+
searchType: "file" | "folder" | "all",
|
|
321
|
+
isEmpty: boolean,
|
|
322
|
+
): void {
|
|
323
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.MENTION_SEARCH_RESULTS, {
|
|
324
|
+
queryLength: query.length,
|
|
325
|
+
resultCount,
|
|
326
|
+
searchType,
|
|
327
|
+
isEmpty,
|
|
328
|
+
timestamp: new Date().toISOString(),
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export function captureAgentCreated(
|
|
333
|
+
telemetry: ITelemetryService | undefined,
|
|
334
|
+
properties: {
|
|
335
|
+
ulid: string;
|
|
336
|
+
modelId?: string;
|
|
337
|
+
provider?: string;
|
|
338
|
+
} & TelemetryAgentIdentityProperties,
|
|
339
|
+
): void {
|
|
340
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.AGENT_CREATED, {
|
|
341
|
+
...properties,
|
|
342
|
+
timestamp: new Date().toISOString(),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function captureAgentTeamCreated(
|
|
347
|
+
telemetry: ITelemetryService | undefined,
|
|
348
|
+
properties: {
|
|
349
|
+
ulid: string;
|
|
350
|
+
teamId: string;
|
|
351
|
+
teamName: string;
|
|
352
|
+
leadAgentId?: string;
|
|
353
|
+
restoredFromPersistence?: boolean;
|
|
354
|
+
},
|
|
355
|
+
): void {
|
|
356
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.TASK.AGENT_TEAM_CREATED, {
|
|
357
|
+
...properties,
|
|
358
|
+
timestamp: new Date().toISOString(),
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export function captureSubagentExecution(
|
|
363
|
+
telemetry: ITelemetryService | undefined,
|
|
364
|
+
properties: {
|
|
365
|
+
ulid: string;
|
|
366
|
+
durationMs: number;
|
|
367
|
+
outputLines?: number;
|
|
368
|
+
event: "created" | "started" | "ended";
|
|
369
|
+
agentId: string;
|
|
370
|
+
parentId?: string;
|
|
371
|
+
errorMessage?: string;
|
|
372
|
+
type?: "agent" | "team";
|
|
373
|
+
} & Partial<TelemetryAgentIdentityProperties>,
|
|
374
|
+
): void {
|
|
375
|
+
emit(
|
|
376
|
+
telemetry,
|
|
377
|
+
properties.event === "ended"
|
|
378
|
+
? CORE_TELEMETRY_EVENTS.TASK.SUBAGENT_COMPLETED
|
|
379
|
+
: CORE_TELEMETRY_EVENTS.TASK.SUBAGENT_STARTED,
|
|
380
|
+
{
|
|
381
|
+
...properties,
|
|
382
|
+
timestamp: new Date().toISOString(),
|
|
383
|
+
},
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export function captureHookDiscovery(
|
|
388
|
+
telemetry: ITelemetryService | undefined,
|
|
389
|
+
hookName: string,
|
|
390
|
+
globalCount: number,
|
|
391
|
+
workspaceCount: number,
|
|
392
|
+
): void {
|
|
393
|
+
emit(telemetry, CORE_TELEMETRY_EVENTS.HOOKS.DISCOVERY_COMPLETED, {
|
|
394
|
+
hookName,
|
|
395
|
+
globalCount,
|
|
396
|
+
workspaceCount,
|
|
397
|
+
totalCount: globalCount + workspaceCount,
|
|
398
|
+
timestamp: new Date().toISOString(),
|
|
399
|
+
});
|
|
400
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
const machineIdSyncMock = vi.hoisted(() => vi.fn());
|
|
7
|
+
|
|
8
|
+
vi.mock("node-machine-id", () => ({
|
|
9
|
+
machineIdSync: machineIdSyncMock,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
describe("resolveCoreDistinctId", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
vi.resetModules();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
machineIdSyncMock.mockReset();
|
|
19
|
+
vi.unstubAllEnvs();
|
|
20
|
+
vi.restoreAllMocks();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("returns the explicit distinct ID override when provided", async () => {
|
|
24
|
+
const { resolveCoreDistinctId } = await import("./distinct-id");
|
|
25
|
+
|
|
26
|
+
expect(resolveCoreDistinctId(" user-provided-id ")).toBe(
|
|
27
|
+
"user-provided-id",
|
|
28
|
+
);
|
|
29
|
+
expect(machineIdSyncMock).not.toHaveBeenCalled();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("uses node-machine-id when no explicit override is provided", async () => {
|
|
33
|
+
machineIdSyncMock.mockReturnValue("machine-id-123");
|
|
34
|
+
const { resolveCoreDistinctId } = await import("./distinct-id");
|
|
35
|
+
|
|
36
|
+
expect(resolveCoreDistinctId()).toBe("machine-id-123");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("persists and reuses a generated fallback when machine ID lookup fails", async () => {
|
|
40
|
+
const tempDir = mkdtempSync(join(tmpdir(), "cline-distinct-id-"));
|
|
41
|
+
try {
|
|
42
|
+
vi.stubEnv("CLINE_DATA_DIR", tempDir);
|
|
43
|
+
machineIdSyncMock.mockImplementation(() => {
|
|
44
|
+
throw new Error("machine id unavailable");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const { resolveCoreDistinctId } = await import("./distinct-id");
|
|
48
|
+
const first = resolveCoreDistinctId();
|
|
49
|
+
const second = resolveCoreDistinctId();
|
|
50
|
+
|
|
51
|
+
expect(first).toMatch(/^cl-/);
|
|
52
|
+
expect(second).toBe(first);
|
|
53
|
+
} finally {
|
|
54
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { resolveSessionDataDir } from "@clinebot/shared/storage";
|
|
4
|
+
import { nanoid } from "nanoid";
|
|
5
|
+
import { machineIdSync } from "node-machine-id";
|
|
6
|
+
|
|
7
|
+
const GENERATED_DISTINCT_ID_FILE_NAME = "machine-id";
|
|
8
|
+
|
|
9
|
+
export function resolveCoreDistinctId(explicitDistinctId?: string): string {
|
|
10
|
+
const normalizedDistinctId = explicitDistinctId?.trim();
|
|
11
|
+
if (normalizedDistinctId) {
|
|
12
|
+
return normalizedDistinctId;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const machineDistinctId = getMachineDistinctId();
|
|
16
|
+
if (machineDistinctId) {
|
|
17
|
+
return machineDistinctId;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return resolveGeneratedFallbackDistinctId();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getMachineDistinctId(): string | undefined {
|
|
24
|
+
try {
|
|
25
|
+
const distinctId = machineIdSync();
|
|
26
|
+
return distinctId.trim() || undefined;
|
|
27
|
+
} catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function resolveGeneratedFallbackDistinctId(): string {
|
|
33
|
+
const sessionDataDir = resolveSessionDataDir();
|
|
34
|
+
const distinctIdPath = resolve(
|
|
35
|
+
sessionDataDir,
|
|
36
|
+
GENERATED_DISTINCT_ID_FILE_NAME,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
if (existsSync(distinctIdPath)) {
|
|
41
|
+
const savedDistinctId = readFileSync(distinctIdPath, "utf8").trim();
|
|
42
|
+
if (savedDistinctId.length > 0) {
|
|
43
|
+
return savedDistinctId;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
// Ignore read errors and try generating a new fallback.
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const generatedDistinctId = `cl-${nanoid()}`;
|
|
51
|
+
try {
|
|
52
|
+
mkdirSync(sessionDataDir, { recursive: true });
|
|
53
|
+
writeFileSync(distinctIdPath, generatedDistinctId, "utf8");
|
|
54
|
+
} catch {
|
|
55
|
+
// Ignore write errors and continue with the in-memory fallback.
|
|
56
|
+
}
|
|
57
|
+
return generatedDistinctId;
|
|
58
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
ITelemetryAdapter,
|
|
3
|
+
TelemetryArray,
|
|
4
|
+
TelemetryMetadata,
|
|
5
|
+
TelemetryObject,
|
|
6
|
+
TelemetryPrimitive,
|
|
7
|
+
TelemetryProperties,
|
|
8
|
+
TelemetryValue,
|
|
9
|
+
} from "./ITelemetryAdapter";
|
|
10
|
+
export {
|
|
11
|
+
OpenTelemetryAdapter,
|
|
12
|
+
type OpenTelemetryAdapterOptions,
|
|
13
|
+
} from "./OpenTelemetryAdapter";
|
|
14
|
+
export {
|
|
15
|
+
type CreateOpenTelemetryTelemetryServiceOptions,
|
|
16
|
+
createConfiguredTelemetryService,
|
|
17
|
+
createOpenTelemetryTelemetryService,
|
|
18
|
+
OpenTelemetryProvider,
|
|
19
|
+
type OpenTelemetryProviderOptions,
|
|
20
|
+
} from "./OpenTelemetryProvider";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for Default Tools
|
|
3
|
+
*
|
|
4
|
+
* Tool name constants and utility arrays.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { DefaultToolName } from "./types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constants for default tool names
|
|
11
|
+
*/
|
|
12
|
+
export const DefaultToolNames = {
|
|
13
|
+
READ_FILES: "read_files",
|
|
14
|
+
SEARCH_CODEBASE: "search_codebase",
|
|
15
|
+
RUN_COMMANDS: "run_commands",
|
|
16
|
+
FETCH_WEB_CONTENT: "fetch_web_content",
|
|
17
|
+
APPLY_PATCH: "apply_patch",
|
|
18
|
+
EDITOR: "editor",
|
|
19
|
+
SKILLS: "skills",
|
|
20
|
+
ASK: "ask_question",
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Array of all default tool names
|
|
25
|
+
*/
|
|
26
|
+
export const ALL_DEFAULT_TOOL_NAMES: DefaultToolName[] = [
|
|
27
|
+
DefaultToolNames.READ_FILES,
|
|
28
|
+
DefaultToolNames.SEARCH_CODEBASE,
|
|
29
|
+
DefaultToolNames.RUN_COMMANDS,
|
|
30
|
+
DefaultToolNames.FETCH_WEB_CONTENT,
|
|
31
|
+
DefaultToolNames.APPLY_PATCH,
|
|
32
|
+
DefaultToolNames.EDITOR,
|
|
33
|
+
DefaultToolNames.SKILLS,
|
|
34
|
+
DefaultToolNames.ASK,
|
|
35
|
+
];
|