@qvac/core 1.0.0-rc.3 → 1.0.0-rc.6

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 (135) hide show
  1. package/CHANGELOG.md +147 -36
  2. package/README.md +55 -4
  3. package/dist-lib/index.d.ts +2 -1
  4. package/dist-lib/lib/api/agents.d.ts +2 -1
  5. package/dist-lib/lib/api/agents.js +5 -1
  6. package/dist-lib/lib/api/app-config.d.ts +3 -0
  7. package/dist-lib/lib/api/app-config.js +20 -0
  8. package/dist-lib/lib/api/approval-rules.d.ts +1 -1
  9. package/dist-lib/lib/api/approval-rules.js +5 -1
  10. package/dist-lib/lib/api/config.d.ts +6 -2
  11. package/dist-lib/lib/api/config.js +9 -5
  12. package/dist-lib/lib/api/device-routes.d.ts +1 -1
  13. package/dist-lib/lib/api/device-routes.js +3 -1
  14. package/dist-lib/lib/api/index.d.ts +12 -2
  15. package/dist-lib/lib/api/index.js +8 -2
  16. package/dist-lib/lib/api/projects.js +3 -4
  17. package/dist-lib/lib/api/rag.js +5 -5
  18. package/dist-lib/lib/api/served.d.ts +2 -2
  19. package/dist-lib/lib/api/served.js +24 -1
  20. package/dist-lib/lib/assistant/harness.d.ts +3 -0
  21. package/dist-lib/lib/assistant/history.js +14 -2
  22. package/dist-lib/lib/assistant/message.d.ts +1 -0
  23. package/dist-lib/lib/assistant/model-round.d.ts +3 -0
  24. package/dist-lib/lib/assistant/model-round.js +18 -4
  25. package/dist-lib/lib/assistant/round-host.d.ts +2 -0
  26. package/dist-lib/lib/assistant/round-host.js +8 -0
  27. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  28. package/dist-lib/lib/assistant-tree.js +4 -2
  29. package/dist-lib/lib/assistant.d.ts +12 -1
  30. package/dist-lib/lib/assistant.js +131 -15
  31. package/dist-lib/lib/client.js +4 -1
  32. package/dist-lib/lib/core/agent-copies.js +9 -2
  33. package/dist-lib/lib/core/agent-hosting.js +9 -4
  34. package/dist-lib/lib/core/agent.js +3 -1
  35. package/dist-lib/lib/core/approval-rules.d.ts +5 -1
  36. package/dist-lib/lib/core/approval-rules.js +16 -1
  37. package/dist-lib/lib/core/chat-copy.d.ts +1 -0
  38. package/dist-lib/lib/core/chat-copy.js +13 -2
  39. package/dist-lib/lib/core/chat.d.ts +0 -1
  40. package/dist-lib/lib/core/chat.js +0 -3
  41. package/dist-lib/lib/core/chunk.js +4 -3
  42. package/dist-lib/lib/core/collections.d.ts +7 -7
  43. package/dist-lib/lib/core/collections.js +7 -7
  44. package/dist-lib/lib/core/config-value.d.ts +1 -0
  45. package/dist-lib/lib/core/config-value.js +1 -0
  46. package/dist-lib/lib/core/contract/project-device-keys.d.ts +4 -2
  47. package/dist-lib/lib/core/contract/project-device-keys.js +12 -12
  48. package/dist-lib/lib/core/contract/project-host-keys.d.ts +5 -3
  49. package/dist-lib/lib/core/contract/project-host-keys.js +22 -11
  50. package/dist-lib/lib/core/contract/projects.d.ts +4 -2
  51. package/dist-lib/lib/core/contract/projects.js +29 -17
  52. package/dist-lib/lib/core/contract/workspace.js +2 -2
  53. package/dist-lib/lib/core/deleted-agent-runs.d.ts +8 -0
  54. package/dist-lib/lib/core/deleted-agent-runs.js +57 -0
  55. package/dist-lib/lib/core/files/index.d.ts +1 -1
  56. package/dist-lib/lib/core/files/index.js +4 -2
  57. package/dist-lib/lib/core/helpers/index.d.ts +1 -1
  58. package/dist-lib/lib/core/helpers/index.js +2 -2
  59. package/dist-lib/lib/core/local/index.d.ts +6 -0
  60. package/dist-lib/lib/core/local/index.js +14 -0
  61. package/dist-lib/lib/core/mesh.d.ts +2 -1
  62. package/dist-lib/lib/core/mesh.js +7 -5
  63. package/dist-lib/lib/core/project-keys.d.ts +5 -2
  64. package/dist-lib/lib/core/project-keys.js +15 -6
  65. package/dist-lib/lib/core/skill-secrets.d.ts +3 -2
  66. package/dist-lib/lib/core/skill-secrets.js +4 -1
  67. package/dist-lib/lib/core/sync/index.js +18 -6
  68. package/dist-lib/lib/core/vault-managed-skills.d.ts +18 -0
  69. package/dist-lib/lib/core/vault-managed-skills.js +105 -0
  70. package/dist-lib/lib/core.d.ts +10 -1
  71. package/dist-lib/lib/core.js +165 -31
  72. package/dist-lib/lib/errors.d.ts +8 -0
  73. package/dist-lib/lib/errors.js +8 -0
  74. package/dist-lib/lib/kv-cache-ledger.d.ts +22 -0
  75. package/dist-lib/lib/kv-cache-ledger.js +72 -0
  76. package/dist-lib/lib/kv-cache-retention.d.ts +1 -0
  77. package/dist-lib/lib/kv-cache-retention.js +5 -2
  78. package/dist-lib/lib/mesh-scoped-engine.js +1 -0
  79. package/dist-lib/lib/model-memory-cap.d.ts +3 -0
  80. package/dist-lib/lib/model-memory-cap.js +15 -6
  81. package/dist-lib/lib/run-replay.d.ts +3 -2
  82. package/dist-lib/lib/run-replay.js +16 -5
  83. package/dist-lib/lib/run-transcript.js +1 -1
  84. package/dist-lib/schema/config.d.ts +1 -1
  85. package/dist-lib/schema/config.js +1 -1
  86. package/dist-lib/schema/engine.js +87 -2
  87. package/dist-lib/schema/qvac.js +66 -3
  88. package/dist-lib/spec/bind.js +15 -0
  89. package/dist-lib/spec/calls.js +5 -0
  90. package/dist-lib/spec/capabilities.d.ts +10 -0
  91. package/dist-lib/spec/config/hyperconf/index.js +1 -1
  92. package/dist-lib/spec/hrpc/hrpc.json +65 -0
  93. package/dist-lib/spec/hrpc/index.js +63 -3
  94. package/dist-lib/spec/hrpc/messages.js +1302 -993
  95. package/dist-lib/spec/hyperschema/index.js +1302 -993
  96. package/dist-lib/spec/hyperschema/schema.json +227 -0
  97. package/dist-lib/spec/hyperschema/types.d.ts +45 -0
  98. package/dist-lib/spec/mesh/hyperdb/db.json +110 -0
  99. package/dist-lib/spec/mesh/hyperdb/index.js +498 -2
  100. package/dist-lib/spec/mesh/hyperdb/messages.js +1385 -892
  101. package/dist-lib/spec/mesh/hyperdispatch/messages.js +561 -301
  102. package/dist-lib/spec/mesh/hyperschema/index.js +561 -301
  103. package/dist-lib/spec/mesh/hyperschema/schema.json +343 -178
  104. package/dist-lib/spec/mesh/hyperschema/types.d.ts +40 -1
  105. package/package.json +34 -18
  106. package/tui/README.md +190 -0
  107. package/tui/app.mjs +8247 -0
  108. package/tui/boot.mjs +159 -0
  109. package/tui/index.mjs +89 -0
  110. package/tui/lib/boot-timing.mjs +41 -0
  111. package/tui/lib/busy-words.mjs +116 -0
  112. package/tui/lib/connect-sheet.mjs +350 -0
  113. package/tui/lib/device-target.mjs +64 -0
  114. package/tui/lib/export.mjs +194 -0
  115. package/tui/lib/folders-command.mjs +84 -0
  116. package/tui/lib/fork-command.mjs +43 -0
  117. package/tui/lib/knowledge-command.mjs +190 -0
  118. package/tui/lib/knowledge-import.mjs +153 -0
  119. package/tui/lib/local-path.mjs +21 -0
  120. package/tui/lib/move-command.mjs +17 -0
  121. package/tui/lib/render.mjs +225 -0
  122. package/tui/lib/save-file.mjs +88 -0
  123. package/tui/lib/select.mjs +81 -0
  124. package/tui/lib/selection.mjs +18 -0
  125. package/tui/lib/setup.mjs +135 -0
  126. package/tui/lib/sidebar.mjs +63 -0
  127. package/tui/lib/skill-connect.mjs +145 -0
  128. package/tui/lib/splash-art.mjs +107 -0
  129. package/tui/lib/splash.mjs +18 -0
  130. package/tui/lib/upload-frames.mjs +9 -0
  131. package/tui/lib/usage.mjs +59 -0
  132. package/tui/lib/wrap.mjs +143 -0
  133. package/tui/main.mjs +279 -0
  134. package/tui/plugins.mjs +158 -0
  135. package/worker/assistant-sidecar.mjs +1 -0
package/tui/main.mjs ADDED
@@ -0,0 +1,279 @@
1
+ // the TUI itself: draws the first frame, then imports boot.mjs, the engine side, behind it
2
+ import fs from 'bare-fs'
3
+ import os from 'bare-os'
4
+ import process from 'bare-process'
5
+ import tui from 'bare-tui'
6
+ import { spawn } from 'child_process'
7
+ import path from 'path'
8
+ import { readBootTiming } from './lib/boot-timing.mjs'
9
+ import { ChatApp } from './app.mjs'
10
+ import b4a from 'b4a'
11
+
12
+ const { Program } = tui
13
+
14
+ // the terminal writes a real sequence in one read, so this only has to beat human perception
15
+ const ESCAPE_TIMEOUT_MS = 50
16
+
17
+ // any other writer to the tty corrupts bare-tui's redraw; errors after exit still print
18
+ function withConsoleSuppressed(fn) {
19
+ const original = {
20
+ log: console.log,
21
+ info: console.info,
22
+ warn: console.warn,
23
+ error: console.error,
24
+ debug: console.debug
25
+ }
26
+ const noop = () => {}
27
+ Object.assign(console, {
28
+ log: noop,
29
+ info: noop,
30
+ warn: noop,
31
+ error: noop,
32
+ debug: noop
33
+ })
34
+
35
+ return fn().finally(() => Object.assign(console, original))
36
+ }
37
+
38
+ // llama.cpp writes straight to the tty fd; a synthetic resize forces a full repaint over its lines
39
+ function requestRepaint(getProgram) {
40
+ const program = getProgram()
41
+ if (!program) {
42
+ return
43
+ }
44
+
45
+ // || not ??: a size-less pty reports 0 columns, and 0-width style math hits repeat(-2)
46
+ program.send({
47
+ type: 'resize',
48
+ width: program.output.columns || 80,
49
+ height: program.output.rows || 24
50
+ })
51
+ }
52
+
53
+ const CLIPBOARD_COMMANDS = {
54
+ darwin: [['pbcopy', []]],
55
+ win32: [['clip', []]],
56
+ linux: [
57
+ ['wl-copy', []],
58
+ ['xclip', ['-selection', 'clipboard']],
59
+ ['xsel', ['--clipboard', '--input']]
60
+ ]
61
+ }
62
+
63
+ // piped to the platform clipboard command so nothing reaches the tty; first to exit 0 wins
64
+ function copyToClipboard(text) {
65
+ const commands = CLIPBOARD_COMMANDS[process.platform] ?? CLIPBOARD_COMMANDS.linux
66
+ return new Promise((resolve, reject) => {
67
+ const attempt = (i) => {
68
+ if (i >= commands.length) {
69
+ reject(new Error('no clipboard command available'))
70
+ return
71
+ }
72
+
73
+ const [cmd, args] = commands[i]
74
+ let child
75
+ try {
76
+ child = spawn(cmd, args, { stdio: ['pipe', 'ignore', 'ignore'] })
77
+ } catch {
78
+ attempt(i + 1)
79
+ return
80
+ }
81
+
82
+ child.on('error', () => attempt(i + 1))
83
+ child.on('exit', (code) => (code === 0 ? resolve() : attempt(i + 1)))
84
+ child.stdin.write(b4a.from(text))
85
+ child.stdin.end()
86
+ }
87
+ attempt(0)
88
+ })
89
+ }
90
+
91
+ // no display (a container, ssh): ask the host terminal to set its clipboard instead
92
+ function copyViaTerminal(program, text) {
93
+ program.output.write(`\x1b]52;c;${b4a.toString(b4a.from(text), 'base64')}\x07`)
94
+ }
95
+
96
+ function readClipboard() {
97
+ const commands =
98
+ process.platform === 'darwin'
99
+ ? [['pbpaste', []]]
100
+ : [
101
+ ['wl-paste', ['--no-newline']],
102
+ ['xclip', ['-o', '-selection', 'clipboard']],
103
+ ['xsel', ['--clipboard', '--output']]
104
+ ]
105
+ return new Promise((resolve, reject) => {
106
+ const attempt = (i) => {
107
+ if (i >= commands.length) {
108
+ reject(new Error('no clipboard command available'))
109
+ return
110
+ }
111
+
112
+ const [cmd, args] = commands[i]
113
+ let child
114
+ try {
115
+ child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'ignore'] })
116
+ } catch {
117
+ attempt(i + 1)
118
+ return
119
+ }
120
+
121
+ const out = []
122
+ child.stdout.on('data', (data) => out.push(data))
123
+ child.on('error', () => attempt(i + 1))
124
+ child.on('exit', (code) =>
125
+ code === 0 ? resolve(b4a.concat(out).toString()) : attempt(i + 1)
126
+ )
127
+ }
128
+ attempt(0)
129
+ })
130
+ }
131
+
132
+ const MIME_TYPES = new Map([
133
+ ['.png', 'image/png'],
134
+ ['.jpg', 'image/jpeg'],
135
+ ['.jpeg', 'image/jpeg'],
136
+ ['.gif', 'image/gif'],
137
+ ['.webp', 'image/webp'],
138
+ ['.heic', 'image/heic'],
139
+ ['.heif', 'image/heif'],
140
+ ['.pdf', 'application/pdf'],
141
+ ['.mov', 'video/quicktime'],
142
+ ['.mp4', 'video/mp4'],
143
+ ['.m4v', 'video/x-m4v'],
144
+ ['.webm', 'video/webm'],
145
+ ['.mkv', 'video/x-matroska'],
146
+ ['.m4a', 'audio/mp4'],
147
+ ['.mp3', 'audio/mpeg'],
148
+ ['.wav', 'audio/wav'],
149
+ ['.txt', 'text/plain'],
150
+ ['.md', 'text/markdown'],
151
+ ['.json', 'application/json']
152
+ ])
153
+ // the engine's own cap (lib/core/files/attachments.ts); a lower one here refused files it takes
154
+ const MAX_ATTACHMENT_BYTES = 100 * 1024 * 1024
155
+
156
+ // raw image data on the clipboard has no portable tty-side accessor, so only file paths attach
157
+ async function resolvePastedFile() {
158
+ const text = (await readClipboard()).trim()
159
+ if (!text || text.includes('\n')) {
160
+ return null
161
+ }
162
+
163
+ const file = expandFilePath(text)
164
+ let stat
165
+ try {
166
+ stat = fs.statSync(file)
167
+ } catch {
168
+ return null
169
+ }
170
+
171
+ if (!stat.isFile()) {
172
+ return null
173
+ }
174
+
175
+ return fileToAttachment(file, stat)
176
+ }
177
+
178
+ // `/attach` resolver: a named path -> attachment; throws on a bad path.
179
+ function resolveFileAttachment(pathString) {
180
+ return fileToAttachment(expandFilePath(pathString))
181
+ }
182
+
183
+ function expandFilePath(text) {
184
+ const file = text.startsWith('file://') ? decodeURI(text.slice('file://'.length)) : text
185
+ return file.startsWith('~/') ? path.join(os.homedir(), file.slice(2)) : file
186
+ }
187
+
188
+ function fileToAttachment(file, stat = fs.statSync(file)) {
189
+ if (!stat.isFile()) throw new Error('not a regular file')
190
+ if (stat.size > MAX_ATTACHMENT_BYTES) {
191
+ throw new Error(`file too large (${MAX_ATTACHMENT_BYTES / (1024 * 1024)}MB cap)`)
192
+ }
193
+
194
+ return {
195
+ fileName: path.basename(file),
196
+ mimeType: MIME_TYPES.get(path.extname(file).toLowerCase()) ?? 'application/octet-stream',
197
+ data: fs.readFileSync(file)
198
+ }
199
+ }
200
+
201
+ // called only once the TUI released the tty, so it never fights bare-tui's live render
202
+ function printBootTiming(booted) {
203
+ if (process.env.QVAC_BOOT_TIMING !== '1' || !booted) return
204
+ const lines = [
205
+ `host: "starting up…" (connect) = ${booted.connectMs}ms`,
206
+ readBootTiming(booted.storagePath)
207
+ ].filter(Boolean)
208
+ console.log(`\nboot timing:\n${lines.join('\n')}`)
209
+ }
210
+
211
+ export function main(args) {
212
+ run(args).catch((err) => {
213
+ console.error(err)
214
+ Bare.exit(1)
215
+ })
216
+ }
217
+
218
+ async function run(args) {
219
+ let program
220
+ // the engine side, once it is up: its teardown, and what the boot report prints
221
+ let booted = null
222
+ // bring-up runs inside the TUI so its "starting up…" frame shows while ~1200 modules load
223
+ const connect = async () => {
224
+ const { boot } = await import('./boot.mjs')
225
+ booted = await boot(args)
226
+ const { engine, skills, deviceId, meshInvite, modelName } = booted
227
+
228
+ return { engine, skills, deviceId, meshInvite, modelName }
229
+ }
230
+
231
+ // the engine's own handles hold the loop open until a signal arrives
232
+ if (args.headless) {
233
+ // armed before connect so a ctrl+C during a first-run model download still unwinds cleanly
234
+ const shutdown = async () => {
235
+ await booted?.close()
236
+ Bare.exit(0)
237
+ }
238
+ process.on('SIGINT', () => void shutdown())
239
+ process.on('SIGTERM', () => void shutdown())
240
+ const { deviceId, meshInvite } = await connect()
241
+ console.log(`storage ${booted.storagePath}`)
242
+ console.log(`log ${booted.logFile}`)
243
+ console.log(`device ${booted.deviceName} ${b4a.toHex(deviceId)}`)
244
+ console.log(`invite ${meshInvite ?? '(none — mesh not writable)'}`)
245
+ printBootTiming(booted)
246
+
247
+ return
248
+ }
249
+
250
+ const app = new ChatApp({
251
+ connect,
252
+ requestRepaint: () => requestRepaint(() => program),
253
+ copyToClipboard: (text) => copyToClipboard(text).catch(() => copyViaTerminal(program, text)),
254
+ resolvePastedFile,
255
+ resolveFileAttachment
256
+ })
257
+ // the transcript selects its own text, since the terminal can't while mouse tracking is on
258
+ program = new Program(app, { mouse: 'drag' })
259
+ // bracketed paste, or each pasted line arrives as keys and submits itself
260
+ program.output.write('\x1b[?2004h')
261
+ try {
262
+ await withConsoleSuppressed(() => {
263
+ const running = program.run()
264
+ // bare-tui cannot configure the decoder, whose 500ms esc timeout delays every overlay close
265
+ if (program._decoder) {
266
+ program._decoder._escapeDelay = ESCAPE_TIMEOUT_MS
267
+ }
268
+
269
+ return running
270
+ })
271
+ } finally {
272
+ program.output.write('\x1b[?2004l')
273
+ }
274
+
275
+ await booted?.close()
276
+ printBootTiming(booted)
277
+ // don't wait for the child to unwind a blocking native call; close() already tore the sidecar down
278
+ Bare.exit(0)
279
+ }
@@ -0,0 +1,158 @@
1
+ // userland plugins: folders under ~/.config/qv-ac/plugins, loaded only when config.json lists them
2
+ import fs from 'bare-fs'
3
+ import os from 'bare-os'
4
+ import process from 'bare-process'
5
+ import { spawn } from 'child_process'
6
+ import path from 'path'
7
+ import Corestore from 'corestore'
8
+ import Hyperdrive from 'hyperdrive'
9
+ import HypercoreId from 'hypercore-id-encoding'
10
+ import Hyperswarm from 'hyperswarm'
11
+
12
+ const DIR = path.join(
13
+ process.env.HOME ?? process.env.USERPROFILE ?? os.homedir(),
14
+ '.config',
15
+ 'qv-ac'
16
+ )
17
+ const PLUGINS = path.join(DIR, 'plugins')
18
+ const CONFIG = path.join(DIR, 'config.json')
19
+
20
+ function readConfig() {
21
+ if (!fs.existsSync(CONFIG)) {
22
+ return { plugins: [] }
23
+ }
24
+
25
+ const config = JSON.parse(fs.readFileSync(CONFIG, 'utf8'))
26
+ config.plugins ??= []
27
+
28
+ return config
29
+ }
30
+
31
+ function writeConfig(config) {
32
+ fs.mkdirSync(DIR, { recursive: true })
33
+ fs.writeFileSync(CONFIG, JSON.stringify(config, null, 2) + '\n')
34
+ }
35
+
36
+ const nameOf = (entry) => (typeof entry === 'string' ? entry : entry.name)
37
+
38
+ export function list() {
39
+ const enabled = readConfig().plugins.map(nameOf)
40
+ const installed = fs.existsSync(PLUGINS)
41
+ ? fs.readdirSync(PLUGINS).filter((name) => fs.statSync(path.join(PLUGINS, name)).isDirectory())
42
+ : []
43
+ const names = [...new Set([...installed, ...enabled])].sort()
44
+ if (names.length === 0) {
45
+ console.log(`no plugins in ${PLUGINS}`)
46
+ }
47
+
48
+ for (const name of names) {
49
+ let state = enabled.includes(name) ? 'enabled' : 'disabled'
50
+ if (!installed.includes(name)) {
51
+ state = 'missing'
52
+ }
53
+
54
+ console.log(`${name.padEnd(24)} ${state}`)
55
+ }
56
+ }
57
+
58
+ // a disabled entry keeps its options and read list under `disabled`, which the harness ignores
59
+ export function enable(name) {
60
+ if (!fs.existsSync(path.join(PLUGINS, name))) {
61
+ throw new Error(`${name} is not installed in ${PLUGINS}`)
62
+ }
63
+
64
+ const config = readConfig()
65
+ if (config.plugins.some((entry) => nameOf(entry) === name)) {
66
+ return
67
+ }
68
+
69
+ const stashed = (config.disabled ?? []).find((entry) => nameOf(entry) === name)
70
+ config.disabled = (config.disabled ?? []).filter((entry) => entry !== stashed)
71
+ config.plugins.push(stashed ?? name)
72
+ writeConfig(config)
73
+ }
74
+
75
+ export function disable(name) {
76
+ const config = readConfig()
77
+ const entry = config.plugins.find((entry) => nameOf(entry) === name)
78
+ if (entry === undefined) {
79
+ return
80
+ }
81
+
82
+ config.plugins = config.plugins.filter((other) => other !== entry)
83
+ config.disabled = [...(config.disabled ?? []), entry]
84
+ writeConfig(config)
85
+ }
86
+
87
+ export async function install(source, name) {
88
+ const hyper = source.startsWith('hyper://')
89
+ name ??= hyper ? undefined : path.basename(source).replace(/\.git$/, '')
90
+ if (!name || path.basename(name) !== name) {
91
+ throw new Error('give the plugin a folder name: duck plugins install <source> <name>')
92
+ }
93
+
94
+ const dest = path.join(PLUGINS, name)
95
+ if (fs.existsSync(dest)) {
96
+ throw new Error(`${name} is already installed in ${PLUGINS}`)
97
+ }
98
+
99
+ fs.mkdirSync(PLUGINS, { recursive: true })
100
+ if (hyper) {
101
+ await fromDrive(source.slice('hyper://'.length).replace(/\/$/, ''), dest)
102
+ } else {
103
+ await gitClone(source, dest)
104
+ }
105
+
106
+ console.log(`installed ${name}; run duck plugins enable ${name} to load it`)
107
+ }
108
+
109
+ function gitClone(url, dest) {
110
+ return new Promise((resolve, reject) => {
111
+ spawn('git', ['clone', '--depth', '1', url, dest], { stdio: 'inherit' })
112
+ .on('error', reject)
113
+ .on('exit', (code) =>
114
+ code === 0 ? resolve() : reject(new Error(`git clone exited ${code}`))
115
+ )
116
+ })
117
+ }
118
+
119
+ async function fromDrive(key, dest) {
120
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'duck-plugin-'))
121
+ const store = new Corestore(tmp)
122
+ const swarm = new Hyperswarm()
123
+ swarm.on('connection', (socket) => store.replicate(socket))
124
+ const drive = new Hyperdrive(store, HypercoreId.decode(key))
125
+ try {
126
+ await drive.ready()
127
+ const donePeering = drive.findingPeers()
128
+ swarm
129
+ .join(drive.discoveryKey, { server: false, client: true })
130
+ .flushed()
131
+ .then(donePeering, donePeering)
132
+ await drive.update({ wait: true })
133
+ for await (const entry of drive.list('/', { recursive: true })) {
134
+ const file = path.resolve(dest, '.' + entry.key)
135
+ if (!file.startsWith(dest + path.sep)) {
136
+ throw new Error(`drive entry ${entry.key} escapes the plugin folder`)
137
+ }
138
+
139
+ const data = await drive.get(entry.key, { wait: true })
140
+ if (data !== null) {
141
+ fs.mkdirSync(path.dirname(file), { recursive: true })
142
+ fs.writeFileSync(file, data)
143
+ }
144
+ }
145
+
146
+ if (!fs.existsSync(dest)) {
147
+ throw new Error(`no peer served any file from hyper://${key}`)
148
+ }
149
+ } catch (err) {
150
+ fs.rmSync(dest, { recursive: true, force: true })
151
+ throw err
152
+ } finally {
153
+ await swarm.destroy()
154
+ await drive.close()
155
+ await store.close()
156
+ fs.rmSync(tmp, { recursive: true, force: true })
157
+ }
158
+ }
@@ -131,6 +131,7 @@ export default stowEntry((ipc) => {
131
131
  imageCacheDir: `${storage.root}/image-cache`,
132
132
  inferenceCallsDir: `${storage.root}/inspector`,
133
133
  runReplayDir: `${storage.root}/run-replay`,
134
+ kvCacheChatsDir: `${storage.root}/kv-cache-chats`,
134
135
  logger,
135
136
  fakeModels
136
137
  })