dsh-task-mascot 0.0.0-stage → 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/ART_LICENSE.md +28 -0
- package/LICENSE +25 -0
- package/NOTICE.md +11 -0
- package/README.md +147 -2
- package/assets/packs/claude/cmd.png +0 -0
- package/assets/packs/claude/cmd.webm +0 -0
- package/assets/packs/claude/cmd.webp +0 -0
- package/assets/packs/claude/coding.png +0 -0
- package/assets/packs/claude/coding.webm +0 -0
- package/assets/packs/claude/coding.webp +0 -0
- package/assets/packs/claude/done.png +0 -0
- package/assets/packs/claude/done.webm +0 -0
- package/assets/packs/claude/done.webp +0 -0
- package/assets/packs/claude/editing.png +0 -0
- package/assets/packs/claude/editing.webm +0 -0
- package/assets/packs/claude/editing.webp +0 -0
- package/assets/packs/claude/error.png +0 -0
- package/assets/packs/claude/error.webm +0 -0
- package/assets/packs/claude/error.webp +0 -0
- package/assets/packs/claude/manifest.json +106 -0
- package/assets/packs/claude/planning.png +0 -0
- package/assets/packs/claude/planning.webm +0 -0
- package/assets/packs/claude/planning.webp +0 -0
- package/assets/packs/claude/reading.png +0 -0
- package/assets/packs/claude/reading.webm +0 -0
- package/assets/packs/claude/reading.webp +0 -0
- package/assets/packs/claude/search.png +0 -0
- package/assets/packs/claude/search.webm +0 -0
- package/assets/packs/claude/search.webp +0 -0
- package/assets/packs/claude/subagents.png +0 -0
- package/assets/packs/claude/subagents.webm +0 -0
- package/assets/packs/claude/subagents.webp +0 -0
- package/assets/packs/claude/thinking.png +0 -0
- package/assets/packs/claude/thinking.webm +0 -0
- package/assets/packs/claude/thinking.webp +0 -0
- package/assets/packs/claude/waiting.png +0 -0
- package/assets/packs/claude/waiting.webm +0 -0
- package/assets/packs/claude/waiting.webp +0 -0
- package/assets/packs/dafeiyu/cmd.png +0 -0
- package/assets/packs/dafeiyu/cmd.webm +0 -0
- package/assets/packs/dafeiyu/cmd.webp +0 -0
- package/assets/packs/dafeiyu/coding.png +0 -0
- package/assets/packs/dafeiyu/coding.webm +0 -0
- package/assets/packs/dafeiyu/coding.webp +0 -0
- package/assets/packs/dafeiyu/done.png +0 -0
- package/assets/packs/dafeiyu/done.webm +0 -0
- package/assets/packs/dafeiyu/done.webp +0 -0
- package/assets/packs/dafeiyu/editing.png +0 -0
- package/assets/packs/dafeiyu/editing.webm +0 -0
- package/assets/packs/dafeiyu/editing.webp +0 -0
- package/assets/packs/dafeiyu/error.png +0 -0
- package/assets/packs/dafeiyu/error.webm +0 -0
- package/assets/packs/dafeiyu/error.webp +0 -0
- package/assets/packs/dafeiyu/manifest.json +106 -0
- package/assets/packs/dafeiyu/planning.png +0 -0
- package/assets/packs/dafeiyu/planning.webm +0 -0
- package/assets/packs/dafeiyu/planning.webp +0 -0
- package/assets/packs/dafeiyu/reading.png +0 -0
- package/assets/packs/dafeiyu/reading.webm +0 -0
- package/assets/packs/dafeiyu/reading.webp +0 -0
- package/assets/packs/dafeiyu/search.png +0 -0
- package/assets/packs/dafeiyu/search.webm +0 -0
- package/assets/packs/dafeiyu/search.webp +0 -0
- package/assets/packs/dafeiyu/subagents.png +0 -0
- package/assets/packs/dafeiyu/subagents.webm +0 -0
- package/assets/packs/dafeiyu/subagents.webp +0 -0
- package/assets/packs/dafeiyu/thinking.png +0 -0
- package/assets/packs/dafeiyu/thinking.webm +0 -0
- package/assets/packs/dafeiyu/thinking.webp +0 -0
- package/assets/packs/dafeiyu/waiting.png +0 -0
- package/assets/packs/dafeiyu/waiting.webm +0 -0
- package/assets/packs/dafeiyu/waiting.webp +0 -0
- package/cordis.patch.yml +5 -0
- package/lib/client.js +654 -0
- package/lib/index.js +162 -0
- package/package.json +67 -4
package/lib/index.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// dsh-task-mascot — host half.
|
|
2
|
+
// 1) Serves character packs (assets/packs/<pack>/manifest.json + media) read-only.
|
|
3
|
+
// 2) Observes session activity (session/event, agent/assistant-stream) and re-broadcasts a
|
|
4
|
+
// small normalized activity stream over Server-Sent Events for the browser half.
|
|
5
|
+
// No external requests, no telemetry, never writes to sessions.
|
|
6
|
+
import { createReadStream, existsSync, statSync, readdirSync, readFileSync, appendFileSync } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
|
|
10
|
+
export const name = 'dsh-task-mascot';
|
|
11
|
+
const ROUTE = '/api/dsh-task-mascot';
|
|
12
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const PACKS_DIR = path.join(HERE, '..', 'assets', 'packs');
|
|
14
|
+
const DEBUG_LOG = process.env.DSH_TASK_MASCOT_DEBUG_LOG || '';
|
|
15
|
+
|
|
16
|
+
const MIME = {
|
|
17
|
+
'.json': 'application/json; charset=utf-8', '.webm': 'video/webm', '.mp4': 'video/mp4', '.mov': 'video/quicktime',
|
|
18
|
+
'.webp': 'image/webp', '.png': 'image/png', '.gif': 'image/gif', '.svg': 'image/svg+xml', '.jpg': 'image/jpeg',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function safeResolve(root, rel) {
|
|
22
|
+
if (typeof rel !== 'string' || rel === '' || rel.includes('\0')) return null;
|
|
23
|
+
const target = path.normalize(path.join(root, rel));
|
|
24
|
+
if (!target.startsWith(root + path.sep)) return null;
|
|
25
|
+
return target;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function listPacks(root = PACKS_DIR) {
|
|
29
|
+
const out = [];
|
|
30
|
+
if (!existsSync(root)) return out;
|
|
31
|
+
for (const d of readdirSync(root, { withFileTypes: true })) {
|
|
32
|
+
if (!d.isDirectory()) continue;
|
|
33
|
+
const mf = path.join(root, d.name, 'manifest.json');
|
|
34
|
+
if (!existsSync(mf)) continue;
|
|
35
|
+
try {
|
|
36
|
+
const m = JSON.parse(readFileSync(mf, 'utf8'));
|
|
37
|
+
out.push({ id: d.name, name: m.name || d.name, title: m.title || m.name || d.name, preview: m.preview || null, license: m.license || null });
|
|
38
|
+
} catch { /* skip broken pack */ }
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Normalize one durable session event into a tiny activity frame (or null). Exported for tests. */
|
|
44
|
+
export function normalizeSessionEvent(sessionId, event) {
|
|
45
|
+
if (!event || typeof event.type !== 'string') return null;
|
|
46
|
+
const d = event.data || {};
|
|
47
|
+
const base = { sessionId: sessionId == null ? null : String(sessionId), ts: Date.now() };
|
|
48
|
+
switch (event.type) {
|
|
49
|
+
case 'turn/start': return { ...base, kind: 'turn-start' };
|
|
50
|
+
case 'turn/end': return { ...base, kind: 'turn-end', reason: (d.reason && d.reason.kind) || 'completed' };
|
|
51
|
+
case 'step/start': return { ...base, kind: 'step-start' };
|
|
52
|
+
case 'tool/call': return { ...base, kind: 'tool-call', tool: typeof d.name === 'string' ? d.name : '', callId: d.callId || d.id || null, args: summarizeArgs(d.arguments ?? d.args ?? d.input) };
|
|
53
|
+
case 'tool/result': { // real shape (dsh 0.2.1): data.message = { role:'tool', toolCallId, isError, content }
|
|
54
|
+
const msg = d.message || {};
|
|
55
|
+
return { ...base, kind: 'tool-result', callId: msg.toolCallId || (msg.source && msg.source.callId) || d.callId || d.id || null, tool: typeof d.name === 'string' ? d.name : '', error: !!(msg.isError || d.isError || d.error || d.status === 'error') };
|
|
56
|
+
}
|
|
57
|
+
case 'approval/asked': return { ...base, kind: 'approval', pending: true };
|
|
58
|
+
case 'approval/decided': return { ...base, kind: 'approval', pending: false };
|
|
59
|
+
case 'question/asked': case 'user-question/asked': return { ...base, kind: 'question', pending: true };
|
|
60
|
+
case 'question/answered': case 'user-question/answered': return { ...base, kind: 'question', pending: false };
|
|
61
|
+
case 'todo/write': return { ...base, kind: 'tool-call', tool: 'todo_write', callId: null };
|
|
62
|
+
case 'user/message': return { ...base, kind: 'user-message' };
|
|
63
|
+
case 'assistant/message': return { ...base, kind: 'assistant-message' };
|
|
64
|
+
default: return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Privacy: the SSE stream is readable by the local web origin, so never forward commands, paths
|
|
69
|
+
// or queries verbatim. Only a coarse hint (target file extension) is kept, for "writing docs" vs "coding".
|
|
70
|
+
function summarizeArgs(a) {
|
|
71
|
+
if (a == null) return undefined;
|
|
72
|
+
if (typeof a === 'string') { try { a = JSON.parse(a); } catch { return undefined; } }
|
|
73
|
+
if (typeof a !== 'object') return undefined;
|
|
74
|
+
const p = a.path ?? a.file_path ?? a.filePath ?? a.target;
|
|
75
|
+
if (typeof p !== 'string') return undefined;
|
|
76
|
+
const m = /\.([A-Za-z0-9]{1,8})$/.exec(p);
|
|
77
|
+
return m ? { ext: m[1].toLowerCase() } : undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function sessionIdOf(session) {
|
|
81
|
+
if (!session) return null;
|
|
82
|
+
return session.id ?? session.sessionId ?? session.key ?? null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function apply(ctx) {
|
|
86
|
+
const clients = new Set();
|
|
87
|
+
const recent = []; // ring buffer replayed to new SSE clients
|
|
88
|
+
const lastStreamAt = new Map();
|
|
89
|
+
const broadcast = (frame) => {
|
|
90
|
+
if (!frame) return;
|
|
91
|
+
recent.push(frame); if (recent.length > 50) recent.shift();
|
|
92
|
+
const line = 'data: ' + JSON.stringify(frame) + '\n\n';
|
|
93
|
+
for (const res of clients) { try { res.write(line); } catch { clients.delete(res); } }
|
|
94
|
+
};
|
|
95
|
+
const debug = (tag, obj) => {
|
|
96
|
+
if (!DEBUG_LOG) return;
|
|
97
|
+
try { appendFileSync(DEBUG_LOG, JSON.stringify({ t: new Date().toISOString(), tag, obj }, (k, v) => (typeof v === 'string' && v.length > 300 ? v.slice(0, 300) + '…' : v)) + '\n'); } catch { /* ignore */ }
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
ctx.on('session/event', (session, event) => {
|
|
101
|
+
debug('session/event', { sid: sessionIdOf(session), type: event?.type, data: event?.data });
|
|
102
|
+
broadcast(normalizeSessionEvent(sessionIdOf(session), event));
|
|
103
|
+
});
|
|
104
|
+
// Live token stream: throttle to one "generating" frame per session per 1.5s.
|
|
105
|
+
ctx.on('agent/assistant-stream', (payload) => {
|
|
106
|
+
const sid = payload?.sessionId ?? sessionIdOf(payload?.session) ?? payload?.agent?.sessionId ?? null;
|
|
107
|
+
const chunkType = payload?.frame?.chunk?.type || payload?.frame?.type || '';
|
|
108
|
+
const key = String(sid);
|
|
109
|
+
const now = Date.now();
|
|
110
|
+
if (now - (lastStreamAt.get(key) || 0) < 1500) return;
|
|
111
|
+
lastStreamAt.set(key, now);
|
|
112
|
+
debug('assistant-stream', { sid, chunkType, keys: Object.keys(payload || {}) });
|
|
113
|
+
broadcast({ sessionId: sid == null ? null : String(sid), ts: now, kind: 'generating', reasoning: /reason|think/i.test(chunkType) });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
ctx.inject(['webServer'], (wctx) => {
|
|
117
|
+
const webServer = wctx.get('webServer');
|
|
118
|
+
const disposers = [];
|
|
119
|
+
disposers.push(webServer.register({
|
|
120
|
+
kind: 'exact', path: ROUTE + '/packs',
|
|
121
|
+
handler: async (_req, res) => {
|
|
122
|
+
res.writeHead(200, { 'Content-Type': MIME['.json'], 'Cache-Control': 'no-cache' });
|
|
123
|
+
res.end(JSON.stringify({ packs: listPacks() }));
|
|
124
|
+
},
|
|
125
|
+
}));
|
|
126
|
+
disposers.push(webServer.register({
|
|
127
|
+
kind: 'exact', path: ROUTE + '/asset',
|
|
128
|
+
handler: async (req, res) => {
|
|
129
|
+
try {
|
|
130
|
+
const url = new URL(req.url, 'http://127.0.0.1');
|
|
131
|
+
const file = safeResolve(PACKS_DIR, url.searchParams.get('f') ?? '');
|
|
132
|
+
if (!file || !existsSync(file) || !statSync(file).isFile()) { res.writeHead(404, { 'Content-Type': 'text/plain' }); res.end('not found'); return; }
|
|
133
|
+
const type = MIME[path.extname(file).toLowerCase()] ?? 'application/octet-stream';
|
|
134
|
+
const size = statSync(file).size;
|
|
135
|
+
const range = /^bytes=(\d*)-(\d*)$/.exec(req.headers.range || '');
|
|
136
|
+
if (range) { // media elements need Range support for smooth looping/seeking
|
|
137
|
+
let start = range[1] ? +range[1] : 0; let end = range[2] ? +range[2] : size - 1;
|
|
138
|
+
if (!range[1] && range[2]) { start = size - +range[2]; end = size - 1; }
|
|
139
|
+
if (start >= size || end >= size || start > end) { res.writeHead(416, { 'Content-Range': `bytes */${size}` }); res.end(); return; }
|
|
140
|
+
res.writeHead(206, { 'Content-Type': type, 'Content-Length': end - start + 1, 'Content-Range': `bytes ${start}-${end}/${size}`, 'Accept-Ranges': 'bytes', 'Cache-Control': 'public, max-age=86400' });
|
|
141
|
+
createReadStream(file, { start, end }).pipe(res); return;
|
|
142
|
+
}
|
|
143
|
+
res.writeHead(200, { 'Content-Type': type, 'Content-Length': size, 'Accept-Ranges': 'bytes', 'Cache-Control': 'public, max-age=86400' });
|
|
144
|
+
createReadStream(file).pipe(res);
|
|
145
|
+
} catch (e) { res.writeHead(400, { 'Content-Type': 'text/plain' }); res.end(String(e?.message ?? e)); }
|
|
146
|
+
},
|
|
147
|
+
}));
|
|
148
|
+
disposers.push(webServer.register({
|
|
149
|
+
kind: 'exact', path: ROUTE + '/events',
|
|
150
|
+
handler: async (req, res) => {
|
|
151
|
+
res.writeHead(200, { 'Content-Type': 'text/event-stream; charset=utf-8', 'Cache-Control': 'no-cache, no-transform', Connection: 'keep-alive', 'X-Accel-Buffering': 'no' });
|
|
152
|
+
res.write('retry: 2000\n\n');
|
|
153
|
+
for (const f of recent.filter((f) => Date.now() - f.ts < 30000)) res.write('data: ' + JSON.stringify({ ...f, replay: true }) + '\n\n');
|
|
154
|
+
clients.add(res);
|
|
155
|
+
const ping = setInterval(() => { try { res.write(': ping\n\n'); } catch { /* ignore */ } }, 15000);
|
|
156
|
+
req.on('close', () => { clearInterval(ping); clients.delete(res); });
|
|
157
|
+
},
|
|
158
|
+
}));
|
|
159
|
+
wctx.effect(() => () => { for (const d of disposers) try { d(); } catch { /* ignore */ } for (const r of clients) try { r.end(); } catch { /* ignore */ } clients.clear(); }, 'dsh-task-mascot: routes');
|
|
160
|
+
});
|
|
161
|
+
ctx.logger?.info?.('dsh-task-mascot: mounted (' + ROUTE + ')');
|
|
162
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-task-mascot",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "metsh · Task Mascot — 真跟着 Agent 每一步工具调用在动。A DeepSeek Harness Web plugin whose mascot acts out every live tool call (read / write / edit / search / run / plan / sub-agent / wait / error) with step cards in chat. Swappable character packs (大肥鱼, Claude娘).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"default": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./client": "./lib/client.js",
|
|
12
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"assets/packs",
|
|
18
|
+
"cordis.patch.yml",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"NOTICE.md",
|
|
22
|
+
"ART_LICENSE.md"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": "^22.19.0 || >=24.0.0",
|
|
26
|
+
"dsh": ">=0.2.0-rc.2"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "node --test test/unit.test.mjs",
|
|
30
|
+
"check": "node --check lib/index.js && node --check lib/client.js",
|
|
31
|
+
"encode": "bash scripts/encode-packs.sh"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"dsh": {
|
|
35
|
+
"bundle": {
|
|
36
|
+
"patch": "./cordis.patch.yml"
|
|
37
|
+
},
|
|
38
|
+
"client": {
|
|
39
|
+
"platform": "web",
|
|
40
|
+
"inject": [
|
|
41
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
42
|
+
"@deepseek-ai/dsh-client-ui-layout"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"dsh",
|
|
48
|
+
"dsh-plugin",
|
|
49
|
+
"deepseek-harness",
|
|
50
|
+
"mascot",
|
|
51
|
+
"desktop-pet",
|
|
52
|
+
"agent",
|
|
53
|
+
"tool-calls",
|
|
54
|
+
"animation",
|
|
55
|
+
"大肥鱼",
|
|
56
|
+
"whale-girl",
|
|
57
|
+
"claude娘"
|
|
58
|
+
],
|
|
59
|
+
"author": "metsh",
|
|
60
|
+
"displayName": "metsh · Task Mascot",
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git+https://github.com/sherconan/dsh-task-mascot.git"
|
|
64
|
+
},
|
|
65
|
+
"homepage": "https://github.com/sherconan/dsh-task-mascot#readme",
|
|
66
|
+
"bugs": {
|
|
67
|
+
"url": "https://github.com/sherconan/dsh-task-mascot/issues"
|
|
68
|
+
}
|
|
69
|
+
}
|