@jianxx/dsh-cc-tool-sleep 0.1.0
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 +56 -0
- package/README.zh.md +56 -0
- package/lib/index.d.ts +36 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +110 -0
- package/lib/index.js.map +1 -0
- package/lib/invariant.d.ts +16 -0
- package/lib/invariant.d.ts.map +1 -0
- package/lib/invariant.js +23 -0
- package/lib/invariant.js.map +1 -0
- package/lib/render.d.ts +27 -0
- package/lib/render.d.ts.map +1 -0
- package/lib/render.js +42 -0
- package/lib/render.js.map +1 -0
- package/package.json +45 -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 run verify-translation-pairing --write packages/core/tool-sleep/README.md
|
|
5
|
+
README.md: d6b0a6fa637faefc995b6a344255ccdfe1bc1ef3
|
|
6
|
+
README.zh.md: 20f51605bc0b9c67b5a3df820d142d54c63b60e0
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @jianxx/dsh-cc-tool-sleep
|
|
2
|
+
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
Model-facing `Sleep` tool that waits for a specified duration with cooperative cancellation, aligned to Claude Code's `SleepTool` semantics. It registers into `ctx.tools` via the `@jianxx/dsh-cc-tools` `ToolRuntime`.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
### `Sleep`
|
|
10
|
+
|
|
11
|
+
Waits for `{ duration }` seconds.
|
|
12
|
+
|
|
13
|
+
| Arg | Type | Notes |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `duration` | number | Seconds to wait. Must be a finite, non-negative number. `0` is a no-op. |
|
|
16
|
+
|
|
17
|
+
The wait is cooperative with cancellation: it arms a timer and an `abort` listener on `exec.signal`, and settles on whichever fires first. When a new turn cancels the call mid-sleep, the tool stops waiting immediately and reports the canonical `ABORTED` outcome — matching CC's `interruptBehavior: 'cancel'`.
|
|
18
|
+
|
|
19
|
+
The tool is `isConcurrencySafe = () => true`, so it may overlap sibling tool calls (CC: "You can call this concurrently with other tools — it won't interfere with them"). Prefer it over spawning a sleeping subprocess, because it does not hold a subprocess or a shell.
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
`Config` is schemastery-typed (mirroring the git-worktree tools' convention):
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
export const Config = z.object({
|
|
27
|
+
minDurationSeconds: z.number(), // optional lower bound (clamped up)
|
|
28
|
+
maxDurationSeconds: z.number(), // optional upper bound (clamped down)
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Each `apply(ctx, config)` call registers the `Sleep` tool into `ctx.tools`. Requires a loaded `ctx.tools`; the plugin stays pending until `inject: ['tools']` is satisfied.
|
|
33
|
+
|
|
34
|
+
## Install / registration
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import * as ToolSleep from '@jianxx/dsh-cc-tool-sleep'
|
|
38
|
+
|
|
39
|
+
await ctx.plugin(ToolRuntime) // @jianxx/dsh-cc-tools
|
|
40
|
+
await ctx.plugin(ToolSleep) // registers the Sleep tool
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Choice of semantics
|
|
44
|
+
|
|
45
|
+
- **Duration in seconds** matches the model-facing parameter contract.
|
|
46
|
+
- **Interrupt-cancel** via `exec.signal` reproduces CC's behavior where a user prompt during sleep interrupts and cancels the current turn.
|
|
47
|
+
- **Concurrency-safe** so `Sleep` never forms an ordering barrier against sibling calls.
|
|
48
|
+
|
|
49
|
+
## Build order
|
|
50
|
+
|
|
51
|
+
`tool-sleep` depends only on the workspace `@jianxx/dsh-cc-tools` package and harness base packages (`@deepseek-ai/cordis`, `@deepseek-ai/dsh-llm`, `@deepseek-ai/dsh-invariants`, `@deepseek-ai/schemastery`). It has no dependency on git-worktree or any other workspace package, so it builds as soon as `core/tools` does; `tsc -b` resolves the reference order automatically.
|
|
52
|
+
|
|
53
|
+
## Known limitations
|
|
54
|
+
|
|
55
|
+
- The `minDurationSeconds` / `maxDurationSeconds` clamps are a loose analog of CC's `minSleepDurationMs` / `maxSleepDurationMs` process settings; they are per-`apply` config here rather than global runtime settings.
|
|
56
|
+
- No `tick`/progress steaming is emitted (CC emits `sleep_progress` ticks in its REPL); the wait is silent on the protocol level.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @jianxx/dsh-cc-tool-sleep
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 中文
|
|
4
|
+
|
|
5
|
+
模型侧 `Sleep` 工具:等待指定时长,并支持协作式取消,语义对齐 Claude Code 的 `SleepTool`。通过 `@jianxx/dsh-cc-tools` 的 `ToolRuntime` 注册进 `ctx.tools`。
|
|
6
|
+
|
|
7
|
+
## 工具
|
|
8
|
+
|
|
9
|
+
### `Sleep`
|
|
10
|
+
|
|
11
|
+
等待 `{ duration }` 秒。
|
|
12
|
+
|
|
13
|
+
| 参数 | 类型 | 说明 |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `duration` | number | 等待的秒数。必须为有限、非负数。`0` 为 no-op。 |
|
|
16
|
+
|
|
17
|
+
等待是协作式可取消的:同时挂起一个定时器与针对 `exec.signal` 的 `abort` 监听器,谁先触发就先 settle。若新一轮会话在睡眠中途取消该调用,工具会立即停止等待并返回规范的 `ABORTED` 结果——与 CC 的 `interruptBehavior: 'cancel'` 一致。
|
|
18
|
+
|
|
19
|
+
该工具为 `isConcurrencySafe = () => true`,因此可以与其他工具调用重叠(CC:"You can call this concurrently with other tools — it won't interfere with them")。优先于 spawn 一个睡眠子进程,因为它不占用子进程或 shell。
|
|
20
|
+
|
|
21
|
+
## 配置
|
|
22
|
+
|
|
23
|
+
`Config` 采用 schemastery 类型(沿用 git-worktree 工具的惯例):
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
export const Config = z.object({
|
|
27
|
+
minDurationSeconds: z.number(), // 可选下限(向上钳制)
|
|
28
|
+
maxDurationSeconds: z.number(), // 可选上限(向下钳制)
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
每次 `apply(ctx, config)` 都会把 `Sleep` 工具注册进 `ctx.tools`。需要已加载的 `ctx.tools`;在 `inject: ['tools']` 满足之前,插件保持等待状态。
|
|
33
|
+
|
|
34
|
+
## 安装 / 注册
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import * as ToolSleep from '@jianxx/dsh-cc-tool-sleep'
|
|
38
|
+
|
|
39
|
+
await ctx.plugin(ToolRuntime) // @jianxx/dsh-cc-tools
|
|
40
|
+
await ctx.plugin(ToolSleep) // 注册 Sleep 工具
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 语义取舍
|
|
44
|
+
|
|
45
|
+
- **以秒为单位**的时长契合模型侧参数契约。
|
|
46
|
+
- **中断即取消**:通过 `exec.signal` 复现 CC 在睡眠途中收到新用户提示时中断并取消当前回合的行为。
|
|
47
|
+
- **并发安全**:`Sleep` 不会对并行的兄弟调用形成顺序屏障。
|
|
48
|
+
|
|
49
|
+
## 构建顺序
|
|
50
|
+
|
|
51
|
+
`tool-sleep` 仅依赖工作区 `@jianxx/dsh-cc-tools` 包与 harness 基础包(`@deepseek-ai/cordis`、`@deepseek-ai/dsh-llm`、`@deepseek-ai/dsh-invariants`、`@deepseek-ai/schemastery`)。它不依赖 git-worktree 或任何其它工作区包,因此只要 `core/tools` 构建完成即可构建;`tsc -b` 会自动解析引用顺序。
|
|
52
|
+
|
|
53
|
+
## 已知限制
|
|
54
|
+
|
|
55
|
+
- `minDurationSeconds` / `maxDurationSeconds` 钳制是 CC 的 `minSleepDurationMs` / `maxSleepDurationMs` 进程设置的松散对应物;此处为每次 `apply` 的配置,而非全局运行时设置。
|
|
56
|
+
- 不发出 `tick`/进度流(CC 在 REPL 中会发出 `sleep_progress` tick);等待在协议层是静默的。
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing `Sleep` tool that waits a specified duration with cooperative
|
|
3
|
+
* cancellation. Aligns with Claude Code's SleepTool semantics: the input is a
|
|
4
|
+
* `{ duration }` in seconds, the wait is interruptible (a new turn cancels it
|
|
5
|
+
* like CC's `interruptBehavior: 'cancel'`), and the tool is concurrency-safe
|
|
6
|
+
* so it may overlap sibling calls.
|
|
7
|
+
* @module @jianxx/dsh-cc-tool-sleep
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
+
import z from '@deepseek-ai/schemastery';
|
|
11
|
+
export declare const name = "tool-sleep";
|
|
12
|
+
export declare const inject: string[];
|
|
13
|
+
/** Runtime configuration for the Sleep tool. */
|
|
14
|
+
export interface Config {
|
|
15
|
+
/**
|
|
16
|
+
* Optional lower bound (seconds) that a `Sleep` call must wait for, used to
|
|
17
|
+
* throttle busy-waiting; positive values clamp short durations up. Mirrors
|
|
18
|
+
* CC's `minSleepDurationMs` in spirit.
|
|
19
|
+
*/
|
|
20
|
+
minDurationSeconds?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Optional upper bound (seconds) that a `Sleep` call may wait for; a request
|
|
23
|
+
* above it is clamped down. Mirrors CC's `maxSleepDurationMs` in spirit.
|
|
24
|
+
*/
|
|
25
|
+
maxDurationSeconds?: number;
|
|
26
|
+
}
|
|
27
|
+
/** Runtime configuration schema. */
|
|
28
|
+
export declare const Config: z<Config>;
|
|
29
|
+
/** Arguments accepted by the Sleep tool. */
|
|
30
|
+
export interface SleepToolArgs {
|
|
31
|
+
/** How long to wait, in seconds. */
|
|
32
|
+
duration: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function apply(ctx: Context, config?: Config): void;
|
|
35
|
+
export { presentSleepCall, presentSleepResult } from './render.ts';
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAMxC,eAAO,MAAM,IAAI,eAAe,CAAA;AAChC,eAAO,MAAM,MAAM,UAAY,CAAA;AAE/B,gDAAgD;AAChD,MAAM,WAAW,MAAM;IACrB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,oCAAoC;AACpC,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAG3B,CAAA;AAEF,4CAA4C;AAC5C,MAAM,WAAW,aAAa;IAC5B,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAA;CACjB;AA6CD,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,MAAW,GAAG,IAAI,CAsD7D;AAED,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing `Sleep` tool that waits a specified duration with cooperative
|
|
3
|
+
* cancellation. Aligns with Claude Code's SleepTool semantics: the input is a
|
|
4
|
+
* `{ duration }` in seconds, the wait is interruptible (a new turn cancels it
|
|
5
|
+
* like CC's `interruptBehavior: 'cancel'`), and the tool is concurrency-safe
|
|
6
|
+
* so it may overlap sibling calls.
|
|
7
|
+
* @module @jianxx/dsh-cc-tool-sleep
|
|
8
|
+
*/
|
|
9
|
+
import z from '@deepseek-ai/schemastery';
|
|
10
|
+
import { HarnessError } from '@deepseek-ai/dsh-llm';
|
|
11
|
+
import { defineTool, TOOL_ABORTED } from '@jianxx/dsh-cc-tools';
|
|
12
|
+
import { presentSleepCall, presentSleepResult } from "./render.js";
|
|
13
|
+
export const name = 'tool-sleep';
|
|
14
|
+
export const inject = ['tools'];
|
|
15
|
+
/** Runtime configuration schema. */
|
|
16
|
+
export const Config = z.object({
|
|
17
|
+
minDurationSeconds: z.number(),
|
|
18
|
+
maxDurationSeconds: z.number(),
|
|
19
|
+
});
|
|
20
|
+
/** Structured, model-visible failure (maps to an isError tool result). */
|
|
21
|
+
class SleepError extends Error {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A `HarnessError` that surfaces as the canonical tool-aborted outcome
|
|
25
|
+
* (`name: AbortError`, `code: TOOL_ABORTED`) — the same shape the harness
|
|
26
|
+
* produces when cancellation supersedes a body and the shape CC uses when a
|
|
27
|
+
* user interrupts the sleep turn (`interruptBehavior: 'cancel'`).
|
|
28
|
+
* @param signal - the aborted tool-call signal whose `reason` is preserved.
|
|
29
|
+
* @returns the abort error to throw.
|
|
30
|
+
*/
|
|
31
|
+
function abortError(signal) {
|
|
32
|
+
const error = new HarnessError('tool call aborted', TOOL_ABORTED, { cause: signal.reason });
|
|
33
|
+
error.name = 'AbortError';
|
|
34
|
+
return error;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Wait for a wall-clock duration, resolving early (with an abort error) the
|
|
38
|
+
* moment `signal` fires. Cooperative: the waiter never spins; it arms a timer
|
|
39
|
+
* for `ms` and an `abort` listener, then settles on whichever fires first.
|
|
40
|
+
* @param ms - the wait duration in milliseconds.
|
|
41
|
+
* @param signal - the tool-call cancellation signal.
|
|
42
|
+
* @returns a promise resolving after `ms`, or rejecting with the abort error on cancellation.
|
|
43
|
+
*/
|
|
44
|
+
function waitFor(ms, signal) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
if (signal.aborted) {
|
|
47
|
+
reject(abortError(signal));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const fail = () => {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
reject(abortError(signal));
|
|
53
|
+
};
|
|
54
|
+
const timer = setTimeout(() => {
|
|
55
|
+
signal.removeEventListener('abort', fail);
|
|
56
|
+
resolve();
|
|
57
|
+
}, ms);
|
|
58
|
+
signal.addEventListener('abort', fail, { once: true });
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export function apply(ctx, config = {}) {
|
|
62
|
+
const minMs = config.minDurationSeconds !== undefined ? config.minDurationSeconds * 1000 : 0;
|
|
63
|
+
const maxMs = config.maxDurationSeconds !== undefined ? config.maxDurationSeconds * 1000 : Number.POSITIVE_INFINITY;
|
|
64
|
+
ctx.tools.register(defineTool({
|
|
65
|
+
name: 'Sleep',
|
|
66
|
+
description: 'Wait for a specified duration. Use this when the user tells you to sleep or rest, when you have '
|
|
67
|
+
+ 'nothing to do, or when you are waiting for something. The user can interrupt the sleep at any time. '
|
|
68
|
+
+ 'This tool is concurrency-safe: you can call it concurrently with other tools — it will not interfere '
|
|
69
|
+
+ 'with them. Prefer this over running a sleep command, because it does not hold a subprocess. '
|
|
70
|
+
+ 'Sleep for a short enough duration that you wake up and are ready when the thing you are waiting for '
|
|
71
|
+
+ 'is likely to be ready; each wake-up costs an API call.',
|
|
72
|
+
parameters: {
|
|
73
|
+
duration: {
|
|
74
|
+
type: 'number',
|
|
75
|
+
description: 'How long to wait, in seconds. Must be a finite, non-negative number.',
|
|
76
|
+
required: true,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
output: {
|
|
80
|
+
schema: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
properties: {
|
|
84
|
+
duration: { type: 'number', required: true },
|
|
85
|
+
message: { type: 'string', required: true },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
render: (_args, value) => [{ type: 'text', text: value.message }],
|
|
89
|
+
},
|
|
90
|
+
isConcurrencySafe: () => true,
|
|
91
|
+
presentCall: presentSleepCall,
|
|
92
|
+
presentResult: presentSleepResult,
|
|
93
|
+
async execute(args, exec) {
|
|
94
|
+
let seconds = args.duration;
|
|
95
|
+
if (!Number.isFinite(seconds) || seconds < 0) {
|
|
96
|
+
throw new SleepError(`Sleep duration must be a finite, non-negative number of seconds (got ${JSON.stringify(args.duration)})`);
|
|
97
|
+
}
|
|
98
|
+
const ms = seconds * 1000;
|
|
99
|
+
const clampedMs = Math.min(Math.max(ms, minMs), maxMs);
|
|
100
|
+
seconds = clampedMs / 1000;
|
|
101
|
+
await waitFor(clampedMs, exec.signal);
|
|
102
|
+
return {
|
|
103
|
+
duration: seconds,
|
|
104
|
+
message: `Slept for ${seconds} second${seconds === 1 ? '' : 's'}.`,
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
export { presentSleepCall, presentSleepResult } from "./render.js";
|
|
110
|
+
//# 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;;;;;;;GAOG;AAGH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAA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AAC,OAAO,EAAE,CAAC;SAC1C;QACD,iBAAiB,EAAE,GAAG,EAAE,CAAC,IAAI;QAC7B,WAAW,EAAE,gBAAgB;QAC7B,aAAa,EAAE,kBAAkB;QACjC,KAAK,CAAC,OAAO,CAAC,IAAmB,EAAE,IAAoB;YACrD,IAAI,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAA;YAC3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;gBAC7C,MAAM,IAAI,UAAU,CAClB,wEAAwE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CACzG,CAAA;YACH,CAAC;YACD,MAAM,EAAE,GAAG,OAAO,GAAG,IAAI,CAAA;YACzB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;YACtD,OAAO,GAAG,SAAS,GAAG,IAAI,CAAA;YAE1B,MAAM,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;YAErC,OAAO;gBACL,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,aAAa,OAAO,UAAU,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;aACnE,CAAA;QACH,CAAC;KACF,CAAC,CAAC,CAAA;AACL,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@jianxx/dsh-cc-tool-sleep`.
|
|
3
|
+
* @module @jianxx/dsh-cc-tool-sleep/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export declare const name = "tool-sleep-invariant";
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export declare const inject: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Register this package's invariant companion.
|
|
12
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
14
|
+
*/
|
|
15
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
16
|
+
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,oCAAoC;AACpC,eAAO,MAAM,IAAI,yBAAyB,CAAA;AAC1C,2EAA2E;AAC3E,eAAO,MAAM,MAAM,UAAiB,CAAA;AASpC;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,OAAO,KAAG,OAAO,CAAC,MAAM,IAAI,CACU,CAAA"}
|
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@jianxx/dsh-cc-tool-sleep`.
|
|
3
|
+
* @module @jianxx/dsh-cc-tool-sleep/invariant
|
|
4
|
+
*/
|
|
5
|
+
const PACKAGE_NAME = '@jianxx/dsh-cc-tool-sleep';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export const name = 'tool-sleep-invariant';
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export const inject = ['invariants'];
|
|
10
|
+
/**
|
|
11
|
+
* No runtime invariant: Sleep waits on a wall-clock timer and a cancellation
|
|
12
|
+
* signal, neither of which publishes a durable projection a companion could
|
|
13
|
+
* cross-check.
|
|
14
|
+
*/
|
|
15
|
+
const install = () => { };
|
|
16
|
+
/**
|
|
17
|
+
* Register this package's invariant companion.
|
|
18
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
19
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
20
|
+
*/
|
|
21
|
+
export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
22
|
+
/* jscpd:ignore-end */
|
|
23
|
+
//# sourceMappingURL=invariant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.js","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,YAAY,GAAG,2BAA2B,CAAA;AAEhD,oCAAoC;AACpC,MAAM,CAAC,MAAM,IAAI,GAAG,sBAAsB,CAAA;AAC1C,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAAY,CAAC,CAAA;AAEpC;;;;GAIG;AACH,MAAM,OAAO,GAAuB,GAAG,EAAE,GAAE,CAAC,CAAA;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAY,EAAuB,EAAE,CACzD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;AACjE,sBAAsB"}
|
package/lib/render.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure presentation (presentCall / presentResult) for the Sleep tool: a
|
|
3
|
+
* generic pending card naming the requested duration, and a generic result
|
|
4
|
+
* card that fences errors so a failure reads distinct from a success summary.
|
|
5
|
+
* @module @jianxx/dsh-cc-tool-sleep/render
|
|
6
|
+
*/
|
|
7
|
+
import type { GenericCallView, ToolResult, ToolResultView } from '@jianxx/dsh-cc-tools';
|
|
8
|
+
/** Arguments accepted by the Sleep tool. */
|
|
9
|
+
export interface SleepToolArgs {
|
|
10
|
+
/** How long to wait, in seconds. */
|
|
11
|
+
duration: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Present a Sleep pending call as a generic execute card naming the duration.
|
|
15
|
+
* @param args - validated tool arguments.
|
|
16
|
+
* @returns a generic card view.
|
|
17
|
+
*/
|
|
18
|
+
export declare function presentSleepCall(args: SleepToolArgs): GenericCallView;
|
|
19
|
+
/**
|
|
20
|
+
* Present a Sleep result as a generic card. Success shows the plain message;
|
|
21
|
+
* errors are fenced so a failure is visually distinct from a success summary.
|
|
22
|
+
* @param _args - validated tool arguments (unused by the presenter).
|
|
23
|
+
* @param result - the finalized tool result.
|
|
24
|
+
* @returns a generic card view, or `undefined` for an unexpected shape.
|
|
25
|
+
*/
|
|
26
|
+
export declare function presentSleepResult(_args: unknown, result: ToolResult): ToolResultView | undefined;
|
|
27
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAEvF,4CAA4C;AAC5C,MAAM,WAAW,aAAa;IAC5B,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,GAAG,eAAe,CAcrE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,GAAG,cAAc,GAAG,SAAS,CAMjG"}
|
package/lib/render.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure presentation (presentCall / presentResult) for the Sleep tool: a
|
|
3
|
+
* generic pending card naming the requested duration, and a generic result
|
|
4
|
+
* card that fences errors so a failure reads distinct from a success summary.
|
|
5
|
+
* @module @jianxx/dsh-cc-tool-sleep/render
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Present a Sleep pending call as a generic execute card naming the duration.
|
|
9
|
+
* @param args - validated tool arguments.
|
|
10
|
+
* @returns a generic card view.
|
|
11
|
+
*/
|
|
12
|
+
export function presentSleepCall(args) {
|
|
13
|
+
const seconds = args.duration;
|
|
14
|
+
return {
|
|
15
|
+
card: 'generic',
|
|
16
|
+
title: 'Sleeping',
|
|
17
|
+
kind: 'execute',
|
|
18
|
+
rawInput: `${seconds} ${seconds === 1 ? 'second' : 'seconds'}`,
|
|
19
|
+
content: [
|
|
20
|
+
{
|
|
21
|
+
type: 'text',
|
|
22
|
+
text: `Wait for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}.`,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Present a Sleep result as a generic card. Success shows the plain message;
|
|
29
|
+
* errors are fenced so a failure is visually distinct from a success summary.
|
|
30
|
+
* @param _args - validated tool arguments (unused by the presenter).
|
|
31
|
+
* @param result - the finalized tool result.
|
|
32
|
+
* @returns a generic card view, or `undefined` for an unexpected shape.
|
|
33
|
+
*/
|
|
34
|
+
export function presentSleepResult(_args, result) {
|
|
35
|
+
const block = result.content.length === 1 ? result.content[0] : undefined;
|
|
36
|
+
if (block === undefined || block.type !== 'text')
|
|
37
|
+
return undefined;
|
|
38
|
+
return result.isError
|
|
39
|
+
? { card: 'generic', content: [{ type: 'text', text: `\`\`\`\n${block.text.replace(/\n+$/, '')}\n\`\`\`` }] }
|
|
40
|
+
: { card: 'generic', content: [{ type: 'text', text: block.text }] };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAmB;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,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align with Claude Code's SleepTool duration, interrupt-cancel, and concurrency semantics",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/jianxx/dsh-cc-plugins.git",
|
|
8
|
+
"directory": "packages/core/tool-sleep"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./invariant": {
|
|
17
|
+
"types": "./lib/invariant.d.ts",
|
|
18
|
+
"default": "./lib/invariant.js"
|
|
19
|
+
},
|
|
20
|
+
"./src/*": "./src/*",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"lib"
|
|
25
|
+
],
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@deepseek-ai/dsh-llm": ">=0.1.1-rc.2",
|
|
29
|
+
"@deepseek-ai/dsh-invariants": ">=0.1.1-rc.2",
|
|
30
|
+
"@deepseek-ai/cordis": ">=0.1.1-rc.2",
|
|
31
|
+
"@deepseek-ai/schemastery": "^3.18.1",
|
|
32
|
+
"@jianxx/dsh-cc-tools": "^0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@deepseek-ai/dsh-llm": "link:../../../../deepseek-harness/packages/llm/llm",
|
|
36
|
+
"@deepseek-ai/dsh-invariants": "link:../../../../deepseek-harness/packages/runtime-diagnostics/invariants",
|
|
37
|
+
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|
|
38
|
+
"@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery",
|
|
39
|
+
"@deepseek-ai/dsh-system-prompt": "link:../../../../deepseek-harness/packages/core/system-prompt",
|
|
40
|
+
"@jianxx/dsh-cc-tools": "^0.1.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|