@morlay/session-mode 0.0.0-stage → 0.2.0-alpha.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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +85 -2
  3. package/dist/endpoint.d.mts +2 -0
  4. package/dist/endpoint.mjs +3 -0
  5. package/dist/index.d.mts +691 -0
  6. package/dist/index.mjs +2350 -0
  7. package/dist/mode-config-BIYT66jI.mjs +22 -0
  8. package/dist/mode-config-rules-z4gdHLR1.mjs +52 -0
  9. package/dist/rolldown-runtime-3qf6kE1h.d.mts +1 -0
  10. package/dist/server.d.mts +2 -0
  11. package/dist/server.mjs +1 -0
  12. package/dist/session-mode-endpoint-CLpvSnzM.d.mts +120 -0
  13. package/dist/session-mode-endpoint-Dq-E_kHt.mjs +53 -0
  14. package/dist/session-mode-endpoint.service-Bn4EH6aB.d.mts +21 -0
  15. package/dist/session-mode-endpoint.service-MrqQipN6.mjs +79 -0
  16. package/dist/testing.d.mts +12 -0
  17. package/dist/testing.mjs +23 -0
  18. package/dist/ui.d.mts +125 -0
  19. package/dist/ui.mjs +1165 -0
  20. package/package.json +63 -3
  21. package/src/context-assembler.provide.ts +139 -0
  22. package/src/context-assembler.service.ts +67 -0
  23. package/src/contract/context-assembler.contract.ts +30 -0
  24. package/src/contract/index.ts +3 -0
  25. package/src/contract/session-mode.contract.ts +104 -0
  26. package/src/contract/session-scope.contract.ts +53 -0
  27. package/src/defaults.ts +39 -0
  28. package/src/endpoint/index.ts +6 -0
  29. package/src/endpoint/mode-config-rules.ts +59 -0
  30. package/src/endpoint/mode-config.ts +58 -0
  31. package/src/endpoint/session-mode-endpoint.ts +121 -0
  32. package/src/endpoint/session-mode-shapes.ts +71 -0
  33. package/src/endpoint/tool-group-ref.ts +11 -0
  34. package/src/events.ts +102 -0
  35. package/src/guidance/groups.ts +101 -0
  36. package/src/guidance/index.ts +4 -0
  37. package/src/guidance/packs/ask.ts +17 -0
  38. package/src/guidance/packs/code.ts +25 -0
  39. package/src/guidance/packs/fs.ts +60 -0
  40. package/src/guidance/packs/index.ts +52 -0
  41. package/src/guidance/packs/mcp.ts +25 -0
  42. package/src/guidance/packs/plan.ts +42 -0
  43. package/src/guidance/packs/shell.ts +45 -0
  44. package/src/guidance/packs/skill.ts +12 -0
  45. package/src/guidance/packs/swarm.ts +60 -0
  46. package/src/guidance/packs/web-access.ts +24 -0
  47. package/src/guidance/tool-groups.ts +72 -0
  48. package/src/guidance/types.ts +29 -0
  49. package/src/index.ts +63 -0
  50. package/src/mode-sources.ts +83 -0
  51. package/src/mode-store.ts +45 -0
  52. package/src/modes.ts +126 -0
  53. package/src/per-agent-rows.ts +62 -0
  54. package/src/per-agent.ts +36 -0
  55. package/src/persona.ts +30 -0
  56. package/src/ptc-describe.ts +136 -0
  57. package/src/ptc-sdk.ts +101 -0
  58. package/src/reminder.ts +89 -0
  59. package/src/rules.ts +8 -0
  60. package/src/server/index.ts +7 -0
  61. package/src/server/session-mode-endpoint.service.ts +117 -0
  62. package/src/session-mode-store.ts +218 -0
  63. package/src/session-mode.projection.ts +78 -0
  64. package/src/session-mode.provide.ts +38 -0
  65. package/src/session-mode.service.ts +670 -0
  66. package/src/session-scope.service.ts +515 -0
  67. package/src/subagent/delegation-context.ts +30 -0
  68. package/src/subagent/return-guidance.ts +56 -0
  69. package/src/subagent/subagent-guidance.service.ts +76 -0
  70. package/src/subagent.provide.ts +5 -0
  71. package/src/system-remainder.ts +43 -0
  72. package/src/testing/index.ts +34 -0
  73. package/src/tool-guidance.service.ts +265 -0
  74. package/src/ui/index.ts +12 -0
  75. package/src/ui/locales.ts +134 -0
  76. package/src/ui/session-mode-endpoint.client.ts +19 -0
  77. package/src/ui/session-mode-locales.contribution.ts +51 -0
  78. package/src/ui/session-mode-panel-tab.ts +39 -0
  79. package/src/ui/session-mode-panel.view.tsx +931 -0
  80. package/src/ui/session-mode-seat.view.tsx +174 -0
  81. package/src/ui/session-mode-slots.ts +13 -0
  82. package/src/ui/session-mode.provide.ts +24 -0
  83. package/src/ui/session-mode.store.ts +90 -0
  84. package/src/ui/use-roster.ts +24 -0
  85. package/src/ui/view-props.ts +19 -0
@@ -0,0 +1,5 @@
1
+ // 子代理文案接管的装配函数:一行 Provider,装配面只调它。
2
+ import { provide } from "@morlay/zephyr";
3
+ import { SubagentGuidance } from "./subagent/subagent-guidance.service.ts";
4
+
5
+ export const provideSubagentGuidance = provide([SubagentGuidance]);
@@ -0,0 +1,43 @@
1
+ // system prompt 的“变化部分”不再挤进 system,而是作为一条 `<system-remainder>` 的 user 消息追加到历史尾部:
2
+ // system 稳定 → 前缀缓存可复用;变化只在历史里追加,且只有内容变了才追加。
3
+ //
4
+ // 这里只放纯函数:怎么收集 section、什么时候 append 由插件接线,边界测试写在 `__tests__/system-remainder.spec.ts`。
5
+ //
6
+ // **本仓生产通道不用它**:生产走 `src/reminder.ts` 的 `<system-reminder id>` 语义(一条 section 一个 id,
7
+ // 同 id 文本未变不重发);本文件那套 `<system-remainder>` 不带 id、按正文比较幂等,在源包里也没有生产消费者。
8
+ // 保留它只为与源包 `dsh-plugin-main/packages/profile/dsh-session-mode` 保持可对账——那 7 条用例是上游同步的
9
+ // 对账锚。改它必须同步改源包口径;**不要**把两套合并或抽成同一个抽象(语义不同:一套按 id 幂等、一套按正文)。
10
+ import type { UserMessage } from "@morlay/dsh-agent/contract";
11
+
12
+ // 一段会被搬进 remainder 的文本(section 名 + 文本)。
13
+ export interface RemainderSection {
14
+ readonly name: string;
15
+ readonly text: string;
16
+ }
17
+
18
+ // 按 section 顺序拼成一段稳定文本:名字保留,方便模型知道每段是什么。
19
+ export function renderRemainder(sections: readonly RemainderSection[]): string {
20
+ return sections
21
+ .filter((section) => section.text.trim().length > 0)
22
+ .map((section) => `## ${section.name}\n\n${section.text.trim()}`)
23
+ .join("\n\n");
24
+ }
25
+
26
+ // 与上一份比较:空白差异不算变化,避免每步都追加一条。
27
+ export function remainderChanged(previous: string | undefined, next: string): boolean {
28
+ return (previous ?? "").trim() !== next.trim();
29
+ }
30
+
31
+ // 会话里落盘用的 user 消息(`id` 由 Session 分配)。
32
+ export type RemainderMessage = Omit<UserMessage, "id">;
33
+
34
+ // 包成一条 user 消息;空内容返回 undefined(不追加)。
35
+ export function remainderMessage(text: string): RemainderMessage | undefined {
36
+ const body = text.trim();
37
+ if (body.length === 0) return undefined;
38
+ return {
39
+ role: "user",
40
+ content: [{ type: "text", text: `<system-remainder>\n${body}\n</system-remainder>` }],
41
+ source: { kind: "user" },
42
+ };
43
+ }
@@ -0,0 +1,34 @@
1
+ // `@morlay/session-mode/testing`:本包 UI 测试的入口 = base 的 `test` + **每个用例自动跑的收尾**。
2
+ //
3
+ // 为什么是 fixture 而不是全局 `setupFiles`:`auto: true` 挂在**这个包导出的 `test`** 上,
4
+ // 谁 import 谁就得到这份收尾——从 import 行就读得出来,spec 里也不用写 `afterEach(cleanup)`。
5
+ import { cleanup } from "@testing-library/react";
6
+ import { test as base } from "@morlay/zephyr/testing";
7
+ import { vi } from "vitest";
8
+
9
+ export { describe, expect } from "@morlay/zephyr/testing";
10
+
11
+ /**
12
+ * 挂了本包 `test` 的 spec 自动得到:
13
+ *
14
+ * - `rtlCleanup`:卸载本轮渲染的 DOM(`@testing-library/react` 的 `cleanup`);
15
+ * - `stubRestore`:还原 `vi.stubEnv` / `vi.stubGlobal` / `vi.spyOn`(不靠 vitest 的隐式全局开关)。
16
+ */
17
+ export const test = base.extend({
18
+ rtlCleanup: [
19
+ async ({}, use: (value: undefined) => Promise<void>) => {
20
+ await use(undefined);
21
+ cleanup();
22
+ },
23
+ { auto: true },
24
+ ],
25
+ stubRestore: [
26
+ async ({}, use: (value: undefined) => Promise<void>) => {
27
+ await use(undefined);
28
+ vi.unstubAllEnvs();
29
+ vi.unstubAllGlobals();
30
+ vi.restoreAllMocks();
31
+ },
32
+ { auto: true },
33
+ ],
34
+ });
@@ -0,0 +1,265 @@
1
+ // 工具说明的汉化:模型看到的**工具描述**必须是一行中文,参数 schema 里只留约束
2
+ // (`description` / `title` 这类说明性字段剥掉,语义在组正文里讲一次)。
3
+ //
4
+ // 改写落在**工具定义对象本身**上(与源包同一手法):装配瀑布不再承载工具声明,而 `llm/stream` 的
5
+ // options 是上游冻结过的——在监听器里写 `options.tools` 会抛只读错误。定义对象可变,改它的
6
+ // `description` / `parameters` 就等于改了 `executor.describe()` 的输出(模型面),
7
+ // 而不经过 `tools.register`、也不触发 `tools/change` 重入。
8
+ //
9
+ // 执行期的输入校验用的是 `defineTool` 闭包里那份原 schema,不受这里替换影响。
10
+ import type { Agent } from "@morlay/dsh-agent/contract";
11
+ import type { ToolDefinition } from "@morlay/dsh-agent/contract";
12
+ import { inject, Injectable, type Context, type OnInit } from "@morlay/zephyr";
13
+ import { ToolRegistrations } from "@morlay/dsh-agent";
14
+ import { SHORT_TOOL_DESCRIPTIONS } from "./guidance/groups.ts";
15
+ import { constantMessage, latestConstantText, renderConstantReminder } from "./reminder.ts";
16
+ import { SessionMode } from "./contract/session-mode.contract.ts";
17
+ import { ContextAssembler } from "./contract/context-assembler.contract.ts";
18
+ import { AgentCreated, AgentPreStep, SystemPromptAssemble, ToolsChanged } from "./events.ts";
19
+ import {
20
+ TOOL_GROUPS,
21
+ groupSkillBody,
22
+ renderToolsDeclaration,
23
+ type ToolGroup,
24
+ } from "./guidance/groups.ts";
25
+ import { PTC_ONLY_SECTION, RUN_CODE_NAME } from "./guidance/tool-groups.ts";
26
+ import { jsonSchemaToTs } from "@morlay/dsh-ptc/contract";
27
+ import { projectToolSchema } from "@morlay/dsh-agent/contract";
28
+
29
+ // 常驻正文的幂等键:所有 `init` 组合并成这一条。
30
+ const BASELINE_KEY = "tool-group-baseline";
31
+
32
+ // 常驻正文的开场说明:签名块怎么用、哪些组要现取。
33
+ const BASELINE_PREAMBLE =
34
+ "`tools.*` 的签名:下面每个组都已给出完整的 d.ts 代码块,**直接按签名调用**,不要再用 `describe_tool` 查这些组。" +
35
+ "这里没列出的组一律 `describe_tool()` 看清单(每组一行判据),再 `describe_tool({ group })` 取那一组——不要在代码里写死组名。" +
36
+ "程序里的变量名必须唯一(`const a = await tools.read(...)`、`const b = …`,或直接 `await tools.read(...)` 不赋值):同一个名字声明两次会直接 SyntaxError。";
37
+
38
+ // 一个组的签名块:组内**已可见**的工具各出一条声明(说明用那一行中文当 doc)。
39
+ function groupTypeDeclaration(
40
+ group: ToolGroup,
41
+ definitions: ReadonlyMap<string, ToolDefinition>,
42
+ visible: (tool: string) => boolean,
43
+ ): string {
44
+ const signatures = group.tools
45
+ .map((entry) => entry.tool)
46
+ .filter((name) => visible(name) && definitions.has(name))
47
+ .map((name) => {
48
+ const definition = definitions.get(name) as ToolDefinition;
49
+ const short = SHORT_TOOL_DESCRIPTIONS[name];
50
+ return {
51
+ name,
52
+ args: jsonSchemaToTs(projectToolSchema(definition, false).parameters),
53
+ output: jsonSchemaToTs(definition.output?.schema ?? {}),
54
+ ...(short === undefined ? {} : { doc: short }),
55
+ };
56
+ });
57
+ return renderToolsDeclaration(signatures);
58
+ }
59
+
60
+ // 已经改写过的定义:同一个对象只改一次(`tools/change` 会反复来)。
61
+ const projected = new WeakSet<object>();
62
+
63
+ // 参数 schema 里要剥掉的说明性字段:约束(`type` / `enum` / `required` / `default`)一个都不动。
64
+ const PROSE_KEYS = ["description", "title", "examples"] as const;
65
+
66
+ /** 剥掉说明性字段,保留约束。 */
67
+ export function slimSchema(schema: unknown): unknown {
68
+ if (Array.isArray(schema)) return schema.map(slimSchema);
69
+ if (typeof schema !== "object" || schema === null) return schema;
70
+ const rest = { ...(schema as Record<string, unknown>) };
71
+ for (const key of PROSE_KEYS) delete rest[key];
72
+ const properties = rest["properties"];
73
+ if (typeof properties === "object" && properties !== null) {
74
+ rest["properties"] = Object.fromEntries(
75
+ Object.entries(properties as Record<string, unknown>).map(([key, value]) => [
76
+ key,
77
+ slimSchema(value),
78
+ ]),
79
+ );
80
+ }
81
+ for (const key of ["items", "additionalProperties"]) {
82
+ if (key in rest) rest[key] = slimSchema(rest[key]);
83
+ }
84
+ return rest;
85
+ }
86
+
87
+ /** 改写一条工具定义(描述汉化 + 参数精简)。已经改过的不重复改。 */
88
+ export function projectDefinition(definition: ToolDefinition): void {
89
+ if (projected.has(definition)) return;
90
+ projected.add(definition);
91
+ const description = SHORT_TOOL_DESCRIPTIONS[definition.name];
92
+ if (description !== undefined) {
93
+ Object.defineProperty(definition, "description", {
94
+ value: description,
95
+ configurable: true,
96
+ enumerable: true,
97
+ writable: true,
98
+ });
99
+ }
100
+ Object.defineProperty(definition, "parameters", {
101
+ value: slimSchema(definition.parameters),
102
+ configurable: true,
103
+ enumerable: true,
104
+ writable: true,
105
+ });
106
+ }
107
+
108
+ /**
109
+ * 工具说明的汉化行:把全局与会话内的工具定义换成中文描述、精简参数。
110
+ *
111
+ * 落点是**定义对象**(不是装配结果、也不是注册表),因为模型面最终由执行器的 `describe()` 读定义算出来。
112
+ * 三个时机各管一段:
113
+ * - `agent/created`:会话建好时把**这个会话**的工具改一遍(第一次装配之前);
114
+ * - `tools/change`(会话级):团队、schedule 这类行在会话建好**之后**才注册工具,全局事件看不到它们;
115
+ * - `tools/change`(全局)+ `onInit`:全局注册表里的工具;
116
+ * - `system-prompt/assemble`:会话内晚注册的(MCP 重连、skill 重载)赶不上前三个,每次装配补一次
117
+ * ——本次装配的声明已按旧定义收集过了,所以从**下一次**请求开始生效。
118
+ */
119
+ /** 这一行的配置:`groups` 是**部署级**开关(本行装在 root,所有会话共用一份)。 */
120
+ export interface ToolGuidanceConfig {
121
+ /**
122
+ * 是否做**用法分组**(`init` 组正文的常驻注入 + 其余组由 `describe_tool({ group })` 按需返回)。
123
+ *
124
+ * 关掉只保留**预处理**(工具描述换一行中文、剥掉参数里的说明性字段)——只想复用汉化、
125
+ * 不要按步注入的部署把这一项关掉。分组正文会改变 system 前缀,逐 token 计费与缓存都受影响,
126
+ * 所以它是显式开关而不是恒开。
127
+ */
128
+ readonly groups?: boolean;
129
+ }
130
+
131
+ function configWithDefaults(input: ToolGuidanceConfig = {}): Required<ToolGuidanceConfig> {
132
+ return { groups: input.groups ?? true };
133
+ }
134
+
135
+ @Injectable()
136
+ export class ToolGuidance implements OnInit {
137
+ static Config = configWithDefaults;
138
+
139
+ private readonly config: Required<ToolGuidanceConfig>;
140
+
141
+ private readonly registrations = inject(ToolRegistrations);
142
+
143
+ private readonly channel = inject(ContextAssembler);
144
+
145
+ private readonly modes = inject.optional(SessionMode);
146
+
147
+ private readonly created$ = new AgentCreated();
148
+
149
+ private readonly assemble$ = new SystemPromptAssemble();
150
+
151
+ private readonly changed$ = new ToolsChanged();
152
+
153
+ private readonly preStep$ = new AgentPreStep();
154
+
155
+ // 这些会话的模型面只有 `run_code`(PTC):正文的可见判据要给它豁免。
156
+ private readonly ptcAgents = new WeakSet<Agent>();
157
+
158
+ constructor(input: ToolGuidanceConfig = {}) {
159
+ this.config = configWithDefaults(input);
160
+ }
161
+
162
+ onInit(_ctx: Context): void {
163
+ const projectAll = (agent?: Agent): void => {
164
+ for (const definition of this.registrations.getAll(agent)) projectDefinition(definition);
165
+ };
166
+
167
+ // 全局注册表:现在有的 + 之后注册的。
168
+ projectAll();
169
+ this.changed$.on(() => projectAll());
170
+
171
+ // 每个会话建好时先改一遍。
172
+ //
173
+ // 跟这个会话自己的 `tools/change` 不在这里挂:团队、schedule 这类行在建好会话**之后**才把工具注册进
174
+ // agent scope,全局那条 `tools/change` 看不到它们——那条订阅归 `ScopedToolGuidance`(per-agent 行),
175
+ // 它的事件字段绑在这个 agent 的 scope 上。
176
+ this.created$.on(({ agent }) => projectAll(agent));
177
+
178
+ // 装配时补一次(晚注册的工具)。改的是定义对象,所以对**下一次**请求生效。
179
+ //
180
+ // 同时认出 PTC:执行器把模型面收窄成 `run_code` 一条,装配期唯一能看到的信号就是它注册的那条
181
+ // section。读**入参**那份(原始装配):通道会把非 keep 的 section 降级成 reminder,`result` 里看不到它。
182
+ this.assemble$.onWaterfall(async (assembly, context, next) => {
183
+ const agent = (context as { agent?: Agent }).agent;
184
+ if (agent !== undefined) {
185
+ projectAll(agent);
186
+ if (assembly.sections.some((section) => section.name === PTC_ONLY_SECTION)) {
187
+ this.ptcAgents.add(agent);
188
+ }
189
+ }
190
+ return next();
191
+ });
192
+
193
+ // `groups: false`:只留**预处理**。不注入组正文、不丢上游 section——
194
+ // 那条路会改 system 前缀(逐 token 计费与缓存都受影响),所以由部署显式选。
195
+ if (!this.config.groups) return;
196
+
197
+ // **不再把按需组注册成 skill**:`describe_tool({ group })` 已经能返回该组的用法正文与 d.ts,
198
+ // skill 目录里的 `tool-group-*` 只是同一份说明的第二个入口(多一个目录项、多一次加载、多一处漂移)。
199
+ // 组正文的读取路径因此只有两条:`init` 组的常驻注入,与 `describe_tool` 的按需返回。
200
+
201
+ // 被丢弃的上游说明:要点已吸收进组正文,原文不再进提示词。
202
+ for (const group of TOOL_GROUPS) {
203
+ for (const section of group.drops) {
204
+ _ctx.effect(() => this.channel.suppressSection(section));
205
+ }
206
+ }
207
+
208
+ // `init` 组的正文按会话常驻注入(一次一条,幂等键固定):多组各发一条会把对话流打散。
209
+ // 注入判据是**这个会话装配结果里最终可见的工具**:收窄掉的工具不列。
210
+ // 每组的正文后面跟它的 d.ts 签名块(模型据此直接调用,不必再 `describe_tool` 查一次)。
211
+ this.preStep$.onWaterfall(async ({ agent, messages, signal }, next) => {
212
+ const decision = await next();
213
+ if (decision.kind !== "enter") return decision;
214
+ const visible = new Set(this.visibleToolsOf(agent));
215
+ const keep = (tool: string): boolean => visible.has(tool);
216
+ const definitions = new Map(
217
+ this.registrations.getAll(agent).map((definition) => [definition.name, definition]),
218
+ );
219
+ const sections: string[] = [BASELINE_PREAMBLE];
220
+ for (const group of TOOL_GROUPS) {
221
+ if (group.injection !== "init") continue;
222
+ const body = groupSkillBody(group, keep);
223
+ if (body.length === 0) continue;
224
+ const type = groupTypeDeclaration(group, definitions, keep);
225
+ sections.push(
226
+ [
227
+ `<tool-definitions group="${group.key}">`,
228
+ "",
229
+ body,
230
+ ...(type.length === 0 ? [] : ["", "```ts", type, "```"]),
231
+ "",
232
+ "</tool-definitions>",
233
+ ].join("\n"),
234
+ );
235
+ }
236
+ if (sections.length === 1) return decision;
237
+ const text = renderConstantReminder(sections.join("\n\n"));
238
+ if (latestConstantText(agent, BASELINE_KEY) === text) return decision;
239
+ signal.throwIfAborted();
240
+
241
+ // 落点:本步认领的用户消息**之后**(不是列表末尾)。
242
+ const claimedEnd = decision.messages.findLastIndex((message) => messages.includes(message));
243
+ return {
244
+ ...decision,
245
+ messages: decision.messages.toSpliced(
246
+ claimedEnd + 1,
247
+ 0,
248
+ constantMessage(BASELINE_KEY, text),
249
+ ),
250
+ };
251
+ });
252
+ }
253
+
254
+ // 这个会话装配结果里最终可见的工具:模式的名单收窄之后的注册表集合。
255
+ // 没有 `SessionMode`(或它还没收口过)时退回注册表全量。
256
+ // `run_code` 豁免:它是 PTC 的入口,不在注册表里,但程序内可用。
257
+ private visibleToolsOf(agent: Agent): readonly string[] {
258
+ const modes = this.modes;
259
+ const known =
260
+ modes === undefined
261
+ ? this.registrations.getAll(agent).map((definition) => definition.name)
262
+ : modes.knownToolsOf(agent);
263
+ return this.ptcAgents.has(agent) ? [...known, RUN_CODE_NAME] : known;
264
+ }
265
+ }
@@ -0,0 +1,12 @@
1
+ // session-mode 的浏览器半(`@morlay/session-mode/ui`):RPC 客户端、读面 store、两个视图与装配函数。
2
+ export { SessionModeEndpointClient } from "./session-mode-endpoint.client.ts";
3
+ export { SessionModeStore } from "./session-mode.store.ts";
4
+ export {
5
+ ConversationInputLeftSlot,
6
+ PANEL_ID,
7
+ SidebarRightPaneTabSlot,
8
+ } from "./session-mode-slots.ts";
9
+ export { SessionModeSeatView } from "./session-mode-seat.view.tsx";
10
+ export { SessionModePanelView } from "./session-mode-panel.view.tsx";
11
+ export { provideSessionModeUi } from "./session-mode.provide.ts";
12
+ export { LOCALE_NS, en, zh, type SessionModeLocaleKey } from "./locales.ts";
@@ -0,0 +1,134 @@
1
+ // 浏览器半的文案:命名空间 `session-mode`。模式的名字与说明是**数据**(宿主给的清单),不在这里。
2
+
3
+ export const zh = {
4
+ seatHint: "选择这个会话的模式",
5
+ lockedHint: "这个会话已经开始:换模式请新开一个会话",
6
+ // chip 切换失败:错误只挂 tooltip 时,鼠标一移开就没人知道刚才那次点没生效。
7
+ seatFailed: "切换模式失败",
8
+ noDescription: "(无说明)",
9
+ panel: "会话模式",
10
+ panelDescription: "当前会话的模式与生效面:工具、技能、政策与注入开关。",
11
+ panelNoSession: "当前没有会话",
12
+ persona: "系统提示词",
13
+ tools: "工具",
14
+ skills: "技能",
15
+ policies: "政策规则",
16
+ switches: "注入面",
17
+ instructions: "工作区指令",
18
+ skillsCatalog: "技能目录",
19
+ runtimeContext: "动态快照",
20
+ empty: "(无)",
21
+ loading: "读取中…",
22
+ saveDefault: "保存为默认",
23
+ reset: "重置",
24
+ apply: "应用到会话",
25
+ applied: "已应用到会话",
26
+ fromSession: "会话覆盖",
27
+ fromMode: "模式默认",
28
+ saveAs: "另存为",
29
+ delete: "删除",
30
+ deleteConfirm: "删除这个模式在会话上的自定义?会话回到内置默认模式,原模式本身不受影响。",
31
+ cancel: "取消",
32
+ confirm: "确定",
33
+ nameLabel: "显示名(可选)",
34
+ codeLabel: "模式 code(必填)",
35
+ codePlaceholder: "例如 my-mode",
36
+ namePlaceholder: "新模式名",
37
+ general: "通用配置",
38
+ // persona 段:两段系统提示词的前后缀,各带一句"它在提示词的哪一头"。
39
+ personaPrefix: "前缀",
40
+ personaSuffix: "后缀",
41
+ personaPrefixHint: "拼在系统提示词最前面的一段",
42
+ personaSuffixHint: "拼在系统提示词最后面的一段",
43
+ stateDefault: "默认",
44
+ stateOn: "开",
45
+ stateOff: "关",
46
+ stateAllow: "允许",
47
+ stateDeny: "禁止",
48
+ stateMixed: "混合",
49
+ otherGroup: "其它",
50
+ // 逐字段回退:清掉这个字段的会话覆盖,回到模式默认。
51
+ restoreDefault: "恢复默认",
52
+ // 「只看可调用」过滤开关。
53
+ onlyCallable: "只看可调用",
54
+ onlyCallableHint: "只列这个会话没被禁止、且当下可见的条目",
55
+ moreSaveWays: "更多保存方式",
56
+ saveAsNeedsName: "需要先给新模式起名(暂未提供输入面)",
57
+ deleteBuiltinReason: "内置模式不能删除,只有会话上自定义过的模式可删",
58
+ deleteCurrentTitle: "删除当前模式",
59
+ confirmDelete: "确认删除",
60
+ deleted: "已删除,会话回到",
61
+ deleteFailed: "删除失败",
62
+ savedNewMode: "已另存为新模式,对新会话生效",
63
+ saved: "已保存,对新会话生效",
64
+ saveFailed: "保存失败",
65
+ loadFailed: "读取失败",
66
+ };
67
+
68
+ export const en: Record<keyof typeof zh, string> = {
69
+ seatHint: "Pick the mode for this session",
70
+ lockedHint: "This session has started: start a new one to pick a mode",
71
+ seatFailed: "Mode switch failed",
72
+ noDescription: "(no description)",
73
+ panel: "Session mode",
74
+ panelDescription:
75
+ "The mode this session runs and what it currently exposes: tools, skills, policies and injections.",
76
+ panelNoSession: "No session",
77
+ persona: "System prompt",
78
+ tools: "Tools",
79
+ skills: "Skills",
80
+ policies: "Policies",
81
+ switches: "Injections",
82
+ instructions: "Workspace instructions",
83
+ skillsCatalog: "Skill catalog",
84
+ runtimeContext: "Runtime context",
85
+ empty: "(none)",
86
+ loading: "Loading…",
87
+ saveDefault: "Save as default",
88
+ reset: "Reset",
89
+ apply: "Apply to session",
90
+ applied: "Applied to session",
91
+ fromSession: "session override",
92
+ fromMode: "mode default",
93
+ saveAs: "Save as",
94
+ delete: "Delete",
95
+ deleteConfirm:
96
+ "Delete this session's customizations? The session falls back to the built-in default mode; the mode itself is untouched.",
97
+ cancel: "Cancel",
98
+ confirm: "Confirm",
99
+ nameLabel: "Display name (optional)",
100
+ codeLabel: "Mode code (required)",
101
+ codePlaceholder: "e.g. my-mode",
102
+ namePlaceholder: "New mode name",
103
+ general: "General",
104
+ personaPrefix: "Prefix",
105
+ personaSuffix: "Suffix",
106
+ personaPrefixHint: "Prepended to the system prompt",
107
+ personaSuffixHint: "Appended to the end of the system prompt",
108
+ stateDefault: "Default",
109
+ stateOn: "On",
110
+ stateOff: "Off",
111
+ stateAllow: "Allow",
112
+ stateDeny: "Deny",
113
+ stateMixed: "Mixed",
114
+ otherGroup: "Other",
115
+ restoreDefault: "Restore default",
116
+ onlyCallable: "Callable only",
117
+ onlyCallableHint: "List only what this session can actually call right now",
118
+ moreSaveWays: "More save options",
119
+ saveAsNeedsName: "A name for the new mode is required (no input surface yet)",
120
+ deleteBuiltinReason: "Built-in modes cannot be deleted; only modes customized on a session can",
121
+ deleteCurrentTitle: "Delete the current mode",
122
+ confirmDelete: "Confirm delete",
123
+ deleted: "Deleted; the session falls back to",
124
+ deleteFailed: "Delete failed",
125
+ savedNewMode: "Saved as a new mode; applies to new sessions",
126
+ saved: "Saved; applies to new sessions",
127
+ saveFailed: "Save failed",
128
+ loadFailed: "Load failed",
129
+ };
130
+
131
+ export type SessionModeLocaleKey = keyof typeof zh;
132
+
133
+ // 本包字典的命名空间。
134
+ export const LOCALE_NS = "session-mode";
@@ -0,0 +1,19 @@
1
+ // `sessionMode` 组的**客户端形态**:只消费、不实现。
2
+ //
3
+ // `@RemoteClient()` 注册成 provider 并给契约里声明的每个方法生成转发。组名从契约继承,这里不写。
4
+ //
5
+ // **不挂载**(没有 `onInit` + `$mount`):这是我们**自己的组**,不是上游组的成员。
6
+ // 上游的 `remote` 是「上游组的注册表」——注册进去要求 typert 描述符、要给直通 codec、还得避开它
7
+ // `RemoteNamespaceService` 原型链上的保留名(`remove` 撞过,已改名 `removeMode`)。
8
+ // 判据见 `dsh-bundle/dsh-session-mode-profile/src/__tests__/remote-on-host.spec.ts`。
9
+ import { inject } from "@morlay/zephyr";
10
+ import { RemoteTransport } from "@morlay/zephyr-app/client";
11
+ import { RemoteClient } from "@morlay/zephyr-app/remote";
12
+ import { SessionModeEndpoint } from "../endpoint/session-mode-endpoint.ts";
13
+
14
+ /** `sessionMode` 组的客户端契约实例。 */
15
+ @RemoteClient()
16
+ export class SessionModeEndpointClient extends SessionModeEndpoint {
17
+ /** 传输:转发走它(我们的组不注册进上游 `remote`)。 */
18
+ protected readonly transport = inject(RemoteTransport);
19
+ }
@@ -0,0 +1,51 @@
1
+ // 本包字典的唯一注册处:上游 `locale.register` 对同一 namespace + locale 二次注册会抛,
2
+ // 所以 tab 类型、chip、面板都只经这里 `bind`,不各自注册。
3
+ //
4
+ // 没有这一条时,右栏 tab 与 guide 入口显示的是**原始键**(`panel` / `panelDescription`)——
5
+ // 实测在浏览器里就是这个症状。
6
+ import { inject, Injectable, type OnDispose, type OnInit } from "@morlay/zephyr";
7
+ import { Locale } from "@morlay/zephyr-app/client";
8
+ import { LOCALE_NS, en, zh, type SessionModeLocaleKey } from "./locales.ts";
9
+
10
+ /** 本包字典的翻译座:`t` 的键集合就是字典的键集合。 */
11
+ export type SessionModeTranslate = (key: SessionModeLocaleKey) => string;
12
+
13
+ /**
14
+ * 字典面按结构使用:字典名只在本包注册,不扩张上游的 namespace 类型表。
15
+ *
16
+ * `register` 的返回值**必须**是上游那个 disposer(`:390-441`):行卸载时上游注册表里不许留这一份。
17
+ */
18
+ interface Dictionaries {
19
+ register(
20
+ ns: string,
21
+ dicts: Readonly<Record<string, Readonly<Record<string, string>>>>,
22
+ ): () => void;
23
+ bind(ns: string): (key: string) => string;
24
+ }
25
+
26
+ @Injectable()
27
+ export class SessionModeLocales implements OnInit, OnDispose {
28
+ private readonly locale = inject(Locale) as unknown as Dictionaries;
29
+
30
+ /**
31
+ * 字典的撤销面。归本行自己的 fiber:我们不 provide 字典,上游注册表才持有它。
32
+ *
33
+ * 自带字段而不是 `this.own(...)`:本行不是 `SlotContribution`(没有 slot 声明,也不该为拿 `own`
34
+ * 去多注入一个 `Slots`),基类的记账面拿不到——同一个理由,`onDispose` 也只能自己写。
35
+ */
36
+ private release: (() => void) | undefined;
37
+
38
+ onInit(): void {
39
+ this.release = this.locale.register(LOCALE_NS, { zh, en });
40
+ }
41
+
42
+ onDispose(): void {
43
+ this.release?.();
44
+ this.release = undefined;
45
+ }
46
+
47
+ /** 本包字典绑定后的翻译座。 */
48
+ t(): SessionModeTranslate {
49
+ return this.locale.bind(LOCALE_NS) as SessionModeTranslate;
50
+ }
51
+ }
@@ -0,0 +1,39 @@
1
+ // 右栏面板的**tab 类型**注册:上游右栏行的面板标签条读的是它自己那一份注册表
2
+ // (`ctx.sidebarRightTabs`),没有这一条,面板正文即使注册在 `sidebar.right.pane.tab` 上也不会出现。
3
+ //
4
+ // 两段式是上游的固定形状:类型(这里是) + 正文(`SessionModePanelView`),两者用同一个 `id`/key 配对。
5
+ import { inject, Injectable, type OnInit } from "@morlay/zephyr";
6
+ import { SidebarRightTabs } from "@morlay/zephyr-app/client";
7
+ import { PANEL_ID } from "./session-mode-slots.ts";
8
+ import { SessionModeLocales } from "./session-mode-locales.contribution.ts";
9
+
10
+ /** 右栏里那一页的 tab 类型。 */
11
+ @Injectable()
12
+ export class SessionModePanelTab implements OnInit {
13
+ private readonly tabs = inject(SidebarRightTabs);
14
+
15
+ private readonly locales = inject(SessionModeLocales);
16
+
17
+ onInit(): void {
18
+ const t = this.locales.t();
19
+ this.tabs.register({
20
+ id: PANEL_ID,
21
+ kind: PANEL_ID,
22
+ // `extension`:外部类型默认档,与上游各 tab 同档(同档不同 kind 可以共存)。
23
+ priority: "extension",
24
+ title: () => t("panel"),
25
+ // **guide 入口**:省略 `guide` 就等于「不上 guide 页」(上游 `tab-registry.ts:409-411` 的
26
+ // `guideEntries` 只来自 `definition.guide`),而本页**没有别的入口**——右栏那一页只由用户
27
+ // 自己从这里打开,漏了它这一页就永远打不开(类型注册上了、正文也注册了,但用户没有按钮)。
28
+ // `order` 接在上游那几档之后(files 10 / terminal 20 / browser 30)。
29
+ guide: [
30
+ {
31
+ id: "panel",
32
+ order: 40,
33
+ title: () => t("panel"),
34
+ description: () => t("panelDescription"),
35
+ },
36
+ ],
37
+ });
38
+ }
39
+ }