@furongjun1999/dsh-memory 0.9.22 → 0.9.23

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 (103) hide show
  1. package/CHANGELOG.en.md +404 -0
  2. package/CHANGELOG.md +45 -0
  3. package/README.en.md +240 -0
  4. package/README.md +3 -1
  5. package/docs/README.md +2 -0
  6. package/docs/en/README.md +190 -0
  7. package/docs/en/TRANSLATION.md +78 -0
  8. package/docs/en/TRANSLATION_MANIFEST.json +170 -0
  9. package/docs/en/TRANSLATION_REPORT.md +11 -0
  10. package/docs/en/dev/README.md +10 -0
  11. package/docs/en/dev/coding-testing.md +72 -0
  12. package/docs/en/dev/switch-matrix.md +10 -0
  13. package/docs/en/glossary.md +97 -0
  14. package/docs/en/harnesses/claude.md +100 -0
  15. package/docs/en/harnesses/codebuddy.md +93 -0
  16. package/docs/en/harnesses/codex.md +88 -0
  17. package/docs/en/harnesses/dsh.md +84 -0
  18. package/docs/en/harnesses/zcode.md +42 -0
  19. package/docs/en/mdcg/ccg.md +32 -0
  20. package/docs/en/mdcg/generated-docs.md +20 -0
  21. package/docs/en/mdcg/guardrail-charter.md +170 -0
  22. package/docs/en/mdcg/mcp-tool-names.md +43 -0
  23. package/docs/en/mdcg/multi-harness.md +43 -0
  24. package/docs/en/mdcg/recall-metadata.md +30 -0
  25. package/docs/en/mdcg/world-model-endpoint.md +379 -0
  26. package/docs/en/mdcg/write-aliases.md +130 -0
  27. package/docs/en/ops/README.md +11 -0
  28. package/docs/en/ops/environment-known-issues.md +244 -0
  29. package/docs/en/ops/install.md +72 -0
  30. package/docs/en/ops/operations-troubleshooting.md +86 -0
  31. package/docs/en/ops/permissions-review.md +79 -0
  32. package/docs/en/ops/release-governance.md +49 -0
  33. package/docs/en/ops/tool-name-migration.md +30 -0
  34. package/docs/en/ops/ui-install-troubleshooting.md +53 -0
  35. package/docs/en/standards/ai-coding-standard-checklist.md +71 -0
  36. package/docs/en/standards/ai-coding-standard-lingshu.md +47 -0
  37. package/docs/en/standards/ai-coding-standard.md +185 -0
  38. package/docs/en/ui/minimal.md +62 -0
  39. package/docs/mdcg/cogmap_ops.md +15 -15
  40. package/lib/hooks.d.ts +22 -0
  41. package/lib/hooks.js +124 -32
  42. package/lib/index.js +19 -3
  43. package/lib/lib/console_web.mjs +30 -3
  44. package/lib/lib/hook_audit.d.ts +3 -2
  45. package/lib/lib/hook_audit.js +14 -4
  46. package/lib/lib/mdcg_client.d.ts +5 -2
  47. package/lib/lib/mdcg_client.js +8 -4
  48. package/lib/lib/prompt_safety.d.ts +24 -0
  49. package/lib/lib/prompt_safety.js +77 -1
  50. package/lib/lib/token_store.js +5 -2
  51. package/lib/tools.js +5 -3
  52. package/md_cg/fsutil.py +80 -25
  53. package/md_cg/mcp_server.py +5761 -5557
  54. package/md_cg/mdcg.py +570 -73
  55. package/md_cg/mdcos.py +36 -11
  56. package/md_cg/nodefile.py +147 -23
  57. package/md_cg/op_table.py +14 -4
  58. package/md_cg/reconcile.py +9 -11
  59. package/md_cg/rollback.py +16 -1
  60. package/md_cg/scrub.py +94 -14
  61. package/md_cg/security.py +4 -2
  62. package/md_cg/test_cond_term_fold.py +183 -0
  63. package/md_cg/test_cond_terms_colon.py +348 -0
  64. package/md_cg/test_generation_guard.py +63 -42
  65. package/md_cg/test_issue362_neg_condition.py +44 -7
  66. package/md_cg/test_issue39_utf8_stdio.py +3 -3
  67. package/md_cg/test_issue444_scrub_evidence_plaintext.py +14 -8
  68. package/md_cg/test_issue677_flush_batch_io.py +139 -0
  69. package/md_cg/test_issue677_info_fast.py +82 -0
  70. package/md_cg/test_issue677_remember_dedupe.py +106 -0
  71. package/md_cg/test_issue712_tokens_sessions_read.py +199 -0
  72. package/md_cg/test_issue722_strict_conditions.py +96 -0
  73. package/md_cg/test_issue730_narrowing_audit.py +121 -0
  74. package/md_cg/test_issue733_verify_override.py +193 -0
  75. package/md_cg/test_issue733_verify_override_and_overwrite_inherit.py +315 -0
  76. package/md_cg/test_issue740_filelock_fd_leak.py +218 -0
  77. package/md_cg/test_issue741_content_hash_same_source.py +158 -0
  78. package/md_cg/test_issue747_slot_contradiction.py +125 -0
  79. package/md_cg/test_issue754_nested_root_guard.py +197 -0
  80. package/md_cg/test_issue757_index_hash_compare.py +85 -0
  81. package/md_cg/test_issue758_disk_hash_single.py +67 -0
  82. package/md_cg/test_issue759_twophase_hash.py +67 -0
  83. package/md_cg/test_n204_n205_n226_n227_n228_n229_exit_gates.py +545 -542
  84. package/md_cg/test_n209_verify_write_face_gates.py +5 -2
  85. package/md_cg/test_neg_condition_hits.py +336 -333
  86. package/md_cg/test_scrub_source_line_false_positive.py +64 -0
  87. package/md_cg/test_twophase.py +286 -286
  88. package/md_cg/tokens.py +55 -7
  89. package/md_cg/twophase.py +15 -6
  90. package/md_cg/writepipe.py +35 -3
  91. package/package.json +137 -134
  92. package/scripts/workspace_index.py +2 -0
  93. package/src/hooks.ts +139 -33
  94. package/src/index.ts +19 -3
  95. package/src/lib/console_web.mjs +30 -3
  96. package/src/lib/hook_audit.ts +15 -5
  97. package/src/lib/mdcg_client.ts +8 -4
  98. package/src/lib/prompt_safety.ts +73 -1
  99. package/src/lib/token_store.ts +5 -2
  100. package/src/tools.ts +5 -3
  101. package/ui/minimal/integrity.json +2 -2
  102. package/ui/minimal/payload/lib/lib/console_web.mjs +30 -3
  103. package/ui/minimal/payload/src/lib/console_web.mjs +30 -3
@@ -55,6 +55,7 @@ import { dirname, join, resolve } from 'node:path'
55
55
  // Python 侧令牌记录落 `<家目录>/.mdcg/_tokens.json`:密钥环被写进插件包目录,
56
56
  // pnpm 更新整目录替换即丢失(下次启动重签新令牌,旧令牌仍在且未吊销)。
57
57
  import { expandHome, pythonPathValue, runRoot } from './datapath.js'
58
+ import { stripLoneSurrogates, truncateSafe } from './prompt_safety.js' // issue #762:错误详情是模型可见文本
58
59
 
59
60
  /** 凭据来源(用于启动日志与故障定位)。 */
60
61
  export type TokenSource =
@@ -223,7 +224,8 @@ function issueToken(python: string, role: string, actor: string, clearance: stri
223
224
  '--tenant', tenant], env)
224
225
  if (r.error) return { error: r.error }
225
226
  if (!r.ok) {
226
- const detail = (r.stderr || r.stdout || '').trim().replace(/\s+/g, ' ').slice(0, 200)
227
+ // issue #762:错误详情可能进工具回执(模型可见)——先清孤代理、再码元安全截断。
228
+ const detail = truncateSafe(stripLoneSurrogates((r.stderr || r.stdout || '').trim().replace(/\s+/g, ' ')), 200)
227
229
  return { error: `md_cg.tokens issue 退出码 ${r.status}${detail ? `:${detail}` : ''}` }
228
230
  }
229
231
  try {
@@ -288,7 +290,8 @@ function checkKeyring(python: string, keyringPath: string, tenant: string,
288
290
  }
289
291
  return { status: 'ok', reason: '', tokenId }
290
292
  }
291
- const detail = (r.stderr || r.stdout || '').trim().replace(/\s+/g, ' ').slice(0, 200)
293
+ // issue #762:错误详情可能进工具回执(模型可见)——先清孤代理、再码元安全截断。
294
+ const detail = truncateSafe(stripLoneSurrogates((r.stderr || r.stdout || '').trim().replace(/\s+/g, ' ')), 200)
292
295
  // 令牌库损坏:`_load` 回落空表后报「令牌不存在」,必须按告警先分出来(N198)。
293
296
  if (/令牌库损坏|令牌库不可读|拒绝整份写回/.test(detail)) {
294
297
  return { status: 'blocked', reason: `令牌库损坏:${detail}` }
package/src/tools.ts CHANGED
@@ -18,7 +18,7 @@ import type { LingshuBridge, McpTool } from './bridge.ts'
18
18
  // 运行时导入写 `.js`(本仓口径:type-only 才写 `.ts`,tsconfig 未开
19
19
  // allowImportingTsExtensions —— 值导入写 `.ts` 会 TS5097 编译失败)。
20
20
  import { attributeSession } from './lib/session_state.js'
21
- import { neutralizeUntrustedBoundary } from './lib/prompt_safety.js'
21
+ import { neutralizeUntrustedBoundary, stripLoneSurrogates, truncateSafe } from './lib/prompt_safety.js'
22
22
 
23
23
  /** 默认暴露的核心工具集合:**记忆面已基元化**,只注册 `cg` / `stg` 两个认知基元。
24
24
  *
@@ -247,9 +247,11 @@ export async function registerLingshuTools(
247
247
  // ②兜底上限(服务端已有 offset 分页,插件层只兜一个远大于单页的硬上限,
248
248
  // 防止一次把整库搬进上下文;截断必须显式标注,不静默)。
249
249
  const raw = extractText((value as McpCallResultLike).content ?? [])
250
- const safe = neutralizeUntrustedBoundary(raw)
250
+ // issue #762:工具返回同样是模型上下文的一部分——半个 emoji 会让宿主
251
+ // JSON.stringify 产出 "\ud83d" ⇒ 整条请求 400。出口先清孤立代理。
252
+ const safe = neutralizeUntrustedBoundary(stripLoneSurrogates(raw))
251
253
  const text = safe.length > TOOL_RENDER_MAX_CHARS
252
- ? safe.slice(0, TOOL_RENDER_MAX_CHARS)
254
+ ? truncateSafe(safe, TOOL_RENDER_MAX_CHARS) // issue #762:不劈代理对
253
255
  + `
254
256
  …[已截断:工具返回超过插件上限 ${TOOL_RENDER_MAX_CHARS} 字符]`
255
257
  : safe
@@ -27,11 +27,11 @@
27
27
  },
28
28
  {
29
29
  "path": "src/lib/console_web.mjs",
30
- "sha256": "9C8F8450571729688033033F35345B18E9EEB68B871E3A4C53A9B619F28AA61E"
30
+ "sha256": "457944C22DBE21B0ABF385D469CFBEF14BE5CFFE9D42B96734E20ADF2B439447"
31
31
  },
32
32
  {
33
33
  "path": "lib/lib/console_web.mjs",
34
- "sha256": "9C8F8450571729688033033F35345B18E9EEB68B871E3A4C53A9B619F28AA61E"
34
+ "sha256": "457944C22DBE21B0ABF385D469CFBEF14BE5CFFE9D42B96734E20ADF2B439447"
35
35
  },
36
36
  {
37
37
  "path": "lib/client.js",
@@ -33,8 +33,12 @@ async function readBody(req) {
33
33
  // 空值被闭包固化,此后每次请求都命中 503「宿主鉴权不可用」,宿主就绪也不会自愈。
34
34
  // 现在改为**每次请求实时取**:服务晚到也能自愈。
35
35
  // 兼容:传的不是函数(旧调用方式/直接给实例)时按常量包裹,行为与旧版一致。
36
- export function createConsoleHandler(mdcg, config, assets, getConnection) {
36
+ // issue #699 第二层(2026-11-04):503 分不清「服务没注入」与「已注册未就绪」。
37
+ // 第 5 参 probeConnection 用 `ctx.get(name, false)` 做诊断:strict=false 时即便 fiber 未就绪
38
+ // 也能看到 impl 存在 ⇒ 可区分 not_injected / not_ready。诊断失败不影响主判据。
39
+ export function createConsoleHandler(mdcg, config, assets, getConnection, probeConnection) {
37
40
  const connectionOf = typeof getConnection === 'function' ? getConnection : () => getConnection
41
+ const probeOf = typeof probeConnection === 'function' ? probeConnection : null
38
42
  const csrf = randomBytes(32).toString('hex');
39
43
  let catalog = null;
40
44
  const tools = async () => catalog ?? (catalog = await mdcg.bridge.listTools());
@@ -42,7 +46,29 @@ export function createConsoleHandler(mdcg, config, assets, getConnection) {
42
46
  try {
43
47
  const path = new URL(req.url, 'http://localhost').pathname;
44
48
  const connection = connectionOf()
45
- if (!connection || typeof connection.admit !== 'function') return reply(res, 503, { error: '宿主鉴权服务尚未就绪,请稍后重试' });
49
+ if (!connection || typeof connection.admit !== 'function') {
50
+ // 三态(#699 复核):not_admit = 服务存在但不提供 admit(服务名撞车/版本不兼容的
51
+ // 唯一可识别指纹);not_injected = 探测到该名字下没有 impl;not_ready = 有 impl 但未就绪。
52
+ // 诊断异常必须可观测(probe_failed),不得默认退回 not_ready 而把「没注入」误报成「未就绪」。
53
+ let reason = connection ? 'not_admit' : 'not_ready'
54
+ if (!connection) {
55
+ try {
56
+ const p = probeOf ? probeOf() : null
57
+ if (p && p.any === false) reason = 'not_injected'
58
+ } catch { reason = 'probe_failed' }
59
+ }
60
+ return reply(res, 503, {
61
+ error: '宿主鉴权服务尚未就绪,请稍后重试',
62
+ reason,
63
+ hint: reason === 'not_injected'
64
+ ? '本插件看不到 connection 服务(inject 声明/服务名不匹配);请把本回执贴到 issue #699'
65
+ : reason === 'not_admit'
66
+ ? 'connection 服务存在但不提供 admit(服务名撞车/版本不兼容);请把本回执贴到 issue #699'
67
+ : reason === 'probe_failed'
68
+ ? '诊断探针异常;请把本回执贴到 issue #699'
69
+ : '服务已注册但尚未就绪;若持续出现请把本回执贴到 issue #699',
70
+ })
71
+ }
46
72
  const admission = connection.admit(req);
47
73
  if ('rejection' in admission) return reply(res, admission.rejection, { error: admission.rejection === 401 ? '未登录,请返回 DSH 登录' : '请求来源不可信' });
48
74
  if (req.method === 'GET' && assets[path]) {
@@ -96,7 +122,8 @@ export function installConsoleWeb(ctx, config, disposers, mdcg) {
96
122
  '/plugins/lingshu/entry.js': [asset('entry.js'), 'application/javascript; charset=utf-8'],
97
123
  };
98
124
  // issue #699:传**取值函数**(每次请求实时取),不再把挂载瞬间的值闭包固化。
99
- const handler = createConsoleHandler(mdcg, config, assets, () => ctx.get('connection'));
125
+ const handler = createConsoleHandler(mdcg, config, assets, () => ctx.get('connection'),
126
+ () => ({ any: !!ctx.get('connection', false) }));
100
127
  for (const path of ['/lingshu', '/lingshu/', '/plugins/lingshu']) disposers.push(web.register({ kind: path === '/plugins/lingshu' ? 'prefix' : 'exact', path, handler }));
101
128
  disposers.push(web.tapIndex(html => html.includes('data-lingshu-entry') ? html : html.replace('</body>', '<script data-lingshu-entry src="/plugins/lingshu/entry.js"></script></body>')));
102
129
  ctx.logger.info('dsh-memory: 极简灵枢控制台已挂载 /lingshu(复用唯一大脑桥)');
@@ -33,8 +33,12 @@ async function readBody(req) {
33
33
  // 空值被闭包固化,此后每次请求都命中 503「宿主鉴权不可用」,宿主就绪也不会自愈。
34
34
  // 现在改为**每次请求实时取**:服务晚到也能自愈。
35
35
  // 兼容:传的不是函数(旧调用方式/直接给实例)时按常量包裹,行为与旧版一致。
36
- export function createConsoleHandler(mdcg, config, assets, getConnection) {
36
+ // issue #699 第二层(2026-11-04):503 分不清「服务没注入」与「已注册未就绪」。
37
+ // 第 5 参 probeConnection 用 `ctx.get(name, false)` 做诊断:strict=false 时即便 fiber 未就绪
38
+ // 也能看到 impl 存在 ⇒ 可区分 not_injected / not_ready。诊断失败不影响主判据。
39
+ export function createConsoleHandler(mdcg, config, assets, getConnection, probeConnection) {
37
40
  const connectionOf = typeof getConnection === 'function' ? getConnection : () => getConnection
41
+ const probeOf = typeof probeConnection === 'function' ? probeConnection : null
38
42
  const csrf = randomBytes(32).toString('hex');
39
43
  let catalog = null;
40
44
  const tools = async () => catalog ?? (catalog = await mdcg.bridge.listTools());
@@ -42,7 +46,29 @@ export function createConsoleHandler(mdcg, config, assets, getConnection) {
42
46
  try {
43
47
  const path = new URL(req.url, 'http://localhost').pathname;
44
48
  const connection = connectionOf()
45
- if (!connection || typeof connection.admit !== 'function') return reply(res, 503, { error: '宿主鉴权服务尚未就绪,请稍后重试' });
49
+ if (!connection || typeof connection.admit !== 'function') {
50
+ // 三态(#699 复核):not_admit = 服务存在但不提供 admit(服务名撞车/版本不兼容的
51
+ // 唯一可识别指纹);not_injected = 探测到该名字下没有 impl;not_ready = 有 impl 但未就绪。
52
+ // 诊断异常必须可观测(probe_failed),不得默认退回 not_ready 而把「没注入」误报成「未就绪」。
53
+ let reason = connection ? 'not_admit' : 'not_ready'
54
+ if (!connection) {
55
+ try {
56
+ const p = probeOf ? probeOf() : null
57
+ if (p && p.any === false) reason = 'not_injected'
58
+ } catch { reason = 'probe_failed' }
59
+ }
60
+ return reply(res, 503, {
61
+ error: '宿主鉴权服务尚未就绪,请稍后重试',
62
+ reason,
63
+ hint: reason === 'not_injected'
64
+ ? '本插件看不到 connection 服务(inject 声明/服务名不匹配);请把本回执贴到 issue #699'
65
+ : reason === 'not_admit'
66
+ ? 'connection 服务存在但不提供 admit(服务名撞车/版本不兼容);请把本回执贴到 issue #699'
67
+ : reason === 'probe_failed'
68
+ ? '诊断探针异常;请把本回执贴到 issue #699'
69
+ : '服务已注册但尚未就绪;若持续出现请把本回执贴到 issue #699',
70
+ })
71
+ }
46
72
  const admission = connection.admit(req);
47
73
  if ('rejection' in admission) return reply(res, admission.rejection, { error: admission.rejection === 401 ? '未登录,请返回 DSH 登录' : '请求来源不可信' });
48
74
  if (req.method === 'GET' && assets[path]) {
@@ -96,7 +122,8 @@ export function installConsoleWeb(ctx, config, disposers, mdcg) {
96
122
  '/plugins/lingshu/entry.js': [asset('entry.js'), 'application/javascript; charset=utf-8'],
97
123
  };
98
124
  // issue #699:传**取值函数**(每次请求实时取),不再把挂载瞬间的值闭包固化。
99
- const handler = createConsoleHandler(mdcg, config, assets, () => ctx.get('connection'));
125
+ const handler = createConsoleHandler(mdcg, config, assets, () => ctx.get('connection'),
126
+ () => ({ any: !!ctx.get('connection', false) }));
100
127
  for (const path of ['/lingshu', '/lingshu/', '/plugins/lingshu']) disposers.push(web.register({ kind: path === '/plugins/lingshu' ? 'prefix' : 'exact', path, handler }));
101
128
  disposers.push(web.tapIndex(html => html.includes('data-lingshu-entry') ? html : html.replace('</body>', '<script data-lingshu-entry src="/plugins/lingshu/entry.js"></script></body>')));
102
129
  ctx.logger.info('dsh-memory: 极简灵枢控制台已挂载 /lingshu(复用唯一大脑桥)');