@dsh-cc/command-export 0.5.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 +50 -0
- package/README.zh.md +50 -0
- package/lib/index.d.ts +52 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +113 -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/transcript.d.ts +46 -0
- package/lib/transcript.d.ts.map +1 -0
- package/lib/transcript.js +83 -0
- package/lib/transcript.js.map +1 -0
- package/package.json +50 -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/session/command-export/README.md
|
|
5
|
+
README.md: 5159b831a8a7804e4537d9fe4d31188515f54a96
|
|
6
|
+
README.zh.md: 25548f2b394510f3be9a6166ea1b8c50ec00bd51
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @dsh-cc/command-export
|
|
2
|
+
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
Human-facing `/export` command that writes the current session transcript to a file through [`ctx.fs`](../../fs/fs/README.md) as markdown (default) or lossless JSON. The plugin registers one global command through [`ctx.commands`](../../interaction/commands/README.md), so every composed command adapter discovers and executes it without a model turn.
|
|
6
|
+
|
|
7
|
+
## Command contract
|
|
8
|
+
|
|
9
|
+
| Input | Result |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `/export` | Write a markdown transcript of the session to `<defaultDir>/transcript-<sessionId>.md` and report the written path and byte count. |
|
|
12
|
+
| `/export json` | Write a lossless JSON transcript (the raw event log) instead. |
|
|
13
|
+
| `/export [json] <path>` | Write to `<path>` (a trailing `/` or a bare name resolves against the default directory; a `.md`/`.json` extension is honored, otherwise appended). |
|
|
14
|
+
|
|
15
|
+
The markdown transcript renders each model-visible event (user, assistant, tool result) as a section; a session with no conversation events exports a document that says so. The JSON transcript is the raw durable event log, so command lifecycle (and any) records appear verbatim alongside conversation events.
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
The plugin `Config` carries the default export directory:
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
- id: command-export
|
|
23
|
+
name: '@dsh-cc/command-export'
|
|
24
|
+
config:
|
|
25
|
+
defaultDir: ./exports
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
When no explicit path is supplied the transcript is written under `defaultDir`; an explicit path overrides it.
|
|
29
|
+
|
|
30
|
+
## Composition
|
|
31
|
+
|
|
32
|
+
The producer injects `commands` and `fs`. A custom app mounts their owners plus this plugin:
|
|
33
|
+
|
|
34
|
+
```yaml
|
|
35
|
+
- id: commands
|
|
36
|
+
name: '@deepseek-ai/dsh-commands'
|
|
37
|
+
- id: fs
|
|
38
|
+
name: '@deepseek-ai/dsh-fs-local'
|
|
39
|
+
- id: command-export
|
|
40
|
+
name: '@dsh-cc/command-export'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Model Experience
|
|
44
|
+
|
|
45
|
+
The slash input, the file write, and the direct success/error output are absent from model requests and consume no model tokens. Rendering is a pure function of the session log; presentation text is never logged.
|
|
46
|
+
|
|
47
|
+
## Known Limitations and Deferred Work
|
|
48
|
+
|
|
49
|
+
- **No archive directory creation** — the target directory must exist; the filesystem seam does not mkdir.
|
|
50
|
+
- **Plain-text-only output** — HTML, PDF, or sanitized redacted transcripts remain future work.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @dsh-cc/command-export
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 中文
|
|
4
|
+
|
|
5
|
+
面向用户的 `/export` 命令,通过 [`ctx.fs`](../../fs/fs/README.md) 把当前会话 transcript 写入文件,格式为 markdown(默认)或无损 JSON。该插件通过 [`ctx.commands`](../../interaction/commands/README.md) 注册一个全局命令,因此每个已组合的命令适配器都能发现并执行它,无需模型轮次。
|
|
6
|
+
|
|
7
|
+
## 命令约定
|
|
8
|
+
|
|
9
|
+
| 输入 | 结果 |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `/export` | 将会话的 markdown transcript 写入 `<defaultDir>/transcript-<sessionId>.md`,并报告写入路径与字节数。 |
|
|
12
|
+
| `/export json` | 改为写入无损 JSON transcript(原始事件日志)。 |
|
|
13
|
+
| `/export [json] <path>` | 写入 `<path>`(结尾 `/` 或裸文件名会解析到默认目录;识别 `.md`/`.json` 后缀,否则自动追加)。 |
|
|
14
|
+
|
|
15
|
+
markdown transcript 会把每个对模型可见的事件(用户、助手、工具结果)渲染为一个小节;没有任何会话事件的会话会导出一个声明性的文档。JSON transcript 是原始持久事件日志,因此命令生命周期(及其他)记录会与对话事件一起按原样出现。
|
|
16
|
+
|
|
17
|
+
## 配置
|
|
18
|
+
|
|
19
|
+
插件 `Config` 承载默认导出目录:
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
- id: command-export
|
|
23
|
+
name: '@dsh-cc/command-export'
|
|
24
|
+
config:
|
|
25
|
+
defaultDir: ./exports
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
未提供显式路径时,transcript 会写入 `defaultDir` 下;显式路径会覆盖它。
|
|
29
|
+
|
|
30
|
+
## 组合
|
|
31
|
+
|
|
32
|
+
生产方注入 `commands` 与 `fs`。自定义应用会挂载它们的拥有者与此插件:
|
|
33
|
+
|
|
34
|
+
```yaml
|
|
35
|
+
- id: commands
|
|
36
|
+
name: '@deepseek-ai/dsh-commands'
|
|
37
|
+
- id: fs
|
|
38
|
+
name: '@deepseek-ai/dsh-fs-local'
|
|
39
|
+
- id: command-export
|
|
40
|
+
name: '@dsh-cc/command-export'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 模型体验
|
|
44
|
+
|
|
45
|
+
斜杠输入、文件写入与直接的成功/错误输出都不会进入模型请求,也不消耗模型 token。渲染是会话日志的纯函数;呈现文本绝不会记录到日志中。
|
|
46
|
+
|
|
47
|
+
## 已知限制与暂缓事项
|
|
48
|
+
|
|
49
|
+
- **不创建归档目录**:目标目录必须已存在;文件系统接缝不做 mkdir。
|
|
50
|
+
- **仅纯文本输出**:HTML、PDF 或脱敏后的精简 transcript 仍属于未来工作。
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-facing `/export` command: writes the current session transcript to a
|
|
3
|
+
* file through `ctx.fs` as markdown (default) or lossless JSON.
|
|
4
|
+
* @module @dsh-cc/command-export
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
7
|
+
import z from '@deepseek-ai/schemastery';
|
|
8
|
+
import { type ExportFormat } from './transcript.ts';
|
|
9
|
+
export declare const name = "command-export";
|
|
10
|
+
export declare const inject: string[];
|
|
11
|
+
/** `/export` configuration: the default export directory. */
|
|
12
|
+
export interface Config {
|
|
13
|
+
/** Directory written to when no output path is supplied. */
|
|
14
|
+
readonly defaultDir: string;
|
|
15
|
+
}
|
|
16
|
+
/** Loader schema; an empty default directory falls back to the current working directory. */
|
|
17
|
+
export declare const Config: z<Schemastery.ObjectS<{
|
|
18
|
+
defaultDir: z<string, string>;
|
|
19
|
+
}>, Schemastery.ObjectT<{
|
|
20
|
+
defaultDir: z<string, string>;
|
|
21
|
+
}>>;
|
|
22
|
+
/** One parsed `/export` invocation. */
|
|
23
|
+
export interface ExportRequest {
|
|
24
|
+
readonly format: ExportFormat;
|
|
25
|
+
/** Exact output path after the format token, or undefined to use the default directory. */
|
|
26
|
+
readonly path: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parse the `/export` argument line into a format and optional path.
|
|
30
|
+
* @param rawInput - exact text following the command name.
|
|
31
|
+
* @returns the parsed format and path (or undefined when no path was supplied).
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseExport(rawInput: string): ExportRequest;
|
|
34
|
+
/**
|
|
35
|
+
* Split an output path into directory and file components, applying the format
|
|
36
|
+
* extension and the default directory when either part is absent.
|
|
37
|
+
* @param config - command configuration carrying the default directory.
|
|
38
|
+
* @param request - parsed invocation.
|
|
39
|
+
* @param sessionId - owning session id used for the default file name.
|
|
40
|
+
* @returns the resolved directory and file name.
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveOutput(config: Config, request: ExportRequest, sessionId: string): {
|
|
43
|
+
dir: string;
|
|
44
|
+
name: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Register the `/export` command for every composed command adapter.
|
|
48
|
+
* @param ctx - context carrying the command registry and filesystem service.
|
|
49
|
+
* @param config - default export directory.
|
|
50
|
+
*/
|
|
51
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAErE,eAAO,MAAM,IAAI,mBAAmB,CAAA;AACpC,eAAO,MAAM,MAAM,UAAqB,CAAA;AAExC,6DAA6D;AAC7D,MAAM,WAAW,MAAM;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B;AAED,6FAA6F;AAC7F,eAAO,MAAM,MAAM;;;;GAEjB,CAAA;AAEF,uCAAuC;AACvC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;IAC7B,2FAA2F;IAC3F,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;CAClC;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAS3D;AAUD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,GAAG;IACxF,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb,CAYA;AA2BD;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CA0BxD"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-facing `/export` command: writes the current session transcript to a
|
|
3
|
+
* file through `ctx.fs` as markdown (default) or lossless JSON.
|
|
4
|
+
* @module @dsh-cc/command-export
|
|
5
|
+
*/
|
|
6
|
+
import z from '@deepseek-ai/schemastery';
|
|
7
|
+
import { renderTranscript } from "./transcript.js";
|
|
8
|
+
export const name = 'command-export';
|
|
9
|
+
export const inject = ['commands', 'fs'];
|
|
10
|
+
/** Loader schema; an empty default directory falls back to the current working directory. */
|
|
11
|
+
export const Config = z.object({
|
|
12
|
+
defaultDir: z.string().default(''),
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Parse the `/export` argument line into a format and optional path.
|
|
16
|
+
* @param rawInput - exact text following the command name.
|
|
17
|
+
* @returns the parsed format and path (or undefined when no path was supplied).
|
|
18
|
+
*/
|
|
19
|
+
export function parseExport(rawInput) {
|
|
20
|
+
const tokens = rawInput.trim().split(/\s+/u).filter(token => token.length > 0);
|
|
21
|
+
let format = 'markdown';
|
|
22
|
+
const rest = [];
|
|
23
|
+
for (const token of tokens) {
|
|
24
|
+
if (format === 'markdown' && token.startsWith('json') && !rest.includes(token))
|
|
25
|
+
format = 'json';
|
|
26
|
+
else
|
|
27
|
+
rest.push(token);
|
|
28
|
+
}
|
|
29
|
+
return { format, path: rest.length === 0 ? undefined : rest.join(' ') };
|
|
30
|
+
}
|
|
31
|
+
/** File extension per export format. */
|
|
32
|
+
const EXTENSION = { markdown: '.md', json: '.json' };
|
|
33
|
+
/** The default output file name derived from the session id. */
|
|
34
|
+
function defaultName(sessionId) {
|
|
35
|
+
return `transcript-${sessionId.replace(/[^a-zA-Z0-9._-]/u, '-')}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Split an output path into directory and file components, applying the format
|
|
39
|
+
* extension and the default directory when either part is absent.
|
|
40
|
+
* @param config - command configuration carrying the default directory.
|
|
41
|
+
* @param request - parsed invocation.
|
|
42
|
+
* @param sessionId - owning session id used for the default file name.
|
|
43
|
+
* @returns the resolved directory and file name.
|
|
44
|
+
*/
|
|
45
|
+
export function resolveOutput(config, request, sessionId) {
|
|
46
|
+
const ext = EXTENSION[request.format];
|
|
47
|
+
const name = defaultName(sessionId);
|
|
48
|
+
if (request.path === undefined)
|
|
49
|
+
return { dir: config.defaultDir, name: `${name}${ext}` };
|
|
50
|
+
const trimmed = request.path.trim();
|
|
51
|
+
if (trimmed.length === 0)
|
|
52
|
+
return { dir: config.defaultDir, name: `${name}${ext}` };
|
|
53
|
+
if (trimmed.endsWith('/'))
|
|
54
|
+
return { dir: trimmed.replace(/\/+$/u, ''), name: `${name}${ext}` };
|
|
55
|
+
const slash = trimmed.lastIndexOf('/');
|
|
56
|
+
const dir = slash === -1 ? config.defaultDir : trimmed.slice(0, slash);
|
|
57
|
+
const base = slash === -1 ? trimmed : trimmed.slice(slash + 1);
|
|
58
|
+
const tail = base.endsWith(ext) ? base : `${base}${ext}`;
|
|
59
|
+
return { dir, name: tail };
|
|
60
|
+
}
|
|
61
|
+
/** Execute `/export`, writing the transcript through the filesystem service. */
|
|
62
|
+
async function executeExport(ctx, config, request, invocation) {
|
|
63
|
+
const events = invocation.agent.session.events;
|
|
64
|
+
const sessionId = invocation.agent.session.id;
|
|
65
|
+
const { dir, name } = resolveOutput(config, request, sessionId);
|
|
66
|
+
const target = await ctx.fs.resolve(joinPath(dir, name));
|
|
67
|
+
const content = renderTranscript(events, request.format, sessionId);
|
|
68
|
+
await ctx.fs.writeText(target, content);
|
|
69
|
+
return {
|
|
70
|
+
kind: 'success',
|
|
71
|
+
text: `Exported ${request.format} transcript to ${ctx.fs.processPath(target)} (${content.length} bytes).`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Join a directory and file name into a single path without a trailing duplicate slash. */
|
|
75
|
+
function joinPath(dir, name) {
|
|
76
|
+
if (dir.length === 0)
|
|
77
|
+
return name;
|
|
78
|
+
return `${dir.replace(/\/+$/u, '')}/${name}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Register the `/export` command for every composed command adapter.
|
|
82
|
+
* @param ctx - context carrying the command registry and filesystem service.
|
|
83
|
+
* @param config - default export directory.
|
|
84
|
+
*/
|
|
85
|
+
export function apply(ctx, config) {
|
|
86
|
+
// Native /export comes from @deepseek-ai/dsh-session-log-export, mounted by
|
|
87
|
+
// dsh-web-app's session-log-download row on the WEB profile (a browser-download
|
|
88
|
+
// stub); it is absent on CLI-only profiles. We defer to it where the name is
|
|
89
|
+
// taken and register our file-writing /export only where it is free. Whether
|
|
90
|
+
// the native command is present is a property of the active runtime profile,
|
|
91
|
+
// not of any particular package version, and may change across releases.
|
|
92
|
+
//
|
|
93
|
+
// This behaviour depends on mount-order luck: bundles mount after base/web-app
|
|
94
|
+
// rows, so ours registers LAST — the native command is already registered on
|
|
95
|
+
// web when we get here, absent when not. Relies on the loader throwing a plain
|
|
96
|
+
// Error whose message matches /is already registered/ for a duplicate name.
|
|
97
|
+
try {
|
|
98
|
+
ctx.commands.register({
|
|
99
|
+
name: 'export',
|
|
100
|
+
description: 'export this session transcript to a markdown or json file',
|
|
101
|
+
input: { hint: '[json] [<path>]' },
|
|
102
|
+
handler: (invocation) => executeExport(ctx, config, parseExport(invocation.rawInput), invocation),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error instanceof Error && /is already registered/.test(error.message)) {
|
|
107
|
+
ctx.logger.info('native /export present, ours skipped');
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# 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;;;;GAIG;AAIH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,OAAO,EAAE,gBAAgB,EAAqB,MAAM,iBAAiB,CAAA;AAErE,MAAM,CAAC,MAAM,IAAI,GAAG,gBAAgB,CAAA;AACpC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAQxC,6FAA6F;AAC7F,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;CACnC,CAAC,CAAA;AASF;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,MA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AA6B,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;SACrH,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,KAAK,YAAY,KAAK,IAAI,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1E,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAA;YACvD,OAAM;QACR,CAAC;QACD,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@dsh-cc/command-export`.
|
|
3
|
+
* @module @dsh-cc/command-export/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export declare const name = "command-export-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,6BAA6B,CAAA;AAC9C,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 `@dsh-cc/command-export`.
|
|
3
|
+
* @module @dsh-cc/command-export/invariant
|
|
4
|
+
*/
|
|
5
|
+
const PACKAGE_NAME = '@dsh-cc/command-export';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export const name = 'command-export-invariant';
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export const inject = ['invariants'];
|
|
10
|
+
/**
|
|
11
|
+
* No runtime invariant: this command adapter owns no event stream or state projection; transcript
|
|
12
|
+
* rendering is a pure function over the session's authoritative event log, the filesystem seam owns
|
|
13
|
+
* write atomicity, and the command registry owns registration and dispatch lifecycle.
|
|
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,wBAAwB,CAAA;AAE7C,oCAAoC;AACpC,MAAM,CAAC,MAAM,IAAI,GAAG,0BAA0B,CAAA;AAC9C,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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure `/export` transcript rendering: session events → markdown or JSON text.
|
|
3
|
+
* No cordis imports, so both renderers are unit-testable in isolation.
|
|
4
|
+
* @module @dsh-cc/command-export/transcript
|
|
5
|
+
*/
|
|
6
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm';
|
|
7
|
+
import type { SessionEvent } from '@deepseek-ai/dsh-session';
|
|
8
|
+
/** The export file formats `/export` can render. */
|
|
9
|
+
export type ExportFormat = 'markdown' | 'json';
|
|
10
|
+
/**
|
|
11
|
+
* Extract user-visible text from one content block: visible text and reasoning
|
|
12
|
+
* as-is, everything else (image references, structured payloads) as compact JSON.
|
|
13
|
+
* @param block - one message content block.
|
|
14
|
+
* @returns its human-readable text.
|
|
15
|
+
*/
|
|
16
|
+
export declare function blockText(block: ContentBlock): string;
|
|
17
|
+
/**
|
|
18
|
+
* Render a whole message content array into readable text.
|
|
19
|
+
* @param blocks - the message's content blocks, in order.
|
|
20
|
+
* @returns joined block text with blank-line separation.
|
|
21
|
+
*/
|
|
22
|
+
export declare function contentText(blocks: readonly ContentBlock[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Render the session log as a readable markdown transcript. Only model-visible
|
|
25
|
+
* events (user, assistant, tool result) become sections; boundary, chunk, and
|
|
26
|
+
* log-only records are trace data and are omitted from the transcript.
|
|
27
|
+
* @param events - the session's durable event log, in sequence order.
|
|
28
|
+
* @param title - the session id or title used for the document heading.
|
|
29
|
+
* @returns the complete markdown document.
|
|
30
|
+
*/
|
|
31
|
+
export declare function renderMarkdown(events: readonly SessionEvent[], title: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Render the session log as a lossless JSON transcript (the raw event array).
|
|
34
|
+
* @param events - the session's durable event log, in sequence order.
|
|
35
|
+
* @returns the JSON document with stable indentation.
|
|
36
|
+
*/
|
|
37
|
+
export declare function renderJson(events: readonly SessionEvent[]): string;
|
|
38
|
+
/**
|
|
39
|
+
* Render a transcript in either supported format.
|
|
40
|
+
* @param events - the session's durable event log.
|
|
41
|
+
* @param format - `'markdown'` or `'json'`.
|
|
42
|
+
* @param title - session label used by the markdown renderer.
|
|
43
|
+
* @returns the complete document text.
|
|
44
|
+
*/
|
|
45
|
+
export declare function renderTranscript(events: readonly SessionEvent[], format: ExportFormat, title: string): string;
|
|
46
|
+
//# sourceMappingURL=transcript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../src/transcript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAE5D,oDAAoD;AACpD,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,MAAM,CAAA;AAE9C;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAQrD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,MAAM,CAEnE;AAgBD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAarF;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,MAAM,CAElE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,YAAY,EAAE,EAC/B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,MAAM,GACZ,MAAM,CAER"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure `/export` transcript rendering: session events → markdown or JSON text.
|
|
3
|
+
* No cordis imports, so both renderers are unit-testable in isolation.
|
|
4
|
+
* @module @dsh-cc/command-export/transcript
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Extract user-visible text from one content block: visible text and reasoning
|
|
8
|
+
* as-is, everything else (image references, structured payloads) as compact JSON.
|
|
9
|
+
* @param block - one message content block.
|
|
10
|
+
* @returns its human-readable text.
|
|
11
|
+
*/
|
|
12
|
+
export function blockText(block) {
|
|
13
|
+
switch (block.type) {
|
|
14
|
+
case 'text':
|
|
15
|
+
case 'reasoning':
|
|
16
|
+
return block.text;
|
|
17
|
+
default:
|
|
18
|
+
return JSON.stringify(block);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Render a whole message content array into readable text.
|
|
23
|
+
* @param blocks - the message's content blocks, in order.
|
|
24
|
+
* @returns joined block text with blank-line separation.
|
|
25
|
+
*/
|
|
26
|
+
export function contentText(blocks) {
|
|
27
|
+
return blocks.map(blockText).filter(text => text.length > 0).join('\n');
|
|
28
|
+
}
|
|
29
|
+
/** Render one event into its markdown section body, or null for non-surface events. */
|
|
30
|
+
function eventMarkdown(event) {
|
|
31
|
+
switch (event.type) {
|
|
32
|
+
case 'user/message':
|
|
33
|
+
return { heading: 'User', body: contentText(event.data.content) };
|
|
34
|
+
case 'assistant/message':
|
|
35
|
+
return { heading: 'Assistant', body: contentText(event.data.message.content) };
|
|
36
|
+
case 'tool/result':
|
|
37
|
+
return { heading: 'Tool', body: contentText(event.data.message.content) };
|
|
38
|
+
default:
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Render the session log as a readable markdown transcript. Only model-visible
|
|
44
|
+
* events (user, assistant, tool result) become sections; boundary, chunk, and
|
|
45
|
+
* log-only records are trace data and are omitted from the transcript.
|
|
46
|
+
* @param events - the session's durable event log, in sequence order.
|
|
47
|
+
* @param title - the session id or title used for the document heading.
|
|
48
|
+
* @returns the complete markdown document.
|
|
49
|
+
*/
|
|
50
|
+
export function renderMarkdown(events, title) {
|
|
51
|
+
const lines = [`# Session transcript: ${title}`, ''];
|
|
52
|
+
let exported = 0;
|
|
53
|
+
for (const event of events) {
|
|
54
|
+
const section = eventMarkdown(event);
|
|
55
|
+
if (section === null)
|
|
56
|
+
continue;
|
|
57
|
+
exported += 1;
|
|
58
|
+
lines.push(`## ${section.heading}`, '', section.body, '');
|
|
59
|
+
}
|
|
60
|
+
if (exported === 0) {
|
|
61
|
+
lines.push('_No conversation events recorded yet._', '');
|
|
62
|
+
}
|
|
63
|
+
return `${lines.join('\n')}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Render the session log as a lossless JSON transcript (the raw event array).
|
|
67
|
+
* @param events - the session's durable event log, in sequence order.
|
|
68
|
+
* @returns the JSON document with stable indentation.
|
|
69
|
+
*/
|
|
70
|
+
export function renderJson(events) {
|
|
71
|
+
return `${JSON.stringify(events, null, 2)}\n`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Render a transcript in either supported format.
|
|
75
|
+
* @param events - the session's durable event log.
|
|
76
|
+
* @param format - `'markdown'` or `'json'`.
|
|
77
|
+
* @param title - session label used by the markdown renderer.
|
|
78
|
+
* @returns the complete document text.
|
|
79
|
+
*/
|
|
80
|
+
export function renderTranscript(events, format, title) {
|
|
81
|
+
return format === 'markdown' ? renderMarkdown(events, title) : renderJson(events);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.js","sourceRoot":"","sources":["../src/transcript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAAmB;IAC3C,Q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AG,aAAa,CAAC,KAAK,CAAC,CAAA;QACpC,IAAI,OAAO,KAAK,IAAI;YAAE,SAAQ;QAC9B,QAAQ,IAAI,CAAC,CAAA;QACb,KAAK,CAAC,IAAI,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IAC3D,CAAC;IACD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,KAAK,CAAC,IAAI,CAAC,wCAAwC,EAAE,EAAE,CAAC,CAAA;IAC1D,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAA+B;IACxD,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAA;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAA+B,EAC/B,MAAoB,EACpB,KAAa;IAEb,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;AACnF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dsh-cc/command-export",
|
|
3
|
+
"description": "Human-facing slash command for exporting a session transcript to a file",
|
|
4
|
+
"version": "0.5.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
8
|
+
"directory": "packages/session/command-export"
|
|
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-commands": ">=0.1.1-rc.2",
|
|
29
|
+
"@deepseek-ai/dsh-fs": ">=0.1.1-rc.2",
|
|
30
|
+
"@deepseek-ai/dsh-invariants": ">=0.1.1-rc.2",
|
|
31
|
+
"@deepseek-ai/dsh-llm": ">=0.1.1-rc.2",
|
|
32
|
+
"@deepseek-ai/dsh-session": ">=0.1.1-rc.2",
|
|
33
|
+
"@deepseek-ai/cordis": ">=0.1.1-rc.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@deepseek-ai/cordis-plugin-loader": "link:../../../../deepseek-harness/vendor/loader",
|
|
37
|
+
"@deepseek-ai/dsh-agent": "link:../../../../deepseek-harness/packages/core/agent",
|
|
38
|
+
"@deepseek-ai/dsh-commands": "link:../../../../deepseek-harness/packages/interaction/commands",
|
|
39
|
+
"@deepseek-ai/dsh-fs": "link:../../../../deepseek-harness/packages/fs/fs",
|
|
40
|
+
"@deepseek-ai/dsh-fs-local": "link:../../../../deepseek-harness/packages/fs/fs-local",
|
|
41
|
+
"@deepseek-ai/dsh-invariants": "link:../../../../deepseek-harness/packages/runtime-diagnostics/invariants",
|
|
42
|
+
"@deepseek-ai/dsh-llm": "link:../../../../deepseek-harness/packages/llm/llm",
|
|
43
|
+
"@deepseek-ai/dsh-session": "link:../../../../deepseek-harness/packages/core/session",
|
|
44
|
+
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|
|
45
|
+
"@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
50
|
+
}
|