@d0nj/dsh-narration 0.0.0-stage → 0.3.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/dist/live.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ export type LivePhase = 'idle' | 'thinking' | 'writing' | 'calling' | 'holding';
2
+ export interface ArgTextReader {
3
+ text(key: string): string | undefined;
4
+ }
5
+ export interface LiveCall {
6
+ readonly callId: string;
7
+ readonly name: string;
8
+ readonly phase: 'preparing' | 'start';
9
+ readonly time: number;
10
+ readonly args: ArgTextReader;
11
+ }
12
+ export interface CallNarration {
13
+ readonly key: string;
14
+ readonly verb: string;
15
+ readonly argument: string;
16
+ readonly preparing: boolean;
17
+ }
18
+ export interface LiveSummary {
19
+ readonly phase: LivePhase;
20
+ readonly reasoning: string;
21
+ readonly answer: string;
22
+ readonly calls: readonly CallNarration[];
23
+ readonly lead: string;
24
+ }
25
+ interface ToolNarration {
26
+ readonly verb: string;
27
+ readonly keys: readonly string[];
28
+ }
29
+ export declare const TOOL_NARRATION: Readonly<Record<string, ToolNarration>>;
30
+ export declare const PREPARING_LABEL = "composing";
31
+ export declare function clip(text: string, limit: number): string;
32
+ export declare function narrateCall(call: LiveCall, limit?: number): CallNarration;
33
+ export declare function splitPath(value: string): {
34
+ directory: string;
35
+ base: string;
36
+ };
37
+ export declare function formatElapsed(ms: number): string;
38
+ export declare function formatRate(charsPerSecond: number): string;
39
+ export declare function summarize(input: {
40
+ readonly calls: readonly LiveCall[];
41
+ readonly reasoning: string;
42
+ readonly answer: string;
43
+ readonly running: boolean;
44
+ readonly limit?: number;
45
+ }): LiveSummary;
46
+ export declare function phaseLabel(phase: LivePhase): string;
47
+ export {};
48
+ //# sourceMappingURL=live.d.ts.map
package/dist/live.js ADDED
@@ -0,0 +1,124 @@
1
+ export const TOOL_NARRATION = {
2
+ apply_patch: { verb: 'Patching', keys: ['path'] },
3
+ bash: { verb: 'Running', keys: ['command'] },
4
+ edit: { verb: 'Editing', keys: ['file_path', 'path'] },
5
+ glob: { verb: 'Globbing', keys: ['pattern'] },
6
+ grep: { verb: 'Searching', keys: ['pattern'] },
7
+ pwsh: { verb: 'Running', keys: ['command'] },
8
+ read: { verb: 'Reading', keys: ['file_path', 'path'] },
9
+ read_image: { verb: 'Opening', keys: ['file_path', 'path'] },
10
+ subagent: { verb: 'Delegating', keys: ['description'] },
11
+ subagent_fork: { verb: 'Forking', keys: ['description'] },
12
+ web_fetch: { verb: 'Fetching', keys: ['url'] },
13
+ web_search: { verb: 'Searching the web', keys: ['query'] },
14
+ workflow: { verb: 'Orchestrating', keys: ['description'] },
15
+ write: { verb: 'Writing', keys: ['file_path', 'path'] },
16
+ };
17
+ const FALLBACK_KEYS = ['command', 'path', 'file_path', 'pattern', 'url', 'query', 'description', 'prompt'];
18
+ export const PREPARING_LABEL = 'composing';
19
+ export function clip(text, limit) {
20
+ const single = text.replace(/\s+/gu, ' ').trim();
21
+ if (single.length <= limit)
22
+ return single;
23
+ return single.slice(0, Math.max(0, completedIndex(single, limit))) + '\u2026';
24
+ }
25
+ function completedIndex(text, limit) {
26
+ if (limit <= 0)
27
+ return 0;
28
+ const code = text.charCodeAt(limit - 1);
29
+ return code >= 0xd800 && code <= 0xdbff ? limit - 1 : limit;
30
+ }
31
+ function readArgument(call, keys) {
32
+ for (const key of keys) {
33
+ const value = call.args.text(key);
34
+ if (value !== undefined && value.length > 0)
35
+ return value;
36
+ }
37
+ return '';
38
+ }
39
+ export function narrateCall(call, limit = 96) {
40
+ const known = TOOL_NARRATION[call.name];
41
+ const keys = known === undefined ? FALLBACK_KEYS : known.keys;
42
+ const raw = readArgument(call, keys);
43
+ const preparing = call.phase === 'preparing';
44
+ const argument = raw.length > 0 ? clip(raw, limit) : preparing ? PREPARING_LABEL + '\u2026' : '';
45
+ const verb = known === undefined ? call.name.replaceAll('_', ' ') : known.verb;
46
+ return {
47
+ key: call.callId,
48
+ verb,
49
+ argument,
50
+ preparing,
51
+ };
52
+ }
53
+ export function splitPath(value) {
54
+ const at = Math.max(value.lastIndexOf('/'), value.lastIndexOf('\\'));
55
+ return at < 0
56
+ ? { directory: '', base: value }
57
+ : { directory: value.slice(0, at + 1), base: value.slice(at + 1) };
58
+ }
59
+ export function formatElapsed(ms) {
60
+ if (!Number.isFinite(ms) || ms < 0)
61
+ return '0.0s';
62
+ const seconds = ms / 1000;
63
+ if (seconds < 10)
64
+ return seconds.toFixed(1) + 's';
65
+ if (seconds < 60)
66
+ return Math.floor(seconds) + 's';
67
+ const whole = Math.floor(seconds);
68
+ return Math.floor(whole / 60) + 'm' + String(whole % 60).padStart(2, '0') + 's';
69
+ }
70
+ export function formatRate(charsPerSecond) {
71
+ if (!Number.isFinite(charsPerSecond) || charsPerSecond <= 0)
72
+ return '\u2014';
73
+ if (charsPerSecond < 10)
74
+ return charsPerSecond.toFixed(1) + '/s';
75
+ return Math.round(charsPerSecond) + '/s';
76
+ }
77
+ export function summarize(input) {
78
+ const limit = input.limit ?? 96;
79
+ const calls = input.calls.map((call) => narrateCall(call, limit));
80
+ const phase = resolvePhase(input.calls, input.answer, input.reasoning, input.running);
81
+ return {
82
+ phase,
83
+ reasoning: input.reasoning,
84
+ answer: input.answer,
85
+ calls,
86
+ lead: leadSentence(phase, calls, input.reasoning, input.answer, limit),
87
+ };
88
+ }
89
+ function resolvePhase(calls, answer, reasoning, running) {
90
+ if (calls.length > 0)
91
+ return 'calling';
92
+ if (answer.length > 0)
93
+ return 'writing';
94
+ if (reasoning.length > 0)
95
+ return 'thinking';
96
+ return running ? 'holding' : 'idle';
97
+ }
98
+ const PHASE_LABEL = {
99
+ idle: 'Ready',
100
+ thinking: 'Thinking',
101
+ writing: 'Writing',
102
+ calling: 'Acting',
103
+ holding: 'Working',
104
+ };
105
+ export function phaseLabel(phase) {
106
+ return PHASE_LABEL[phase];
107
+ }
108
+ function leadSentence(phase, calls, reasoning, answer, limit) {
109
+ const tail = lastLine(phase === 'writing' ? answer : reasoning, limit);
110
+ if (tail.length > 0)
111
+ return tail;
112
+ const head = calls[0];
113
+ if (head === undefined)
114
+ return '';
115
+ const target = head.argument.length > 0 ? ' ' + head.argument : '';
116
+ const more = calls.length > 1 ? ' +' + String(calls.length - 1) : '';
117
+ return (head.preparing ? head.verb + ' \u2026' + target : head.verb + target) + more;
118
+ }
119
+ function lastLine(text, limit) {
120
+ const trimmed = text.trimEnd();
121
+ const breakAt = trimmed.lastIndexOf('\n');
122
+ return clip(breakAt >= 0 ? trimmed.slice(breakAt + 1) : trimmed, limit);
123
+ }
124
+ //# sourceMappingURL=live.js.map
@@ -0,0 +1,9 @@
1
+ export interface NarrationOptions {
2
+ readonly intentLine: boolean;
3
+ readonly parallelReads: boolean;
4
+ readonly intentWords: number;
5
+ }
6
+ export declare const SECTION_NAME = "d0nj-narration";
7
+ export declare const SECTION_ORDER = 700;
8
+ export declare function buildNarrationSection(options: NarrationOptions): string | null;
9
+ //# sourceMappingURL=narration.d.ts.map
@@ -0,0 +1,27 @@
1
+ export const SECTION_NAME = 'd0nj-narration';
2
+ export const SECTION_ORDER = 700;
3
+ const INTENT_RULE = [
4
+ 'Before every tool call, open the message with one sentence of intent that names the exact file, command or symbol you are about to touch, then make the call in that same message.',
5
+ '',
6
+ 'Reading src/server.rs to trace how frames are dispatched.',
7
+ '',
8
+ '- One sentence, present tense, no preamble.',
9
+ '- Never send a message that only announces work.',
10
+ '- Never restate a call\u2019s own arguments in prose.',
11
+ ].join('\n');
12
+ const PARALLEL_RULE = [
13
+ 'When calls are independent, put them in one message: read, grep, glob and read_image run concurrently, and the single intent sentence covers the batch.',
14
+ ].join('\n');
15
+ export function buildNarrationSection(options) {
16
+ if (!options.intentLine && !options.parallelReads)
17
+ return null;
18
+ const parts = ['## Narration before action'];
19
+ if (options.intentLine) {
20
+ parts.push(INTENT_RULE);
21
+ parts.push('Keep it under ' + String(options.intentWords) + ' words.');
22
+ }
23
+ if (options.parallelReads)
24
+ parts.push(PARALLEL_RULE);
25
+ return parts.join('\n\n');
26
+ }
27
+ //# sourceMappingURL=narration.js.map
@@ -0,0 +1,17 @@
1
+ export declare function frameBudget(pending: number): number;
2
+ export declare class PacedText {
3
+ #private;
4
+ get pending(): number;
5
+ get closed(): boolean;
6
+ push(text: string): void;
7
+ close(): void;
8
+ take(): string;
9
+ reset(): void;
10
+ }
11
+ export declare class RateMeter {
12
+ #private;
13
+ constructor(spanMs?: number);
14
+ sample(at: number, total: number): number;
15
+ reset(): void;
16
+ }
17
+ //# sourceMappingURL=pacing.d.ts.map
package/dist/pacing.js ADDED
@@ -0,0 +1,92 @@
1
+ export function frameBudget(pending) {
2
+ if (pending <= 0)
3
+ return 0;
4
+ if (pending <= 2)
5
+ return pending;
6
+ if (pending <= 16)
7
+ return 2;
8
+ if (pending <= 96)
9
+ return 4;
10
+ if (pending <= 320)
11
+ return 8;
12
+ return Math.max(16, Math.ceil(pending / 6));
13
+ }
14
+ function pairSafeLength(text) {
15
+ const last = text.charCodeAt(text.length - 1);
16
+ return last >= 0xd800 && last <= 0xdbff ? text.length - 1 : text.length;
17
+ }
18
+ export class PacedText {
19
+ #parts = [];
20
+ #pending = 0;
21
+ #closed = false;
22
+ get pending() {
23
+ return this.#pending;
24
+ }
25
+ get closed() {
26
+ return this.#closed;
27
+ }
28
+ push(text) {
29
+ if (text.length === 0)
30
+ return;
31
+ this.#parts.push(text);
32
+ this.#pending += text.length;
33
+ }
34
+ close() {
35
+ this.#closed = true;
36
+ }
37
+ take() {
38
+ const limit = Math.min(frameBudget(this.#pending), this.#pending);
39
+ if (limit <= 0)
40
+ return '';
41
+ let out = '';
42
+ let need = limit;
43
+ while (need > 0) {
44
+ const head = this.#parts[0];
45
+ if (head === undefined)
46
+ break;
47
+ if (head.length <= need) {
48
+ out += head;
49
+ this.#parts.shift();
50
+ need -= head.length;
51
+ continue;
52
+ }
53
+ out += head.slice(0, need);
54
+ this.#parts[0] = head.slice(need);
55
+ need = 0;
56
+ }
57
+ const usable = pairSafeLength(out);
58
+ if (usable < out.length)
59
+ this.#parts.unshift(out.slice(usable));
60
+ this.#pending -= usable;
61
+ return out.slice(0, usable);
62
+ }
63
+ reset() {
64
+ this.#parts = [];
65
+ this.#pending = 0;
66
+ this.#closed = false;
67
+ }
68
+ }
69
+ export class RateMeter {
70
+ #window = [];
71
+ #spanMs;
72
+ constructor(spanMs = 1200) {
73
+ this.#spanMs = spanMs;
74
+ }
75
+ sample(at, total) {
76
+ const window = this.#window;
77
+ window.push({ at, total });
78
+ while (window.length > 1 && at - window[0].at > this.#spanMs)
79
+ window.shift();
80
+ const first = window[0];
81
+ if (first === undefined || window.length < 2)
82
+ return 0;
83
+ const elapsed = at - first.at;
84
+ if (elapsed <= 0)
85
+ return 0;
86
+ return Math.max(0, ((total - first.total) * 1000) / elapsed);
87
+ }
88
+ reset() {
89
+ this.#window.length = 0;
90
+ }
91
+ }
92
+ //# sourceMappingURL=pacing.js.map
package/icon.svg ADDED
@@ -0,0 +1,16 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Live Narration">
2
+ <defs>
3
+ <linearGradient id="live" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0" stop-color="#34d399"/>
5
+ <stop offset="0.55" stop-color="#22d3ee"/>
6
+ <stop offset="1" stop-color="#3f8cff"/>
7
+ </linearGradient>
8
+ </defs>
9
+ <rect x="6" y="6" width="52" height="52" rx="12" fill="none" stroke="url(#live)" stroke-width="2.6"/>
10
+ <g stroke="url(#live)" stroke-width="2.8" stroke-linecap="round" fill="none">
11
+ <line x1="16" y1="22" x2="48" y2="22" opacity="0.4"/>
12
+ <line x1="16" y1="32" x2="42" y2="32" opacity="0.7"/>
13
+ <line x1="16" y1="42" x2="28" y2="42"/>
14
+ </g>
15
+ <rect x="31.5" y="36.5" width="4" height="11" rx="1.4" fill="url(#live)"/>
16
+ </svg>
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Live Narration",
4
+ "description": "Keep the agent's work on screen while it happens: a streaming reasoning tail, tool calls with arguments still being written, elapsed time and throughput, plus a prompt rule that makes the agent state its intent before every action."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "实时叙述",
4
+ "description": "在智能体工作时持续显示进度:流式推理摘要、参数尚在生成中的工具调用、耗时与吞吐量,并通过提示规则要求智能体在每次操作前用一句话说明意图。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@d0nj/dsh-narration",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.3.0",
4
+ "description": "Always-on live narration for the DeepSeek Harness Web UI: streaming reasoning, preparing tool calls and a frame-paced activity rail instead of collapsed blocks and blank spinners.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/d0nj/dsh-plugins.git",
9
+ "directory": "packages/narration"
10
+ },
11
+ "keywords": [
12
+ "dsh-plugin",
13
+ "deepseek-harness",
14
+ "cordis",
15
+ "streaming",
16
+ "ui"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "type": "module",
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./client": "./dist/client/client.js",
30
+ "./locale/*.json": "./locale/*.json",
31
+ "./icon": "./icon.svg"
32
+ },
33
+ "files": [
34
+ "dist/**/*.js",
35
+ "dist/**/*.d.ts",
36
+ "dist/client/client.js",
37
+ "cordis.patch.yml",
38
+ "locale/*.json",
39
+ "icon.svg",
40
+ "README.md"
41
+ ],
42
+ "dsh": {
43
+ "bundle": {
44
+ "patch": "./cordis.patch.yml"
45
+ },
46
+ "client": {
47
+ "platform": "web",
48
+ "immediately": true,
49
+ "inject": [
50
+ "@deepseek-ai/dsh-client-ui-slots"
51
+ ]
52
+ }
53
+ },
54
+ "peerDependencies": {
55
+ "@deepseek-ai/cordis": "~4.1.0",
56
+ "@deepseek-ai/schemastery": "~3.19.0"
57
+ },
58
+ "devDependencies": {
59
+ "@deepseek-ai/cordis": "~4.1.0",
60
+ "@deepseek-ai/schemastery": "~3.19.0",
61
+ "@types/node": "^24.0.0",
62
+ "typescript": "^5.9.0"
63
+ },
64
+ "scripts": {
65
+ "build": "tsc -p tsconfig.build.json && node scripts/stamp-client.mjs",
66
+ "typecheck": "tsc -p tsconfig.test.json --noEmit",
67
+ "pretest": "tsc -p tsconfig.test.json",
68
+ "test": "node --test \"dist-test/**/*.test.js\"",
69
+ "check": "node --check dist/index.js && node --check dist/client/client.js && node --check dist/pacing.js && node --check dist/live.js && node --check dist/diff.js && node --check dist/ansi.js && node --check dist/envelope.js && node --check dist/narration.js",
70
+ "clean": "node -e \"const fs=require('node:fs');for(const d of ['dist','dist-test'])fs.rmSync(d,{recursive:true,force:true})\""
71
+ }
6
72
  }