@samuelchung2010/dshift 0.0.0-stage → 0.3.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 (46) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/LICENSE +21 -0
  3. package/README.en.md +116 -0
  4. package/README.md +116 -3
  5. package/assets/dshift-readme.gif +0 -0
  6. package/client.js +18831 -0
  7. package/cordis.patch.yml +58 -0
  8. package/docs/architecture.md +203 -0
  9. package/docs/configuration.md +103 -0
  10. package/docs/development.md +125 -0
  11. package/docs/limitations.md +74 -0
  12. package/docs/math-boxed-qquad.png +0 -0
  13. package/docs/math-boxed-single.png +0 -0
  14. package/docs/memory-integration.md +111 -0
  15. package/docs/perf/baseline-before.json +4872 -0
  16. package/docs/perf/baseline-before.summary.json +659 -0
  17. package/docs/perf/fixed-after.json +2927 -0
  18. package/docs/perf/fixed-after.summary.json +583 -0
  19. package/docs/perf/long-chat-performance.md +340 -0
  20. package/docs/perf/merged-after.json +1953 -0
  21. package/docs/perf/merged-after.summary.json +382 -0
  22. package/docs/perf/mount-after.json +82 -0
  23. package/docs/perf/mount-baseline.json +82 -0
  24. package/docs/user-guide.md +202 -0
  25. package/icon.svg +13 -0
  26. package/index.js +16 -0
  27. package/lib/api.js +336 -0
  28. package/lib/artifact/approval-bus.js +94 -0
  29. package/lib/artifact/prompt.js +99 -0
  30. package/lib/artifact/service.js +602 -0
  31. package/lib/artifact/workspace.js +260 -0
  32. package/lib/import/convert.js +343 -0
  33. package/lib/import/format.js +262 -0
  34. package/lib/import/index.js +585 -0
  35. package/lib/import/media.js +101 -0
  36. package/lib/import/zip.js +296 -0
  37. package/lib/memory-store.js +629 -0
  38. package/lib/memory-text.js +162 -0
  39. package/lib/memory.js +871 -0
  40. package/lib/model-config.js +280 -0
  41. package/lib/protocol.js +593 -0
  42. package/lib/service.js +2102 -0
  43. package/lib/store.js +1011 -0
  44. package/locale/en.json +6 -0
  45. package/locale/zh.json +6 -0
  46. package/package.json +49 -6
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Build the single prompt that starts (or continues) one document task.
3
+ *
4
+ * The Agent owns all document work: this prompt only states the user's request,
5
+ * what already exists in its task folder, and the hard rules that keep the
6
+ * user's originals read-only. It deliberately carries no Chat history and no
7
+ * long-term memory, so a document turn costs one Agent task and nothing more.
8
+ * The session cwd is the shared Documents workspace; `{dir}` confines the Agent
9
+ * to this conversation's subfolder so parallel chats never share files.
10
+ */
11
+
12
+ const ZH = {
13
+ header: '文档任务',
14
+ workspace: '当前会话的工作目录是共享的 Documents 文档工作区。',
15
+ scope: '本任务只操作 `{dir}` 子目录,不要读取或修改 Documents 下其他子目录。',
16
+ request: '用户请求',
17
+ empty: '(用户没有输入文字,请根据附带的文件或文件名自行判断最合理的文档任务。)',
18
+ uploads: '用户上传的文件(只读副本)',
19
+ uploadRule: '编辑这些文件时,先复制一份到 `{dir}files/`,只修改那里的副本;绝不修改、覆盖或删除 `{dir}uploads/` 中的原文件。',
20
+ existing: '本任务文件夹已有的文件',
21
+ rules: '工作要求',
22
+ ruleSkill: '先调用 skill 工具加载 office 技能(按目标格式加载 office-docx / office-xlsx / office-pptx),再用官方 Office 工具与技能自带的 Python 库完成工作。',
23
+ ruleOutput: '所有最终文件都保存到 `{dir}files/`,文件名清晰、可直接打开。不要输出到本任务文件夹之外。',
24
+ ruleEdit: '修改已有文档时保留原有结构、样式与语言;无法保留时在总结中说明。PDF 不能直接编辑,需要改变 PDF 时先编辑源文档再另存为 PDF。',
25
+ rulePresent: '完成并自检后,对每个交付文件调用 present 工具(使用相对于会话工作目录的路径,`{dir}files/...`),然后再给出总结。',
26
+ ruleAsk: '不要调用 ask_user_question;信息不足时按最合理的假设完成,并在总结中列出假设。',
27
+ ruleSummary: '最后用用户使用的语言写 2-5 句简短总结:创建或修改了什么、文件在哪里、有哪些假设或限制。不要粘贴代码或大段文件内容。',
28
+ deliver: '交付要求',
29
+ kindHint: '可创建 Word(.docx)、Excel(.xlsx)、PowerPoint(.pptx)与 PDF;需要 PDF 时可由源文档转换生成。',
30
+ }
31
+
32
+ const EN = {
33
+ header: 'Document task',
34
+ workspace: 'The session working directory is the shared Documents workspace.',
35
+ scope: 'Work only inside the `{dir}` subfolder; do not read or modify other subfolders of Documents.',
36
+ request: 'User request',
37
+ empty: '(The user wrote no text. Infer the most reasonable document task from the attached files or their names.)',
38
+ uploads: 'Files the user uploaded (read-only copies)',
39
+ uploadRule: 'To edit one, copy it into `{dir}files/` first and modify only that copy; never modify, overwrite or delete the originals under `{dir}uploads/`.',
40
+ existing: 'Files already in this task folder',
41
+ rules: 'Working rules',
42
+ ruleSkill: 'Call the skill tool first to load an office skill (office-docx / office-xlsx / office-pptx for the target format), then use the official Office tools and the Python libraries those skills describe.',
43
+ ruleOutput: 'Save every final file under `{dir}files/` with a clear, openable name. Never write outside this task folder.',
44
+ ruleEdit: 'Preserve the structure, styling and language of an existing document; mention anything you could not preserve. PDFs cannot be edited directly: edit the source document and export a PDF instead.',
45
+ rulePresent: 'When done and checked, call the present tool for every delivered file (using a path relative to the session working directory, `{dir}files/...`), then write the summary.',
46
+ ruleAsk: 'Do not call ask_user_question. If information is missing, make the most reasonable assumption and list it in the summary.',
47
+ ruleSummary: 'Finish with a 2-5 sentence summary in the user\'s language: what was created or changed, where the files are, and any assumptions or limitations. Do not paste code or large file contents.',
48
+ deliver: 'Delivery',
49
+ kindHint: 'You can create Word (.docx), Excel (.xlsx), PowerPoint (.pptx) and PDF; a PDF can be produced by converting a source document.',
50
+ }
51
+
52
+ function fileLine(file, dir) {
53
+ const size = typeof file.bytes === 'number' ? ` (${formatBytes(file.bytes)})` : ''
54
+ return `- ${dir}${file.relPath}${size}`
55
+ }
56
+
57
+ function formatBytes(bytes) {
58
+ if (bytes < 1024) return `${bytes} B`
59
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
60
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`
61
+ }
62
+
63
+ /**
64
+ * One prompt for a document turn.
65
+ * @param request - the user's text, the task folder name, uploads, files, locale.
66
+ * @returns the prompt text sent as the only message of this Agent turn.
67
+ */
68
+ export function buildArtifactPrompt({ text, taskDir, uploads = [], files = [], locale = 'zh' }) {
69
+ const dict = locale === 'en' ? EN : ZH
70
+ const dir = typeof taskDir === 'string' && taskDir !== '' ? `${taskDir}/` : ''
71
+ const fill = value => value.replaceAll('{dir}', dir)
72
+ const lines = [
73
+ dict.header,
74
+ fill(dict.workspace),
75
+ fill(dict.scope),
76
+ '',
77
+ `${dict.request}:`,
78
+ text.trim() === '' ? dict.empty : text.trim(),
79
+ '',
80
+ ]
81
+ if (uploads.length > 0) {
82
+ lines.push(`${dict.uploads}:`, ...uploads.map(file => fileLine(file, dir)), fill(dict.uploadRule), '')
83
+ }
84
+ if (files.length > 0) {
85
+ lines.push(`${dict.existing}:`, ...files.map(file => fileLine(file, dir)), '')
86
+ }
87
+ lines.push(
88
+ `${dict.rules}:`,
89
+ `1. ${fill(dict.ruleSkill)}`,
90
+ `2. ${fill(dict.ruleOutput)}`,
91
+ `3. ${dict.ruleEdit}`,
92
+ `4. ${fill(dict.rulePresent)}`,
93
+ `5. ${dict.ruleAsk}`,
94
+ `6. ${dict.ruleSummary}`,
95
+ '',
96
+ `${dict.deliver}: ${dict.kindHint}`,
97
+ )
98
+ return lines.join('\n')
99
+ }