@deepseek-ai/dsh-chunked-list 0.1.5-alpha.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
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.
@@ -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 run verify-translation-pairing --write packages/util/chunked-list/README.md
5
+ README.md: f0af89e5dd6cfdc6388fe90aaeaf2fb70b149827
6
+ README.zh.md: 9f28884ad7414ceeae1d7e624cb20efca9033b25
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ ---
2
+ description: "Immutable append-only lists for projection state, with bounded append copying, insertion-order iteration, and Zod checkpoint validation."
3
+ kind: "package-library"
4
+ ---
5
+
6
+ # @deepseek-ai/dsh-chunked-list
7
+
8
+ English | [中文](README.zh.md)
9
+
10
+ ## Summary
11
+
12
+ `dsh-chunked-list` lets callers append values while retaining earlier list versions without copying the whole collection. Callers can iterate every value in insertion order and validate JSON checkpoints with their own value schema. The subagent catalog uses it for immutable projection state.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Use this package](#use-this-package)
17
+ - [Understand the implementation](#understand-the-implementation)
18
+ - [Further Exploration](#further-exploration)
19
+ - [Model Experience](#model-experience)
20
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
21
+ - [Dev Note](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## Use this package
27
+
28
+ Use this list when an append-only collection needs immutable versions and JSON-compatible storage. An empty list is `undefined`; appending returns a new head without modifying existing nodes. The list shares stored values by reference, so callers must treat them as immutable.
29
+
30
+ ```ts
31
+ import { appendChunkedList, iterateChunkedList } from '@deepseek-ai/dsh-chunked-list'
32
+
33
+ const first = appendChunkedList(undefined, 'first')
34
+ const second = appendChunkedList(first, 'second')
35
+ console.log([...iterateChunkedList(second)])
36
+ ```
37
+
38
+ The example produces `['first', 'second']`; `first` still contains only its original value. `chunkedListSchema(valueSchema)` validates JSON checkpoints and rejects unknown fields, invalid values, and empty or oversized chunks. Use `.optional()` on the schema when the containing field also permits an empty list. See the [source contracts](src/index.ts) for the operations.
39
+
40
+ -----
41
+
42
+ <a id="understand-the-implementation"></a>
43
+ ## Understand the implementation
44
+
45
+ <details>
46
+ <summary>Implementation internals — click to expand</summary>
47
+
48
+ The newest chunk stores up to 64 values. Appends copy at most that chunk and share older nodes, taking bounded O(1) work. The capacity controls storage layout, not total list length. Iteration visits all N values in O(N) time and uses O(N / 64) scratch space to visit chunks from oldest to newest. A single capacity constant governs append rollover and recursive Zod validation.
49
+
50
+ | File | Role |
51
+ |---|---|
52
+ | [`src/index.ts`](src/index.ts) | Persistent list operations and checkpoint validation |
53
+ | [`tests/chunked-list.spec.ts`](tests/chunked-list.spec.ts) | Version isolation, ordering, structural sharing, and checkpoint acceptance |
54
+
55
+ No runtime invariant companion is published because this library has no independently changing observations; its operations return caller-owned immutable values.
56
+
57
+ </details>
58
+
59
+ -----
60
+
61
+ <a id="further-exploration"></a>
62
+ ## Further Exploration
63
+
64
+ - [Utility package map](../README.md) — shared primitives.
65
+ - [Subagent catalog decision](../../../.agents/notes/implemented/architecture/2026-09-01-parent-owned-subagent-catalog.md) — why projection state uses chunks.
66
+
67
+ -----
68
+
69
+ <a id="model-experience"></a>
70
+ ## Model Experience
71
+
72
+ None, as this collection registers nothing model-facing.
73
+
74
+ #### KV Cache effect
75
+
76
+ Nothing here enters a model request, so provider cache reuse is unaffected.
77
+
78
+ ## Known Limitations and Deferred Work
79
+
80
+ <a id="known-limitations-and-deferred-work"></a>
81
+
82
+ - **Append-only access** — callers needing removal or random access need another collection.
83
+ - **Recursive checkpoints** — JSON serialization and schema validation remain subject to runtime nesting limits. Stored values must themselves support the caller's serialization format.
84
+
85
+ <a id="dev-note"></a>
86
+ ### Dev Note
87
+
88
+ <details>
89
+ <summary>Working context for maintainers — click to expand</summary>
90
+
91
+ None.
92
+
93
+ </details>
package/README.zh.md ADDED
@@ -0,0 +1,93 @@
1
+ ---
2
+ description: "用于 projection state 的不可变追加列表,提供有界追加复制、按插入顺序迭代和 Zod 检查点校验。"
3
+ kind: "package-library"
4
+ ---
5
+
6
+ # @deepseek-ai/dsh-chunked-list
7
+
8
+ [English](README.md) | 中文
9
+
10
+ ## 概述
11
+
12
+ `dsh-chunked-list` 让调用方追加值并保留早期列表版本,无需复制整个集合。调用方可以按插入顺序迭代所有值,并使用自己的值 schema 校验 JSON 检查点。subagent 目录用它保存不可变的 projection state。
13
+
14
+ ## 目录
15
+
16
+ - [使用此包](#use-this-package)
17
+ - [理解实现](#understand-the-implementation)
18
+ - [进一步探索](#further-exploration)
19
+ - [模型体验](#model-experience)
20
+ - [已知限制与延后工作](#known-limitations-and-deferred-work)
21
+ - [开发备注](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## 使用此包
27
+
28
+ 当仅追加集合需要不可变版本和兼容 JSON 的存储时,使用此列表。空列表用 `undefined` 表示;追加返回新的头节点,不修改已有节点。列表按引用共享所存的值,因此调用方必须将这些值视为不可变。
29
+
30
+ ```ts
31
+ import { appendChunkedList, iterateChunkedList } from '@deepseek-ai/dsh-chunked-list'
32
+
33
+ const first = appendChunkedList(undefined, 'first')
34
+ const second = appendChunkedList(first, 'second')
35
+ console.log([...iterateChunkedList(second)])
36
+ ```
37
+
38
+ 示例输出 `['first', 'second']`;`first` 仍只包含原来的值。`chunkedListSchema(valueSchema)` 校验 JSON 检查点并拒绝未知字段、无效值和空块或超大块。当外层字段也允许空列表时,在 schema 上使用 `.optional()`。各操作详见[源码约定](src/index.ts)。
39
+
40
+ -----
41
+
42
+ <a id="understand-the-implementation"></a>
43
+ ## 理解实现
44
+
45
+ <details>
46
+ <summary>实现内部机制——点击展开</summary>
47
+
48
+ 最新的块最多存储 64 个值。追加最多复制该块并共享较旧的节点,工作量为有界 O(1)。容量控制存储布局,不限制列表总长度。迭代以 O(N) 时间访问全部 N 个值,并使用 O(N / 64) 临时空间按从旧到新的顺序访问各块。追加换块与递归 Zod 校验共用一个容量常量。
49
+
50
+ | 文件 | 职责 |
51
+ |---|---|
52
+ | [`src/index.ts`](src/index.ts) | 持久化列表操作与检查点校验 |
53
+ | [`tests/chunked-list.spec.ts`](tests/chunked-list.spec.ts) | 版本隔离、排序、结构共享与检查点接受条件 |
54
+
55
+ 此库没有独立变化的观测值,因此不发布运行时不变式伴随模块;其操作返回调用方拥有的不可变值。
56
+
57
+ </details>
58
+
59
+ -----
60
+
61
+ <a id="further-exploration"></a>
62
+ ## 进一步探索
63
+
64
+ - [工具包映射](../README.zh.md)——共享原语。
65
+ - [Subagent 目录决策](../../../.agents/notes/implemented/architecture/2026-09-01-parent-owned-subagent-catalog.zh.md)——projection state 使用分块的原因。
66
+
67
+ -----
68
+
69
+ <a id="model-experience"></a>
70
+ ## 模型体验
71
+
72
+ 无,因为此集合不注册任何面向模型的内容。
73
+
74
+ #### KV Cache 影响
75
+
76
+ 本包没有内容进入模型请求,因此不影响提供方缓存复用。
77
+
78
+ ## 已知限制与延后工作
79
+
80
+ <a id="known-limitations-and-deferred-work"></a>
81
+
82
+ - **仅追加访问**——需要删除或随机访问的调用方应使用其他集合。
83
+ - **递归检查点**——JSON 序列化与 schema 校验仍受运行时嵌套深度限制。所存的值本身必须支持调用方的序列化格式。
84
+
85
+ <a id="dev-note"></a>
86
+ ### 开发备注
87
+
88
+ <details>
89
+ <summary>维护者的工作上下文——点击展开</summary>
90
+
91
+ 无。
92
+
93
+ </details>
package/lib/index.js ADDED
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+ //#region lib/types/index.js
3
+ /**
4
+ * Persistent append-only lists with bounded copying and JSON checkpoint validation.
5
+ * @module @deepseek-ai/dsh-chunked-list
6
+ */
7
+ const CHUNK_CAPACITY = 64;
8
+ /**
9
+ * Append without modifying the input, copying at most one 64-value chunk.
10
+ * @param head - current list, or `undefined` for an empty list.
11
+ * @param value - value to retain by reference.
12
+ * @returns new list sharing the unchanged older chunks.
13
+ */
14
+ function appendChunkedList(head, value) {
15
+ if (head === void 0 || head.values.length === CHUNK_CAPACITY) return {
16
+ values: [value],
17
+ ...head === void 0 ? {} : { previous: head }
18
+ };
19
+ return {
20
+ values: [...head.values, value],
21
+ ...head.previous === void 0 ? {} : { previous: head.previous }
22
+ };
23
+ }
24
+ /**
25
+ * Visit all values in insertion order, with O(N) time and O(N / 64) scratch space.
26
+ * @param head - current list, or `undefined` for an empty list.
27
+ * @returns iterator yielding the stored values by reference, without truncation.
28
+ */
29
+ function* iterateChunkedList(head) {
30
+ const chunks = [];
31
+ for (let chunk = head; chunk !== void 0; chunk = chunk.previous) chunks.push(chunk);
32
+ for (const chunk of chunks.reverse()) yield* chunk.values;
33
+ }
34
+ /**
35
+ * Validate nonempty list checkpoints, including every stored value and chunk size.
36
+ * @param valueSchema - caller-owned validation for each stored value.
37
+ * @returns recursive Zod schema rejecting empty or oversized chunks and unknown fields.
38
+ */
39
+ function chunkedListSchema(valueSchema) {
40
+ const schema = z.lazy(() => z.object({
41
+ values: z.array(valueSchema).min(1).max(CHUNK_CAPACITY),
42
+ previous: schema.optional()
43
+ }).strict());
44
+ return schema;
45
+ }
46
+ //#endregion
47
+ export { appendChunkedList, chunkedListSchema, iterateChunkedList };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Persistent append-only lists with bounded copying and JSON checkpoint validation.
3
+ * @module @deepseek-ai/dsh-chunked-list
4
+ */
5
+ import { z } from 'zod';
6
+ /**
7
+ * Newest chunk of an immutable list; `undefined` represents the empty list.
8
+ * Values within each chunk follow insertion order. Callers treat nodes, arrays,
9
+ * and stored values as immutable; operations share values and older chunks.
10
+ */
11
+ export interface ChunkedList<T> {
12
+ readonly values: readonly T[];
13
+ readonly previous?: ChunkedList<T> | undefined;
14
+ }
15
+ /**
16
+ * Append without modifying the input, copying at most one 64-value chunk.
17
+ * @param head - current list, or `undefined` for an empty list.
18
+ * @param value - value to retain by reference.
19
+ * @returns new list sharing the unchanged older chunks.
20
+ */
21
+ export declare function appendChunkedList<T>(head: ChunkedList<T> | undefined, value: T): ChunkedList<T>;
22
+ /**
23
+ * Visit all values in insertion order, with O(N) time and O(N / 64) scratch space.
24
+ * @param head - current list, or `undefined` for an empty list.
25
+ * @returns iterator yielding the stored values by reference, without truncation.
26
+ */
27
+ export declare function iterateChunkedList<T>(head: ChunkedList<T> | undefined): Generator<T>;
28
+ /**
29
+ * Validate nonempty list checkpoints, including every stored value and chunk size.
30
+ * @param valueSchema - caller-owned validation for each stored value.
31
+ * @returns recursive Zod schema rejecting empty or oversized chunks and unknown fields.
32
+ */
33
+ export declare function chunkedListSchema<T>(valueSchema: z.ZodType<T>): z.ZodType<ChunkedList<T>>;
34
+ //# sourceMappingURL=index.d.ts.map
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@deepseek-ai/dsh-chunked-list",
3
+ "description": "Persistent append-only chunked lists with bounded copying and JSON checkpoint validation",
4
+ "version": "0.1.5-alpha.2",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
11
+ "directory": "packages/util/chunked-list"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./src/*": "./src/*",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "lib/index.js",
26
+ "lib/types/**/*.d.ts"
27
+ ],
28
+ "license": "MIT",
29
+ "peerDependencies": {
30
+ "@deepseek-ai/cordis": "^4.0.2"
31
+ },
32
+ "devDependencies": {
33
+ "@deepseek-ai/cordis": "^4.0.2"
34
+ },
35
+ "dependencies": {
36
+ "zod": "^4.4.3"
37
+ }
38
+ }