@qvac/harness 1.0.0-rc.21 → 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.
Files changed (61) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +2 -0
  3. package/dist-lib/index.d.ts +4 -1
  4. package/dist-lib/index.js +12 -4
  5. package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +3 -1
  6. package/dist-lib/lib/capabilities/completion-engine/tool-outcome.js +2 -4
  7. package/dist-lib/lib/capabilities/tool-turns/answered.d.ts +15 -0
  8. package/dist-lib/lib/capabilities/tool-turns/answered.js +16 -0
  9. package/dist-lib/lib/capabilities/tool-turns.d.ts +2 -0
  10. package/dist-lib/lib/capabilities/tool-turns.js +1 -0
  11. package/dist-lib/lib/contract/completion.d.ts +2 -1
  12. package/dist-lib/lib/contract/drive.d.ts +24 -0
  13. package/dist-lib/lib/contract/root-search.d.ts +34 -0
  14. package/dist-lib/lib/contract/root-search.js +1 -0
  15. package/dist-lib/lib/contract/run.d.ts +2 -0
  16. package/dist-lib/lib/helpers/root-search.d.ts +3 -0
  17. package/dist-lib/lib/helpers/root-search.js +74 -0
  18. package/dist-lib/lib/machine/completion/actions/tools.js +7 -1
  19. package/dist-lib/lib/machine/completion/metrics.js +3 -1
  20. package/dist-lib/lib/machine/completion/types.d.ts +2 -0
  21. package/dist-lib/lib/models/model-catalog-constants.d.ts +1 -0
  22. package/dist-lib/lib/models/model-catalog-constants.js +5 -1
  23. package/dist-lib/lib/models/model-catalog.d.ts +10 -3
  24. package/dist-lib/lib/models/model-catalog.js +14 -8
  25. package/dist-lib/lib/models/model-delete.js +3 -0
  26. package/dist-lib/lib/models/model-list.d.ts +2 -1
  27. package/dist-lib/lib/models/model-list.js +5 -1
  28. package/dist-lib/lib/models/model-pool.d.ts +5 -0
  29. package/dist-lib/lib/models/model-pool.js +16 -4
  30. package/dist-lib/lib/plugins/registry.d.ts +2 -0
  31. package/dist-lib/lib/residency/index.js +9 -6
  32. package/dist-lib/lib/spawn.d.ts +9 -0
  33. package/dist-lib/lib/tools/files/glob.js +71 -10
  34. package/dist-lib/lib/tools/files/grep.js +65 -22
  35. package/dist-lib/lib/tools/files/read-file.js +120 -76
  36. package/dist-lib/lib/tools/fs/engine.d.ts +9 -0
  37. package/dist-lib/lib/tools/fs/engine.js +28 -0
  38. package/dist-lib/lib/tools/fs/suggest.d.ts +8 -0
  39. package/dist-lib/lib/tools/fs/suggest.js +110 -0
  40. package/dist-lib/lib/tools/fs/tool-path.d.ts +3 -0
  41. package/dist-lib/lib/tools/fs/tool-path.js +13 -0
  42. package/dist-lib/lib/tools/fs/walk.d.ts +3 -0
  43. package/dist-lib/lib/tools/fs/walk.js +20 -20
  44. package/dist-lib/lib/tools/toolsets.d.ts +1 -1
  45. package/dist-lib/lib/tools/toolsets.js +2 -0
  46. package/dist-lib/plugins/charts/chart-tool.d.ts +8 -0
  47. package/dist-lib/plugins/charts/chart-tool.js +175 -0
  48. package/dist-lib/plugins/charts/index.d.ts +16 -0
  49. package/dist-lib/plugins/charts/index.js +21 -0
  50. package/dist-lib/plugins/diagrams/draw.d.ts +10 -0
  51. package/dist-lib/plugins/diagrams/draw.js +90 -0
  52. package/dist-lib/plugins/diagrams/index.d.ts +13 -0
  53. package/dist-lib/plugins/diagrams/index.js +15 -0
  54. package/dist-lib/plugins/diagrams/render.d.ts +16 -0
  55. package/dist-lib/plugins/diagrams/render.js +285 -0
  56. package/dist-lib/plugins/ripgrep/index.d.ts +15 -0
  57. package/dist-lib/plugins/ripgrep/index.js +28 -0
  58. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  59. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  60. package/package.json +28 -2
  61. package/worker/harness-sidecar.mjs +5 -0
package/CHANGELOG.md CHANGED
@@ -21,6 +21,57 @@ breaking change is listed under Changed and Removed.
21
21
 
22
22
  ### Added
23
23
 
24
+ - `plugins/ripgrep` lets `grep` and `glob` search a shared local folder with ripgrep's engine instead
25
+ of walking and reading the drive in JavaScript, so a tree past the 10,000-entry walk cap is searched
26
+ whole. A regex the engine rejects falls back to the JS engine. A local root takes an optional `search`
27
+ and `walk`, set from the new `rootSearch` service; with no such plugin nothing changes. The native
28
+ addon is `bare-ripgrep`, a new optional peer. (#889)
29
+
30
+ - `grep` takes `caseSensitive` to match exact case, and `grep` and `glob` take `includeIgnored` to also
31
+ search what `.gitignore`, `.ignore` and cache folders leave out; `.git`, `node_modules` and `.trash`
32
+ stay skipped. `glob` takes `limit` (default 100, at most 500) and `offset`. A `glob` that finds more
33
+ than 100 paths, with neither set, now samples across the top-level folders instead of taking the
34
+ newest 100, and says so in a `note`; with `limit` or `offset` it pages newest first as before.
35
+ (#888)
36
+ - A host turns on speculative decoding with `llmLoad: { speculative: true }`. Qwen3.8-27B, the one
37
+ catalog model with a drafter (`QWEN3_8_27B_DFLASH2_Q8_0`), then decodes about 1.5× faster: 79 to
38
+ 119 tokens a second on an H100, for about 45 ms more to the first token. The drafter downloads with
39
+ the model, counts toward the memory cap and is deleted with it, and a round's metrics carry
40
+ `draftTokens` and `draftAcceptedTokens`. It is read when the harness is created, so switching it
41
+ means a restart. (#884)
42
+ - A `Diagrams` plugin gives the model `draw_diagram`: a diagram type and its links in, and the
43
+ Mermaid block the app renders out, as the run's reply. It draws flowcharts, sequence, state,
44
+ ER and class diagrams, mind maps, timelines, Gantt charts and pies, escapes every label itself,
45
+ and draws a horizontal sequence as a numbered `flowchart LR`, but only when a user turn asks for
46
+ horizontal, left to right or sideways in words. It sits in a new `diagrams`
47
+ toolset, and the shipped sidecar registers it with its read grant. On the diagrams pack, with the
48
+ `diagrams` skill that declares it, the 2B succeeds in 180 of 198 runs against 161 and draws no
49
+ broken diagram against 12; the 4B 180 against 170, with none broken against 18.
50
+ ```js
51
+ new Harness({ plugins: [new Diagrams({ read: ['draw_diagram'] })] })
52
+ ```
53
+ (#892)
54
+ - `answeredToolTurns` and `isAnswer` in `@qvac/harness/lib/capabilities/tool-turns`: a call whose
55
+ result answered the run (`{ content, answer: true }`) has no round after it, so a host that
56
+ rebuilds a chat from its own record replays it with these, before the run's reply. (#892)
57
+ - `ToolExecuteContext.userTurns`: the user's turns as the host sent them, so a tool can check an
58
+ argument the model sent against what was asked. (#892)
59
+ - A `Charts` plugin gives the model `create_chart`: the model describes the numbers, and
60
+ [qvac-charts](https://github.com/tetherto/qvac-charts) picks the chart, computes shares and
61
+ growth, and draws a 1080×1350 SVG, saved as a chat attachment. A map of countries is drawn on
62
+ the world, or on the one continent that holds them all. The result carries a one-line
63
+ summary of what was drawn, so the model can talk about it without seeing it. A host sets the
64
+ default theme, which the model overrides when the user asks for a light or dark chart, and
65
+ passes its own brand mark; the plugin ships no logo. It sits in a new `charts`
66
+ toolset, is skill-gated, and the shipped sidecar registers it with its read grant and the
67
+ options in `pluginOptions.charts`. `qvac-charts` is a new optional peer.
68
+
69
+ ```js
70
+ new Harness({ plugins: [new Charts({ read: ['create_chart'], theme: 'light', mark })] })
71
+ ```
72
+
73
+ (#901)
74
+
24
75
  - Workspace skills run in every chat of the workspace. Send them as `workspaceSkills`, shaped like
25
76
  `projectSkills`. On a name clash the project's skill wins over the workspace's, and the workspace's
26
77
  over your own. A workspace skill with a script asks each member by its hash, as a project skill
@@ -586,6 +637,40 @@ breaking change is listed under Changed and Removed.
586
637
 
587
638
  ### Changed
588
639
 
640
+ - **Breaking** for a host that spawns the shipped sidecar: install `qvac-charts`, which the
641
+ `charts` plugin checks on import, or the sidecar throws at boot. npm does not install an
642
+ optional peer, and a host with its own entry that leaves out `Charts` needs nothing. See
643
+ [Plugin dependencies](docs/hosting.md#plugin-dependencies). (#901)
644
+
645
+ - Two calls in one round whose results each answer the run (`{ content, answer: true }`) both
646
+ reach the reply, joined in order; only the first did before. (#892)
647
+
648
+ - **Breaking:** image generation defaults to FLUX.2 Klein off phones.
649
+ `DEFAULT_IMAGE_MODEL_CHOICE` is `flux2-klein`, where it was `sd2`, so an
650
+ agent with the image-generation skill and no `imageModelChoice` has
651
+ `skillModelsForAgent` and `modelsForAgent` answer `FLUX.2-Klein-4B-Q4_0`.
652
+ FLUX.2 Klein is 5.1 GB with its text encoder and VAE (Stable Diffusion 2.1
653
+ is 2.3 GB), needs a GPU, and edits from several reference images. On a
654
+ mobile host the default stays `sd2`, the one choice that runs on a CPU:
655
+ `modelsForAgent(agent, host)` answers it, and `defaultImageModelChoice(host)`
656
+ gives a host the same answer for its `Image` plugin, which still takes its
657
+ model from the host. `skillModelsForAgent` now requires the host as its
658
+ second argument, `null` when there is none, so a caller on a phone cannot
659
+ get the desktop default by leaving it out. An `imageModelChoice` the agent
660
+ set is never changed. Set it to `sd2` to keep Stable Diffusion 2.1 on a
661
+ desktop. (#867)
662
+
663
+ ```js
664
+ // before: an agent with no choice resolved to StableDiffusion-2.1-Q8_0
665
+ // after: off phones it resolves to FLUX.2-Klein-4B-Q4_0; to keep the old model
666
+ const agent = { ...saved, imageModelChoice: 'sd2' }
667
+
668
+ // before
669
+ skillModelsForAgent(agent)
670
+ // after
671
+ skillModelsForAgent(agent, await harness.capability())
672
+ ```
673
+
589
674
  - **Breaking:** speech defaults to Audio8. A `speak` or `speakStream` that
590
675
  names no model loads `Audio8-Q8_0` on every device profile, where it loaded
591
676
  Supertonic 3. Audio8 is 1.05 GB with its codec decoder (Supertonic was 85 MB
@@ -1366,6 +1451,24 @@ breaking change is listed under Changed and Removed.
1366
1451
 
1367
1452
  ### Fixed
1368
1453
 
1454
+ - `read_file` returns what a model can use. A CRLF line loses its `\r`, and a
1455
+ line over 2000 characters is cut there, so one long line no longer uses up
1456
+ the read; the cut names the full length,
1457
+ `… (line cut at 2000 chars; 5800 bytes in all)` for a text file and
1458
+ `5800 chars` for a document. A `startLine` past the end returns the last 50
1459
+ lines under `startLine N is past the end; the file has T lines`, and a
1460
+ negative `startLine` reads from the end (`-50` is the last 50 lines). A range
1461
+ names the exact total (`lines 2-2 of 50001`) where it said `of unknown`.
1462
+ Every read is one pass over one stream: the file is counted to its end
1463
+ without decoding it, and the tail is kept in a ring as it goes. The count
1464
+ stops at 8 MiB: past it a range's total stays unknown, and a tail returns
1465
+ `has more than N lines; its end is past the 8 MiB read_file counts` instead
1466
+ of reading on. A missing
1467
+ path suggests up to three near matches: the same name in another case, the
1468
+ same name with another extension, a name that contains it, or a one- or
1469
+ two-letter typo. For a missing folder it names the nearest folder that
1470
+ exists, and for a path written from the wrong root it suggests the same path
1471
+ under the shared folder. Denied paths are never suggested. (#887)
1369
1472
  - OCR loads in the harness sidecar. Since rc.16 the first OCR model load
1370
1473
  failed with `CANNOT_LOAD`, so a scanned PDF got no text on desktop. (#844)
1371
1474
  - `edit_file`, `insert_text` and `edit_many` write only what they change. A
package/README.md CHANGED
@@ -327,6 +327,8 @@ itself.
327
327
  | [`TranslationPlugin`](plugins/translation/README.md) | Translation on device |
328
328
  | [`LanguageHint`](plugins/language-hint/README.md) | A prompt in another language, in English too, for the model |
329
329
  | [`Weather`](plugins/weather/README.md) | Weather lookup |
330
+ | [`Diagrams`](plugins/diagrams/README.md) | Diagrams drawn from a type and its links, as the Mermaid the app renders |
331
+ | [`Charts`](plugins/charts/README.md) | Charts drawn from numbers the model describes, as an SVG attachment |
330
332
  | [`ObsidianRoute`](plugins/obsidian/README.md) | `obsidian …` commands against a vault |
331
333
 
332
334
  Each plugin is imported from `@qvac/harness/plugins/<folder>`. Its own dependencies are optional
@@ -46,6 +46,7 @@ export type { ModelFitBasis, ModelFitEvidence, ModelFitVerdict } from './lib/mod
46
46
  export * from './lib/capabilities/download.ts';
47
47
  export type { EmbedContext } from './lib/capabilities/embed.ts';
48
48
  export type { OcrImage, OcrPage, OcrReadContext, OcrService } from './lib/contract/ocr.ts';
49
+ export type { RootSearch, RootSearchQuery, RootSearchResult, RootSearchScope, RootWalkResult } from './lib/contract/root-search.ts';
49
50
  export type { SpeakContext, SpeakResult, SpeakStreamContext, SpeechService, TranscribeContext } from './lib/contract/speech.ts';
50
51
  export type { EmbedDevice } from './lib/models/embed-config.ts';
51
52
  export type { MemoryBudget } from './lib/hardware/memory-budget.ts';
@@ -54,7 +55,7 @@ export * from './lib/models/model-list.ts';
54
55
  export type { ModelTaskType } from './lib/models/model-task.ts';
55
56
  export type { DeleteModelResult, DeleteModelSummary } from './lib/models/model-delete.ts';
56
57
  export type { RecoveryResolution } from './lib/run-log/index.ts';
57
- export { harnessChild, spawnHarness, type HarnessChildOptions, type HarnessKnowledgeConfig, type HarnessMcpServer, type HarnessPluginOptions, type HarnessSpeechOptions, type SpawnHarnessOptions } from './lib/spawn.ts';
58
+ export { harnessChild, spawnHarness, type HarnessChartsOptions, type HarnessChildOptions, type HarnessKnowledgeConfig, type HarnessMcpServer, type HarnessPluginOptions, type HarnessSpeechOptions, type SpawnHarnessOptions } from './lib/spawn.ts';
58
59
  export * from './lib/tools/skills/catalog.ts';
59
60
  export { requiredSettings, settingEnvName, type SkillSettingEntry, type SkillSettingsFn } from './lib/tools/skills/skill-settings.ts';
60
61
  export type { ToolCatalogEntry } from './lib/tools/catalog.ts';
@@ -218,6 +219,7 @@ export declare class Harness extends ReadyResource {
218
219
  private _shell;
219
220
  private _projectionModel;
220
221
  private _customProjection;
222
+ private readonly _speculative;
221
223
  private readonly _contextSize?;
222
224
  private readonly _recentFits;
223
225
  private readonly _gpuStats?;
@@ -260,6 +262,7 @@ export declare class Harness extends ReadyResource {
260
262
  get toolNames(): string[];
261
263
  get supportsImages(): boolean;
262
264
  supportsImagesFor(model: string): boolean;
265
+ private _draftFor;
263
266
  private _projectionFor;
264
267
  setCustomModels(entries: ReadonlyArray<CustomModelEntry>): void;
265
268
  setModelIdleTimeout(ms: number): void;
package/dist-lib/index.js CHANGED
@@ -19,7 +19,7 @@ import { Embeddings } from './lib/embeddings/index.js';
19
19
  import { deleteAllKvCaches, deleteKvCacheKey } from './lib/capabilities/kv-cache.js';
20
20
  import { pushQueue } from './lib/queue.js';
21
21
  import { AbortedError } from './lib/helpers/race-abort.js';
22
- import { audioGenDownloadMetadata, categoryDownloadMetadata, customProjectionMap, defaultProjectionMap, catalogModelName, defaultVoiceModel, diffusionDownloadMetadata, infraModelsFor, modelNameToCapabilityProfile, residentSrc, setCustomModels } from './lib/models/model-catalog.js';
22
+ import { audioGenDownloadMetadata, categoryDownloadMetadata, customProjectionMap, defaultProjectionMap, catalogModelName, defaultVoiceModel, diffusionDownloadMetadata, infraModelsFor, speculativeDraft, modelNameToCapabilityProfile, residentSrc, setCustomModels } from './lib/models/model-catalog.js';
23
23
  import { customModelRows, isModelSourceCached, mergeCustomRows, listModels } from './lib/models/model-list.js';
24
24
  import { createDownloadGate } from './lib/models/download-gate.js';
25
25
  import { deleteModelFiles, summarizeDelete } from './lib/models/model-delete.js';
@@ -109,6 +109,7 @@ export class Harness extends ReadyResource {
109
109
  _shell;
110
110
  _projectionModel;
111
111
  _customProjection = {};
112
+ _speculative;
112
113
  _contextSize;
113
114
  _recentFits = new Map();
114
115
  _gpuStats;
@@ -168,6 +169,7 @@ export class Harness extends ReadyResource {
168
169
  this._hostTools = tools;
169
170
  this._tools = tools;
170
171
  this._projectionModel = projectionModel ?? defaultProjectionMap();
172
+ this._speculative = llmLoad?.speculative === true;
171
173
  this._modelsDir = modelsDir;
172
174
  this._skillsDir = skillsDir;
173
175
  this._skills = new SkillsHost({
@@ -448,6 +450,9 @@ export class Harness extends ReadyResource {
448
450
  supportsImagesFor(model) {
449
451
  return Boolean(this._projectionFor(model));
450
452
  }
453
+ _draftFor(model) {
454
+ return this._speculative ? speculativeDraft(model)?.model?.src : undefined;
455
+ }
451
456
  _projectionFor(model) {
452
457
  const custom = this._customProjection[model];
453
458
  if (custom) {
@@ -584,7 +589,9 @@ export class Harness extends ReadyResource {
584
589
  download(args) {
585
590
  this._lifecycle.assertNotClosing();
586
591
  let releaseWork = null;
587
- const projection = (args.addon ?? 'llm') === 'llm' ? this._projectionFor(args.model) : undefined;
592
+ const llm = (args.addon ?? 'llm') === 'llm';
593
+ const projection = llm ? this._projectionFor(args.model) : undefined;
594
+ const draft = llm ? this._draftFor(args.model) : undefined;
588
595
  const multiFile = diffusionDownloadMetadata(args.model, args.addon) ??
589
596
  audioGenDownloadMetadata(args.model, args.addon) ??
590
597
  categoryDownloadMetadata(args.model, args.addon);
@@ -605,7 +612,7 @@ export class Harness extends ReadyResource {
605
612
  }, {
606
613
  ...args,
607
614
  projection,
608
- companions: multiFile?.companions,
615
+ companions: draft ? [...(multiFile?.companions ?? []), draft] : multiFile?.companions,
609
616
  assetSizes: multiFile?.assetSizes
610
617
  }, (event) => {
611
618
  this._residency.invalidateStatus();
@@ -700,7 +707,8 @@ export class Harness extends ReadyResource {
700
707
  this._lifecycle.assertNotClosing();
701
708
  const rows = await listModels(sdk, options, {
702
709
  cache: this._residency.status,
703
- projectionFor: (name) => this._projectionFor(name)
710
+ projectionFor: (name) => this._projectionFor(name),
711
+ draftFor: (name) => this._draftFor(name)
704
712
  });
705
713
  const loaded = this._residency.settled();
706
714
  const loading = this._residency.loading();
@@ -6,6 +6,7 @@ import { modelTurns, trustedSourcesFrom } from '../turns.js';
6
6
  import { skillNameOf } from '../../tool-plan.js';
7
7
  import { unreadySkillState } from '../../skill-entry.js';
8
8
  import { runSpill } from '../../../spill.js';
9
+ import { withRootSearch } from '../../../helpers/root-search.js';
9
10
  export function resolvedCall(session, call) {
10
11
  const tool = session.enabled.find((tool) => tool.name === call.name);
11
12
  return {
@@ -22,13 +23,14 @@ export function toolContext({ deps, context, name }) {
22
23
  const { args, session, commitFacts } = deps;
23
24
  return {
24
25
  currentTime: args.messages.findLast((turn) => turn.role === 'user')?.sentAt || session.startedAt,
26
+ userTurns: args.messages.filter((turn) => turn.role === 'user').map((turn) => turn.content),
25
27
  ...session.toolContext(session.turnImages, context.metrics.ctxSize ?? args.ctxSize, args.signal),
26
28
  skills: context.activated.filter((skill) => Agent.skillIsActive(skill, session.activation) &&
27
29
  !unreadySkillState(skill, args.skillCatalog ?? [])),
28
30
  skillsLoadedThisTurn: [...session.loadedThisTurn],
29
31
  settings: args.toolConfigs?.[name],
30
32
  toolOps: session.grantedOps,
31
- fsRoots: args.fsRoots ?? [],
33
+ fsRoots: withRootSearch(args.fsRoots ?? [], deps.services?.rootSearch),
32
34
  fsWriteRoots: session.writableRoots,
33
35
  policy: session.access,
34
36
  toolNames: session.enabled.map((tool) => tool.name),
@@ -1,4 +1,5 @@
1
1
  import { isRecord } from '../../guards.js';
2
+ import { isAnswer } from '../tool-turns.js';
2
3
  const RETRYABLE_STATUS = new Set([408, 429]);
3
4
  const RETRYABLE_CODE = new Set(['timeout', 'transport', 'busy']);
4
5
  export function callSucceeded(result, outcome) {
@@ -9,10 +10,7 @@ export function callSucceeded(result, outcome) {
9
10
  return typeof exitCode !== 'number' || exitCode === 0;
10
11
  }
11
12
  export function answerOf(result) {
12
- if (!isRecord(result) || result.answer !== true || typeof result.content !== 'string') {
13
- return undefined;
14
- }
15
- return result.content.trim() ? result.content : undefined;
13
+ return isAnswer(result) ? result.content : undefined;
16
14
  }
17
15
  function retryHints(result) {
18
16
  if (!isRecord(result) || Array.isArray(result)) {
@@ -0,0 +1,15 @@
1
+ import type { Message } from '../../contract/index.ts';
2
+ export interface AnsweredCall {
3
+ readonly name: string;
4
+ readonly id: string;
5
+ readonly arguments: Record<string, unknown>;
6
+ }
7
+ export interface Answer {
8
+ readonly answer: true;
9
+ readonly content: string;
10
+ }
11
+ export declare function isAnswer(result: unknown): result is Answer;
12
+ export interface AnsweredTurn extends Message {
13
+ readonly role: 'assistant' | 'tool';
14
+ }
15
+ export declare function answeredToolTurns(call: AnsweredCall): AnsweredTurn[];
@@ -0,0 +1,16 @@
1
+ import { isRecord } from '../../guards.js';
2
+ import { ToolCallMarkup } from '../../helpers/tool-call-markup.js';
3
+ import { toolResultTurn } from './result-turn.js';
4
+ const ANSWERED_PAYLOAD = { answered: true };
5
+ export function isAnswer(result) {
6
+ return (isRecord(result) &&
7
+ result.answer === true &&
8
+ typeof result.content === 'string' &&
9
+ result.content.trim().length > 0);
10
+ }
11
+ export function answeredToolTurns(call) {
12
+ return [
13
+ { role: 'assistant', content: ToolCallMarkup.toolCallMarkup([call]) },
14
+ { role: 'tool', content: toolResultTurn(call.name, call.id, ANSWERED_PAYLOAD) }
15
+ ];
16
+ }
@@ -1,3 +1,5 @@
1
+ export { answeredToolTurns, isAnswer } from './tool-turns/answered.ts';
2
+ export type { AnsweredCall, AnsweredTurn } from './tool-turns/answered.ts';
1
3
  export { attachedFiles, attachmentTurn, deliversFile } from './tool-turns/attachments.ts';
2
4
  export type { AttachedFile } from './tool-turns/attachments.ts';
3
5
  export { FILE_DELIVERED_NUDGE, GOAL_CONTINUATION_NUDGE, GOAL_STALLED_NUDGE, TOOL_CONTEXT_BOUNDARY_MESSAGE, TOOL_CONTINUATION_NUDGE, TOOL_CUT_OFF_MESSAGE, TOOL_DENIED_MESSAGE, TOOL_FAILING_MESSAGE, TOOL_REPEATED_FAILURE_MESSAGE, TOOL_REPEATED_MESSAGE, TOOL_ROUND_CUT_MESSAGE, TOOL_UNCHANGED_MESSAGE, WRAP_UP_NUDGE } from './tool-turns/copy.ts';
@@ -1,3 +1,4 @@
1
+ export { answeredToolTurns, isAnswer } from './tool-turns/answered.js';
1
2
  export { attachedFiles, attachmentTurn, deliversFile } from './tool-turns/attachments.js';
2
3
  export { FILE_DELIVERED_NUDGE, GOAL_CONTINUATION_NUDGE, GOAL_STALLED_NUDGE, TOOL_CONTEXT_BOUNDARY_MESSAGE, TOOL_CONTINUATION_NUDGE, TOOL_CUT_OFF_MESSAGE, TOOL_DENIED_MESSAGE, TOOL_FAILING_MESSAGE, TOOL_REPEATED_FAILURE_MESSAGE, TOOL_REPEATED_MESSAGE, TOOL_ROUND_CUT_MESSAGE, TOOL_UNCHANGED_MESSAGE, WRAP_UP_NUDGE } from './tool-turns/copy.js';
3
4
  export { DIRECT_CALL_ID, TOOL_RESULT_MAX_CHARS, historyPayload, materializeCompletionHistory, redactFailureTurns, toolResultHistoryEntry, toolResultTurn, withHookContext } from './tool-turns/result-turn.js';
@@ -153,6 +153,7 @@ export interface SkillTree {
153
153
  }
154
154
  export interface ToolExecuteContext {
155
155
  currentTime?: number | undefined;
156
+ userTurns?: readonly string[] | undefined;
156
157
  agentId?: string | null | undefined;
157
158
  skillTrees?: ReadonlyMap<string, SkillTree> | undefined;
158
159
  skills?: readonly string[] | undefined;
@@ -194,7 +195,7 @@ export interface CallTool {
194
195
  (name: string, args: unknown): Promise<unknown>;
195
196
  readonly names: readonly string[];
196
197
  }
197
- export type Toolset = 'web-search' | 'knowledge' | 'files' | 'exec' | 'http-request' | 'mcp-call' | 'image' | 'music' | 'coding' | 'team';
198
+ export type Toolset = 'web-search' | 'knowledge' | 'files' | 'exec' | 'http-request' | 'mcp-call' | 'image' | 'diagrams' | 'charts' | 'music' | 'coding' | 'team';
198
199
  export interface ToolsetScoped {
199
200
  toolset?: string | null;
200
201
  }
@@ -1,3 +1,4 @@
1
+ import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
1
2
  import type { Writable } from 'streamx';
2
3
  export interface DriveEntry {
3
4
  key: string;
@@ -114,10 +115,33 @@ export interface WalkSummary {
114
115
  }
115
116
  export interface FolderSearchResult extends SearchResult, WalkSummary {
116
117
  }
118
+ export interface LocalSearchQuery extends DriveSearchQuery {
119
+ include?: string;
120
+ deny: readonly string[];
121
+ signal?: BareAbortSignal | undefined;
122
+ }
123
+ export interface LocalWalkQuery {
124
+ folder: string;
125
+ include?: string;
126
+ includeIgnored: boolean;
127
+ deny: readonly string[];
128
+ maxMs: number;
129
+ signal?: BareAbortSignal | undefined;
130
+ }
131
+ export interface LocalWalkResult {
132
+ files: Array<{
133
+ path: string;
134
+ key: string;
135
+ mtime: number;
136
+ }>;
137
+ truncated: boolean;
138
+ }
117
139
  export interface LocalRoot {
118
140
  readonly kind: 'local';
119
141
  readonly root: string;
120
142
  readonly drive: Drive;
143
+ readonly search?: (query: LocalSearchQuery) => Promise<FolderSearchResult>;
144
+ readonly walk?: (query: LocalWalkQuery) => Promise<LocalWalkResult>;
121
145
  }
122
146
  export interface HyperRoot {
123
147
  readonly kind: 'hyper';
@@ -0,0 +1,34 @@
1
+ export interface RootSearchScope {
2
+ root: string;
3
+ folder: string;
4
+ include?: string;
5
+ deny: readonly string[];
6
+ includeIgnored: boolean;
7
+ signal?: AbortSignal;
8
+ }
9
+ export interface RootSearchQuery extends RootSearchScope {
10
+ queries: string[];
11
+ regex: boolean;
12
+ caseSensitive: boolean;
13
+ maxMatches: number;
14
+ }
15
+ export interface RootSearchResult {
16
+ hits: Array<{
17
+ path: string;
18
+ line: number;
19
+ text: string;
20
+ }>;
21
+ truncated: boolean;
22
+ cut: boolean;
23
+ }
24
+ export interface RootWalkResult {
25
+ files: Array<{
26
+ path: string;
27
+ mtime: number;
28
+ }>;
29
+ truncated: boolean;
30
+ }
31
+ export interface RootSearch {
32
+ search(query: RootSearchQuery): Promise<RootSearchResult>;
33
+ walk(scope: RootSearchScope): Promise<RootWalkResult>;
34
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -153,6 +153,8 @@ export interface RoundSpeed {
153
153
  tokensPerSecond?: number;
154
154
  timeToFirstToken?: number;
155
155
  avgConcurrentSeq?: number;
156
+ draftTokens?: number;
157
+ draftAcceptedTokens?: number;
156
158
  stopReason?: string;
157
159
  overflows?: number;
158
160
  contextBoundary?: true;
@@ -0,0 +1,3 @@
1
+ import type { RootSearch } from '../contract/root-search.ts';
2
+ import type { DriveRoot } from '../contract/drive.ts';
3
+ export declare function withRootSearch(roots: readonly DriveRoot[], engine: RootSearch | undefined): readonly DriveRoot[];
@@ -0,0 +1,74 @@
1
+ import path from 'path';
2
+ export function withRootSearch(roots, engine) {
3
+ if (!engine) {
4
+ return roots;
5
+ }
6
+ return roots.map((root) => (root.kind === 'local' ? searchable(root, engine) : root));
7
+ }
8
+ function searchable(root, engine) {
9
+ return {
10
+ ...root,
11
+ async search({ maxMs, signal, ...query }) {
12
+ const found = await bounded((stop) => engine.search({
13
+ ...query,
14
+ root: root.root,
15
+ folder: query.folder.slice(1),
16
+ signal: stop
17
+ }), { maxMs, signal, late: { hits: [], truncated: true, cut: false } });
18
+ const capped = found.hits.length >= query.maxMatches;
19
+ return {
20
+ hits: found.hits.map(({ path: rel, line, text }) => ({
21
+ file: path.join(root.root, rel),
22
+ line,
23
+ text
24
+ })),
25
+ capped,
26
+ cut: found.cut,
27
+ truncated: found.truncated && !capped,
28
+ skippedLinks: 0
29
+ };
30
+ },
31
+ async walk({ maxMs, signal, ...query }) {
32
+ const found = await bounded((stop) => engine.walk({
33
+ ...query,
34
+ root: root.root,
35
+ folder: query.folder.slice(1),
36
+ signal: stop
37
+ }), { maxMs, signal, late: { files: [], truncated: true } });
38
+ return {
39
+ files: found.files.map(({ path: rel, mtime }) => ({
40
+ path: path.join(root.root, rel),
41
+ key: `/${rel}`,
42
+ mtime
43
+ })),
44
+ truncated: found.truncated
45
+ };
46
+ }
47
+ };
48
+ }
49
+ async function bounded(run, { maxMs, signal, late }) {
50
+ const controller = new AbortController();
51
+ const abort = () => controller.abort();
52
+ let expired = false;
53
+ const timer = setTimeout(() => {
54
+ expired = true;
55
+ abort();
56
+ }, maxMs);
57
+ signal?.addEventListener('abort', abort);
58
+ if (signal?.aborted) {
59
+ abort();
60
+ }
61
+ try {
62
+ return await run(controller.signal);
63
+ }
64
+ catch (err) {
65
+ if (expired && !signal?.aborted) {
66
+ return late;
67
+ }
68
+ throw err;
69
+ }
70
+ finally {
71
+ clearTimeout(timer);
72
+ signal?.removeEventListener('abort', abort);
73
+ }
74
+ }
@@ -55,9 +55,15 @@ export function endRunOnTool(args) {
55
55
  export function finishDirectTool({ context, params }) {
56
56
  return { ...applyToolResult(context, params, context.currentCall), directSearchDone: true };
57
57
  }
58
+ function joinAnswers(earlier, next) {
59
+ if (earlier === null || !next) {
60
+ return earlier ?? next ?? null;
61
+ }
62
+ return `${earlier.trimEnd()}\n\n${next}`;
63
+ }
58
64
  function roundResult(context, payload) {
59
65
  return {
60
- answer: context.answer ?? payload.answer ?? null,
66
+ answer: joinAnswers(context.answer, payload.answer),
61
67
  deliveredThisRound: context.deliveredThisRound || payload.delivered === true,
62
68
  deliveryEndsRun: context.deliveryEndsRun || payload.deliveryEndsRun === true,
63
69
  shownThisRound: payload.shown
@@ -39,7 +39,9 @@ const ROUND_STATS = [
39
39
  'promptTokensPerSecond',
40
40
  'tokensPerSecond',
41
41
  'timeToFirstToken',
42
- 'avgConcurrentSeq'
42
+ 'avgConcurrentSeq',
43
+ 'draftTokens',
44
+ 'draftAcceptedTokens'
43
45
  ];
44
46
  function roundSpeed(round, { stats, stopReason, durationMs, overflows, reasoningDeltas, keyed }) {
45
47
  const speed = { round, durationMs: durationMs ?? 0 };
@@ -9,6 +9,8 @@ export interface CompletionStats {
9
9
  promptTokens?: number | undefined;
10
10
  cacheTokens?: number | undefined;
11
11
  avgConcurrentSeq?: number | undefined;
12
+ draftTokens?: number | undefined;
13
+ draftAcceptedTokens?: number | undefined;
12
14
  contextBoundary?: boolean | undefined;
13
15
  }
14
16
  export interface EngineEvent {
@@ -27,6 +27,7 @@ export declare function capabilityProfileModelLabel(profile: CapabilityProfile):
27
27
  export declare function isMultimodalLlm(modelName: string): boolean;
28
28
  export type ImageModelChoice = 'sd2' | 'sdxl' | 'flux2-klein';
29
29
  export declare const DEFAULT_IMAGE_MODEL_CHOICE: ImageModelChoice;
30
+ export declare function defaultImageModelChoice(host: HostCapability | null): ImageModelChoice;
30
31
  export interface ImageChoiceEntry {
31
32
  readonly choice: ImageModelChoice;
32
33
  readonly label: string;
@@ -99,7 +99,11 @@ const MULTIMODAL_LLMS = new Set([
99
99
  export function isMultimodalLlm(modelName) {
100
100
  return MULTIMODAL_LLMS.has(modelName);
101
101
  }
102
- export const DEFAULT_IMAGE_MODEL_CHOICE = 'sd2';
102
+ export const DEFAULT_IMAGE_MODEL_CHOICE = 'flux2-klein';
103
+ const MOBILE_IMAGE_MODEL_CHOICE = 'sd2';
104
+ export function defaultImageModelChoice(host) {
105
+ return host?.mobile ? MOBILE_IMAGE_MODEL_CHOICE : DEFAULT_IMAGE_MODEL_CHOICE;
106
+ }
103
107
  export const IMAGE_CHOICE_CATALOG = [
104
108
  {
105
109
  choice: 'sd2',
@@ -4,8 +4,8 @@ import type { ModelAddon } from './model-source.ts';
4
4
  export interface SdkModelAsset extends ModelRegistryEntry {
5
5
  readonly src: string;
6
6
  }
7
- import { CAPABILITY_PROFILE_ORDER, QWEN_35_2B, QWEN_35_4B, QWEN_35_9B, QWEN_36_35B_A3B, QWEN_38_27B, KAT_CODER_25_35B, BONSAI_2_27B_PQ2, BONSAI_2_27B_PTQ1, MEDPSY_1_7B, MEDPSY_4B, isCapabilityProfile, meetsMinCapabilityProfile, modelNameToCapabilityProfile, capabilityProfileToModelName, isMultimodalLlm, AGENT_MODEL_NAMES, modelDisplayName, capabilityProfileModelLabel, DEFAULT_IMAGE_MODEL_CHOICE, IMAGE_CHOICE_CATALOG, isMobilePlatform, runnableModelName, type CapabilityProfile, type HostCapability, type ImageModelChoice, type ImageChoiceEntry } from './model-catalog-constants.ts';
8
- export { CAPABILITY_PROFILE_ORDER, QWEN_35_2B, QWEN_35_4B, QWEN_35_9B, QWEN_36_35B_A3B, QWEN_38_27B, KAT_CODER_25_35B, BONSAI_2_27B_PQ2, BONSAI_2_27B_PTQ1, MEDPSY_1_7B, MEDPSY_4B, isCapabilityProfile, meetsMinCapabilityProfile, modelNameToCapabilityProfile, capabilityProfileToModelName, isMultimodalLlm, AGENT_MODEL_NAMES, modelDisplayName, capabilityProfileModelLabel, DEFAULT_IMAGE_MODEL_CHOICE, IMAGE_CHOICE_CATALOG, isMobilePlatform, runnableModelName };
7
+ import { CAPABILITY_PROFILE_ORDER, QWEN_35_2B, QWEN_35_4B, QWEN_35_9B, QWEN_36_35B_A3B, QWEN_38_27B, KAT_CODER_25_35B, BONSAI_2_27B_PQ2, BONSAI_2_27B_PTQ1, MEDPSY_1_7B, MEDPSY_4B, isCapabilityProfile, meetsMinCapabilityProfile, modelNameToCapabilityProfile, capabilityProfileToModelName, isMultimodalLlm, AGENT_MODEL_NAMES, modelDisplayName, capabilityProfileModelLabel, DEFAULT_IMAGE_MODEL_CHOICE, defaultImageModelChoice, IMAGE_CHOICE_CATALOG, isMobilePlatform, runnableModelName, type CapabilityProfile, type HostCapability, type ImageModelChoice, type ImageChoiceEntry } from './model-catalog-constants.ts';
8
+ export { CAPABILITY_PROFILE_ORDER, QWEN_35_2B, QWEN_35_4B, QWEN_35_9B, QWEN_36_35B_A3B, QWEN_38_27B, KAT_CODER_25_35B, BONSAI_2_27B_PQ2, BONSAI_2_27B_PTQ1, MEDPSY_1_7B, MEDPSY_4B, isCapabilityProfile, meetsMinCapabilityProfile, modelNameToCapabilityProfile, capabilityProfileToModelName, isMultimodalLlm, AGENT_MODEL_NAMES, modelDisplayName, capabilityProfileModelLabel, DEFAULT_IMAGE_MODEL_CHOICE, defaultImageModelChoice, IMAGE_CHOICE_CATALOG, isMobilePlatform, runnableModelName };
9
9
  export type { CapabilityProfile, HostCapability, ImageModelChoice, ImageChoiceEntry };
10
10
  export interface LlmCatalogEntry {
11
11
  readonly name: string;
@@ -14,8 +14,14 @@ export interface LlmCatalogEntry {
14
14
  readonly projection?: SdkModelAsset;
15
15
  readonly textOnly?: true;
16
16
  readonly toolDialect?: ToolDialect;
17
+ readonly draft?: SpeculativeDraft;
18
+ }
19
+ export interface SpeculativeDraft {
20
+ readonly specType: 'draft-dflash' | 'draft-mtp';
21
+ readonly model?: SdkModelAsset;
17
22
  }
18
23
  export declare const LLM_CATALOG: ReadonlyArray<LlmCatalogEntry>;
24
+ export declare function speculativeDraft(model: string): SpeculativeDraft | undefined;
19
25
  export declare function defaultProjectionMap(): Record<string, string>;
20
26
  export type ModelCategory = 'tts' | 'transcription' | 'embedding';
21
27
  export interface CategoryDefault {
@@ -98,7 +104,7 @@ export interface AgentModel extends CatalogModel {
98
104
  export interface AgentModelInput extends AgentSkillModelInput {
99
105
  readonly modelName?: string | null;
100
106
  }
101
- export declare function skillModelsForAgent(agent: AgentSkillModelInput): ReadonlyArray<AgentModel>;
107
+ export declare function skillModelsForAgent(agent: AgentSkillModelInput, host: HostCapability | null): ReadonlyArray<AgentModel>;
102
108
  export declare function modelsForAgent(agent: AgentModelInput, host: HostCapability | null): ReadonlyArray<AgentModel>;
103
109
  export declare function diffusionSizeBytes(entry: DiffusionCatalogEntry): number;
104
110
  export declare function imageModelFor(choice: string | undefined): ImageModelSet | null;
@@ -129,6 +135,7 @@ export interface CuratedListable {
129
135
  readonly asset: SdkModelAsset;
130
136
  readonly companions: SdkModelAsset[];
131
137
  readonly projection?: SdkModelAsset;
138
+ readonly draft?: SdkModelAsset;
132
139
  }
133
140
  export declare function curatedListables(): CuratedListable[];
134
141
  export declare function curatedModelAsset(name: string, addon: ModelRegistryEntry['addon']): SdkModelAsset | undefined;