@westwall/dsh-friendly-expression 0.0.0-stage → 0.1.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.
@@ -0,0 +1,83 @@
1
+ /** Per-session prompt snapshots stay durable when storage is present and in memory otherwise. */
2
+ import { z } from 'zod';
3
+ import { defineDomain, domainTable } from '@deepseek-ai/dsh-storage-domain';
4
+ import { MAX_SECTION_CHARS } from "./prompt.js";
5
+ const WARNING_PREFIX = '[dsh-friendly-expression]';
6
+ // The cap covers the hidden prefix plus a maximum-length body, so a legacy
7
+ // body-only record still fits. A tighter cap would fail schema validation on
8
+ // the next open, where the domain backs the record up and skips it.
9
+ const promptSnapshotSchema = z.object({
10
+ prompt: z.string().max(MAX_SECTION_CHARS),
11
+ capturedAt: z.number().int().nonnegative(),
12
+ }).strict();
13
+ export const promptSnapshotDomain = defineDomain({
14
+ name: 'friendly_expression',
15
+ version: 1,
16
+ layout: 'per-record',
17
+ invalidRecords: 'backup-and-skip',
18
+ tables: {
19
+ sessions: domainTable(promptSnapshotSchema),
20
+ },
21
+ });
22
+ function warn(message, error) {
23
+ if (error === undefined)
24
+ console.warn(`${WARNING_PREFIX} ${message}`);
25
+ else
26
+ console.warn(`${WARNING_PREFIX} ${message}`, error);
27
+ }
28
+ function createCachedStore(now, table, closeDomain) {
29
+ const cache = new Map();
30
+ return {
31
+ get(sessionId) {
32
+ const cached = cache.get(sessionId);
33
+ if (cached !== undefined)
34
+ return cached.prompt;
35
+ const stored = table?.get(sessionId);
36
+ if (stored !== undefined)
37
+ cache.set(sessionId, stored);
38
+ return stored?.prompt;
39
+ },
40
+ async capture(sessionId, prompt) {
41
+ const snapshot = { prompt, capturedAt: now() };
42
+ cache.set(sessionId, snapshot);
43
+ if (table === undefined)
44
+ return;
45
+ try {
46
+ await table.put(sessionId, snapshot);
47
+ }
48
+ catch (error) {
49
+ warn(`failed to persist the prompt snapshot for session ${sessionId}`, error);
50
+ throw error;
51
+ }
52
+ },
53
+ async close() {
54
+ cache.clear();
55
+ await closeDomain?.();
56
+ },
57
+ };
58
+ }
59
+ /** Process-local fallback. A capture is readable before its returned promise settles. */
60
+ export function createMemorySnapshotStore(now = Date.now) {
61
+ return createCachedStore(now);
62
+ }
63
+ /** Open the durable domain when the Host provides it, otherwise keep snapshots for this run. */
64
+ export async function openSnapshotStore(ctx) {
65
+ const facility = ctx.get('storageDomain');
66
+ if (facility === undefined) {
67
+ warn('storageDomain unavailable; keeping prompt snapshots in memory for this run');
68
+ return createMemorySnapshotStore();
69
+ }
70
+ try {
71
+ const domain = await facility.open(promptSnapshotDomain);
72
+ return createCachedStore(Date.now, domain.table('sessions'), () => domain.close());
73
+ }
74
+ catch (error) {
75
+ warn('failed to open the friendly_expression snapshot domain; keeping prompt snapshots in memory for this run', error);
76
+ return createMemorySnapshotStore();
77
+ }
78
+ }
79
+ /** Only a brand new, non-subagent, non-seeded, empty session captures a prompt. */
80
+ export function shouldCapture(input) {
81
+ return !input.isSubagent && !input.isSeeded && !input.hasMessages;
82
+ }
83
+ //# sourceMappingURL=snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,cAAc,GAAG,2BAA2B,CAAA;AAoBlD,2EAA2E;AAC3E,6EAA6E;AAC7E,oEAAoE;AACpE,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,iBAAiB,CAAC;IACzC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EA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C,UAAU,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,WAAW,CAAA;AACnE,CAAC"}
package/locale/en.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "meta": {
3
+ "title": "Friendly expression",
4
+ "description": "Agent replies sprawl and flow diagrams often arrive as ASCII boxes. An editable expression contract constrains wording and structure, and Mermaid fences render as zoomable diagrams."
5
+ },
6
+ "settings.nav": "Friendly expression",
7
+ "settings.title": "Friendly expression",
8
+ "settings.subtitle": "Make the agent say it clearly, and draw it clearly.",
9
+ "settings.cardTitle": "Expression style",
10
+ "settings.cardNote": "New sessions only",
11
+ "settings.description": "This text enters the system prompt on every request and shapes wording, structure, and tone.",
12
+ "settings.placeholder": "Describe how replies should read…",
13
+ "settings.counter": "{count} / {max}",
14
+ "settings.save": "Save",
15
+ "settings.saving": "Saving…",
16
+ "settings.reset": "Restore default",
17
+ "settings.saved": "Saved. New sessions use the new prompt.",
18
+ "settings.saveFailed": "The setting was not saved.",
19
+ "settings.loading": "Reading the configuration…",
20
+ "settings.unavailable": "This Host does not expose the configuration.",
21
+ "settings.readonly": "This configuration is read-only.",
22
+ "settings.hint": "Restoring the default brings back the recommended copy; existing sessions keep their prompt.",
23
+ "badge.tooltip": "Friendly expression is on",
24
+ "fence.source": "View source",
25
+ "fence.diagram": "Diagram",
26
+ "fence.copySource": "Copy source",
27
+ "fence.expand": "Open viewer",
28
+ "fence.copied": "Copied",
29
+ "fence.copyFailed": "Copy failed",
30
+ "fence.copyFeedback": "Copied. Paste it into the conversation.",
31
+ "fence.rendering": "Rendering diagram…",
32
+ "fence.errorTitle": "Diagram could not render",
33
+ "fence.copyError": "Copy error for the agent",
34
+ "fence.viewSource": "View source",
35
+ "fence.errorCopyText": "Mermaid rendering failed. Please regenerate. Error:\n{message}",
36
+ "fence.openViewer": "Open diagram viewer",
37
+ "fence.zoomHint": "Click to enlarge",
38
+ "viewer.copySource": "Copy source",
39
+ "viewer.download": "Download SVG",
40
+ "viewer.close": "Close",
41
+ "viewer.copied": "Copied",
42
+ "viewer.copyFailed": "Copy failed",
43
+ "viewer.saveFailed": "Download failed.",
44
+ "viewer.zoomOut": "Zoom out",
45
+ "viewer.zoomIn": "Zoom in",
46
+ "viewer.fit": "Fit",
47
+ "viewer.actual": "1:1",
48
+ "types.flowchart": "Flowchart",
49
+ "types.sequence": "Sequence diagram",
50
+ "types.state": "State diagram",
51
+ "types.er": "ER diagram",
52
+ "types.class": "Class diagram",
53
+ "types.gantt": "Gantt chart",
54
+ "types.pie": "Pie chart",
55
+ "types.mindmap": "Mindmap",
56
+ "types.timeline": "Timeline",
57
+ "types.journey": "User journey",
58
+ "types.gitGraph": "Git graph",
59
+ "types.quadrant": "Quadrant chart",
60
+ "types.other": "Mermaid diagram"
61
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "meta": {
3
+ "title": "友好表达",
4
+ "description": "Agent 回复容易堆砌跑题,流程图常用 ASCII 方框。用可编辑的受控表达约束措辞与结构,并把 Mermaid 围栏渲染成可缩放的图。"
5
+ },
6
+ "settings.nav": "友好表达",
7
+ "settings.title": "友好表达",
8
+ "settings.subtitle": "让 Agent 说得清楚,也画得明白。",
9
+ "settings.cardTitle": "表达方式",
10
+ "settings.cardNote": "保存后对新会话生效",
11
+ "settings.description": "这段文字会随每个请求进入系统提示词,约束措辞、结构与语气。",
12
+ "settings.placeholder": "写下你希望 Agent 的表达方式…",
13
+ "settings.counter": "{count} / {max}",
14
+ "settings.save": "保存",
15
+ "settings.saving": "保存中…",
16
+ "settings.reset": "恢复默认",
17
+ "settings.saved": "已保存,新会话生效。",
18
+ "settings.saveFailed": "设置未能保存。",
19
+ "settings.loading": "正在读取配置…",
20
+ "settings.unavailable": "当前宿主未提供该配置。",
21
+ "settings.readonly": "当前配置为只读。",
22
+ "settings.hint": "恢复默认会回到系统推荐文案;已有会话保持原提示词。",
23
+ "badge.tooltip": "友好表达已开启",
24
+ "fence.source": "查看源码",
25
+ "fence.diagram": "图表",
26
+ "fence.copySource": "复制源码",
27
+ "fence.expand": "放大查看",
28
+ "fence.copied": "已复制",
29
+ "fence.copyFailed": "复制失败",
30
+ "fence.copyFeedback": "已复制,粘贴发送给 Agent。",
31
+ "fence.rendering": "正在渲染图表…",
32
+ "fence.errorTitle": "图表渲染失败",
33
+ "fence.copyError": "复制错误给 Agent",
34
+ "fence.viewSource": "查看源码",
35
+ "fence.errorCopyText": "Mermaid 渲染失败,请重新生成。错误信息:\n{message}",
36
+ "fence.openViewer": "打开图表浮窗",
37
+ "fence.zoomHint": "点击放大",
38
+ "viewer.copySource": "复制源码",
39
+ "viewer.download": "下载 SVG",
40
+ "viewer.close": "关闭",
41
+ "viewer.copied": "已复制",
42
+ "viewer.copyFailed": "复制失败",
43
+ "viewer.saveFailed": "下载失败。",
44
+ "viewer.zoomOut": "缩小",
45
+ "viewer.zoomIn": "放大",
46
+ "viewer.fit": "适合窗口",
47
+ "viewer.actual": "1:1",
48
+ "types.flowchart": "流程图",
49
+ "types.sequence": "时序图",
50
+ "types.state": "状态图",
51
+ "types.er": "ER 图",
52
+ "types.class": "类图",
53
+ "types.gantt": "甘特图",
54
+ "types.pie": "饼图",
55
+ "types.mindmap": "思维导图",
56
+ "types.timeline": "时间线",
57
+ "types.journey": "用户旅程",
58
+ "types.gitGraph": "Git 图",
59
+ "types.quadrant": "四象限图",
60
+ "types.other": "Mermaid 图表"
61
+ }
package/package.json CHANGED
@@ -1,6 +1,97 @@
1
1
  {
2
2
  "name": "@westwall/dsh-friendly-expression",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "友好表达:可编辑的受控表达约束 Agent 的措辞与结构,并把 Mermaid 围栏渲染成可缩放的图。",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/westwall586/dsh-westwall-plugins.git",
8
+ "directory": "packages/friendly-expression"
9
+ },
10
+ "homepage": "https://github.com/westwall586/dsh-westwall-plugins/tree/main/packages/friendly-expression#readme",
11
+ "keywords": [
12
+ "dsh",
13
+ "dsh-plugin",
14
+ "deepseek-harness",
15
+ "mermaid",
16
+ "diagram",
17
+ "prompt",
18
+ "tone",
19
+ "expression"
20
+ ],
21
+ "type": "module",
22
+ "engines": {
23
+ "node": ">=22.19.0"
24
+ },
25
+ "main": "lib/index.js",
26
+ "types": "lib/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./lib/index.d.ts",
30
+ "default": "./lib/index.js"
31
+ },
32
+ "./client": "./client.js",
33
+ "./locale/*.json": "./locale/*.json",
34
+ "./icon": "./icon.svg",
35
+ "./package.json": "./package.json"
36
+ },
37
+ "dsh": {
38
+ "manifestVersion": 1,
39
+ "bundle": {
40
+ "patch": "./cordis.patch.yml"
41
+ },
42
+ "engines": {
43
+ "dsh": ">=0.2.2-rc.2"
44
+ },
45
+ "client": {
46
+ "platform": "web"
47
+ }
48
+ },
49
+ "scripts": {
50
+ "build": "tsc -p tsconfig.json && node tools/build-client.mjs",
51
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p client/tsconfig.json",
52
+ "test": "node --test 'test/**/*.test.ts'"
53
+ },
54
+ "dependencies": {
55
+ "zod": "4.6.6"
56
+ },
57
+ "devDependencies": {
58
+ "@deepseek-ai/cordis": "^4.0.4",
59
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.2",
60
+ "@deepseek-ai/dsh-storage-domain": "0.2.2-rc.2",
61
+ "@deepseek-ai/schemastery": "^3.19.0",
62
+ "@types/node": "^24.0.0",
63
+ "@types/react": "^19.0.0",
64
+ "esbuild": "^0.25.0",
65
+ "mermaid": "11.15.0",
66
+ "typescript": "~5.9.3"
67
+ },
68
+ "files": [
69
+ "lib",
70
+ "client.js",
71
+ "cordis.patch.yml",
72
+ "locale",
73
+ "icon.svg",
74
+ "README.md",
75
+ "docs",
76
+ "icon-180.png",
77
+ "icon-512.png",
78
+ "assets",
79
+ "screenshots.json"
80
+ ],
81
+ "license": "Apache-2.0",
82
+ "publishConfig": {
83
+ "access": "public",
84
+ "registry": "https://registry.npmjs.org/"
85
+ },
86
+ "peerDependencies": {
87
+ "@deepseek-ai/cordis": "^4.0.4",
88
+ "@deepseek-ai/dsh": "^0.2.2-rc.2",
89
+ "@deepseek-ai/dsh-storage-domain": ">=0.2.2-rc.2 <0.3.0",
90
+ "@deepseek-ai/schemastery": "^3.19.0"
91
+ },
92
+ "peerDependenciesMeta": {
93
+ "@deepseek-ai/dsh": {
94
+ "optional": true
95
+ }
96
+ }
97
+ }
@@ -0,0 +1,6 @@
1
+ [
2
+ "assets/screenshot-1.png",
3
+ "assets/screenshot-2.png",
4
+ "assets/screenshot-3.png",
5
+ "assets/screenshot-4.png"
6
+ ]