@qvac/core 0.1.2 → 0.1.3

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.
package/README.md CHANGED
@@ -655,14 +655,15 @@ bun run engine:collabora
655
655
  ```
656
656
 
657
657
  The TUI copies its mesh invite to the clipboard on ctrl+y. On a second machine
658
- (or a second terminal):
658
+ (or a second terminal), start `duck` and join from inside it:
659
659
 
660
- ```sh
661
- duck qvac://mesh/…
660
+ ```
661
+ /join qvac://mesh/…
662
662
  ```
663
663
 
664
- A running TUI moves mesh with `/join qvac://mesh/…` — it retires the mesh it is
665
- on, joins that one, and re-resolves the agent and chat from it.
664
+ That retires the mesh it is on, joins the invited one, and re-resolves the agent
665
+ and chat from it. The engine takes an invite live, so joining never needed to be
666
+ a boot argument.
666
667
 
667
668
  `--headless` brings the same stack up with no TUI: it prints the invite and then
668
669
  streams logs (including the sidecar child's own output, which the TUI drops) to
@@ -683,8 +684,7 @@ same replicated stream: load progress, thinking, tokens, tool approvals
683
684
  ```sh
684
685
  npm test # node + bare suites
685
686
  npm run build:schema # regenerate spec/ from schema/ (bare)
686
- bun run duck # build the assistant bundle, then run the TUI on it
687
- bun run duck:warm # run the TUI against the last-built bundle
687
+ bun run duck # run the TUI (no build step)
688
688
  ```
689
689
 
690
690
  The TUI lives in [`tui/`](tui/README.md) and installs as the `duck` command.
@@ -21,6 +21,7 @@ export interface UploadStream<In, Out> extends WatchStream<Out> {
21
21
 
22
22
  // what hrpc hands a duplex handler (its own async iterator hangs - see api/attachments.ts)
23
23
  export interface HandlerFrames<Frame> {
24
+ readonly writeStream?: { readonly destroyed: boolean; readonly destroying: boolean; on(event: 'close', listener: () => void): void; off(event: 'close', listener: () => void): void }
24
25
  on(event: 'data', listener: (frame: Frame) => void): void
25
26
  on(event: 'end', listener: () => void): void
26
27
  on(event: 'error', listener: (err: Error) => void): void
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "Peer-to-peer AI across your devices",
6
6
  "exports": {
@@ -134,8 +134,7 @@
134
134
  "./suspend-lifecycle": {
135
135
  "types": "./dist-lib/lib/suspend-lifecycle.d.ts",
136
136
  "default": "./dist-lib/lib/suspend-lifecycle.js"
137
- },
138
- "./dist/assistant.cjs": "./dist/assistant.cjs"
137
+ }
139
138
  },
140
139
  "bin": {
141
140
  "duck": "./tui/index.mjs"
@@ -143,8 +142,7 @@
143
142
  "scripts": {
144
143
  "build:splash": "node tui/build-splash.mjs",
145
144
  "build:schema": "bare schema/build.ts",
146
- "duck": "node scripts/build-bundle.mjs && bare tui/index.mjs",
147
- "duck:warm": "bare tui/index.mjs",
145
+ "duck": "bare tui/index.mjs",
148
146
  "mesh-peer": "bare examples/mesh-peer.mjs",
149
147
  "mesh-lab": "bare examples/mesh-lab.mjs",
150
148
  "test": "npm run test:node && npm run test:bare && npm run test:addons",
@@ -154,7 +152,7 @@
154
152
  "format": "prettier . --write",
155
153
  "lint": "prettier . --check && lunte && tsc --noEmit",
156
154
  "build:bundle": "node scripts/build-bundle.mjs",
157
- "prepack": "node scripts/build-lib.mjs && node scripts/build-bundle.mjs --minify",
155
+ "prepack": "node scripts/build-lib.mjs",
158
156
  "build:lib": "node scripts/build-lib.mjs",
159
157
  "test:addons": "node --test scripts/addon-externals.test.cjs"
160
158
  },
@@ -218,7 +216,7 @@
218
216
  }
219
217
  },
220
218
  "dependencies": {
221
- "@qvac/harness": "^0.2.1",
219
+ "@qvac/harness": "^0.2.4",
222
220
  "@qvac/skills": "^0.1.3",
223
221
  "asenion": "^0.1.0",
224
222
  "autobee": "2.6.0",
@@ -242,6 +240,7 @@
242
240
  "bare-rpc": "^1.3.7",
243
241
  "bare-semver": "^1.1.0",
244
242
  "bare-storage": "^1.1.0",
243
+ "bare-stow": "^0.1.4",
245
244
  "bare-stream": "^2.13.3",
246
245
  "bare-subprocess": "^6.1.0",
247
246
  "bare-supervisor": "^0.1.1",
@@ -271,6 +270,9 @@
271
270
  "protomux-wakeup": "^2.9.0",
272
271
  "rache": "^1.0.0",
273
272
  "ready-guard": "^1.0.0",
273
+ "ready-resource": "^1.2.0",
274
+ "rocksdb-native": "^3.17.4",
275
+ "safety-catch": "^1.0.3",
274
276
  "scope-lock": "^1.2.4",
275
277
  "streamx": "^2.28.0",
276
278
  "suspendify": "^1.7.2",
@@ -287,7 +289,6 @@
287
289
  "bare-pack": "^2.2.1",
288
290
  "bare-runtime": "^1.30.0",
289
291
  "bare-sidecar": "^0.5.2",
290
- "bare-stow": "^0.1.4",
291
292
  "brittle": "^4.0.2",
292
293
  "holepunch-types": "^0.2.1",
293
294
  "hyperdht": "^6.32.0",
package/tui/README.md CHANGED
@@ -14,25 +14,26 @@ npm i -g @qvac/core # duck
14
14
  In the repo:
15
15
 
16
16
  ```sh
17
- bun run duck # build the assistant bundle, then run
18
- bun run duck:warm # reuse the last-built bundle
17
+ bun run duck # no build step
19
18
  ```
20
19
 
21
- `duck` runs the SAME `dist/assistant.bundle` the desktop app ships — the stow of
22
- `worker/assistant-sidecar.mjs` that `scripts/build-bundle.mjs` builds. `bun run
23
- duck` rebuilds it first, because a stale bundle decodes with the old wire format
24
- and dies on the first call whose encoding changed; a freshly written bundle also
25
- pays a one-time cold start on its first spawn (OS page-cache miss + the
26
- platform's security assessment of the new binary and its native addons). The TUI
27
- host (`index.mjs`, `app.mjs`) is not in that bundle, so while iterating on the
28
- TUI use `duck:warm`. Rebuild after changing any `worker/`, wire, or `lib/`
29
- source.
30
-
31
- The bundle carries its JS but not its native addons: `build-bundle.mjs` offloads
32
- those beside the bundle and leaves the forest out of the tarball, shipping
33
- `dist/prebuilds-manifest.json` instead. `lib/prebuilds.mjs` links this host's
34
- addons back into place from the installed `node_modules` on first run — which is
35
- why an installed `duck` needs no postinstall step.
20
+ `duck` spawns `worker/assistant-sidecar.mjs` — the same entry the desktop app
21
+ stows — and the harness the same way, as files rather than bundles. There is
22
+ nothing to rebuild: every source it runs is read from disk, so an edit to
23
+ `worker/`, `lib/` or the TUI itself takes effect on the next run.
24
+
25
+ A stow bundle is two halves — the JS inlined into it, and the native addons
26
+ offloaded beside it, since dlopen cannot read a path inside a bundle — and it
27
+ earns that split only when the code is relocated away from `node_modules`. The
28
+ desktop and mobile apps do exactly that, and stow their own entries at their own
29
+ build time, from one tree, so their halves cannot disagree. `duck` runs from
30
+ inside `node_modules`, where every addon already sits beside the JS that calls
31
+ it, so a bundle here would only separate a pair that is already together. This
32
+ package published one anyway until 0.1.2, and a `bare-pipe` one patch release
33
+ ahead of the JS calling it hung the sidecar on boot with no error at all.
34
+
35
+ `scripts/build-bundle.mjs` still builds one for anyone who does relocate; it is
36
+ not published.
36
37
 
37
38
  `index.mjs` is the `duck` bin — a `#!/usr/bin/env bare` script, so `bare` has to
38
39
  be on PATH (`bare-runtime` puts it in `node_modules/.bin`). `bare-tui` needs
package/tui/index.mjs CHANGED
@@ -52,19 +52,13 @@ import {
52
52
  import sidecarRunner from 'bare-supervisor/runner/sidecar'
53
53
  import { duplexPair } from '@qvac/harness/transport'
54
54
  import { bootTimer, readBootTiming } from './lib/boot-timing.mjs'
55
- import { ensurePrebuilds } from './lib/prebuilds.mjs'
56
55
  import { ChatApp, credKey } from './app.mjs'
57
56
  import { parseProjectionEnv } from './lib/projection-env.mjs'
58
57
 
59
58
  const skillsDir = path.dirname(
60
59
  path.dirname(new URL(import.meta.resolve('@qvac/skills/skills/weather/SKILL.md')).pathname)
61
60
  )
62
- // The harness the assistant sidecar spawns as its own child — the bundle
63
- // @qvac/harness publishes, resolved through its only dist export's sibling.
64
- const harnessEntry = path.join(
65
- path.dirname(new URL(import.meta.resolve('@qvac/harness/dist/harness.cjs')).pathname),
66
- 'harness.bundle'
67
- )
61
+ const harnessEntry = new URL(import.meta.resolve('@qvac/harness/worker/stow-entry.mjs')).pathname
68
62
 
69
63
  function createCredentialStore() {
70
64
  let engine
@@ -413,27 +407,14 @@ async function startInProcess({ storagePath, deviceName, modelName, logger, onMo
413
407
  }
414
408
  }
415
409
 
416
- // The prod/desktop topology (the default), and the whole integration story:
417
- // this spawns the SAME bundle the desktop app ships — dist/assistant.bundle,
418
- // stowed from worker/assistant-sidecar.mjs by scripts/build-bundle.mjs — and
419
- // speaks to it through a Client. The TUI used to stow a near-copy of that entry
420
- // of its own (tui/sidecar.mjs), which is how the two drifted: the copy built
421
- // its harness in-process while prod spawns one as a further child, and only
422
- // prod ran the credential pusher. One entry means a break here is a break
423
- // there. The child's stdout/stderr are pipes, so native model logs can never
424
- // corrupt this tty — the logger is where that output goes instead: the log file
425
- // always, and stdout too when headless.
410
+ // The default topology: spawn worker/assistant-sidecar.mjs, the same entry the
411
+ // desktop app stows, and speak to it through a Client. Its stdout/stderr are
412
+ // pipes, so native model logs reach the logger rather than this tty.
426
413
  async function startSidecar({ config, logger }) {
427
- const bundle = fileURLToPath(new URL('../dist/assistant.bundle', import.meta.url))
428
- if (!fs.existsSync(bundle)) {
429
- throw new Error('assistant bundle missing — run `npm run build:bundle`')
430
- }
431
- // Both bundles: the assistant spawns the harness, and a published install has
432
- // neither forest on disk until now.
433
- ensurePrebuilds(bundle)
434
- ensurePrebuilds(config.harnessEntry)
414
+ const entry = fileURLToPath(new URL('../worker/stow-entry.mjs', import.meta.url))
415
+ if (!fs.existsSync(entry)) throw new Error(`assistant sidecar entry missing at ${entry}`)
435
416
  const engine = new Client(async () => {
436
- const { ipc, exit } = sidecarRunner(bundle, [JSON.stringify(config)], logger)
417
+ const { ipc, exit } = sidecarRunner(entry, [JSON.stringify(config)], logger)
437
418
  // the loser resolves rather than rejects: an armed rejection outlives the
438
419
  // race, and the child's own clean exit at teardown would then go unhandled
439
420
  const died = exit.then((code) => `sidecar exited (${code}) before ready`)
@@ -0,0 +1,138 @@
1
+ /* global Bare */
2
+ import Supervisor from 'bare-supervisor'
3
+ import stowEntry from 'bare-supervisor/entry'
4
+ import sidecarRunner from 'bare-supervisor/runner/sidecar'
5
+ import { Core, assistantChild, clientSessions } from '../dist-lib/index.js'
6
+ import { DEFAULT_RAG_MODEL } from '../dist-lib/lib/core/files/rag/models.js'
7
+ import { Logger, toLoggerOptions } from '../dist-lib/lib/log.js'
8
+ import { releaseChannel, resolveStorage } from '@qvac/harness/storage'
9
+ import {
10
+ DEFAULT_IMAGE_MODEL_CHOICE,
11
+ DEFAULT_MUSIC_MODEL_CHOICE,
12
+ harnessChild,
13
+ imageClampsFromEnv,
14
+ imageModelFor,
15
+ imageModelFromEnv
16
+ } from '@qvac/harness'
17
+ import { startCredentialPusher } from '../dist-lib/lib/credential-pusher.js'
18
+
19
+ const DEFAULT_KV_CACHE = { kvCacheK: 'q8_0', kvCacheV: 'q8_0' }
20
+
21
+ export default stowEntry((ipc) => {
22
+ const {
23
+ logFlags = {},
24
+ environment = 'local',
25
+ storage: storageOverrides = {},
26
+ skillsDir = undefined,
27
+ wheelsDir = undefined,
28
+ imageEnv = {},
29
+ harnessEntry,
30
+ bootstrapNodes: bootstrapJson = undefined,
31
+ device,
32
+ app = undefined,
33
+ llm = DEFAULT_KV_CACHE,
34
+ hostsModelSource = true,
35
+ eager = true
36
+ } = JSON.parse(Bare.argv[2] || '{}')
37
+
38
+ const bootstrapNodes = bootstrapJson ? JSON.parse(bootstrapJson) : undefined
39
+
40
+ const channel = releaseChannel(environment)
41
+ const storage = resolveStorage(channel, storageOverrides)
42
+ const storagePath = storage.assistant
43
+
44
+ const logFile = logFlags.logFile || `${storage.root}/assistant.log`
45
+ const logger = new Logger(toLoggerOptions({ ...logFlags, logFile }))
46
+
47
+ // Hosts install the image tools by default: without an imageModel the harness
48
+ // registers no generate_image/edit_image, and the image-generation skill then
49
+ // resolves to `unsupported` ("Not available on this device"). Env only picks a
50
+ // different set; per-agent imageModelChoice still overrides at generation time.
51
+ const imageModel =
52
+ imageModelFromEnv(
53
+ imageEnv,
54
+ () =>
55
+ logger.warn(
56
+ 'assistant',
57
+ 'QVAC_IMAGE_MODEL is a catalog choice — ignoring QVAC_IMAGE_LLM/QVAC_IMAGE_VAE/QVAC_IMAGE_PREDICTION'
58
+ ),
59
+ () =>
60
+ logger.warn(
61
+ 'assistant',
62
+ 'QVAC_IMAGE_PREDICTION needs QVAC_IMAGE_LLM and QVAC_IMAGE_VAE (a FLUX set) — ignoring it'
63
+ )
64
+ ) ?? imageModelFor(DEFAULT_IMAGE_MODEL_CHOICE)
65
+ const imageClamps = imageClampsFromEnv(imageEnv)
66
+
67
+ // Same for music: without a musicModel the harness registers no generate_music
68
+ // and the music-generation skill resolves to "Not available on this device".
69
+ // A per-agent choice from the generate_music tool-config still overrides at
70
+ // generation time; the harness resolves the choice string to its ACE-Step stages.
71
+ const musicModel = DEFAULT_MUSIC_MODEL_CHOICE
72
+
73
+ const sup = new Supervisor()
74
+ const sessions = clientSessions(ipc)
75
+ const core = new Core(() => sessions.current, {
76
+ logger,
77
+ storagePath,
78
+ device,
79
+ bootstrapNodes,
80
+ app: app ? { ...app, channel } : undefined,
81
+ hostsModelSource,
82
+ apiLifecycle: {
83
+ suspend: () => sup.suspend(),
84
+ resume: () => sup.resume()
85
+ }
86
+ })
87
+
88
+ // the host resets the session when its renderer reloads: same process, same Core, a fresh
89
+ // client over the one pipe
90
+ ipc.on('session-reset', () => {
91
+ core
92
+ .connect(sessions.reset())
93
+ .catch((err) => logger.warn('assistant-sidecar', 'session reset failed', err?.message))
94
+ })
95
+
96
+ sup.add('core', {
97
+ start: () => core,
98
+ presuspend: (handle) => handle.presuspend(),
99
+ suspend: (handle) => handle.suspend(),
100
+ wakeup: (handle) => handle.wakeup(),
101
+ resume: (handle) => handle.resume()
102
+ })
103
+
104
+ sup.add(
105
+ 'assistant',
106
+ assistantChild({
107
+ // knowledge indexing volunteers this device; rebuilt against each harness incarnation
108
+ embedder: (harness) => ({
109
+ model: DEFAULT_RAG_MODEL,
110
+ embed: ({ texts, signal }) => harness.embed({ model: DEFAULT_RAG_MODEL, texts, signal })
111
+ }),
112
+ harness: harnessChild(harnessEntry, {
113
+ runner: sidecarRunner,
114
+ skillsDir,
115
+ wheelsDir,
116
+ sdkStorage: storage.sdk,
117
+ imageModel,
118
+ imageClamps,
119
+ musicModel,
120
+ llm: { ...llm },
121
+ logger,
122
+ eager
123
+ }),
124
+ onHarness: (harness, { engine }) => startCredentialPusher(harness, engine, logger),
125
+ logger
126
+ })
127
+ )
128
+
129
+ for (const event of ['child-died', 'child-restarting', 'stall']) {
130
+ sup.on(event, (payload) => logger.warn('assistant-sidecar', event, payload))
131
+ }
132
+ sup.on('gave-up', ({ name, error }) =>
133
+ logger.error('assistant-sidecar', `${name} gave up`, error?.message)
134
+ )
135
+ sup.on('power', (payload) => logger.info('assistant-sidecar', 'power', payload))
136
+
137
+ return sup
138
+ })
@@ -0,0 +1,51 @@
1
+ /* global Bare */
2
+ // bare-stow's generated bundle shim (lib/shim.js) as a plain file, so the
3
+ // sidecar can be spawned without stowing one.
4
+ import protocol from 'bare-stow/protocol'
5
+
6
+ const ipc = protocol.attach(Bare.IPC)
7
+
8
+ let stop = null
9
+ let readied = false
10
+ let exited = false
11
+
12
+ function ready() {
13
+ if (readied) return
14
+ readied = true
15
+
16
+ ipc.send('ready')
17
+ }
18
+
19
+ async function shutdown(code, err = null) {
20
+ if (exited) return
21
+ exited = true
22
+
23
+ try {
24
+ if (stop) await stop()
25
+ } catch (e) {
26
+ err = err || e
27
+ }
28
+
29
+ if (err) ipc.send('error', { message: err.message, stack: err.stack })
30
+
31
+ await ipc.send('exit', { code })
32
+
33
+ Bare.exit(code)
34
+ }
35
+
36
+ ipc.on('terminate', () => shutdown(0))
37
+
38
+ Bare.on('beforeExit', (exitCode) => shutdown(exitCode))
39
+ .on('uncaughtException', (err) => shutdown(1, err))
40
+ .on('unhandledRejection', (err) => shutdown(1, err))
41
+
42
+ try {
43
+ const entry = await import('./assistant-sidecar.mjs')
44
+ const start = entry.default
45
+
46
+ stop = (await start(ipc, ready)) || null
47
+
48
+ ready()
49
+ } catch (err) {
50
+ shutdown(1, err)
51
+ }