deepccc 0.1.23 → 0.1.25
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/README.md +11 -2
- package/dist/config.d.ts +5 -0
- package/dist/config.js +2 -0
- package/dist/context.d.ts +9 -1
- package/dist/context.js +8 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,6 +77,7 @@ $env:DEEPCCC_STREAMING="true"
|
|
|
77
77
|
"model": "deepseek-v4-pro",
|
|
78
78
|
"effort": "",
|
|
79
79
|
"streaming": true,
|
|
80
|
+
"contextWindow": 1048576,
|
|
80
81
|
"rawStreamLogs": {
|
|
81
82
|
"enabled": true,
|
|
82
83
|
"maxBytesPerTurn": 1048576,
|
|
@@ -90,15 +91,23 @@ $env:DEEPCCC_STREAMING="true"
|
|
|
90
91
|
`DEEPCCC_PROVIDER` 或命令行 `--provider` 覆盖:
|
|
91
92
|
|
|
92
93
|
- `openai` 使用 OpenAI-compatible Chat Completions 协议,兼容 DeepSeek、OpenAI、LiteLLM、vLLM 等服务。
|
|
93
|
-
- `anthropic` 使用 Anthropic Messages 协议。配置中的 `baseURL`
|
|
94
|
+
- `anthropic` 使用 Anthropic Messages 协议。配置中的 `baseURL` **完全按填写值使用,不自动补 `/v1`**,请填写到完整版本化地址,例如 DeepSeek 官方 Anthropic 端点为 `https://api.deepseek.com/anthropic/v1`(官方 Anthropic SDK 使用的 `https://api.deepseek.com/anthropic` 基址会拼接为 `.../anthropic/v1/messages`)。`effort` 是 OpenAI/DeepSeek 扩展参数,在 Anthropic 模式下不会发送。
|
|
94
95
|
|
|
95
96
|
`streaming` 控制主对话是否使用流式请求,默认 `true`;也可以通过
|
|
96
97
|
`DEEPCCC_STREAMING=true|false` 覆盖。关闭后,终端会在整条模型响应完成后一次性显示结果。
|
|
97
98
|
|
|
99
|
+
`contextWindow` 是模型上下文窗口(token),默认 `1048576`(1M,DeepSeek V4 Pro/Flash
|
|
100
|
+
原生规格);上下文压缩阈值自动 = `contextWindow × 0.8`(超出即把较早消息压缩为摘要)。
|
|
101
|
+
可通过 `DEEPCCC_CONTEXT_WINDOW` 环境变量覆盖。⚠️ 超过模型/服务端实际上限时请求会被
|
|
102
|
+
API 拒绝(context length exceeded),实际窗口以模型与所用服务端为准(如 litellm 的
|
|
103
|
+
`max_input_tokens`)。
|
|
104
|
+
|
|
98
105
|
`rawStreamLogs.enabled` 默认 `true`,通过 `DEEPCCC_RAW_STREAM_LOGS` 环境变量或配置 JSON 关闭。
|
|
99
106
|
开启时,每次对话的原始流按 gzip JSONL 落到 `~/.deepccc/raw-stream-logs/`,供
|
|
100
107
|
`session_search` 工具在会话被压缩后找回被压缩消息的精确原文(检索时设置
|
|
101
|
-
`include_raw_logs=true
|
|
108
|
+
`include_raw_logs=true`)。压缩后注入的恢复提示会携带当前会话 ID:优先用
|
|
109
|
+
`session_id` 限定只搜当前会话,未命中时可省略 `session_id` 做全库检索。
|
|
110
|
+
关闭后,压缩后的旧消息原文将无法找回。
|
|
102
111
|
|
|
103
112
|
## 命令行交互
|
|
104
113
|
|
package/dist/config.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export interface DeepCccConfig {
|
|
|
9
9
|
effort: string;
|
|
10
10
|
/** 主对话是否使用流式请求;默认开启 */
|
|
11
11
|
streaming: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* 模型上下文窗口(token),默认 1048576(1M,DeepSeek V4 Pro/Flash 原生规格)。
|
|
14
|
+
* 上下文压缩阈值自动 = contextWindow × 0.8;超过模型/服务端实际上限会被 API 拒绝。
|
|
15
|
+
*/
|
|
16
|
+
contextWindow: number;
|
|
12
17
|
rawStreamLogs: {
|
|
13
18
|
enabled: boolean;
|
|
14
19
|
maxBytesPerTurn: number;
|
package/dist/config.js
CHANGED
|
@@ -14,6 +14,7 @@ export const DEFAULT_CONFIG = {
|
|
|
14
14
|
model: "deepseek-v4-pro",
|
|
15
15
|
effort: "",
|
|
16
16
|
streaming: true,
|
|
17
|
+
contextWindow: 1_048_576,
|
|
17
18
|
rawStreamLogs: {
|
|
18
19
|
// 默认开启:压缩后可通过 session_search(include_raw_logs=true)找回原文。
|
|
19
20
|
// 如需关闭,在 ~/.deepccc/config.json 中设置 rawStreamLogs.enabled=false。
|
|
@@ -67,6 +68,7 @@ function loadConfig() {
|
|
|
67
68
|
model: env("DEEPCCC_MODEL") ?? env("DEEPSEEK_MODEL") ?? file.model ?? DEFAULT_CONFIG.model,
|
|
68
69
|
effort: env("DEEPCCC_EFFORT") ?? env("DEEPSEEK_EFFORT") ?? file.effort ?? DEFAULT_CONFIG.effort,
|
|
69
70
|
streaming: boolEnv("DEEPCCC_STREAMING") ?? file.streaming ?? DEFAULT_CONFIG.streaming,
|
|
71
|
+
contextWindow: numberEnv("DEEPCCC_CONTEXT_WINDOW") ?? file.contextWindow ?? DEFAULT_CONFIG.contextWindow,
|
|
70
72
|
rawStreamLogs: {
|
|
71
73
|
enabled: boolEnv("DEEPCCC_RAW_STREAM_LOGS") ?? rawLogs.enabled ?? DEFAULT_CONFIG.rawStreamLogs.enabled,
|
|
72
74
|
maxBytesPerTurn: numberEnv("DEEPCCC_RAW_STREAM_MAX_BYTES") ?? rawLogs.maxBytesPerTurn ?? DEFAULT_CONFIG.rawStreamLogs.maxBytesPerTurn,
|
package/dist/context.d.ts
CHANGED
|
@@ -48,11 +48,19 @@ export interface BuiltinContextOptions {
|
|
|
48
48
|
contextDir?: string;
|
|
49
49
|
sessionId?: string;
|
|
50
50
|
cwd?: string;
|
|
51
|
+
/** 模型上下文窗口(token)。缺省时压缩阈值 = contextWindow × 0.8。 */
|
|
52
|
+
contextWindow?: number;
|
|
53
|
+
/** 直接指定压缩阈值(token),优先于 contextWindow 的 80% 派生。 */
|
|
51
54
|
compactAtTokens?: number;
|
|
52
55
|
keepRecentMessages?: number;
|
|
53
56
|
}
|
|
54
57
|
export declare const DEFAULT_BUILTIN_CONTEXT_DIR: string;
|
|
55
|
-
|
|
58
|
+
/** 默认模型上下文窗口:1M(DeepSeek V4 Pro/Flash 原生规格)。 */
|
|
59
|
+
export declare const DEFAULT_CONTEXT_WINDOW_TOKENS = 1048576;
|
|
60
|
+
/** 压缩阈值 = 窗口 × 0.8(业界惯例:在窗口接近上限前主动压缩,留出安全余量)。 */
|
|
61
|
+
export declare const COMPACTION_THRESHOLD_RATIO = 0.8;
|
|
62
|
+
/** 默认压缩阈值 = 1M × 0.8。 */
|
|
63
|
+
export declare const DEFAULT_COMPACT_AT_TOKENS: number;
|
|
56
64
|
export declare const DEFAULT_KEEP_RECENT_MESSAGES = 16;
|
|
57
65
|
export declare function normalizeBuiltinSessionId(value: string): string;
|
|
58
66
|
export declare function defaultBuiltinSessionId(cwd?: string): string;
|
package/dist/context.js
CHANGED
|
@@ -3,7 +3,12 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFile
|
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
export const DEFAULT_BUILTIN_CONTEXT_DIR = join(homedir(), ".deepccc", "sessions");
|
|
6
|
-
|
|
6
|
+
/** 默认模型上下文窗口:1M(DeepSeek V4 Pro/Flash 原生规格)。 */
|
|
7
|
+
export const DEFAULT_CONTEXT_WINDOW_TOKENS = 1_048_576;
|
|
8
|
+
/** 压缩阈值 = 窗口 × 0.8(业界惯例:在窗口接近上限前主动压缩,留出安全余量)。 */
|
|
9
|
+
export const COMPACTION_THRESHOLD_RATIO = 0.8;
|
|
10
|
+
/** 默认压缩阈值 = 1M × 0.8。 */
|
|
11
|
+
export const DEFAULT_COMPACT_AT_TOKENS = Math.floor(DEFAULT_CONTEXT_WINDOW_TOKENS * COMPACTION_THRESHOLD_RATIO);
|
|
7
12
|
export const DEFAULT_KEEP_RECENT_MESSAGES = 16;
|
|
8
13
|
const RECENT_CONTEXT_BUDGET_RATIO = 0.6;
|
|
9
14
|
const MAX_COMPACTION_SUMMARY_CHARS = 8_000;
|
|
@@ -247,7 +252,8 @@ export class BuiltinContextManager {
|
|
|
247
252
|
this.contextDir = options.contextDir ?? DEFAULT_BUILTIN_CONTEXT_DIR;
|
|
248
253
|
this.sessionId = normalizeBuiltinSessionId(options.sessionId ?? defaultBuiltinSessionId());
|
|
249
254
|
this.cwd = options.cwd;
|
|
250
|
-
this.compactAtTokens = options.compactAtTokens
|
|
255
|
+
this.compactAtTokens = options.compactAtTokens
|
|
256
|
+
?? Math.floor((options.contextWindow ?? DEFAULT_CONTEXT_WINDOW_TOKENS) * COMPACTION_THRESHOLD_RATIO);
|
|
251
257
|
this.keepRecentMessages = Math.max(1, options.keepRecentMessages ?? DEFAULT_KEEP_RECENT_MESSAGES);
|
|
252
258
|
this.state = this.load();
|
|
253
259
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,11 @@ export interface ChatSessionOptions {
|
|
|
47
47
|
sessionId?: string;
|
|
48
48
|
/** Compact older context when the rough token estimate exceeds this value. */
|
|
49
49
|
compactAtTokens?: number;
|
|
50
|
+
/**
|
|
51
|
+
* 模型上下文窗口(token),默认 1048576(1M)。压缩阈值自动 = contextWindow × 0.8;
|
|
52
|
+
* 显式 compactAtTokens 优先于该派生值。
|
|
53
|
+
*/
|
|
54
|
+
contextWindow?: number;
|
|
50
55
|
/** Number of recent raw messages retained after compaction. */
|
|
51
56
|
keepRecentMessages?: number;
|
|
52
57
|
/** Hard deadline for all context-compaction passes in one turn. */
|
package/dist/index.js
CHANGED
|
@@ -61,13 +61,16 @@ const SUMMARY_SYSTEM_PROMPT = [
|
|
|
61
61
|
/**
|
|
62
62
|
* 压缩后注入的恢复提示(lead-in,对齐业界 Codex 的 post-compaction lead-in 思路):
|
|
63
63
|
* 只要会话发生过压缩(存在摘要),就在摘要后告知模型可用 session_search 找回原文。
|
|
64
|
-
*
|
|
65
|
-
*
|
|
64
|
+
* 提示动态携带当前会话 ID:模型可优先用 session_id 限定只搜当前会话,
|
|
65
|
+
* 未命中时也可省略 session_id 退化全库检索。这样模型在后续每一轮都知道
|
|
66
|
+
* "较早消息已压缩、原文可检索",而不是把恢复完全外包给模型的自发判断。
|
|
66
67
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
function buildCompactionRecoveryHint(sessionId) {
|
|
69
|
+
return [
|
|
70
|
+
"[系统提示] 本会话较早的消息已压缩为摘要。当前会话 ID:" + sessionId + "。",
|
|
71
|
+
`如需找回被压缩消息的精确原文,优先调用 session_search 工具并设置 session_id="${sessionId}"(仅检索当前会话);若未命中,可省略 session_id 做全库检索(较慢)。检索时请设置 include_raw_logs=true 以扫描本地 gzip 原始流日志。`,
|
|
72
|
+
].join("\n");
|
|
73
|
+
}
|
|
71
74
|
const COMPACTION_RECOVERY_HINT_DISABLED = [
|
|
72
75
|
"[系统提示] 本会话较早的消息已压缩为摘要,原始消息未保留(raw stream logs 已关闭)。",
|
|
73
76
|
].join("\n");
|
|
@@ -139,16 +142,18 @@ function addAnthropicToolJsonCompatibilityNote(messages) {
|
|
|
139
142
|
}
|
|
140
143
|
/**
|
|
141
144
|
* 压缩后恢复提示注入:只要会话存在摘要(即发生过压缩),就在摘要消息后追加
|
|
142
|
-
* 一条提示,告知模型可用 session_search
|
|
143
|
-
*
|
|
145
|
+
* 一条提示,告知模型可用 session_search 找回被压缩的原文。
|
|
146
|
+
* - raw stream logs 开启:提示携带当前会话 ID,优先 session_id 限定当前会话,
|
|
147
|
+
* 未命中时可省略 session_id 做全库检索;
|
|
148
|
+
* - raw stream logs 关闭:仅告知原文未保留,不给出误导性承诺。
|
|
144
149
|
*/
|
|
145
|
-
function maybeAppendCompactionRecoveryHint(messages, summary, rawLogsEnabled) {
|
|
150
|
+
function maybeAppendCompactionRecoveryHint(messages, summary, rawLogsEnabled, sessionId) {
|
|
146
151
|
if (!summary.trim())
|
|
147
152
|
return messages;
|
|
148
153
|
const summaryIndex = messages.findIndex((message) => message.role === "user" && message.content.startsWith("以下是更早的对话摘要"));
|
|
149
154
|
if (summaryIndex < 0)
|
|
150
155
|
return messages;
|
|
151
|
-
const hint = rawLogsEnabled ?
|
|
156
|
+
const hint = rawLogsEnabled ? buildCompactionRecoveryHint(sessionId) : COMPACTION_RECOVERY_HINT_DISABLED;
|
|
152
157
|
return messages.map((message, index) => (index === summaryIndex
|
|
153
158
|
? { ...message, content: `${message.content}\n\n${hint}` }
|
|
154
159
|
: message));
|
|
@@ -205,8 +210,10 @@ function normalizeMaxSteps(value) {
|
|
|
205
210
|
return value;
|
|
206
211
|
}
|
|
207
212
|
function normalizeAnthropicBaseURL(baseURL) {
|
|
208
|
-
|
|
209
|
-
|
|
213
|
+
// 完全按用户填写的地址使用,不自动补 /v1(AI SDK 仅对官方 api.anthropic.com
|
|
214
|
+
// 特判补一次 /v1,其他地址原样拼接 /messages)。
|
|
215
|
+
// DeepSeek Anthropic 端点示例:https://api.deepseek.com/anthropic/v1。
|
|
216
|
+
return baseURL.trim().replace(/\/+$/, "");
|
|
210
217
|
}
|
|
211
218
|
export class ChatSession {
|
|
212
219
|
model;
|
|
@@ -260,6 +267,7 @@ export class ChatSession {
|
|
|
260
267
|
contextDir: options.contextDir,
|
|
261
268
|
sessionId: options.sessionId ?? defaultBuiltinSessionId(this.cwd),
|
|
262
269
|
cwd: this.cwd,
|
|
270
|
+
contextWindow: options.contextWindow ?? appConfig.contextWindow,
|
|
263
271
|
compactAtTokens: options.compactAtTokens,
|
|
264
272
|
keepRecentMessages: options.keepRecentMessages,
|
|
265
273
|
});
|
|
@@ -333,7 +341,7 @@ export class ChatSession {
|
|
|
333
341
|
const system = this.buildSystemPrompt(skills);
|
|
334
342
|
this.systemPrompt = system;
|
|
335
343
|
const contextMessages = this.context.buildModelMessages();
|
|
336
|
-
const hintedMessages = maybeAppendCompactionRecoveryHint(contextMessages, this.context.summary, appConfig.rawStreamLogs.enabled);
|
|
344
|
+
const hintedMessages = maybeAppendCompactionRecoveryHint(contextMessages, this.context.summary, appConfig.rawStreamLogs.enabled, this.context.sessionId);
|
|
337
345
|
const modelMessages = this.provider === "anthropic"
|
|
338
346
|
? addAnthropicToolJsonCompatibilityNote(hintedMessages)
|
|
339
347
|
: hintedMessages;
|