@volcengine/tls-observer-claude-code 0.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/.claude-plugin/plugin.json +11 -0
- package/LICENCE +13 -0
- package/README.md +91 -0
- package/dist/config.d.ts +25 -0
- package/dist/exporter.d.ts +10 -0
- package/dist/hooks/compact.d.ts +4 -0
- package/dist/hooks/dispatch.d.ts +3 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/stop.d.ts +5 -0
- package/dist/hooks/subagent-stop.d.ts +3 -0
- package/dist/hooks/tool-use.d.ts +4 -0
- package/dist/hooks/trace-flow.d.ts +32 -0
- package/dist/hooks/user-prompt-submit.d.ts +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1982 -0
- package/dist/state.d.ts +6 -0
- package/dist/stdin.d.ts +1 -0
- package/dist/tls-producer.d.ts +12 -0
- package/dist/trace.d.ts +23 -0
- package/dist/transcript.d.ts +15 -0
- package/dist/types.d.ts +223 -0
- package/hooks/hooks.json +121 -0
- package/package.json +54 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tls-observer-claude-code",
|
|
3
|
+
"description": "Export Claude Code prompts, assistant responses, tool calls, and token usage to Volcengine TLS as OTLP traces.",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Volcengine"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://code.byted.org",
|
|
9
|
+
"hooks": "./hooks/hooks.json",
|
|
10
|
+
"defaultEnabled": true
|
|
11
|
+
}
|
package/LICENCE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2023 Beijing Volcano Engine Technology Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# TLS Observer for Claude Code
|
|
2
|
+
|
|
3
|
+
将 Claude Code 的 prompt、assistant response、tool call、token usage、subagent 和 compact 事件转换为 GenAI Trace,并通过 Volcengine TLS Producer 写入 Trace Topic。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
推荐使用安装器:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm exec -y \
|
|
11
|
+
--package=@volcengine/tls-observer-claude-code-install -- \
|
|
12
|
+
tls-observer-claude-code-install
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
安装器会:
|
|
16
|
+
|
|
17
|
+
1. 从 registry 下载插件包。
|
|
18
|
+
2. 安装到 `~/.claude/skills/tls-observer-claude-code`。
|
|
19
|
+
3. 在 `~/.claude/settings.json` 启用 `tls-observer-claude-code@skills-dir`。
|
|
20
|
+
4. 将 TLS 配置写入 `~/.claude/tls-observer-claude-code.env`。
|
|
21
|
+
|
|
22
|
+
## 采集事件
|
|
23
|
+
|
|
24
|
+
- `UserPromptSubmit`
|
|
25
|
+
- `PreToolUse`
|
|
26
|
+
- `PostToolUse` / `PostToolUseFailure`
|
|
27
|
+
- `Stop` / `StopFailure`
|
|
28
|
+
- `SubagentStop`
|
|
29
|
+
- `PreCompact` / `PostCompact`
|
|
30
|
+
- `SessionEnd`
|
|
31
|
+
|
|
32
|
+
`Stop` 和 `SessionEnd` 从 transcript 增量读取当前 turn。工具 hooks 补充工具开始时间、结果和错误状态;Subagent transcript 在主 turn 结束时导出。
|
|
33
|
+
|
|
34
|
+
## Trace
|
|
35
|
+
|
|
36
|
+
```text
|
|
37
|
+
agent.turn (server)
|
|
38
|
+
llm.request (client)
|
|
39
|
+
tool.call (client)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
根 span 包含最终模型、prompt、最终 assistant output 和所有模型调用 token 汇总。工具 span 包含:
|
|
43
|
+
|
|
44
|
+
- `gen_ai.tool.name`
|
|
45
|
+
- `gen_ai.tool.call.id`
|
|
46
|
+
- `gen_ai.tool.call.arguments`
|
|
47
|
+
- `gen_ai.tool.call.result`
|
|
48
|
+
- `tool.error`
|
|
49
|
+
- `error.message`
|
|
50
|
+
|
|
51
|
+
所有 span 都包含 `session.id` 和 `tls.app.type=claude-code`。对象和数组类 attribute 会 JSON stringify 后写入。
|
|
52
|
+
|
|
53
|
+
## 内容采集
|
|
54
|
+
|
|
55
|
+
插件默认采集完整 prompt、assistant output、tool input/output:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
CLAUDE_CODE_TLS_CAPTURE_CONTENT=1
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
设置为 `0` 可关闭正文,只保留结构、模型、token 和工具元数据。
|
|
62
|
+
|
|
63
|
+
## 本地诊断
|
|
64
|
+
|
|
65
|
+
默认 data root:
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
~/.claude/plugins/data/tls-observer-claude-code
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
最近一次导出结果:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
cat ~/.claude/plugins/data/tls-observer-claude-code/logs/send/latest.send-log.json
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
设置 `CLAUDE_CODE_TLS_DEBUG_ARTIFACTS=1` 后还会生成:
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
artifacts/otel-traces/
|
|
81
|
+
artifacts/otlp-payloads/
|
|
82
|
+
artifacts/schema-aligned/
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 开发
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
emo run test --filter @volcengine/tls-observer-claude-code --skip-cache
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Rslib 会把 shared OTEL、storage 和 utils 源码内联进 `dist/index.js`。发布包只携带 `dist`、`hooks`、`.claude-plugin` 和 README。
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
dataRoot: string;
|
|
4
|
+
stateFilePath: string;
|
|
5
|
+
sendLogsDir: string;
|
|
6
|
+
artifactsDir: string;
|
|
7
|
+
diagnosticLogMaxBytes: number;
|
|
8
|
+
captureContent: boolean;
|
|
9
|
+
debugArtifacts: boolean;
|
|
10
|
+
serviceName: string;
|
|
11
|
+
serviceInstanceId: string;
|
|
12
|
+
tlsEndpoint?: string;
|
|
13
|
+
otelEndpoint?: string;
|
|
14
|
+
region?: string;
|
|
15
|
+
traceTopicId?: string;
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
ak?: string;
|
|
18
|
+
sk?: string;
|
|
19
|
+
authMode: 'header' | 'resource';
|
|
20
|
+
exportTimeoutMs: number;
|
|
21
|
+
exportTimeoutRetries: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function loadEnvFile(filePath?: string): boolean;
|
|
24
|
+
export declare function loadConfig(): Config;
|
|
25
|
+
export declare function localIdentityMetadata(): Record<string, unknown>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Config } from './config';
|
|
2
|
+
import { closeTraceLogProducers } from './tls-producer';
|
|
3
|
+
import type { ExportResult, TraceModel, TraceSpan } from './types';
|
|
4
|
+
export declare const SCHEMA_FIELD_ORDER: string[];
|
|
5
|
+
export declare function buildOtlpPayload(trace: TraceModel, config: Config): Record<string, unknown>;
|
|
6
|
+
export declare function exportTraceToTls(trace: TraceModel, config: Config): Promise<ExportResult>;
|
|
7
|
+
export { closeTraceLogProducers };
|
|
8
|
+
export declare function buildSchemaAlignedRecord(trace: TraceModel, span: TraceSpan, observedTimeUnixMs?: number): Record<string, unknown>;
|
|
9
|
+
export declare function buildSchemaAlignedRecords(trace: TraceModel, observedTimeUnixMs?: number): Array<Record<string, unknown>>;
|
|
10
|
+
export declare function exportSummary(trace: TraceModel, result: ExportResult): Record<string, unknown>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Config } from '../config';
|
|
2
|
+
import type { PostCompactHookInput, PreCompactHookInput } from '../types';
|
|
3
|
+
export declare function handlePreCompact(input: PreCompactHookInput, config: Config): Promise<void>;
|
|
4
|
+
export declare function handlePostCompact(input: PostCompactHookInput, config: Config): Promise<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { dispatchHook } from './dispatch';
|
|
2
|
+
export { handlePostCompact, handlePreCompact } from './compact';
|
|
3
|
+
export { handleSessionEnd, handleStop, handleStopFailure } from './stop';
|
|
4
|
+
export { handleSubagentStop } from './subagent-stop';
|
|
5
|
+
export { handlePostToolUse, handlePreToolUse } from './tool-use';
|
|
6
|
+
export { handleUserPromptSubmit } from './user-prompt-submit';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Config } from '../config';
|
|
2
|
+
import type { SessionEndHookInput, StopFailureHookInput, StopHookInput } from '../types';
|
|
3
|
+
export declare function handleStop(input: StopHookInput, config: Config): Promise<void>;
|
|
4
|
+
export declare function handleStopFailure(input: StopFailureHookInput, config: Config): Promise<void>;
|
|
5
|
+
export declare function handleSessionEnd(input: SessionEndHookInput, config: Config): Promise<void>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Config } from '../config';
|
|
2
|
+
import type { PostToolUseHookInput, PreToolUseHookInput } from '../types';
|
|
3
|
+
export declare function handlePreToolUse(input: PreToolUseHookInput, config: Config): Promise<void>;
|
|
4
|
+
export declare function handlePostToolUse(input: PostToolUseHookInput, config: Config): Promise<void>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Config } from '../config';
|
|
2
|
+
import type { SessionEndHookInput, SessionState, StopHookInput, TraceModel } from '../types';
|
|
3
|
+
export declare function expandHome(filePath: string | undefined): string | undefined;
|
|
4
|
+
export declare function writeSendLog(config: Config, record: Record<string, unknown>): Promise<void>;
|
|
5
|
+
export declare function exportTraceAndLog(options: {
|
|
6
|
+
config: Config;
|
|
7
|
+
trace: TraceModel;
|
|
8
|
+
hookEventName: string;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
export declare function exportTranscriptTurns(options: {
|
|
11
|
+
input: StopHookInput;
|
|
12
|
+
config: Config;
|
|
13
|
+
transcriptPath: string;
|
|
14
|
+
afterLine: number;
|
|
15
|
+
afterOffset?: number;
|
|
16
|
+
session: SessionState;
|
|
17
|
+
hookEventName: string;
|
|
18
|
+
source?: string;
|
|
19
|
+
traceSeedSuffix?: string;
|
|
20
|
+
extraAttributes?: Record<string, unknown>;
|
|
21
|
+
turnIndexBase?: number;
|
|
22
|
+
synthesizeFinalAssistant?: boolean;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
lastLine: number;
|
|
25
|
+
lastOffset: number;
|
|
26
|
+
tracedTurns: number;
|
|
27
|
+
}>;
|
|
28
|
+
export declare function exportPendingSubagents(options: {
|
|
29
|
+
input: StopHookInput | SessionEndHookInput;
|
|
30
|
+
config: Config;
|
|
31
|
+
session: SessionState;
|
|
32
|
+
}): Promise<number>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|