dsh-plugin-global-instructions 1.0.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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # dsh-plugin-global-instructions
2
+
3
+ 设置页全局指令(AGENTS.md)读写。
@@ -0,0 +1,4 @@
1
+ # dsh-plugin-global-instructions —— DSH bundle patch
2
+ - insert:
3
+ - id: dsh-plugin-global-instructions
4
+ name: dsh-plugin-global-instructions
package/lib/index.js ADDED
@@ -0,0 +1,63 @@
1
+ import path from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import fs from 'node:fs'
4
+ import os from 'node:os'
5
+
6
+ const DSH_HOME = process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
7
+ const AGENTS_PATH = path.join(DSH_HOME, 'AGENTS.md')
8
+ function readGlobalInstructions() {
9
+ try { return fs.readFileSync(AGENTS_PATH, 'utf8') } catch (e) { return '' }
10
+ }
11
+ function writeGlobalInstructions(text) {
12
+ fs.mkdirSync(DSH_HOME, { recursive: true })
13
+ fs.writeFileSync(AGENTS_PATH, String(text ?? ''), 'utf8')
14
+ return { saved: true }
15
+ }
16
+
17
+ const CLIENT_JS = `(function(){
18
+ if (window.__dshGI) return
19
+ window.__dshGI = true
20
+ function ensurePanel() {
21
+ var host = findHost()
22
+ if (!host) return setTimeout(ensurePanel, 300)
23
+ if (host.querySelector('.dsh-gi-panel')) return
24
+ var p = document.createElement('div'); p.className='dsh-gi-panel'
25
+ p.innerHTML = [
26
+ '<div class="dsh-gi-head">全局指令(AGENTS.md)</div>',
27
+ '<textarea class="dsh-gi-ta" placeholder="# 全局指令\\n\\n对所有对话生效的规则…"></textarea>',
28
+ '<div class="dsh-gi-btns"><button class="dsh-gi-save">保存</button><span class="dsh-gi-status"></span></div>'
29
+ ].join('')
30
+ host.appendChild(p)
31
+ var ta=p.querySelector('.dsh-gi-ta'), status=p.querySelector('.dsh-gi-status'), save=p.querySelector('.dsh-gi-save')
32
+ function load(){
33
+ fetch('/dsh-plugin-global-instructions/global.json').then(r=>r.json()).then(function(d){ ta.value = d.content || '' })
34
+ .catch(function(){ status.textContent='读取失败' })
35
+ }
36
+ save.addEventListener('click', function(){
37
+ save.disabled=true; status.textContent='保存中…'
38
+ fetch('/dsh-plugin-global-instructions/global.json',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({content:ta.value})})
39
+ .then(r=>r.json()).then(function(d){ status.textContent = d.saved ? '已保存 ✓' : ('失败:'+(d.error||'')) })
40
+ .catch(function(){ status.textContent='保存失败' }).finally(function(){ save.disabled=false })
41
+ })
42
+ load()
43
+ }
44
+ function findHost(){ return document.querySelector('[class*="settings"], [data-role="settings"], main, body') }
45
+ if (document.readyState==='loading') document.addEventListener('DOMContentLoaded', ensurePanel)
46
+ else ensurePanel()
47
+ })()`
48
+
49
+ const name = 'dsh-plugin-global-instructions'
50
+ const inject = ['webServer']
51
+ function apply(ctx){
52
+ const json=(res,o)=>{res.writeHead(200,{'Content-Type':'application/json; charset=utf-8','Cache-Control':'no-store'});res.end(JSON.stringify(o))}
53
+ ctx.webServer.register({
54
+ kind:'exact', path:'/dsh-plugin-global-instructions/global.json',
55
+ handler:(req,res)=>{
56
+ if(req.method==='POST'){
57
+ let body=''; req.on('data',c=>body+=c); req.on('end',()=>{ try{ const p=JSON.parse(body||'{}'); writeGlobalInstructions(p.content); json(res,{saved:true}) }catch(e){ json(res,{saved:false,error:String(e&&e.message||e)}) } })
58
+ } else { json(res,{content:readGlobalInstructions(),exists:true}) }
59
+ },
60
+ })
61
+
62
+ }
63
+ export { name, inject, apply }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "dsh-plugin-global-instructions",
3
+ "version": "1.0.0",
4
+ "description": "DSH 设置:全局指令(AGENTS.md)编辑",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "global-instructions",
10
+ "agents-md"
11
+ ],
12
+ "type": "module",
13
+ "main": "lib/index.js",
14
+ "files": [
15
+ "lib",
16
+ "cordis.patch.yml",
17
+ "README.md"
18
+ ],
19
+ "dsh": {
20
+ "bundle": {
21
+ "patch": "./cordis.patch.yml"
22
+ }
23
+ },
24
+ "license": "MIT",
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/mengyu-arch/dsh-plugins.git"
31
+ }
32
+ }