@goodandready/dsh-dsml-artifact-guard 0.1.1
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 +21 -0
- package/README.md +54 -0
- package/cordis.patch.yml +8 -0
- package/lib/index.js +1 -0
- package/package.json +1 -0
- package/test/index.test.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GooDAnDReaDY
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# dsh-dsml-artifact-guard
|
|
2
|
+
|
|
3
|
+
Safe DeepSeek DSML artifact sanitizer for DeepSeek Harness.
|
|
4
|
+
|
|
5
|
+
## What it fixes
|
|
6
|
+
|
|
7
|
+
Some provider responses append protocol closing tags such as
|
|
8
|
+
`</|DSML|parameter> </|DSML|invoke> </|DSML|tool_calls>` to the visible
|
|
9
|
+
assistant text. The guard detects that terminal artifact and can remove it
|
|
10
|
+
before the text reaches the chat UI.
|
|
11
|
+
|
|
12
|
+
The `llm/stream` hook is deliberately synchronous. Cordis expects a stream (an
|
|
13
|
+
`AsyncIterable`) immediately; making the hook `async` would return a `Promise`
|
|
14
|
+
and break every turn with `stream is not async iterable`.
|
|
15
|
+
|
|
16
|
+
## Configuration
|
|
17
|
+
|
|
18
|
+
The bundle accepts:
|
|
19
|
+
|
|
20
|
+
- `mode`: `audit` (default, log detections without changing text),
|
|
21
|
+
`sanitize` (remove the terminal artifact), or `disabled`;
|
|
22
|
+
- `providerId`: provider identifier to inspect (default `opencode-go`);
|
|
23
|
+
- `modelId`: model identifier to inspect (default `deepseek-v4-flash`).
|
|
24
|
+
|
|
25
|
+
Only matching provider/model streams are changed. Other streams pass through
|
|
26
|
+
unchanged. The sanitizer is fail-open: malformed or non-text chunks are
|
|
27
|
+
forwarded, and only a terminal closing-tag sequence is considered an artifact.
|
|
28
|
+
|
|
29
|
+
## Compatibility
|
|
30
|
+
|
|
31
|
+
Version 0.1.0 is compatible with DeepSeek Harness 0.1.2 alpha and rc web
|
|
32
|
+
profiles and Cordis 4.x. The synchronous hook fix is required for the rc.1
|
|
33
|
+
runtime and remains valid for later 0.1.2 releases.
|
|
34
|
+
|
|
35
|
+
## Development and tests
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm test
|
|
39
|
+
npm run check
|
|
40
|
+
npm pack --dry-run --json
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Tests cover split stream chunks, audit versus sanitize behavior, scope
|
|
44
|
+
matching, and the synchronous Cordis hook contract.
|
|
45
|
+
|
|
46
|
+
## Related fixes
|
|
47
|
+
|
|
48
|
+
- Gitea issue #4: synchronous `llm/stream` hook (`stream is not async iterable`).
|
|
49
|
+
- Gitea issue #6: package license, ignore rules, and deterministic package
|
|
50
|
+
contents.
|
|
51
|
+
|
|
52
|
+
## Release v0.1.1
|
|
53
|
+
|
|
54
|
+
This public hotfix release packages the synchronous stream-hook repair and the deterministic package hygiene changes from Gitea PR #7. It is compatible with DeepSeek Harness 0.1.2 alpha/rc web profiles and keeps the fail-open, provider/model-scoped sanitizer behavior described above.
|
package/cordis.patch.yml
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import Schema from '@deepseek-ai/schemastery'; const TAIL=/(?:<\/|DSML|parameter>\s*)?(?:<\/|DSML|invoke>\s*)?<\/|DSML|tool_calls>\s*$/u,OPEN=/<|DSML|(?:tool_calls|invoke|parameter)>/u,KEEP=96; export const name='@goodandready/dsh-dsml-artifact-guard',inject=['llm'],Config=Schema.object({mode:Schema.string().default('audit'),providerId:Schema.string().default('opencode-go'),modelId:Schema.string().default('deepseek-v4-flash')}); export function matchesScope(o,c){return (o?.providerId??o?.provider?.id??o?.provider)==c.providerId&&(o?.modelId??o?.model?.id??o?.model?.name??o?.model)==c.modelId} export async function* sanitizeDsmlArtifacts(s,{mode,onArtifact}={}){let p='',i,open=false;const flush=async function*(end){if(!p)return;let text=p;if(end&&!open&&TAIL.test(text)){onArtifact?.({mode,removed:1});if(mode==='sanitize')text=text.replace(TAIL,'')}if(text)yield{type:'text-delta',index:i,text};p='';i=undefined};for await(const c of s){if(c?.type==='text-delta'&&typeof c.text==='string'){if(p&&i!==c.index)yield*flush(false);i=c.index;p+=c.text;open||=OPEN.test(c.text);if(p.length>KEEP){const n=p.length-KEEP;yield{type:'text-delta',index:i,text:p.slice(0,n)};p=p.slice(n)}continue}if(c?.type==='finish'){yield*flush(true);yield c;continue}yield*flush(false);yield c}yield*flush(true)} export function apply(ctx,c={}){const e=Config(c)??{};ctx.on('llm/stream',(o,next)=>{const s=next(o);return e.mode==='disabled'||!matchesScope(o,e)?s:sanitizeDsmlArtifacts(s,{mode:e.mode,onArtifact:x=>ctx.logger?.info?.('DSML closing-tag artifact detected',x)})})}
|
package/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"@goodandready/dsh-dsml-artifact-guard","version":"0.1.1","description":"Sanitizes leaked DeepSeek DSML closing tags from model text streams","type":"module","main":"lib/index.js","license":"MIT","files":["lib","test","README.md","LICENSE","cordis.patch.yml"],"scripts":{"check":"node --check lib/index.js","test":"node --test"},"dsh":{"bundle":{"patch":"./cordis.patch.yml"}},"peerDependencies":{"@deepseek-ai/cordis":"^4.0.1","@deepseek-ai/schemastery":"^3.18.1"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import assert from'node:assert/strict';import test from'node:test';import{apply,matchesScope,sanitizeDsmlArtifacts}from'../lib/index.js';const tail='</|DSML|parameter> </|DSML|invoke> </|DSML|tool_calls>';async function collect(c,o){const r=[];async function*s(){yield*c}for await(const x of sanitizeDsmlArtifacts(s(),o))r.push(x);return r}test('removes terminal tail',async()=>{const c=[{type:'tool-call-delta',index:1},{type:'text-delta',index:2,text:'Done. '+tail},{type:'finish'}];assert.deepEqual(await collect(c,{mode:'sanitize'}),[c[0],{type:'text-delta',index:2,text:'Done. '},c[2]])});test('split tail',async()=>{const c=[{type:'text-delta',index:0,text:'A '+tail.slice(0,20)},{type:'text-delta',index:0,text:tail.slice(20)},{type:'finish'}];assert.deepEqual(await collect(c,{mode:'sanitize'}),[{type:'text-delta',index:0,text:'A '},c[2]])});test('audit unchanged',async()=>{const c=[{type:'text-delta',index:0,text:tail},{type:'finish'}];assert.deepEqual(await collect(c,{mode:'audit'}),c)});test('keeps prose',async()=>{const c=[{type:'text-delta',index:0,text:'<|DSML|tool_calls>x</|DSML|tool_calls>'},{type:'usage'},{type:'finish'}];assert.deepEqual(await collect(c,{mode:'sanitize'}),c)});test('scope',()=>assert.equal(matchesScope({providerId:'opencode-go',modelId:'deepseek-v4-flash'},{providerId:'opencode-go',modelId:'deepseek-v4-flash'}),true));test('llm stream hook returns an async iterable synchronously',()=>{let hook;const ctx={on(_event,fn){hook=fn},logger:{info(){}}};apply(ctx,{mode:'sanitize',providerId:'opencode-go',modelId:'deepseek-v4-flash'});assert.equal(typeof hook,'function');async function*stream(){yield{type:'finish'}}const source=stream();const result=hook({providerId:'opencode-go',modelId:'deepseek-v4-flash'},()=>source);assert.equal(typeof result?.[Symbol.asyncIterator],'function');assert.equal(typeof result?.then,'undefined')});test('out of scope stream passes through unchanged',()=>{let hook;const ctx={on(_event,fn){hook=fn},logger:{info(){}}};apply(ctx,{mode:'sanitize',providerId:'opencode-go',modelId:'deepseek-v4-flash'});async function*stream(){yield{type:'finish'}}const source=stream();assert.equal(hook({providerId:'other',modelId:'model'},()=>source),source)});
|