@qvac/core 0.1.3 → 0.1.5
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/.claude/skills/asana/SKILL.md +86 -0
- package/.claude/skills/compaction/SKILL.md +127 -0
- package/.claude/skills/device-mesh-debug/SKILL.md +328 -0
- package/.claude/skills/gh-stack/SKILL.md +181 -0
- package/.claude/skills/gh-stack/references/commands.md +177 -0
- package/.claude/skills/gh-stack/references/stack-design.md +97 -0
- package/.claude/skills/gh-stack/references/troubleshooting.md +159 -0
- package/.claude/skills/js-house-style/SKILL.md +670 -0
- package/.claude/skills/pr-create/SKILL.md +137 -0
- package/.claude/skills/pr-review/SKILL.md +147 -0
- package/CLAUDE.md +42 -0
- package/README.md +54 -23
- package/dist-lib/lib/assistant.js +2 -1
- package/dist-lib/lib/core/mesh.d.ts +1 -0
- package/dist-lib/lib/core/mesh.js +25 -1
- package/dist-lib/lib/oauth/common.d.ts +1 -1
- package/dist-lib/lib/oauth/common.js +1 -3
- package/dist-lib/lib/oauth/keys.d.ts +1 -0
- package/dist-lib/lib/oauth/keys.js +3 -0
- package/ducks.png +0 -0
- package/package.json +3 -2
- package/tui/README.md +15 -14
- package/tui/app.mjs +27 -18
- package/tui/boot.mjs +141 -0
- package/tui/index.mjs +34 -617
- package/tui/lib/render.mjs +4 -0
- package/tui/main.mjs +284 -0
package/tui/app.mjs
CHANGED
|
@@ -5,29 +5,23 @@
|
|
|
5
5
|
import tui from 'bare-tui'
|
|
6
6
|
import { spawn } from 'child_process'
|
|
7
7
|
import fs from 'fs'
|
|
8
|
-
import {
|
|
8
|
+
import { TOOLSETS } from '@qvac/harness/lib/tools/toolsets.ts'
|
|
9
9
|
import os from 'os'
|
|
10
10
|
import path from 'path'
|
|
11
11
|
import process from 'process'
|
|
12
12
|
import {
|
|
13
13
|
ASANA_MCP_CREDENTIAL_KEY,
|
|
14
|
-
ASANA_OAUTH_STATE_KEY,
|
|
15
|
-
connectAsana,
|
|
16
|
-
connectGoogle,
|
|
17
|
-
connectNotion,
|
|
18
|
-
connectSpotify,
|
|
19
|
-
oauthKeySpec,
|
|
20
14
|
NOTION_MCP_CREDENTIAL_KEY,
|
|
21
|
-
|
|
15
|
+
oauthKeySpec,
|
|
22
16
|
scopedKey,
|
|
23
|
-
SPOTIFY_CREDENTIAL_KEY
|
|
24
|
-
|
|
25
|
-
} from '../dist-lib/lib/oauth.js'
|
|
17
|
+
SPOTIFY_CREDENTIAL_KEY
|
|
18
|
+
} from '../dist-lib/lib/oauth/keys.js'
|
|
26
19
|
import {
|
|
27
20
|
busyStatus,
|
|
28
21
|
findPendingApproval,
|
|
29
22
|
runInFlight,
|
|
30
23
|
runningAgentTurn,
|
|
24
|
+
turnDone,
|
|
31
25
|
turnsFromChunks
|
|
32
26
|
} from './lib/render.mjs'
|
|
33
27
|
import { exportMarkdown } from './lib/export.mjs'
|
|
@@ -524,8 +518,11 @@ export function renderTurn(turn, agentName, deviceLabels, opts = {}) {
|
|
|
524
518
|
const label = turn.from === 'user' ? fg.cyan.render(userLabel) : fg.magenta.render(agentName)
|
|
525
519
|
const lines = [`${label}:`]
|
|
526
520
|
for (const segment of turn.segments) {
|
|
527
|
-
if (segment.type === 'thinking')
|
|
528
|
-
|
|
521
|
+
if (segment.type === 'thinking') {
|
|
522
|
+
// a model that skips its reasoning still streams the think tags' newlines
|
|
523
|
+
const thought = segment.text.trim()
|
|
524
|
+
if (thought) lines.push(fg.dim.render(` (thinking: ${thought})`))
|
|
525
|
+
} else if (segment.type === 'tool-call') {
|
|
529
526
|
const call = ` → ${segment.detail.name}(${JSON.stringify(segment.detail.arguments)})`
|
|
530
527
|
lines.push(fg.amber.render(clampTool(call, opts)))
|
|
531
528
|
} else if (segment.type === 'tool-result') {
|
|
@@ -560,7 +557,14 @@ export function renderTurn(turn, agentName, deviceLabels, opts = {}) {
|
|
|
560
557
|
: `${name}(${JSON.stringify(args)})`
|
|
561
558
|
if (status === 'pending') lines.push(fg.amber.render(` allow ${call}? [y/a/n]`))
|
|
562
559
|
else lines.push(fg.dim.render(` [${status}] ${call}`))
|
|
563
|
-
} else
|
|
560
|
+
} else {
|
|
561
|
+
// a model streams newlines between its tool calls; the … is the answer still to come
|
|
562
|
+
const text = segment.text.trim()
|
|
563
|
+
if (text) lines.push(fg.white.render(` ${text}`))
|
|
564
|
+
else if (!turnDone(turn) && segment === turn.segments.at(-1)) {
|
|
565
|
+
lines.push(fg.white.render(' …'))
|
|
566
|
+
}
|
|
567
|
+
}
|
|
564
568
|
}
|
|
565
569
|
if (turn.status === 'failed') {
|
|
566
570
|
lines.push(fg.err.render(` [failed${turn.statusReason ? `: ${turn.statusReason}` : ''}]`))
|
|
@@ -1397,11 +1401,12 @@ export class ChatApp {
|
|
|
1397
1401
|
if (field === 'size') {
|
|
1398
1402
|
const match = /^(\d+)x(\d+)$/.exec(value ?? '')
|
|
1399
1403
|
if (!match) return notice(USAGE)
|
|
1400
|
-
// persist through the runtime's own clamp/snap so the stored size is the effective one
|
|
1401
|
-
const width = settingsDimension(Number(match[1]))
|
|
1402
|
-
const height = settingsDimension(Number(match[2]))
|
|
1403
|
-
if (!width || !height) return notice(USAGE)
|
|
1404
1404
|
return run(async () => {
|
|
1405
|
+
// persist through the runtime's own clamp/snap so the stored size is the effective one
|
|
1406
|
+
const { settingsDimension } = await import('@qvac/harness/lib/tools/generate-image.ts')
|
|
1407
|
+
const width = settingsDimension(Number(match[1]))
|
|
1408
|
+
const height = settingsDimension(Number(match[2]))
|
|
1409
|
+
if (!width || !height) return USAGE
|
|
1405
1410
|
await engine.updateAgent({ id: agent.id, imageWidth: width, imageHeight: height })
|
|
1406
1411
|
return `image size set to ${width}x${height}`
|
|
1407
1412
|
})
|
|
@@ -1722,6 +1727,7 @@ export class ChatApp {
|
|
|
1722
1727
|
return notice('set GOOGLE_OAUTH_CLIENT_ID and GOOGLE_OAUTH_CLIENT_SECRET, then retry')
|
|
1723
1728
|
}
|
|
1724
1729
|
return run(async () => {
|
|
1730
|
+
const { connectGoogle } = await import('../dist-lib/lib/oauth.js')
|
|
1725
1731
|
const tokens = await connectGoogle({
|
|
1726
1732
|
clientId,
|
|
1727
1733
|
clientSecret,
|
|
@@ -1754,6 +1760,7 @@ export class ChatApp {
|
|
|
1754
1760
|
return notice('set SPOTIFY_OAUTH_CLIENT_ID, then retry')
|
|
1755
1761
|
}
|
|
1756
1762
|
return run(async () => {
|
|
1763
|
+
const { connectSpotify, SPOTIFY_OAUTH_STATE_KEY } = await import('../dist-lib/lib/oauth.js')
|
|
1757
1764
|
const tokens = await connectSpotify({
|
|
1758
1765
|
clientId,
|
|
1759
1766
|
openUrl: (url) => {
|
|
@@ -1779,6 +1786,7 @@ export class ChatApp {
|
|
|
1779
1786
|
}
|
|
1780
1787
|
if (provider === 'notion') {
|
|
1781
1788
|
return run(async () => {
|
|
1789
|
+
const { connectNotion, NOTION_OAUTH_STATE_KEY } = await import('../dist-lib/lib/oauth.js')
|
|
1782
1790
|
const tokens = await connectNotion({
|
|
1783
1791
|
openUrl: (url) => {
|
|
1784
1792
|
this.status = fg.dim.render(`authorize in your browser: ${url}`)
|
|
@@ -1808,6 +1816,7 @@ export class ChatApp {
|
|
|
1808
1816
|
return notice('set ASANA_OAUTH_CLIENT_ID and ASANA_OAUTH_CLIENT_SECRET, then retry')
|
|
1809
1817
|
}
|
|
1810
1818
|
return run(async () => {
|
|
1819
|
+
const { connectAsana, ASANA_OAUTH_STATE_KEY } = await import('../dist-lib/lib/oauth.js')
|
|
1811
1820
|
const tokens = await connectAsana({
|
|
1812
1821
|
clientId,
|
|
1813
1822
|
clientSecret,
|
package/tui/boot.mjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// The engine side of the TUI: storage resolution, the log, the sidecar the
|
|
2
|
+
// stack comes up in, and the Client that speaks to it. main.mjs draws its
|
|
3
|
+
// first frame before importing this, so the ~1200 modules behind it load
|
|
4
|
+
// behind "starting up…" rather than in front of it.
|
|
5
|
+
import fs from 'bare-fs'
|
|
6
|
+
import os from 'bare-os'
|
|
7
|
+
import process from 'bare-process'
|
|
8
|
+
import { fileURLToPath } from 'bare-url'
|
|
9
|
+
import path from 'path'
|
|
10
|
+
import { Client } from '../dist-lib/lib/client.js'
|
|
11
|
+
import { Logger, toLoggerOptions } from '../dist-lib/lib/log.js'
|
|
12
|
+
import { configureSdkStorage } from '@qvac/harness/sdk-storage'
|
|
13
|
+
import { MODEL_CACHE_PATH_ENV, releaseChannel, resolveStorage } from '@qvac/harness/storage'
|
|
14
|
+
import sidecarRunner from 'bare-supervisor/runner/sidecar'
|
|
15
|
+
|
|
16
|
+
const skillsDir = path.dirname(
|
|
17
|
+
path.dirname(new URL(import.meta.resolve('@qvac/skills/skills/weather/SKILL.md')).pathname)
|
|
18
|
+
)
|
|
19
|
+
const harnessEntry = new URL(import.meta.resolve('@qvac/harness/worker/stow-entry.mjs')).pathname
|
|
20
|
+
const sidecarEntry = fileURLToPath(new URL('../worker/stow-entry.mjs', import.meta.url))
|
|
21
|
+
if (!fs.existsSync(sidecarEntry)) {
|
|
22
|
+
throw new Error(`assistant sidecar entry missing at ${sidecarEntry}`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Spawn worker/assistant-sidecar.mjs, the same entry the desktop app stows,
|
|
26
|
+
// and speak to it through a Client. Its stdout/stderr are pipes, so native
|
|
27
|
+
// model logs reach the logger rather than this tty.
|
|
28
|
+
async function startSidecar({ entry, config, logger }) {
|
|
29
|
+
const engine = new Client(async () => {
|
|
30
|
+
const { ipc, exit } = sidecarRunner(entry, [JSON.stringify(config)], logger)
|
|
31
|
+
// the loser resolves rather than rejects: an armed rejection outlives the
|
|
32
|
+
// race, and the child's own clean exit at teardown would then go unhandled
|
|
33
|
+
const died = exit.then((code) => `sidecar exited (${code}) before ready`)
|
|
34
|
+
const failure = await Promise.race([ipc.ready.then(() => null), died])
|
|
35
|
+
if (failure) throw new Error(failure)
|
|
36
|
+
return ipc
|
|
37
|
+
})
|
|
38
|
+
await engine.ready()
|
|
39
|
+
return {
|
|
40
|
+
engine,
|
|
41
|
+
close: () => engine.close(),
|
|
42
|
+
skills: async (agentId, modelName) => (await engine.skills({ agentId, modelName })).skills ?? []
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Storage precedence: --storage <dir> > QVAC_STORAGE > --temp/QVAC_TEMP=1
|
|
47
|
+
// throwaway > the persistent global default. Joining a mesh is /join inside the
|
|
48
|
+
// app — the engine takes an invite live, so it never needed to be a flag.
|
|
49
|
+
// Resolves once the engine answers: the connection, its teardown, and the
|
|
50
|
+
// timings the boot report prints (QVAC_BOOT_TIMING=1).
|
|
51
|
+
export default async function boot(args) {
|
|
52
|
+
const connectStart = Date.now()
|
|
53
|
+
// Only override the agent's model when QVAC_MODEL is EXPLICITLY set — otherwise
|
|
54
|
+
// resuming a shared mesh would silently rewrite the desktop's agent to this
|
|
55
|
+
// demo default. `recommendedModel` is just the device-row hint on first mint.
|
|
56
|
+
const modelOverride = process.env.QVAC_MODEL || null
|
|
57
|
+
const recommendedModel = modelOverride || 'Qwen3.5-9B-Q4_K_M'
|
|
58
|
+
// Default storage IS the desktop app's own release root, so the TUI resumes
|
|
59
|
+
// the same mesh + chats the desktop persists there. One at a time — quit the
|
|
60
|
+
// desktop first, the corestore is single-writer; only safe across matching
|
|
61
|
+
// Core/schema versions. configureSdkStorage points the SDK at this root's
|
|
62
|
+
// private sdk-home and the shared model cache, before the SDK's first load so
|
|
63
|
+
// spawned children inherit both.
|
|
64
|
+
const useTemp = args.temp || process.env.QVAC_TEMP === '1'
|
|
65
|
+
const explicitRoot =
|
|
66
|
+
args.storage ||
|
|
67
|
+
process.env.QVAC_STORAGE ||
|
|
68
|
+
(useTemp ? fs.mkdtempSync(path.join(os.tmpdir(), 'duck-')) : null)
|
|
69
|
+
const environment = process.env.QVAC_ENV || 'local'
|
|
70
|
+
const storage = resolveStorage(releaseChannel(environment), {
|
|
71
|
+
root: explicitRoot,
|
|
72
|
+
models: process.env[MODEL_CACHE_PATH_ENV] ?? null
|
|
73
|
+
})
|
|
74
|
+
const storagePath = storage.assistant
|
|
75
|
+
fs.mkdirSync(storagePath, { recursive: true })
|
|
76
|
+
configureSdkStorage(storage.sdk)
|
|
77
|
+
const deviceName = `duck-${process.pid}`
|
|
78
|
+
// Every run logs; only the destination differs. Both modes write
|
|
79
|
+
// <storage.root>/assistant.log — the same file the desktop app writes, and
|
|
80
|
+
// the only way to read a TUI session's engine and sidecar output, since
|
|
81
|
+
// anything printed outside bare-tui's renderer corrupts the frame. Headless
|
|
82
|
+
// owns nothing on the tty, so it streams to stdout as well.
|
|
83
|
+
const logFile = process.env.QVAC_LOG_FILE || path.join(storage.root, 'assistant.log')
|
|
84
|
+
const logger = new Logger(
|
|
85
|
+
toLoggerOptions({ logFile, logLevel: process.env.QVAC_LOG_LEVEL, logVerbose: args.headless })
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
const { engine, close, skills } = await startSidecar({
|
|
89
|
+
entry: sidecarEntry,
|
|
90
|
+
// worker/assistant-sidecar.mjs's own contract, verbatim: it resolves
|
|
91
|
+
// its storage, logger and image set from this, and spawns the
|
|
92
|
+
// harness child from harnessEntry. Everything it leaves out keeps
|
|
93
|
+
// that entry's default (llm kv-cache, hostsModelSource, eager).
|
|
94
|
+
config: {
|
|
95
|
+
environment,
|
|
96
|
+
// ALREADY resolved, not the overrides this host resolved from.
|
|
97
|
+
// worker/assistant-sidecar.mjs calls resolveStorage again, and by
|
|
98
|
+
// then configureSdkStorage (below) has exported SDK_HOME_ENV,
|
|
99
|
+
// which resolveStorage reads as the base a relative root hangs
|
|
100
|
+
// off: a null root would re-resolve to <root>/sdk-home/qvac/<ch>
|
|
101
|
+
// — a second, empty mesh beside the real one, with an empty model
|
|
102
|
+
// cache to match. Passing both values makes that call a
|
|
103
|
+
// pass-through.
|
|
104
|
+
storage: { root: storage.root, models: storage.sdk.models },
|
|
105
|
+
logFlags: {
|
|
106
|
+
logFile,
|
|
107
|
+
logLevel: process.env.QVAC_LOG_LEVEL,
|
|
108
|
+
logVerbose: args.headless
|
|
109
|
+
},
|
|
110
|
+
skillsDir,
|
|
111
|
+
harnessEntry,
|
|
112
|
+
// only the image keys cross: the arg is argv on a spawned process,
|
|
113
|
+
// readable by anything that can list processes
|
|
114
|
+
imageEnv: Object.fromEntries(
|
|
115
|
+
Object.entries(process.env).filter(([key]) => key.startsWith('QVAC_IMAGE_'))
|
|
116
|
+
),
|
|
117
|
+
device: {
|
|
118
|
+
name: deviceName,
|
|
119
|
+
capabilityProfile: 'mid',
|
|
120
|
+
recommendedModelName: recommendedModel
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
logger
|
|
124
|
+
})
|
|
125
|
+
// The device id IS the device's public key — the raw 32-byte buffer end to
|
|
126
|
+
// end (schema fixed32), never a hex string.
|
|
127
|
+
const deviceId = (await engine.deviceInfo({})).id
|
|
128
|
+
const meshInvite = (await engine.meshInvite({})).invite ?? null
|
|
129
|
+
return {
|
|
130
|
+
engine,
|
|
131
|
+
skills,
|
|
132
|
+
close,
|
|
133
|
+
deviceId,
|
|
134
|
+
meshInvite,
|
|
135
|
+
modelName: modelOverride,
|
|
136
|
+
storagePath,
|
|
137
|
+
logFile,
|
|
138
|
+
deviceName,
|
|
139
|
+
connectMs: Date.now() - connectStart
|
|
140
|
+
}
|
|
141
|
+
}
|