@dsh-cc/reasoning-fold 0.6.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/LICENSE +201 -0
- package/README.i18n.yaml +6 -0
- package/README.md +40 -0
- package/README.zh.md +40 -0
- package/lib/index.d.ts +43 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +85 -0
- package/lib/index.js.map +1 -0
- package/lib/ledger.d.ts +50 -0
- package/lib/ledger.d.ts.map +1 -0
- package/lib/ledger.js +60 -0
- package/lib/ledger.js.map +1 -0
- package/lib/settings.d.ts +30 -0
- package/lib/settings.d.ts.map +1 -0
- package/lib/settings.js +34 -0
- package/lib/settings.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
|
2
|
+
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
|
+
# after editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm check:readme --write
|
|
5
|
+
README.md: 036e3393895a71ba5bcb6599ef8a8bd2ef1b2d24
|
|
6
|
+
README.zh.md: 3698781f16228ec295ea9d679dc6823e5e70babd
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @dsh-cc/reasoning-fold
|
|
2
|
+
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
Stage-0 reasoning-fold **probe**: a READ-ONLY `llm/stream` listener that byte-counts `reasoning-delta` vs `text-delta` chunks and captures the terminal usage chunk into a per-session JSONL ledger. Measurement before any behavior change (docs/plans/2026-09-10-reasoning-fold-deepseek.md): the probe is **read-only, ledger-only, no behavior change** — every chunk passes through untouched, probe failures are swallowed inside the listener, and a ledger failure never degrades a model call. The fold itself (dropping reasoning from the re-send) is a gated, separate Stage-1/2 effort.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
The plugin registers one read-only `llm/stream` waterfall listener (the only legal read-only shape in a cordis waterfall: it observes chunks while forwarding them from `next()`). Per call it keeps a local record `{provider, model, sessionId, purpose, reasoningBytes, textBytes, usage?}` — no shared state across calls — and appends exactly one ledger row in a `finally`, so an aborted or mid-stream-failed call still records its partial counts. The probe decision is read once per call at its start: a settings flip mid-call never discards an in-flight record.
|
|
10
|
+
|
|
11
|
+
Byte counts are UTF-8 (`Buffer.byteLength`), so multibyte reasoning (CJK, emoji) counts by wire bytes. A call with no usage chunk simply omits `usage` from its row.
|
|
12
|
+
|
|
13
|
+
## Ledger
|
|
14
|
+
|
|
15
|
+
`$DSH_HOME/reasoning-fold/<sessionId>.jsonl`, append-only, one JSON line per model call:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{"ts":"2026-09-10T12:00:00.000Z","sessionId":"...","provider":"...","model":"...","purpose":null,"reasoningBytes":1234,"textBytes":567,"usage":{"inputTokens":100,"outputTokens":20,"totalTokens":120,"cacheReadTokens":80,"cacheWriteTokens":0,"reasoningTokens":50}}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`purpose` is `null` for ordinary conversation calls and `"compaction"` / `"session-title"` for auxiliary ones. All ledger I/O errors are swallowed. Growth is bounded by session count (one file per session); rotate/cap only when `reasoning-fold/` exceeds ~10MB or Stage 1 ships.
|
|
22
|
+
|
|
23
|
+
Usage semantics (harness `llm/src/types.ts` TokenUsage): `inputTokens` counts uncached input only; billed input = `inputTokens + cacheReadTokens + cacheWriteTokens`. Any "re-sent reasoning share of metered input" analysis MUST use that summed billed-input denominator. `reasoningTokens` is output-side and cannot measure re-send cost.
|
|
24
|
+
|
|
25
|
+
## Settings
|
|
26
|
+
|
|
27
|
+
Namespace `cc-reasoning-fold`:
|
|
28
|
+
|
|
29
|
+
| Key | Default | Meaning |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| `probe` | `true` | Master flag. `false` (read live per call) disables the probe; an in-flight call keeps the decision pinned at its start and still appends its row. |
|
|
32
|
+
|
|
33
|
+
Stage-1 keys below are documented for the future fold — they are **inert in Stage 0** and deliberately NOT declared in the settings schema (schema keys without a consumption chain fail the capability manifest audit):
|
|
34
|
+
|
|
35
|
+
- `providers` — restrict the probe/fold to matching provider routes.
|
|
36
|
+
- `head-chars` (default 4000), `tail-chars` (default 2000) — Stage-1 fold window sizes; `floor-chars` (default 12000) is the minimum reasoning block length for the fold to apply, with the `floorChars > headChars + tailChars` validation landing at Stage 1.
|
|
37
|
+
|
|
38
|
+
## Shape
|
|
39
|
+
|
|
40
|
+
Plain cordis plugin (publishes no Service, handoff-store/memory pattern — avoids leakedServices/isolate-key concerns); it registers nothing when the settings provider is absent, `probe` is false, or `dshHomePath` is missing (ledger skipped, chunks still pass through). Mounted by `packages/preset/cc` in the cc-services group.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @dsh-cc/reasoning-fold
|
|
2
|
+
|
|
3
|
+
English | [中文](README.md)
|
|
4
|
+
|
|
5
|
+
Stage-0 reasoning-fold **探针**:一个只读的 `llm/stream` 监听器,按字节统计 `reasoning-delta` 与 `text-delta` 块,并把终止的 usage 块记录到按会话划分的 JSONL 账本。先测量、后改变行为(docs/plans/2026-09-10-reasoning-fold-deepseek.md):探针**只读、只记账、不改变任何行为**——每个 chunk 原样透传,探针自身失败在监听器内吞掉,账本失败也绝不影响模型调用。折叠本身(在重发历史中丢弃 reasoning)是门控的独立 Stage-1/2 工作。
|
|
6
|
+
|
|
7
|
+
## 工作方式
|
|
8
|
+
|
|
9
|
+
插件注册一个只读的 `llm/stream` 瀑布监听器(cordis 瀑布中唯一合法的只读形态:观察 chunk 并原样转发 `next()` 的输出)。每次调用维护一个局部记录 `{provider, model, sessionId, purpose, reasoningBytes, textBytes, usage?}`——调用之间不共享任何可变状态——并在 `finally` 中追加恰好一条账本行,因此中止或中途失败的调用仍会记录部分计数。探针开关在每次调用开始时读取一次:调用中途的设置变更不会丢弃进行中的记录。
|
|
10
|
+
|
|
11
|
+
字节计数使用 UTF-8(`Buffer.byteLength`),多字节 reasoning(中文、emoji)按线上字节数统计。没有 usage 块的调用,其行中省略 `usage`。
|
|
12
|
+
|
|
13
|
+
## 账本
|
|
14
|
+
|
|
15
|
+
`$DSH_HOME/reasoning-fold/<sessionId>.jsonl`,只追加,每次模型调用一行 JSON:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{"ts":"2026-09-10T12:00:00.000Z","sessionId":"...","provider":"...","model":"...","purpose":null,"reasoningBytes":1234,"textBytes":567,"usage":{"inputTokens":100,"outputTokens":20,"totalTokens":120,"cacheReadTokens":80,"cacheWriteTokens":0,"reasoningTokens":50}}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`purpose` 对普通对话调用为 `null`,辅助调用为 `"compaction"` / `"session-title"`。所有账本 I/O 错误一律吞掉。增长受会话数约束(每会话一个文件);仅在 `reasoning-fold/` 超过 ~10MB 或 Stage 1 落地时做轮转/封顶。
|
|
22
|
+
|
|
23
|
+
Usage 语义(harness `llm/src/types.ts` 的 TokenUsage):`inputTokens` 只计未缓存输入;计费输入 = `inputTokens + cacheReadTokens + cacheWriteTokens`。任何"重发 reasoning 占计费输入比例"的分析必须使用该合计分母。`reasoningTokens` 属于输出侧,无法度量重发成本。
|
|
24
|
+
|
|
25
|
+
## 设置
|
|
26
|
+
|
|
27
|
+
命名空间 `cc-reasoning-fold`:
|
|
28
|
+
|
|
29
|
+
| 键 | 默认 | 含义 |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| `probe` | `true` | 总开关。`false`(每次调用实时读取)关闭探针;进行中的调用保持其开始时的决定并仍追加该行。 |
|
|
32
|
+
|
|
33
|
+
下列 Stage-1 键仅为未来折叠功能的前置文档——**在 Stage 0 中不起作用**,且有意不写入 settings schema(无消费链的 schema 键会挂能力清单审计):
|
|
34
|
+
|
|
35
|
+
- `providers` — 将探针/折叠限定到匹配的 provider 路由。
|
|
36
|
+
- `head-chars`(默认 4000)、`tail-chars`(默认 2000)— Stage-1 折叠窗口大小;`floor-chars`(默认 12000)为折叠适用的最小 reasoning 块长度,`floorChars > headChars + tailChars` 的校验随 Stage 1 落地。
|
|
37
|
+
|
|
38
|
+
## 形态
|
|
39
|
+
|
|
40
|
+
普通 cordis 插件(不发布 Service,handoff-store/memory 模式——避免 leakedServices/isolate 问题);当 settings provider 缺失、`probe` 为 false 或 `dshHomePath` 缺失时不注册任何东西(跳过账本,chunk 照常透传)。由 `packages/preset/cc` 挂载在 cc-services 组内。
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage-0 reasoning-fold probe: a READ-ONLY `llm/stream` listener that
|
|
3
|
+
* byte-counts `reasoning-delta` vs `text-delta` chunks and captures the
|
|
4
|
+
* terminal usage chunk into a per-session JSONL ledger under
|
|
5
|
+
* `<dshHome>/reasoning-fold/<sessionId>.jsonl`. Measurement before any
|
|
6
|
+
* behavior change (docs/plans/2026-09-10-reasoning-fold-deepseek.md): the
|
|
7
|
+
* listener always passes every chunk through untouched (LEDGER-ONLY) —
|
|
8
|
+
* probe failures are swallowed and never break the model call.
|
|
9
|
+
*
|
|
10
|
+
* Plain cordis plugin (publishes no Service — handoff-store/memory pattern),
|
|
11
|
+
* so it needs no isolate realm of its own. No-ops when the settings provider
|
|
12
|
+
* is absent or `cc-reasoning-fold.probe` is `false`, or when `dshHomePath`
|
|
13
|
+
* is absent (ledger skipped, chunks still pass through).
|
|
14
|
+
*
|
|
15
|
+
* @module @dsh-cc/reasoning-fold
|
|
16
|
+
*/
|
|
17
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
18
|
+
import type { StreamChunk } from '@deepseek-ai/dsh-llm';
|
|
19
|
+
import { type FoldRecord } from './ledger.ts';
|
|
20
|
+
export { appendLedgerRow, observeChunk, type FoldRecord, type LedgerRow } from './ledger.ts';
|
|
21
|
+
export { registerProbeSetting, SETTINGS_NAMESPACE, SettingsSchema } from './settings.ts';
|
|
22
|
+
declare module '@deepseek-ai/cordis' {
|
|
23
|
+
interface Context {
|
|
24
|
+
/** Harness-home path resolver, provided by @deepseek-ai/dsh-app-boot at boot. Optional in tests. */
|
|
25
|
+
dshHomePath?: (...segments: string[]) => string;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The read-only passthrough listener body. Detached from `apply` for direct
|
|
30
|
+
* unit testing (incl. the abort path: the ledger row is appended in
|
|
31
|
+
* `finally`, so an upstream throw mid-iteration still records).
|
|
32
|
+
*/
|
|
33
|
+
export declare function foldStream(record: FoldRecord, probeOn: boolean, observe: (record: FoldRecord, chunk: StreamChunk) => void, append: (record: FoldRecord) => Promise<void>, next: () => AsyncIterable<StreamChunk>): AsyncGenerator<StreamChunk>;
|
|
34
|
+
/**
|
|
35
|
+
* Mount the probe. No-op (registers nothing) when the settings provider is
|
|
36
|
+
* absent or `probe` is false.
|
|
37
|
+
* @param ctx - the plug context.
|
|
38
|
+
* @returns the listener disposer, or `undefined` when not registered.
|
|
39
|
+
*/
|
|
40
|
+
export declare function apply(ctx: Context): (() => void) | undefined;
|
|
41
|
+
/** Cordis plugin id. */
|
|
42
|
+
export declare const name = "cc-reasoning-fold";
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAiC,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AAG5E,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5F,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAKxF,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,OAAO;QACf,oGAAoG;QACpG,WAAW,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,KAAK,MAAM,CAAA;KAChD;CACF;AAUD;;;;GAIG;AACH,wBAAuB,UAAU,CAC/B,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,EACzD,MAAM,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,EAC7C,IAAI,EAAE,MAAM,aAAa,CAAC,WAAW,CAAC,GACrC,cAAc,CAAC,WAAW,CAAC,CAmB7B;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAwB5D;AAED,wBAAwB;AACxB,eAAO,MAAM,IAAI,sBAAsB,CAAA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage-0 reasoning-fold probe: a READ-ONLY `llm/stream` listener that
|
|
3
|
+
* byte-counts `reasoning-delta` vs `text-delta` chunks and captures the
|
|
4
|
+
* terminal usage chunk into a per-session JSONL ledger under
|
|
5
|
+
* `<dshHome>/reasoning-fold/<sessionId>.jsonl`. Measurement before any
|
|
6
|
+
* behavior change (docs/plans/2026-09-10-reasoning-fold-deepseek.md): the
|
|
7
|
+
* listener always passes every chunk through untouched (LEDGER-ONLY) —
|
|
8
|
+
* probe failures are swallowed and never break the model call.
|
|
9
|
+
*
|
|
10
|
+
* Plain cordis plugin (publishes no Service — handoff-store/memory pattern),
|
|
11
|
+
* so it needs no isolate realm of its own. No-ops when the settings provider
|
|
12
|
+
* is absent or `cc-reasoning-fold.probe` is `false`, or when `dshHomePath`
|
|
13
|
+
* is absent (ledger skipped, chunks still pass through).
|
|
14
|
+
*
|
|
15
|
+
* @module @dsh-cc/reasoning-fold
|
|
16
|
+
*/
|
|
17
|
+
import { appendLedgerRow, observeChunk } from "./ledger.js";
|
|
18
|
+
import { registerProbeSetting } from "./settings.js";
|
|
19
|
+
export { appendLedgerRow, observeChunk } from "./ledger.js";
|
|
20
|
+
export { registerProbeSetting, SETTINGS_NAMESPACE, SettingsSchema } from "./settings.js";
|
|
21
|
+
function dshHomeFn(ctx) {
|
|
22
|
+
try {
|
|
23
|
+
return ctx.dshHomePath;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The read-only passthrough listener body. Detached from `apply` for direct
|
|
31
|
+
* unit testing (incl. the abort path: the ledger row is appended in
|
|
32
|
+
* `finally`, so an upstream throw mid-iteration still records).
|
|
33
|
+
*/
|
|
34
|
+
export async function* foldStream(record, probeOn, observe, append, next) {
|
|
35
|
+
try {
|
|
36
|
+
for await (const chunk of await next()) {
|
|
37
|
+
if (probeOn) {
|
|
38
|
+
try {
|
|
39
|
+
observe(record, chunk);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// LEDGER-ONLY: probe failures must never break the model call.
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
yield chunk;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
try {
|
|
50
|
+
await append(record);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Best-effort: the row is observability, never the call's fate.
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Mount the probe. No-op (registers nothing) when the settings provider is
|
|
59
|
+
* absent or `probe` is false.
|
|
60
|
+
* @param ctx - the plug context.
|
|
61
|
+
* @returns the listener disposer, or `undefined` when not registered.
|
|
62
|
+
*/
|
|
63
|
+
export function apply(ctx) {
|
|
64
|
+
const readProbe = registerProbeSetting(ctx);
|
|
65
|
+
if (readProbe === undefined || !readProbe())
|
|
66
|
+
return undefined;
|
|
67
|
+
const home = dshHomeFn(ctx);
|
|
68
|
+
return ctx.on('llm/stream', (options, next) => {
|
|
69
|
+
// Probe decision pinned at call start: a settings flip mid-call cannot
|
|
70
|
+
// discard the in-flight record (it still appends its row).
|
|
71
|
+
const probeOn = readProbe();
|
|
72
|
+
const record = {
|
|
73
|
+
provider: options.provider,
|
|
74
|
+
model: options.model,
|
|
75
|
+
sessionId: String(options.sessionId ?? 'unknown'),
|
|
76
|
+
purpose: options.purpose ?? null,
|
|
77
|
+
reasoningBytes: 0,
|
|
78
|
+
textBytes: 0,
|
|
79
|
+
};
|
|
80
|
+
return foldStream(record, probeOn, observeChunk, (r) => home === undefined ? Promise.resolve() : appendLedgerRow(home('reasoning-fold', `${r.sessionId}.jsonl`), r), next);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Cordis plugin id. */
|
|
84
|
+
export const name = 'cc-reasoning-fold';
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,eAAe,EAAE,YAAY,EAAmB,MAAM,aAAa,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAmC,MAAM,aAAa,CAAA;AAC5F,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAYxF,SAAS,SAAS,CAAC,GAAY;IAC7B,IAAI,CAAC;QACH,OAAO,GAAG,CAAC,WAAW,CAAA;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,UAAU,CAC/B,MAAkB,EAClB,OAAgB,EAChB,OAAyD,EACzD,MAA6C,EAC7C,IAAsC;IAEtC,IAAI,CAAC;QACH,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,EAAE,CAAC;YACvC,IAAI,OAAO,EAAE,CAAC;gBACZ,IAAI,CAAC;oBACH,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;gBACxB,CAAC;gBAAC,MAAM,CAAC;oBACP,+DAA+D;gBACjE,CAAC;YACH,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,MAAM,CAAC,CAAA;QACtB,CAAC;QAAC,MAAM,CAAC;YACP,gEAAgE;QAClE,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,GAAY;IAChC,MAAM,SAAS,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAA;IAC3C,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,SAAS,EAAE;QAAE,OAAO,SAAS,CAAA;IAC7D,MAAM,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;IAC3B,OAAO,GAAG,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,OAAwB,EAAE,IAAsC,EAAE,EAAE;QAC/F,uEAAuE;QACvE,2DAA2D;QAC3D,MAAM,OAAO,GAAG,SAAS,EAAE,CAAA;QAC3B,MAAM,MAAM,GAAe;YACzB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC;YACjD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,IAAI;YAChC,cAAc,EAAE,CAAC;YACjB,SAAS,EAAE,CAAC;SACb,CAAA;QACD,OAAO,UAAU,CACf,MAAM,EACN,OAAO,EACP,YAAY,EACZ,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC,SAAS,QAAQ,CAAC,EAAE,CAAC,CAAC,EAClH,IAAI,CACL,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,wBAAwB;AACxB,MAAM,CAAC,MAAM,IAAI,GAAG,mBAAmB,CAAA"}
|
package/lib/ledger.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Probe record + append-only fold ledger (`<dshHome>/reasoning-fold/<sessionId>.jsonl`).
|
|
3
|
+
*
|
|
4
|
+
* Ledger growth is bounded by session count (one file per session); rotate/cap
|
|
5
|
+
* only when reasoning-fold/ exceeds ~10MB or Stage 1 ships.
|
|
6
|
+
*
|
|
7
|
+
* SavingsLedger idiom (context-crusher/src/ledger.ts): one appendFile per row,
|
|
8
|
+
* all I/O errors swallowed — the ledger is observability and must never
|
|
9
|
+
* degrade a model call.
|
|
10
|
+
*
|
|
11
|
+
* @module @dsh-cc/reasoning-fold/ledger
|
|
12
|
+
*/
|
|
13
|
+
import type { StreamChunk, TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
14
|
+
/**
|
|
15
|
+
* Per-call probe record. A LOCAL const inside one `llm/stream` listener
|
|
16
|
+
* invocation — never shared mutable state across calls.
|
|
17
|
+
*/
|
|
18
|
+
export interface FoldRecord {
|
|
19
|
+
readonly provider: string;
|
|
20
|
+
readonly model: string;
|
|
21
|
+
readonly sessionId: string;
|
|
22
|
+
readonly purpose: 'compaction' | 'session-title' | null;
|
|
23
|
+
reasoningBytes: number;
|
|
24
|
+
textBytes: number;
|
|
25
|
+
/** Full usage-chunk capture; a call with no usage chunk leaves this unset. */
|
|
26
|
+
usage?: TokenUsage;
|
|
27
|
+
}
|
|
28
|
+
/** One JSONL ledger row (`usage` omitted when the call carried no usage chunk). */
|
|
29
|
+
export interface LedgerRow {
|
|
30
|
+
readonly ts: string;
|
|
31
|
+
readonly sessionId: string;
|
|
32
|
+
readonly provider: string;
|
|
33
|
+
readonly model: string;
|
|
34
|
+
readonly purpose: 'compaction' | 'session-title' | null;
|
|
35
|
+
readonly reasoningBytes: number;
|
|
36
|
+
readonly textBytes: number;
|
|
37
|
+
readonly usage?: TokenUsage;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Observe one upstream chunk into the record (READ-ONLY: mutates only the
|
|
41
|
+
* record, never the chunk). Byte counts are UTF-8 so multibyte deltas count
|
|
42
|
+
* by wire bytes, not code points.
|
|
43
|
+
*/
|
|
44
|
+
export declare function observeChunk(record: FoldRecord, chunk: StreamChunk): void;
|
|
45
|
+
/**
|
|
46
|
+
* Append one ledger row; never throws. `usage` is omitted from the row when
|
|
47
|
+
* the call carried no usage chunk.
|
|
48
|
+
*/
|
|
49
|
+
export declare function appendLedgerRow(filePath: string, record: FoldRecord): Promise<void>;
|
|
50
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../src/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEnE;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,eAAe,GAAG,IAAI,CAAA;IACvD,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB;AAED,mFAAmF;AACnF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,eAAe,GAAG,IAAI,CAAA;IACvD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAA;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAgBzE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBzF"}
|
package/lib/ledger.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Probe record + append-only fold ledger (`<dshHome>/reasoning-fold/<sessionId>.jsonl`).
|
|
3
|
+
*
|
|
4
|
+
* Ledger growth is bounded by session count (one file per session); rotate/cap
|
|
5
|
+
* only when reasoning-fold/ exceeds ~10MB or Stage 1 ships.
|
|
6
|
+
*
|
|
7
|
+
* SavingsLedger idiom (context-crusher/src/ledger.ts): one appendFile per row,
|
|
8
|
+
* all I/O errors swallowed — the ledger is observability and must never
|
|
9
|
+
* degrade a model call.
|
|
10
|
+
*
|
|
11
|
+
* @module @dsh-cc/reasoning-fold/ledger
|
|
12
|
+
*/
|
|
13
|
+
import { appendFile, mkdir } from 'node:fs/promises';
|
|
14
|
+
import { dirname } from 'node:path';
|
|
15
|
+
/**
|
|
16
|
+
* Observe one upstream chunk into the record (READ-ONLY: mutates only the
|
|
17
|
+
* record, never the chunk). Byte counts are UTF-8 so multibyte deltas count
|
|
18
|
+
* by wire bytes, not code points.
|
|
19
|
+
*/
|
|
20
|
+
export function observeChunk(record, chunk) {
|
|
21
|
+
switch (chunk.type) {
|
|
22
|
+
case 'reasoning-delta':
|
|
23
|
+
record.reasoningBytes += Buffer.byteLength(chunk.text, 'utf8');
|
|
24
|
+
break;
|
|
25
|
+
case 'text-delta':
|
|
26
|
+
record.textBytes += Buffer.byteLength(chunk.text, 'utf8');
|
|
27
|
+
break;
|
|
28
|
+
case 'usage':
|
|
29
|
+
// Spread copy: detach from the upstream chunk (frozen or otherwise).
|
|
30
|
+
record.usage = { ...chunk.usage };
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
// block-start/block-end/tool-call-delta/finish are ignored.
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Append one ledger row; never throws. `usage` is omitted from the row when
|
|
39
|
+
* the call carried no usage chunk.
|
|
40
|
+
*/
|
|
41
|
+
export async function appendLedgerRow(filePath, record) {
|
|
42
|
+
try {
|
|
43
|
+
const row = {
|
|
44
|
+
ts: new Date().toISOString(),
|
|
45
|
+
sessionId: record.sessionId,
|
|
46
|
+
provider: record.provider,
|
|
47
|
+
model: record.model,
|
|
48
|
+
purpose: record.purpose,
|
|
49
|
+
reasoningBytes: record.reasoningBytes,
|
|
50
|
+
textBytes: record.textBytes,
|
|
51
|
+
...record.usage === undefined ? {} : { usage: record.usage },
|
|
52
|
+
};
|
|
53
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
54
|
+
await appendFile(filePath, `${JSON.stringify(row)}\n`, 'utf8');
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Best-effort observability; never surface into the model-call waterfall.
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../src/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA8BnC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB,EAAE,KAAkB;IACjE,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,iBAAiB;YACpB,MAAM,CAAC,cAAc,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YAC9D,MAAK;QACP,KAAK,YAAY;YACf,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YACzD,MAAK;QACP,KAAK,OAAO;YACV,qEAAqE;YACrE,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;YACjC,MAAK;QACP;YACE,4DAA4D;YAC5D,MAAK;IACT,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAgB,EAAE,MAAkB;IACxE,IAAI,CAAC;QACH,MAAM,GAAG,GAAc;YACrB,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YAC5B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,GAAG,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;SAC7D,CAAA;QACD,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACnD,MAAM,UAAU,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;IAC5E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings namespace registration for the `cc-reasoning-fold` probe.
|
|
3
|
+
* Handoff-store settings.ts pattern: the namespace is registered once at
|
|
4
|
+
* mount; the live scope is re-read on EVERY stream invocation so a settings
|
|
5
|
+
* write applies immediately (while a call already in flight keeps the
|
|
6
|
+
* decision pinned at its start).
|
|
7
|
+
* @module @dsh-cc/reasoning-fold/settings
|
|
8
|
+
*/
|
|
9
|
+
import z from '@deepseek-ai/schemastery';
|
|
10
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
11
|
+
import type { SettingsNamespace } from '@deepseek-ai/dsh-settings';
|
|
12
|
+
/** The settings namespace carrying the probe flag. */
|
|
13
|
+
export declare const SETTINGS_NAMESPACE: SettingsNamespace;
|
|
14
|
+
/**
|
|
15
|
+
* Schema. Stage-0 carries ONLY `probe`; the Stage-1 keys
|
|
16
|
+
* (`providers` / `head-chars` / `tail-chars` / `floor-chars`) are documented
|
|
17
|
+
* in the README as inert/future and are deliberately NOT declared here —
|
|
18
|
+
* schema keys without a consumption chain fail the capability manifest audit.
|
|
19
|
+
*/
|
|
20
|
+
export declare const SettingsSchema: z<{
|
|
21
|
+
probe: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Register the settings namespace and return the live probe reader.
|
|
25
|
+
* @param ctx - the plug context.
|
|
26
|
+
* @returns a per-use probe reader, or `undefined` when the host has no
|
|
27
|
+
* settings provider (the plugin then registers nothing).
|
|
28
|
+
*/
|
|
29
|
+
export declare function registerProbeSetting(ctx: Context): (() => boolean) | undefined;
|
|
30
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,2BAA2B,CAAA;AAEpF,sDAAsD;AACtD,eAAO,MAAM,kBAAkB,EAA0B,iBAAiB,CAAA;AAE1E;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,CAAC,CAAC;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,CAE/C,CAAA;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,SAAS,CAK9E"}
|
package/lib/settings.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings namespace registration for the `cc-reasoning-fold` probe.
|
|
3
|
+
* Handoff-store settings.ts pattern: the namespace is registered once at
|
|
4
|
+
* mount; the live scope is re-read on EVERY stream invocation so a settings
|
|
5
|
+
* write applies immediately (while a call already in flight keeps the
|
|
6
|
+
* decision pinned at its start).
|
|
7
|
+
* @module @dsh-cc/reasoning-fold/settings
|
|
8
|
+
*/
|
|
9
|
+
import z from '@deepseek-ai/schemastery';
|
|
10
|
+
/** The settings namespace carrying the probe flag. */
|
|
11
|
+
export const SETTINGS_NAMESPACE = 'cc-reasoning-fold';
|
|
12
|
+
/**
|
|
13
|
+
* Schema. Stage-0 carries ONLY `probe`; the Stage-1 keys
|
|
14
|
+
* (`providers` / `head-chars` / `tail-chars` / `floor-chars`) are documented
|
|
15
|
+
* in the README as inert/future and are deliberately NOT declared here —
|
|
16
|
+
* schema keys without a consumption chain fail the capability manifest audit.
|
|
17
|
+
*/
|
|
18
|
+
export const SettingsSchema = z.object({
|
|
19
|
+
probe: z.boolean().default(true),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Register the settings namespace and return the live probe reader.
|
|
23
|
+
* @param ctx - the plug context.
|
|
24
|
+
* @returns a per-use probe reader, or `undefined` when the host has no
|
|
25
|
+
* settings provider (the plugin then registers nothing).
|
|
26
|
+
*/
|
|
27
|
+
export function registerProbeSetting(ctx) {
|
|
28
|
+
const settings = ctx.get('settings');
|
|
29
|
+
if (settings === undefined)
|
|
30
|
+
return undefined;
|
|
31
|
+
const scope = settings.register(SETTINGS_NAMESPACE, SettingsSchema);
|
|
32
|
+
return () => scope?.get?.()?.probe ?? true;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAIxC,sDAAsD;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAAwC,CAAA;AAE1E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAA0B,CAAC,CAAC,MAAM,CAAC;IAC5D,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;CACjC,CAAC,CAAA;AAEF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAY;IAC/C,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAiC,CAAA;IACpE,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAA;IACnE,OAAO,GAAG,EAAE,CAAE,KAAK,EAAE,GAAG,EAAE,EAAsC,EAAE,KAAK,IAAI,IAAI,CAAA;AACjF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dsh-cc/reasoning-fold",
|
|
3
|
+
"description": "Stage-0 reasoning-fold probe: read-only llm/stream observer that byte-counts reasoning vs text deltas into a per-session JSONL ledger; no behavior change",
|
|
4
|
+
"version": "0.6.2",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
8
|
+
"directory": "packages/llm-tuning/reasoning-fold"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@deepseek-ai/cordis": ">=0.1.2-rc.1",
|
|
25
|
+
"@deepseek-ai/dsh-llm": ">=0.1.2-rc.1",
|
|
26
|
+
"@deepseek-ai/dsh-settings": ">=0.1.2-rc.1",
|
|
27
|
+
"@deepseek-ai/schemastery": "^3.18.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|
|
31
|
+
"@deepseek-ai/dsh-llm": "link:../../../../deepseek-harness/packages/llm/llm",
|
|
32
|
+
"@deepseek-ai/dsh-settings": "link:../../../../deepseek-harness/packages/settings/settings",
|
|
33
|
+
"@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery",
|
|
34
|
+
"vitest": "^4.1.8"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|