dsh-macro-memory 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 (130) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +457 -2
  3. package/cordis.patch.yml +6 -0
  4. package/lib/client.js +3623 -0
  5. package/lib/index.js +469 -0
  6. package/lib/macro/brand.js +82 -0
  7. package/lib/macro/bridge.js +158 -0
  8. package/lib/macro/chain.js +206 -0
  9. package/lib/macro/contract.js +471 -0
  10. package/lib/macro/cost.js +164 -0
  11. package/lib/macro/defs/admin.js +439 -0
  12. package/lib/macro/defs/dream.js +24 -0
  13. package/lib/macro/defs/link.js +257 -0
  14. package/lib/macro/defs/project.js +25 -0
  15. package/lib/macro/defs/read.js +145 -0
  16. package/lib/macro/defs/remember.js +213 -0
  17. package/lib/macro/defs/search.js +661 -0
  18. package/lib/macro/defs/update.js +161 -0
  19. package/lib/macro/dreamledger.js +1398 -0
  20. package/lib/macro/facade.js +135 -0
  21. package/lib/macro/fusion.js +182 -0
  22. package/lib/macro/linkflow.js +391 -0
  23. package/lib/macro/links.js +448 -0
  24. package/lib/macro/neighbor.js +209 -0
  25. package/lib/macro/panel.js +96 -0
  26. package/lib/macro/prompt.js +139 -0
  27. package/lib/macro/provenance.js +148 -0
  28. package/lib/macro/render.js +35 -0
  29. package/lib/macro/revisions.js +253 -0
  30. package/lib/macro/shared.js +113 -0
  31. package/lib/macro/store.js +103 -0
  32. package/lib/macro/tokencost.js +90 -0
  33. package/lib/macro/tools.js +67 -0
  34. package/package.json +54 -4
  35. package/vendor/VENDOR.json +23 -0
  36. package/vendor/dsh-memory-nebula/CONTRIBUTING.md +48 -0
  37. package/vendor/dsh-memory-nebula/LICENSE +21 -0
  38. package/vendor/dsh-memory-nebula/README.en.md +203 -0
  39. package/vendor/dsh-memory-nebula/README.md +253 -0
  40. package/vendor/dsh-memory-nebula/SECURITY.md +43 -0
  41. package/vendor/dsh-memory-nebula/SUPPORT.md +33 -0
  42. package/vendor/dsh-memory-nebula/cordis.patch.yml +4 -0
  43. package/vendor/dsh-memory-nebula/lib/client.js +105 -0
  44. package/vendor/dsh-memory-nebula/lib/host/adapters/index.js +279 -0
  45. package/vendor/dsh-memory-nebula/lib/host/adapters/ingest.js +230 -0
  46. package/vendor/dsh-memory-nebula/lib/host/adapters/meow.js +317 -0
  47. package/vendor/dsh-memory-nebula/lib/host/adapters/notes.js +305 -0
  48. package/vendor/dsh-memory-nebula/lib/host/adapters/sqlite.js +287 -0
  49. package/vendor/dsh-memory-nebula/lib/host/adapters/util.js +231 -0
  50. package/vendor/dsh-memory-nebula/lib/host/bridge.js +351 -0
  51. package/vendor/dsh-memory-nebula/lib/host/compress.js +97 -0
  52. package/vendor/dsh-memory-nebula/lib/host/demo.js +357 -0
  53. package/vendor/dsh-memory-nebula/lib/host/diagnostics.js +125 -0
  54. package/vendor/dsh-memory-nebula/lib/host/doctor.js +270 -0
  55. package/vendor/dsh-memory-nebula/lib/host/graph.js +1663 -0
  56. package/vendor/dsh-memory-nebula/lib/host/graphcache.js +282 -0
  57. package/vendor/dsh-memory-nebula/lib/host/http.js +993 -0
  58. package/vendor/dsh-memory-nebula/lib/host/injectcfg.js +95 -0
  59. package/vendor/dsh-memory-nebula/lib/host/ledger.js +175 -0
  60. package/vendor/dsh-memory-nebula/lib/host/live.js +204 -0
  61. package/vendor/dsh-memory-nebula/lib/host/nebula.js +2105 -0
  62. package/vendor/dsh-memory-nebula/lib/host/page.js +75 -0
  63. package/vendor/dsh-memory-nebula/lib/host/path.js +83 -0
  64. package/vendor/dsh-memory-nebula/lib/host/recall.js +451 -0
  65. package/vendor/dsh-memory-nebula/lib/host/share.js +633 -0
  66. package/vendor/dsh-memory-nebula/lib/host/sources.js +266 -0
  67. package/vendor/dsh-memory-nebula/lib/host/store.js +333 -0
  68. package/vendor/dsh-memory-nebula/lib/host/text.js +410 -0
  69. package/vendor/dsh-memory-nebula/lib/host/transcripts.js +396 -0
  70. package/vendor/dsh-memory-nebula/lib/index.js +759 -0
  71. package/vendor/dsh-memory-nebula/lib/standalone.mjs +315 -0
  72. package/vendor/dsh-memory-nebula/lib/web/api.js +426 -0
  73. package/vendor/dsh-memory-nebula/lib/web/app.js +4159 -0
  74. package/vendor/dsh-memory-nebula/lib/web/i18n.js +580 -0
  75. package/vendor/dsh-memory-nebula/lib/web/index.html +174 -0
  76. package/vendor/dsh-memory-nebula/lib/web/nav.js +132 -0
  77. package/vendor/dsh-memory-nebula/lib/web/render.js +1890 -0
  78. package/vendor/dsh-memory-nebula/lib/web/space3d.js +1883 -0
  79. package/vendor/dsh-memory-nebula/lib/web/style.css +1402 -0
  80. package/vendor/dsh-memory-nebula/locale/en.json +7 -0
  81. package/vendor/dsh-memory-nebula/locale/zh.json +7 -0
  82. package/vendor/dsh-memory-nebula/market/assets/icon-180.png +0 -0
  83. package/vendor/dsh-memory-nebula/market/assets/icon.svg +40 -0
  84. package/vendor/dsh-memory-nebula/market/index.json +101 -0
  85. package/vendor/dsh-memory-nebula/package.json +87 -0
  86. package/vendor/dsh-memory-nebula/sidecar.ps1 +119 -0
  87. package/vendor/meow-memory/LICENSE +21 -0
  88. package/vendor/meow-memory/README.en.md +192 -0
  89. package/vendor/meow-memory/README.md +174 -0
  90. package/vendor/meow-memory/README.pt-br.md +180 -0
  91. package/vendor/meow-memory/cordis.patch.yml +7 -0
  92. package/vendor/meow-memory/lib/client.js +3344 -0
  93. package/vendor/meow-memory/lib/client.js.map +7 -0
  94. package/vendor/meow-memory/lib/index.js +9567 -0
  95. package/vendor/meow-memory/lib/index.js.map +7 -0
  96. package/vendor/meow-memory/lib/prompts/README.md +65 -0
  97. package/vendor/meow-memory/lib/prompts/en/dream-atomic.md +36 -0
  98. package/vendor/meow-memory/lib/prompts/en/dream-header.md +9 -0
  99. package/vendor/meow-memory/lib/prompts/en/dream-project-summary.md +12 -0
  100. package/vendor/meow-memory/lib/prompts/en/dream-topic.md +27 -0
  101. package/vendor/meow-memory/lib/prompts/en/external-memory-notice.md +8 -0
  102. package/vendor/meow-memory/lib/prompts/en/first-create-notice.md +8 -0
  103. package/vendor/meow-memory/lib/prompts/en/labels.md +98 -0
  104. package/vendor/meow-memory/lib/prompts/en/reflect.md +31 -0
  105. package/vendor/meow-memory/lib/prompts/en/system-guide.md +121 -0
  106. package/vendor/meow-memory/lib/prompts/en/tools.md +83 -0
  107. package/vendor/meow-memory/lib/prompts/en/welcome-guide.md +12 -0
  108. package/vendor/meow-memory/lib/prompts/pt-br/dream-atomic.md +36 -0
  109. package/vendor/meow-memory/lib/prompts/pt-br/dream-header.md +9 -0
  110. package/vendor/meow-memory/lib/prompts/pt-br/dream-project-summary.md +12 -0
  111. package/vendor/meow-memory/lib/prompts/pt-br/dream-topic.md +27 -0
  112. package/vendor/meow-memory/lib/prompts/pt-br/external-memory-notice.md +8 -0
  113. package/vendor/meow-memory/lib/prompts/pt-br/first-create-notice.md +8 -0
  114. package/vendor/meow-memory/lib/prompts/pt-br/labels.md +98 -0
  115. package/vendor/meow-memory/lib/prompts/pt-br/reflect.md +31 -0
  116. package/vendor/meow-memory/lib/prompts/pt-br/system-guide.md +121 -0
  117. package/vendor/meow-memory/lib/prompts/pt-br/tools.md +83 -0
  118. package/vendor/meow-memory/lib/prompts/pt-br/welcome-guide.md +12 -0
  119. package/vendor/meow-memory/lib/prompts/zh/dream-atomic.md +36 -0
  120. package/vendor/meow-memory/lib/prompts/zh/dream-header.md +9 -0
  121. package/vendor/meow-memory/lib/prompts/zh/dream-project-summary.md +19 -0
  122. package/vendor/meow-memory/lib/prompts/zh/dream-topic.md +27 -0
  123. package/vendor/meow-memory/lib/prompts/zh/external-memory-notice.md +8 -0
  124. package/vendor/meow-memory/lib/prompts/zh/first-create-notice.md +8 -0
  125. package/vendor/meow-memory/lib/prompts/zh/labels.md +98 -0
  126. package/vendor/meow-memory/lib/prompts/zh/reflect.md +30 -0
  127. package/vendor/meow-memory/lib/prompts/zh/system-guide.md +119 -0
  128. package/vendor/meow-memory/lib/prompts/zh/tools.md +83 -0
  129. package/vendor/meow-memory/lib/prompts/zh/welcome-guide.md +12 -0
  130. package/vendor/meow-memory/package.json +64 -0
@@ -0,0 +1,113 @@
1
+ /**
2
+ * 8 个统一工具共用的东西:枚举、输出形状、取值小工具。
3
+ *
4
+ * 单独一个文件是为了让 `defs/*.js` 各自只依赖它和 `linkflow.js`,
5
+ * 谁也不会反向依赖装配器 `tools.js`,加工具时不用动别人的 import(DESIGN §16)。
6
+ */
7
+ import * as Meow from '../../vendor/meow-memory/lib/index.js'
8
+
9
+ /** 以 meow 导出为准;vendor 换版本时不会因为枚举漂移而注册失败。 */
10
+ export const LEVELS =
11
+ Array.isArray(Meow.LEVELS) && Meow.LEVELS.length > 0
12
+ ? Meow.LEVELS
13
+ : ['soul', 'user', 'rules', 'fact', 'lesson', 'topic', 'project']
14
+
15
+ export const PROJECT_SUBCATEGORIES =
16
+ Array.isArray(Meow.PROJECT_SUBCATEGORIES) && Meow.PROJECT_SUBCATEGORIES.length > 0
17
+ ? Meow.PROJECT_SUBCATEGORIES
18
+ : ['overview', 'structure', 'decisions', 'quotes', 'ops', 'todo']
19
+
20
+ /** 所有统一工具都吐纯文本:模型读得懂,也没必要为 8 个工具各设计一套结构化输出。 */
21
+ export const TEXT_OUT = {
22
+ schema: { type: 'string' },
23
+ render: (_args, value) => [
24
+ { type: 'text', text: typeof value === 'string' ? value : safeJson(value) },
25
+ ],
26
+ }
27
+
28
+ export function safeJson(value) {
29
+ try {
30
+ return JSON.stringify(value, null, 2)
31
+ } catch {
32
+ return String(value)
33
+ }
34
+ }
35
+
36
+ /** 只把调用方真的给过的参数转给子插件——别用 undefined 覆盖 vendor 的默认值。 */
37
+ export function pick(source, keys) {
38
+ const out = {}
39
+ for (const key of keys) {
40
+ if (source[key] !== undefined) out[key] = source[key]
41
+ }
42
+ return out
43
+ }
44
+
45
+ /**
46
+ * [macro-fusion 0.2.62] 条数类参数的唯一出口:给多少就照办多少,改过了就得说出口。
47
+ *
48
+ * 以前 memory_read 里是「三元给默认 + `Number()`」后面接一句
49
+ * `if (!Number.isFinite(want) || want <= 0) return said`:非数字、负数、0 三种情况
50
+ * 一起被压成「这次没有邻居段」,读的人只会以为这条记忆压根没有邻居(DESIGN §72)。
51
+ *
52
+ * 约定:
53
+ * - 没给(undefined / null / 空串)→ 默认值,不说话;
54
+ * - 给了 0 → 照办 0(0 是什么意思由调用方定义),不说话;
55
+ * - 非数字 / 负数 → 回默认值,并把原值和原因写出来;
56
+ * - 非整数 → 抹掉小数,并说清「少掉的那半条不是你给的条件」;
57
+ * - 超出上界 → 夹到上界,并说清「结果是被改过的条件算出来的」。
58
+ */
59
+ export function countParam(name, raw, { min = 0, max = Number.POSITIVE_INFINITY, def } = {}) {
60
+ if (raw === undefined || raw === null) return { value: def, note: '' }
61
+ if (typeof raw === 'string' && raw.trim() === '') return { value: def, note: '' }
62
+ const n = Number(raw)
63
+ if (!Number.isFinite(n)) {
64
+ return {
65
+ value: def,
66
+ note: `${name} 给的是「${String(raw)}」,不是数字——这次按默认 ${def} 条算,不是你给的那个。`,
67
+ }
68
+ }
69
+ if (n < 0) {
70
+ return {
71
+ value: def,
72
+ note: `${name} 给的是「${n}」,是负数——条数没有「从后往前数」这回事,这次按默认 ${def} 条算。`,
73
+ }
74
+ }
75
+ if (n === 0) return { value: 0, note: '' }
76
+ const whole = Math.floor(n)
77
+ const clamped = Math.max(min, Math.min(max, whole))
78
+ const bits = []
79
+ if (whole !== n) bits.push(`条数只能是整数,这次按 ${clamped} 条算——少掉的那半条不是你给的条件`)
80
+ if (clamped !== whole) {
81
+ bits.push(`超出 ${min}–${max},这次按 ${clamped} 条算——结果是被改过的条件算出来的,不是你给的那个`)
82
+ }
83
+ if (bits.length === 0) return { value: whole, note: '' }
84
+ return { value: clamped, note: `${name} 给的是「${n}」,${bits.join(';')}。` }
85
+ }
86
+
87
+ /** 从星图 inspect 文本里只取「连接到的记忆」那一段,避免与 meow 的正文重复。 */
88
+ export function neighborSection(text, marker = '## 连接到的记忆') {
89
+ if (typeof text !== 'string') return ''
90
+ const at = text.indexOf(marker)
91
+ if (at < 0) return ''
92
+ return text.slice(at).trim()
93
+ }
94
+
95
+ /**
96
+ * [macro-fusion 0.2.77] 邻居段没拿到时的那句话。
97
+ * 以前 read.js 只写 `section ? said + '\n\n' + section : said`:星图失败或回执改了格式时,
98
+ * 那句解释被整段丢掉,读者只看得到正文——于是把「没带到」读成「这条记忆没有邻居」。
99
+ * 三种情况要说三种话,这里只认「段在不在」和「这一问查成没查成」,
100
+ * 不接收星图原文(内部错误不该原样甩给模型)。
101
+ */
102
+ export function neighborGapNote(section, reachable, raw = '') {
103
+ if (typeof section === 'string' && section.trim().length > 0) return ''
104
+ if (!reachable) {
105
+ return '星图这次没答上来(这一问没查成),所以邻居一条都没带到——这不是「这条记忆没有邻居」。'
106
+ }
107
+ const said = String(raw ?? '')
108
+ // 星图答上来了,但答的是「没这条记忆」:那是第三种情况,不能套「格式变了」。
109
+ if (/星图里没有|图是空的|还没有节点/.test(said)) {
110
+ return '星图这次没查到这条记忆(可能刚写还没入图,也可能 id 不对),所以没有邻居段——这不是「它没有邻居」。'
111
+ }
112
+ return '星图的回执里没有「连接到的记忆」这一段(多半是它改了格式),所以这次邻居没带到——这不是「这条记忆没有邻居」。'
113
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * 存储层:macro 自己的两个 jsonl 文件「在哪、怎么写、怎么读」。
3
+ *
4
+ * 为什么单开一个文件(0.2.21):路径与 jsonl 的读写原本散在 `cost.js`(成本账本)与 `links.js`
5
+ * (待补连线队列)里,于是队列要从成本账本 import 一个 `macroHome()` —— 依赖方向与现实语义
6
+ * 正好反了(队列不是成本的一部分),而且「读文件→按行 JSON.parse→跳过坏行」这段一模一样的
7
+ * 循环写了两遍。两处各自都正确,合起来就是两个错:谁都能改路径,谁都能改解析规则。
8
+ *
9
+ * 三条约定,改这个文件之前先读:
10
+ * 1. **`$DSH_HOME` 只在这里读一次**。别处的路径一律由 `ledgerPath()` / `pendingPath()` 给出,
11
+ * 这样「换个 home」只需要改一处,doctor 也能用一行断言盯住。
12
+ * 2. **jsonl 的坏行一律跳过,不抛**。这两个文件都是「降级不影响记忆主功能」的类型:
13
+ * 一行坏掉的账不该让整个账本读不出来。
14
+ * 3. **这层不认识业务**。它不知道「成本」和「待补连线」是什么,只知道文件名与行格式。
15
+ */
16
+ import { appendFileSync, mkdirSync, readFileSync } from 'node:fs'
17
+ import { homedir } from 'node:os'
18
+ import { join } from 'node:path'
19
+
20
+ /** macro 的数据目录:`$DSH_HOME/macro-memory`(没设 DSH_HOME 时退回 ~/.dsh)。 */
21
+ export function macroHome() {
22
+ const root = process.env.DSH_HOME && process.env.DSH_HOME.length > 0 ? process.env.DSH_HOME : join(homedir(), '.dsh')
23
+ return join(root, 'macro-memory')
24
+ }
25
+
26
+ /** 成本账本。 */
27
+ export function ledgerPath() {
28
+ return join(macroHome(), 'cost.jsonl')
29
+ }
30
+
31
+ /** 待补连线队列。 */
32
+ export function pendingPath() {
33
+ return join(macroHome(), 'pending-links.jsonl')
34
+ }
35
+
36
+ /**
37
+ * 读一个 jsonl 文件,**并把「为什么没读到」一起回出来**(0.2.55)。
38
+ *
39
+ * [macro-fusion 0.2.55] 一处 `[]` 原来同时代表四种来路:
40
+ * 从没写过 / 文件读不出来(EACCES、EISDIR)/ 整份都是坏行 / 写了但一条都没落成。
41
+ * 上游面板只能拿这个「空」去编一句话,就变成「账本还是空的,调用几次再看」——
42
+ * 明明是我们写不进去,说出来却像用户没调用过。
43
+ *
44
+ * @returns {{entries: any[], exists: boolean, unreadable: boolean, badLines: number, lines: number, error: string}}
45
+ */
46
+ export function readJsonlDetail(file) {
47
+ let raw = ''
48
+ try {
49
+ raw = readFileSync(file, 'utf8')
50
+ } catch (err) {
51
+ const missing = err && err.code === 'ENOENT'
52
+ // ENOENT 才是「真的没有」;别的错误(权限、把目录当文件读)都是「这次读不出来」
53
+ return {
54
+ entries: [],
55
+ exists: !missing,
56
+ unreadable: !missing,
57
+ badLines: 0,
58
+ lines: 0,
59
+ error: missing ? '' : String(err?.message ?? err),
60
+ }
61
+ }
62
+ const entries = []
63
+ let badLines = 0
64
+ let lines = 0
65
+ for (const line of raw.split('\n')) {
66
+ if (line.trim().length === 0) continue
67
+ lines += 1
68
+ try {
69
+ entries.push(JSON.parse(line))
70
+ } catch {
71
+ badLines += 1
72
+ }
73
+ }
74
+ return { entries, exists: true, unreadable: false, badLines, lines, error: '' }
75
+ }
76
+
77
+ /**
78
+ * 读一个 jsonl 文件,返回能解析的条目数组。
79
+ * 文件不存在 → 空数组;空行与坏行 → 跳过(约定 2)。
80
+ */
81
+ export function readJsonl(file) {
82
+ return readJsonlDetail(file).entries
83
+ }
84
+
85
+ /**
86
+ * 追加一行 JSON(目录不存在就先建),并把失败原因带出来(0.2.55)。
87
+ * 约定 2 是「写不进去不打断调用方」,不是「写不进去不许说」——调用方可以继续省略,
88
+ * 但面板需要知道这批账到底存下来了没有。
89
+ */
90
+ export function appendJsonlDetail(file, entry) {
91
+ try {
92
+ mkdirSync(macroHome(), { recursive: true })
93
+ appendFileSync(file, `${JSON.stringify(entry)}\n`, 'utf8')
94
+ return { ok: true, error: '' }
95
+ } catch (err) {
96
+ return { ok: false, error: String(err?.message ?? err) }
97
+ }
98
+ }
99
+
100
+ /** 追加一行 JSON(目录不存在就先建);写不进去就算了,绝不打断调用方。 */
101
+ export function appendJsonl(file, entry) {
102
+ return appendJsonlDetail(file, entry).ok
103
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * [macro-fusion 0.2.109] 回执成本:省 token 的前提是知道自己花了多少。
3
+ *
4
+ * 为什么单独一格:记忆系统的六个衡量维度里,「效率(检索快、不拖累当前任务)」是唯一没有数的——
5
+ * probe 里有条数、有耗时,没有「这次检索占了多少上下文」。没有这个数,
6
+ * 「多查几次也无所谓」就永远是一句空话,调用方也没法判断「值不值」。
7
+ *
8
+ * 口径三件事:
9
+ * 1. 这是**估算**,不是计量。CJK 一个字按 1 token 算(偏保守:真实分词常见 1 字 0.6~1),
10
+ * 其余按 4 字符 1 token。报出来的用量级够用来决定「要不要收紧、收紧多少」,
11
+ * 不够用来跟账单对账——这句要写在尾注里,不然读者会拿它当账单。
12
+ * 2. 只在回执已经够大时才报(`COST_SHOW_MIN`)。一条 40 token 的成本说明加在 80 token 的回执上,
13
+ * 就是拿 token 换噪音——省 token 的工具自己先要省。
14
+ * 3. 预算(budget)是**约束**,不是愿望:给了就让工具自己收缩并如实交代缩了什么;
15
+ * 装不下就说最小能给多少,绝不假装装下了。
16
+ */
17
+
18
+ /** CJK 统一表意文字 + 日文假名 + 谚文 + 全角标点:这些按「一字一 token」估。 */
19
+ const CJK = /[\u3000-\u303f\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uac00-\ud7af\uff00-\uffef]/g
20
+
21
+ /** 回执大到这个量级才值得报成本(token)。低于它的成本说明本身比省下的还贵。 */
22
+ export const COST_SHOW_MIN = 500
23
+
24
+ /** 小到这个量级才建议「只看骨架」。再小就没有可省的了。 */
25
+ export const COST_HINT_MIN = 1200
26
+
27
+ /** 预算下限:比它还小的预算连一条标题都装不下,按不限额处理并说明原因。 */
28
+ export const BUDGET_MIN = 80
29
+
30
+ /** 估算 token 数:CJK 一字算 1,其余 4 字符算 1(向上取整)。空串算 0。 */
31
+ export function estTokens(text) {
32
+ const s = typeof text === 'string' ? text : String(text ?? '')
33
+ if (s.length === 0) return 0
34
+ const cjk = (s.match(CJK) ?? []).length
35
+ return cjk + Math.ceil((s.length - cjk) / 4)
36
+ }
37
+
38
+ /** 报数格式:一千以内给整数,过千给一位小数的 k(`1.2k`),不写成 `1.0k`。 */
39
+ export function fmtTokens(n) {
40
+ const v = Number(n)
41
+ if (!Number.isFinite(v) || v < 0) return '0'
42
+ if (v < 1000) return String(Math.round(v))
43
+ const k = (v / 1000).toFixed(1)
44
+ return `${k.endsWith('.0') ? k.slice(0, -2) : k}k`
45
+ }
46
+
47
+ /**
48
+ * 解析 budget。四种结果要分开,别压成「没给」:
49
+ * - 没给 → `{ value: null, note: '' }`(不限额,也不解释)
50
+ * - 给了但不像数 → 不限额 + 说清「你给的那个没被用上」
51
+ * - 给了但太小 → 不限额 + 说清最小可用值(假装缩到 80 只会给出一条标题,问不出东西)
52
+ * - 给了但太大 → 夹到上界 + 说清「结果是被改过的条件算出来的」
53
+ */
54
+ export function budgetOf(raw, { max = 20000 } = {}) {
55
+ if (raw === undefined || raw === null) return { value: null, note: '' }
56
+ if (typeof raw === 'string' && raw.trim() === '') return { value: null, note: '' }
57
+ const n = Number(raw)
58
+ if (!Number.isFinite(n)) {
59
+ return { value: null, note: `budget 给的是「${String(raw)}」,不是数字——这次按不限额给(回执仍会报成本)。` }
60
+ }
61
+ if (n < BUDGET_MIN) {
62
+ return {
63
+ value: null,
64
+ note: `budget 给的是「${n}」,比最小可用预算 ${BUDGET_MIN} token 还小——这么点连一条标题都装不下,这次按不限额给。`,
65
+ }
66
+ }
67
+ const whole = Math.floor(n)
68
+ if (whole > max) {
69
+ return { value: max, note: `budget 给的是「${whole}」,超出上界 ${max}——这次按 ${max} token 算,不是你给的那个。` }
70
+ }
71
+ return { value: whole, note: '' }
72
+ }
73
+
74
+ /** 成本那句话(不含预算部分):`成本 ≈1.2k token(…)`。 */
75
+ export function costSentence(text) {
76
+ const est = estTokens(text)
77
+ return `成本 ≈${fmtTokens(est)} token(CJK 一字算 1、其余 4 字符算 1,是量级不是账单)`
78
+ }
79
+
80
+ /**
81
+ * 给「读」这类固定形态的回执补成本:够大才说,不够大一个字不加。
82
+ * 阈值放在这里而不是调用处——两处各写一个数,迟早一个来改、一个忘改。
83
+ */
84
+ export function readCostTail(text, { min = COST_SHOW_MIN, hint = COST_HINT_MIN } = {}) {
85
+ const s = String(text ?? '')
86
+ const est = estTokens(s)
87
+ if (est < min) return s
88
+ const hintText = est >= hint ? ';只要骨架就少给几条邻居(neighbors=0 或 3)' : ''
89
+ return `${s}\n\n${costSentence(s)}${hintText}`
90
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * macro-memory 的统一工具面装配器:把 8 个 `defs/*.js` 拼成工具数组。
3
+ *
4
+ * 规矩(DESIGN §7 R2):写路径一律复用子插件自己的工具定义,
5
+ * 这里只做「选哪个子插件工具 + 参数路由 + 结果拼接」,绝不重写记忆逻辑。
6
+ *
7
+ * 0.2.5 起工具定义按「一个工具一个文件」放在 `lib/macro/defs/`,
8
+ * 本文件只剩装配 + 兼容别名;加点工具时改一个文件、在下面 push 一行即可(DESIGN §16)。
9
+ */
10
+ import { TEXT_OUT } from './shared.js'
11
+ import { createLinkFlow } from './linkflow.js'
12
+ import { createRemember } from './defs/remember.js'
13
+ import { createUpdate } from './defs/update.js'
14
+ import { createSearch } from './defs/search.js'
15
+ import { createRead } from './defs/read.js'
16
+ import { createProject } from './defs/project.js'
17
+ import { createLink } from './defs/link.js'
18
+ import { createDream } from './defs/dream.js'
19
+ import { createAdmin } from './defs/admin.js'
20
+
21
+ export { LEVELS, PROJECT_SUBCATEGORIES, neighborSection } from './shared.js'
22
+ export { LINKS_SCHEMA, normalizeLinks } from './linkflow.js'
23
+
24
+ export function createUnifiedTools({ bridge, config = {}, meowDir }) {
25
+ const flow = createLinkFlow({ bridge, config })
26
+
27
+ return [
28
+ createRemember({ flow }),
29
+ createUpdate({ flow, meowDir }),
30
+ createSearch({ flow }),
31
+ createRead({ flow, meowDir }),
32
+ createProject({ flow }),
33
+ createLink({ flow }),
34
+ createDream({ flow }),
35
+ createAdmin({ flow, bridge, config, meowDir }),
36
+ ]
37
+ }
38
+
39
+ /**
40
+ * 兼容别名:把子插件原来的工具原样暴露(默认关)。
41
+ * 只在主人明确要做 A/B 对比或第三方提示词还写着 nebula_* 时才打开。
42
+ */
43
+ export function createAliasTools({ bridge }) {
44
+ const wanted = [
45
+ 'memory_find_similar',
46
+ 'memory_home',
47
+ 'nebula_recall',
48
+ 'nebula_inspect',
49
+ 'nebula_link',
50
+ 'nebula_path',
51
+ 'nebula_stats',
52
+ 'nebula_hygiene',
53
+ 'nebula_bridge',
54
+ 'nebula_sources',
55
+ 'nebula_ingest',
56
+ ]
57
+ return wanted.map((name) => ({
58
+ name,
59
+ description: `兼容别名 → 建议改用 memory_* 统一工具(原 ${name})。`,
60
+ parameters: { type: 'object', additionalProperties: true, properties: {} },
61
+ output: TEXT_OUT,
62
+ async execute(args, exec) {
63
+ const r = await bridge.call(name, args, exec)
64
+ return r.text
65
+ },
66
+ }))
67
+ }
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "dsh-macro-memory",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "private": false,
5
+ "description": "宏观记忆调控插件:以 meow-memory 的记忆库为主库、dsh-memory-nebula 的星图为索引,融合成一套 8 个 memory_* 统一工具 + 一段最小注入;两个原插件退化为引擎,工具面与注入面由本插件统一接管并互相联动。",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/hanhan9999999999999999999/dsh-macro-memory.git"
10
+ },
11
+ "homepage": "https://github.com/hanhan9999999999999999999/dsh-macro-memory#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/hanhan9999999999999999999/dsh-macro-memory/issues"
14
+ },
15
+ "main": "lib/index.js",
16
+ "exports": {
17
+ ".": "./lib/index.js",
18
+ "./client": "./lib/client.js",
19
+ "./cordis.patch.yml": "./cordis.patch.yml",
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": [
23
+ "lib",
24
+ "vendor",
25
+ "cordis.patch.yml",
26
+ "README.md"
27
+ ],
28
+ "scripts": {
29
+ "build:client": "node build.mjs",
30
+ "verify": "node verify.mjs",
31
+ "probe": "node tools/probe-fusion.mjs"
32
+ },
33
+ "license": "MIT",
34
+ "dsh": {
35
+ "bundle": {
36
+ "patch": "./cordis.patch.yml"
37
+ },
38
+ "client": {
39
+ "platform": "web",
40
+ "inject": []
41
+ }
42
+ },
43
+ "engines": {
44
+ "node": ">=24.0.0"
45
+ },
46
+ "keywords": [
47
+ "deepseek-harness",
48
+ "dsh-plugin",
49
+ "memory",
50
+ "macro",
51
+ "meow-memory",
52
+ "memory-nebula",
53
+ "fusion",
54
+ "unified-tools"
55
+ ]
56
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "note": "vendor 账本:这里的源码是从上游拷贝进来的(不是 npm 依赖)。改了就重跑 tools/make-vendor-manifest.mjs;doctor 会核对。",
3
+ "generatedBy": "tools/make-vendor-manifest.mjs",
4
+ "hashedBy": "tools/vendor-hash.mjs",
5
+ "vendors": [
6
+ {
7
+ "dir": "vendor/meow-memory",
8
+ "name": "meow-memory",
9
+ "version": "0.32.8",
10
+ "files": 44,
11
+ "bytes": 1985163,
12
+ "sha256": "c822a00e87ac34acf69b0b16828632ed1716eb3156fd496180aee1608001f88c"
13
+ },
14
+ {
15
+ "dir": "vendor/dsh-memory-nebula",
16
+ "name": "dsh-memory-nebula",
17
+ "version": "1.11.74",
18
+ "files": 51,
19
+ "bytes": 1020104,
20
+ "sha256": "f7f00d07e295e0c272c694206d26ca9cfa0cb7d2c758c895b80c455812fa6642"
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,48 @@
1
+ # Contributing
2
+
3
+ Thanks for looking. This is a small, dependency-free plugin, and the fastest
4
+ way to keep it healthy is to run the same checks CI runs.
5
+
6
+ ## Setup
7
+
8
+ - Node.js 24 or newer (CI runs 24 on both Linux and Windows; 22 is not supported).
9
+ - No install step: the package has no runtime or dev dependencies.
10
+ - The repo is the plugin source. To try it inside DSH, point a profile at this
11
+ directory or install the packed tarball; see `docs/distribution.md`.
12
+
13
+ ## Before opening a pull request
14
+
15
+ ```bash
16
+ npm test # node --test "test/*.test.mjs"
17
+ npm run check # static release checks (version, UTF-8, links, assets)
18
+ ```
19
+
20
+ For HTTP or UI changes, also start the standalone engine and run the smoke
21
+ tests:
22
+
23
+ ```bash
24
+ node lib/standalone.mjs --port 7891 --root <a-memory-root>
25
+ node scripts/smoke.mjs http://127.0.0.1:7891/api/memory-nebula
26
+ ```
27
+
28
+ If you change the market index or locale files, keep the package version and
29
+ `market/index.json` version in sync; `test/market.test.mjs` enforces it.
30
+
31
+ ## Rules of the house
32
+
33
+ - Read-only toward memory stores. Never write into `~/.dsh-meow`, OpenViking
34
+ directories, or user notes.
35
+ - No new runtime dependencies without a strong reason; the single-file
36
+ snapshot and offline story depend on shipping everything ourselves.
37
+ - Keep UI strings in `lib/web/i18n.js`; Chinese is the source text. If you add
38
+ a visible string, add the English entry and run `dev/check-i18n.mjs`.
39
+ - Add a test for behavior changes. A bug fix without a regression test will
40
+ usually be asked for one.
41
+ - Keep commits focused. Update `CHANGELOG.md` for user-visible changes and bump
42
+ the version only when preparing a release.
43
+
44
+ ## Reporting bugs
45
+
46
+ Open an issue with the version, platform, and the diagnostics report from
47
+ `?` → “复制诊断” (it contains no memory text or local paths). For security
48
+ issues use `SECURITY.md`, not a public issue.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 主人 & 小代码酱
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.