@morlay/dsh-context-assembler 0.0.10 → 0.0.11-alpha.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.
package/dist/index.d.mts CHANGED
@@ -1,12 +1,9 @@
1
1
  import { Context, Service } from "@deepseek-ai/cordis";
2
2
  import z from "@deepseek-ai/schemastery";
3
3
  import { Agent } from "@deepseek-ai/dsh-agent";
4
- //#region src/defaults.d.ts
5
4
  export declare const DEFAULT_KEEP: readonly string[];
6
5
  export declare const DEFAULT_SUPPRESS: readonly string[];
7
6
  export declare const DEFAULT_REPLACE: Readonly<Record<string, string>>;
8
- //#endregion
9
- //#region src/channel.d.ts
10
7
  export declare class ContextAssembler extends Service {
11
8
  private readonly replacements;
12
9
  private readonly suppressed;
@@ -30,8 +27,6 @@ declare module "@deepseek-ai/cordis" {
30
27
  contextAssembler: ContextAssembler;
31
28
  }
32
29
  }
33
- //#endregion
34
- //#region src/index.d.ts
35
30
  export declare const name = "context-assembler";
36
31
  export declare const inject: string[];
37
32
  export interface Config {
@@ -40,5 +35,4 @@ export interface Config {
40
35
  replace?: Record<string, string>;
41
36
  }
42
37
  export declare const Config: z<Config>;
43
- export declare function apply(ctx: Context, config: Config): void;
44
- //#endregion
38
+ export declare function apply(ctx: Context, config: Config): void;
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import z from "@deepseek-ai/schemastery";
2
2
  import { Service } from "@deepseek-ai/cordis";
3
3
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
4
4
  import { PERSONA_PREFIX_SECTION, PERSONA_SUFFIX_SECTION } from "@deepseek-ai/dsh-system-prompt";
5
- //#region src/reminder.ts
5
+ // src/reminder.ts
6
6
  const REMINDER_OPEN = "<system-reminder";
7
7
  const REMINDER_CLOSE = "</system-reminder>";
8
8
  const RULES_SECTION = "assembler:rules";
@@ -20,12 +20,11 @@ function renderReminder(id, body) {
20
20
  return `${REMINDER_OPEN} id="${escapeAttr(id)}">\n${escapeFrameBody(body)}\n${REMINDER_CLOSE}`;
21
21
  }
22
22
  function latestReminderText(agent, id) {
23
- for (const seq of agent.session.surface.nodes.toReversed()) {
24
- const event = agent.session.eventAt(seq);
25
- if (event?.type !== "user/message") continue;
26
- if (promptEntryIdOf(event.data.source) !== id) continue;
27
- const [block] = event.data.content;
28
- return event.data.content.length === 1 && block?.type === "text" ? block.text : "";
23
+ for (const message of agent.session.deriveMessages().toReversed()) {
24
+ if (message.role !== "user") continue;
25
+ if (promptEntryIdOf(message.source) !== id) continue;
26
+ const [block] = message.content;
27
+ return message.content.length === 1 && block?.type === "text" ? block.text : "";
29
28
  }
30
29
  }
31
30
  function reminderMessage(key, text) {
@@ -41,8 +40,7 @@ function reminderMessage(key, text) {
41
40
  }
42
41
  });
43
42
  }
44
- //#endregion
45
- //#region src/channel.ts
43
+ // src/channel.ts
46
44
  var ContextAssembler = class extends Service {
47
45
  replacements = /* @__PURE__ */ new Map();
48
46
  suppressed = /* @__PURE__ */ new Set();
@@ -93,8 +91,7 @@ var ContextAssembler = class extends Service {
93
91
  return state;
94
92
  }
95
93
  };
96
- //#endregion
97
- //#region src/defaults.ts
94
+ // src/defaults.ts
98
95
  const DEFAULT_KEEP = [
99
96
  PERSONA_PREFIX_SECTION,
100
97
  PERSONA_SUFFIX_SECTION,
@@ -114,11 +111,9 @@ const DEFAULT_REPLACE = {
114
111
  "context:file-reference": "以 @ 开头的词是用户显式引用的工作区路径,相对于工作区根。结尾带斜杠表示目录:需要时列目录内容。其余是文件:需要内容时用 read 工具读取,不要在读取前声称自己已经看过。用 @\"...\" 括住含空格的路径。",
115
112
  "ui:deliverable-file-references": "成功创建或修改文件后,在最终回复里点明主要产物。除命令、配置表达式与代码块之外,每处提到已存在的文件都要链到它的完整路径(相对工作目录或绝对路径);已知行号时在目标后加 `#L24` 或 `#L24-L30`。链接文本用文件名或清晰别名,只加够区分的父目录,不要把完整路径放进标签;默认只用文件名,需要精确位置时在标签后接 `:24` 或 `:24–30`(不带 `#` 或 `L`)。"
116
113
  };
117
- //#endregion
118
- //#region src/rules.ts
114
+ // src/rules.ts
119
115
  const RULES_TEXT = ["system-reminder 与 skill_content 块是本系统提示词的一部分,持续有效:同一条内容的最新一条取代更早的(带 id 的块以 id 为准,其余按来源),不同来源互不影响。", "skill_content 是要遵循的技能说明(随请求送来的与你后来加载的一样),file_content 是本步引用的文件内容。"].join("");
120
- //#endregion
121
- //#region src/index.ts
116
+ // src/index.ts
122
117
  const name = "context-assembler";
123
118
  const RULES_ORDER = 1;
124
119
  const inject = ["systemPrompt"];
@@ -190,5 +185,4 @@ function sectionId(name) {
190
185
  function pendingEntries(agent, channel) {
191
186
  return [...channel.collect(agent)].filter(([key, text]) => latestReminderText(agent, key) !== text).toSorted(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
192
187
  }
193
- //#endregion
194
188
  export { Config, ContextAssembler, DEFAULT_KEEP, DEFAULT_REPLACE, DEFAULT_SUPPRESS, apply, inject, name };
package/dist/rows.d.mts CHANGED
@@ -1,9 +1,7 @@
1
- //#region src/rows.d.ts
2
1
  export declare const CONTEXT_PACKAGE = "@morlay/dsh-context-assembler";
3
2
  export interface ContextRow {
4
3
  readonly id: string;
5
4
  readonly name: string;
6
5
  readonly config?: Readonly<Record<string, unknown>>;
7
6
  }
8
- export declare function contextChannel(): ContextRow;
9
- //#endregion
7
+ export declare function contextChannel(): ContextRow;
package/dist/rows.mjs CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/rows.ts
1
+ // src/rows.ts
2
2
  const CONTEXT_PACKAGE = "@morlay/dsh-context-assembler";
3
3
  function contextChannel() {
4
4
  return {
@@ -6,5 +6,4 @@ function contextChannel() {
6
6
  name: CONTEXT_PACKAGE
7
7
  };
8
8
  }
9
- //#endregion
10
9
  export { CONTEXT_PACKAGE, contextChannel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morlay/dsh-context-assembler",
3
- "version": "0.0.10",
3
+ "version": "0.0.11-alpha.2",
4
4
  "description": "Prompt channel for dsh: assembly-result text conversion (replace / suppress) plus per-step delivery of demoted sections. Workspace instructions and the skill catalog use the official rows (@deepseek-ai/dsh-agent-instructions / @deepseek-ai/dsh-tool-skill); the per-session scope gate lives in @morlay/dsh-session-mode. Reference expansion is its own package (@morlay/dsh-reference).",
5
5
  "keywords": [
6
6
  "context",
@@ -35,31 +35,31 @@
35
35
  "./locale/*.json": "./locale/*.json"
36
36
  },
37
37
  "dependencies": {
38
- "@deepseek-ai/schemastery": "^3.18.5"
38
+ "@deepseek-ai/schemastery": "^3.18.6-alpha.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@deepseek-ai/cordis": "^4.0.5",
42
- "@deepseek-ai/dsh-agent": "^0.2.1-rc.1",
43
- "@deepseek-ai/dsh-agent-loop": "^0.2.1-rc.1",
44
- "@deepseek-ai/dsh-agent-loop-testkit": "^0.2.1-rc.1",
45
- "@deepseek-ai/dsh-compaction-basic": "^0.2.1-rc.1",
46
- "@deepseek-ai/dsh-llm": "^0.2.1-rc.1",
47
- "@deepseek-ai/dsh-scope": "^0.2.1-rc.1",
48
- "@deepseek-ai/dsh-session": "^0.2.1-rc.1",
49
- "@deepseek-ai/dsh-session-persistence-jsonl": "^0.2.1-rc.1",
50
- "@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.1",
51
- "@deepseek-ai/dsh-token-meter": "^0.2.1-rc.1",
52
- "@morlay/session-rdb": "0.1.9"
41
+ "@deepseek-ai/cordis": "^4.0.6-alpha.1",
42
+ "@deepseek-ai/dsh-agent": "^0.2.2-alpha.2",
43
+ "@deepseek-ai/dsh-agent-loop": "^0.2.2-alpha.2",
44
+ "@deepseek-ai/dsh-agent-loop-testkit": "^0.2.2-alpha.2",
45
+ "@deepseek-ai/dsh-compaction-basic": "^0.2.2-alpha.2",
46
+ "@deepseek-ai/dsh-llm": "^0.2.2-alpha.2",
47
+ "@deepseek-ai/dsh-scope": "^0.2.2-alpha.2",
48
+ "@deepseek-ai/dsh-session": "^0.2.2-alpha.2",
49
+ "@deepseek-ai/dsh-session-persistence-jsonl": "^0.2.2-alpha.2",
50
+ "@deepseek-ai/dsh-system-prompt": "^0.2.2-alpha.2",
51
+ "@deepseek-ai/dsh-token-meter": "^0.2.2-alpha.2",
52
+ "@morlay/session-rdb": "0.1.10-alpha.2"
53
53
  },
54
54
  "peerDependencies": {
55
- "@deepseek-ai/cordis": "^4.0.5",
56
- "@deepseek-ai/dsh-agent": "^0.2.1-rc.1",
57
- "@deepseek-ai/dsh-llm": "^0.2.1-rc.1",
58
- "@deepseek-ai/dsh-session": "^0.2.1-rc.1",
59
- "@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.1"
55
+ "@deepseek-ai/cordis": "^4.0.6-alpha.1",
56
+ "@deepseek-ai/dsh-agent": "^0.2.2-alpha.2",
57
+ "@deepseek-ai/dsh-llm": "^0.2.2-alpha.2",
58
+ "@deepseek-ai/dsh-session": "^0.2.2-alpha.2",
59
+ "@deepseek-ai/dsh-system-prompt": "^0.2.2-alpha.2"
60
60
  },
61
61
  "engines": {
62
- "dsh": ">= 0.2.1-rc.1 < 0.2.2"
62
+ "dsh": ">= 0.2.2-alpha.2 < 0.2.3"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "pnpm exec tsdown"
package/src/reminder.ts CHANGED
@@ -42,13 +42,14 @@ export function renderReminder(id: string, body: string): string {
42
42
  }
43
43
 
44
44
  // surface 上最近一条该 id 的 reminder 原文(含信封);没有则 undefined。
45
+ // 走 `deriveMessages()`(surface 的派生消息视图,受支持的同步读)而不是逐 seq 读事件:
46
+ // `Session.eventAt` / `snapshotEvents` / `ownEvents` 已被上游声明为「新调用禁止」。
45
47
  export function latestReminderText(agent: Agent, id: string): string | undefined {
46
- for (const seq of agent.session.surface.nodes.toReversed()) {
47
- const event = agent.session.eventAt(seq);
48
- if (event?.type !== "user/message") continue;
49
- if (promptEntryIdOf(event.data.source) !== id) continue;
50
- const [block] = event.data.content;
51
- return event.data.content.length === 1 && block?.type === "text" ? block.text : "";
48
+ for (const message of agent.session.deriveMessages().toReversed()) {
49
+ if (message.role !== "user") continue;
50
+ if (promptEntryIdOf(message.source) !== id) continue;
51
+ const [block] = message.content;
52
+ return message.content.length === 1 && block?.type === "text" ? block.text : "";
52
53
  }
53
54
  return undefined;
54
55
  }