dsh-axonhub-tracing 0.0.0-stage → 0.2.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ ## 0.2.2
4
+
5
+ - 修复 AxonHub 的 Responses 路径可能因 `prompt_cache_key` 超过 64 字符而返回 HTTP 400 的问题。`AH-Trace-Id` 超过 47 字符时,改用整条追踪号的 16 位十六进制哈希;较短的追踪号、线程号和 `hashIds: true` 的行为均不变。
6
+
7
+ ## 0.2.1
8
+
9
+ - 重新发布版本。0.2.0 因 npm 账号邮箱变更被整体撤回,代码与 0.2.0 相同。
10
+
11
+ ## 0.2.0
12
+
13
+ - 标题和审批拆成两个独立开关,默认都走独立线程,分别落在 `#title` 和 `#review`。
14
+ - 「整段会话一条追踪」改成「轮次追踪」,只控制轮次后缀,不再影响标题、审批和子代理的分组。
15
+ - 旧设置自动迁移:`traceGranularity=session` 映射为关闭轮次追踪,`internalThread` 映射到标题和审批两个开关。
16
+ - 说明修正:AxonHub 的渠道粘性先按追踪、再按线程回退,两者都缓存三十分钟。轮次后缀不会破坏同一会话的渠道粘性。
17
+
18
+ ## 0.1.0
19
+
20
+ 第一个可用版本。
21
+
22
+ - 走 `llm-pi-ai/request-headers` 给发往 AxonHub 的请求加 `AH-Thread-Id`、`AH-Trace-Id`、`AH-Kind`。
23
+ - 普通轮次按轮次生成追踪,重试和同轮工具调用保持同一个追踪号。
24
+ - 起标题、自动审批、压缩摘要各自分类。压缩摘要复用当前轮次的追踪号。
25
+ - 子代理默认独立线程,追踪号里带父会话和子代理名。
26
+ - 渠道支持自动、全部、全关三种默认范围,外加逐个渠道的手动开关。
27
+ - 设置卡片显示渠道列表和最近若干条已打标的请求。
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 JasonWen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,138 @@
1
+ # dsh-axonhub-tracing
2
+
3
+ [中文](README.md) | English
4
+
5
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
6
+ [![DSH](https://img.shields.io/badge/DSH-0.2.x-4B32C3.svg)](https://github.com/deepseek-ai/deepseek-harness)
7
+ [![Node](https://img.shields.io/badge/node-%E2%89%A5%2020-brightgreen.svg)](#)
8
+ [![platform](https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey.svg)](#)
9
+ [![AxonHub](https://img.shields.io/badge/gateway-AxonHub-0A7E8C.svg)](https://github.com/looplj/axonhub)
10
+
11
+ This plugin attaches identity request headers recognized by AxonHub to model requests sent from DeepSeek Harness (DSH).
12
+
13
+ Once installed and enabled, AxonHub's tracing view groups model calls by conversation thread and interaction turn instead of listing every request as an isolated record. Title generation and auto-approval requests stay out of the main conversation timeline, context compaction summaries are tagged as a distinct type, and subagent tasks are placed under their own dedicated traces.
14
+
15
+ ## What Problem It Solves
16
+
17
+ By default, DSH sends model requests without any session identifiers. When the AxonHub gateway receives these requests, it treats each one as an isolated call: it cannot tell which requests belong to the same conversation, nor can it distinguish regular chat replies from title generation, auto-approval, or context compaction requests.
18
+
19
+ Using DSH's `llm-pi-ai/request-headers` hook, this plugin injects three HTTP request headers before each request is sent so AxonHub can identify and group them:
20
+
21
+ 1. `AH-Thread-Id`: The conversation thread ID. Related requests within the same conversation share the same thread value.
22
+ 2. `AH-Trace-Id`: The trace ID for a single conversation turn or task. Within a turn, this value remains constant regardless of how many tool calls or retries occur.
23
+ 3. `AH-Kind`: The request type identifier, indicating to the gateway whether the request is a regular chat turn, subagent task, title generation, auto-approval, or compaction summary.
24
+
25
+ When AxonHub receives a request, it creates or links a conversation thread from `AH-Thread-Id` and a trace record from `AH-Trace-Id`. `AH-Kind` is recorded alongside the request headers so calls can be told apart by type.
26
+
27
+ ## Installation
28
+
29
+ You can add this plugin package directly from the plugin management view in DSH, or install it from the command line with `dsh plugin --profile desktop add <path>` (replacing `<path>` with the actual plugin directory path):
30
+
31
+ ```sh
32
+ dsh plugin --profile desktop add /path/to/dsh-axonhub-tracing
33
+ ```
34
+
35
+ Restart DSH once after installation, and "AxonHub Tracing" (AxonHub 追踪) will appear in the plugin list.
36
+
37
+ ## Settings
38
+
39
+ Open the Plugins page in DSH Settings and select "AxonHub Tracing" (AxonHub 追踪) to configure the plugin.
40
+
41
+ At the top of the page is the master toggle. Turning it off stops attaching the three headers starting from the next request, letting you pause tracing immediately without uninstalling the plugin.
42
+
43
+ Below the master toggle is the default channel scope setting, which governs channels that do not have an explicit per-channel override. Three modes are available:
44
+
45
+ 1. Auto (自动): Attach headers only to channels whose name or endpoint URL contains `axon`.
46
+ 2. All (全部): Attach headers to all supported channels.
47
+ 3. Off (全关): Attach headers to no channels by default.
48
+
49
+ Below the default scope is the channel list, where per-channel manual toggles take precedence over the default scope. Checking a channel forces headers on for that channel; unchecking it forces headers off. Next to each channel, a label indicates whether its current state comes from the default scope or a manual override. Channels with a manual override show a "Restore default" (恢复默认) button on the right, which clears the override and returns the channel to the default scope rule. With this setup, newly added channels automatically follow the default scope without requiring plugin reconfiguration, and only channels that need special handling require manual overrides.
50
+
51
+ The bottom of the page displays the 20 most recent calls where headers were attached, showing the timestamp, request type, channel, and trace ID. This list is empty right after installation and populates once you send a chat message.
52
+
53
+ All settings are stored in the following local file, which can also be edited by hand:
54
+
55
+ ```
56
+ ~/.dsh/axonhub-tracing/settings.json
57
+ ```
58
+
59
+ The settings file is owned by a single DSH process. If two DSH processes are running at the same time and both modify settings, the last write wins, and the other process must be restarted to pick up the updated values. If the settings file is corrupted, the plugin disables itself rather than silently resetting to defaults and continuing to attach headers; it resumes once the file is fixed or deleted and recreated.
60
+
61
+ ## Grouping Rules
62
+
63
+ A thread represents a conversation, and a trace represents a single interaction turn or task. By default, requests use the current session as their thread. Some request types can use a separate thread.
64
+
65
+ On its Responses path, AxonHub appends `-` and a 16-digit hexadecimal fingerprint to the trace ID to build a `prompt_cache_key` with a 64-character limit. With the default setting `hashIds: false`, the plugin sends the trace IDs described below as-is when they are at most 47 characters long. If a trace ID is longer, the plugin replaces the entire value with a stable 16-digit hexadecimal hash. This length rule does not affect thread IDs.
66
+
67
+ 1. Regular chat and turn tracing: "Turn tracing" (轮次追踪) is on by default. Each turn has a separate trace, built as `<session>:t<turn>` before the length rule. With a standard `session-<uuid>` ID, turns 1–9 keep that format and turn 10 onward uses a hash. Tool calls and retries in the same turn share a trace. Turn off "Turn tracing" to use a single trace for the whole session. The thread ID stays the same, so session stickiness is unaffected.
68
+ 2. Compaction summaries: Context compaction summaries always share the current turn's trace. Because compaction requests operate on the same context as the active conversation, keeping them in the same trace preserves a continuous context history while still distinguishing them from regular calls via the kind header.
69
+ 3. Titles and approvals: Title generation and auto-approval each have an independent setting, both defaulting to separate mode. Their thread IDs are `<session>#title` and `<session>#review` in separate mode, keeping them out of the main session timeline. Their raw trace IDs are `<session>:title` and `<session>:review`; both are hashed with a standard session ID. These tasks do not share the main conversation's cache prefix, so separate threads incur no cache penalty. To merge either thread back into the main session, switch its setting to follow the main session.
70
+ 4. Subagents: By default, a subagent uses its own session ID as its thread ID. Its raw trace ID is `<parent-session>:c<name>.<short-code>:t<turn>`, which is hashed with a standard session ID. The short code comes from the child session ID and distinguishes subagents launched under the same name by the same parent. The plugin reads the parent-child relationship from DSH without extra configuration. Separate threads may be routed to a different channel. If sharing the parent's prefix cache is more important, set subagents to follow the parent session.
71
+
72
+ ## Relationship with Caching
73
+
74
+ This plugin only sends identity headers on outgoing requests; it does not directly increase cache hit rates on its own. Channel pinning is controlled by AxonHub's channel stickiness setting, `trace_sticky_mode`.
75
+
76
+ When `trace_sticky_mode` is enabled on the gateway, AxonHub first checks which channel was last used for the same trace, and on a miss falls back to the channel last used for the same thread. Both mapping levels are cached for 30 minutes. Routing to the same channel means using the same upstream account, which is a prerequisite for prefix cache hits.
77
+
78
+ Depending on whether the plugin and gateway stickiness are enabled, there are three scenarios:
79
+
80
+ 1. Plugin installed, gateway stickiness disabled: AxonHub records traces and usage accounting, while gateway channel selection behaves the same as before installation.
81
+ 2. Gateway stickiness enabled, plugin not installed: No effect on DSH, because DSH sends neither trace IDs nor thread IDs by default, leaving the gateway with no identifier to pin against.
82
+ 3. Both plugin and gateway stickiness enabled: Gateway routing stays pinned according to the identity headers carried by each request.
83
+
84
+ The second-level fallback is key to how this works. Because an entire main conversation shares a single thread ID, starting a new turn with a new trace ID (when turn tracing is enabled) still resolves to the previous channel via the thread lookup. The turn suffix does not break session stickiness, so default turn tracing will not scatter a conversation across different channels. Only requests split into separate threads, such as titles, approvals, and subagents in separate mode, can be routed to a different channel. For titles and approvals, the prompt prefix differs from the main conversation anyway, so switching channels has little impact; for subagents that share a prefix with the parent session, configuring them to follow the parent session keeps routing stable.
85
+
86
+ ## Supported Channels
87
+
88
+ The plugin hooks into `llm-pi-ai/request-headers` and only covers channels routed through the `pi-ai` adapter. This includes a local AxonHub primary channel as well as manually configured `anthropic`, `google`, `openai`, or `kimi` channels pointed at a local gateway.
89
+
90
+ DSH's native DeepSeek endpoint and subscription account endpoints are not supported. Those two paths send only their own authentication headers and do not invoke the `llm-pi-ai/request-headers` extension hook in the underlying request pipeline, so the plugin cannot attach headers to them.
91
+
92
+ Unsupported channels never receive headers from this plugin and do not need to be manually disabled; for supported channels you want to trace, either let the default scope match them or check them manually in settings.
93
+
94
+ ## Verification
95
+
96
+ After installation, you can verify that tracing is working as expected with the following steps:
97
+
98
+ 1. Send a regular chat message and wait for the reply to finish.
99
+ 2. Open the Traces page in AxonHub, confirm that a record for the current turn appears, and open it to verify that all model calls from that turn are grouped inside.
100
+ 3. Check the Threads page in AxonHub and confirm that multiple turns from the same conversation are grouped under the same thread.
101
+ 4. Start a new conversation to trigger automatic title generation, then check the thread list to confirm that a separate thread ending in `#title` appears with a title request type, without mixing into the regular chat thread.
102
+ 5. Launch a subagent to run a task, then check that a separate thread appears with the `subagent` request kind. With standard session IDs, the trace ID should be a 16-digit hexadecimal hash.
103
+ 6. Turn off the plugin's master toggle, send another message, and inspect the request headers via a packet capture tool or gateway logs to confirm that no headers starting with `AH` are present.
104
+
105
+ You can also use the recent requests list at the bottom of the plugin settings page for a quick check; it displays the request type and trace ID for each call that had headers attached.
106
+
107
+ ## Development and Testing
108
+
109
+ This repository has no runtime dependencies. After cloning, run the test suite directly:
110
+
111
+ ```sh
112
+ npm test
113
+ ```
114
+
115
+ The tests cover ID derivation, channel selection, settings migration, atomic header injection, the recent requests list, and multi-process settings merging.
116
+
117
+ ## Uninstallation
118
+
119
+ You can remove this plugin from the plugin management view in DSH, or run the `remove` command from the command line:
120
+
121
+ ```sh
122
+ dsh plugin --profile desktop remove dsh-axonhub-tracing
123
+ ```
124
+
125
+ The plugin does not write to any database or modify channel configurations. Once uninstalled, outgoing model request headers immediately return to their default state. Only the local settings file `~/.dsh/axonhub-tracing/settings.json` remains on disk; you can delete it manually if desired, or leave it in place without side effects.
126
+
127
+ ## Known Limitations
128
+
129
+ 1. Channel coverage: The plugin uses `llm-pi-ai/request-headers` and only covers channels routed through `pi-ai`. DSH's native DeepSeek endpoint and subscription account endpoints are not supported, and the plugin cannot intercept those requests.
130
+ 2. External backend subagents: If a subagent runs on an external backend such as Claude Code or Codex, its requests bypass DSH's model layer and therefore will not carry headers from this plugin. This is expected behavior.
131
+ 3. Privacy and identifier hashing: Unhashed thread and trace IDs may contain session IDs or subagent names, but never conversation content. To hide the original identifiers, set `hashIds` to `true` in the settings file. This hashes all thread and trace IDs regardless of length, so the gateway UI will no longer show the original values. The underlying model library may still send its own session IDs under some protocols. The plugin does not write those IDs, and `hashIds` does not affect them.
132
+
133
+ ## Troubleshooting
134
+
135
+ 1. Settings page shows "Channel list not loaded yet" (还没有读到渠道列表): The host has not finished registering channels yet. Send one message first, then reopen the settings page.
136
+ 2. Settings page shows an error: The host plugin failed to load completely. Restart DSH once and verify that the plugin appears in the plugin list.
137
+ 3. Requests appear in AxonHub but are not grouped: First confirm that the request headers include `AH-Trace-Id`. If the header is present and requests are still ungrouped, check whether `trace_header` in the gateway's tracing configuration was changed to a different header name.
138
+ 4. Trace IDs do not advance per turn: Check whether "Turn tracing" (轮次追踪) is turned off in settings. When turned off, the entire conversation shares a single trace ID and appears unsplit across turns in the gateway UI.
package/README.md CHANGED
@@ -1,3 +1,138 @@
1
- # Temporary Holding Version
1
+ # dsh-axonhub-tracing
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [English](README.en.md) | 中文
4
+
5
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
6
+ [![DSH](https://img.shields.io/badge/DSH-0.2.x-4B32C3.svg)](https://github.com/deepseek-ai/deepseek-harness)
7
+ [![Node](https://img.shields.io/badge/node-%E2%89%A5%2020-brightgreen.svg)](#)
8
+ [![platform](https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey.svg)](#)
9
+ [![AxonHub](https://img.shields.io/badge/gateway-AxonHub-0A7E8C.svg)](https://github.com/looplj/axonhub)
10
+
11
+ 本插件用于为 DeepSeek Harness(简称 DSH)发出的模型请求附加 AxonHub 可识别的身份标识请求头。
12
+
13
+ 安装并启用后,AxonHub 的追踪页面可以按对话线程与问答轮次清晰归类每一次模型调用,不再将所有请求混作零散记录。对话标题生成与自动审批请求不会混入正常对话时间线,上下文压缩摘要会标记独立类型,子代理任务也会归入各自独立的追踪位置。
14
+
15
+ ## 它解决什么问题
16
+
17
+ 在默认情况下,DSH 发送模型请求时不携带任何会话标识。AxonHub 网关收到请求后,只能将其视为彼此孤立的单次调用,无法判断哪些请求属于同一段对话,也无法区分正常对话回复、生成对话标题、自动审批或上下文压缩等不同用途的请求。
18
+
19
+ 本插件通过 DSH 的 `llm-pi-ai/request-headers` 接口,在请求发出前向 HTTP 请求头注入三个字段,供 AxonHub 识别并归类请求:
20
+
21
+ 1. `AH-Thread-Id`:对话线程编号。同一段对话内的相关请求共用同一个线程值。
22
+ 2. `AH-Trace-Id`:单轮对话或单项任务的追踪编号。在同一轮对话中,无论模型调用了多少次工具或触发了多少次重试,该值都保持不变。
23
+ 3. `AH-Kind`:请求类型标识,用于向网关标明当前请求属于正常对话、子代理、标题生成、自动审批还是压缩摘要。
24
+
25
+ AxonHub 收到请求后,会根据 `AH-Thread-Id` 建立对话线程,根据 `AH-Trace-Id` 建立单次追踪记录。`AH-Kind` 会随请求一起写入请求头记录,便于事后按类型区分调用。
26
+
27
+ ## 装法
28
+
29
+ 可以在 DSH 的插件管理界面中直接添加本插件包,也可以在命令行中执行 `dsh plugin --profile desktop add <路径>`(将 `<路径>` 替换为插件目录的实际位置):
30
+
31
+ ```sh
32
+ dsh plugin --profile desktop add /path/to/dsh-axonhub-tracing
33
+ ```
34
+
35
+ 安装完成后重启一次 DSH,插件列表中即会显示「AxonHub 追踪」。
36
+
37
+ ## 设置
38
+
39
+ 打开 DSH 设置中的插件页面,找到「AxonHub 追踪」即可配置各项参数。
40
+
41
+ 页面顶部为插件总开关。关闭总开关后,从下一次请求开始将不再附加上述三个请求头,无需卸载插件即可立即停用追踪功能。
42
+
43
+ 总开关下方是渠道选择的默认范围设置。默认范围用于控制未单独设置手动开关的渠道,共有三种模式:
44
+
45
+ 1. 自动:仅对名称或接口地址中包含 `axon` 的渠道附加请求头。
46
+ 2. 全部:对所有受支持的渠道附加请求头。
47
+ 3. 全关:默认不对任何渠道附加请求头。
48
+
49
+ 默认范围下方是渠道列表,逐个渠道的手动开关优先于默认范围。勾选某个渠道后,该渠道将始终附加请求头;取消勾选后,该渠道将始终不附加请求头。每个渠道旁边会注明当前状态是来自默认范围的自动命中,还是来自用户的手动开关。如果某个渠道被手动修改过,右侧会显示「恢复默认」按钮,点击即可清除手动设置并恢复按默认范围计算。通过这种设计,后续新增渠道时无需重新调整插件配置,新渠道会自动按默认范围归类,仅在需要单独特殊处理时再手动调整。
50
+
51
+ 页面底部展示最近二十条已附加请求头的调用记录,可直接查看请求时间、类型、渠道和追踪号。插件刚安装完成时该列表为空,发送一条对话消息后即会生成记录。
52
+
53
+ 所有设置保存在以下本地文件中,支持直接手动编辑:
54
+
55
+ ```
56
+ ~/.dsh/axonhub-tracing/settings.json
57
+ ```
58
+
59
+ 该设置文件由单个 DSH 进程持有。如果同时开启两个 DSH 进程并分别修改设置,文件内容以最后一次写入为准,另一个进程需要重启后才会读取到新值。当设置文件损坏时,插件不会自行恢复默认值并继续附加请求头,而是会自动停用,待用户修复该文件或将其删除重建后再恢复工作。
60
+
61
+ ## 分组规则
62
+
63
+ 线程代表一段对话,追踪代表一轮交互或一项具体任务。默认情况下,所有请求都以当前会话本身作为线程,只有特定类型的请求会按配置拆分到独立线程。
64
+
65
+ AxonHub 的 Responses 路径会在追踪号后加上 `-` 和 16 位十六进制指纹,生成最多 64 字符的 `prompt_cache_key`。因此,在默认设置 `hashIds: false` 下,下述格式生成的追踪号不超过 47 字符时原样发送;超过 47 字符时,插件将整条追踪号替换为 16 位十六进制哈希。同一个原始值总是得到同一个哈希,线程号不受此长度规则影响。
66
+
67
+ 1. 普通对话与轮次追踪:普通对话默认开启「轮次追踪」,每轮对话生成一条独立追踪,原始格式为 `<会话>:t<轮次>`。使用标准 `session-<uuid>` 时,第 1 至 9 轮保留原样,第 10 轮起使用哈希。同一轮内的工具调用和重试共用同一追踪号。关闭「轮次追踪」后,整段会话共用一个追踪号,不再区分轮次;线程号不变,因此不影响会话粘性。
68
+ 2. 压缩摘要:上下文压缩摘要始终与当前轮次共用同一条追踪。压缩请求与正常对话使用同一段上下文,归入同一条追踪便于保持上下文记录连续,同时仍可通过类型标识将其与普通调用区分开。
69
+ 3. 标题与审批:生成标题和自动审批各有一个独立开关,默认均为独立模式。独立模式的线程分别为 `<会话>#title` 和 `<会话>#review`,不会占用主会话的时间线。原始追踪号分别为 `<会话>:title` 和 `<会话>:review`,使用标准会话编号时两者都会被哈希。标题和审批原本就不与主对话共享缓存前缀,拆分线程不会造成缓存损失。要并回主会话,分别切换对应的开关即可。
70
+ 4. 子代理:子代理默认使用自己的会话编号作线程号。原始追踪号格式为 `<父会话>:c<名字>.<短码>:t<轮次>`,使用标准会话编号时会被哈希。`<短码>` 由子会话编号计算,用于区分同一父会话启动的同名子代理。插件直接读取 DSH 记录的父子关系,无需额外配置。独立线程可能被分配到其他渠道;如果更看重与父会话共享前缀缓存,可以在设置中将子代理改为跟父会话。
71
+
72
+ ## 和缓存的关系
73
+
74
+ 本插件只负责在请求头中发送身份标识,不会直接提高缓存命中率。真正决定渠道固定分配的是 AxonHub 的渠道粘性设置 `trace_sticky_mode`。
75
+
76
+ 当网关开启 `trace_sticky_mode` 后,网关会先查看同一追踪上一次使用了哪个渠道,未命中时再查看同一线程上一次使用了哪个渠道,两级映射记录均缓存三十分钟。分配到同一个渠道意味着使用同一个上游账号,只有在同一个上游账号下,前缀缓存才有可能命中。
77
+
78
+ 根据插件与网关粘性的开启组合,共有三种情况:
79
+
80
+ 1. 仅安装插件,网关未开启粘性:可以在 AxonHub 中进行追踪和记账,但网关的选路方式与安装前一致。
81
+ 2. 仅开启网关粘性,未安装插件:对 DSH 不起作用,因为 DSH 默认不发送追踪号与线程号,网关没有可用于保持粘性的标识。
82
+ 3. 同时启用插件与网关粘性:网关选路会跟随请求携带的身份标识保持稳定。
83
+
84
+ 这套机制的关键在于第二级回退。因为同一段主对话共用同一个线程,即使开启轮次追踪使每一轮更换了追踪号,新一轮请求仍然会通过同一线程找到上一次使用的渠道,轮次后缀不影响会话粘性,默认的轮次追踪不会把同一段对话拆分到不同渠道。真正可能切换渠道的是被拆分出去的独立线程,例如独立模式下的标题、审批和子代理。标题和审批与主对话的缓存前缀原本就不同,切换渠道影响不大;如果子代理与父会话共享缓存前缀,将其改为跟父会话会更加稳定。
85
+
86
+ ## 哪些渠道能打标签
87
+
88
+ 插件走 `llm-pi-ai/request-headers` 接口,只覆盖走 `pi-ai` 适配器的渠道。例如本机的 AxonHub 主渠道,以及手动配置指向本机网关的 `anthropic`、`google`、`openai`、`kimi` 等渠道,都属于这一类。
89
+
90
+ DSH 原生 DeepSeek 接口和订阅账号接口不支持。这两类接口只发送自身的鉴权请求头,底层链路上没有接入 `llm-pi-ai/request-headers` 扩展接口,因此插件无法向其添加请求头。
91
+
92
+ 如果某些渠道原本就不属于支持范围,无需特意在插件中关闭,它们本身就不会被附加请求头;对于需要追踪的受支持渠道,在设置中按默认范围匹配或手动勾选即可。
93
+
94
+ ## 怎么验证
95
+
96
+ 安装完成后,可以按以下步骤核验功能是否正常生效:
97
+
98
+ 1. 发送一条普通的对话消息,等待回复结束。
99
+ 2. 打开 AxonHub 的追踪页面,确认能看到当前轮次对应的记录,点击进入后能看到该轮对话包含的所有模型调用。
100
+ 3. 查看 AxonHub 的线程页面,确认同一段对话的多个轮次都挂在同一个线程下面。
101
+ 4. 新开一段对话并触发自动生成标题,查看线程列表,确认多出一条名称带 `#title` 的独立线程,内部请求类型为标题,且没有混入正常对话。
102
+ 5. 启动一个子代理执行任务,随后查看线程列表,确认多出一条子代理线程,请求类型为 `subagent`。使用标准会话编号时,追踪号应是 16 位十六进制哈希。
103
+ 6. 关闭插件总开关后再发送一条消息,使用抓包工具或查看网关日志检查请求头,确认请求中不再包含任何以 `AH` 开头的请求头。
104
+
105
+ 此外,插件设置页面最下方的最近请求列表也可用于快速自查,列表中会显示每一条已附加请求头的调用所使用的请求类型和追踪号。
106
+
107
+ ## 开发与测试
108
+
109
+ 本仓库没有运行时依赖,克隆后可直接运行测试:
110
+
111
+ ```sh
112
+ npm test
113
+ ```
114
+
115
+ 测试覆盖身份编号推导、渠道选择、设置迁移、请求头原子写入、最近请求列表和多进程设置合并。
116
+
117
+ ## 卸载
118
+
119
+ 可以在 DSH 的插件管理界面中移除本插件,也可以在命令行中执行以下 `remove` 命令:
120
+
121
+ ```sh
122
+ dsh plugin --profile desktop remove dsh-axonhub-tracing
123
+ ```
124
+
125
+ 插件不写数据库,也不修改渠道配置。卸载后,模型请求头会立即恢复原状,本地仅保留设置文件 `~/.dsh/axonhub-tracing/settings.json`,可根据需要手动删除,保留不删也不会产生影响。
126
+
127
+ ## 已知边界
128
+
129
+ 1. 渠道支持范围:插件走 `llm-pi-ai/request-headers`,只覆盖走 `pi-ai` 的渠道,DSH 原生 DeepSeek 接口和订阅账号接口不支持,插件无法介入这些请求。
130
+ 2. 外部后端子代理:如果子代理使用的是 Claude Code 或 Codex 等外部后端,这类请求不经过 DSH 的模型层,因此也不会带有本插件的请求头,这属于预期行为。
131
+ 3. 隐私与标识处理:未哈希的线程号和追踪号可能包含会话编号或子代理名称,不包含对话内容。要隐藏原始标识,可将设置文件中的 `hashIds` 改为 `true`。开启后,线程号和追踪号全部使用哈希,不论原始长度;网关后台也不再能直接读出原始含义。模型库在某些协议下可能自行发送会话标识,那部分并非本插件写入,不受 `hashIds` 控制。
132
+
133
+ ## 排查
134
+
135
+ 1. 设置页显示「还没有读到渠道列表」:说明宿主尚未完成渠道注册,先发送一条消息后再返回设置页查看。
136
+ 2. 设置页显示错误:通常是宿主插件未加载成功,重启一次 DSH,再检查插件列表中是否存在本插件。
137
+ 3. AxonHub 中能看到请求但未分组:先确认请求头中是否包含 `AH-Trace-Id`;如果请求头已包含该字段但仍不分组,请检查网关的追踪配置是否将 `trace_header` 修改成了其他名称。
138
+ 4. 追踪号与轮次对不上:先检查设置中的「轮次追踪」是否已关闭;关闭后整段对话共用一个追踪号,在后台看起来就是未按轮次拆分的状态。