@qvac/core 0.2.2 → 0.3.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 (50) hide show
  1. package/.claude/skills/compaction/SKILL.md +15 -11
  2. package/.claude/skills/js-house-style/SKILL.md +1 -0
  3. package/.claude/skills/pr-create/SKILL.md +42 -0
  4. package/.claude/skills/pr-review/SKILL.md +4 -0
  5. package/.claude/skills/release/SKILL.md +122 -0
  6. package/CLAUDE.md +7 -2
  7. package/dist-lib/lib/api/agents.js +2 -3
  8. package/dist-lib/lib/api/chat.js +3 -3
  9. package/dist-lib/lib/api/chunks.d.ts +1 -1
  10. package/dist-lib/lib/api/chunks.js +5 -15
  11. package/dist-lib/lib/api/current-mesh.d.ts +16 -1
  12. package/dist-lib/lib/api/current-mesh.js +18 -0
  13. package/dist-lib/lib/api/devices.js +6 -3
  14. package/dist-lib/lib/api/index.js +1 -1
  15. package/dist-lib/lib/api/knowledge.js +11 -7
  16. package/dist-lib/lib/api/members.js +2 -3
  17. package/dist-lib/lib/api/sync.d.ts +1 -1
  18. package/dist-lib/lib/api/sync.js +2 -1
  19. package/dist-lib/lib/api/tool-activity.js +2 -2
  20. package/dist-lib/lib/api/tool-configs.js +2 -2
  21. package/dist-lib/lib/api/watchable.d.ts +6 -1
  22. package/dist-lib/lib/api/watchable.js +13 -2
  23. package/dist-lib/lib/assistant/history.d.ts +1 -2
  24. package/dist-lib/lib/assistant/history.js +0 -6
  25. package/dist-lib/lib/assistant.d.ts +3 -7
  26. package/dist-lib/lib/assistant.js +65 -110
  27. package/dist-lib/lib/core/chunk.d.ts +1 -0
  28. package/dist-lib/lib/core/chunk.js +27 -0
  29. package/dist-lib/lib/core/contract/devices.js +3 -2
  30. package/dist-lib/lib/core/harness-loan.js +1 -1
  31. package/dist-lib/lib/core/local/index.js +6 -0
  32. package/dist-lib/lib/core.d.ts +1 -0
  33. package/dist-lib/lib/core.js +20 -12
  34. package/dist-lib/lib/fs-drive-bridge.js +1 -1
  35. package/dist-lib/lib/mesh-scoped-engine.js +5 -0
  36. package/dist-lib/lib/model-download.d.ts +2 -0
  37. package/dist-lib/lib/model-download.js +20 -5
  38. package/dist-lib/lib/oauth/keys.js +1 -0
  39. package/dist-lib/lib/oauth/spotify.js +1 -0
  40. package/dist-lib/lib/oauth/verify.d.ts +8 -0
  41. package/dist-lib/lib/oauth/verify.js +58 -0
  42. package/dist-lib/lib/oauth.d.ts +1 -0
  43. package/dist-lib/lib/oauth.js +1 -0
  44. package/dist-lib/schema/qvac.d.ts +3 -0
  45. package/dist-lib/schema/qvac.js +7 -0
  46. package/package.json +4 -4
  47. package/tui/app.mjs +327 -46
  48. package/tui/lib/render.mjs +17 -1
  49. package/tui/lib/selection.mjs +16 -0
  50. package/tui/lib/usage.mjs +54 -0
@@ -103,6 +103,17 @@ export class ModelDownloadReconciler {
103
103
  this._paused = false;
104
104
  this._kick();
105
105
  }
106
+ meshSelected() {
107
+ if (this._closed)
108
+ return;
109
+ const agents = this._agentsStream;
110
+ this._agentsStream = null;
111
+ if (agents?.return)
112
+ void agents.return().catch(() => { });
113
+ this._watchAgents();
114
+ this._swapToolConfigsWatch(this._toolConfigsAgentId);
115
+ this._kick();
116
+ }
106
117
  yieldToRuns(models) {
107
118
  if (this._closed)
108
119
  return;
@@ -162,11 +173,11 @@ export class ModelDownloadReconciler {
162
173
  signal.aborted) {
163
174
  return;
164
175
  }
165
- const rows = await this._harness.list({}).catch(() => null);
176
+ const rows = await this._harness.list({}).catch(noop);
166
177
  if (this._closed || this._handled.has(model) || signal.aborted)
167
178
  return;
168
179
  let addon = 'llm';
169
- if (rows !== null) {
180
+ if (rows) {
170
181
  const row = rows.find((entry) => entry.name === model);
171
182
  if (!row || row.isCached)
172
183
  return;
@@ -241,6 +252,9 @@ export class ModelDownloadReconciler {
241
252
  const agentId = this._config?.activeAgentId ?? null;
242
253
  if (agentId === this._toolConfigsAgentId)
243
254
  return;
255
+ this._swapToolConfigsWatch(agentId);
256
+ }
257
+ _swapToolConfigsWatch(agentId) {
244
258
  const previous = this._toolConfigsStream;
245
259
  this._toolConfigsStream = null;
246
260
  this._toolConfigsAgentId = null;
@@ -567,7 +581,7 @@ export class ModelDownloadReconciler {
567
581
  const activeAgentId = this._config?.activeAgentId;
568
582
  if (!activeAgentId)
569
583
  return;
570
- const agent = await this._engine.getAgent({ id: activeAgentId }).catch(() => null);
584
+ const agent = await this._engine.getAgent({ id: activeAgentId }).catch(noop);
571
585
  if (!agent?.modelName)
572
586
  return;
573
587
  if (!agent.providerDeviceId?.equals(this._deviceId))
@@ -593,8 +607,8 @@ export class ModelDownloadReconciler {
593
607
  const configs = await this._engine
594
608
  .listToolConfigs({ agentId })
595
609
  .then((result) => result.configs ?? [])
596
- .catch(() => null);
597
- if (configs === null)
610
+ .catch(noop);
611
+ if (!configs)
598
612
  return { ok: false };
599
613
  const row = configs.find((entry) => entry?.toolName === GENERATE_MUSIC_TOOL);
600
614
  const settings = row?.settings;
@@ -785,3 +799,4 @@ function shouldFlush(previous, percentage, at, intervalMs, percentageStep) {
785
799
  at - previous.at >= intervalMs ||
786
800
  percentage - previous.percentage >= percentageStep);
787
801
  }
802
+ function noop() { }
@@ -47,6 +47,7 @@ export const OAUTH_KEY_SPECS = [
47
47
  stateKey: 'spotify_oauth',
48
48
  provider: 'spotify',
49
49
  scopes: [
50
+ 'user-read-private',
50
51
  'user-read-playback-state',
51
52
  'user-modify-playback-state',
52
53
  'user-read-currently-playing',
@@ -10,6 +10,7 @@ const REDIRECT_URI = oauthRedirectUri(SPOTIFY_OAUTH_PORT);
10
10
  const AUTH_URL = 'https://accounts.spotify.com/authorize';
11
11
  const TOKEN_URL = 'https://accounts.spotify.com/api/token';
12
12
  const SCOPES = [
13
+ 'user-read-private',
13
14
  'user-read-playback-state',
14
15
  'user-modify-playback-state',
15
16
  'user-read-currently-playing',
@@ -0,0 +1,8 @@
1
+ import type { Fetch } from './common.ts';
2
+ export type VerifyResult = {
3
+ ok: true;
4
+ } | {
5
+ ok: false;
6
+ error: string;
7
+ };
8
+ export declare function verifyOAuthTokens(credentialKey: string, accessToken: string, fetch: Fetch): Promise<VerifyResult>;
@@ -0,0 +1,58 @@
1
+ import { oauthKeySpec } from './keys.js';
2
+ export async function verifyOAuthTokens(credentialKey, accessToken, fetch) {
3
+ const provider = oauthKeySpec(credentialKey)?.provider;
4
+ if (provider !== 'asana' && provider !== 'spotify')
5
+ return { ok: true };
6
+ const controller = typeof globalThis.AbortController === 'function' ? new globalThis.AbortController() : null;
7
+ const timer = setTimeout(() => controller?.abort(), 5_000);
8
+ try {
9
+ if (provider === 'asana') {
10
+ const response = await fetch('https://mcp.asana.com/v2/mcp', {
11
+ method: 'POST',
12
+ headers: {
13
+ Authorization: `Bearer ${accessToken}`,
14
+ 'Content-Type': 'application/json',
15
+ Accept: 'application/json, text/event-stream'
16
+ },
17
+ body: JSON.stringify({
18
+ jsonrpc: '2.0',
19
+ id: 1,
20
+ method: 'initialize',
21
+ params: {
22
+ protocolVersion: '2025-03-26',
23
+ capabilities: {},
24
+ clientInfo: { name: 'qvac', version: '1.0.0' }
25
+ }
26
+ }),
27
+ signal: controller?.signal
28
+ });
29
+ if (response.status === 401 || response.status === 403) {
30
+ return { ok: false, error: 'OAuth error: asana_not_mcp_app' };
31
+ }
32
+ return { ok: true };
33
+ }
34
+ const response = await fetch('https://api.spotify.com/v1/me', {
35
+ method: 'GET',
36
+ headers: { Authorization: `Bearer ${accessToken}` },
37
+ signal: controller?.signal
38
+ });
39
+ if (response.status === 401 || response.status === 403)
40
+ return { ok: true };
41
+ if (response.status < 200 || response.status >= 300)
42
+ return { ok: true };
43
+ try {
44
+ const body = (await response.json());
45
+ if (Object.prototype.hasOwnProperty.call(body, 'product') && body.product !== 'premium') {
46
+ return { ok: false, error: 'OAuth error: spotify_premium_required' };
47
+ }
48
+ }
49
+ catch { }
50
+ return { ok: true };
51
+ }
52
+ catch {
53
+ return { ok: true };
54
+ }
55
+ finally {
56
+ clearTimeout(timer);
57
+ }
58
+ }
@@ -11,4 +11,5 @@ export { buildProviderConfig, providerRequiresSecret, providerSupportsDcr, provi
11
11
  export type { OAuthCallbackResult, OAuthRedirect, OAuthRedirectFactory } from './oauth/redirect-types.ts';
12
12
  export { registerOAuthClient, resolveDynamicClientId } from './oauth/register.ts';
13
13
  export { isTokenExpired, refreshOAuthTokens } from './oauth/token-exchange.ts';
14
+ export { verifyOAuthTokens, type VerifyResult } from './oauth/verify.ts';
14
15
  export type { OAuthCredentials, OAuthFlowDeps, OAuthFlowResult, OAuthProvider, OAuthProviderConfig } from './oauth/types.ts';
@@ -10,3 +10,4 @@ export { generatePkceChallenge } from './oauth/pkce.js';
10
10
  export { buildProviderConfig, providerRequiresSecret, providerSupportsDcr, providerSupportsSharedIosSession } from './oauth/providers.js';
11
11
  export { registerOAuthClient, resolveDynamicClientId } from './oauth/register.js';
12
12
  export { isTokenExpired, refreshOAuthTokens } from './oauth/token-exchange.js';
13
+ export { verifyOAuthTokens } from './oauth/verify.js';
@@ -17,6 +17,9 @@ export declare const MAX_TOOL_CONFIGS_BYTES: number;
17
17
  export declare function toolConfigsWithinBounds(settings: unknown): boolean;
18
18
  export declare const MAX_TOOL_ACTIVITY_ARGS_BYTES: number;
19
19
  export declare function capToolActivityArguments(args: unknown): unknown;
20
+ export declare const MAX_DEVICE_NAME_CHARS = 100;
21
+ export declare function deviceNameWithinBounds(name: string): boolean;
22
+ export declare function capDeviceName(name: string): string;
20
23
  export declare function registerQvacTypes(ns: any): void;
21
24
  export declare function registerQvacCollections(dbns: any, helpersPath: string): void;
22
25
  export declare function registerQvacDispatch(ds: any): void;
@@ -36,6 +36,13 @@ export function capToolActivityArguments(args) {
36
36
  return args;
37
37
  return { truncated: true };
38
38
  }
39
+ export const MAX_DEVICE_NAME_CHARS = 100;
40
+ export function deviceNameWithinBounds(name) {
41
+ return name.length <= MAX_DEVICE_NAME_CHARS;
42
+ }
43
+ export function capDeviceName(name) {
44
+ return name.length <= MAX_DEVICE_NAME_CHARS ? name : name.slice(0, MAX_DEVICE_NAME_CHARS);
45
+ }
39
46
  export function registerQvacTypes(ns) {
40
47
  const versioned = versionedRegistrar(ns, 'qvac');
41
48
  registerContentTypes(ns, 'qvac');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/core",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Peer-to-peer AI across your devices",
6
6
  "exports": {
@@ -153,7 +153,7 @@
153
153
  "mesh-recover-account": "bare examples/mesh-recover-account.mjs",
154
154
  "mesh-user-names": "bare examples/mesh-user-names.mjs",
155
155
  "test": "npm run test:bare",
156
- "test:bare": "QVAC_NO_SKILL_BIN_PROBE=1 prettytap -- brittle-bare test/all.ts",
156
+ "test:bare": "QVAC_NO_SKILL_BIN_PROBE=1 brittle-jobs 'test/*.ts' 'test/{api,basic,rag}/**/*.ts' 'test/tui/**/!(helpers).ts'",
157
157
  "test:model": "QVAC_TEST_MODELS=1 npm run test:bare",
158
158
  "format": "prettier . --write",
159
159
  "lint": "prettier . --check && lunte && tsc --noEmit",
@@ -296,6 +296,7 @@
296
296
  "bare-runtime": "^1.30.0",
297
297
  "bare-sidecar": "^0.5.2",
298
298
  "brittle": "^4.0.2",
299
+ "brittle-jobs": "0.2.1",
299
300
  "holepunch-types": "^0.2.2",
300
301
  "hyperdht": "^6.32.0",
301
302
  "hyperschema-regen": "^3.0.1",
@@ -324,8 +325,7 @@
324
325
  "pyodide@314.0.2": "patches/pyodide@314.0.2.patch",
325
326
  "localwatch@1.4.3": "patches/localwatch@1.4.3.patch",
326
327
  "bare-stow@0.1.5": "patches/bare-stow@0.1.5.patch",
327
- "@qvac/inference@0.19.0": "patches/@qvac%2Finference@0.19.0.patch",
328
- "brittle@4.1.0": "patches/brittle@4.1.0.patch"
328
+ "@qvac/inference@0.19.0": "patches/@qvac%2Finference@0.19.0.patch"
329
329
  },
330
330
  "overrides": {
331
331
  "@qvac/asr-ggml": "0.4.2",