@qvac/harness 1.0.0-rc.22 → 1.0.0-rc.23
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/CHANGELOG.md +59 -0
- package/README.md +1 -0
- package/dist-lib/index.d.ts +4 -1
- package/dist-lib/index.js +12 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +2 -1
- package/dist-lib/lib/contract/completion.d.ts +1 -1
- package/dist-lib/lib/contract/drive.d.ts +24 -0
- package/dist-lib/lib/contract/root-search.d.ts +34 -0
- package/dist-lib/lib/contract/root-search.js +1 -0
- package/dist-lib/lib/contract/run.d.ts +2 -0
- package/dist-lib/lib/helpers/root-search.d.ts +3 -0
- package/dist-lib/lib/helpers/root-search.js +74 -0
- package/dist-lib/lib/machine/completion/metrics.js +3 -1
- package/dist-lib/lib/machine/completion/types.d.ts +2 -0
- package/dist-lib/lib/models/model-catalog-constants.d.ts +1 -0
- package/dist-lib/lib/models/model-catalog-constants.js +5 -1
- package/dist-lib/lib/models/model-catalog.d.ts +10 -3
- package/dist-lib/lib/models/model-catalog.js +14 -8
- package/dist-lib/lib/models/model-delete.js +3 -0
- package/dist-lib/lib/models/model-list.d.ts +2 -1
- package/dist-lib/lib/models/model-list.js +5 -1
- package/dist-lib/lib/models/model-pool.d.ts +5 -0
- package/dist-lib/lib/models/model-pool.js +16 -4
- package/dist-lib/lib/plugins/registry.d.ts +2 -0
- package/dist-lib/lib/residency/index.js +9 -6
- package/dist-lib/lib/spawn.d.ts +9 -0
- package/dist-lib/lib/tools/files/glob.js +24 -2
- package/dist-lib/lib/tools/files/grep.js +47 -18
- package/dist-lib/lib/tools/fs/engine.d.ts +9 -0
- package/dist-lib/lib/tools/fs/engine.js +28 -0
- package/dist-lib/lib/tools/fs/walk.d.ts +3 -0
- package/dist-lib/lib/tools/fs/walk.js +20 -20
- package/dist-lib/lib/tools/toolsets.d.ts +1 -1
- package/dist-lib/lib/tools/toolsets.js +1 -0
- package/dist-lib/plugins/charts/chart-tool.d.ts +8 -0
- package/dist-lib/plugins/charts/chart-tool.js +175 -0
- package/dist-lib/plugins/charts/index.d.ts +16 -0
- package/dist-lib/plugins/charts/index.js +21 -0
- package/dist-lib/plugins/ripgrep/index.d.ts +15 -0
- package/dist-lib/plugins/ripgrep/index.js +28 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/package.json +24 -2
- package/worker/harness-sidecar.mjs +3 -0
|
@@ -4,7 +4,7 @@ import { transferProgress } from '../model-download-progress.js';
|
|
|
4
4
|
import ResourcePuddle from 'resource-puddle';
|
|
5
5
|
import { ModelHandle } from './model-handle.js';
|
|
6
6
|
import { defaultContextSize } from './context.js';
|
|
7
|
-
import { customContextLength } from './model-catalog.js';
|
|
7
|
+
import { customContextLength, speculativeDraft } from './model-catalog.js';
|
|
8
8
|
import { localWeightFile } from './custom-model-cache.js';
|
|
9
9
|
import { GGUF_STUB_MAX_BYTES, parseGgufHeader, readGgufHeaderBytes } from './gguf-header.js';
|
|
10
10
|
import { adrenoSafeKvCache, headSafeKvCache } from './kv-cache.js';
|
|
@@ -94,6 +94,8 @@ export function modelKey(model, opts = {}) {
|
|
|
94
94
|
opts.llama?.['ubatch-size'] ?? '',
|
|
95
95
|
opts.llama?.['kv-offload'] ?? '',
|
|
96
96
|
opts.llama?.['n-cpu-moe'] ?? '',
|
|
97
|
+
opts.llama?.speculative ? 'spec' : '',
|
|
98
|
+
opts.llama?.spec_draft_n_max ?? '',
|
|
97
99
|
opts.slots && opts.slots > 1 ? opts.slots : ''
|
|
98
100
|
].join('\0');
|
|
99
101
|
}
|
|
@@ -424,8 +426,13 @@ export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = cr
|
|
|
424
426
|
? deviceConfig.openclCacheDir()
|
|
425
427
|
: undefined;
|
|
426
428
|
const placement = deviceConfig.device === 'cpu' ? deviceConfig.cpuPlacement?.() : undefined;
|
|
429
|
+
const { speculative, ...llama } = resolved.llama ?? {};
|
|
430
|
+
const draft = speculative ? speculativeDraft(model) : undefined;
|
|
427
431
|
const config = definedFields({
|
|
428
|
-
...
|
|
432
|
+
...llama,
|
|
433
|
+
spec_type: draft?.specType,
|
|
434
|
+
spec_draft_n_max: draft ? llama.spec_draft_n_max : undefined,
|
|
435
|
+
draftModelSrc: draft?.model?.src,
|
|
429
436
|
verbosity: llmVerbosity(),
|
|
430
437
|
system_prompt: '',
|
|
431
438
|
tools: true,
|
|
@@ -446,8 +453,13 @@ export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = cr
|
|
|
446
453
|
? chosen
|
|
447
454
|
: await chooseContext({ ...pending, modelConfig: { ...config } }, chosen);
|
|
448
455
|
const modelConfig = { ...config, ctx_size: ctxSize * slots };
|
|
449
|
-
const { projectionModelSrc: projection, ...loggedConfig } = modelConfig;
|
|
450
|
-
HarnessLog.debug('llm load config', {
|
|
456
|
+
const { projectionModelSrc: projection, draftModelSrc, ...loggedConfig } = modelConfig;
|
|
457
|
+
HarnessLog.debug('llm load config', {
|
|
458
|
+
model,
|
|
459
|
+
projection: Boolean(projection),
|
|
460
|
+
draft: Boolean(draftModelSrc),
|
|
461
|
+
...loggedConfig
|
|
462
|
+
});
|
|
451
463
|
const admission = await beforeLoad?.({ ...pending, modelConfig });
|
|
452
464
|
const loadStarted = Date.now();
|
|
453
465
|
const modelId = await loadClockGuard(model, sdk)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AddonLoaders, ToolDefinition, ToolExecuteContext, ToolFetch } from '../contract/index.ts';
|
|
2
2
|
import type { KnowledgeService } from '../contract/knowledge.ts';
|
|
3
3
|
import type { OcrService } from '../contract/ocr.ts';
|
|
4
|
+
import type { RootSearch } from '../contract/root-search.ts';
|
|
4
5
|
import type { SandboxService } from '../contract/sandbox.ts';
|
|
5
6
|
import type { EgressProxyService } from '../contract/egress-proxy.ts';
|
|
6
7
|
import type { EmbedHost, ModelHost } from '../contract/models.ts';
|
|
@@ -18,6 +19,7 @@ declare module './context.ts' {
|
|
|
18
19
|
embed: EmbedHost;
|
|
19
20
|
knowledge: KnowledgeService;
|
|
20
21
|
ocr: OcrService;
|
|
22
|
+
rootSearch: RootSearch;
|
|
21
23
|
sandbox: SandboxService;
|
|
22
24
|
'egress-proxy': EgressProxyService;
|
|
23
25
|
'image-rounds': MediaRoundServer;
|
|
@@ -10,7 +10,7 @@ import { resolveMainGpu } from '../models/gpu-selection.js';
|
|
|
10
10
|
import { createIdleReaper } from '../models/idle-unload.js';
|
|
11
11
|
import { createLoadRequests } from '../models/load-requests.js';
|
|
12
12
|
import { memoryCapBytes, nextVictim, VictimRank } from '../models/memory-cap.js';
|
|
13
|
-
import { assetBytes, curatedListables, curatedModelAsset, customContextLength, customModelSrc, modelAddonOf } from '../models/model-catalog.js';
|
|
13
|
+
import { assetBytes, curatedListables, curatedModelAsset, customContextLength, customModelSrc, modelAddonOf, speculativeDraft } from '../models/model-catalog.js';
|
|
14
14
|
import { ModelFit } from '../models/model-fit.js';
|
|
15
15
|
import { createModelStatusCache, invalidateModelStatusCache } from '../models/model-list.js';
|
|
16
16
|
import { awaitModelCapacity, contextSize, slotCount, createModelPool, evictIdle, evictIdleWhere, evictIdleWithin, evictModel, evictModelWithin, isResident, leaseCount, loadedModels, loadingModels, modelKey, modelOf, releaseModel, resolveLoadOptions, settledEntries, settledModels } from '../models/model-pool.js';
|
|
@@ -526,7 +526,10 @@ export class Residency {
|
|
|
526
526
|
modelConfig = {
|
|
527
527
|
ctx_size: ctxSize,
|
|
528
528
|
parallel: slots > 1 ? slots : undefined,
|
|
529
|
-
projectionModelSrc: this._projectionFor(model)
|
|
529
|
+
projectionModelSrc: this._projectionFor(model),
|
|
530
|
+
draftModelSrc: target.loadOpts.llama?.speculative
|
|
531
|
+
? speculativeDraft(model)?.model?.src
|
|
532
|
+
: undefined
|
|
530
533
|
};
|
|
531
534
|
}
|
|
532
535
|
const sized = await this._sizeLoad({
|
|
@@ -582,8 +585,8 @@ export class Residency {
|
|
|
582
585
|
}
|
|
583
586
|
async _sizeLoad({ model, modelSrc, modelType, modelConfig }) {
|
|
584
587
|
const downloaded = downloadBytes(modelSrc);
|
|
585
|
-
const { projectionModelSrc, ...config } = modelConfig ?? {};
|
|
586
|
-
const
|
|
588
|
+
const { projectionModelSrc, draftModelSrc, spec_type, spec_draft_n_max, ...config } = modelConfig ?? {};
|
|
589
|
+
const companions = (downloadBytes(projectionModelSrc) ?? 0) + (downloadBytes(draftModelSrc) ?? 0);
|
|
587
590
|
try {
|
|
588
591
|
const sdk = await this.sdk.load();
|
|
589
592
|
const { models } = await sdk.assessModelFit({
|
|
@@ -592,7 +595,7 @@ export class Residency {
|
|
|
592
595
|
const [fit] = models;
|
|
593
596
|
const bytes = fit?.floorBytes ?? downloaded;
|
|
594
597
|
return {
|
|
595
|
-
bytes: bytes === undefined ? undefined : bytes +
|
|
598
|
+
bytes: bytes === undefined ? undefined : bytes + companions,
|
|
596
599
|
tooLarge: fit?.verdict === 'likely-too-large',
|
|
597
600
|
confirmed: fit?.verdict === 'likely-fits' && fit.evidence === 'native-fit'
|
|
598
601
|
};
|
|
@@ -600,7 +603,7 @@ export class Residency {
|
|
|
600
603
|
catch (err) {
|
|
601
604
|
HarnessLog.warn('fit estimate failed', { model, err: errorMessage(err) });
|
|
602
605
|
return {
|
|
603
|
-
bytes: downloaded === undefined ? undefined : downloaded +
|
|
606
|
+
bytes: downloaded === undefined ? undefined : downloaded + companions,
|
|
604
607
|
tooLarge: false,
|
|
605
608
|
confirmed: false
|
|
606
609
|
};
|
package/dist-lib/lib/spawn.d.ts
CHANGED
|
@@ -44,11 +44,20 @@ export interface HarnessMcpServer {
|
|
|
44
44
|
};
|
|
45
45
|
defer?: boolean;
|
|
46
46
|
}
|
|
47
|
+
export interface HarnessChartsOptions {
|
|
48
|
+
theme?: 'dark' | 'light';
|
|
49
|
+
mark?: {
|
|
50
|
+
href: string;
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
47
55
|
export interface HarnessPluginOptions {
|
|
48
56
|
speech?: HarnessSpeechOptions;
|
|
49
57
|
mcp?: {
|
|
50
58
|
servers?: HarnessMcpServer[];
|
|
51
59
|
};
|
|
60
|
+
charts?: HarnessChartsOptions;
|
|
52
61
|
ocr?: boolean;
|
|
53
62
|
[name: string]: unknown;
|
|
54
63
|
}
|
|
@@ -2,7 +2,8 @@ import { relativeKey, searchTargets } from '../fs/targets.js';
|
|
|
2
2
|
import { compileGlob } from '../fs/glob.js';
|
|
3
3
|
import { callDenyRoots, defaultRealpath, isDeniedPath } from '../fs/scope.js';
|
|
4
4
|
import { anchorOf, MAX_LIMIT, pagingError, shownPath, stringArg } from '../fs/tool-path.js';
|
|
5
|
-
import {
|
|
5
|
+
import { engineAnswer } from '../fs/engine.js';
|
|
6
|
+
import { MAX_WALK_MS, walkFiles } from '../fs/walk.js';
|
|
6
7
|
import { folderArg, folderPaths } from './list-dir.js';
|
|
7
8
|
const GLOB_MATCHES = 100;
|
|
8
9
|
function interleaveTopLevel(hits) {
|
|
@@ -71,7 +72,13 @@ export function createGlobTool({ realpath = defaultRealpath, deniedRoots } = {})
|
|
|
71
72
|
const hits = [];
|
|
72
73
|
let walkTruncated = false;
|
|
73
74
|
for (const [index, target] of scoped.targets.entries()) {
|
|
74
|
-
const
|
|
75
|
+
const base = target.folder.replace(/^\/+|\/+$/g, '');
|
|
76
|
+
const walk = await walkTarget(target, {
|
|
77
|
+
include: byName || !base ? pattern : `${base}/${pattern}`,
|
|
78
|
+
includeIgnored,
|
|
79
|
+
deny,
|
|
80
|
+
signal: ctx?.signal
|
|
81
|
+
});
|
|
75
82
|
walkTruncated ||= walk.truncated;
|
|
76
83
|
for (const file of walk.files) {
|
|
77
84
|
const rel = relativeKey(file.key, target.folder);
|
|
@@ -102,3 +109,18 @@ export function createGlobTool({ realpath = defaultRealpath, deniedRoots } = {})
|
|
|
102
109
|
}
|
|
103
110
|
};
|
|
104
111
|
}
|
|
112
|
+
async function walkTarget({ root, folder }, { include, includeIgnored, deny, signal }) {
|
|
113
|
+
const native = root.kind === 'local' ? root.walk : undefined;
|
|
114
|
+
if (native) {
|
|
115
|
+
const walked = await engineAnswer(root, folder, {
|
|
116
|
+
run: () => native({ folder, include, includeIgnored, deny, maxMs: MAX_WALK_MS, signal }),
|
|
117
|
+
found: (answer) => answer.files.length > 0 || answer.truncated,
|
|
118
|
+
includeIgnored,
|
|
119
|
+
signal
|
|
120
|
+
});
|
|
121
|
+
if (walked) {
|
|
122
|
+
return walked;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return walkFiles(root, folder, { includeIgnored });
|
|
126
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { errorMessage } from '../../guards.js';
|
|
2
2
|
import { searchTargets } from '../fs/targets.js';
|
|
3
3
|
import { compileGlob } from '../fs/glob.js';
|
|
4
|
-
import { callDenyRoots, defaultRealpath } from '../fs/scope.js';
|
|
4
|
+
import { callDenyRoots, defaultRealpath, isDeniedPath } from '../fs/scope.js';
|
|
5
5
|
import { DriveSearch } from '../fs/search.js';
|
|
6
6
|
import { anchorOf, MAX_LIMIT, pagingError, shownPath, stringArg } from '../fs/tool-path.js';
|
|
7
|
+
import { engineAnswer } from '../fs/engine.js';
|
|
7
8
|
import { MAX_WALK_ENTRIES, MAX_WALK_MS } from '../fs/walk.js';
|
|
8
9
|
import { folderArg, folderPaths } from './list-dir.js';
|
|
9
10
|
const GREP_MATCHES = 100;
|
|
@@ -103,7 +104,9 @@ export function createGrepTool({ realpath = defaultRealpath, deniedRoots, maxWal
|
|
|
103
104
|
regex,
|
|
104
105
|
caseSensitive,
|
|
105
106
|
includeIgnored: args.includeIgnored === true,
|
|
106
|
-
include: stringArg(args, 'include') ?
|
|
107
|
+
include: stringArg(args, 'include') ? String(args.include).replace(/^\.\//, '') : undefined,
|
|
108
|
+
anchor: anchorOf(ctx),
|
|
109
|
+
signal: ctx?.signal,
|
|
107
110
|
deny,
|
|
108
111
|
maxEntries: maxWalkEntries
|
|
109
112
|
};
|
|
@@ -144,7 +147,7 @@ export function createGrepTool({ realpath = defaultRealpath, deniedRoots, maxWal
|
|
|
144
147
|
};
|
|
145
148
|
}
|
|
146
149
|
function includes(pattern, anchor) {
|
|
147
|
-
const glob = compileGlob(pattern
|
|
150
|
+
const glob = compileGlob(pattern);
|
|
148
151
|
return pattern.includes('/') ? (_name, full) => glob(shownPath(full, anchor)) : glob;
|
|
149
152
|
}
|
|
150
153
|
const reach = (output, lines) => output === 'content' ? lines : TALLY_MATCHES;
|
|
@@ -203,24 +206,50 @@ function noMatches(pattern, { regex, offset, found }) {
|
|
|
203
206
|
}
|
|
204
207
|
return 'no matches';
|
|
205
208
|
}
|
|
206
|
-
function searchTarget({ root, folder }, { search, queries, regex, caseSensitive, includeIgnored, include, deny, maxEntries, maxMatches }) {
|
|
209
|
+
async function searchTarget({ root, folder }, { search, queries, regex, caseSensitive, includeIgnored, include, anchor, signal, deny, maxEntries, maxMatches }) {
|
|
210
|
+
const query = {
|
|
211
|
+
folder,
|
|
212
|
+
queries: [...queries],
|
|
213
|
+
regex,
|
|
214
|
+
caseSensitive,
|
|
215
|
+
includeIgnored,
|
|
216
|
+
maxMatches,
|
|
217
|
+
maxEntries,
|
|
218
|
+
maxMs: MAX_WALK_MS
|
|
219
|
+
};
|
|
207
220
|
if (root.kind === 'hyper' && root.search && !include) {
|
|
208
|
-
return root.search(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
includeIgnored,
|
|
221
|
+
return root.search(query);
|
|
222
|
+
}
|
|
223
|
+
const native = root.kind === 'local' ? await nativeSearch(root, { ...query, include, deny, signal }) : null;
|
|
224
|
+
return (native ??
|
|
225
|
+
search.searchFolder(root, folder, {
|
|
214
226
|
maxMatches,
|
|
215
227
|
maxEntries,
|
|
216
|
-
|
|
217
|
-
|
|
228
|
+
include: include ? includes(include, anchor) : null,
|
|
229
|
+
deny,
|
|
230
|
+
includeIgnored
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
async function nativeSearch(root, query) {
|
|
234
|
+
const native = root.search;
|
|
235
|
+
if (!native) {
|
|
236
|
+
return null;
|
|
218
237
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
includeIgnored
|
|
238
|
+
const found = await engineAnswer(root, query.folder, {
|
|
239
|
+
run: () => native(query),
|
|
240
|
+
found: (answer) => answer.hits.length > 0 || answer.truncated,
|
|
241
|
+
includeIgnored: query.includeIgnored,
|
|
242
|
+
signal: query.signal
|
|
225
243
|
});
|
|
244
|
+
if (!found) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
const hits = found.hits.filter((hit) => !isDeniedPath(hit.file, query.deny));
|
|
248
|
+
const cutShort = found.capped && hits.length < found.hits.length;
|
|
249
|
+
return {
|
|
250
|
+
...found,
|
|
251
|
+
hits,
|
|
252
|
+
capped: hits.length >= query.maxMatches,
|
|
253
|
+
truncated: found.truncated || cutShort
|
|
254
|
+
};
|
|
226
255
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
|
+
import type { DriveRoot } from '../../contract/drive.ts';
|
|
3
|
+
export interface EngineCall<T> {
|
|
4
|
+
run: () => Promise<T>;
|
|
5
|
+
found: (answer: T) => boolean;
|
|
6
|
+
includeIgnored: boolean;
|
|
7
|
+
signal: BareAbortSignal | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function engineAnswer<T>(root: DriveRoot, folder: string, { run, found, includeIgnored, signal }: EngineCall<T>): Promise<T | null>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HIDDEN_DIRS, rootRules, WALK_SKIP_DIRS } from './walk.js';
|
|
2
|
+
async function ignoredFolder(root, folder, { includeIgnored }) {
|
|
3
|
+
const parts = folder.split('/').filter(Boolean);
|
|
4
|
+
if (parts.some((name) => WALK_SKIP_DIRS.has(name))) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (includeIgnored) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const rules = await rootRules(root, folder);
|
|
11
|
+
const isDir = true;
|
|
12
|
+
return parts.some((name, i) => HIDDEN_DIRS.has(name) || rules.ignored(parts.slice(0, i + 1).join('/'), isDir));
|
|
13
|
+
}
|
|
14
|
+
export async function engineAnswer(root, folder, { run, found, includeIgnored, signal }) {
|
|
15
|
+
try {
|
|
16
|
+
const answer = await run();
|
|
17
|
+
if (found(answer)) {
|
|
18
|
+
return answer;
|
|
19
|
+
}
|
|
20
|
+
return (await ignoredFolder(root, folder, { includeIgnored })) ? null : answer;
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
if (signal?.aborted) {
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { DriveRoot, WalkSummary } from '../../contract/drive.ts';
|
|
2
|
+
import { IgnoreRules } from './ignore.ts';
|
|
2
3
|
export declare const WALK_SKIP_DIRS: Set<string>;
|
|
4
|
+
export declare const HIDDEN_DIRS: Set<string>;
|
|
3
5
|
export declare const MAX_WALK_ENTRIES = 10000;
|
|
4
6
|
export declare const MAX_WALK_MS = 30000;
|
|
5
7
|
export interface WalkedFile {
|
|
@@ -20,5 +22,6 @@ export interface WalkOptions {
|
|
|
20
22
|
maxEntries?: number;
|
|
21
23
|
maxMs?: number;
|
|
22
24
|
}
|
|
25
|
+
export declare function rootRules(root: DriveRoot, folder: string): Promise<IgnoreRules>;
|
|
23
26
|
export declare function walkFiles(root: DriveRoot, folder?: string, opts?: WalkOptions): Promise<WalkResult>;
|
|
24
27
|
export declare function streamFiles(root: DriveRoot, folder?: string, opts?: WalkOptions): WalkStream;
|
|
@@ -5,13 +5,29 @@ import { pushQueue } from '../../queue.js';
|
|
|
5
5
|
import { IgnoreRules } from './ignore.js';
|
|
6
6
|
import { displayPath } from './scope.js';
|
|
7
7
|
export const WALK_SKIP_DIRS = new Set(['.git', 'node_modules', '.trash']);
|
|
8
|
-
const HIDDEN_DIRS = new Set(['.hg', '.svn', '.venv', '.cache', '.next']);
|
|
8
|
+
export const HIDDEN_DIRS = new Set(['.hg', '.svn', '.venv', '.cache', '.next']);
|
|
9
9
|
const IGNORE_FILES = ['.gitignore', '.ignore'];
|
|
10
10
|
export const MAX_WALK_ENTRIES = 10_000;
|
|
11
11
|
export const MAX_WALK_MS = 30_000;
|
|
12
12
|
function childKey(dir, name) {
|
|
13
13
|
return dir === '/' ? `/${name}` : `${dir}/${name}`;
|
|
14
14
|
}
|
|
15
|
+
async function withIgnoreFile(root, rules, key) {
|
|
16
|
+
const bytes = await root.drive.get(key);
|
|
17
|
+
const dir = key.slice(0, key.lastIndexOf('/'));
|
|
18
|
+
return bytes === null ? rules : rules.add(dir.slice(1), b4a.toString(bytes, 'utf8'));
|
|
19
|
+
}
|
|
20
|
+
export async function rootRules(root, folder) {
|
|
21
|
+
let rules = new IgnoreRules();
|
|
22
|
+
const parts = folder.split('/').filter(Boolean);
|
|
23
|
+
for (let depth = 0; depth < parts.length; depth++) {
|
|
24
|
+
const dir = '/' + parts.slice(0, depth).join('/');
|
|
25
|
+
for (const name of IGNORE_FILES) {
|
|
26
|
+
rules = await withIgnoreFile(root, rules, childKey(dir, name));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return rules;
|
|
30
|
+
}
|
|
15
31
|
function isIgnoreFile(child, key) {
|
|
16
32
|
return !('dir' in child) && child.value.linkname === null && child.key === key;
|
|
17
33
|
}
|
|
@@ -30,24 +46,8 @@ class Walk {
|
|
|
30
46
|
this.#maxEntries = maxEntries;
|
|
31
47
|
this.#deadline = Date.now() + maxMs;
|
|
32
48
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const dir = key.slice(0, key.lastIndexOf('/'));
|
|
36
|
-
return bytes === null ? rules : rules.add(dir.slice(1), b4a.toString(bytes, 'utf8'));
|
|
37
|
-
}
|
|
38
|
-
async rootRules(folder) {
|
|
39
|
-
let rules = new IgnoreRules();
|
|
40
|
-
if (this.#includeIgnored) {
|
|
41
|
-
return rules;
|
|
42
|
-
}
|
|
43
|
-
const parts = folder.split('/').filter(Boolean);
|
|
44
|
-
for (let depth = 0; depth < parts.length; depth++) {
|
|
45
|
-
const dir = '/' + parts.slice(0, depth).join('/');
|
|
46
|
-
for (const name of IGNORE_FILES) {
|
|
47
|
-
rules = await this.#withIgnoreFile(rules, childKey(dir, name));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return rules;
|
|
49
|
+
rootRules(folder) {
|
|
50
|
+
return this.#includeIgnored ? Promise.resolve(new IgnoreRules()) : rootRules(this.#root, folder);
|
|
51
51
|
}
|
|
52
52
|
async #list(dir) {
|
|
53
53
|
const children = [];
|
|
@@ -71,7 +71,7 @@ class Walk {
|
|
|
71
71
|
for (const name of IGNORE_FILES) {
|
|
72
72
|
const key = childKey(dir, name);
|
|
73
73
|
if (!this.#includeIgnored && children.some((child) => isIgnoreFile(child, key))) {
|
|
74
|
-
rules = await this.#
|
|
74
|
+
rules = await withIgnoreFile(this.#root, rules, key);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
return rules;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Toolset } from '../contract/index.ts';
|
|
2
2
|
export type { Toolset };
|
|
3
|
-
export declare const TOOLSETS: readonly ["web-search", "knowledge", "files", "exec", "http-request", "mcp-call", "image", "diagrams", "music", "coding", "team"];
|
|
3
|
+
export declare const TOOLSETS: readonly ["web-search", "knowledge", "files", "exec", "http-request", "mcp-call", "image", "diagrams", "charts", "music", "coding", "team"];
|
|
4
4
|
export declare function asToolset(value?: string | null): Toolset | null;
|
|
5
5
|
export declare function toolsetEnabled(toolset: Toolset, disabled?: ReadonlyArray<string> | null): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Chart, Mark, ThemeName } from 'qvac-charts';
|
|
2
|
+
import type { ToolDefinition } from '../../lib/contract/index.ts';
|
|
3
|
+
export interface ChartToolOptions {
|
|
4
|
+
chart: typeof Chart;
|
|
5
|
+
theme: ThemeName;
|
|
6
|
+
mark: Mark | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare function createChartTool({ chart, theme, mark }: ChartToolOptions): ToolDefinition;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { isRecord } from '../../lib/guards.js';
|
|
3
|
+
import { retryMemo } from '../../lib/helpers/retry-memo.js';
|
|
4
|
+
const WORDS = ['shape', 'variant', 'highlight', 'scale', 'unit', 'callout'];
|
|
5
|
+
const THEMES = ['dark', 'light'];
|
|
6
|
+
const DATA = {
|
|
7
|
+
type: 'array',
|
|
8
|
+
description: 'One item per label; for several series or moments, one per label and group',
|
|
9
|
+
items: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
label: { type: 'string', description: 'The name: "Rent", "2021", "India"' },
|
|
13
|
+
value: { type: 'number', description: 'Its number, in the scale below' },
|
|
14
|
+
group: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'The series, the moment or the piece; leave out for one series'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
required: ['label', 'value']
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const ANNOTATIONS = {
|
|
23
|
+
type: 'array',
|
|
24
|
+
description: 'At most two short facts, each about one data label; often none',
|
|
25
|
+
items: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
label: { type: 'string', description: 'The data label it is about' },
|
|
29
|
+
text: { type: 'string', description: 'The fact' }
|
|
30
|
+
},
|
|
31
|
+
required: ['label', 'text']
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const loadMaps = retryMemo(async () => import('qvac-charts/maps'));
|
|
35
|
+
export function createChartTool({ chart, theme, mark }) {
|
|
36
|
+
return {
|
|
37
|
+
name: 'create_chart',
|
|
38
|
+
toolset: 'charts',
|
|
39
|
+
skillGated: true,
|
|
40
|
+
description: 'Draw a chart from numbers as an image the user sees in the chat. Describe the data; ' +
|
|
41
|
+
'the chart type, the arithmetic and the layout are chosen for you. Use the numbers the ' +
|
|
42
|
+
'user gave, every one of them; numbers from memory get the source "Approximate, from ' +
|
|
43
|
+
'model knowledge". Returns the attachment id and a one-line summary of what was drawn.',
|
|
44
|
+
parameters: parameters(chart),
|
|
45
|
+
effect: () => 'read',
|
|
46
|
+
resource: (args) => ({ kind: 'chart', label: String(args.title ?? '').slice(0, 80) }),
|
|
47
|
+
execute: (args, ctx) => draw(args, { ctx, chart, theme, mark })
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function draw(args, { ctx, chart, theme, mark }) {
|
|
51
|
+
const spec = specFrom(args);
|
|
52
|
+
if (typeof spec === 'string') {
|
|
53
|
+
return { error: spec };
|
|
54
|
+
}
|
|
55
|
+
if (!ctx?.attach) {
|
|
56
|
+
return { error: 'this device cannot save charts' };
|
|
57
|
+
}
|
|
58
|
+
let drawn;
|
|
59
|
+
try {
|
|
60
|
+
const maps = spec.shape === 'places'
|
|
61
|
+
? await (await loadMaps()).mapsFor(spec.data.map((d) => d.label))
|
|
62
|
+
: undefined;
|
|
63
|
+
drawn = chart.from(spec, { maps });
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (err instanceof RangeError) {
|
|
67
|
+
return { error: err.message };
|
|
68
|
+
}
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
const record = await ctx.attach({
|
|
72
|
+
fileName: `chart-${Date.now()}.svg`,
|
|
73
|
+
mimeType: 'image/svg+xml',
|
|
74
|
+
bytes: b4a.from(drawn.toSVG({ theme: THEMES.find((t) => t === args.theme) ?? theme, mark })),
|
|
75
|
+
raw: true
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
attachments: [
|
|
79
|
+
{ attachmentId: record.id, fileName: record.fileName, byteLength: record.byteLength }
|
|
80
|
+
],
|
|
81
|
+
summary: drawn.summary
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function parameters(chart) {
|
|
85
|
+
const { properties, required } = chart.schema;
|
|
86
|
+
return {
|
|
87
|
+
type: 'object',
|
|
88
|
+
properties: {
|
|
89
|
+
shape: {
|
|
90
|
+
type: 'string',
|
|
91
|
+
enum: properties.shape.enum,
|
|
92
|
+
description: 'ranking: items by size. parts: pieces of a whole. over-time: values across periods. ' +
|
|
93
|
+
'change: the same items at two moments, each item twice. sizes: sizes that differ ' +
|
|
94
|
+
'hugely. places: a map, one value per country; states or cities are a ranking'
|
|
95
|
+
},
|
|
96
|
+
variant: {
|
|
97
|
+
type: 'string',
|
|
98
|
+
enum: properties.variant.enum,
|
|
99
|
+
description: 'Only when the user names a chart type'
|
|
100
|
+
},
|
|
101
|
+
title: { type: 'string', description: 'Short and declarative: the story, with no number' },
|
|
102
|
+
subtitle: { type: 'string', description: 'What is measured, and the year' },
|
|
103
|
+
data: DATA,
|
|
104
|
+
highlight: {
|
|
105
|
+
type: 'string',
|
|
106
|
+
description: 'The one label or group the story is about, copied from the data'
|
|
107
|
+
},
|
|
108
|
+
scale: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
enum: properties.scale.enum,
|
|
111
|
+
description: 'What the numbers are counted in: "30.77 trillion" is 30.77 in trillions'
|
|
112
|
+
},
|
|
113
|
+
unit: {
|
|
114
|
+
type: 'string',
|
|
115
|
+
enum: properties.unit.enum,
|
|
116
|
+
description: 'A currency, percent, or number for anything else'
|
|
117
|
+
},
|
|
118
|
+
annotations: ANNOTATIONS,
|
|
119
|
+
callout: {
|
|
120
|
+
type: 'string',
|
|
121
|
+
enum: properties.callout.enum,
|
|
122
|
+
description: 'share for parts, growth for one series over time, ratio when the top item dwarfs ' +
|
|
123
|
+
'the second, else none; the number is computed for you'
|
|
124
|
+
},
|
|
125
|
+
source: {
|
|
126
|
+
type: 'string',
|
|
127
|
+
description: 'Where the numbers come from; the user\'s own are "User data"'
|
|
128
|
+
},
|
|
129
|
+
theme: {
|
|
130
|
+
type: 'string',
|
|
131
|
+
enum: [...THEMES],
|
|
132
|
+
description: 'Only when the user asks for a light or a dark chart or background'
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
required
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function specFrom(args) {
|
|
139
|
+
const { title, subtitle, source, data } = args;
|
|
140
|
+
if (typeof title !== 'string' || typeof subtitle !== 'string' || typeof source !== 'string') {
|
|
141
|
+
return 'title, subtitle and source must be strings';
|
|
142
|
+
}
|
|
143
|
+
const items = Array.isArray(data) ? data.flatMap(dataItem) : [];
|
|
144
|
+
if (!Array.isArray(data) || items.length !== data.length) {
|
|
145
|
+
return 'data must be a list of { label, value }, with a string label and a number value';
|
|
146
|
+
}
|
|
147
|
+
const spec = { title, subtitle, source, data: items, annotations: notes(args.annotations) };
|
|
148
|
+
for (const key of WORDS) {
|
|
149
|
+
const word = args[key];
|
|
150
|
+
if (typeof word === 'string') {
|
|
151
|
+
spec[key] = word;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return spec;
|
|
155
|
+
}
|
|
156
|
+
function dataItem(item) {
|
|
157
|
+
if (!isRecord(item) || typeof item.label !== 'string' || typeof item.value !== 'number') {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
return [
|
|
161
|
+
{
|
|
162
|
+
label: item.label,
|
|
163
|
+
value: item.value,
|
|
164
|
+
group: typeof item.group === 'string' ? item.group : undefined
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
function notes(value) {
|
|
169
|
+
if (!Array.isArray(value)) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
return value.flatMap((note) => isRecord(note) && typeof note.label === 'string' && typeof note.text === 'string'
|
|
173
|
+
? [{ label: note.label, text: note.text }]
|
|
174
|
+
: []);
|
|
175
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Mark, ThemeName } from 'qvac-charts';
|
|
2
|
+
import type { HarnessPlugin, PluginSetup } from '../../lib/plugins/index.ts';
|
|
3
|
+
export interface ChartsOptions {
|
|
4
|
+
readonly read?: readonly string[];
|
|
5
|
+
readonly theme?: ThemeName;
|
|
6
|
+
readonly mark?: Mark;
|
|
7
|
+
}
|
|
8
|
+
export declare class Charts implements HarnessPlugin {
|
|
9
|
+
readonly name = "charts";
|
|
10
|
+
readonly api = 1;
|
|
11
|
+
readonly read: readonly string[] | undefined;
|
|
12
|
+
private readonly _theme;
|
|
13
|
+
private readonly _mark;
|
|
14
|
+
constructor({ read, theme, mark }?: ChartsOptions);
|
|
15
|
+
setup(): Promise<PluginSetup>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
2
|
+
import { createChartTool } from './chart-tool.js';
|
|
3
|
+
PluginRegistry.requirePeers('charts', {
|
|
4
|
+
'qvac-charts': () => import.meta.resolve('qvac-charts')
|
|
5
|
+
});
|
|
6
|
+
export class Charts {
|
|
7
|
+
name = 'charts';
|
|
8
|
+
api = PluginRegistry.API_VERSION;
|
|
9
|
+
read;
|
|
10
|
+
_theme;
|
|
11
|
+
_mark;
|
|
12
|
+
constructor({ read, theme = 'dark', mark } = {}) {
|
|
13
|
+
this.read = read;
|
|
14
|
+
this._theme = theme;
|
|
15
|
+
this._mark = mark;
|
|
16
|
+
}
|
|
17
|
+
async setup() {
|
|
18
|
+
const { Chart } = await import('qvac-charts');
|
|
19
|
+
return { tools: [createChartTool({ chart: Chart, theme: this._theme, mark: this._mark })] };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HarnessPlugin, PluginSetup } from '../../lib/plugins/index.ts';
|
|
2
|
+
export interface RipgrepOptions {
|
|
3
|
+
maxEntries?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class Ripgrep implements HarnessPlugin {
|
|
6
|
+
#private;
|
|
7
|
+
readonly name = "ripgrep";
|
|
8
|
+
readonly api = 1;
|
|
9
|
+
readonly provides: string[];
|
|
10
|
+
readonly addons: {
|
|
11
|
+
'bare-ripgrep': () => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
constructor({ maxEntries }?: RipgrepOptions);
|
|
14
|
+
setup(): Promise<PluginSetup>;
|
|
15
|
+
}
|