deepccc 0.2.24 → 0.2.26

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,40 @@
1
+ # Caller-owned completions
2
+
3
+ `CompletionSession` is an opt-in stateless OpenAI-compatible transport. Pass the
4
+ entire `messages` array; no system guidance, workspace files, skills, tools,
5
+ history or compaction is injected. This is useful when comparing integrations
6
+ without rewriting their established prompt builders.
7
+
8
+ ```js
9
+ import {CompletionSession} from 'deepccc';
10
+ const session = new CompletionSession({
11
+ apiKey: process.env.DEEPCCC_API_KEY,
12
+ baseURL: process.env.DEEPCCC_BASE_URL,
13
+ model: process.env.DEEPCCC_MODEL,
14
+ });
15
+ const result = await session.complete({
16
+ messages: [{role: 'system', content: 'Return JSON only.'},
17
+ {role: 'user', content: 'Return an object with ok=true.'}],
18
+ json: true, timeoutMs: 5000, maxOutputTokens: 256, temperature: 0.1,
19
+ });
20
+ if (result.status === 'success') console.log(result.content);
21
+ ```
22
+
23
+ JSON mode sends `response_format: {type: 'json_object'}`; callers still parse,
24
+ validate and authorize results. No local syntax repair or automatic retry is
25
+ performed here. Completion is accepted only after a normal stop, never a length
26
+ limit or interrupted stream. Text mode preserves plain-text output. Parallel
27
+ calls do not share mutable history. `timeoutMs` covers stream consumption;
28
+ optional cancellation is the second argument. Context/response character limits
29
+ default to one million each. Oversize input and invalid options throw before
30
+ network activity; runtime failures return fixed diagnostics without raw errors.
31
+
32
+ JSON responses are collected as text without constructing partial objects for
33
+ each streamed fragment. This avoids unnecessary parsing and allocation for large
34
+ responses. Ordinary ChatSession, CLI and Web streaming behavior is unchanged.
35
+
36
+ Optional `extensions` passes caller-supplied provider-specific JSON options.
37
+ It cannot override messages, model, streaming, tool settings, response format,
38
+ temperature or token limits. Keep credentials in config, not extensions. No
39
+ messages, headers or generated content are logged or persisted by this class.
40
+ Metrics include duration and request count. Remote cancellation is best effort.
@@ -1,192 +1,196 @@
1
- # Bounded structured decisions
2
-
3
- `DecisionSession` is an opt-in, programmatic, text-only API for integrations that
4
- own their state and need a bounded decision loop. Existing `ChatSession`, CLI and
5
- Web behavior is unchanged. The model client is reusable, but each `decide()` call
6
- starts with exactly the supplied context. No conversation history, workspace
7
- instructions, global skills, file tools, model-based compaction or raw stream
8
- logging is loaded automatically.
9
-
10
- This is not a simulator, a game-specific policy or a guarantee of model latency.
11
- Use an adapter to provide observations, validate decisions against current state,
12
- and execute actions. Keep application knowledge and private data outside the
13
- package. Read any skill references at application setup, then pass the relevant
14
- instructions through `systemPrompt`.
15
-
16
- ## Minimal integration
17
-
18
- ```js
19
- import { DecisionSession } from 'deepccc';
20
- import { jsonSchema } from 'ai';
21
-
22
- const outputSchema = jsonSchema({
23
- type: 'object',
24
- properties: { action: { type: 'string', enum: ['left', 'right', 'wait'] } },
25
- required: ['action'],
26
- additionalProperties: false,
27
- }, {
28
- validate(value) {
29
- if (value && typeof value === 'object' && !Array.isArray(value)
30
- && Object.keys(value).length === 1
31
- && ['left', 'right', 'wait'].includes(value.action)) {
32
- return { success: true, value };
33
- }
34
- return { success: false, error: new Error('Invalid decision') };
35
- },
36
- });
37
-
38
- const session = new DecisionSession({
39
- model: process.env.DEEPCCC_MODEL,
40
- effort: '', // Omit effort when the target service does not support it.
41
- maxOutputTokens: 2048,
42
- }, {
43
- systemPrompt: 'Choose a safe action toward the supplied goal. Unknown data stays unknown.',
44
- outputSchema,
45
- maxSteps: 1,
46
- maxContextChars: 32000,
47
- });
48
-
49
- const result = await session.decide({
50
- requestId: 'example-request-1',
51
- stateVersion: 3,
52
- timeoutMs: 5000,
53
- context: {
54
- observation: { position: 1, blocked: [0] },
55
- goal: { position: 4 },
56
- plan: null,
57
- memory: [],
58
- },
59
- });
60
-
61
- if (result.status === 'success') {
62
- // Re-check result.stateVersion and legality in the adapter before execution.
63
- console.log(result.value);
64
- } else {
65
- console.log(result.status); // Never execute partial text as an action.
66
- }
67
- ```
68
-
69
- The default Provider/model/credentials are resolved in the same way as
70
- `ChatSession`. This API always consumes a structured streaming response;
71
- `streaming` and `subModel` from ChatSession configuration are not decision options.
72
- There is no summarization call or hidden model switch.
73
-
74
- `outputSchema` and allowed tool input schemas **must contain runtime validators**.
75
- Use a Standard Schema supported by the AI SDK, or `jsonSchema(schema, {validate})`.
76
- A JSON schema alone describes the model contract but is not a runtime safety
77
- check, so the constructor rejects schemas without validators. Validators may be
78
- asynchronous and share the request deadline. The provider must support tool calls.
79
- The default `outputMode: 'tools'` uses the reserved `submit_result` tool; free-form
80
- JSON text is not accepted as an alternative in that mode.
81
-
82
- Since 0.2.24, `outputMode: 'json'` is available for OpenAI-compatible endpoints.
83
- It sends `response_format: {type: 'json_object'}` with no tools or tool choice;
84
- the schema is included in the system prompt and runtime validation is still
85
- mandatory. Nonempty `allowedTools` and other provider protocols are rejected in
86
- this mode. JSON syntax constraints do not guarantee semantic correctness.
87
- One local fallback removes trailing commas outside quoted strings, preserving
88
- values and escapes. Missing values, truncated streams, prose and invalid schemas
89
- are rejected; no extra model request is made for syntax recovery. Optional
90
- `metrics.jsonRepairs` counts repaired responses. Deadlines, cancellation, size
91
- limits, freshness checks and caller-owned context remain unchanged.
92
-
93
- ## Explicit capabilities
94
-
95
- Supply a `tools` record with `description`, `inputSchema` and `execute`, and list
96
- the capabilities to expose in `allowedTools`. Supplying a tool does **not** enable
97
- it. Both default to empty. Tool names must begin with a letter and use only
98
- letters, digits or underscores (at most 64 characters); `submit_result` is reserved.
99
-
100
- ```js
101
- const options = {
102
- systemPrompt: 'Inspect relevant information only when needed, then submit a result.',
103
- outputSchema,
104
- maxSteps: 2, // one inspection step plus one final submission
105
- maxToolCalls: 2,
106
- allowedTools: ['inspect_state'],
107
- tools: {
108
- inspect_state: {
109
- description: 'Return a compact observation for the supplied request.',
110
- inputSchema: jsonSchema({ type: 'object', additionalProperties: false }, {
111
- validate(value) {
112
- return value && typeof value === 'object' && !Array.isArray(value)
113
- && Object.keys(value).length === 0
114
- ? { success: true, value }
115
- : { success: false, error: new Error('Expected empty input') };
116
- },
117
- }),
118
- async execute(input, { signal, requestId, stateVersion }) {
119
- // Your adapter must honor signal and return a small JSON-serializable value.
120
- return adapter.observe({ signal, requestId, stateVersion });
121
- },
122
- },
123
- },
124
- };
125
- ```
126
-
127
- The entire model tool batch is checked before any tool runs. Unknown names,
128
- invalid inputs, duplicate call IDs and mixing a final submission with other
129
- calls fail closed. Tools execute sequentially and receive the same cancellation
130
- signal and request identity. They are not given to the SDK for automatic execution.
131
- The last permitted model step must submit a result; it cannot start more tools.
132
-
133
- Prefer observation-only capabilities. A tool allowlist is not an OS sandbox.
134
- Register trusted code only. Cancellation cannot undo effects of a tool that already
135
- started. Idempotency, freshness and actual execution acknowledgements are adapter
136
- responsibilities. Returned identity allows the adapter to reject stale decisions;
137
- the core does not know whether external state has changed.
138
-
139
- ## Budgets and results
140
-
141
- | Option | Default | Meaning |
142
- | --- | --- | --- |
143
- | request `timeoutMs` | Required | One wall-clock budget across generation, tools and validation |
144
- | `maxSteps` | 1 | Model requests, including final submission |
145
- | `maxToolCalls` | 4 | Total non-submission calls in a decision |
146
- | `maxContextChars` | 32000 | System prompt plus serialized messages |
147
- | `maxToolResultChars` | 8000 | Each serialized observation |
148
- | `maxResponseChars` | 32000 | Bounded streamed text/tool data; may count tool arguments twice |
149
- | model `maxOutputTokens` | Configured value, otherwise 2048 | Per-request provider output budget, including reasoning where applicable |
150
-
151
- Character budgets are protective size limits, not token estimates. Oversized
152
- state/results fail with `context_limit`; they are never silently truncated or
153
- summarized. Keep raw logs outside decision context. Assemble the latest state,
154
- active plan and selected evidence before calling the API. Background summaries
155
- should produce versioned memory snapshots rather than mutate an in-flight request.
156
-
157
- `success` is the only status carrying a validated `value`. Other statuses are
158
- `timed_out`, `cancelled`, `invalid_output`, `step_limit`, `tool_error`,
159
- `context_limit` and `error`. Metrics report total/model/tool milliseconds, model
160
- and tool call counts, and the last assembled context size. Provider/tool error
161
- payloads and partial generated content are not copied into result messages.
162
- Invalid configuration/request budgets throw before contacting the provider.
163
-
164
- Since 0.2.23, failures also include a safe `diagnostic` object with a fixed `code`
165
- and `stage`. Categories distinguish provider errors, invalid tool input, result
166
- schema failures, truncated output, interrupted output, deadlines and cancellation.
167
- Provider HTTP status is included when available, but error messages, raw tool
168
- arguments, prompts, headers and response bodies are never copied into diagnostics.
169
- The SDK's default raw error logging is disabled for this API. Integrations can
170
- record their own schema issue paths inside their validators; keep values and raw
171
- payloads out of those records. The original `status` remains the control-flow
172
- contract. Diagnostics do not relax validation or trigger automatic retries.
173
-
174
- Pass an optional `AbortSignal` as the second argument to `decide()`. Provider SDK
175
- automatic retries are disabled; any future application retry needs a fresh,
176
- explicit budget. Non-cooperative asynchronous tools/streams are raced against
177
- cancellation, and late results do not continue the decision loop. Cleanup is
178
- best-effort; it cannot guarantee remote inference billing stops or an external
179
- side effect is rolled back. Synchronous code that blocks the Node event loop
180
- cannot be preempted by a JavaScript timer: use a worker/process for heavy work.
181
-
182
- A deadline bounds waiting, not the probability of receiving a good result.
183
- Measure valid-result rate, median/p95 decision latency and application outcomes
184
- on the actual endpoint. Do not count a timeout as a fast successful decision.
185
-
186
- ## Release checks
187
-
188
- Tests use synthetic states and a loopback model endpoint, never production data.
189
- For publication, inspect staged changes, outgoing commits and the actual packed
190
- archive (including compiled output), and review public PR/release text. Never put
191
- credentials, private endpoints, proprietary assets or application traces into
192
- examples, tests, documentation or package files.
1
+ # Bounded structured decisions
2
+
3
+ `DecisionSession` is an opt-in, programmatic, text-only API for integrations that
4
+ own their state and need a bounded decision loop. Existing `ChatSession`, CLI and
5
+ Web behavior is unchanged. The model client is reusable, but each `decide()` call
6
+ starts with exactly the supplied context. No conversation history, workspace
7
+ instructions, global skills, file tools, model-based compaction or raw stream
8
+ logging is loaded automatically.
9
+
10
+ This is not a simulator, a game-specific policy or a guarantee of model latency.
11
+ Use an adapter to provide observations, validate decisions against current state,
12
+ and execute actions. Keep application knowledge and private data outside the
13
+ package. Read any skill references at application setup, then pass the relevant
14
+ instructions through `systemPrompt`.
15
+
16
+ ## Minimal integration
17
+
18
+ ```js
19
+ import { DecisionSession } from 'deepccc';
20
+ import { jsonSchema } from 'ai';
21
+
22
+ const outputSchema = jsonSchema({
23
+ type: 'object',
24
+ properties: { action: { type: 'string', enum: ['left', 'right', 'wait'] } },
25
+ required: ['action'],
26
+ additionalProperties: false,
27
+ }, {
28
+ validate(value) {
29
+ if (value && typeof value === 'object' && !Array.isArray(value)
30
+ && Object.keys(value).length === 1
31
+ && ['left', 'right', 'wait'].includes(value.action)) {
32
+ return { success: true, value };
33
+ }
34
+ return { success: false, error: new Error('Invalid decision') };
35
+ },
36
+ });
37
+
38
+ const session = new DecisionSession({
39
+ model: process.env.DEEPCCC_MODEL,
40
+ effort: '', // Omit effort when the target service does not support it.
41
+ maxOutputTokens: 2048,
42
+ }, {
43
+ systemPrompt: 'Choose a safe action toward the supplied goal. Unknown data stays unknown.',
44
+ outputSchema,
45
+ maxSteps: 1,
46
+ maxContextChars: 32000,
47
+ });
48
+
49
+ const result = await session.decide({
50
+ requestId: 'example-request-1',
51
+ stateVersion: 3,
52
+ timeoutMs: 5000,
53
+ context: {
54
+ observation: { position: 1, blocked: [0] },
55
+ goal: { position: 4 },
56
+ plan: null,
57
+ memory: [],
58
+ },
59
+ });
60
+
61
+ if (result.status === 'success') {
62
+ // Re-check result.stateVersion and legality in the adapter before execution.
63
+ console.log(result.value);
64
+ } else {
65
+ console.log(result.status); // Never execute partial text as an action.
66
+ }
67
+ ```
68
+
69
+ The default Provider/model/credentials are resolved in the same way as
70
+ `ChatSession`. This API always consumes a structured streaming response;
71
+ `streaming` and `subModel` from ChatSession configuration are not decision options.
72
+ There is no summarization call or hidden model switch.
73
+
74
+ `outputSchema` and allowed tool input schemas **must contain runtime validators**.
75
+ Use a Standard Schema supported by the AI SDK, or `jsonSchema(schema, {validate})`.
76
+ A JSON schema alone describes the model contract but is not a runtime safety
77
+ check, so the constructor rejects schemas without validators. Validators may be
78
+ asynchronous and share the request deadline. The provider must support tool calls.
79
+ The default `outputMode: 'tools'` uses the reserved `submit_result` tool; free-form
80
+ JSON text is not accepted as an alternative in that mode.
81
+
82
+ Since 0.2.24, `outputMode: 'json'` is available for OpenAI-compatible endpoints.
83
+ It sends `response_format: {type: 'json_object'}` with no tools or tool choice;
84
+ the schema is included in the system prompt and runtime validation is still
85
+ mandatory. Nonempty `allowedTools` and other provider protocols are rejected in
86
+ this mode. JSON syntax constraints do not guarantee semantic correctness.
87
+ One local fallback removes trailing commas outside quoted strings, preserving
88
+ values and escapes. Missing values, truncated streams, prose and invalid schemas
89
+ are rejected; no extra model request is made for syntax recovery. Optional
90
+ `metrics.jsonRepairs` counts repaired responses. Deadlines, cancellation, size
91
+ limits, freshness checks and caller-owned context remain unchanged.
92
+
93
+ JSON mode collects streamed text and parses the completed response once, rather
94
+ than constructing intermediate partial objects. Final syntax recovery and schema
95
+ validation remain mandatory. Tools mode and ordinary ChatSession are unchanged.
96
+
97
+ ## Explicit capabilities
98
+
99
+ Supply a `tools` record with `description`, `inputSchema` and `execute`, and list
100
+ the capabilities to expose in `allowedTools`. Supplying a tool does **not** enable
101
+ it. Both default to empty. Tool names must begin with a letter and use only
102
+ letters, digits or underscores (at most 64 characters); `submit_result` is reserved.
103
+
104
+ ```js
105
+ const options = {
106
+ systemPrompt: 'Inspect relevant information only when needed, then submit a result.',
107
+ outputSchema,
108
+ maxSteps: 2, // one inspection step plus one final submission
109
+ maxToolCalls: 2,
110
+ allowedTools: ['inspect_state'],
111
+ tools: {
112
+ inspect_state: {
113
+ description: 'Return a compact observation for the supplied request.',
114
+ inputSchema: jsonSchema({ type: 'object', additionalProperties: false }, {
115
+ validate(value) {
116
+ return value && typeof value === 'object' && !Array.isArray(value)
117
+ && Object.keys(value).length === 0
118
+ ? { success: true, value }
119
+ : { success: false, error: new Error('Expected empty input') };
120
+ },
121
+ }),
122
+ async execute(input, { signal, requestId, stateVersion }) {
123
+ // Your adapter must honor signal and return a small JSON-serializable value.
124
+ return adapter.observe({ signal, requestId, stateVersion });
125
+ },
126
+ },
127
+ },
128
+ };
129
+ ```
130
+
131
+ The entire model tool batch is checked before any tool runs. Unknown names,
132
+ invalid inputs, duplicate call IDs and mixing a final submission with other
133
+ calls fail closed. Tools execute sequentially and receive the same cancellation
134
+ signal and request identity. They are not given to the SDK for automatic execution.
135
+ The last permitted model step must submit a result; it cannot start more tools.
136
+
137
+ Prefer observation-only capabilities. A tool allowlist is not an OS sandbox.
138
+ Register trusted code only. Cancellation cannot undo effects of a tool that already
139
+ started. Idempotency, freshness and actual execution acknowledgements are adapter
140
+ responsibilities. Returned identity allows the adapter to reject stale decisions;
141
+ the core does not know whether external state has changed.
142
+
143
+ ## Budgets and results
144
+
145
+ | Option | Default | Meaning |
146
+ | --- | --- | --- |
147
+ | request `timeoutMs` | Required | One wall-clock budget across generation, tools and validation |
148
+ | `maxSteps` | 1 | Model requests, including final submission |
149
+ | `maxToolCalls` | 4 | Total non-submission calls in a decision |
150
+ | `maxContextChars` | 32000 | System prompt plus serialized messages |
151
+ | `maxToolResultChars` | 8000 | Each serialized observation |
152
+ | `maxResponseChars` | 32000 | Bounded streamed text/tool data; may count tool arguments twice |
153
+ | model `maxOutputTokens` | Configured value, otherwise 2048 | Per-request provider output budget, including reasoning where applicable |
154
+
155
+ Character budgets are protective size limits, not token estimates. Oversized
156
+ state/results fail with `context_limit`; they are never silently truncated or
157
+ summarized. Keep raw logs outside decision context. Assemble the latest state,
158
+ active plan and selected evidence before calling the API. Background summaries
159
+ should produce versioned memory snapshots rather than mutate an in-flight request.
160
+
161
+ `success` is the only status carrying a validated `value`. Other statuses are
162
+ `timed_out`, `cancelled`, `invalid_output`, `step_limit`, `tool_error`,
163
+ `context_limit` and `error`. Metrics report total/model/tool milliseconds, model
164
+ and tool call counts, and the last assembled context size. Provider/tool error
165
+ payloads and partial generated content are not copied into result messages.
166
+ Invalid configuration/request budgets throw before contacting the provider.
167
+
168
+ Since 0.2.23, failures also include a safe `diagnostic` object with a fixed `code`
169
+ and `stage`. Categories distinguish provider errors, invalid tool input, result
170
+ schema failures, truncated output, interrupted output, deadlines and cancellation.
171
+ Provider HTTP status is included when available, but error messages, raw tool
172
+ arguments, prompts, headers and response bodies are never copied into diagnostics.
173
+ The SDK's default raw error logging is disabled for this API. Integrations can
174
+ record their own schema issue paths inside their validators; keep values and raw
175
+ payloads out of those records. The original `status` remains the control-flow
176
+ contract. Diagnostics do not relax validation or trigger automatic retries.
177
+
178
+ Pass an optional `AbortSignal` as the second argument to `decide()`. Provider SDK
179
+ automatic retries are disabled; any future application retry needs a fresh,
180
+ explicit budget. Non-cooperative asynchronous tools/streams are raced against
181
+ cancellation, and late results do not continue the decision loop. Cleanup is
182
+ best-effort; it cannot guarantee remote inference billing stops or an external
183
+ side effect is rolled back. Synchronous code that blocks the Node event loop
184
+ cannot be preempted by a JavaScript timer: use a worker/process for heavy work.
185
+
186
+ A deadline bounds waiting, not the probability of receiving a good result.
187
+ Measure valid-result rate, median/p95 decision latency and application outcomes
188
+ on the actual endpoint. Do not count a timeout as a fast successful decision.
189
+
190
+ ## Release checks
191
+
192
+ Tests use synthetic states and a loopback model endpoint, never production data.
193
+ For publication, inspect staged changes, outgoing commits and the actual packed
194
+ archive (including compiled output), and review public PR/release text. Never put
195
+ credentials, private endpoints, proprietary assets or application traces into
196
+ examples, tests, documentation or package files.
@@ -1,41 +1,41 @@
1
- # 项目理解与搜索
2
-
3
- DeepCCC CLI、Web 与 ChatCCC 内置 CCC 共用这些能力。无需配置向量服务、下载模型或修改项目指令文件;地图与证据保存在本机 `~/.deepccc/workspace-index/<工作目录哈希>/`。不在不同工作目录间自动合并知识(包括 worktree)。选入上下文的片段仍会随正常模型请求发送给用户配置的模型服务;“本地索引”不意味着模型请求离线。
4
-
5
- ## 搜索范围不是权限边界
6
-
7
- - `search_code({query: "Policy"})`:默认 `project`,跳过常见依赖/构建目录及隐藏条目;ripgrep 还遵循 ignore 文件。
8
- - `search_code({query: "Policy", scope: "all"})`:包含依赖、隐藏及被忽略文件。不自动跟随目录符号链接,也不提升操作系统权限。
9
- - `search_code({query: "forward", path: ".venv/Lib/site-packages/example"})`:指定非工作目录根的路径时,缺省按 `all` 搜索。调用者可显式选择 `project`。
10
- - `scope`、`excluded`、`engine`、`warnings`、`truncated` 描述实际查询边界。无命中不证明项目中不存在相关能力。
11
- - Node 降级搜索支持相同的 project/all 范围切换,但不解析 `.gitignore`/`.ignore`,会明确返回警告;正则为 JavaScript 语法。正常路径优先使用内置 ripgrep,不拼接 shell 命令。
12
-
13
- 明确指定文件时保留文件名输出,避免单文件命中被解析器丢弃。无效正则、超时、取消等不会伪装成正常无命中;降级路径跳过不可读条目时返回警告。
14
-
15
- ## 有限预算的项目地图
16
-
17
- `workspace_map({query: "Policy", path: "可选目录", maxChars: 6000})` 提供文件清单、部分定义/导入/文档标题线索和证据笔记。支持 TS/JS、Python、Go、Rust、Java、C#、C/C++、Ruby、PHP 等文本线索;其他文件仍可按名称发现并用读取/搜索工具检查。
18
-
19
- 这是**词法导航,不是 AST、完整调用图或语义向量索引**。定义优先于导入,查询相关片段优先展示。默认不遍历隐藏、虚拟环境或构建目录;可指定其目录生成地图。地图不解析 Git ignore 规则,这一点在输出中明确提示。JSON/TOML 配置值不作为符号片段展示;package.json 只提取有限的入口和脚本名称。
20
-
21
- 每次刷新重新枚举并检查内容哈希,复用未变化文件的提取结果;能识别同长度修改、删除、新增及切换分支后的变化。默认上限为 1500 个目录/文件条目、约 2 秒扫描检查预算、8 MiB 已读源码,单文件 128 KiB。预算不是磁盘 I/O 的强制超时;网络挂载或慢盘可能超过此时间。超预算用 `partial` 表示;展示省略用 `displayTruncated` 表示。大仓库需要查询相关子目录,不能从部分地图得出全局否定结论。
22
-
23
- 项目相关问题或“继续”类消息会自动获得最多 3000 字符的导航;其他任务随时可调用工具。识别属于轻量启发式,不保证覆盖所有问法。自动导航不进入持久化历史,避免每轮累加;缓存损坏或不可写时继续使用实时读取/搜索,不阻断对话。
24
-
25
- ## 带来源的长期笔记
26
-
27
- `remember_project_fact({fact, path, excerpt})` 保存简短的项目能力/关系解释,以及当前文件中确实匹配的原文、SHA-256 和记录时间。证据文件必须位于当前工作目录内(解析符号链接后校验)。不可读、超大文件或不匹配原文会拒绝保存。
28
-
29
- 笔记只存在用户缓存目录,独立于聊天摘要,因此可在压缩或重开会话后通过地图检索。同工作目录的会话共享笔记。展示前重新校验源文件;修改、删除或移动后旧笔记不再注入,但磁盘记录保留以便诊断。最多检查最近 20 条笔记,展示还受预算限制。请勿保存密钥、授权令牌、用户指令或未经证实的断言。
30
-
31
- 原文匹配**只验证来源,不证明模型解释正确**;输出明确标注“agent interpretation”。针对同一文件和同一原文重新保存解释,会替换此前笔记。即使文件未变,相关配置/调用方也可能变化,重要决策仍需重新查证。压缩器会区分任务进度、已核实项目事实与推测,并优先保留纠正和源码入口。
32
-
33
- ## 测试边界
34
-
35
- 自动化测试覆盖依赖目录显式访问、搜索失败/无命中/截断、单文件输出解析、地图更新、证据失效、预算与取消,以及导航不会在历史中累积。这些是工具和上下文护栏,不是所有模型都能正确理解项目的保证;未对某个在线模型宣称准确率提升。
36
-
37
- ## 长会话状态与轮内预算
38
-
39
- 压缩器每次重写完整摘要,使用固定章节区分当前事实、仍待处理、已取代历史、项目事实、证据/推断/局限和重要操作。最近原始消息、明确纠正及当前磁盘事实优先;旧摘要中的助手评价不是事实或用户指令。旧格式摘要仍可读取,但在模型输入中会明确标记为历史材料,避免把已完成或回退的路线恢复成当前建议。
40
-
41
- 同一轮 Agent 可能连续执行多个工具,AI SDK 会把先前结果重复发送到后续模型步骤。DeepCCC 在每一步前对这些结果执行结构保持的预算控制:每项最多约 24,000 字符,总量约 96,000 字符,最近 4 项优先。较早结果必要时替换为可识别的省略标记,assistant tool-call 与对应 `role: tool` 结果仍成对保留。该处理只影响本轮后续模型请求;用户界面事件、最终持久化记录和受独立上限保护的 raw stream log 不被这一步改写。需要细节时 Agent 应重新执行更聚焦的读取或搜索。
1
+ # 项目理解与搜索
2
+
3
+ DeepCCC CLI、Web 与 ChatCCC 内置 CCC 共用这些能力。无需配置向量服务、下载模型或修改项目指令文件;地图与证据保存在本机 `~/.deepccc/workspace-index/<工作目录哈希>/`。不在不同工作目录间自动合并知识(包括 worktree)。选入上下文的片段仍会随正常模型请求发送给用户配置的模型服务;“本地索引”不意味着模型请求离线。
4
+
5
+ ## 搜索范围不是权限边界
6
+
7
+ - `search_code({query: "Policy"})`:默认 `project`,跳过常见依赖/构建目录及隐藏条目;ripgrep 还遵循 ignore 文件。
8
+ - `search_code({query: "Policy", scope: "all"})`:包含依赖、隐藏及被忽略文件。不自动跟随目录符号链接,也不提升操作系统权限。
9
+ - `search_code({query: "forward", path: ".venv/Lib/site-packages/example"})`:指定非工作目录根的路径时,缺省按 `all` 搜索。调用者可显式选择 `project`。
10
+ - `scope`、`excluded`、`engine`、`warnings`、`truncated` 描述实际查询边界。无命中不证明项目中不存在相关能力。
11
+ - Node 降级搜索支持相同的 project/all 范围切换,但不解析 `.gitignore`/`.ignore`,会明确返回警告;正则为 JavaScript 语法。正常路径优先使用内置 ripgrep,不拼接 shell 命令。
12
+
13
+ 明确指定文件时保留文件名输出,避免单文件命中被解析器丢弃。无效正则、超时、取消等不会伪装成正常无命中;降级路径跳过不可读条目时返回警告。
14
+
15
+ ## 有限预算的项目地图
16
+
17
+ `workspace_map({query: "Policy", path: "可选目录", maxChars: 6000})` 提供文件清单、部分定义/导入/文档标题线索和证据笔记。支持 TS/JS、Python、Go、Rust、Java、C#、C/C++、Ruby、PHP 等文本线索;其他文件仍可按名称发现并用读取/搜索工具检查。
18
+
19
+ 这是**词法导航,不是 AST、完整调用图或语义向量索引**。定义优先于导入,查询相关片段优先展示。默认不遍历隐藏、虚拟环境或构建目录;可指定其目录生成地图。地图不解析 Git ignore 规则,这一点在输出中明确提示。JSON/TOML 配置值不作为符号片段展示;package.json 只提取有限的入口和脚本名称。
20
+
21
+ 每次刷新重新枚举并检查内容哈希,复用未变化文件的提取结果;能识别同长度修改、删除、新增及切换分支后的变化。默认上限为 1500 个目录/文件条目、约 2 秒扫描检查预算、8 MiB 已读源码,单文件 128 KiB。预算不是磁盘 I/O 的强制超时;网络挂载或慢盘可能超过此时间。超预算用 `partial` 表示;展示省略用 `displayTruncated` 表示。大仓库需要查询相关子目录,不能从部分地图得出全局否定结论。
22
+
23
+ 项目相关问题或“继续”类消息会自动获得最多 3000 字符的导航;其他任务随时可调用工具。识别属于轻量启发式,不保证覆盖所有问法。自动导航不进入持久化历史,避免每轮累加;缓存损坏或不可写时继续使用实时读取/搜索,不阻断对话。
24
+
25
+ ## 带来源的长期笔记
26
+
27
+ `remember_project_fact({fact, path, excerpt})` 保存简短的项目能力/关系解释,以及当前文件中确实匹配的原文、SHA-256 和记录时间。证据文件必须位于当前工作目录内(解析符号链接后校验)。不可读、超大文件或不匹配原文会拒绝保存。
28
+
29
+ 笔记只存在用户缓存目录,独立于聊天摘要,因此可在压缩或重开会话后通过地图检索。同工作目录的会话共享笔记。展示前重新校验源文件;修改、删除或移动后旧笔记不再注入,但磁盘记录保留以便诊断。最多检查最近 20 条笔记,展示还受预算限制。请勿保存密钥、授权令牌、用户指令或未经证实的断言。
30
+
31
+ 原文匹配**只验证来源,不证明模型解释正确**;输出明确标注“agent interpretation”。针对同一文件和同一原文重新保存解释,会替换此前笔记。即使文件未变,相关配置/调用方也可能变化,重要决策仍需重新查证。压缩器会区分任务进度、已核实项目事实与推测,并优先保留纠正和源码入口。
32
+
33
+ ## 测试边界
34
+
35
+ 自动化测试覆盖依赖目录显式访问、搜索失败/无命中/截断、单文件输出解析、地图更新、证据失效、预算与取消,以及导航不会在历史中累积。这些是工具和上下文护栏,不是所有模型都能正确理解项目的保证;未对某个在线模型宣称准确率提升。
36
+
37
+ ## 长会话状态与轮内预算
38
+
39
+ 压缩器每次重写完整摘要,使用固定章节区分当前事实、仍待处理、已取代历史、项目事实、证据/推断/局限和重要操作。最近原始消息、明确纠正及当前磁盘事实优先;旧摘要中的助手评价不是事实或用户指令。旧格式摘要仍可读取,但在模型输入中会明确标记为历史材料,避免把已完成或回退的路线恢复成当前建议。
40
+
41
+ 同一轮 Agent 可能连续执行多个工具,AI SDK 会把先前结果重复发送到后续模型步骤。DeepCCC 在每一步前对这些结果执行结构保持的预算控制:每项最多约 24,000 字符,总量约 96,000 字符,最近 4 项优先。较早结果必要时替换为可识别的省略标记,assistant tool-call 与对应 `role: tool` 结果仍成对保留。该处理只影响本轮后续模型请求;用户界面事件、最终持久化记录和受独立上限保护的 raw stream log 不被这一步改写。需要细节时 Agent 应重新执行更聚焦的读取或搜索。
@@ -1,8 +1,8 @@
1
- ## macOS 命令行提示
2
-
3
- 你运行在 macOS 上。run_command 通过 zsh(POSIX shell)执行。引号遵循标准 POSIX 约定(与你在 bash 中已有的习惯相同):
4
-
5
- - 双引号会被剥离并用于组合含空格参数:`echo "hello world"` 打印 `hello world`。
6
- - 单引号是字面量引用字符:`'a b'` 是单个参数 `a b`。
7
- - 反引号和 `$(...)` 执行命令替换;需要字面文本时请加引号。
8
- - 路径使用 `/` 分隔符,`~` 展开为主目录。
1
+ ## macOS 命令行提示
2
+
3
+ 你运行在 macOS 上。run_command 通过 zsh(POSIX shell)执行。引号遵循标准 POSIX 约定(与你在 bash 中已有的习惯相同):
4
+
5
+ - 双引号会被剥离并用于组合含空格参数:`echo "hello world"` 打印 `hello world`。
6
+ - 单引号是字面量引用字符:`'a b'` 是单个参数 `a b`。
7
+ - 反引号和 `$(...)` 执行命令替换;需要字面文本时请加引号。
8
+ - 路径使用 `/` 分隔符,`~` 展开为主目录。
@@ -1,8 +1,8 @@
1
- ## Linux 命令行提示
2
-
3
- 你运行在 Linux 上。run_command 通过 POSIX shell(bash/sh)执行。引语遵循标准 POSIX 约定(与你在 bash 中已有的习惯相同):
4
-
5
- - 双引号会被剥离并用于组合含空格参数:`echo "hello world"` 打印 `hello world`。
6
- - 单引号是字面量引用字符:`'a b'` 是单个参数 `a b`。
7
- - 反引号和 `$(...)` 执行命令替换;需要字面文本时请加引号。
8
- - 路径使用 `/` 分隔符,`~` 展开为主目录。
1
+ ## Linux 命令行提示
2
+
3
+ 你运行在 Linux 上。run_command 通过 POSIX shell(bash/sh)执行。引语遵循标准 POSIX 约定(与你在 bash 中已有的习惯相同):
4
+
5
+ - 双引号会被剥离并用于组合含空格参数:`echo "hello world"` 打印 `hello world`。
6
+ - 单引号是字面量引用字符:`'a b'` 是单个参数 `a b`。
7
+ - 反引号和 `$(...)` 执行命令替换;需要字面文本时请加引号。
8
+ - 路径使用 `/` 分隔符,`~` 展开为主目录。
@@ -1,11 +1,11 @@
1
- ## Windows 命令行提示
2
-
3
- 你运行在 Windows 上。优先绕过 shell,只有需要 shell 运算符时才进入 cmd.exe:
4
-
5
- - 单个程序优先用 `run_process`,把可执行文件和每个参数分别放进 `executable` / `args`。它使用 `shell:false`,不会让 cmd.exe 再解释引号、反斜杠、`&`、`%VAR%` 等内容。
6
- - 多行或引号密集的 Python/Node 代码必须用 `run_script`。不要塞进 `python -c` / `node -e`;Windows 下复杂内联代码会被 `run_command` 拒绝,避免命令返回 0 却实际执行了不同代码。
7
- - `run_command` 仅用于 `&&`、管道、重定向等必须由 shell 解析的场景;它通过 cmd.exe 执行,不是 bash,也不是 PowerShell。
8
- - 双引号在 cmd.exe、Node 的 shell 封装和目标程序的 argv 解析之间会经历多层处理;是否保留或剥离取决于具体调用链,不能假设会“原样到达”。单引号在 cmd.exe 中不是可靠的引用字符。
9
- - 使用各命令工具的 `cwd` 参数切换工作目录,不要前置 `cd /d ... &&`。只有手工编写纯 cmd 命令时,跨盘 `cd` 才需要 `/d`。
10
- - PowerShell 专用语法(Get-Item、2>$null、Select-Object)不能直接写进 `run_command`;确需使用时,用 `run_process` 显式执行 `powershell.exe` 并逐项传参。
11
- - npm 11.x 在 Windows 上忽略 `--prefix` 对 `npm publish` 的作用。发布时把工具的 `cwd` 参数设为目标包目录,再执行 `npm publish`。
1
+ ## Windows 命令行提示
2
+
3
+ 你运行在 Windows 上。优先绕过 shell,只有需要 shell 运算符时才进入 cmd.exe:
4
+
5
+ - 单个程序优先用 `run_process`,把可执行文件和每个参数分别放进 `executable` / `args`。它使用 `shell:false`,不会让 cmd.exe 再解释引号、反斜杠、`&`、`%VAR%` 等内容。
6
+ - 多行或引号密集的 Python/Node 代码必须用 `run_script`。不要塞进 `python -c` / `node -e`;Windows 下复杂内联代码会被 `run_command` 拒绝,避免命令返回 0 却实际执行了不同代码。
7
+ - `run_command` 仅用于 `&&`、管道、重定向等必须由 shell 解析的场景;它通过 cmd.exe 执行,不是 bash,也不是 PowerShell。
8
+ - 双引号在 cmd.exe、Node 的 shell 封装和目标程序的 argv 解析之间会经历多层处理;是否保留或剥离取决于具体调用链,不能假设会“原样到达”。单引号在 cmd.exe 中不是可靠的引用字符。
9
+ - 使用各命令工具的 `cwd` 参数切换工作目录,不要前置 `cd /d ... &&`。只有手工编写纯 cmd 命令时,跨盘 `cd` 才需要 `/d`。
10
+ - PowerShell 专用语法(Get-Item、2>$null、Select-Object)不能直接写进 `run_command`;确需使用时,用 `run_process` 显式执行 `powershell.exe` 并逐项传参。
11
+ - npm 11.x 在 Windows 上忽略 `--prefix` 对 `npm publish` 的作用。发布时把工具的 `cwd` 参数设为目标包目录,再执行 `npm publish`。