@ssamurias/dsh-fish 1.1.0 → 1.1.2

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 (44) hide show
  1. package/AGENTS.md +377 -367
  2. package/CHANGELOG.md +234 -0
  3. package/README.md +417 -377
  4. package/RELEASE-NOTES-1.1.1.md +61 -0
  5. package/RELEASE-NOTES-1.1.2.md +103 -0
  6. package/docs/troubleshooting.md +24 -4
  7. package/docs//350/256/244/344/272/272/345/210/244/346/215/256.md +33 -5
  8. package/lib/bridgeclaim.js +158 -0
  9. package/lib/claim.js +183 -13
  10. package/lib/client/01-state-load.js +30 -3
  11. package/lib/client/06-tab-status-grow.js +12 -1
  12. package/lib/client/08-tab-memory-plugins.js +675 -755
  13. package/lib/client/11-tab-data-frame.js +3 -1
  14. package/lib/client.js +58 -98
  15. package/lib/compact.js +28 -7
  16. package/lib/derive.js +6 -1
  17. package/lib/drive.js +7 -4
  18. package/lib/identity.js +53 -27
  19. package/lib/index.js +9 -4
  20. package/lib/log.js +1 -1
  21. package/lib/mapserve.js +132 -0
  22. package/lib/markup.js +32 -13
  23. package/lib/memorymap-html.js +2 -0
  24. package/lib/memorymap.js +456 -0
  25. package/lib/meta.js +2 -1
  26. package/lib/observe-home.js +58 -3
  27. package/lib/observe-state.js +19 -1
  28. package/lib/observe.js +31 -2
  29. package/lib/persona.js +32 -7
  30. package/lib/proactive.js +57 -1
  31. package/lib/restrict.js +58 -18
  32. package/lib/say.js +76 -28
  33. package/lib/scheduler.js +17 -5
  34. package/lib/scrub.js +10 -5
  35. package/lib/settings.js +20 -0
  36. package/lib/tenant.js +21 -4
  37. package/lib/transcript.js +12 -2
  38. package/lib/turns.js +50 -4
  39. package/lib/types.d.ts +9 -0
  40. package/lib/use.js +3 -3
  41. package/lib/wiki.js +14 -2
  42. package/package.json +1 -1
  43. package/scripts/build-client.mjs +15 -1
  44. package/tools/check-install.mjs +64 -23
@@ -0,0 +1,132 @@
1
+ /**
2
+ * 记忆图的出口:一个只在本机回环上的小 HTTP 服务(2026-11-26 用户 m03077)。
3
+ *
4
+ * 和 wikiserve.js 同一个理由:宿主对 http(s) 一律 openExternal + deny,
5
+ * 而信任栅栏要的 cookie 只有 App 自己的 webContents 带着。想要「点一下就
6
+ * 在浏览器里看」,只能自己起一个只监听回环、只认 GET、只吐一份 HTML 的服务。
7
+ *
8
+ * 端口写死 17322(wiki 是 17321,别撞)。被占了就退回系统分配的随机端口。
9
+ */
10
+ import { createServer } from 'node:http'
11
+
12
+ const HOST = '127.0.0.1'
13
+ const DEFAULT_PORT = 17322
14
+
15
+ let STATE = null
16
+
17
+ function hostOk(raw, port) {
18
+ const h = String(raw || '').trim().toLowerCase()
19
+ return h === `${HOST}:${port}` || h === `localhost:${port}`
20
+ }
21
+
22
+ function send(res, code, headers, body) {
23
+ res.writeHead(code, headers)
24
+ res.end(body)
25
+ }
26
+
27
+ function plain(res, code, text) {
28
+ const body = Buffer.from(text, 'utf8')
29
+ send(res, code, {
30
+ 'content-type': 'text/plain; charset=utf-8',
31
+ 'content-length': body.length,
32
+ 'cache-control': 'no-store',
33
+ }, body)
34
+ }
35
+
36
+ /**
37
+ * 起服务。可重复调用:已经在跑就只把新的 getHtml 换上。
38
+ * @param {{getHtml: () => string | Promise<string>, port?: number}} opts
39
+ */
40
+ export function startMapServer(opts = {}) {
41
+ const getHtml = typeof opts.getHtml === 'function' ? opts.getHtml : () => '<!doctype html><meta charset="utf-8"><p>记忆图还没准备好。</p>'
42
+ if (STATE) {
43
+ STATE.getHtml = getHtml
44
+ return api(STATE)
45
+ }
46
+
47
+ const st = { getHtml, port: 0, url: '', server: null, triedFallback: false }
48
+
49
+ const server = createServer(async (req, res) => {
50
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
51
+ plain(res, 405, '只读。')
52
+ return
53
+ }
54
+ if (!hostOk(req.headers.host, st.port)) {
55
+ plain(res, 403, '不认这个地址。')
56
+ return
57
+ }
58
+ let path = '/'
59
+ try { path = new URL(req.url || '/', 'http://127.0.0.1').pathname } catch { path = '/' }
60
+ if (path !== '/' && path !== '/map' && path !== '/map.html') {
61
+ plain(res, 404, '没有这一页。')
62
+ return
63
+ }
64
+ let html = ''
65
+ try {
66
+ html = await st.getHtml()
67
+ } catch (err) {
68
+ plain(res, 500, `这张图没读出来:${err?.message ?? err}`)
69
+ return
70
+ }
71
+ const body = Buffer.from(String(html), 'utf8')
72
+ send(res, 200, {
73
+ 'content-type': 'text/html; charset=utf-8',
74
+ 'content-length': body.length,
75
+ 'cache-control': 'no-store',
76
+ 'x-content-type-options': 'nosniff',
77
+ 'referrer-policy': 'no-referrer',
78
+ }, req.method === 'HEAD' ? undefined : body)
79
+ })
80
+ st.server = server
81
+
82
+ server.on('error', (err) => {
83
+ if (err?.code === 'EADDRINUSE' && !st.triedFallback) {
84
+ st.triedFallback = true
85
+ try { server.listen(0, HOST) } catch { /* 下一层还有 error 事件 */ }
86
+ return
87
+ }
88
+ console.warn('[dsh-fish] 记忆图服务起不来', err?.message ?? err)
89
+ })
90
+ server.on('listening', () => {
91
+ const addr = server.address()
92
+ st.port = typeof addr === 'object' && addr ? addr.port : 0
93
+ st.url = `http://${HOST}:${st.port}/`
94
+ })
95
+ server.unref?.()
96
+
97
+ const wanted = Number.isInteger(opts.port) && opts.port >= 0 ? opts.port : DEFAULT_PORT
98
+ try { server.listen(wanted, HOST) } catch (err) {
99
+ console.warn('[dsh-fish] 记忆图服务起不来', err?.message ?? err)
100
+ }
101
+
102
+ STATE = st
103
+ return api(st)
104
+ }
105
+
106
+ function api(st) {
107
+ return {
108
+ /** 起来之前是空串。UI 那一头拿到空串就显示「正在准备」。 */
109
+ get url() { return st.url },
110
+ get port() { return st.port },
111
+ close() {
112
+ if (STATE === st) STATE = null
113
+ try { st.server?.close() } catch { /* 已经关了 */ }
114
+ st.url = ''
115
+ },
116
+ }
117
+ }
118
+
119
+ /** 给界面用:现取,不缓存。 */
120
+ export function mapUrl() {
121
+ return STATE?.url || ''
122
+ }
123
+
124
+ export function closeMapServer() {
125
+ const st = STATE
126
+ STATE = null
127
+ if (!st) return
128
+ try { st.server?.close() } catch { /* 已经关了 */ }
129
+ st.url = ''
130
+ }
131
+
132
+ export const MAP_PORT = DEFAULT_PORT
package/lib/markup.js CHANGED
@@ -29,6 +29,11 @@
29
29
  * 带 invoke 头 + 多参数的那种还会把参数名剥进正文(`add</parameter>`)。现在改成
30
30
  * **按配对扫参数段**:任意位置认 `<parameter name=…>…</parameter>`,只取 `name="text"`
31
31
  * 那一段的字,别的参数与 invoke/calls 外壳一并丢掉;收尾没闭合的仍然一律不动。
32
+ *
33
+ * 2026-11-26(issue #166 第三轮,外部报告 @mxc881031 复测):A–G 七条在记录层
34
+ * (`stripToolMarkup` / `stripLeakedToolSyntax`)已经全干净,只剩 `stripToolShell`
35
+ * 自己对 F 仍原样返回——三个函数对同一段给出两个答案。这里把 F 也收进配对扫:
36
+ * 开标签被 DSML 残标打断时先补回 `<`,仍然认不出 `text` 段就按原样返回。
32
37
  */
33
38
 
34
39
  /**
@@ -62,6 +67,19 @@ export function hasToolMarkup(text) {
62
67
  return CORE.test(String(text ?? ''))
63
68
  }
64
69
 
70
+ /** 把 `SHELL_PAIR` 扫一遍,按出现顺序返回 `{ name, start, end, inner }`(不 splice)。 */
71
+ function scanShellPairs(source) {
72
+ SHELL_PAIR.lastIndex = 0
73
+ const pairs = []
74
+ let m
75
+ while ((m = SHELL_PAIR.exec(source)) !== null) {
76
+ const name = (m[1] ?? m[2] ?? m[3] ?? '').trim().toLowerCase()
77
+ pairs.push({ name, start: m.index, end: m.index + m[0].length, inner: m[4] })
78
+ if (m[0].length === 0) SHELL_PAIR.lastIndex += 1
79
+ }
80
+ return pairs
81
+ }
82
+
65
83
  /**
66
84
  * 剥掉漏进正文的参数壳,留下她真说的话;认不出参数段就原样返回(不加 trim)。
67
85
  *
@@ -70,6 +88,8 @@ export function hasToolMarkup(text) {
70
88
  * - 外面可能还裹着 `<invoke name="…">` / `</invoke>` / `</calls>` / `<function_calls>`
71
89
  * - 一个调用里多个参数时,只留 `text` 那段;别的参数(`action`、`title`…)连同标签丢掉
72
90
  * - 收尾后只剩标点的(`</invoke>。`)一起吸收
91
+ * - 开标签被 DSML 残标打断了 `<` 的(`<||DSML|| parameter name="text">`),
92
+ * 补回那一笔再按配对扫(issue #166 的 F,2026-11-26)
73
93
  *
74
94
  * 不动的形状:收尾没闭合的、正文中间提到 `<parameter>` 而没写 `</parameter>` 的
75
95
  * ——宁可漏判,不可把她真说的话切掉。
@@ -78,27 +98,26 @@ export function hasToolMarkup(text) {
78
98
  * @returns {string}
79
99
  */
80
100
  export function stripToolShell(text) {
81
- const raw = String(text ?? '')
82
- if (!raw || !/parameter/i.test(raw)) return raw
83
- SHELL_PAIR.lastIndex = 0
84
- const pairs = []
85
- let m
86
- while ((m = SHELL_PAIR.exec(raw)) !== null) {
87
- const name = (m[1] ?? m[2] ?? m[3] ?? '').trim().toLowerCase()
88
- pairs.push({ name, start: m.index, end: m.index + m[0].length, inner: m[4] })
89
- if (m[0].length === 0) SHELL_PAIR.lastIndex += 1
90
- }
91
- if (!pairs.length) return raw
101
+ const original = String(text ?? '')
102
+ if (!original || !/parameter/i.test(original)) return original
103
+ // issue #166 的 F(2026-11-26):`<||DSML|| parameter name="text">…` 这种开标签
104
+ // 比参数段少了 `<` 这一笔,配对扫认不出来。只把这一笔补回去,别的字符不动;
105
+ // 补完仍然认不出 `text` 段就按原样返回——那种是 DSML 形态的调用体,不该当正文。
106
+ const source = original.replace(/<||DSML||\s*(?=parameter\b)/gi, '<')
107
+ const normalized = source !== original
108
+ const pairs = scanShellPairs(source)
109
+ if (!pairs.length) return original
110
+ if (normalized && !pairs.some((p) => p.name === 'text')) return original
92
111
 
93
112
  let out = ''
94
113
  let cursor = 0
95
114
  for (const p of pairs) {
96
- out += raw.slice(cursor, p.start)
115
+ out += source.slice(cursor, p.start)
97
116
  // 只有 `text` 是她要说的话;其余参数是调用的一部分,不该进正文。
98
117
  if (p.name === 'text') out += p.inner
99
118
  cursor = p.end
100
119
  }
101
- let tail = raw.slice(cursor).replace(SHELL_TAGS, '')
120
+ let tail = source.slice(cursor).replace(SHELL_TAGS, '')
102
121
  // `</invoke>` 后面跟一个句号的那种:那是壳的尾巴,不是她又说了一句。
103
122
  if (SHELL_TAIL.test(tail)) tail = ''
104
123
  out += tail