@nelsonlongxiang/dsh-prompt-templates 0.4.4 → 0.13.2

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.
Files changed (50) hide show
  1. package/README.md +113 -62
  2. package/README_zh.md +112 -62
  3. package/cordis.patch.yml +4 -0
  4. package/lib/cli/app.js +169 -0
  5. package/lib/cli/database.js +162 -0
  6. package/lib/cli/main.js +6 -0
  7. package/lib/cli/model.js +247 -0
  8. package/lib/client/Library.js +290 -0
  9. package/lib/client/Panel.js +37 -201
  10. package/lib/client/PanelButton.js +27 -3
  11. package/lib/client/PromptTab.js +11 -0
  12. package/lib/client/api.js +16 -0
  13. package/lib/client/filter.js +27 -0
  14. package/lib/client/index.js +53 -36
  15. package/lib/client/locales.js +34 -2
  16. package/lib/client/meta.js +10 -0
  17. package/lib/client/service.js +57 -37
  18. package/lib/client/slots.js +5 -3
  19. package/lib/client/store.js +12 -1
  20. package/lib/client/tab.js +32 -0
  21. package/lib/client.js +798 -286
  22. package/lib/client.js.map +1 -1
  23. package/lib/index.js +35 -16
  24. package/lib/inject.js +236 -0
  25. package/lib/invariant.js +1 -1
  26. package/lib/store.js +108 -32
  27. package/lib/types/cli/app.d.ts +1 -0
  28. package/lib/types/cli/database.d.ts +69 -0
  29. package/lib/types/cli/main.d.ts +2 -0
  30. package/lib/types/cli/model.d.ts +62 -0
  31. package/lib/types/client/Library.d.ts +34 -0
  32. package/lib/types/client/Panel.d.ts +1 -1
  33. package/lib/types/client/PanelButton.d.ts +10 -9
  34. package/lib/types/client/PromptTab.d.ts +17 -0
  35. package/lib/types/client/api.d.ts +11 -1
  36. package/lib/types/client/filter.d.ts +10 -0
  37. package/lib/types/client/index.d.ts +6 -2
  38. package/lib/types/client/locales.d.ts +34 -2
  39. package/lib/types/client/meta.d.ts +6 -0
  40. package/lib/types/client/service.d.ts +50 -6
  41. package/lib/types/client/slots.d.ts +57 -5
  42. package/lib/types/client/store.d.ts +14 -1
  43. package/lib/types/client/tab.d.ts +31 -0
  44. package/lib/types/index.d.ts +8 -1
  45. package/lib/types/inject.d.ts +150 -0
  46. package/lib/types/store.d.ts +27 -4
  47. package/lib/types/types.d.ts +49 -0
  48. package/lib/types/variables.d.ts +24 -0
  49. package/lib/variables.js +36 -0
  50. package/package.json +98 -105
@@ -1,17 +1,24 @@
1
1
  /**
2
2
  * Pure-TS template store over `node:sqlite`, replacing the former Python
3
3
  * backend child. Owns the same SQLite database file and schema
4
- * (`templates` table, `user_version` 1), so an existing
5
- * `$DSH_HOME/ext/prompt-templates/db.sqlite3` keeps working unchanged.
4
+ * (`templates` + `categories` tables, `user_version` 4), so an existing
5
+ * `$DSH_HOME/ext/prompt-templates/db.sqlite3` keeps working and migrates
6
+ * in place.
6
7
  *
7
8
  * Business rules ported verbatim from the Python store:
8
9
  * - a template name is unique within its scope partition `(scope, session_id)`
9
10
  * - `scope='session'` requires `session_id`; `scope='global'` must not carry one
10
11
  * - make-global rejects already-global rows and global name collisions
12
+ * and extended in v3 with the auto-inject facts:
13
+ * - `inject_enabled` toggles per-round scheduled injection
14
+ * - `inject_every` is the interval in rounds (1..injectMaxEvery); it is
15
+ * required whenever `inject_enabled` is on and may persist while off
11
16
  *
12
17
  * @module dsh-prompt-templates/store
13
18
  */
14
- import type { CategoryCreateRequest, CategoryView, PromptScope, TemplateCreateRequest, TemplateUpdateRequest, TemplateView } from './types.ts';
19
+ import type { CategoryCreateRequest, CategoryView, PromptScope, TemplateCreateRequest, TemplateInjectMode, TemplateUpdateRequest, TemplateView } from './types.ts';
20
+ /** Upper bound of the inject interval when the deployment config omits one. */
21
+ export declare const DEFAULT_INJECT_MAX_EVERY = 1000;
15
22
  /** Business-rule violation surfaced to routes as HTTP 400. */
16
23
  export declare class TemplateRuleError extends Error {
17
24
  constructor(message: string);
@@ -26,18 +33,34 @@ export interface TemplateRow {
26
33
  description: string | null;
27
34
  position: number;
28
35
  category: string | null;
36
+ /** Storage truth for the auto-inject switch: 1 = on, 0 = off. */
37
+ inject_enabled: 0 | 1;
38
+ /** Injection interval in rounds; `null` when never configured. */
39
+ inject_every: number | null;
40
+ /** Scheduled-injection delivery mode ('inject' default, 'visible' = user channel). */
41
+ mode: TemplateInjectMode;
29
42
  created_at: string;
30
43
  updated_at: string;
31
44
  }
45
+ /** Storage options a deployment may tune. */
46
+ export interface TemplateStoreOptions {
47
+ /** Upper bound accepted for `inject_every`; defaults to {@link DEFAULT_INJECT_MAX_EVERY}. */
48
+ readonly injectMaxEvery?: number;
49
+ }
32
50
  /** Pure-TS prompt-template store owning one SQLite database file. */
33
51
  export declare class TemplateStore {
34
52
  #private;
35
53
  private readonly db;
36
- constructor(dbPath: string);
54
+ constructor(dbPath: string, options?: TemplateStoreOptions);
37
55
  /** Close the underlying database handle. */
38
56
  close(): void;
39
57
  /** List templates ordered by position then creation time, with optional scope/session filters. */
40
58
  list(scope?: string, sessionId?: string): TemplateView[];
59
+ /**
60
+ * List injection-enabled templates that apply to one session: global ones
61
+ * plus the session's own, ordered by position then creation time.
62
+ */
63
+ listInjectable(sessionId: string): TemplateView[];
41
64
  /** Fetch one template; `undefined` when absent. */
42
65
  get(id: string): TemplateView | undefined;
43
66
  /** Insert a template, rejecting a duplicate name in its scope partition. */
@@ -6,6 +6,14 @@
6
6
  */
7
7
  /** Scope partition of one template: global or private to one session. */
8
8
  export type PromptScope = 'global' | 'session';
9
+ /**
10
+ * Delivery mode of a scheduled injection: `inject` (default) rides the
11
+ * pre-step waterfall as a model-only `<system-reminder>` (invisible in the
12
+ * chat transcript by DSH design); `visible` stamps the message with the
13
+ * user channel source so the chat view renders it as a normal user message
14
+ * (with a header marker naming it as a scheduled injection).
15
+ */
16
+ export type TemplateInjectMode = 'inject' | 'visible';
9
17
  /** Canonical template record as stored by the backend. */
10
18
  export interface TemplateView {
11
19
  readonly id: string;
@@ -18,6 +26,12 @@ export interface TemplateView {
18
26
  readonly position: number;
19
27
  /** Category name; `null` = one of the default tabs (全局/会话模板). */
20
28
  readonly category: string | null;
29
+ /** Auto-inject switch: the host injects this template every N rounds. */
30
+ readonly inject_enabled: boolean;
31
+ /** Injection interval in rounds; `null` when never configured. */
32
+ readonly inject_every: number | null;
33
+ /** Scheduled-injection delivery mode; defaults to `inject`. */
34
+ readonly mode: TemplateInjectMode;
21
35
  /** ISO timestamp without timezone, as emitted by the backend. */
22
36
  readonly created_at: string;
23
37
  readonly updated_at: string;
@@ -38,6 +52,9 @@ export interface TemplateCreateRequest {
38
52
  readonly description?: string | null;
39
53
  readonly position?: number;
40
54
  readonly category?: string | null;
55
+ readonly inject_enabled?: boolean;
56
+ readonly inject_every?: number | null;
57
+ readonly mode?: TemplateInjectMode;
41
58
  }
42
59
  /** Update payload; every field optional. */
43
60
  export interface TemplateUpdateRequest {
@@ -46,6 +63,9 @@ export interface TemplateUpdateRequest {
46
63
  readonly description?: string | null;
47
64
  readonly position?: number;
48
65
  readonly category?: string | null;
66
+ readonly inject_enabled?: boolean;
67
+ readonly inject_every?: number | null;
68
+ readonly mode?: TemplateInjectMode;
49
69
  }
50
70
  /** Category create payload. */
51
71
  export interface CategoryCreateRequest {
@@ -53,3 +73,32 @@ export interface CategoryCreateRequest {
53
73
  readonly scope?: PromptScope;
54
74
  readonly session_id?: string | null;
55
75
  }
76
+ /**
77
+ * Client-facing summary of a session's latest scheduled injection, polled by
78
+ * the panel/tab toolbar badge (`⟳N`). Lives here (not in inject.ts) because
79
+ * the client bundles type-import it and must not pull the host-only module
80
+ * graph (node:sqlite, dsh-agent) into the browser tsconfig project.
81
+ */
82
+ export interface InjectionStatusView {
83
+ /** The boundary turn the latest injection landed on (1-based, durable). */
84
+ readonly turn: number;
85
+ /** Wall-clock epoch milliseconds of the injection. */
86
+ readonly at: number;
87
+ /** Template names carried by that injection, in injection order. */
88
+ readonly templates: readonly string[];
89
+ }
90
+ /**
91
+ * One recent scheduled injection in a session's history (newest first),
92
+ * rendered by the panel badge's history dropdown. Adds the injected bodies
93
+ * to the status summary so the dropdown can show what actually went out.
94
+ */
95
+ export interface InjectionHistoryEntry {
96
+ /** The boundary turn this injection landed on (1-based, durable). */
97
+ readonly turn: number;
98
+ /** Wall-clock epoch milliseconds of the injection. */
99
+ readonly at: number;
100
+ /** Template names carried by this injection, in injection order. */
101
+ readonly templates: readonly string[];
102
+ /** The injected template bodies, joined in injection order. */
103
+ readonly content: string;
104
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Template-variable expansion, shared by the host scheduled-injection path
3
+ * and the composer delivery verbs (insert / send / interject). Client-safe:
4
+ * no host-only imports, so the browser tsconfig project bundles it too.
5
+ *
6
+ * Semantics: a variable expands ONLY when its value is available in the
7
+ * delivery context; unavailable and unknown placeholders stay literal, so
8
+ * the user sees what did not resolve instead of a silent deletion. Storage
9
+ * always keeps the raw template — expansion is a delivery-time concern.
10
+ * @module dsh-prompt-templates/variables
11
+ */
12
+ /** Variable names the expander understands (the advertised set). */
13
+ export declare const TEMPLATE_VARIABLES: readonly ["date", "time", "datetime", "weekday", "session", "turn"];
14
+ /** What one delivery can tell the expander; every field optional. */
15
+ export interface VariableContext {
16
+ /** The instant clock variables render from; defaults to now. */
17
+ readonly now?: Date;
18
+ /** The session the delivery targets, when known. */
19
+ readonly sessionId?: string;
20
+ /** The boundary turn, when the delivery is a scheduled injection. */
21
+ readonly turn?: number;
22
+ }
23
+ /** Expand every resolvable placeholder in the content; the rest passes through. */
24
+ export declare function expandTemplateVariables(content: string, context: VariableContext): string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Template-variable expansion, shared by the host scheduled-injection path
3
+ * and the composer delivery verbs (insert / send / interject). Client-safe:
4
+ * no host-only imports, so the browser tsconfig project bundles it too.
5
+ *
6
+ * Semantics: a variable expands ONLY when its value is available in the
7
+ * delivery context; unavailable and unknown placeholders stay literal, so
8
+ * the user sees what did not resolve instead of a silent deletion. Storage
9
+ * always keeps the raw template — expansion is a delivery-time concern.
10
+ * @module dsh-prompt-templates/variables
11
+ */
12
+ /** Variable names the expander understands (the advertised set). */
13
+ export const TEMPLATE_VARIABLES = ['date', 'time', 'datetime', 'weekday', 'session', 'turn'];
14
+ /** The placeholder namespace: a double-brace name with optional inner spacing. */
15
+ const PATTERN = /\{\{\s*(date|time|datetime|weekday|session|turn)\s*\}\}/g;
16
+ const WEEKDAYS = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
17
+ function pad(value) {
18
+ return String(value).padStart(2, '0');
19
+ }
20
+ /** Expand every resolvable placeholder in the content; the rest passes through. */
21
+ export function expandTemplateVariables(content, context) {
22
+ const now = context.now ?? new Date();
23
+ const date = now.getFullYear() + '-' + pad(now.getMonth() + 1) + '-' + pad(now.getDate());
24
+ const clock = pad(now.getHours()) + ':' + pad(now.getMinutes());
25
+ return content.replace(PATTERN, (match, name) => {
26
+ switch (name) {
27
+ case 'date': return date;
28
+ case 'time': return clock;
29
+ case 'datetime': return date + ' ' + clock;
30
+ case 'weekday': return WEEKDAYS[now.getDay()] ?? match;
31
+ case 'session': return context.sessionId ?? match;
32
+ case 'turn': return context.turn !== undefined ? String(context.turn) : match;
33
+ default: return match;
34
+ }
35
+ });
36
+ }
package/package.json CHANGED
@@ -1,105 +1,98 @@
1
- {
2
- "name": "@nelsonlongxiang/dsh-prompt-templates",
3
- "version": "0.4.4",
4
- "description": "Quick prompt templates for DeepSeek Harness: global and per-session templates, a browser panel, and a pure-TS node:sqlite persistence backend",
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "types": "lib/types/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/types/index.d.ts",
11
- "default": "./lib/index.js"
12
- },
13
- "./client": {
14
- "types": "./lib/types/client/index.d.ts",
15
- "default": "./lib/client.js"
16
- },
17
- "./cordis.patch.yml": "./cordis.patch.yml",
18
- "./package.json": "./package.json"
19
- },
20
- "files": [
21
- "lib",
22
- "cordis.patch.yml",
23
- "README.md",
24
- "README_zh.md",
25
- "images"
26
- ],
27
- "dsh": {
28
- "bundle": {
29
- "patch": "./cordis.patch.yml"
30
- },
31
- "client": {
32
- "platform": "web",
33
- "inject": [
34
- "@deepseek-ai/dsh-client-runtime",
35
- "@deepseek-ai/dsh-client-locale",
36
- "@deepseek-ai/dsh-client-ui-conversation"
37
- ]
38
- }
39
- },
40
- "scripts": {
41
- "build": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && tsdown",
42
- "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.client.json --noEmit",
43
- "prepare": "pnpm build",
44
- "verify": "pnpm typecheck"
45
- },
46
- "peerDependencies": {
47
- "@deepseek-ai/cordis": ">=4.0.1-rc.1",
48
- "@deepseek-ai/dsh-invariants": ">=0.1.0-rc.6",
49
- "@deepseek-ai/dsh-settings": ">=0.1.0-rc.6",
50
- "@deepseek-ai/dsh-subprocess": ">=0.1.0-rc.6",
51
- "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.6",
52
- "@deepseek-ai/dsh-client-runtime": ">=0.1.0-rc.6",
53
- "@deepseek-ai/dsh-client-ui-conversation": ">=0.1.0-rc.6",
54
- "@deepseek-ai/dsh-client-ui-primitives": ">=0.1.0-rc.6",
55
- "@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.6",
56
- "@deepseek-ai/schemastery": ">=3.18.1-rc.1",
57
- "react": "^18.2.0"
58
- },
59
- "peerDependenciesMeta": {
60
- "@deepseek-ai/cordis": {
61
- "optional": true
62
- },
63
- "@deepseek-ai/dsh-invariants": {
64
- "optional": true
65
- },
66
- "@deepseek-ai/dsh-settings": {
67
- "optional": true
68
- },
69
- "@deepseek-ai/dsh-subprocess": {
70
- "optional": true
71
- },
72
- "@deepseek-ai/dsh-client-locale": {
73
- "optional": true
74
- },
75
- "@deepseek-ai/dsh-client-runtime": {
76
- "optional": true
77
- },
78
- "@deepseek-ai/dsh-client-ui-conversation": {
79
- "optional": true
80
- },
81
- "@deepseek-ai/dsh-client-ui-primitives": {
82
- "optional": true
83
- },
84
- "@deepseek-ai/dsh-client-ui-slots": {
85
- "optional": true
86
- },
87
- "@deepseek-ai/schemastery": {
88
- "optional": true
89
- },
90
- "react": {
91
- "optional": true
92
- }
93
- },
94
- "devDependencies": {
95
- "@types/node": "^24.13.3",
96
- "@types/react": "~18.3.1",
97
- "@types/react-dom": "^18.3.7",
98
- "lightningcss": "^1.33.0",
99
- "react": "^18.2.0",
100
- "react-dom": "^18.2.0",
101
- "tsdown": "0.22.2",
102
- "typescript": "^5.9.3"
103
- },
104
- "license": "MIT"
105
- }
1
+ {
2
+ "name": "@nelsonlongxiang/dsh-prompt-templates",
3
+ "version": "0.13.2",
4
+ "description": "Quick prompt templates for DeepSeek Harness: global and per-session templates, a browser panel, and a pure-TS node:sqlite persistence backend",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "lib/types/index.d.ts",
8
+ "bin": {
9
+ "dsh-prompt-templates": "./lib/cli/main.js"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/types/index.d.ts",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./client": {
17
+ "types": "./lib/types/client/index.d.ts",
18
+ "default": "./lib/client.js"
19
+ },
20
+ "./cordis.patch.yml": "./cordis.patch.yml",
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "lib",
25
+ "cordis.patch.yml",
26
+ "README.md",
27
+ "README_zh.md",
28
+ "images"
29
+ ],
30
+ "dsh": {
31
+ "bundle": {
32
+ "patch": "./cordis.patch.yml"
33
+ },
34
+ "client": {
35
+ "platform": "web",
36
+ "inject": [
37
+ "@deepseek-ai/dsh-client-locale",
38
+ "@deepseek-ai/dsh-client-ui-conversation"
39
+ ]
40
+ }
41
+ },
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && tsdown",
44
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.client.json --noEmit",
45
+ "test:cli": "node --experimental-strip-types --test tests/*.test.ts",
46
+ "test:package": "node tests/cli-package.mjs",
47
+ "prepare": "pnpm build",
48
+ "verify": "pnpm typecheck && pnpm test:cli && pnpm build && pnpm test:package",
49
+ "verify:release": "pnpm verify"
50
+ },
51
+ "peerDependencies": {
52
+ "@deepseek-ai/cordis": ">=4.0.1-rc.1",
53
+ "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.6 || >=0.2.0-rc.1",
54
+ "@deepseek-ai/dsh-client-store": ">=0.2.0-rc.1",
55
+ "@deepseek-ai/dsh-client-ui-conversation": ">=0.1.0-rc.6 || >=0.2.0-rc.1",
56
+ "@deepseek-ai/dsh-client-ui-layout": ">=0.1.0-rc.6 || >=0.2.0-rc.1",
57
+ "@deepseek-ai/dsh-client-ui-primitives": ">=0.1.0-rc.6 || >=0.2.0-rc.1",
58
+ "@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.6 || >=0.2.0-rc.1",
59
+ "@deepseek-ai/dsh-invariants": ">=0.1.0-rc.6 || >=0.2.0-rc.1",
60
+ "@deepseek-ai/dsh-settings": ">=0.1.0-rc.6 || >=0.2.0-rc.1",
61
+ "@deepseek-ai/schemastery": ">=3.18.1-rc.1",
62
+ "react": "^18.2.0"
63
+ },
64
+ "devDependencies": {
65
+ "@types/node": "^24.13.3",
66
+ "@types/react": "~18.3.1",
67
+ "@types/react-dom": "^18.3.7",
68
+ "@deepseek-ai/cordis": "4.0.5",
69
+ "@deepseek-ai/schemastery": "3.18.5",
70
+ "@deepseek-ai/dsh-agent": "0.2.1-rc.2",
71
+ "@deepseek-ai/dsh-llm": "0.2.1-rc.2",
72
+ "@deepseek-ai/dsh-session": "0.2.1-rc.2",
73
+ "@deepseek-ai/dsh-settings": "0.2.1-rc.2",
74
+ "@deepseek-ai/dsh-invariants": "0.2.0-rc.2",
75
+ "@deepseek-ai/dsh-api-session-controller": "0.2.1-rc.2",
76
+ "@deepseek-ai/dsh-client-store": "0.2.1-rc.2",
77
+ "@deepseek-ai/dsh-client-locale": "0.2.1-rc.2",
78
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-rc.2",
79
+ "@deepseek-ai/dsh-client-ui-layout": "0.2.1-rc.2",
80
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.2",
81
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.2",
82
+ "@deepseek-ai/dsh-client-ui-session": "0.2.1-rc.2",
83
+ "@deepseek-ai/dsh-client-ui-sidebar-right": "0.2.1-rc.2",
84
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.2",
85
+ "lightningcss": "^1.33.0",
86
+ "react": "^18.2.0",
87
+ "react-dom": "^18.2.0",
88
+ "tsdown": "0.22.2",
89
+ "typescript": "^5.9.3"
90
+ },
91
+ "license": "MIT",
92
+ "overrides": {
93
+ "@deepseek-ai/dsh-settings": "0.2.1-rc.2",
94
+ "@deepseek-ai/dsh-agent": "0.2.1-rc.2",
95
+ "@deepseek-ai/dsh-llm": "0.2.1-rc.2",
96
+ "@deepseek-ai/dsh-session": "0.2.1-rc.2"
97
+ }
98
+ }