@qvac/harness 1.0.0-rc.15 → 1.0.0-rc.17

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 (145) hide show
  1. package/CHANGELOG.md +139 -2
  2. package/dist-lib/index.d.ts +6 -1
  3. package/dist-lib/index.js +17 -3
  4. package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
  5. package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +28 -3
  6. package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +3 -0
  7. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
  8. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -8
  9. package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +6 -3
  10. package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +1 -1
  11. package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +2 -2
  12. package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +2 -1
  13. package/dist-lib/lib/capabilities/completion-engine/durable.js +7 -1
  14. package/dist-lib/lib/capabilities/completion-engine/engine.js +23 -39
  15. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +2 -1
  16. package/dist-lib/lib/capabilities/completion-engine/operations.js +28 -9
  17. package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -2
  18. package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +3 -1
  19. package/dist-lib/lib/capabilities/completion-engine/session.d.ts +1 -0
  20. package/dist-lib/lib/capabilities/completion-engine/session.js +1 -0
  21. package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +2 -1
  22. package/dist-lib/lib/capabilities/completion-engine/turns.js +5 -2
  23. package/dist-lib/lib/capabilities/enhance.js +3 -3
  24. package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -1
  25. package/dist-lib/lib/capabilities/sdk-tool.js +3 -2
  26. package/dist-lib/lib/capabilities/skill-entry.d.ts +9 -1
  27. package/dist-lib/lib/capabilities/skill-entry.js +11 -7
  28. package/dist-lib/lib/capabilities/tool-turns.d.ts +5 -0
  29. package/dist-lib/lib/capabilities/tool-turns.js +24 -27
  30. package/dist-lib/lib/client/index.js +3 -2
  31. package/dist-lib/lib/connect.d.ts +2 -0
  32. package/dist-lib/lib/connect.js +33 -3
  33. package/dist-lib/lib/contract/completion.d.ts +17 -0
  34. package/dist-lib/lib/contract/exec.d.ts +1 -0
  35. package/dist-lib/lib/contract/models.d.ts +1 -1
  36. package/dist-lib/lib/contract/ocr.d.ts +13 -0
  37. package/dist-lib/lib/contract/ocr.js +1 -0
  38. package/dist-lib/lib/contract/run.d.ts +8 -0
  39. package/dist-lib/lib/contract-types.d.ts +4 -1
  40. package/dist-lib/lib/guards.d.ts +2 -0
  41. package/dist-lib/lib/guards.js +7 -0
  42. package/dist-lib/lib/hardware/capability-probe.js +10 -7
  43. package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
  44. package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
  45. package/dist-lib/lib/helpers/completion-params.d.ts +2 -1
  46. package/dist-lib/lib/helpers/completion-params.js +16 -1
  47. package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
  48. package/dist-lib/lib/helpers/control-tokens.js +25 -0
  49. package/dist-lib/lib/machine/completion/actions/completion.js +34 -5
  50. package/dist-lib/lib/machine/completion/actions/tools.js +4 -1
  51. package/dist-lib/lib/machine/completion/rules.d.ts +2 -0
  52. package/dist-lib/lib/machine/completion/rules.js +7 -0
  53. package/dist-lib/lib/machine/completion/types.d.ts +6 -0
  54. package/dist-lib/lib/machine/index.d.ts +2 -1
  55. package/dist-lib/lib/machine/index.js +2 -1
  56. package/dist-lib/lib/models/gpu-selection.d.ts +6 -1
  57. package/dist-lib/lib/models/gpu-selection.js +29 -5
  58. package/dist-lib/lib/no-redirect-fetch-impl.d.ts +1 -1
  59. package/dist-lib/lib/no-redirect-fetch-impl.js +13 -7
  60. package/dist-lib/lib/plugins/registry.d.ts +5 -0
  61. package/dist-lib/lib/plugins/registry.js +15 -1
  62. package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
  63. package/dist-lib/lib/plugins/require-bare.js +13 -0
  64. package/dist-lib/lib/run-log/request-codec.js +2 -2
  65. package/dist-lib/lib/serve.js +43 -35
  66. package/dist-lib/lib/sidecar/index.js +2 -1
  67. package/dist-lib/lib/skills-host/index.js +7 -1
  68. package/dist-lib/lib/spawn.d.ts +3 -0
  69. package/dist-lib/lib/spawn.js +5 -3
  70. package/dist-lib/lib/tools/ask-user.d.ts +2 -0
  71. package/dist-lib/lib/tools/ask-user.js +137 -0
  72. package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
  73. package/dist-lib/lib/tools/attachments/delivered.js +16 -0
  74. package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
  75. package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
  76. package/dist-lib/lib/tools/exec.js +2 -1
  77. package/dist-lib/lib/tools/files/read-file.js +3 -3
  78. package/dist-lib/lib/tools/fs/document-text.d.ts +7 -1
  79. package/dist-lib/lib/tools/fs/document-text.js +4 -20
  80. package/dist-lib/lib/tools/http-request/request.d.ts +2 -2
  81. package/dist-lib/lib/tools/http-request/request.js +1 -1
  82. package/dist-lib/lib/tools/http-request.d.ts +1 -0
  83. package/dist-lib/lib/tools/http-request.js +54 -3
  84. package/dist-lib/lib/tools/index.d.ts +2 -1
  85. package/dist-lib/lib/tools/index.js +5 -1
  86. package/dist-lib/lib/tools/office.js +20 -12
  87. package/dist-lib/lib/tools/operations/builders.d.ts +4 -3
  88. package/dist-lib/lib/tools/operations/builders.js +41 -3
  89. package/dist-lib/lib/tools/operations/calendar-range.d.ts +16 -0
  90. package/dist-lib/lib/tools/operations/calendar-range.js +40 -0
  91. package/dist-lib/lib/tools/operations/compile.js +4 -2
  92. package/dist-lib/lib/tools/operations/manifest.d.ts +4 -0
  93. package/dist-lib/lib/tools/pdf/build.d.ts +11 -1
  94. package/dist-lib/lib/tools/pdf/build.js +52 -16
  95. package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
  96. package/dist-lib/lib/tools/pdf/pages.js +28 -0
  97. package/dist-lib/lib/tools/pdf/recognize.d.ts +13 -0
  98. package/dist-lib/lib/tools/pdf/recognize.js +58 -0
  99. package/dist-lib/lib/tools/pdf.js +42 -13
  100. package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
  101. package/dist-lib/lib/tools/skills/scope-key.js +4 -0
  102. package/dist-lib/lib/tools/web-fetch.js +41 -130
  103. package/dist-lib/plugins/knowledge/index.js +3 -3
  104. package/dist-lib/plugins/mcp/call.js +5 -1
  105. package/dist-lib/plugins/mcp/protocol.d.ts +6 -1
  106. package/dist-lib/plugins/mcp/protocol.js +2 -2
  107. package/dist-lib/plugins/ocr/bmp.d.ts +2 -0
  108. package/dist-lib/plugins/ocr/bmp.js +27 -0
  109. package/dist-lib/plugins/ocr/index.d.ts +12 -0
  110. package/dist-lib/plugins/ocr/index.js +18 -0
  111. package/dist-lib/plugins/ocr/ocr-runtime.d.ts +23 -0
  112. package/dist-lib/plugins/ocr/ocr-runtime.js +82 -0
  113. package/dist-lib/plugins/ocr/reading-order.d.ts +5 -0
  114. package/dist-lib/plugins/ocr/reading-order.js +218 -0
  115. package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
  116. package/dist-lib/plugins/python/bare-floor.js +2 -0
  117. package/dist-lib/plugins/python/index.d.ts +1 -0
  118. package/dist-lib/plugins/python/index.js +1 -0
  119. package/dist-lib/plugins/python/language.js +9 -8
  120. package/dist-lib/plugins/python/python-adapter.d.ts +4 -0
  121. package/dist-lib/plugins/python/python-adapter.js +26 -0
  122. package/dist-lib/plugins/python/worker/client.js +1 -1
  123. package/dist-lib/plugins/python/worker/entry.js +2 -8
  124. package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
  125. package/dist-lib/plugins/python/worker/preload.js +2 -0
  126. package/dist-lib/plugins/python/worker/spawn.js +1 -1
  127. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  128. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  129. package/dist-lib/plugins/weather/lookup.js +1 -0
  130. package/dist-lib/schema/harness.js +17 -0
  131. package/dist-lib/spec/bind.js +3 -0
  132. package/dist-lib/spec/calls.js +1 -0
  133. package/dist-lib/spec/hrpc/hrpc.json +13 -0
  134. package/dist-lib/spec/hrpc/index.js +15 -3
  135. package/dist-lib/spec/hrpc/messages.js +32 -0
  136. package/dist-lib/spec/hyperschema/index.js +32 -0
  137. package/dist-lib/spec/hyperschema/schema.json +40 -0
  138. package/dist-lib/spec/hyperschema/types.d.ts +12 -0
  139. package/package.json +26 -8
  140. package/scripts/addon-externals.cjs +3 -0
  141. package/worker/harness-sidecar.mjs +5 -0
  142. package/dist-lib/lib/capabilities/completion-engine/event-mailbox.d.ts +0 -20
  143. package/dist-lib/lib/capabilities/completion-engine/event-mailbox.js +0 -110
  144. package/dist-lib/lib/helpers/input-budget.d.ts +0 -8
  145. package/dist-lib/lib/helpers/input-budget.js +0 -9
package/CHANGELOG.md CHANGED
@@ -21,6 +21,52 @@ breaking change is listed under Changed and Removed.
21
21
 
22
22
  ### Added
23
23
 
24
+ - A vision model sees an image a tool attaches. A call whose result attached a
25
+ file (`attachmentId`, or a list under `attachments`) offers it to a new host
26
+ port, `showImage({ attachmentId })`. The host answers with its own file for
27
+ the image, or `null`. Up to four a round ride the user turn that closes the
28
+ round, as its `attachments`, with a line naming them. A host without the
29
+ port changes nothing. Over the wire it is a `fetch-ask` with
30
+ `payload: { show: true }`, so the schema is unchanged.
31
+
32
+ ```js
33
+ harness.completion({
34
+ ...run,
35
+ showImage: async ({ attachmentId }) => imageFileFor(attachmentId) // or null
36
+ })
37
+ ```
38
+
39
+ See [the decision record](docs/decisions/2026-11-06-a-tool-image-rides-the-turn-closing-its-round.md).
40
+
41
+ - The model can ask the user with a form. `ask_user` takes a question and its
42
+ fields (single choice, multiple choice, date, short text, note, number;
43
+ `required` per field) and waits on `askUser`, which now carries the fields as
44
+ `form`. The host answers with a JSON object of field id to value, or `null`
45
+ for Skip; any other text reaches the model as the user's own reply. A form
46
+ with a file pick, an unknown type or a choice without options is refused.
47
+ Off by default: `Tools.product({ ask: true })`, or `spawnHarness({ ask: true })`
48
+ for the sidecar
49
+ ([#728](https://github.com/tetherto/qvac-harness/issues/728)).
50
+ - `http_request` attaches a 2xx response whose `Content-Type` names a file
51
+ (PDF, Office, image, audio, video, any binary) to the chat instead of
52
+ returning it as text, and the result carries its `attachmentId`, `fileName`,
53
+ `mimeType` and `byteLength`. A skill reaches a private file with the
54
+ credential it already holds, such as a Drive file through `alt=media`. The
55
+ new `fileName` argument names it; without one, the server's
56
+ `Content-Disposition` or the URL does. The total timeout is 120 s, up from
57
+ 30 s; a stalled server still fails at 10 s. A text file cut to the context
58
+ window, such as a long log, is attached whole beside the cut text, and the
59
+ `truncated` note says how to stage it into `exec` to read the rest. (#812)
60
+ - A scanned PDF page is read by OCR. The `ocr` plugin
61
+ (`@qvac/harness/plugins/ocr`) runs DocTR over the SDK's `ggml-ocr` as one
62
+ pooled model, unloaded when idle; `pdf` and `read_file` use it for a page with
63
+ an image and no text layer, and the reply notes the page was read by OCR. On
64
+ by default; `pluginOptions.ocr: false` leaves it out for a host that shows
65
+ scanned pages to the model as images. See
66
+ [plugins/ocr/README.md](plugins/ocr/README.md) and
67
+ [the decision record](docs/decisions/2026-11-03-a-scanned-pdf-page-is-read-by-ocr.md).
68
+ (#768)
69
+
24
70
  - `isLoading` covers image and music models, and a reply waiting for room. An
25
71
  image or music row reads `true` from the request, through any wait for a
26
72
  download or for room, until the model is resident or the load fails, and the
@@ -985,8 +1031,7 @@ breaking change is listed under Changed and Removed.
985
1031
  - **Breaking:** nothing a run does can load a new native addon: the sidecar
986
1032
  seals addon loading once the harness is ready. A plugin or tool that imports
987
1033
  a native addon lazily declares it in `HarnessPlugin.addons` or
988
- `ToolDefinition.addons`. A `QVAC_PYODIDE_WORKER_ENTRY` must exit when
989
- `workerData.preload` is true. See the
1034
+ `ToolDefinition.addons`. See the
990
1035
  [decision record](docs/decisions/2026-10-02-the-sidecar-seals-addon-loading-after-boot.md).
991
1036
  (#177)
992
1037
  - **Breaking:** `SandboxWorkspace` gains `start(command, { cwd? })`, returning a
@@ -1177,6 +1222,98 @@ breaking change is listed under Changed and Removed.
1177
1222
 
1178
1223
  ### Fixed
1179
1224
 
1225
+ - Text that spells a chat-template token no longer becomes one. A tool result,
1226
+ file, page, user turn or tool description holding `<|im_start|>`,
1227
+ `<tool_response>`, `<think>` and the like reaches the model with a word joiner
1228
+ after the `<`, so its words are read but cannot open a turn. A log holding a
1229
+ captured prompt used to hand the model a fake user turn mid-run, and it
1230
+ answered that instead. A tool never sees the joiner: a call copying that text
1231
+ runs with it as the file held it. A tool result now reaches the model as the
1232
+ same bytes in its own run and on replay, where replay used to strip it. (#825)
1233
+ - A model that cannot see images now hears when a new `pptx`, `docx` or `xlsx`
1234
+ file leaves out the image the user uploaded. Without `turnImages` the tool
1235
+ said "Done", and a deck shipped without the image while the model claimed it
1236
+ was there. (#817)
1237
+ - `web_fetch` downloads a file of up to 100 MB, as large as one a user can
1238
+ attach, instead of refusing anything past 8 MB. The cap is picked from the
1239
+ response's `Content-Type`, so a page keeps its 8 MB budget, and a declared
1240
+ file attaches without being decoded as text first. A stalled download fails
1241
+ after 15 s without a byte; one that keeps arriving has 120 s, where any fetch
1242
+ used to stop at 15 s. (#811)
1243
+ - A tool that attaches a large file no longer stalls the run. Every host
1244
+ callback's input went through JSON twice and into the run journal whole, so
1245
+ a 24 MB file became tens of millions of object keys and the attach never
1246
+ reached the host. The bytes now go to the host as a copy, and the journal
1247
+ records them as `{ byteLength, sha256 }`, which a resume still matches. (#811)
1248
+ - `weather_lookup` is listed under `weather` in the `tool_search` catalog, not
1249
+ under its `http-request` toolset. The search scores a tool's heading, so a
1250
+ query such as "http request tool" also loaded the weather tool next to
1251
+ `http_request`. (#818)
1252
+ - The package loads on Bare 1.33.4, the runtime of `react-native-bare-kit`
1253
+ 0.16.0: `engines.bare` is `>=1.33.4`, so a mobile host no longer patches it.
1254
+ Python still needs Bare 1.34.0, and importing `@qvac/harness/plugins/python`
1255
+ on an older Bare throws `@qvac/harness/plugins/python needs Bare 1.34.0 or
1256
+ later` instead of a stowed harness failing to open with `ADDON_NOT_FOUND` for
1257
+ `bare-channel`. A plugin names its own floor with
1258
+ `PluginRegistry.requireBare(plugin, floor)`. (#806)
1259
+ - The refusal for a skill that is `disconnected` or `needs-setup` carries
1260
+ `setup: { skill, state }` beside its `error`, so a host can offer the setup
1261
+ itself. Its text asks the model to say it once and to name no menu path,
1262
+ which a small model invented as "Settings → Skills".
1263
+ - `@qvac/turbovec-ggml` is an optional peer at `^0.3.1`. 0.3.0 depends on
1264
+ `@qvac/fabric` ^0.24.0 while every other model addon is on ^0.25.0, so a host
1265
+ that resolved it loaded two fabric copies into one process. A host whose lock
1266
+ holds 0.3.0 updates it. (#807)
1267
+ - A credential the host removes from `setCredentials` forgets its rejected
1268
+ verdict, so its skill reads as needing setup instead of disconnected, and a
1269
+ token pushed for the same key at another scope is probed afresh. (#807)
1270
+ - An MCP session is keyed by the token that opened it, so a token rotated under
1271
+ the same credential key opens its own session instead of reusing the old one,
1272
+ which a server that binds a session to its user refused with 403 and marked
1273
+ the fresh token rejected. (#807)
1274
+ - A `%` that starts no escape in an `http_request` URL (`?q=50%`) is kept as
1275
+ text, as in Node, instead of throwing `URI malformed` on Bare when `query` is
1276
+ also given; the skill-eval judge crashed on the same URL. Both now parse with
1277
+ the `bare-url` package, at least 2.5.6 (holepunchto/bare-url#46), instead of
1278
+ the global `URL` built into the Bare runtime, which no Bare release has
1279
+ updated yet. (#799)
1280
+ - Calendar reads build their own query: validated arguments, encoded dates
1281
+ and timezone offsets, and a local day range resolved from the turn's clock
1282
+ that holds across pages and DST, so "today" and "tomorrow" no longer fail
1283
+ and get explained as a credential problem. (#770)
1284
+ - On Linux the NVIDIA card is pinned as `main-gpu` only when another GPU could
1285
+ take the load. A host whose NVIDIA GPU is the only one, such as a DGX Spark
1286
+ or a Jetson, registers it as integrated and was loading on the CPU. (#786)
1287
+ - Restore the completion output queue and pending-input handling from before #684.
1288
+ Output events retain their original boundaries, with no mailbox chunking,
1289
+ coalescing, or count/byte limits. Pending steer/follow-up inputs no longer have
1290
+ admission limits in the engine or transport. Unread output and pending input
1291
+ remain unbounded in memory.
1292
+ - A skill-gated tool is sent only once the run may call it, from the round its
1293
+ skill loads, so `tool_search`'s catalog no longer names it before. The catalog
1294
+ line read as a tool to search for and call, so a 9B asked for a PDF skipped the
1295
+ pdf skill and wrote Python with reportlab or fpdf instead: 4 of 5 runs on 0.8.12
1296
+ against 0 of 10 on 0.8.11. The tool joins on the round the SDK already
1297
+ re-prefills to declare what the skill loaded, so it costs no cache. A gated tool
1298
+ a small model may call early, such as `pdf` on a 2B, is sent from the first
1299
+ round. (QVAC-27769)
1300
+ - `exec` refuses Python that imports `reportlab`, `fpdf`, `pypdf` or `PyPDF2`,
1301
+ or declares their packages, before it runs, when the run offers the `pdf`
1302
+ tool, and names that tool instead, or the skill to load first when it has not
1303
+ loaded yet. Offline, a model asked for a PDF reached for reportlab before
1304
+ loading the pdf skill, could not install it, and wrote the PDF bytes by hand:
1305
+ the file attached as a success with only its title, or no text at all. A
1306
+ skill's own script and a run without the `pdf` tool still run as before. A
1307
+ tool now also gets `offeredTools`, every tool the run offers, alongside
1308
+ `toolNames`, the ones it can call now. (QVAC-27769)
1309
+ - A repeat save by the `pdf`, `pptx`, `docx` or `xlsx` tool in a later round of
1310
+ the same run, or after the run resumes, returns the file already attached
1311
+ instead of attaching it again. Each round got its own `attach`, which the
1312
+ tools' per-turn record keyed on, so a small model that called again delivered
1313
+ the same file twice. The record now lives in the run budget as `delivered`,
1314
+ saved with the run.
1315
+ - A `pdf` save under a name already attached with different content is refused
1316
+ as the Office tools already refuse it, instead of returning the old file.
1180
1317
  - `tools/list` through `mcp_call` comes back as a line per tool, with each
1181
1318
  argument's type and allowed values, and `params.names` gives the tools named
1182
1319
  whole. Asana's 52 tools were 148 KB, so the model saw 5 of them cut or waited
@@ -3,7 +3,7 @@ import ReadyResource from 'ready-resource';
3
3
  import { Policy } from './lib/policy/index.ts';
4
4
  import type { EngineBoot, EngineStep, RecoveryResolution } from './lib/run-log/index.ts';
5
5
  import { type CompletionArgs, type ModelRoundIo, type ModelRoundPort, type ModelRoundRequest, type ModelRoundResult } from './lib/capabilities/completion-engine/index.ts';
6
- import type { AccessPolicy, AgentConfig, ApproveFn, AskUserFn, AttachFn, CompletionEvent, FetchAttachmentFn, Message, ProgressFn, ResponseFormat, RunGoal, RunInput, ToolDefinition, ToolExecuteContext } from './lib/contract/index.ts';
6
+ import type { AccessPolicy, AgentConfig, ApproveFn, AskUserFn, AttachFn, CompletionEvent, FetchAttachmentFn, Message, ProgressFn, ResponseFormat, RunGoal, RunInput, ShowImageFn, ToolDefinition, ToolExecuteContext } from './lib/contract/index.ts';
7
7
  import { type DetectLanguageContext, type DetectedLanguage } from './lib/capabilities/detect-language.ts';
8
8
  import { type Capability } from './lib/capabilities/invoke.ts';
9
9
  import { type ModelSourcePreview, type PreviewModelSourceContext } from './lib/capabilities/preview-model-source.ts';
@@ -12,6 +12,7 @@ import { type DownloadArgs, type DownloadEventStream } from './lib/capabilities/
12
12
  import type { EmbedContext } from './lib/capabilities/embed.ts';
13
13
  import { type KvCacheDeletionResult } from './lib/capabilities/kv-cache.ts';
14
14
  import type { LlmGenerationParams } from './lib/models/llm-presets.ts';
15
+ import type { OcrReadContext } from './lib/contract/ocr.ts';
15
16
  import type { SpeakContext, SpeakResult, SpeakStreamContext, TranscribeContext } from './lib/contract/speech.ts';
16
17
  import type { CapabilityInfo, CredentialEntry, HarnessDiagnostics, InfraModel, LoadModelResult, MemoryUsage, SkillWriteResult, UnloadModelContext, UnloadModelResult } from './lib/contract-types.ts';
17
18
  import { type CustomModelEntry } from './lib/models/model-catalog.ts';
@@ -44,6 +45,7 @@ export type { ModelSourceFile, ModelSourcePreview, ModelSourceRefusal, PreviewMo
44
45
  export type { ModelFitBasis, ModelFitEvidence, ModelFitVerdict } from './lib/models/model-fit.ts';
45
46
  export * from './lib/capabilities/download.ts';
46
47
  export type { EmbedContext } from './lib/capabilities/embed.ts';
48
+ export type { OcrImage, OcrReadContext, OcrService } from './lib/contract/ocr.ts';
47
49
  export type { SpeakContext, SpeakResult, SpeakStreamContext, SpeechService, TranscribeContext } from './lib/contract/speech.ts';
48
50
  export type { EmbedDevice } from './lib/models/embed-config.ts';
49
51
  export type { MemoryBudget } from './lib/hardware/memory-budget.ts';
@@ -153,6 +155,7 @@ export interface CompletionContext {
153
155
  approve?: ApproveFn;
154
156
  attach?: AttachFn;
155
157
  fetchAttachment?: FetchAttachmentFn;
158
+ showImage?: ShowImageFn;
156
159
  progress?: ProgressFn;
157
160
  askUser?: AskUserFn;
158
161
  boot?: EngineBoot;
@@ -284,6 +287,8 @@ export declare class Harness extends ReadyResource {
284
287
  knowledgeStatus(): Promise<KnowledgeStatus>;
285
288
  transcribe(context: TranscribeContext): Promise<string>;
286
289
  private _transcribe;
290
+ ocrRead({ image, signal }: OcrReadContext): Promise<string>;
291
+ private _ocrService;
287
292
  detectLanguage(context: DetectLanguageContext): Promise<DetectedLanguage[]>;
288
293
  speak(context: SpeakContext): Promise<SpeakResult>;
289
294
  private _speak;
package/dist-lib/index.js CHANGED
@@ -77,6 +77,7 @@ export const PLUGIN_API_VERSION = PluginRegistry.API_VERSION;
77
77
  const SUSPEND_SETTLE_MS = 500;
78
78
  const SPEECH_PLUGIN_MISSING = 'speech needs the speech plugin';
79
79
  const KNOWLEDGE_PLUGIN_MISSING = 'knowledge needs the knowledge plugin';
80
+ const OCR_PLUGIN_MISSING = 'ocr needs the ocr plugin';
80
81
  const UNLOAD_FAILED = 'Runtime unload failed; close the harness before loading models again';
81
82
  const HOST_SHELL = { name: 'host' };
82
83
  function execOptions(exec) {
@@ -246,8 +247,10 @@ export class Harness extends ReadyResource {
246
247
  async _open() {
247
248
  try {
248
249
  installResolutionDetector(import.meta);
250
+ const core = PluginRegistry.loadAddons('the harness', this._sdk.addons);
251
+ core.catch(noop);
249
252
  await this._startPlugins();
250
- await this._loadAddons();
253
+ await this._loadAddons(core);
251
254
  await this._skills.open();
252
255
  HarnessLog.info('open', { skills: this._skills.names.length, tools: this._tools.length });
253
256
  }
@@ -376,9 +379,9 @@ export class Harness extends ReadyResource {
376
379
  sdk: () => this._sdk.loadEmbed()
377
380
  };
378
381
  }
379
- async _loadAddons() {
382
+ async _loadAddons(core) {
380
383
  await Promise.all([
381
- PluginRegistry.loadAddons('the harness', this._sdk.addons),
384
+ core,
382
385
  ...this._tools.map((tool) => PluginRegistry.loadAddons(`tool '${tool.name}'`, tool.addons))
383
386
  ]);
384
387
  }
@@ -653,6 +656,17 @@ export class Harness extends ReadyResource {
653
656
  signal
654
657
  });
655
658
  }
659
+ ocrRead({ image, signal }) {
660
+ return this._residency.busy(async () => (await this._ocrService()).read(image, signal));
661
+ }
662
+ async _ocrService() {
663
+ if (!this.opened)
664
+ await this.ready();
665
+ if (!this._plugins.ctx.ocr) {
666
+ throw new Error(OCR_PLUGIN_MISSING);
667
+ }
668
+ return this._plugins.ctx.ocr;
669
+ }
656
670
  detectLanguage(context) {
657
671
  return detectLanguage(context);
658
672
  }
@@ -1,7 +1,7 @@
1
1
  import type { CompletionActor, CompletionActorInput } from '../session.ts';
2
2
  import { type ToolExecutionPlan } from './execution-plan.ts';
3
3
  import { type ToolCallRunResult } from './execute.ts';
4
- import type { CompletionContext } from '../../../machine/index.ts';
4
+ import { type CompletionContext, type ShownImage } from '../../../machine/index.ts';
5
5
  import type { CompletionEvent } from '../../../contract/index.ts';
6
6
  import type { ToolDonePayload, ToolExecutionSnapshot } from '../stages.ts';
7
7
  export declare const executing: CompletionActor<ToolDonePayload>;
@@ -16,6 +16,7 @@ export interface RanCall {
16
16
  landedBefore: number;
17
17
  executed: ToolCallRunResult;
18
18
  durationMs: number;
19
+ shown?: ShownImage[] | undefined;
19
20
  }
20
21
  export declare function runCall({ input: deps, context }: CompletionActorInput, { plan: vetted, execution, emit }: RunCallInput): Promise<RanCall>;
21
22
  interface SettleCallInput {
@@ -4,12 +4,13 @@ import { spliceFrom } from '../splice.js';
4
4
  import { answerOf, callSucceeded, readyPreflightFromFacts, reportFailure, settledFailure } from '../tool-execution.js';
5
5
  import { directToolHistory } from '../turns.js';
6
6
  import { labelOf } from '../loop.js';
7
- import { DIRECT_CALL_ID, FAILURE_STREAK, TOOL_FAILING_MESSAGE, deliversFile, historyPayload, materializeCompletionHistory, withHookContext, toolResultHistoryEntry, toolResultTurn } from '../../tool-turns.js';
7
+ import { attachedFiles, DIRECT_CALL_ID, FAILURE_STREAK, TOOL_FAILING_MESSAGE, deliversFile, historyPayload, materializeCompletionHistory, withHookContext, toolResultHistoryEntry, toolResultTurn } from '../../tool-turns.js';
8
8
  import { defers, TOOL_SEARCH_TOOL_NAME } from '../../sdk-tool.js';
9
9
  import { executionPlan, trustedSources } from './execution-plan.js';
10
10
  import { runToolCall } from './execute.js';
11
11
  import { toolCaller } from '../tool-caller.js';
12
12
  import { loadSkill } from './loading-skill.js';
13
+ import { CompletionMachine } from '../../../machine/index.js';
13
14
  import { failureResultRef, storeFailureResult } from '../../../helpers/failure-result.js';
14
15
  import { namesPath, provesResult, runsCheck, writtenTexts } from '../../../helpers/goal-check.js';
15
16
  const CHECK_OUTPUT_CHARS = 2000;
@@ -52,6 +53,7 @@ export const executing = async function executing(input) {
52
53
  answer: settled.answer,
53
54
  delivered: settled.delivered,
54
55
  deliveryEndsRun: settled.deliveryEndsRun,
56
+ shown: settled.shown,
55
57
  endedRun: succeeded && plan.resolved.tool.endsRun === true ? true : undefined,
56
58
  durationMs: settled.durationMs,
57
59
  checked: settled.checked,
@@ -107,7 +109,8 @@ export async function runCall({ input: deps, context }, { plan: vetted, executio
107
109
  display
108
110
  });
109
111
  const durationMs = Date.now() - startedAt;
110
- const output = callSucceeded(executed.output, executed.outcome)
112
+ const succeeded = callSucceeded(executed.output, executed.outcome);
113
+ const output = succeeded
111
114
  ? executed.output
112
115
  : await reportFailure(session.pipeline, {
113
116
  runId: session.runId,
@@ -119,7 +122,28 @@ export async function runCall({ input: deps, context }, { plan: vetted, executio
119
122
  outcome: executed.outcome,
120
123
  result: executed.output
121
124
  });
122
- return { plan, denied, landedBefore, executed: { ...executed, output }, durationMs };
125
+ const shown = succeeded ? await shownImages(args.showImage, output, args.signal) : undefined;
126
+ return { plan, denied, landedBefore, executed: { ...executed, output }, durationMs, shown };
127
+ }
128
+ async function shownImages(show, output, signal) {
129
+ if (!show) {
130
+ return undefined;
131
+ }
132
+ const shown = [];
133
+ for (const { attachmentId, fileName } of attachedFiles(output)) {
134
+ if (shown.length === CompletionMachine.MAX_SHOWN_IMAGES) {
135
+ break;
136
+ }
137
+ const path = await show({ attachmentId, signal }).catch((err) => {
138
+ if (signal?.aborted)
139
+ throw err;
140
+ return null;
141
+ });
142
+ if (path) {
143
+ shown.push({ path, fileName });
144
+ }
145
+ }
146
+ return shown.length ? shown : undefined;
123
147
  }
124
148
  function withRunPorts({ input: deps, context }, { plan, denied, emit }) {
125
149
  const { tool, call } = plan.resolved;
@@ -200,6 +224,7 @@ export function settleCall({ input: { session }, context }, { ran, direct, emit
200
224
  answer: succeeded ? answerOf(output) : undefined,
201
225
  delivered: delivered ? true : undefined,
202
226
  deliveryEndsRun: delivered && plan.resolved.tool.deliversMany !== true ? true : undefined,
227
+ shown: ran.shown,
203
228
  durationMs: executed.executed ? durationMs : undefined,
204
229
  checked: executed.executed
205
230
  ? checksRun(context, {
@@ -21,6 +21,7 @@ export function resolvedCall(session, call) {
21
21
  export function toolContext({ deps, context, name }) {
22
22
  const { args, session, commitFacts } = deps;
23
23
  return {
24
+ currentTime: args.messages.findLast((turn) => turn.role === 'user')?.sentAt || session.startedAt,
24
25
  ...session.toolContext(session.turnImages, context.metrics.ctxSize ?? args.ctxSize, args.signal),
25
26
  skills: context.activated.filter((skill) => Agent.skillIsActive(skill, session.activation) &&
26
27
  !unreadySkillState(skill, args.skillCatalog ?? [])),
@@ -31,7 +32,9 @@ export function toolContext({ deps, context, name }) {
31
32
  fsWriteRoots: session.writableRoots,
32
33
  policy: session.access,
33
34
  toolNames: session.enabled.map((tool) => tool.name),
35
+ offeredTools: [...session.grantable],
34
36
  knowledge: args.knowledge,
37
+ ocr: deps.services?.ocr,
35
38
  planMode: context.planMode,
36
39
  spill: session.enabled.some((tool) => tool.name === 'read_file')
37
40
  ? runSpill(session.runId)
@@ -1,5 +1,5 @@
1
1
  import { type ToolPolicyFacts } from '../../tool-plan.ts';
2
- import type { CompletionActor, CompletionDeps } from '../session.ts';
2
+ import { type CompletionActor, type CompletionDeps } from '../session.ts';
3
3
  import type { CompletionContext } from '../../../machine/index.ts';
4
4
  import type { InspectingOutput, ResolvedCallSnapshot } from '../stages.ts';
5
5
  import type { ResourceDescriptor } from '../../../contract/index.ts';
@@ -2,9 +2,10 @@ import { AbortedError } from '../../../helpers/race-abort.js';
2
2
  import { HarnessLog } from '../../../log.js';
3
3
  import { Agent } from '../../../agent/index.js';
4
4
  import { planToolCall } from '../../tool-plan.js';
5
+ import { loadedSkills } from '../session.js';
5
6
  import { approvalGate, resolvedCall, toolContext, trustedSources } from './execution-plan.js';
6
7
  import { detachJson } from '../../../helpers/detach-json.js';
7
- import { unreadySkillMessage } from '../../skill-entry.js';
8
+ import { unreadySkillRefusal } from '../../skill-entry.js';
8
9
  import { deniedWithoutApprover, gateRejection, policyActivity } from './rejection.js';
9
10
  export const inspecting = async function inspecting({ input: deps, context }) {
10
11
  const snapshot = context.currentCall;
@@ -89,7 +90,7 @@ export function inspectCall(deps, context, snapshot) {
89
90
  resource,
90
91
  call: snapshot,
91
92
  answeredRead,
92
- unknownTool: unknownToolError(session, resolved.call.name)
93
+ unknownTool: unknownToolError(session, context, resolved.call.name)
93
94
  });
94
95
  return {
95
96
  call: snapshot,
@@ -111,11 +112,12 @@ export function inspectCall(deps, context, snapshot) {
111
112
  rejection
112
113
  };
113
114
  }
114
- function unknownToolError(session, name) {
115
- const searchable = session.sdkTools?.some((tool) => tool.name === name && tool.deferLoading);
116
- const [owner] = searchable
117
- ? (Agent.collectToolGrants(session.inContextSkills).grantedOwners.get(name) ?? [])
115
+ function unknownToolError(session, context, name) {
116
+ const loaded = loadedSkills(context, session);
117
+ const owners = session.grantable.has(name)
118
+ ? [...(Agent.collectToolGrants(session.inContextSkills).grantedOwners.get(name) ?? [])]
118
119
  : [];
120
+ const owner = owners.find((skill) => !loaded.has(skill));
119
121
  return owner
120
122
  ? `${name} needs the ${owner} skill. Load it first, then call ${name}.`
121
123
  : `unknown tool: ${name}`;
@@ -137,8 +139,11 @@ function inspectRejection({ context, plan, execution, resource, call, answeredRe
137
139
  };
138
140
  }
139
141
  if (plan.skillStatus) {
140
- const error = unreadySkillMessage(plan.skillName, plan.skillStatus);
141
- return { ...base, result: { error }, activity: policyActivity({ call, effect, resource }) };
142
+ return {
143
+ ...base,
144
+ result: unreadySkillRefusal(plan.skillName, plan.skillStatus),
145
+ activity: policyActivity({ call, effect, resource })
146
+ };
142
147
  }
143
148
  if (plan.skillCall && (!plan.toolAvailable || !plan.skillActive)) {
144
149
  return {
@@ -111,8 +111,9 @@ async function prepare({ input, context, reconstruct, source, emit }) {
111
111
  const names = new Set(resolved.select(loaded).map(({ name }) => name));
112
112
  return catalog.filter(({ name }) => name === TOOL_SEARCH_TOOL_NAME || names.has(name));
113
113
  };
114
+ const sendable = (tools) => toSdkTools(catalog, new Set(tools.map(({ name }) => name)));
114
115
  const enabled = callable(loadedSkills);
115
- const sdkTools = toSdkTools(catalog);
116
+ const sdkTools = sendable(enabled);
116
117
  const { skillsSelected } = activation;
117
118
  const sent = reconstruct ? context.history[0] : undefined;
118
119
  let systemContent = sent && 'role' in sent && sent.role === 'system' ? sent.content : system.text;
@@ -140,8 +141,9 @@ async function prepare({ input, context, reconstruct, source, emit }) {
140
141
  const changed = names !== session.enabled.map((tool) => tool.name).join();
141
142
  if (changed) {
142
143
  session.enabled = reselected;
144
+ session.sdkTools = sendable(reselected);
143
145
  }
144
- const tools = renderedTools(sdkTools, history);
146
+ const tools = renderedTools(session.sdkTools, history);
145
147
  const prefix = promptPrefixHash({ system: systemContent, tools });
146
148
  if (changed) {
147
149
  logSelection(prefix);
@@ -153,7 +155,7 @@ async function prepare({ input, context, reconstruct, source, emit }) {
153
155
  systemContent = systemParts.text;
154
156
  session.promptParts = promptUsageParts({
155
157
  system: systemParts,
156
- toolSchemas: renderedTools(sdkTools, history)
158
+ toolSchemas: renderedTools(session.sdkTools, history)
157
159
  });
158
160
  return systemContent;
159
161
  };
@@ -192,6 +194,7 @@ async function prepare({ input, context, reconstruct, source, emit }) {
192
194
  prepareSession(session, {
193
195
  enabled,
194
196
  sdkTools,
197
+ grantable: new Set(catalog.map(({ name }) => name)),
195
198
  grantedOps,
196
199
  activation,
197
200
  inContextSkills,
@@ -44,7 +44,7 @@ export function runPrepare(source) {
44
44
  effect,
45
45
  decision: 'blocked'
46
46
  };
47
- result = { error: refusal };
47
+ result = refusal;
48
48
  }
49
49
  else {
50
50
  try {
@@ -7,7 +7,7 @@ import { skillLoadTurns } from '../../sdk-tool.js';
7
7
  import { Agent } from '../../../agent/index.js';
8
8
  import { errorMessage, isRecord } from '../../../guards.js';
9
9
  import { isFailureResultReference } from '../../../helpers/failure-result.js';
10
- import { mentionHandle, unreadySkillMessage, unreadySkillState } from '../../skill-entry.js';
10
+ import { mentionHandle, unreadySkillRefusal, unreadySkillState } from '../../skill-entry.js';
11
11
  export const skillStep = {
12
12
  label: 'Skill loading',
13
13
  propose({ session }, { preload }) {
@@ -27,7 +27,7 @@ export const skillStep = {
27
27
  refusal({ args }, step) {
28
28
  const name = skillOf(step);
29
29
  const state = unreadySkillState(name, args.skillCatalog ?? []);
30
- return state ? unreadySkillMessage(name, state) : null;
30
+ return state ? unreadySkillRefusal(name, state) : null;
31
31
  },
32
32
  settle({ deps, context, step, result, announce }) {
33
33
  const { session } = deps;
@@ -54,10 +54,11 @@ export interface DurableFacts extends Record<string, unknown> {
54
54
  }
55
55
  export interface ToolOperationFacts {
56
56
  backends: RunBackendUse[];
57
- runBudget: Pick<RunBudget, 'outputBytesUsed'>;
57
+ runBudget: Pick<RunBudget, 'outputBytesUsed' | 'delivered'>;
58
58
  outcome: Pick<RunOutcomeState, 'confirmedWrites'>;
59
59
  }
60
60
  export declare function captureFacts(session: Session): DurableFacts;
61
61
  export declare function captureToolOperationFacts(session: Session): ToolOperationFacts;
62
+ export declare function laterDelivered(current: RunBudget['delivered'], recorded: RunBudget['delivered']): RunBudget['delivered'];
62
63
  export declare function restoreFacts(deps: CompletionDeps, facts: DurableFacts): void;
63
64
  export {};
@@ -106,10 +106,16 @@ export function captureFacts(session) {
106
106
  export function captureToolOperationFacts(session) {
107
107
  return copy({
108
108
  backends: [...session.backends],
109
- runBudget: { outputBytesUsed: session.runBudget.outputBytesUsed },
109
+ runBudget: {
110
+ outputBytesUsed: session.runBudget.outputBytesUsed,
111
+ delivered: session.runBudget.delivered
112
+ },
110
113
  outcome: { confirmedWrites: session.runOutcomes.snapshot().confirmedWrites }
111
114
  });
112
115
  }
116
+ export function laterDelivered(current, recorded) {
117
+ return (recorded?.length ?? 0) > (current?.length ?? 0) ? recorded : current;
118
+ }
113
119
  export function restoreFacts(deps, facts) {
114
120
  facts = copy(facts);
115
121
  const session = deps.session;