@chopin-ai/harness-dsh 0.0.0-stage → 0.2.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 +202 -0
- package/dist/acp.d.ts +5 -0
- package/dist/acp.js +65 -0
- package/dist/acp.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +21 -0
- package/dist/plugin.js +180 -0
- package/dist/plugin.js.map +1 -0
- package/dist/run.d.ts +13 -0
- package/dist/run.js +45 -0
- package/dist/run.js.map +1 -0
- package/package.json +56 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/acp.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SessionUpdate, StopReason } from "@agentclientprotocol/sdk";
|
|
2
|
+
import type { SessionEvent, TurnEndReason } from "@deepseek-ai/dsh-session";
|
|
3
|
+
/** What one session event says, in ACP. Events the model never sees say nothing. */
|
|
4
|
+
export declare function eventUpdates(event: SessionEvent): SessionUpdate[];
|
|
5
|
+
export declare function stopReason(reason: TurnEndReason): StopReason;
|
package/dist/acp.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** What one session event says, in ACP. Events the model never sees say nothing. */
|
|
2
|
+
export function eventUpdates(event) {
|
|
3
|
+
switch (event.type) {
|
|
4
|
+
case "user/message":
|
|
5
|
+
// Context the harness injects as user-role messages is not what the user said.
|
|
6
|
+
if (event.data.source.kind !== "user")
|
|
7
|
+
return [];
|
|
8
|
+
return texts(event.data.content).map((text) => ({ sessionUpdate: "user_message_chunk", content: { type: "text", text } }));
|
|
9
|
+
case "assistant/message":
|
|
10
|
+
return event.data.message.content.flatMap((block) => {
|
|
11
|
+
if (block.type === "text")
|
|
12
|
+
return [{ sessionUpdate: "agent_message_chunk", content: { type: "text", text: block.text ?? "" } }];
|
|
13
|
+
if (block.type === "reasoning")
|
|
14
|
+
return [{ sessionUpdate: "agent_thought_chunk", content: { type: "text", text: block.text ?? "" } }];
|
|
15
|
+
if (block.type !== "tool-call")
|
|
16
|
+
return [];
|
|
17
|
+
return [{
|
|
18
|
+
sessionUpdate: "tool_call", toolCallId: block.id ?? "", title: block.name ?? "", kind: toolKind(block.name ?? ""),
|
|
19
|
+
status: "pending", rawInput: parsed(block.arguments),
|
|
20
|
+
}];
|
|
21
|
+
});
|
|
22
|
+
case "tool/result":
|
|
23
|
+
return [{
|
|
24
|
+
sessionUpdate: "tool_call_update", toolCallId: event.data.message.toolCallId,
|
|
25
|
+
status: event.data.message.isError === true ? "failed" : "completed",
|
|
26
|
+
content: texts(event.data.message.content).map((text) => ({ type: "content", content: { type: "text", text } })),
|
|
27
|
+
}];
|
|
28
|
+
default:
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function stopReason(reason) {
|
|
33
|
+
if (reason.kind === "aborted")
|
|
34
|
+
return "cancelled";
|
|
35
|
+
if (reason.kind === "max-tokens")
|
|
36
|
+
return "max_tokens";
|
|
37
|
+
if (reason.kind === "blocked")
|
|
38
|
+
return "refusal";
|
|
39
|
+
return "end_turn";
|
|
40
|
+
}
|
|
41
|
+
function texts(content) {
|
|
42
|
+
return content.flatMap((block) => (block.type === "text" && block.text !== undefined ? [block.text] : []));
|
|
43
|
+
}
|
|
44
|
+
/** ACP's kind of each built-in tool, a hint clients use to present the call. */
|
|
45
|
+
const KINDS = {
|
|
46
|
+
read: "read", read_image: "read", skill: "read",
|
|
47
|
+
glob: "search", grep: "search",
|
|
48
|
+
write: "edit", edit: "edit", str_replace_editor: "edit",
|
|
49
|
+
bash: "execute",
|
|
50
|
+
};
|
|
51
|
+
function toolKind(name) {
|
|
52
|
+
return Object.hasOwn(KINDS, name) ? KINDS[name] : "other";
|
|
53
|
+
}
|
|
54
|
+
/** Tool arguments travel as the model's JSON text; text that does not parse is kept as it is. */
|
|
55
|
+
function parsed(text) {
|
|
56
|
+
if (text === undefined)
|
|
57
|
+
return undefined;
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(text);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return text;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=acp.js.map
|
package/dist/acp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.js","sourceRoot":"","sources":["../src/acp.ts"],"names":[],"mappings":"AAKA,oFAAoF;AACpF,MAAM,UAAU,YAAY,CAAC,KAAmB;IAC9C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,cAAc;YACjB,+EAA+E;YAC/E,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM;gBAAE,OAAO,EAAE,CAAC;YACjD,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,oBAAoB,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;QAC7H,KAAK,mBAAmB;YACtB,OAAQ,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAA4B,CAAC,OAAO,CAAC,CAAC,KAAK,EAAmB,EAAE;gBACzF,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;oBAAE,OAAO,CAAC,EAA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CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8HAA8H;AAC9H,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
3
|
+
declare module "@deepseek-ai/dsh-session-projection/types" {
|
|
4
|
+
interface SessionProjectionStateMap {
|
|
5
|
+
"chopin.succeeded": {
|
|
6
|
+
calls: Record<string, string>;
|
|
7
|
+
tools: string[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare const name = "@chopin-ai/harness-dsh";
|
|
12
|
+
export declare const inject: string[];
|
|
13
|
+
export interface Config {
|
|
14
|
+
/** The mutable layer directory. */
|
|
15
|
+
layer: string;
|
|
16
|
+
/** Where each session's ACP transcript is written, one `<session>.jsonl` per session. */
|
|
17
|
+
transcripts?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const Config: Schema<Config>;
|
|
20
|
+
/** Loads the portable layer into the harness: instructions, skills, MCP servers and gates, and records transcripts in ACP. */
|
|
21
|
+
export declare function apply(ctx: Context, config: Config): Promise<void>;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { appendFile, mkdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { gateRefusal, loadLayer, skillBody, unmetGates, withChopinMeta } from "@chopin-ai/core";
|
|
4
|
+
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
5
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { eventUpdates, stopReason } from "./acp.js";
|
|
8
|
+
export const name = "@chopin-ai/harness-dsh";
|
|
9
|
+
export const inject = ["tools", "systemPrompt", "skills", "sessionProjections"];
|
|
10
|
+
export const Config = Schema.object({
|
|
11
|
+
layer: Schema.string().required().description("The mutable layer directory"),
|
|
12
|
+
transcripts: Schema.string().description("Directory receiving one ACP transcript per session"),
|
|
13
|
+
});
|
|
14
|
+
/** Loads the portable layer into the harness: instructions, skills, MCP servers and gates, and records transcripts in ACP. */
|
|
15
|
+
export async function apply(ctx, config) {
|
|
16
|
+
const result = await loadLayer(resolve(config.layer));
|
|
17
|
+
if (!result.ok)
|
|
18
|
+
throw new Error(`invalid layer ${config.layer}:\n${result.problems.join("\n")}`);
|
|
19
|
+
const { instructions, skills, mcpServers, gates } = result.layer;
|
|
20
|
+
if (instructions !== undefined) {
|
|
21
|
+
ctx.systemPrompt.section({ name: "chopin:guidance", order: 9000, text: instructions, interpolate: false });
|
|
22
|
+
}
|
|
23
|
+
if (skills.length > 0)
|
|
24
|
+
ctx.skills.registerProvider(() => skillProvider(skills));
|
|
25
|
+
for (const [serverName, server] of Object.entries(mcpServers))
|
|
26
|
+
ctx.plugin(McpClient, mcpConfig(serverName, server));
|
|
27
|
+
if (gates.length > 0)
|
|
28
|
+
enforceGates(ctx, gates);
|
|
29
|
+
if (config.transcripts !== undefined)
|
|
30
|
+
recordTranscripts(ctx, resolve(config.transcripts));
|
|
31
|
+
}
|
|
32
|
+
function skillProvider(skills) {
|
|
33
|
+
const candidates = skills.map((skill) => ({
|
|
34
|
+
name: skill.name,
|
|
35
|
+
description: skill.description,
|
|
36
|
+
path: join(skill.directory, "SKILL.md"),
|
|
37
|
+
invocation: { modelInvocable: true, userInvocable: true },
|
|
38
|
+
source: "custom",
|
|
39
|
+
provider: "chopin-layer",
|
|
40
|
+
resourceBase: { kind: "directory", path: skill.directory },
|
|
41
|
+
rank: 0,
|
|
42
|
+
locator: skill.directory,
|
|
43
|
+
}));
|
|
44
|
+
return {
|
|
45
|
+
name: "chopin-layer",
|
|
46
|
+
list: async () => candidates,
|
|
47
|
+
get: async (candidate) => {
|
|
48
|
+
const text = await readFile(join(candidate.locator, "SKILL.md"), "utf8");
|
|
49
|
+
return { ...candidate, content: skillBody(text) };
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function mcpConfig(serverName, server) {
|
|
54
|
+
if ("command" in server)
|
|
55
|
+
return { transport: "stdio", serverName, command: server.command, args: server.args ?? [], env: server.env ?? {} };
|
|
56
|
+
return { transport: "streamable-http", serverName, url: server.url, headers: server.headers ?? {} };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gates read which tools have succeeded from the session log, through a projection that resume and fork replay,
|
|
60
|
+
* and refuse through the monotonic guard, which no later listener can relax.
|
|
61
|
+
*/
|
|
62
|
+
function enforceGates(ctx, gates) {
|
|
63
|
+
ctx.sessionProjections.register({
|
|
64
|
+
key: "chopin.succeeded",
|
|
65
|
+
stateVersion: 1,
|
|
66
|
+
stateSchema: z.object({ calls: z.record(z.string(), z.string()), tools: z.array(z.string()) }),
|
|
67
|
+
init: () => ({ calls: {}, tools: [] }),
|
|
68
|
+
apply: (state, event) => {
|
|
69
|
+
if (event.type === "tool/call")
|
|
70
|
+
return { ...state, calls: { ...state.calls, [event.data.callId]: event.data.name } };
|
|
71
|
+
if (event.type !== "tool/result")
|
|
72
|
+
return state;
|
|
73
|
+
const { [event.data.message.toolCallId]: tool, ...calls } = state.calls;
|
|
74
|
+
const succeeded = tool !== undefined && event.data.message.isError !== true && !state.tools.includes(tool);
|
|
75
|
+
return { calls, tools: succeeded ? [...state.tools, tool] : state.tools };
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
ctx.tools.guard((execution) => {
|
|
79
|
+
const session = execution.agent?.session;
|
|
80
|
+
if (session === undefined)
|
|
81
|
+
return undefined;
|
|
82
|
+
const succeeded = new Set(ctx.sessionProjections.stateOf(session, "chopin.succeeded")?.tools ?? []);
|
|
83
|
+
const unmet = unmetGates(gates, execution.name, succeeded);
|
|
84
|
+
if (unmet.length === 0)
|
|
85
|
+
return undefined;
|
|
86
|
+
const registered = new Set(unmet.flatMap((rule) => [rule.tool, ...rule.requires]).filter((tool) => ctx.tools.get(tool) !== undefined));
|
|
87
|
+
return gateRefusal(unmet, registered);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** Writes each session as ACP, appended in order as its events commit. */
|
|
91
|
+
function recordTranscripts(ctx, directory) {
|
|
92
|
+
const writes = new Map();
|
|
93
|
+
// The folder is made once, and made again should it fail or go away.
|
|
94
|
+
let made;
|
|
95
|
+
const folder = () => (made ??= mkdir(directory, { recursive: true }).then(() => { }, (error) => {
|
|
96
|
+
made = undefined;
|
|
97
|
+
throw error;
|
|
98
|
+
}));
|
|
99
|
+
const append = async (file, text) => {
|
|
100
|
+
await folder();
|
|
101
|
+
try {
|
|
102
|
+
await appendFile(file, text);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error.code !== "ENOENT")
|
|
106
|
+
throw error;
|
|
107
|
+
made = undefined;
|
|
108
|
+
await folder();
|
|
109
|
+
await appendFile(file, text);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const turns = new Map();
|
|
113
|
+
ctx.on("session/event", (session, event) => {
|
|
114
|
+
const sessionId = String(session.id);
|
|
115
|
+
const at = new Date(event.time).toISOString();
|
|
116
|
+
const entries = eventUpdates(event).map((update) => ({ at, notification: { sessionId, update } }));
|
|
117
|
+
if (event.type === "assistant/message") {
|
|
118
|
+
const turn = turns.get(sessionId) ?? { messages: [], usage: emptyUsage() };
|
|
119
|
+
turn.messages.push(event.data.message.source);
|
|
120
|
+
add(turn.usage, event.data.usage);
|
|
121
|
+
turns.set(sessionId, turn);
|
|
122
|
+
}
|
|
123
|
+
if (event.type === "turn/end") {
|
|
124
|
+
const turn = turns.get(sessionId);
|
|
125
|
+
turns.delete(sessionId);
|
|
126
|
+
const last = turn?.messages.at(-1);
|
|
127
|
+
entries.push({
|
|
128
|
+
at, sessionId,
|
|
129
|
+
turnEnd: withChopinMeta({ stopReason: stopReason(event.data.reason), usage: turn?.usage ?? emptyUsage() }, {
|
|
130
|
+
...(last && { model: { provider: last.provider, id: last.model } }),
|
|
131
|
+
...(turnError(event.data.reason) !== undefined && { error: turnError(event.data.reason) }),
|
|
132
|
+
}),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (entries.length === 0)
|
|
136
|
+
return;
|
|
137
|
+
const text = entries.map((entry) => `${JSON.stringify(entry)}\n`).join("");
|
|
138
|
+
const file = join(directory, `${sessionId}.jsonl`);
|
|
139
|
+
const previous = writes.get(sessionId) ?? Promise.resolve();
|
|
140
|
+
const next = previous.then(() => append(file, text)).catch((error) => {
|
|
141
|
+
ctx.logger.warn("transcript %s: %s", sessionId, String(error));
|
|
142
|
+
}).finally(() => {
|
|
143
|
+
if (writes.get(sessionId) === next)
|
|
144
|
+
writes.delete(sessionId);
|
|
145
|
+
});
|
|
146
|
+
writes.set(sessionId, next);
|
|
147
|
+
});
|
|
148
|
+
// The session's durability checkpoint waits for its transcript too, so a run that exits right after loses nothing.
|
|
149
|
+
ctx.on("session/flush", async (session) => {
|
|
150
|
+
await writes.get(String(session.id));
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** Why a turn ended without finishing its work, if it did. */
|
|
154
|
+
function turnError(reason) {
|
|
155
|
+
if (reason.kind === "error")
|
|
156
|
+
return reason.error.message;
|
|
157
|
+
if (reason.kind === "interrupted")
|
|
158
|
+
return "interrupted: the harness stopped before the turn ended";
|
|
159
|
+
if (reason.kind === "blocked")
|
|
160
|
+
return "blocked: the harness rejected the input before any step ran";
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
function emptyUsage() {
|
|
164
|
+
return { totalTokens: 0, inputTokens: 0, outputTokens: 0, thoughtTokens: 0, cachedReadTokens: 0, cachedWriteTokens: 0 };
|
|
165
|
+
}
|
|
166
|
+
/** Adds one call in ACP's terms, as the durable adapter counts: input includes what the cache read and wrote. */
|
|
167
|
+
function add(total, usage) {
|
|
168
|
+
if (usage === undefined)
|
|
169
|
+
return;
|
|
170
|
+
const cacheRead = usage.cacheReadTokens ?? 0;
|
|
171
|
+
const cacheWrite = usage.cacheWriteTokens ?? 0;
|
|
172
|
+
const input = usage.inputTokens + cacheRead + cacheWrite;
|
|
173
|
+
total.inputTokens += input;
|
|
174
|
+
total.outputTokens += usage.outputTokens;
|
|
175
|
+
total.totalTokens += usage.totalTokens ?? input + usage.outputTokens;
|
|
176
|
+
total.thoughtTokens += usage.reasoningTokens ?? 0;
|
|
177
|
+
total.cachedReadTokens += cacheRead;
|
|
178
|
+
total.cachedWriteTokens += cacheWrite;
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAmE,MAAM,iBAAiB,CAAC;AAEjK,OAAO,KAAK,SAAS,MAAM,6BAA6B,CAAC;AAKzD,OAAO,MAAM,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAQpD,MAAM,CAAC,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAC7C,MAA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K,CAAC,gBAAgB,IAAI,SAAS,CAAC;IACpC,KAAK,CAAC,iBAAiB,IAAI,UAAU,CAAC;AACxC,CAAC"}
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type TaskRun } from "@chopin-ai/core";
|
|
2
|
+
import { type Workspace } from "@chopin-ai/workspace";
|
|
3
|
+
export interface DshTaskOptions {
|
|
4
|
+
/** A profile, inside the workspace, that mounts this plugin. */
|
|
5
|
+
profile: string;
|
|
6
|
+
/** The `transcripts` directory that profile's plugin writes to, inside the workspace. */
|
|
7
|
+
transcripts: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Runs one prompt headless with the harness inside the workspace, where it keeps its agent, and returns the run
|
|
11
|
+
* as the plugin recorded it in ACP, with what it changed in the workspace.
|
|
12
|
+
*/
|
|
13
|
+
export declare function runTask(workspace: Workspace, prompt: string, options: DshTaskOptions): Promise<TaskRun>;
|
package/dist/run.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { chopinMeta, parseTranscript, withChopinMeta } from "@chopin-ai/core";
|
|
2
|
+
import { diff, run, snapshot } from "@chopin-ai/workspace";
|
|
3
|
+
/**
|
|
4
|
+
* Runs one prompt headless with the harness inside the workspace, where it keeps its agent, and returns the run
|
|
5
|
+
* as the plugin recorded it in ACP, with what it changed in the workspace.
|
|
6
|
+
*/
|
|
7
|
+
export async function runTask(workspace, prompt, options) {
|
|
8
|
+
await workspace.start();
|
|
9
|
+
const base = await snapshot(workspace);
|
|
10
|
+
const result = await run(workspace, ["dsh", "--profile", options.profile, "--json"], { input: prompt });
|
|
11
|
+
const session = result.stdout.split("\n").map(event)
|
|
12
|
+
.find((e) => e?.type === "session" && typeof e.sessionId === "string");
|
|
13
|
+
if (session === undefined)
|
|
14
|
+
throw new Error(`dsh did not start a session (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
15
|
+
const recorded = await run(workspace, ["cat", `${options.transcripts}/${session.sessionId}.jsonl`]);
|
|
16
|
+
// A finished run without a transcript means the profile does not record; an unfinished one may have stopped first.
|
|
17
|
+
if (recorded.exitCode !== 0 && result.exitCode === 0) {
|
|
18
|
+
throw new Error(`no transcript for ${session.sessionId}: ${recorded.stderr.trim()}`);
|
|
19
|
+
}
|
|
20
|
+
const transcript = recorded.exitCode === 0 ? parseTranscript(recorded.stdout) : [];
|
|
21
|
+
if (result.exitCode !== 0)
|
|
22
|
+
failed(transcript, session.sessionId, `dsh exited with ${result.exitCode}: ${result.stderr.trim()}`);
|
|
23
|
+
return { transcript, diff: base === undefined ? undefined : await diff(workspace, base) };
|
|
24
|
+
}
|
|
25
|
+
/** Marks a run the harness did not finish: on its last turn end, or on one added when it recorded none. */
|
|
26
|
+
function failed(transcript, sessionId, error) {
|
|
27
|
+
const last = transcript.at(-1);
|
|
28
|
+
if (last !== undefined && "turnEnd" in last) {
|
|
29
|
+
const meta = chopinMeta(last.turnEnd);
|
|
30
|
+
if (meta?.error === undefined)
|
|
31
|
+
last.turnEnd = withChopinMeta(last.turnEnd, { ...meta, error });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
transcript.push({ at: new Date().toISOString(), sessionId, turnEnd: withChopinMeta({ stopReason: "end_turn" }, { error }) });
|
|
35
|
+
}
|
|
36
|
+
/** One line of the harness's JSON output; anything else it printed is not an event. */
|
|
37
|
+
function event(line) {
|
|
38
|
+
try {
|
|
39
|
+
return JSON.parse(line);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAsC,MAAM,iBAAiB,CAAC;AAClH,OAAO,EAAE,IAAI,EAAE,GA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;IACpE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chopin-ai/harness-dsh",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Plugin harness adapter: mutable-layer loading and headless task runs",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/CodePrometheus/chopin-ai.git",
|
|
9
|
+
"directory": "packages/harness-dsh"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=24.8.0"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./run": {
|
|
21
|
+
"types": "./dist/run.d.ts",
|
|
22
|
+
"default": "./dist/run.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@agentclientprotocol/sdk": "^1.9.0",
|
|
30
|
+
"@chopin-ai/core": "^0.2.0",
|
|
31
|
+
"@chopin-ai/workspace": "^0.2.0",
|
|
32
|
+
"zod": "4.4.3"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@deepseek-ai/cordis": "~4.0.5",
|
|
36
|
+
"@deepseek-ai/dsh-llm": "0.2.1-rc.2",
|
|
37
|
+
"@deepseek-ai/dsh-mcp-client": "0.2.1-rc.2",
|
|
38
|
+
"@deepseek-ai/dsh-session": "0.2.1-rc.2",
|
|
39
|
+
"@deepseek-ai/dsh-session-projection": "0.2.1-rc.2",
|
|
40
|
+
"@deepseek-ai/dsh-skill": "0.2.1-rc.2",
|
|
41
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.1-rc.2",
|
|
42
|
+
"@deepseek-ai/dsh-tools": "0.2.1-rc.2",
|
|
43
|
+
"@deepseek-ai/schemastery": "~3.18.5"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@deepseek-ai/cordis": "~4.0.5",
|
|
47
|
+
"@deepseek-ai/dsh-llm": "0.2.1-rc.2",
|
|
48
|
+
"@deepseek-ai/dsh-mcp-client": "0.2.1-rc.2",
|
|
49
|
+
"@deepseek-ai/dsh-session": "0.2.1-rc.2",
|
|
50
|
+
"@deepseek-ai/dsh-session-projection": "0.2.1-rc.2",
|
|
51
|
+
"@deepseek-ai/dsh-skill": "0.2.1-rc.2",
|
|
52
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.1-rc.2",
|
|
53
|
+
"@deepseek-ai/dsh-tools": "0.2.1-rc.2",
|
|
54
|
+
"@deepseek-ai/schemastery": "~3.18.5"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"image": "node scripts/build-image.mjs"
|
|
58
|
+
}
|
|
6
59
|
}
|
package/README.md
DELETED