dsh-tiddlywiki 0.27.2 → 0.28.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 (41) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +3 -0
  3. package/cordis.patch.yml +13 -13
  4. package/docs/CHANGELOG.md +2 -1
  5. package/docs/code-review-2026-09-17.md +151 -0
  6. package/docs/features.md +5 -2
  7. package/docs/usage.md +34 -3
  8. package/docs/wiki-split.md +97 -0
  9. package/lib/client.js +54 -27
  10. package/lib/index.js +2803 -517
  11. package/lib/index.js.map +1 -1
  12. package/package.json +5 -4
  13. package/skills/wiki-split/SKILL.md +106 -0
  14. package/src/client/endpoints.ts +37 -0
  15. package/src/client/index.ts +14 -0
  16. package/src/client/knowledge-fab.ts +62 -3
  17. package/src/client/markdown-editor.ts +128 -128
  18. package/src/client/panel.ts +2 -1
  19. package/src/client/settings-page.ts +217 -3
  20. package/src/client/state.ts +39 -39
  21. package/src/client/status-cache.ts +17 -0
  22. package/src/client/styles.ts +27 -0
  23. package/src/client/toast.ts +22 -22
  24. package/src/client/tw-frame.ts +28 -4
  25. package/src/client/wiki-focus.ts +70 -0
  26. package/src/client/wiki-scope-dock.ts +116 -0
  27. package/src/host/admin.ts +175 -35
  28. package/src/host/git.ts +50 -5
  29. package/src/host/path-key.ts +35 -0
  30. package/src/host/prompt.ts +24 -0
  31. package/src/host/repo-committers.ts +149 -0
  32. package/src/host/routes.ts +254 -81
  33. package/src/host/seeds.ts +51 -10
  34. package/src/host/session-scope.ts +154 -0
  35. package/src/host/skill-install.ts +121 -0
  36. package/src/host/tools.ts +141 -49
  37. package/src/host/wiki-farm.ts +417 -0
  38. package/src/host/wiki-instance.ts +596 -0
  39. package/src/host/wiki-registry.ts +601 -0
  40. package/src/host/wiki.ts +19 -0
  41. package/src/index.ts +686 -459
package/src/host/tools.ts CHANGED
@@ -65,17 +65,51 @@ export interface ToolsCtx {
65
65
  tools: { register(tool: unknown): () => void }
66
66
  }
67
67
 
68
+ /**
69
+ * What one tool call may act on (v0.28.0).
70
+ *
71
+ * `ambiguous` is true when MORE THAN ONE knowledge base is visible to the agent:
72
+ * only then does every tool result carry a 「知识库:…」 header, so a single-wiki
73
+ * install keeps byte-identical output while a multi-wiki one always says which
74
+ * base a result came from (writing to the wrong one is the failure this feature
75
+ * most needs to make visible).
76
+ */
77
+ export interface ToolScope {
78
+ /** Live TW client of the resolved wiki (undefined = cannot serve). */
79
+ client?: TiddlyWebClient
80
+ /** Id + display label of the resolved wiki. */
81
+ id?: string
82
+ label?: string
83
+ /** Actionable sentence for the tool error when there is no client. */
84
+ reason?: string
85
+ /** More than one visible wiki ⇒ results must name the one they used. */
86
+ ambiguous: boolean
87
+ }
88
+
68
89
  export interface ToolsDeps {
69
- /** Lazy TW client — undefined while the service is not up. */
70
- wiki: () => TiddlyWebClient | undefined
90
+ /**
91
+ * The knowledge base a tool call acts on, resolved per SESSION (v0.28.0).
92
+ *
93
+ * `sessionId` is the calling session (`sessionIdOf(exec)`), or undefined in
94
+ * headless tests. The host resolves it through the session's scope, filtered
95
+ * by `agentVisible`, and returns a REASON instead of a client when it cannot
96
+ * serve — the tool then fails loudly rather than writing to another wiki.
97
+ */
98
+ scope: (sessionId: string | undefined) => ToolScope
71
99
  git: GitFace
72
100
  wikiPath: () => string
73
101
  /** Debounced auto-commit touch (fires after our writes). */
74
102
  autoCommit: () => void
75
- /** Restart the TW child (same port). Called after a pull that changed the
76
- * working tree, so the server drops its stale in-memory snapshot and the
77
- * agent sees the pulled content. Optional — absent in headless contexts. */
78
- restartWiki?: () => Promise<void>
103
+ /**
104
+ * After a pull moved HEAD: restart the running wikis whose CONTENT changed and
105
+ * report their ids (v0.28.0).
106
+ *
107
+ * `dir` is the folder the pull ran in (the repo is resolved from it) and
108
+ * `changedFiles` are the repository-relative paths the pull touched. Several
109
+ * wikis may share one repository, so "the pull changed something" is NOT the
110
+ * same question as "this wiki needs a restart".
111
+ */
112
+ restartAffected?: (dir: string, changedFiles: readonly string[]) => Promise<{ restarted: string[]; failed: Array<{ id: string; message: string }> }>
79
113
  /**
80
114
  * Workspace (project) name for a session, resolved from its cwd (v0.24.0).
81
115
  * Absent in headless contexts → no automatic workspace marking.
@@ -456,6 +490,49 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
456
490
  // Re-collect on every pass: a hot reload re-registers the whole toolset, and
457
491
  // a stale entry must never linger in the prompt catalogue.
458
492
  REGISTERED_TOOL_SUMMARY.length = 0
493
+
494
+ /** A registered tool plus the two members the scope wrapper needs. */
495
+ interface WrappableTool extends RegistrableTool {
496
+ execute?: (args: unknown, exec: unknown) => Promise<unknown>
497
+ output?: { render?: (args: unknown, value: unknown) => Array<{ type: 'text'; text: string }> }
498
+ }
499
+
500
+ /**
501
+ * Give EVERY tool result a 「知识库:…」 header — but only when more than one
502
+ * knowledge base is visible to the agent (v0.28.0).
503
+ *
504
+ * Done HERE, once, instead of inside 15 renders: a tool result is the only
505
+ * place the model can learn WHICH knowledge base it just wrote to, and "wrote
506
+ * into the wrong wiki" is the failure this feature most needs to make visible.
507
+ * With a single visible wiki (`ambiguous === false`) the output stays
508
+ * byte-identical to before, so existing installs see no change at all.
509
+ */
510
+ const withScopeHeader = (tool: WrappableTool): WrappableTool => {
511
+ const render = tool.output?.render
512
+ const execute = tool.execute
513
+ if (render === undefined || execute === undefined) return tool
514
+ return {
515
+ ...tool,
516
+ async execute(args: unknown, exec: unknown): Promise<unknown> {
517
+ const scope = deps.scope(sessionIdOf(exec))
518
+ const value = await execute(args, exec)
519
+ if (!scope.ambiguous || scope.id === undefined) return value
520
+ if (value === null || typeof value !== 'object') return value
521
+ return { ...(value as Record<string, unknown>), wiki: { id: scope.id, label: scope.label ?? scope.id } }
522
+ },
523
+ output: {
524
+ ...tool.output,
525
+ render(args: unknown, value: unknown): Array<{ type: 'text'; text: string }> {
526
+ const lines = render(args, value)
527
+ const wiki = (value as { wiki?: { id: string; label: string } } | null)?.wiki
528
+ if (wiki === undefined || lines.length === 0) return lines
529
+ const [first, ...rest] = lines
530
+ return [{ ...(first as { type: 'text'; text: string }), text: `【知识库:${wiki.label}(${wiki.id})】\n${(first as { text: string }).text}` }, ...rest]
531
+ },
532
+ },
533
+ }
534
+ }
535
+
459
536
  const register = (tool: RegistrableTool): void => {
460
537
  const properties = (tool.parameters.properties ?? {}) as Record<string, unknown>
461
538
  const required = Array.isArray(tool.parameters.required) ? (tool.parameters.required as string[]) : []
@@ -463,15 +540,15 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
463
540
  name: tool.name,
464
541
  params: Object.keys(properties).map((name) => ({ name, required: required.includes(name) })),
465
542
  })
466
- disposers.push(ctx.tools.register(tool))
543
+ disposers.push(ctx.tools.register(withScopeHeader(tool) as never))
467
544
  }
468
545
 
469
546
  /** Every read/write tool needs a live TW client — shared guard for the 8
470
547
  * wiki-facing tools (git tools operate on the repo path instead). */
471
- const requireWiki = (): TiddlyWebClient => {
472
- const wiki = deps.wiki()
473
- if (wiki === undefined) throw new Error('TiddlyWiki 服务未运行(tiddlywiki_status 可查)')
474
- return wiki
548
+ const requireWiki = (sessionId?: string): TiddlyWebClient => {
549
+ const scope = deps.scope(sessionId)
550
+ if (scope.client === undefined) throw new Error(scope.reason ?? 'TiddlyWiki 服务未运行(tiddlywiki_status 可查)')
551
+ return scope.client
475
552
  }
476
553
 
477
554
  // ── tiddlywiki_search ────────────────────────────────────────────────────
@@ -518,7 +595,7 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
518
595
  },
519
596
  },
520
597
  execute: async (args: { query: string; tags?: string[]; tag?: string; since?: string; type?: string; field?: string; value?: string; limit?: number }, exec: unknown): Promise<SearchResult> => {
521
- const wiki = requireWiki()
598
+ const wiki = requireWiki(sessionIdOf(exec))
522
599
  const options = {
523
600
  tags: args.tags,
524
601
  tag: args.tag,
@@ -577,8 +654,8 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
577
654
  return [{ type: 'text', text: lines.join('\n') }]
578
655
  },
579
656
  },
580
- execute: async (args: { limit?: number; since?: string }): Promise<RecentResult> => {
581
- const wiki = requireWiki()
657
+ execute: async (args: { limit?: number; since?: string }, exec: unknown): Promise<RecentResult> => {
658
+ const wiki = requireWiki(sessionIdOf(exec))
582
659
  const items = await wiki.recent(args.limit ?? 15, args.since)
583
660
  return {
584
661
  since: args.since ?? null,
@@ -607,8 +684,8 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
607
684
  return [{ type: 'text', text: lines.join('\n') }]
608
685
  },
609
686
  },
610
- execute: async (args: { limit?: number }): Promise<TagListResult> => {
611
- const wiki = requireWiki()
687
+ execute: async (args: { limit?: number }, exec: unknown): Promise<TagListResult> => {
688
+ const wiki = requireWiki(sessionIdOf(exec))
612
689
  const stats = await wiki.tagStats()
613
690
  const limit = typeof args.limit === 'number' && Number.isFinite(args.limit)
614
691
  ? Math.max(1, Math.min(Math.floor(args.limit), 1000))
@@ -647,8 +724,8 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
647
724
  return [{ type: 'text', text: lines.join('\n') }]
648
725
  },
649
726
  },
650
- execute: async (args: { title: string }): Promise<GetResult> => {
651
- const wiki = requireWiki()
727
+ execute: async (args: { title: string }, exec: unknown): Promise<GetResult> => {
728
+ const wiki = requireWiki(sessionIdOf(exec))
652
729
  const t = await wiki.get(args.title)
653
730
  if (t === undefined) return { notFound: true, title: args.title, text: '', tags: [], fields: {}, modified: null }
654
731
  const binary = isBinaryType(typeof t.type === 'string' ? t.type : undefined)
@@ -702,7 +779,7 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
702
779
  },
703
780
  },
704
781
  execute: async (args: { title: string; text: string; tags?: string[]; fields?: Record<string, unknown>; expectedModified?: string; expectedRevision?: number; force?: boolean }, exec: unknown): Promise<PutResult> => {
705
- const wiki = requireWiki()
782
+ const wiki = requireWiki(sessionIdOf(exec))
706
783
  if (args.title.trim().length === 0) throw new Error('tiddlywiki_put: title 不能为空')
707
784
  // Read WITHOUT swallowing errors: only a 404 means "new tiddler". A
708
785
  // transient failure treated as "new" would silently tag an existing
@@ -790,7 +867,7 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
790
867
  },
791
868
  },
792
869
  execute: async (args: { items: Array<{ title: string; text: string; tags?: string[]; fields?: Record<string, unknown>; expectedModified?: string }>; overwrite?: boolean }, exec: unknown): Promise<BatchResult> => {
793
- const wiki = requireWiki()
870
+ const wiki = requireWiki(sessionIdOf(exec))
794
871
  const list = Array.isArray(args.items) ? args.items : []
795
872
  if (list.length === 0) return { ok: true, written: 0, skipped: 0, failed: 0, items: [] }
796
873
  const overwrite = args.overwrite !== false
@@ -874,8 +951,8 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
874
951
  return [{ type: 'text', text: lines.join('\n') }]
875
952
  },
876
953
  },
877
- execute: async (args: { oldTitle: string; newTitle: string; updateRefs?: boolean; expectedModified?: string; expectedRevision?: number; force?: boolean }): Promise<RenameResult> => {
878
- const wiki = requireWiki()
954
+ execute: async (args: { oldTitle: string; newTitle: string; updateRefs?: boolean; expectedModified?: string; expectedRevision?: number; force?: boolean }, exec: unknown): Promise<RenameResult> => {
955
+ const wiki = requireWiki(sessionIdOf(exec))
879
956
  const { oldTitle, newTitle } = args
880
957
  if (oldTitle === newTitle) return { ok: true, from: oldTitle, to: newTitle, refsUpdated: 0, refsTiddlers: 0 }
881
958
  const existing = await wiki.get(oldTitle)
@@ -982,8 +1059,8 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
982
1059
  : `已永久删除 tiddler「${value.title}」。`,
983
1060
  }],
984
1061
  },
985
- execute: async (args: { title: string; permanent?: boolean; expectedModified?: string; expectedRevision?: number; force?: boolean }): Promise<DeleteResult> => {
986
- const wiki = requireWiki()
1062
+ execute: async (args: { title: string; permanent?: boolean; expectedModified?: string; expectedRevision?: number; force?: boolean }, exec: unknown): Promise<DeleteResult> => {
1063
+ const wiki = requireWiki(sessionIdOf(exec))
987
1064
  const existing = await wiki.get(args.title)
988
1065
  // Deleting something the caller never saw is fine only when it does not
989
1066
  // exist; a token means the note WAS read, so a changed revision since then
@@ -1066,8 +1143,8 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
1066
1143
  return [{ type: 'text', text: lines.join('\n') }]
1067
1144
  },
1068
1145
  },
1069
- execute: async (args: { action: 'list' | 'restore' | 'empty'; title?: string; limit?: number }): Promise<TrashResult> => {
1070
- const wiki = requireWiki()
1146
+ execute: async (args: { action: 'list' | 'restore' | 'empty'; title?: string; limit?: number }, exec: unknown): Promise<TrashResult> => {
1147
+ const wiki = requireWiki(sessionIdOf(exec))
1071
1148
  const index = await readTrashIndex(wiki)
1072
1149
  // A failed/corrupt index must never be treated as「回收站是空的」: `empty`
1073
1150
  // would then report success while doing nothing, and `restore` would claim
@@ -1158,7 +1235,7 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
1158
1235
  },
1159
1236
  },
1160
1237
  execute: async (args: { title: string; text: string; mode?: 'append' | 'prepend'; heading?: string; createIfMissing?: boolean; tags?: string[]; fields?: Record<string, unknown>; expectedModified?: string; expectedRevision?: number; force?: boolean }, exec: unknown): Promise<AppendResult> => {
1161
- const wiki = requireWiki()
1238
+ const wiki = requireWiki(sessionIdOf(exec))
1162
1239
  const title = args.title.trim()
1163
1240
  if (title.length === 0) throw new Error('tiddlywiki_append: title 不能为空')
1164
1241
  const existing = await wiki.get(title)
@@ -1248,8 +1325,8 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
1248
1325
  return [{ type: 'text', text: lines.join('\n') }]
1249
1326
  },
1250
1327
  },
1251
- execute: async (args: { title: string; includeTags?: boolean; limit?: number }): Promise<BacklinkResult> => {
1252
- const wiki = requireWiki()
1328
+ execute: async (args: { title: string; includeTags?: boolean; limit?: number }, exec: unknown): Promise<BacklinkResult> => {
1329
+ const wiki = requireWiki(sessionIdOf(exec))
1253
1330
  const target = args.title.trim()
1254
1331
  if (target.length === 0) throw new Error('tiddlywiki_backlinks: title 不能为空')
1255
1332
  const includeTags = args.includeTags !== false
@@ -1295,8 +1372,8 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
1295
1372
  return [{ type: 'text', text: lines.join('\n') }]
1296
1373
  },
1297
1374
  },
1298
- execute: async (args: { title: string; path?: string; url?: string; tags?: string[]; noteTitle?: string; expectedModified?: string; expectedRevision?: number; force?: boolean }): Promise<AttachResult> => {
1299
- const wiki = requireWiki()
1375
+ execute: async (args: { title: string; path?: string; url?: string; tags?: string[]; noteTitle?: string; expectedModified?: string; expectedRevision?: number; force?: boolean }, exec: unknown): Promise<AttachResult> => {
1376
+ const wiki = requireWiki(sessionIdOf(exec))
1300
1377
  const title = args.title.trim()
1301
1378
  if (title.length === 0) throw new Error('tiddlywiki_attach: title 不能为空')
1302
1379
  const hasPath = typeof args.path === 'string' && args.path.trim().length > 0
@@ -1423,8 +1500,8 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
1423
1500
  return [{ type: 'text', text: lines.join('\n') }]
1424
1501
  },
1425
1502
  },
1426
- execute: async (args: { limit?: number; checks?: string[]; staleAfterDays?: number }): Promise<LintResult> => {
1427
- const wiki = requireWiki()
1503
+ execute: async (args: { limit?: number; checks?: string[]; staleAfterDays?: number }, exec: unknown): Promise<LintResult> => {
1504
+ const wiki = requireWiki(sessionIdOf(exec))
1428
1505
  const limit = Math.max(1, Math.min(args.limit ?? 10, 100))
1429
1506
  // Validate `checks` against the real list (v0.25.0). The old `new Set(checks)`
1430
1507
  // silently ignored an unknown name, so a typo ('broken-link') ran NO checks
@@ -1595,11 +1672,19 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
1595
1672
  output: {
1596
1673
  render: (_args, value: SyncResult) => renderSync(value),
1597
1674
  },
1598
- execute: async (args: { action: 'pull' | 'push' | 'sync'; message?: string }): Promise<SyncResult> => {
1675
+ execute: async (args: { action: 'pull' | 'push' | 'sync'; message?: string }, exec: unknown): Promise<SyncResult> => {
1599
1676
  const dir = deps.wikiPath()
1600
- /** Restart TW after a pull that changed the tree (stale snapshot drop). */
1601
- const restartIfChanged = async (pulled: { changed?: boolean }): Promise<{ restarted?: boolean; restartError?: string }> => {
1602
- if (pulled.changed !== true || deps.restartWiki === undefined) return {}
1677
+ /**
1678
+ * Restart the RUNNING wikis whose content this pull changed.
1679
+ *
1680
+ * `changedFiles` is what makes this correct with several knowledge bases in
1681
+ * one repository: restarting "the wiki I happened to pull from" would miss
1682
+ * the one that actually changed, and would interrupt a wiki nothing
1683
+ * happened to (v0.28.0).
1684
+ */
1685
+ const restartIfChanged = async (pulled: { changed?: boolean; changedFiles?: string[] }): Promise<{ restarted?: string[]; restartFailed?: Array<{ id: string; message: string }> }> => {
1686
+ if (pulled.changed !== true) return {}
1687
+ if (deps.restartAffected === undefined) return {}
1603
1688
  try {
1604
1689
  // DRAIN THE SYNCER FIRST (v0.19.1, data safety): a PUT answers 204 as
1605
1690
  // soon as the tiddler is in TW's in-memory store; the filesystem
@@ -1608,11 +1693,14 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
1608
1693
  // note is gone — not even the git commit that follows can recover it).
1609
1694
  // The agent path is the risky one: `tiddlywiki_put` → `git_sync`
1610
1695
  // back-to-back. Same sentinel trick as seeds.ts / index.ts.
1611
- await flushPendingWrites(requireWiki(), join(dir, 'tiddlers')).catch(() => undefined)
1612
- await deps.restartWiki()
1613
- return { restarted: true }
1696
+ await flushPendingWrites(requireWiki(sessionIdOf(exec)), join(dir, 'tiddlers')).catch(() => undefined)
1697
+ const outcome = await deps.restartAffected(dir, pulled.changedFiles ?? [])
1698
+ return {
1699
+ ...(outcome.restarted.length > 0 ? { restarted: outcome.restarted } : {}),
1700
+ ...(outcome.failed.length > 0 ? { restartFailed: outcome.failed } : {}),
1701
+ }
1614
1702
  } catch (err) {
1615
- return { restartError: err instanceof Error ? err.message : String(err) }
1703
+ return { restartFailed: [{ id: '(全部)', message: err instanceof Error ? err.message : String(err) }] }
1616
1704
  }
1617
1705
  }
1618
1706
  switch (args.action) {
@@ -1677,7 +1765,7 @@ export function registerTiddlywikiTools(ctx: ToolsCtx, deps: ToolsDeps): Array<(
1677
1765
  return [{ type: 'text', text: lines.join('\n') }]
1678
1766
  },
1679
1767
  },
1680
- execute: async (args: { strategy: 'keep-local' | 'keep-remote' | 'list'; files?: string[] }): Promise<ResolveResult> => {
1768
+ execute: async (args: { strategy: 'keep-local' | 'keep-remote' | 'list'; files?: string[] }, exec: unknown): Promise<ResolveResult> => {
1681
1769
  const dir = deps.wikiPath()
1682
1770
  if (args.strategy === 'list') {
1683
1771
  const status = await deps.git.status(dir)
@@ -1772,8 +1860,10 @@ interface SyncResult {
1772
1860
  commit?: string
1773
1861
  push?: string
1774
1862
  changed?: boolean
1775
- restarted?: boolean
1776
- restartError?: string
1863
+ /** Ids of the knowledge bases whose TW child was restarted after the pull. */
1864
+ restarted?: string[]
1865
+ /** Wikis that could not be restarted (the pull itself still succeeded). */
1866
+ restartFailed?: Array<{ id: string; message: string }>
1777
1867
  status?: GitStatusView
1778
1868
  }
1779
1869
  interface ResolveResult {
@@ -1807,15 +1897,17 @@ function renderSync(value: SyncResult): Array<{ type: 'text'; text: string }> {
1807
1897
  if (value.commit !== undefined) lines.push(`本地 commit: ${value.commit}`)
1808
1898
  if (value.push !== undefined) lines.push(`远端 push: ${value.push}`)
1809
1899
  if (value.changed === true) {
1810
- lines.push(value.restarted === true
1811
- ? '本次 pull 拉取了新内容,TW 服务已自动重启(同端口),读取/搜索均为最新快照。'
1812
- : '本次 pull 拉取了新内容,但 TW 服务未能自动重启(如需最新快照,请手动重启 TW)。')
1900
+ lines.push(value.restarted !== undefined && value.restarted.length > 0
1901
+ ? `本次 pull 拉取了新内容,已重启:${value.restarted.join('、')}(同端口),其读取/搜索均为最新快照。`
1902
+ : '本次 pull 拉取了新内容,但没有正在运行的知识库受影响(无需重启,或改动落在未运行的库里)。')
1903
+ }
1904
+ if (value.restartFailed !== undefined) {
1905
+ for (const item of value.restartFailed) lines.push(`TW 重启失败:${item.id} —— ${item.message}`)
1813
1906
  }
1814
- if (value.restartError !== undefined) lines.push(`TW 重启失败: ${value.restartError}`)
1815
1907
  if (value.status !== undefined) {
1816
1908
  lines.push(`状态: ${gitStatusBits(value.status)}`)
1817
1909
  const s = value.status
1818
1910
  if (s.dirty && s.dirtyFiles.length > 0) lines.push(` 未提交: ${s.dirtyFiles.join(', ')}`)
1819
1911
  }
1820
1912
  return [{ type: 'text', text: lines.join('\n') }]
1821
- }
1913
+ }