hongcoding commited on
Commit
4ce05b9
·
verified ·
1 Parent(s): 11e2b39

feat: persona + models + files + conversations bundle layout

Browse files
src/cli/commands/export.ts CHANGED
@@ -23,9 +23,9 @@ export async function exportData(opts: ExportOpts): Promise<void> {
23
  withConversations: opts.noConversations !== true,
24
  });
25
 
26
- console.log(` ✅ 人物设定:${result.personas} 个 Bot → personas.md`);
27
  if (result.materialsDirs.length > 0) {
28
- console.log(` ✅ 文件资料:${result.materialsDirs.length} 个目录,${(result.materialsBytes / 1024 / 1024).toFixed(1)} MB`);
29
  for (const d of result.materialsDirs) console.log(` ${d}`);
30
  }
31
  if (result.conversationFiles > 0) {
 
23
  withConversations: opts.noConversations !== true,
24
  });
25
 
26
+ console.log(` ✅ 人设:${result.personas} 个角色 → persona.md`);
27
  if (result.materialsDirs.length > 0) {
28
+ console.log(` ✅ 文件:${result.materialsDirs.length} 个目录,${(result.materialsBytes / 1024 / 1024).toFixed(1)} MB`);
29
  for (const d of result.materialsDirs) console.log(` ${d}`);
30
  }
31
  if (result.conversationFiles > 0) {
src/cli/commands/import.ts CHANGED
@@ -29,6 +29,6 @@ export async function importData(opts: ImportOpts): Promise<void> {
29
  console.log(` ✅ 数据目录:${r.dataDir}`);
30
  console.log(` ✅ 全局指令:${r.instructionsFile}(已写入导入段落,幂等)`);
31
  if (r.skillFile) console.log(` ✅ Skill:${r.skillFile}`);
32
- console.log(`\n 人物设定 ${r.personas} 个 · 对话 ${r.conversations} 条 · 资料 ${(r.materialsBytes / 1024 / 1024).toFixed(1)} MB`);
33
  console.log(`\n重启 ${opts.to} 后,它会自动读取这些资料。`);
34
  }
 
29
  console.log(` ✅ 数据目录:${r.dataDir}`);
30
  console.log(` ✅ 全局指令:${r.instructionsFile}(已写入导入段落,幂等)`);
31
  if (r.skillFile) console.log(` ✅ Skill:${r.skillFile}`);
32
+ console.log(`\n 人设 ${r.personas} 个 · 模型配置已导出 · 对话 ${r.conversations} 条 · 文件 ${(r.materialsBytes / 1024 / 1024).toFixed(1)} MB`);
33
  console.log(`\n重启 ${opts.to} 后,它会自动读取这些资料。`);
34
  }
src/export/dsh.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync, readdirSync, statSync, mkdirSync, writeFileSync, cpSync } from "node:fs";
2
  import { homedir } from "node:os";
3
  import { join, resolve } from "node:path";
4
  import { execFileSync } from "node:child_process";
@@ -11,6 +11,7 @@ export interface Persona {
11
  color?: string;
12
  avatar?: string;
13
  model?: string;
 
14
  capabilities?: string[];
15
  instructions: string;
16
  }
@@ -50,6 +51,7 @@ export function readPersonas(): Persona[] {
50
  color: typeof bot?.color === "string" ? bot.color : undefined,
51
  avatar: bot?.avatar ? JSON.stringify(bot.avatar) : undefined,
52
  model: typeof bot?.model === "string" ? bot.model : undefined,
 
53
  capabilities: Array.isArray(bot?.capabilities) ? bot.capabilities : undefined,
54
  instructions: typeof bot?.instructions === "string" ? bot.instructions : "",
55
  });
@@ -59,7 +61,7 @@ export function readPersonas(): Persona[] {
59
 
60
  /** Render personas as a portable markdown document. */
61
  export function renderPersonas(personas: Persona[]): string {
62
- const lines: string[] = ["# DSH 人物设定(Bot 团队)", ""];
63
  for (const p of personas) {
64
  lines.push(`## ${p.name}`);
65
  lines.push("");
@@ -77,13 +79,32 @@ export function renderPersonas(personas: Persona[]): string {
77
  return lines.join("\n");
78
  }
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  /** Copy material directories (workspace, memory, optionally attachments). */
81
  export function exportMaterials(outDir: string, withAttachments: boolean): { dirs: string[]; bytes: number } {
82
  const targets: Array<[string, string]> = [
83
- [join(HOME, ".dsh", "bot", "workspace"), "materials/workspace"],
84
- [join(HOME, ".dsh", "bot", "memory"), "materials/memory"],
85
  ];
86
- if (withAttachments) targets.push([join(HOME, ".dsh", "attachments"), "materials/attachments"]);
87
 
88
  const copied: string[] = [];
89
  let bytes = 0;
@@ -201,9 +222,15 @@ function renderInstructionFile(personas: Persona[], target: "agents" | "claude")
201
  export function exportDsh(options: DshExportOptions): DshExportResult {
202
  const outDir = resolve(options.outDir);
203
  mkdirSync(outDir, { recursive: true });
 
 
 
 
 
204
 
205
  const personas = readPersonas();
206
- writeFileSync(join(outDir, "personas.md"), renderPersonas(personas), "utf8");
 
207
  // Ready-to-use instruction files for the two shared standards.
208
  writeFileSync(join(outDir, "AGENTS.md"), renderInstructionFile(personas, "agents"), "utf8");
209
  writeFileSync(join(outDir, "CLAUDE.md"), renderInstructionFile(personas, "claude"), "utf8");
@@ -238,9 +265,10 @@ export function exportDsh(options: DshExportOptions): DshExportResult {
238
  "",
239
  "这是 AgentLens 从 DeepSeek Harness 导出的便携包,包含三类内容:",
240
  "",
241
- "1. `personas.md` — 所有 Bot 的人物设定(名字、角色、模型、指令)",
242
- "2. `materials/` — 工作区文件与记忆快照" + (options.withAttachments ? "(含附件)" : ""),
243
- "3. `conversations/` — 每个会话的完整对话记录(Markdown)",
 
244
  "",
245
  "把这整个目录放进任何 AI Agent 可以读取的项目里,它就能了解���的人物设定、资料和过往对话。",
246
  "",
 
1
+ import { existsSync, readFileSync, readdirSync, statSync, mkdirSync, writeFileSync, cpSync, rmSync } from "node:fs";
2
  import { homedir } from "node:os";
3
  import { join, resolve } from "node:path";
4
  import { execFileSync } from "node:child_process";
 
11
  color?: string;
12
  avatar?: string;
13
  model?: string;
14
+ effort?: string;
15
  capabilities?: string[];
16
  instructions: string;
17
  }
 
51
  color: typeof bot?.color === "string" ? bot.color : undefined,
52
  avatar: bot?.avatar ? JSON.stringify(bot.avatar) : undefined,
53
  model: typeof bot?.model === "string" ? bot.model : undefined,
54
+ effort: typeof bot?.effort === "string" ? bot.effort : (typeof bot?.appliedEffort === "string" ? bot.appliedEffort : undefined),
55
  capabilities: Array.isArray(bot?.capabilities) ? bot.capabilities : undefined,
56
  instructions: typeof bot?.instructions === "string" ? bot.instructions : "",
57
  });
 
61
 
62
  /** Render personas as a portable markdown document. */
63
  export function renderPersonas(personas: Persona[]): string {
64
+ const lines: string[] = ["# 人设档案", ""];
65
  for (const p of personas) {
66
  lines.push(`## ${p.name}`);
67
  lines.push("");
 
79
  return lines.join("\n");
80
  }
81
 
82
+ /** Render the model configuration (persona → model + reasoning effort). */
83
+ export function renderModels(personas: Persona[]): string {
84
+ const lines: string[] = ["# 模型配置", ""];
85
+ lines.push("| 人设 | 角色 | 模型 | 推理档位 |");
86
+ lines.push("|---|---|---|---|");
87
+ for (const p of personas) {
88
+ lines.push(`| ${p.name} | ${p.role ?? "-"} | ${p.model ?? "-"} | ${p.effort ?? "-"} |`);
89
+ }
90
+ lines.push("");
91
+ const unique = [...new Set(personas.map((p) => p.model).filter(Boolean))];
92
+ if (unique.length > 0) {
93
+ lines.push("## 使用到的模型");
94
+ lines.push("");
95
+ for (const m of unique) lines.push(`- ${m}`);
96
+ lines.push("");
97
+ }
98
+ return lines.join("\n");
99
+ }
100
+
101
  /** Copy material directories (workspace, memory, optionally attachments). */
102
  export function exportMaterials(outDir: string, withAttachments: boolean): { dirs: string[]; bytes: number } {
103
  const targets: Array<[string, string]> = [
104
+ [join(HOME, ".dsh", "bot", "workspace"), "files/workspace"],
105
+ [join(HOME, ".dsh", "bot", "memory"), "files/memory"],
106
  ];
107
+ if (withAttachments) targets.push([join(HOME, ".dsh", "attachments"), "files/attachments"]);
108
 
109
  const copied: string[] = [];
110
  let bytes = 0;
 
222
  export function exportDsh(options: DshExportOptions): DshExportResult {
223
  const outDir = resolve(options.outDir);
224
  mkdirSync(outDir, { recursive: true });
225
+ // Remove legacy bundle artifacts from older AgentLens versions.
226
+ for (const legacy of ["personas.md", "materials"]) {
227
+ const p = join(outDir, legacy);
228
+ if (existsSync(p)) rmSync(p, { recursive: true, force: true });
229
+ }
230
 
231
  const personas = readPersonas();
232
+ writeFileSync(join(outDir, "persona.md"), renderPersonas(personas), "utf8");
233
+ writeFileSync(join(outDir, "models.md"), renderModels(personas), "utf8");
234
  // Ready-to-use instruction files for the two shared standards.
235
  writeFileSync(join(outDir, "AGENTS.md"), renderInstructionFile(personas, "agents"), "utf8");
236
  writeFileSync(join(outDir, "CLAUDE.md"), renderInstructionFile(personas, "claude"), "utf8");
 
265
  "",
266
  "这是 AgentLens 从 DeepSeek Harness 导出的便携包,包含三类内容:",
267
  "",
268
+ "1. `persona.md` — 人设档案(每个角色的外观、职责、完整指令)",
269
+ "2. `models.md` — 模型配置(每个角色用的模型与推理档位)",
270
+ "3. `files/` — 工作区文件与记忆快照" + (options.withAttachments ? "(含附件)" : ""),
271
+ "4. `conversations/` — 每个会话的完整对话记录(Markdown)",
272
  "",
273
  "把这整个目录放进任何 AI Agent 可以读取的项目里,它就能了解���的人物设定、资料和过往对话。",
274
  "",
src/import/dsh-import.ts CHANGED
@@ -47,12 +47,13 @@ function sectionFor(dataDir: string): string {
47
  "",
48
  "以下资料从 DeepSeek Harness 一键导入,回答前先阅读后再作答:",
49
  "",
50
- `- 人物设定:\`${join(dataDir, "personas.md")}\``,
51
- `- 工作区文件:\`${join(dataDir, "materials", "workspace")}\``,
52
- `- 记忆快照:\`${join(dataDir, "materials", "memory")}\``,
 
53
  `- 对话记录:\`${join(dataDir, "conversations")}\``,
54
  "",
55
- "使用规则:涉及用户偏好/角色设定时先读 personas.md;需要资料时查 materials/;需要历史上下文时检索 conversations/。",
56
  MARK_END,
57
  ].join("\n");
58
  }
@@ -90,12 +91,13 @@ function writeSkill(skillsDir: string | undefined, dataDir: string): string | un
90
  "",
91
  "| 内容 | 路径 | 什么时候用 |",
92
  "|---|---|---|",
93
- `| 人物设定 | \`${join(dataDir, "personas.md")}\` | 用户问"你是谁""按我的设定来"时 |`,
94
- `| 工作区文件 | \`${join(dataDir, "materials", "workspace")}\` | 需要之前的文件资料时 |`,
95
- `| 记忆快照 | \`${join(dataDir, "materials", "memory")}\` | 需要历史决策/结论时 |`,
 
96
  `| 对话记录 | \`${join(dataDir, "conversations")}\` | 需要之前聊过什么时 |`,
97
  "",
98
- "阅读顺序:先 personas.md 了解角色设定,再按需检索 materials / conversations。",
99
  "",
100
  ].join("\n");
101
  writeFileSync(file, content, "utf8");
 
47
  "",
48
  "以下资料从 DeepSeek Harness 一键导入,回答前先阅读后再作答:",
49
  "",
50
+ `- 人设档案:\`${join(dataDir, "persona.md")}\``,
51
+ `- 模型配置:\`${join(dataDir, "models.md")}\``,
52
+ `- 文件资料:\`${join(dataDir, "files", "workspace")}\``,
53
+ `- 记忆快照:\`${join(dataDir, "files", "memory")}\``,
54
  `- 对话记录:\`${join(dataDir, "conversations")}\``,
55
  "",
56
+ "使用规则:涉及角色设定时先读 persona.md;模型偏好见 models.md;需要资料时查 files/;需要历史上下文时检索 conversations/。",
57
  MARK_END,
58
  ].join("\n");
59
  }
 
91
  "",
92
  "| 内容 | 路径 | 什么时候用 |",
93
  "|---|---|---|",
94
+ `| 人设档案 | \`${join(dataDir, "persona.md")}\` | 用户问"你是谁""按我的设定来"时 |`,
95
+ `| 模型配置 | \`${join(dataDir, "models.md")}\` | 用户问用的什么模型时 |`,
96
+ `| 文件资料 | \`${join(dataDir, "files", "workspace")}\` | 需要之前的文件资料时 |`,
97
+ `| 记忆快照 | \`${join(dataDir, "files", "memory")}\` | 需要历史决策/结论时 |`,
98
  `| 对话记录 | \`${join(dataDir, "conversations")}\` | 需要之前聊过什么时 |`,
99
  "",
100
+ "阅读顺序:先 persona.md 了解人设,models.md 看模型,再按需检索 files / conversations。",
101
  "",
102
  ].join("\n");
103
  writeFileSync(file, content, "utf8");
tests/export.test.ts CHANGED
@@ -1,5 +1,5 @@
1
  import { describe, it, expect } from "vitest";
2
- import { renderPersonas } from "../src/export/dsh.js";
3
  import type { Persona } from "../src/export/dsh.js";
4
 
5
  const personas: Persona[] = [
@@ -10,7 +10,7 @@ const personas: Persona[] = [
10
  describe("renderPersonas", () => {
11
  it("renders every persona with metadata and instructions", () => {
12
  const md = renderPersonas(personas);
13
- expect(md).toContain("# DSH 人物设定(Bot 团队)");
14
  expect(md).toContain("## Chief");
15
  expect(md).toContain("- 角色:总管");
16
  expect(md).toContain("- 模型:deepseek-flash");
@@ -21,6 +21,19 @@ describe("renderPersonas", () => {
21
 
22
  it("handles empty persona list", () => {
23
  const md = renderPersonas([]);
24
- expect(md).toContain("# DSH 人物设定");
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  });
26
  });
 
1
  import { describe, it, expect } from "vitest";
2
+ import { renderPersonas, renderModels } from "../src/export/dsh.js";
3
  import type { Persona } from "../src/export/dsh.js";
4
 
5
  const personas: Persona[] = [
 
10
  describe("renderPersonas", () => {
11
  it("renders every persona with metadata and instructions", () => {
12
  const md = renderPersonas(personas);
13
+ expect(md).toContain("# 人设档案");
14
  expect(md).toContain("## Chief");
15
  expect(md).toContain("- 角色:总管");
16
  expect(md).toContain("- 模型:deepseek-flash");
 
21
 
22
  it("handles empty persona list", () => {
23
  const md = renderPersonas([]);
24
+ expect(md).toContain("# 人设档案");
25
+ });
26
+ });
27
+
28
+ describe("renderModels", () => {
29
+ it("renders a model table with effort", () => {
30
+ const md = renderModels([
31
+ { id: "a", name: "Chief", role: "总管", model: "deepseek-flash", effort: "high", instructions: "x" },
32
+ { id: "b", name: "代码 bot", role: "代码", model: "xiaomi/mimo-v2.6-pro", instructions: "y" },
33
+ ]);
34
+ expect(md).toContain("# 模型配置");
35
+ expect(md).toContain("| Chief | 总管 | deepseek-flash | high |");
36
+ expect(md).toContain("| 代码 bot | 代码 | xiaomi/mimo-v2.6-pro | - |");
37
+ expect(md).toContain("deepseek-flash");
38
  });
39
  });
tests/import.test.ts CHANGED
@@ -17,7 +17,7 @@ describe("mergeInstructions", () => {
17
  const out = readFileSync(file, "utf8");
18
  expect(out).toContain("- Keep this");
19
  expect(out).toContain("agentlens-import:start");
20
- expect(out).toContain("/data/dsh/personas.md");
21
  });
22
 
23
  it("is idempotent across repeated runs", () => {
@@ -29,7 +29,7 @@ describe("mergeInstructions", () => {
29
  const out = readFileSync(file, "utf8");
30
  // Exactly one section, and it reflects the latest data dir.
31
  expect((out.match(/agentlens-import:start/g) || []).length).toBe(1);
32
- expect(out).toContain("/data/b/personas.md");
33
- expect(out).not.toContain("/data/a/personas.md");
34
  });
35
  });
 
17
  const out = readFileSync(file, "utf8");
18
  expect(out).toContain("- Keep this");
19
  expect(out).toContain("agentlens-import:start");
20
+ expect(out).toContain("/data/dsh/persona.md");
21
  });
22
 
23
  it("is idempotent across repeated runs", () => {
 
29
  const out = readFileSync(file, "utf8");
30
  // Exactly one section, and it reflects the latest data dir.
31
  expect((out.match(/agentlens-import:start/g) || []).length).toBe(1);
32
+ expect(out).toContain("/data/b/persona.md");
33
+ expect(out).not.toContain("/data/a/persona.md");
34
  });
35
  });