@qvac/core 1.0.0-rc.8 → 1.0.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 (226) hide show
  1. package/CHANGELOG.md +234 -3
  2. package/README.md +1 -0
  3. package/dist-lib/lib/api/attachments.d.ts +1 -1
  4. package/dist-lib/lib/api/attachments.js +11 -0
  5. package/dist-lib/lib/api/chunks.d.ts +4 -2
  6. package/dist-lib/lib/api/chunks.js +6 -3
  7. package/dist-lib/lib/api/devices.js +6 -18
  8. package/dist-lib/lib/api/execution.d.ts +6 -2
  9. package/dist-lib/lib/api/execution.js +29 -3
  10. package/dist-lib/lib/api/host-run-log.d.ts +7 -1
  11. package/dist-lib/lib/api/host-run-log.js +3 -1
  12. package/dist-lib/lib/api/index.d.ts +3 -1
  13. package/dist-lib/lib/api/index.js +17 -6
  14. package/dist-lib/lib/api/members.js +13 -29
  15. package/dist-lib/lib/api/mesh.d.ts +2 -1
  16. package/dist-lib/lib/api/projects.d.ts +1 -1
  17. package/dist-lib/lib/api/projects.js +9 -5
  18. package/dist-lib/lib/api/rag-label.d.ts +4 -0
  19. package/dist-lib/lib/api/rag-label.js +21 -0
  20. package/dist-lib/lib/api/rag-lexical.d.ts +22 -0
  21. package/dist-lib/lib/api/rag-lexical.js +1058 -0
  22. package/dist-lib/lib/api/rag-manifest.d.ts +13 -0
  23. package/dist-lib/lib/api/rag-manifest.js +46 -0
  24. package/dist-lib/lib/api/rag-outline.d.ts +36 -0
  25. package/dist-lib/lib/api/rag-outline.js +426 -0
  26. package/dist-lib/lib/api/rag-plugin.d.ts +20 -0
  27. package/dist-lib/lib/api/rag-plugin.js +70 -0
  28. package/dist-lib/lib/api/rag-synthesis.d.ts +7 -0
  29. package/dist-lib/lib/api/rag-synthesis.js +102 -0
  30. package/dist-lib/lib/api/rag-targets.d.ts +23 -0
  31. package/dist-lib/lib/api/rag-targets.js +215 -0
  32. package/dist-lib/lib/api/rag-window.d.ts +5 -0
  33. package/dist-lib/lib/api/rag-window.js +46 -0
  34. package/dist-lib/lib/api/rag.d.ts +3 -2
  35. package/dist-lib/lib/api/rag.js +421 -181
  36. package/dist-lib/lib/api/served.js +8 -14
  37. package/dist-lib/lib/api/workspace.d.ts +8 -1
  38. package/dist-lib/lib/api/workspace.js +27 -13
  39. package/dist-lib/lib/assistant/harness.d.ts +9 -1
  40. package/dist-lib/lib/assistant/history.d.ts +11 -2
  41. package/dist-lib/lib/assistant/history.js +74 -4
  42. package/dist-lib/lib/assistant/media-round.d.ts +61 -0
  43. package/dist-lib/lib/assistant/media-round.js +111 -0
  44. package/dist-lib/lib/assistant/message.d.ts +7 -0
  45. package/dist-lib/lib/assistant/model-round.d.ts +12 -0
  46. package/dist-lib/lib/assistant/model-round.js +130 -17
  47. package/dist-lib/lib/assistant/pdf-pages.d.ts +16 -1
  48. package/dist-lib/lib/assistant/pdf-pages.js +67 -3
  49. package/dist-lib/lib/assistant/round-host.d.ts +22 -0
  50. package/dist-lib/lib/assistant/round-host.js +142 -8
  51. package/dist-lib/lib/assistant/upload.d.ts +12 -0
  52. package/dist-lib/lib/assistant/upload.js +36 -0
  53. package/dist-lib/lib/assistant-client.d.ts +1 -0
  54. package/dist-lib/lib/assistant-client.js +40 -19
  55. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  56. package/dist-lib/lib/assistant-tree.js +41 -1
  57. package/dist-lib/lib/assistant.d.ts +15 -0
  58. package/dist-lib/lib/assistant.js +474 -89
  59. package/dist-lib/lib/client.d.ts +1 -0
  60. package/dist-lib/lib/client.js +4 -1
  61. package/dist-lib/lib/compaction.js +2 -2
  62. package/dist-lib/lib/core/agent.js +12 -45
  63. package/dist-lib/lib/core/approval-rules.js +1 -8
  64. package/dist-lib/lib/core/archived-mesh.d.ts +2 -1
  65. package/dist-lib/lib/core/archived-mesh.js +12 -8
  66. package/dist-lib/lib/core/chat-copy.d.ts +18 -3
  67. package/dist-lib/lib/core/chat-copy.js +74 -25
  68. package/dist-lib/lib/core/chat-fork.js +15 -6
  69. package/dist-lib/lib/core/chat-group.js +16 -24
  70. package/dist-lib/lib/core/chat-move.d.ts +9 -0
  71. package/dist-lib/lib/core/chat-move.js +94 -3
  72. package/dist-lib/lib/core/chat-order.js +12 -18
  73. package/dist-lib/lib/core/chat.js +38 -31
  74. package/dist-lib/lib/core/chunk.d.ts +2 -2
  75. package/dist-lib/lib/core/chunk.js +18 -25
  76. package/dist-lib/lib/core/collections.d.ts +2 -0
  77. package/dist-lib/lib/core/collections.js +2 -0
  78. package/dist-lib/lib/core/contract/activity.d.ts +4 -0
  79. package/dist-lib/lib/core/contract/activity.js +34 -4
  80. package/dist-lib/lib/core/contract/chat-group.d.ts +1 -0
  81. package/dist-lib/lib/core/contract/chat-group.js +21 -1
  82. package/dist-lib/lib/core/contract/chat.d.ts +9 -0
  83. package/dist-lib/lib/core/contract/chat.js +127 -5
  84. package/dist-lib/lib/core/contract/chunks.d.ts +1 -0
  85. package/dist-lib/lib/core/contract/chunks.js +37 -6
  86. package/dist-lib/lib/core/contract/features.d.ts +21 -0
  87. package/dist-lib/lib/core/contract/features.js +22 -0
  88. package/dist-lib/lib/core/contract/index.js +2 -0
  89. package/dist-lib/lib/core/contract/indexing.js +4 -2
  90. package/dist-lib/lib/core/contract/knowledge.js +5 -4
  91. package/dist-lib/lib/core/contract/members.js +16 -10
  92. package/dist-lib/lib/core/contract/mesh-kind.d.ts +1 -0
  93. package/dist-lib/lib/core/contract/mesh-kind.js +3 -1
  94. package/dist-lib/lib/core/contract/projects.d.ts +5 -0
  95. package/dist-lib/lib/core/contract/projects.js +13 -5
  96. package/dist-lib/lib/core/contract/roles.js +32 -4
  97. package/dist-lib/lib/core/contract/run-requests.d.ts +1 -0
  98. package/dist-lib/lib/core/contract/run-requests.js +35 -2
  99. package/dist-lib/lib/core/contract/seed-defaults.js +2 -2
  100. package/dist-lib/lib/core/contract/tool-configs.js +3 -2
  101. package/dist-lib/lib/core/contract/workspace.d.ts +2 -0
  102. package/dist-lib/lib/core/contract/workspace.js +40 -7
  103. package/dist-lib/lib/core/contract/writers.js +2 -2
  104. package/dist-lib/lib/core/departures.d.ts +3 -1
  105. package/dist-lib/lib/core/departures.js +3 -0
  106. package/dist-lib/lib/core/devices.js +1 -8
  107. package/dist-lib/lib/core/files/attachments.d.ts +2 -0
  108. package/dist-lib/lib/core/files/attachments.js +19 -1
  109. package/dist-lib/lib/core/files/index.d.ts +20 -4
  110. package/dist-lib/lib/core/files/index.js +132 -21
  111. package/dist-lib/lib/core/files/processing/document.d.ts +4 -0
  112. package/dist-lib/lib/core/files/processing/document.js +7 -0
  113. package/dist-lib/lib/core/files/processing/index.d.ts +13 -0
  114. package/dist-lib/lib/core/files/processing/index.js +144 -12
  115. package/dist-lib/lib/core/files/processing/protocol.js +13 -34
  116. package/dist-lib/lib/core/files/processing/state.d.ts +2 -0
  117. package/dist-lib/lib/core/files/rag/build.d.ts +19 -2
  118. package/dist-lib/lib/core/files/rag/build.js +123 -19
  119. package/dist-lib/lib/core/files/rag/failure.js +2 -1
  120. package/dist-lib/lib/core/files/rag/index.d.ts +11 -3
  121. package/dist-lib/lib/core/files/rag/index.js +13 -1
  122. package/dist-lib/lib/core/files/rag/load.d.ts +6 -3
  123. package/dist-lib/lib/core/files/rag/load.js +27 -6
  124. package/dist-lib/lib/core/files/rag/plugin-index.d.ts +32 -0
  125. package/dist-lib/lib/core/files/rag/plugin-index.js +127 -0
  126. package/dist-lib/lib/core/files/rag/produce.d.ts +5 -3
  127. package/dist-lib/lib/core/files/rag/produce.js +104 -16
  128. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +3 -1
  129. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +62 -13
  130. package/dist-lib/lib/core/files/rag/text-cache.d.ts +28 -0
  131. package/dist-lib/lib/core/files/rag/text-cache.js +141 -0
  132. package/dist-lib/lib/core/files/records/knowledge.d.ts +1 -3
  133. package/dist-lib/lib/core/files/records/knowledge.js +7 -40
  134. package/dist-lib/lib/core/files/records/reclaim.js +5 -10
  135. package/dist-lib/lib/core/files/upload.js +68 -41
  136. package/dist-lib/lib/core/fs-drives.js +14 -26
  137. package/dist-lib/lib/core/invite.d.ts +1 -0
  138. package/dist-lib/lib/core/invite.js +4 -2
  139. package/dist-lib/lib/core/local/files.d.ts +1 -1
  140. package/dist-lib/lib/core/local/files.js +5 -5
  141. package/dist-lib/lib/core/local/index.d.ts +13 -6
  142. package/dist-lib/lib/core/local/index.js +103 -69
  143. package/dist-lib/lib/core/local/run-logs.d.ts +1 -1
  144. package/dist-lib/lib/core/local/run-logs.js +5 -5
  145. package/dist-lib/lib/core/mesh-processor.d.ts +19 -0
  146. package/dist-lib/lib/core/mesh-processor.js +87 -0
  147. package/dist-lib/lib/core/mesh.d.ts +48 -5
  148. package/dist-lib/lib/core/mesh.js +318 -129
  149. package/dist-lib/lib/core/migrations/agent-catalog.js +2 -8
  150. package/dist-lib/lib/core/migrations/agent-tools-scope.js +5 -11
  151. package/dist-lib/lib/core/migrations/workspace-from-0-21/index.d.ts +88 -0
  152. package/dist-lib/lib/core/migrations/workspace-from-0-21/index.js +731 -0
  153. package/dist-lib/lib/core/migrations/writer-links.d.ts +2 -0
  154. package/dist-lib/lib/core/migrations/writer-links.js +32 -0
  155. package/dist-lib/lib/core/project-keys.d.ts +6 -0
  156. package/dist-lib/lib/core/project-keys.js +11 -0
  157. package/dist-lib/lib/core/public-mesh.d.ts +3 -0
  158. package/dist-lib/lib/core/public-mesh.js +10 -8
  159. package/dist-lib/lib/core/run-requests.d.ts +3 -0
  160. package/dist-lib/lib/core/run-requests.js +21 -1
  161. package/dist-lib/lib/core/skill-availability.d.ts +33 -0
  162. package/dist-lib/lib/core/skill-availability.js +67 -0
  163. package/dist-lib/lib/core/sync/background.d.ts +0 -1
  164. package/dist-lib/lib/core/sync/background.js +2 -1
  165. package/dist-lib/lib/core/sync/changed.d.ts +4 -2
  166. package/dist-lib/lib/core/sync/changed.js +1 -1
  167. package/dist-lib/lib/core/sync/index.js +52 -10
  168. package/dist-lib/lib/core/sync/view-updates.d.ts +18 -12
  169. package/dist-lib/lib/core/sync/view-updates.js +82 -91
  170. package/dist-lib/lib/core/sync-status.js +97 -41
  171. package/dist-lib/lib/core/tool-activity.js +6 -12
  172. package/dist-lib/lib/core/tool-configs.js +17 -29
  173. package/dist-lib/lib/core/upgrade-summary.d.ts +19 -0
  174. package/dist-lib/lib/core/upgrade-summary.js +67 -0
  175. package/dist-lib/lib/core/view-read.d.ts +4 -0
  176. package/dist-lib/lib/core/view-read.js +23 -0
  177. package/dist-lib/lib/core/workspace-upgrade.d.ts +7 -0
  178. package/dist-lib/lib/core/workspace-upgrade.js +27 -16
  179. package/dist-lib/lib/core.d.ts +39 -42
  180. package/dist-lib/lib/core.js +661 -639
  181. package/dist-lib/lib/errors.d.ts +20 -0
  182. package/dist-lib/lib/errors.js +20 -0
  183. package/dist-lib/lib/llm-model-names.d.ts +1 -1
  184. package/dist-lib/lib/llm-model-names.js +1 -1
  185. package/dist-lib/lib/mesh-scoped-engine.js +4 -0
  186. package/dist-lib/lib/model-context.js +1 -2
  187. package/dist-lib/lib/probe-rounds.d.ts +7 -2
  188. package/dist-lib/lib/probe-rounds.js +6 -1
  189. package/dist-lib/lib/run-transcript.d.ts +4 -1
  190. package/dist-lib/lib/run-transcript.js +15 -6
  191. package/dist-lib/schema/engine.js +83 -6
  192. package/dist-lib/schema/indexes.d.ts +3 -0
  193. package/dist-lib/schema/indexes.js +5 -0
  194. package/dist-lib/schema/local.js +11 -2
  195. package/dist-lib/schema/qvac.js +49 -5
  196. package/dist-lib/spec/bind.js +34 -0
  197. package/dist-lib/spec/calls.js +5 -0
  198. package/dist-lib/spec/capabilities.d.ts +17 -0
  199. package/dist-lib/spec/hrpc/hrpc.json +65 -0
  200. package/dist-lib/spec/hrpc/index.js +68 -5
  201. package/dist-lib/spec/hrpc/messages.js +260 -23
  202. package/dist-lib/spec/hyperschema/index.js +260 -23
  203. package/dist-lib/spec/hyperschema/schema.json +181 -0
  204. package/dist-lib/spec/hyperschema/types.d.ts +48 -0
  205. package/dist-lib/spec/local/hyperdb/messages.js +270 -224
  206. package/dist-lib/spec/local/hyperschema/index.js +73 -38
  207. package/dist-lib/spec/local/hyperschema/schema.json +31 -0
  208. package/dist-lib/spec/local/hyperschema/types.d.ts +8 -0
  209. package/dist-lib/spec/mesh/hyperdb/db.json +39 -2
  210. package/dist-lib/spec/mesh/hyperdb/index.js +120 -3
  211. package/dist-lib/spec/mesh/hyperdb/messages.js +1328 -838
  212. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +30 -0
  213. package/dist-lib/spec/mesh/hyperdispatch/index.js +86 -1
  214. package/dist-lib/spec/mesh/hyperdispatch/messages.js +682 -287
  215. package/dist-lib/spec/mesh/hyperschema/index.js +682 -287
  216. package/dist-lib/spec/mesh/hyperschema/schema.json +201 -0
  217. package/dist-lib/spec/mesh/hyperschema/types.d.ts +52 -0
  218. package/package.json +75 -70
  219. package/tui/README.md +2 -1
  220. package/tui/app.mjs +28 -7
  221. package/tui/boot.mjs +5 -1
  222. package/tui/lib/attachment-files.mjs +82 -0
  223. package/tui/lib/reopen-meshes.mjs +15 -0
  224. package/tui/main.mjs +4 -43
  225. package/worker/assistant-sidecar.mjs +10 -3
  226. package/worker/stow-entry.mjs +3 -52
package/tui/app.mjs CHANGED
@@ -38,6 +38,7 @@ import {
38
38
  turnDone,
39
39
  turnsFromChunks
40
40
  } from './lib/render.mjs'
41
+ import { skippedLine } from './lib/attachment-files.mjs'
41
42
  import { exportMarkdown } from './lib/export.mjs'
42
43
  import { paintSelection, selectionText } from './lib/select.mjs'
43
44
  import { center, splash } from './lib/splash.mjs'
@@ -233,7 +234,11 @@ const COMMANDS = [
233
234
  desc: "the agent's toolset switches and the tools in each; space toggles a set"
234
235
  },
235
236
  { name: 'permissions', desc: "the agent's approval mode; space toggles" },
236
- { name: 'attach', desc: 'attach one or more local files to this chat by path', palette: true },
237
+ {
238
+ name: 'attach',
239
+ desc: "attach local files, or a directory's document files, to this chat by path",
240
+ palette: true
241
+ },
237
242
  {
238
243
  name: 'save',
239
244
  desc: 'download the latest (or n-th) attachment to ~/Downloads',
@@ -1920,7 +1925,6 @@ export class ChatApp {
1920
1925
  // clipboard access is host plumbing, not app logic; null disables the shortcut
1921
1926
  this._copyToClipboard = copyToClipboard || null
1922
1927
  this._resolvePastedFile = resolvePastedFile || null
1923
- // `/attach <path>` resolver: named path -> attachment, or throws.
1924
1928
  this._resolveFileAttachment = resolveFileAttachment || null
1925
1929
  this.updateBanner = applyUpdate
1926
1930
  ? updateBanner.create({ onAccept: applyUpdate, acceptKey: 'ctrl+u' })
@@ -2554,7 +2558,7 @@ export class ChatApp {
2554
2558
  ' /files — show upload progress, local readiness, and failures for this chat',
2555
2559
  ' /compact — fold the older turns of this chat into a summary now (what a full context window triggers on its own); the notice shows the summary or why the fold was refused',
2556
2560
  ' /usage — this chat’s context usage as the last run reported it: the window, how much of it is in use, and what the prompt spends it on (conversation, system prompt, agent instructions, skills, tools)',
2557
- ' /attach <path> [<path> …] — attach local files to this chat (quote paths that contain spaces)',
2561
+ " /attach <path> [<path> …] — attach local files, or a directory's document files, to this chat (quote paths that contain spaces)",
2558
2562
  ' /save [n] — download the latest (or n-th) attachment to ~/Downloads',
2559
2563
  ' /export [n] — write the last run (or last n) to a markdown file: prompt, thinking, answer, tools',
2560
2564
  '',
@@ -3254,12 +3258,29 @@ export class ChatApp {
3254
3258
  return run(async () => {
3255
3259
  const lines = []
3256
3260
  for (const p of paths) {
3261
+ const failure = (label, err) =>
3262
+ lines.push(`✗ ${label} — ${err.code === 'ENOENT' ? 'no such file' : err.message}`)
3263
+ let resolved
3257
3264
  try {
3258
- const file = app._resolveFileAttachment(p)
3259
- await app._uploadAttachment(file)
3260
- lines.push(`attached ${file.fileName} (${file.data.length}B) ✓`)
3265
+ resolved = app._resolveFileAttachment(p)
3261
3266
  } catch (err) {
3262
- lines.push(`✗ ${p} — ${err.code === 'ENOENT' ? 'no such file' : err.message}`)
3267
+ failure(p, err)
3268
+ continue
3269
+ }
3270
+
3271
+ for (const { path: source, read } of resolved.files) {
3272
+ try {
3273
+ const file = read()
3274
+ await app._uploadAttachment(file)
3275
+ lines.push(`attached ${file.fileName} (${file.data.length}B) ✓`)
3276
+ } catch (err) {
3277
+ failure(source, err)
3278
+ }
3279
+ }
3280
+
3281
+ const skipped = skippedLine(resolved.skipped)
3282
+ if (skipped) {
3283
+ lines.push(skipped)
3263
3284
  }
3264
3285
  }
3265
3286
 
package/tui/boot.mjs CHANGED
@@ -21,6 +21,7 @@ async function resolvePaths(entries) {
21
21
  }
22
22
  }
23
23
 
24
+ const harnessSpecifier = '@qvac/harness/worker/stow-entry.mjs'
24
25
  const sidecarEntry = fileURLToPath(new URL('../worker/stow-entry.mjs', import.meta.url))
25
26
  if (!fs.existsSync(sidecarEntry)) {
26
27
  throw new Error(`assistant sidecar entry missing at ${sidecarEntry}`)
@@ -29,7 +30,8 @@ async function resolvePaths(entries) {
29
30
  return {
30
31
  // imported here, as at load it reads a path from import.meta.url, which a bundle does not have
31
32
  skillsDir: (await import('@qvac/skills')).skillsDir,
32
- harnessEntry: fileURLToPath(import.meta.resolve('@qvac/harness/worker/stow-entry.mjs')),
33
+ // a variable, as bare-pack follows a literal and would bundle the harness graph into duck again
34
+ harnessEntry: fileURLToPath(import.meta.resolve(harnessSpecifier)),
33
35
  sidecarEntry
34
36
  }
35
37
  }
@@ -139,6 +141,8 @@ export async function boot(args, entries = null) {
139
141
  },
140
142
  skillsDir,
141
143
  harnessEntry,
144
+ // replaces the sidecar's default, so its cache types are restated; 4 replies decode at once
145
+ llm: { kvCacheK: 'q8_0', kvCacheV: 'q8_0', slots: 4 },
142
146
  fakeModels: args.fakeModels || process.env.QVAC_FAKE_MODELS === '1',
143
147
  // only the image keys cross: the arg is argv, readable by anything that can list processes
144
148
  imageEnv: Object.fromEntries(
@@ -0,0 +1,82 @@
1
+ import fs from 'fs'
2
+ import path from 'path'
3
+ import { RAG_ACCEPT_EXTENSIONS } from '../../dist-lib/lib/core/files/rag/document-types.js'
4
+ import { resolveLocalPath } from './local-path.mjs'
5
+
6
+ const OPENXML = 'application/vnd.openxmlformats-officedocument'
7
+ const MIME_TYPES = new Map([
8
+ ['.png', 'image/png'],
9
+ ['.jpg', 'image/jpeg'],
10
+ ['.jpeg', 'image/jpeg'],
11
+ ['.gif', 'image/gif'],
12
+ ['.webp', 'image/webp'],
13
+ ['.heic', 'image/heic'],
14
+ ['.heif', 'image/heif'],
15
+ ['.pdf', 'application/pdf'],
16
+ ['.mov', 'video/quicktime'],
17
+ ['.mp4', 'video/mp4'],
18
+ ['.m4v', 'video/x-m4v'],
19
+ ['.webm', 'video/webm'],
20
+ ['.mkv', 'video/x-matroska'],
21
+ ['.m4a', 'audio/mp4'],
22
+ ['.mp3', 'audio/mpeg'],
23
+ ['.wav', 'audio/wav'],
24
+ ['.txt', 'text/plain'],
25
+ ['.md', 'text/markdown'],
26
+ ['.json', 'application/json'],
27
+ ['.csv', 'text/csv'],
28
+ ['.rtf', 'application/rtf'],
29
+ ['.docx', `${OPENXML}.wordprocessingml.document`],
30
+ ['.xlsx', `${OPENXML}.spreadsheetml.sheet`],
31
+ ['.pptx', `${OPENXML}.presentationml.presentation`]
32
+ ])
33
+ const DIRECTORY_EXTENSIONS = new Set([...RAG_ACCEPT_EXTENSIONS, '.docx', '.xlsx', '.pptx'])
34
+ const MAX_ATTACHMENT_BYTES = 100 * 1024 * 1024
35
+
36
+ export function fileToAttachment(file, stat = fs.statSync(file)) {
37
+ if (!stat.isFile()) throw new Error('not a regular file')
38
+ if (stat.size > MAX_ATTACHMENT_BYTES) {
39
+ throw new Error(`file too large (${MAX_ATTACHMENT_BYTES / (1024 * 1024)}MB cap)`)
40
+ }
41
+
42
+ return {
43
+ fileName: path.basename(file),
44
+ mimeType: MIME_TYPES.get(path.extname(file).toLowerCase()) ?? 'application/octet-stream',
45
+ data: fs.readFileSync(file)
46
+ }
47
+ }
48
+
49
+ const MAX_SKIPPED_LISTED = 10
50
+
51
+ export function resolveFileAttachment(pathString) {
52
+ const target = resolveLocalPath(pathString)
53
+ const stat = fs.statSync(target)
54
+ if (!stat.isDirectory()) {
55
+ return { files: [{ path: target, read: () => fileToAttachment(target, stat) }], skipped: [] }
56
+ }
57
+
58
+ const entries = fs
59
+ .readdirSync(target, { withFileTypes: true })
60
+ .filter((entry) => !entry.name.startsWith('.') && !entry.isDirectory())
61
+ .sort((a, b) => (a.name < b.name ? -1 : 1))
62
+ const supported = (entry) => DIRECTORY_EXTENSIONS.has(path.extname(entry.name).toLowerCase())
63
+
64
+ return {
65
+ files: entries.filter(supported).map((entry) => {
66
+ const file = path.join(target, entry.name)
67
+
68
+ return { path: file, read: () => fileToAttachment(file) }
69
+ }),
70
+ skipped: entries.filter((entry) => !supported(entry)).map((entry) => entry.name)
71
+ }
72
+ }
73
+
74
+ export function skippedLine(skipped) {
75
+ if (skipped.length === 0) {
76
+ return null
77
+ }
78
+
79
+ const listed = skipped.slice(0, MAX_SKIPPED_LISTED).join(', ')
80
+
81
+ return `skipped ${skipped.length} unsupported: ${listed}${skipped.length > MAX_SKIPPED_LISTED ? ', …' : ''}`
82
+ }
@@ -0,0 +1,15 @@
1
+ // Core opens a saved mesh only when a route names it, and a headless duck names none
2
+ export async function reopenMeshes(engine, log) {
3
+ const { meshes } = await engine.listMeshes({})
4
+ await Promise.all(
5
+ (meshes ?? [])
6
+ .filter((mesh) => !mesh.open)
7
+ .map(async ({ meshId }) => {
8
+ try {
9
+ await engine.openMesh({ meshId })
10
+ } catch (error) {
11
+ log(`could not reopen mesh ${meshId.slice(0, 8)}: ${error.message}`)
12
+ }
13
+ })
14
+ )
15
+ }
package/tui/main.mjs CHANGED
@@ -6,7 +6,9 @@ import pear from 'bare-tui-updater/pear'
6
6
  import { spawn } from 'child_process'
7
7
  import path from 'path'
8
8
  import { readBootTiming } from './lib/boot-timing.mjs'
9
+ import { fileToAttachment, resolveFileAttachment } from './lib/attachment-files.mjs'
9
10
  import { resolveLocalPath } from './lib/local-path.mjs'
11
+ import { reopenMeshes } from './lib/reopen-meshes.mjs'
10
12
  import { applyUnattended, startUpdater } from './lib/updater.mjs'
11
13
  import { ChatApp } from './app.mjs'
12
14
  import b4a from 'b4a'
@@ -132,30 +134,6 @@ function readClipboard() {
132
134
  })
133
135
  }
134
136
 
135
- const MIME_TYPES = new Map([
136
- ['.png', 'image/png'],
137
- ['.jpg', 'image/jpeg'],
138
- ['.jpeg', 'image/jpeg'],
139
- ['.gif', 'image/gif'],
140
- ['.webp', 'image/webp'],
141
- ['.heic', 'image/heic'],
142
- ['.heif', 'image/heif'],
143
- ['.pdf', 'application/pdf'],
144
- ['.mov', 'video/quicktime'],
145
- ['.mp4', 'video/mp4'],
146
- ['.m4v', 'video/x-m4v'],
147
- ['.webm', 'video/webm'],
148
- ['.mkv', 'video/x-matroska'],
149
- ['.m4a', 'audio/mp4'],
150
- ['.mp3', 'audio/mpeg'],
151
- ['.wav', 'audio/wav'],
152
- ['.txt', 'text/plain'],
153
- ['.md', 'text/markdown'],
154
- ['.json', 'application/json']
155
- ])
156
- // the engine's own cap (lib/core/files/attachments.ts); a lower one here refused files it takes
157
- const MAX_ATTACHMENT_BYTES = 100 * 1024 * 1024
158
-
159
137
  // raw image data on the clipboard has no portable tty-side accessor, so only file paths attach
160
138
  async function resolvePastedFile() {
161
139
  const text = (await readClipboard()).trim()
@@ -178,24 +156,6 @@ async function resolvePastedFile() {
178
156
  return fileToAttachment(file, stat)
179
157
  }
180
158
 
181
- // `/attach` resolver: a named path -> attachment; throws on a bad path.
182
- function resolveFileAttachment(pathString) {
183
- return fileToAttachment(resolveLocalPath(pathString))
184
- }
185
-
186
- function fileToAttachment(file, stat = fs.statSync(file)) {
187
- if (!stat.isFile()) throw new Error('not a regular file')
188
- if (stat.size > MAX_ATTACHMENT_BYTES) {
189
- throw new Error(`file too large (${MAX_ATTACHMENT_BYTES / (1024 * 1024)}MB cap)`)
190
- }
191
-
192
- return {
193
- fileName: path.basename(file),
194
- mimeType: MIME_TYPES.get(path.extname(file).toLowerCase()) ?? 'application/octet-stream',
195
- data: fs.readFileSync(file)
196
- }
197
- }
198
-
199
159
  // called only once the TUI released the tty, so it never fights bare-tui's live render
200
160
  function printBootTiming(booted) {
201
161
  if (process.env.QVAC_BOOT_TIMING !== '1' || !booted) return
@@ -242,7 +202,8 @@ async function run(args, standalone, entries) {
242
202
  applyUnattended(updates.updater, console.log, () => void shutdown(75))
243
203
  }
244
204
 
245
- const { deviceId, meshInvite } = await connect()
205
+ const { engine, deviceId, meshInvite } = await connect()
206
+ await reopenMeshes(engine, console.log)
246
207
  console.log(`storage ${booted.storagePath}`)
247
208
  console.log(`log ${booted.logFile}`)
248
209
  console.log(`device ${booted.deviceName} ${b4a.toHex(deviceId)}`)
@@ -37,7 +37,9 @@ export default stowEntry((ipc) => {
37
37
  eager = true,
38
38
  // undefined keeps Core's own choice; false lets a host start without fetching default models
39
39
  autoDownloadModels = undefined,
40
- fakeModels = false
40
+ fakeModels = false,
41
+ // the harness's knowledge plugin holds the index; false keeps core's own, rebuilt each start
42
+ harnessKnowledge = true
41
43
  } = JSON.parse(Bare.argv[2] || '{}')
42
44
 
43
45
  const bootstrapNodes = bootstrapJson ? JSON.parse(bootstrapJson) : undefined
@@ -87,8 +89,10 @@ export default stowEntry((ipc) => {
87
89
 
88
90
  // the host resets the session when its renderer reloads: same Core, a fresh client over one pipe
89
91
  ipc.on('session-reset', () => {
90
- core
91
- .connect(sessions.reset())
92
+ const stream = sessions.reset()
93
+ ipc
94
+ .send('session-reset')
95
+ .then(() => core.connect(stream))
92
96
  .catch((err) => logger.warn('assistant-sidecar', 'session reset failed', err?.message))
93
97
  })
94
98
 
@@ -123,6 +127,9 @@ export default stowEntry((ipc) => {
123
127
  imageClamps,
124
128
  musicModel,
125
129
  llm: { ...llm },
130
+ knowledge: harnessKnowledge
131
+ ? { dir: `${storage.root}/knowledge`, model: DEFAULT_RAG_MODEL }
132
+ : undefined,
126
133
  logger,
127
134
  eager
128
135
  }),
@@ -1,56 +1,7 @@
1
1
  /* global Bare */
2
2
  // bare-stow's bundle shim as a plain file, so the sidecar can be spawned without stowing
3
- import protocol from 'bare-stow/protocol'
3
+ import runtime from 'bare-stow-runtime/process'
4
4
 
5
- const ipc = protocol.attach(Bare.IPC)
5
+ const ipc = runtime.attach(Bare.IPC)
6
6
 
7
- let stop = null
8
- let readied = false
9
- let exited = false
10
-
11
- function ready() {
12
- if (readied) return
13
- readied = true
14
-
15
- ipc.send('ready')
16
- }
17
-
18
- async function shutdown(code, err = null) {
19
- if (exited) return
20
- exited = true
21
-
22
- try {
23
- if (stop) {
24
- await stop()
25
- }
26
- } catch (e) {
27
- err = err || e
28
- }
29
-
30
- if (err) {
31
- // the host may not be listening yet, so the reason also lands in the log
32
- console.error(err.stack || err.message || err)
33
- ipc.send('error', { message: err.message, stack: err.stack })
34
- }
35
-
36
- await ipc.send('exit', { code })
37
-
38
- Bare.exit(code)
39
- }
40
-
41
- ipc.on('terminate', () => shutdown(0))
42
-
43
- Bare.on('beforeExit', (exitCode) => shutdown(exitCode))
44
- .on('uncaughtException', (err) => shutdown(1, err))
45
- .on('unhandledRejection', (err) => shutdown(1, err))
46
-
47
- try {
48
- const entry = await import('./assistant-sidecar.mjs')
49
- const start = entry.default
50
-
51
- stop = (await start(ipc, ready)) || null
52
-
53
- ready()
54
- } catch (err) {
55
- shutdown(1, err)
56
- }
7
+ ipc.run(() => import('./assistant-sidecar.mjs'), ipc)