@qvac/harness 1.0.0-rc.8 → 1.0.0-rc.9

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 (41) hide show
  1. package/CHANGELOG.md +26 -13
  2. package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +11 -2
  3. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +0 -13
  4. package/dist-lib/lib/capabilities/completion-engine/driver.js +1 -0
  5. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +1 -0
  6. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +1 -1
  7. package/dist-lib/lib/capabilities/completion-engine/round.d.ts +1 -1
  8. package/dist-lib/lib/capabilities/completion-engine/round.js +24 -8
  9. package/dist-lib/lib/capabilities/completion-engine/session.d.ts +1 -1
  10. package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +1 -1
  11. package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +1 -1
  12. package/dist-lib/lib/capabilities/download.d.ts +1 -1
  13. package/dist-lib/lib/capabilities/kv-cache.d.ts +1 -1
  14. package/dist-lib/lib/capabilities/prompt-prefix.d.ts +1 -1
  15. package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -1
  16. package/dist-lib/lib/capabilities/tool-prompt-log.d.ts +1 -1
  17. package/dist-lib/lib/capabilities/tool-turns.d.ts +2 -0
  18. package/dist-lib/lib/capabilities/tool-turns.js +4 -0
  19. package/dist-lib/lib/contract/completion.d.ts +1 -1
  20. package/dist-lib/lib/contract/models.d.ts +1 -1
  21. package/dist-lib/lib/contract/speech.d.ts +1 -1
  22. package/dist-lib/lib/machine/completion/actions/tools.js +12 -0
  23. package/dist-lib/lib/machine/completion/types.d.ts +2 -0
  24. package/dist-lib/lib/models/context.d.ts +1 -1
  25. package/dist-lib/lib/models/model-catalog.d.ts +1 -1
  26. package/dist-lib/lib/models/model-delete.d.ts +1 -1
  27. package/dist-lib/lib/models/model-fit.d.ts +1 -1
  28. package/dist-lib/lib/models/model-list.d.ts +1 -1
  29. package/dist-lib/lib/models/model-pool.d.ts +3 -3
  30. package/dist-lib/lib/models/model-source.d.ts +2 -2
  31. package/dist-lib/lib/models/tool-dialect.d.ts +1 -1
  32. package/dist-lib/lib/policy/index.d.ts +2 -1
  33. package/dist-lib/lib/policy/index.js +6 -0
  34. package/dist-lib/plugins/sandbox-linux/index.d.ts +3 -1
  35. package/dist-lib/plugins/sandbox-linux/index.js +10 -3
  36. package/dist-lib/plugins/sandbox-macos/index.d.ts +3 -1
  37. package/dist-lib/plugins/sandbox-macos/index.js +10 -5
  38. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  39. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  40. package/package.json +4 -6
  41. package/patches/@qvac%2Finference@0.22.0.patch +0 -59
package/CHANGELOG.md CHANGED
@@ -21,6 +21,16 @@ breaking change is listed under Changed and Removed.
21
21
 
22
22
  ### Added
23
23
 
24
+ - The macOS and Linux sandboxes take `writable`: absolute folders every shell line may write on
25
+ top of the run's policy, for a toolchain cache outside the project such as Go's build cache.
26
+ The file tools never see them, they are made at setup if missing, and a denied root still wins.
27
+ `Policy.withWrites(policy, roots)` returns a compiled policy that may also write those roots.
28
+ - A call that fails three times in a row, such as a test command the model
29
+ keeps patching against, comes back with a note telling the model to step
30
+ back: re-read the output and the requirements, find what the failures share
31
+ and change approach. The note repeats every third failure and a success
32
+ clears the streak. `wording.toolFailing` replaces the text; `{count}` is the
33
+ streak length.
24
34
  - `Tools.product` takes `files: false` to leave the file tools out, for a host
25
35
  with no folder to share, such as a phone entry that composes its tools with
26
36
  the mcp, web-search and weather plugins. `isDeviceSharedCredentialKey` from
@@ -583,27 +593,23 @@ breaking change is listed under Changed and Removed.
583
593
  (#453, #480)
584
594
  - A response cut off by the length limit runs its complete calls; only the
585
595
  call the cut truncated is answered, and a truncated call to a tool that is
586
- not loaded is answered as cut. A cut the patch flags as the output cap gets
596
+ not loaded is answered as cut. A cut at a `predict` cap gets
587
597
  `wording.toolCutOff`; any other `length` cut gets
588
598
  `wording.toolContextBoundary`, which says the context window filled before
589
599
  the arguments were complete. (#155, #450, #454, #458)
590
600
  - With tools on, a prose round cut at the context window is retried with the
591
601
  history folded, or wrapped up, instead of answered with its fragment. A cut
592
- the patch flags as the output cap (`contextBoundary: false`), or a round with
602
+ at a `predict` cap (`contextBoundary: false`), or a round with
593
603
  no tools, keeps the fragment. `round-reset` fires only when the round is
594
604
  retried or wrapped. (#456, #483)
595
- - A host recopies `patches/@qvac%2Finference@0.22.0.patch` into its
596
- `patchedDependencies` on this bump. The patch sets `contextBoundary` on every
597
- `length` stop: `true` at the context window, `false` at a `predict` cap.
598
- Every round, the wrap-up included, reads a stop flagged `false` as the output
599
- cap and any other `length` stop as the context window: a cut call gets
605
+ - The round sets `contextBoundary` on every `length` stop: `true` at the
606
+ context window, `false` at a `predict` cap. Every round, the wrap-up
607
+ included, reads a stop flagged `false` as the output cap and any other
608
+ `length` stop as the context window: a cut call gets
600
609
  `wording.toolContextBoundary`, a cut prose round with tools on is retried
601
610
  with a fold, a wrap-up answers with the fallback and emits `round-reset`, and
602
611
  `RoundSpeed.contextBoundary` is `true`. A stop flagged as the cap no longer
603
- makes the next round fold. Without the patch's `plugin.js` hunk every
604
- `length` stop, a `predict` cap included, reads as the window, and the harness
605
- logs this once. See [Install](docs/hosting.md#install). (#450, #481, #485,
606
- #488)
612
+ makes the next round fold. (#450, #481, #485, #488, #647)
607
613
  - A host that runs python on Node recopies `patches/pyodide@314.0.2.patch`
608
614
  into its `patchedDependencies`. Pyodide now loads `child-process-stub.cjs`
609
615
  by path, so guest `os.system` cannot spawn a process on Node either. A Bare
@@ -663,8 +669,8 @@ breaking change is listed under Changed and Removed.
663
669
  now ends the run at its fourth identical run. The re-read after a fold carries
664
670
  no unchanged note and no progress credit. (#507)
665
671
  - A wrap-up cut off at the context window answers with the fallback instead of
666
- its fragment and emits `round-reset` for what it streamed; a wrap-up the
667
- patch flags as cut at the output cap (`contextBoundary: false`) keeps its
672
+ its fragment and emits `round-reset` for what it streamed; a wrap-up
673
+ cut at its `predict` cap (`contextBoundary: false`) keeps its
668
674
  text as the answer. The run's outcome does not
669
675
  change. The wrap-up sends `predict` as `reasoning_budget + 4096`; a host
670
676
  `predict` wins. (#452, #480)
@@ -1041,6 +1047,13 @@ breaking change is listed under Changed and Removed.
1041
1047
 
1042
1048
  ### Fixed
1043
1049
 
1050
+ - A host needs neither `@qvac/sdk` nor a patch of `@qvac/inference`. The
1051
+ published types import `@qvac/inference`, so a Bare host type-checks
1052
+ without the SDK or a `tsconfig` path, and the round tells a `length` stop at
1053
+ the context window from one at a `predict` cap from the `predict` it sent.
1054
+ A host drops its copy of `patches/@qvac%2Finference@0.22.0.patch`; one that
1055
+ keeps it sees the same behaviour. (#647)
1056
+
1044
1057
  - A message keeps the wire layout 0.8.13 shipped: `sentAt` is its fourth
1045
1058
  field again, ahead of `toolCalls`, `toolCallId`, `name`, `id` and `context`.
1046
1059
  Up to rc.6 a 1.0 harness could not decode a message from a 0.8.13 host that
@@ -4,7 +4,7 @@ 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, deliversFile, historyPayload, materializeCompletionHistory, withHookContext, toolResultHistoryEntry, toolResultTurn } from '../../tool-turns.js';
7
+ import { 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';
@@ -141,6 +141,15 @@ function textsOf(value) {
141
141
  }
142
142
  return value && typeof value === 'object' ? Object.values(value).flatMap(textsOf) : [];
143
143
  }
144
+ function failingNoted(context, { key: callKey, output, outcome }) {
145
+ if (!settledFailure(output, outcome)) {
146
+ return output;
147
+ }
148
+ const streak = (context.failureStreaks?.[callKey] ?? 0) + 1;
149
+ return streak % FAILURE_STREAK === 0
150
+ ? withHookContext(output, (context.policy.failingMessage ?? TOOL_FAILING_MESSAGE).replaceAll('{count}', String(streak)))
151
+ : output;
152
+ }
144
153
  export function settleCall({ input: { session }, context }, { ran, direct, emit }) {
145
154
  const { plan, denied, landedBefore, executed, durationMs } = ran;
146
155
  const { call, key: callKey, args: callArgs } = plan.resolved;
@@ -152,7 +161,7 @@ export function settleCall({ input: { session }, context }, { ran, direct, emit
152
161
  const unchanged = repeated && !silent(historyPayload(executed.output));
153
162
  const output = unchanged && !prior.folded
154
163
  ? withHookContext(executed.output, context.policy.unchangedMessage.replaceAll('{count}', String(prior.repeats + 2)))
155
- : executed.output;
164
+ : failingNoted(context, { key: callKey, output: executed.output, outcome });
156
165
  if (outcome.kind !== 'success' && session.landed.length > landedBefore) {
157
166
  session.landed.length = landedBefore;
158
167
  }
@@ -3,9 +3,6 @@ import { recordWholeRound, runRecoveredRound } from '../round.js';
3
3
  import { ModelRound } from '../model-round.js';
4
4
  import { ToolSets } from '../tool-sets.js';
5
5
  import { AbortedError } from '../../../helpers/race-abort.js';
6
- import { HarnessLog } from '../../../log.js';
7
- const BOUNDARY_UNFLAGGED = "length stop without contextBoundary: the host's @qvac/inference patch lacks the contextBoundary hunk";
8
- let boundaryUnflaggedLogged = false;
9
6
  export async function forwardStream({ stream, emit }) {
10
7
  try {
11
8
  while (true) {
@@ -39,7 +36,6 @@ export async function runRound({ sdk, modelRound, kind, args, session, emit }) {
39
36
  emit
40
37
  });
41
38
  session.liveRound = null;
42
- logUnflaggedBoundary(round.final, args.round, kind);
43
39
  return round;
44
40
  }
45
41
  catch (error) {
@@ -83,15 +79,6 @@ async function remoteRound({ port, kind, args, runId, emit }) {
83
79
  cut: result.cut
84
80
  };
85
81
  }
86
- function logUnflaggedBoundary(final, round, kind) {
87
- if (boundaryUnflaggedLogged || final.stopReason !== 'length')
88
- return;
89
- if (final.stats?.contextBoundary !== undefined)
90
- return;
91
- boundaryUnflaggedLogged = true;
92
- const log = HarnessLog.enabled('info') ? HarnessLog.info : HarnessLog.diag;
93
- log(BOUNDARY_UNFLAGGED, { round, kind });
94
- }
95
82
  export async function assembleAnswer({ contentText, replay, landed, emit }) {
96
83
  let response = replay || contentText;
97
84
  if (replay) {
@@ -361,6 +361,7 @@ function runPolicy({ maxToolRounds, goal, wording }) {
361
361
  roundCutMessage: wording?.toolRoundCut ?? TOOL_ROUND_CUT_MESSAGE,
362
362
  repeatedCallMessage: wording?.toolRepeated ?? TOOL_REPEATED_MESSAGE,
363
363
  unchangedMessage: wording?.toolUnchanged ?? TOOL_UNCHANGED_MESSAGE,
364
+ failingMessage: wording?.toolFailing,
364
365
  goalNudge: wording?.goalContinuation ?? GOAL_CONTINUATION_NUDGE
365
366
  };
366
367
  }
@@ -58,6 +58,7 @@ export interface CompletionArgs {
58
58
  toolContextBoundary?: string;
59
59
  toolRepeated?: string;
60
60
  toolUnchanged?: string;
61
+ toolFailing?: string;
61
62
  goalContinuation?: string;
62
63
  };
63
64
  }
@@ -1,4 +1,4 @@
1
- import type { CompletionFinal, Tool as SdkTool, ToolDialect } from '@qvac/sdk';
1
+ import type { CompletionFinal, Tool as SdkTool, ToolDialect } from '@qvac/inference';
2
2
  import { type AbortSignal as BareAbortSignal } from 'bare-abort-controller';
3
3
  import type { TextEvent } from '../../helpers/thinking.ts';
4
4
  import type { CompletionSdk, LlmGenerationParams, Message, ResponseFormat, RoundModelLease, RunLifecycleEvent } from '../../contract/index.ts';
@@ -1,4 +1,4 @@
1
- import type { CompletionFinal, CompletionStats, Tool as SdkTool, ToolDialect } from '@qvac/sdk';
1
+ import type { CompletionFinal, CompletionStats, Tool as SdkTool, ToolDialect } from '@qvac/inference';
2
2
  import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
3
3
  import { type KnownTool } from '../../helpers/tool-call-markup.ts';
4
4
  import { type TextEvent } from '../../helpers/thinking.ts';
@@ -218,11 +218,22 @@ export function foldTokens(stats, cacheable) {
218
218
  return undefined;
219
219
  return stats.promptTokens + (stats.generatedTokens ?? 0);
220
220
  }
221
- function withoutCacheTokens(stats) {
221
+ function slotStats(stats, previous) {
222
222
  if (!stats)
223
223
  return undefined;
224
224
  const { cacheTokens: _summed, ...rest } = stats;
225
- return rest;
225
+ if (previous === undefined || stats.promptTokens === undefined) {
226
+ return rest;
227
+ }
228
+ return { ...rest, cacheTokens: previous + stats.promptTokens + (stats.generatedTokens ?? 0) };
229
+ }
230
+ function boundaryStats(final, predict) {
231
+ const stats = copy(final.stats);
232
+ if (final.stopReason !== 'length' || stats?.contextBoundary !== undefined) {
233
+ return stats;
234
+ }
235
+ const capped = predict !== undefined && predict > 0 && (stats?.generatedTokens ?? 0) >= predict;
236
+ return { ...stats, contextBoundary: !capped };
226
237
  }
227
238
  function roundTokens(stats) {
228
239
  if (!stats)
@@ -256,7 +267,7 @@ export async function* runRecoveredRound(sdk, args) {
256
267
  }
257
268
  const ctxSize = lease?.ctxSize ?? args.fold?.ctxSize;
258
269
  const slotted = (lease?.slots ?? 1) > 1;
259
- const attempts = { sent: 0, uncached: slotted, overflows: 0, unsettled };
270
+ const attempts = { sent: 0, uncached: false, overflows: 0, unsettled };
260
271
  const round = yield* runRecoveredRoundWith({
261
272
  sdk: roundSdk,
262
273
  args,
@@ -264,16 +275,21 @@ export async function* runRecoveredRound(sdk, args) {
264
275
  ctxSize,
265
276
  attempts
266
277
  });
278
+ const final = slotted
279
+ ? {
280
+ ...round.final,
281
+ stats: slotStats(round.final.stats, round.cacheable !== false && args.cacheKey
282
+ ? (Fold.reading(args.cacheKey)?.cacheTokens ?? 0)
283
+ : undefined)
284
+ }
285
+ : round.final;
267
286
  if (args.fold?.cacheKey) {
268
287
  Fold.observe(args.fold.cacheKey, {
269
- cacheTokens: foldTokens(round.final.stats, round.cacheable),
288
+ cacheTokens: foldTokens(final.stats, round.cacheable),
270
289
  ctxSize
271
290
  });
272
291
  }
273
292
  const overflows = attempts.overflows ? { overflows: attempts.overflows } : {};
274
- const final = slotted
275
- ? { ...round.final, stats: withoutCacheTokens(round.final.stats) }
276
- : round.final;
277
293
  return { ...round, final, ctxSize: lease?.ctxSize, ...overflows };
278
294
  }
279
295
  finally {
@@ -679,7 +695,7 @@ async function* runCandidate({ sdk, args, modelId, candidate, progress, baseHist
679
695
  ...final,
680
696
  toolCalls: copy(state.runaway || state.cut !== null ? state.calls : (final.toolCalls ?? [])),
681
697
  toolErrors: copy(final.toolErrors ?? []),
682
- stats: copy(final.stats)
698
+ stats: boundaryStats(final, params.generationParams?.predict)
683
699
  };
684
700
  if (args.capture) {
685
701
  yield inferenceSent({ args, candidate, final: detachedFinal });
@@ -1,4 +1,4 @@
1
- import type { Tool as SdkTool } from '@qvac/sdk';
1
+ import type { Tool as SdkTool } from '@qvac/inference';
2
2
  import type { HookPipeline } from '../../hooks/index.ts';
3
3
  import { type RunOutcomeTracker } from '../../helpers/run-outcome.ts';
4
4
  import type { AgentPolicy, AgentPorts, CompletionEvent, CliValidator, CompiledPolicy, CompletionSdk, DriveRoot, LlmGenerationParams, OutboundGuard, RunBackendUse, RunBudget, SkillActivation, ToolDefinition } from '../../contract/index.ts';
@@ -1,4 +1,4 @@
1
- import type { ToolCallWithCall } from '@qvac/sdk';
1
+ import type { ToolCallWithCall } from '@qvac/inference';
2
2
  import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
3
3
  import type { HookPipeline } from '../../hooks/index.ts';
4
4
  import type { NetworkMode, PreToolCallPayload, ToolFailurePayload } from '../../contract/index.ts';
@@ -1,4 +1,4 @@
1
- import type { Tool as SdkTool } from '@qvac/sdk';
1
+ import type { Tool as SdkTool } from '@qvac/inference';
2
2
  export declare class ToolSets {
3
3
  sets: Map<string, {
4
4
  type: "function";
@@ -1,5 +1,5 @@
1
1
  import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
2
- import type { ModelProgressUpdate } from '@qvac/sdk';
2
+ import type { ModelProgressUpdate } from '@qvac/inference';
3
3
  import { Readable } from 'streamx';
4
4
  import { type ModelAddon, type ModelRegistrySdk } from '../models/model-source.ts';
5
5
  export type DownloadProgress = Omit<ModelProgressUpdate, 'type'>;
@@ -7,7 +7,7 @@ export type KvCacheDeletionResult = {
7
7
  status: 'unsupported';
8
8
  error: string;
9
9
  };
10
- type KvCacheSdk = Pick<typeof import('@qvac/sdk'), 'deleteCache'>;
10
+ type KvCacheSdk = Pick<typeof import('@qvac/inference'), 'deleteCache'>;
11
11
  export declare function deleteAllKvCaches(loadSdk: () => Promise<KvCacheSdk>): Promise<KvCacheDeletionResult>;
12
12
  export declare function deleteKvCacheKey(loadSdk: () => Promise<KvCacheSdk>, kvCacheKey: string): Promise<KvCacheDeletionResult>;
13
13
  export declare function unsupportedKvCacheDeletion(error?: string): KvCacheDeletionResult;
@@ -1,4 +1,4 @@
1
- import type { Tool as SdkTool } from '@qvac/sdk';
1
+ import type { Tool as SdkTool } from '@qvac/inference';
2
2
  export interface PromptPrefix {
3
3
  system: string | null;
4
4
  tools: ReadonlyArray<SdkTool> | undefined;
@@ -1,4 +1,4 @@
1
- import type { Tool as SdkTool } from '@qvac/sdk';
1
+ import type { Tool as SdkTool } from '@qvac/inference';
2
2
  import type { AgentSkill, CompletionHistoryEntry, Message, ToolDefinition } from '../contract/index.ts';
3
3
  export declare const TOOL_SEARCH_TOOL_NAME: string;
4
4
  export declare function defers(tool: ToolDefinition): boolean;
@@ -1,4 +1,4 @@
1
- import type { Tool as SdkTool } from '@qvac/sdk';
1
+ import type { Tool as SdkTool } from '@qvac/inference';
2
2
  export interface ToolOwnership {
3
3
  readonly name: string;
4
4
  readonly skillGated?: boolean | undefined;
@@ -11,6 +11,8 @@ export declare const TOOL_CUT_OFF_MESSAGE: string;
11
11
  export declare const TOOL_ROUND_CUT_MESSAGE: string;
12
12
  export declare const TOOL_CONTEXT_BOUNDARY_MESSAGE: string;
13
13
  export declare const TOOL_REPEATED_MESSAGE: string;
14
+ export declare const TOOL_FAILING_MESSAGE: string;
15
+ export declare const FAILURE_STREAK = 3;
14
16
  export declare const TOOL_UNCHANGED_MESSAGE: string;
15
17
  export declare const GOAL_CONTINUATION_NUDGE: string;
16
18
  export declare function checkMaxToolRounds(rounds: number): number;
@@ -24,6 +24,10 @@ export const TOOL_CONTEXT_BOUNDARY_MESSAGE = 'This tool call was not executed: t
24
24
  'them short.';
25
25
  export const TOOL_REPEATED_MESSAGE = 'You sent the same tool call more than once in one response. It ran once, and its result ' +
26
26
  'is below. Send each call once.';
27
+ export const TOOL_FAILING_MESSAGE = 'This call has failed {count} times in a row. Before changing anything again, step back: ' +
28
+ 're-read the failing output and the requirements, work out what the failures have in common, ' +
29
+ 'and change your approach instead of patching the last error.';
30
+ export const FAILURE_STREAK = 3;
27
31
  export const TOOL_UNCHANGED_MESSAGE = 'This call returned the same result the last {count} times it ran. Running it again will ' +
28
32
  'not change it: use the result you have, try something else, or answer.';
29
33
  export const GOAL_CONTINUATION_NUDGE = '[The goal is not met yet. Keep working on it: call the next tool. Track the work with ' +
@@ -1,4 +1,4 @@
1
- import type { CompletionEvent as SdkCompletionEvent, CompletionFinal, Tool as SdkTool, ToolCallWithCall, ToolDialect } from '@qvac/sdk';
1
+ import type { CompletionEvent as SdkCompletionEvent, CompletionFinal, Tool as SdkTool, ToolCallWithCall, ToolDialect } from '@qvac/inference';
2
2
  import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
3
3
  import type { TextEvent } from '../helpers/thinking.ts';
4
4
  import type { LlmGenerationParams } from '../models/llm-presets.ts';
@@ -1,4 +1,4 @@
1
- import type { createVectorIndex, loadVectorIndex } from '@qvac/sdk';
1
+ import type { createVectorIndex, loadVectorIndex } from '@qvac/inference';
2
2
  import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
3
3
  import type { ModelSrc } from '../models/context.ts';
4
4
  import type { HoldFn } from '../models/download-gate.ts';
@@ -1,4 +1,4 @@
1
- import type { TextToSpeechStreamClientParams, TextToSpeechStreamSession } from '@qvac/sdk';
1
+ import type { TextToSpeechStreamClientParams, TextToSpeechStreamSession } from '@qvac/inference';
2
2
  import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
3
3
  import type { CapabilityProfile } from '../models/model-catalog-constants.ts';
4
4
  export type TtsStreamSession = TextToSpeechStreamSession;
@@ -158,6 +158,17 @@ function unchangedRound(context, payload) {
158
158
  function settledSince(settled) {
159
159
  return Object.fromEntries(Object.entries(settled).map(([key, result]) => [key, { ...result, repeats: 0 }]));
160
160
  }
161
+ function failureStreaks(context, payload) {
162
+ const streaks = context.failureStreaks;
163
+ if (payload.failed) {
164
+ return { ...streaks, [payload.failed.key]: (streaks?.[payload.failed.key] ?? 0) + 1 };
165
+ }
166
+ if (streaks && payload.settled && payload.settled.key in streaks) {
167
+ const { [payload.settled.key]: _cleared, ...rest } = streaks;
168
+ return rest;
169
+ }
170
+ return streaks;
171
+ }
161
172
  function applyToolResult(context, payload, call) {
162
173
  const failedCalls = payload.failed
163
174
  ? {
@@ -184,6 +195,7 @@ function applyToolResult(context, payload, call) {
184
195
  : context.deniedKeys,
185
196
  failedCalls,
186
197
  blockedRepeats: context.blockedRepeats + (payload.blockedRepeat || unchangedRound(context, payload) ? 1 : 0),
198
+ failureStreaks: failureStreaks(context, payload),
187
199
  settledResults: payload.settled
188
200
  ? {
189
201
  ...(payload.progressed ? settledSince(context.settledResults) : context.settledResults),
@@ -254,6 +254,7 @@ export interface RunPolicy {
254
254
  roundCutMessage: string;
255
255
  repeatedCallMessage: string;
256
256
  unchangedMessage: string;
257
+ failingMessage?: string;
257
258
  goalNudge: string;
258
259
  }
259
260
  export interface SettledResult {
@@ -309,6 +310,7 @@ export interface CompletionContext {
309
310
  failedCalls: Record<string, SettledCall>;
310
311
  blockedRepeats: number;
311
312
  settledResults: Record<string, SettledResult>;
313
+ failureStreaks?: Record<string, number>;
312
314
  answeredReads?: string[];
313
315
  roundProgressed: boolean;
314
316
  answer: string | null;
@@ -1,4 +1,4 @@
1
- import type { ModelRegistryEntry } from '@qvac/sdk';
1
+ import type { ModelRegistryEntry } from '@qvac/inference';
2
2
  export type ModelSrc = string | (ModelRegistryEntry & {
3
3
  src: string;
4
4
  });
@@ -1,4 +1,4 @@
1
- import type { ModelRegistryEntry, ToolDialect } from '@qvac/sdk';
1
+ import type { ModelRegistryEntry, ToolDialect } from '@qvac/inference';
2
2
  import type { ModelSrc } from './context.ts';
3
3
  import type { ModelAddon } from './model-source.ts';
4
4
  export interface SdkModelAsset extends ModelRegistryEntry {
@@ -1,4 +1,4 @@
1
- import type * as QvacSdk from '@qvac/sdk';
1
+ import type * as QvacSdk from '@qvac/inference';
2
2
  export type ModelDeleteSdk = Pick<typeof QvacSdk, 'getModelInfo'>;
3
3
  export interface DeletedModelFile {
4
4
  readonly path: string;
@@ -1,4 +1,4 @@
1
- import type { AssessModelFitInput, AssessModelFitResult } from '@qvac/sdk';
1
+ import type { AssessModelFitInput, AssessModelFitResult } from '@qvac/inference';
2
2
  export type ModelFitVerdict = AssessModelFitResult['verdict'];
3
3
  export type ModelFitBasis = AssessModelFitResult['basis'];
4
4
  export type ModelFitEvidence = NonNullable<AssessModelFitResult['evidence']>;
@@ -1,4 +1,4 @@
1
- import type * as QvacSdk from '@qvac/sdk';
1
+ import type * as QvacSdk from '@qvac/inference';
2
2
  import { type ModelAddon, type ModelRegistrySdk } from './model-source.ts';
3
3
  import { type ModelTaskType } from './model-task.ts';
4
4
  import type { ModelFitBasis, ModelFitEvidence, ModelFitVerdict } from './model-fit.ts';
@@ -4,11 +4,11 @@ import { type ModelSrc } from './context.ts';
4
4
  import type { CpuPlacement } from '../hardware/cpu-placement.ts';
5
5
  import { type ModelAddon } from './model-source.ts';
6
6
  import type { GpuFaultState } from './sdk-faults.ts';
7
- import type { LoadedModelInfo } from '@qvac/sdk';
7
+ import type { LoadedModelInfo } from '@qvac/inference';
8
8
  import type { LoadedModel } from '../contract-types.ts';
9
9
  import type { HoldFn } from './download-gate.ts';
10
- type SdkModule = typeof import('@qvac/sdk');
11
- type FitModelType = NonNullable<import('@qvac/sdk').AssessModelFitInput['models'][number]['modelType']>;
10
+ type SdkModule = typeof import('@qvac/inference');
11
+ type FitModelType = NonNullable<import('@qvac/inference').AssessModelFitInput['models'][number]['modelType']>;
12
12
  export interface FitProbeSdk {
13
13
  getLoadedModelInfo?(params: {
14
14
  modelId: string;
@@ -1,5 +1,5 @@
1
- import type * as QvacSdk from '@qvac/sdk';
2
- import type { ModelRegistryEntryAddon } from '@qvac/sdk';
1
+ import type * as QvacSdk from '@qvac/inference';
2
+ import type { ModelRegistryEntryAddon } from '@qvac/inference';
3
3
  import type { ModelSrc } from './context.ts';
4
4
  export type ModelRegistrySdk = Pick<typeof QvacSdk, 'modelRegistrySearch'>;
5
5
  export type ModelAddon = ModelRegistryEntryAddon;
@@ -1,2 +1,2 @@
1
- import type { ToolDialect } from '@qvac/sdk';
1
+ import type { ToolDialect } from '@qvac/inference';
2
2
  export declare function detectToolDialect(src: string, name?: string): ToolDialect | undefined;
@@ -1,10 +1,11 @@
1
- import type { AccessPolicy, CompiledPolicy, PolicyGrants, PolicyProvider, RunRoots } from '../contract/policy.ts';
1
+ import type { AccessPolicy, CompiledPolicy, PolicyGrants, PolicyProvider, PolicyRoot, RunRoots } from '../contract/policy.ts';
2
2
  export declare class Policy {
3
3
  static narrow(...layers: readonly (AccessPolicy | null | undefined)[]): AccessPolicy;
4
4
  static compile(policy: AccessPolicy | null | undefined, grants?: PolicyGrants): CompiledPolicy;
5
5
  static enforceable(policy: CompiledPolicy, { enforces }: PolicyProvider): string | null;
6
6
  static refusal(policy: CompiledPolicy, providers: readonly PolicyProvider[]): string | null;
7
7
  static forRun(layers: readonly (AccessPolicy | null | undefined)[], { fsRoots, fsWriteRoots, deny }: RunRoots, providers: readonly PolicyProvider[]): CompiledPolicy | undefined;
8
+ static withWrites(policy: CompiledPolicy, roots: readonly PolicyRoot[]): CompiledPolicy;
8
9
  static hostsOf(policy: CompiledPolicy | undefined): readonly string[] | undefined;
9
10
  static allowsHost(hosts: readonly string[], host: string): boolean;
10
11
  }
@@ -90,6 +90,12 @@ export class Policy {
90
90
  }
91
91
  return access;
92
92
  }
93
+ static withWrites(policy, roots) {
94
+ if (roots.length === 0) {
95
+ return policy;
96
+ }
97
+ return { ...policy, files: { ...policy.files, write: [...policy.files.write, ...roots] } };
98
+ }
93
99
  static hostsOf(policy) {
94
100
  return policy?.network.mode === 'hosts' ? policy.network.hosts : undefined;
95
101
  }
@@ -4,6 +4,7 @@ import type { PolicyEnforcement } from '../../lib/contract/index.ts';
4
4
  import { type SeccompArch } from './seccomp.ts';
5
5
  export interface LinuxSandboxOptions {
6
6
  readonly bwrap?: string;
7
+ readonly writable?: readonly string[];
7
8
  }
8
9
  export interface BwrapRun {
9
10
  readonly read: 'all' | readonly string[];
@@ -34,9 +35,10 @@ export declare class LinuxSandbox implements HarnessPlugin {
34
35
  readonly enforces: PolicyEnforcement;
35
36
  readonly shell: ExecShell;
36
37
  private readonly _bwrap;
38
+ private readonly _writable;
37
39
  private _denied;
38
40
  private readonly _stubs;
39
- constructor({ bwrap }?: LinuxSandboxOptions);
41
+ constructor({ bwrap, writable }?: LinuxSandboxOptions);
40
42
  validate(): string | null;
41
43
  setup(ctx: PluginContext): Promise<PluginSetup>;
42
44
  static argv(run: BwrapRun, line: string): string[];
@@ -42,10 +42,12 @@ export class LinuxSandbox {
42
42
  enforces = ENFORCES;
43
43
  shell;
44
44
  _bwrap;
45
+ _writable;
45
46
  _denied = [];
46
47
  _stubs = new Map();
47
- constructor({ bwrap = '/usr/bin/bwrap' } = {}) {
48
+ constructor({ bwrap = '/usr/bin/bwrap', writable = [] } = {}) {
48
49
  this._bwrap = bwrap;
50
+ this._writable = writable;
49
51
  this.shell = {
50
52
  name: 'bwrap',
51
53
  enforces: ENFORCES,
@@ -73,10 +75,15 @@ export class LinuxSandbox {
73
75
  if (process.platform !== 'linux') {
74
76
  return `bubblewrap runs on Linux only, not ${process.platform}`;
75
77
  }
76
- return ARCHES[process.arch] ? null : `has no seccomp program for ${process.arch}`;
78
+ if (!ARCHES[process.arch]) {
79
+ return `has no seccomp program for ${process.arch}`;
80
+ }
81
+ const relative = this._writable.find((folder) => !path.isAbsolute(folder));
82
+ return relative === undefined ? null : `needs absolute writable folders, not ${relative}`;
77
83
  }
78
84
  async setup(ctx) {
79
85
  this._denied = ctx.deniedRoots;
86
+ await Promise.all(this._writable.map((folder) => fs.promises.mkdir(folder, { recursive: true })));
80
87
  await this._probe();
81
88
  return { exec: { shell: this.shell }, services: { sandbox: this._service() } };
82
89
  }
@@ -132,7 +139,7 @@ export class LinuxSandbox {
132
139
  if (refused) {
133
140
  throw new Error(`${this.name} ${refused}`);
134
141
  }
135
- return policy;
142
+ return Policy.withWrites(policy, this._writable);
136
143
  }
137
144
  async _workspace(dir, policy) {
138
145
  const tmp = await scratch();
@@ -12,6 +12,7 @@ export interface ProfileCounts {
12
12
  }
13
13
  export interface SeatbeltOptions {
14
14
  readonly sandboxExec?: string;
15
+ readonly writable?: readonly string[];
15
16
  }
16
17
  export declare class SeatbeltSandbox implements HarnessPlugin {
17
18
  readonly name = "sandbox-macos";
@@ -32,10 +33,11 @@ export declare class SeatbeltSandbox implements HarnessPlugin {
32
33
  };
33
34
  readonly shell: ExecShell;
34
35
  private readonly _sandboxExec;
36
+ private readonly _writable;
35
37
  private _denied;
36
38
  private _proxy;
37
39
  private _userTemp;
38
- constructor({ sandboxExec }?: SeatbeltOptions);
40
+ constructor({ sandboxExec, writable }?: SeatbeltOptions);
39
41
  get enforces(): PolicyEnforcement;
40
42
  validate(): string | null;
41
43
  setup(ctx: PluginContext): Promise<PluginSetup>;
@@ -76,11 +76,13 @@ export class SeatbeltSandbox {
76
76
  addons = { 'bare-subprocess': () => import('bare-subprocess') };
77
77
  shell;
78
78
  _sandboxExec;
79
+ _writable;
79
80
  _denied = [];
80
81
  _proxy = () => undefined;
81
82
  _userTemp = null;
82
- constructor({ sandboxExec = '/usr/bin/sandbox-exec' } = {}) {
83
+ constructor({ sandboxExec = '/usr/bin/sandbox-exec', writable = [] } = {}) {
83
84
  this._sandboxExec = sandboxExec;
85
+ this._writable = writable;
84
86
  const enforcement = () => this.enforces;
85
87
  this.shell = {
86
88
  name: 'seatbelt',
@@ -115,13 +117,16 @@ export class SeatbeltSandbox {
115
117
  return this._proxy() ? HOSTS : ON_OFF;
116
118
  }
117
119
  validate() {
118
- return process.platform === 'darwin'
119
- ? null
120
- : `Seatbelt runs on macOS only, not ${process.platform}`;
120
+ if (process.platform !== 'darwin') {
121
+ return `Seatbelt runs on macOS only, not ${process.platform}`;
122
+ }
123
+ const relative = this._writable.find((folder) => !path.isAbsolute(folder));
124
+ return relative === undefined ? null : `needs absolute writable folders, not ${relative}`;
121
125
  }
122
126
  async setup(ctx) {
123
127
  this._denied = ctx.deniedRoots;
124
128
  this._proxy = () => ctx.services['egress-proxy'];
129
+ await Promise.all(this._writable.map((folder) => fs.promises.mkdir(folder, { recursive: true })));
125
130
  await this._probe();
126
131
  this._userTemp = await SeatbeltSandbox._darwinUserTemp();
127
132
  return { exec: { shell: this.shell }, services: { sandbox: this._service() } };
@@ -152,7 +157,7 @@ export class SeatbeltSandbox {
152
157
  if (refused) {
153
158
  throw new Error(`${this.name} ${refused}`);
154
159
  }
155
- return policy;
160
+ return Policy.withWrites(policy, this._writable);
156
161
  }
157
162
  async _workspace(dir, policy) {
158
163
  const tmp = await this._scratch();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/harness",
3
- "version": "1.0.0-rc.8",
3
+ "version": "1.0.0-rc.9",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "bare": ">=1.34.0",
@@ -550,12 +550,12 @@
550
550
  "default": "buffer"
551
551
  },
552
552
  "#sdk": {
553
- "types": "@qvac/sdk",
553
+ "types": "@qvac/inference",
554
554
  "bare": "@qvac/inference",
555
555
  "default": "@qvac/sdk"
556
556
  },
557
557
  "#sdk-logging": {
558
- "types": "@qvac/sdk/logging",
558
+ "types": "@qvac/inference/logging",
559
559
  "bare": "@qvac/inference/logging",
560
560
  "default": "@qvac/sdk/logging"
561
561
  },
@@ -740,7 +740,6 @@
740
740
  "lunte": "^1.8.6",
741
741
  "lunte-plugin-qvac": "^0.2.0",
742
742
  "paparam": "^1.13.0",
743
- "pdfjs-dist": "^6.3.289",
744
743
  "prettier": "^3.6.2",
745
744
  "prettier-config-holepunch": "^2.0.0",
746
745
  "pyodide": "314.0.2",
@@ -749,8 +748,7 @@
749
748
  },
750
749
  "patchedDependencies": {
751
750
  "pyodide@314.0.2": "patches/pyodide@314.0.2.patch",
752
- "localwatch@1.4.3": "patches/localwatch@1.4.3.patch",
753
- "@qvac/inference@0.22.0": "patches/@qvac%2Finference@0.22.0.patch"
751
+ "localwatch@1.4.3": "patches/localwatch@1.4.3.patch"
754
752
  },
755
753
  "repository": {
756
754
  "type": "git",
@@ -1,59 +0,0 @@
1
- diff --git a/dist/plugins/builtin/llamacpp-completion/plugin.js b/dist/plugins/builtin/llamacpp-completion/plugin.js
2
- index e9b4d9465016822145c7d01373ba3cc0a2770ad2..8a1709c8094d3641247df25dd435741bc72a82cd 100644
3
- --- a/dist/plugins/builtin/llamacpp-completion/plugin.js
4
- +++ b/dist/plugins/builtin/llamacpp-completion/plugin.js
5
- @@ -386,8 +386,12 @@ export const llmPlugin = definePlugin({
6
- generatedTokens: stats?.generatedTokens,
7
- stoppedAtContextBoundary
8
- });
9
- + // qvac-harness patch: tell a stop at the context window from one at the predict cap
10
- + const finalStats = lengthStop
11
- + ? { ...stats, contextBoundary: stoppedAtContextBoundary }
12
- + : stats;
13
- const terminalEvents = normalizer.finish({
14
- - ...(stats && { stats }),
15
- + ...(finalStats && { stats: finalStats }),
16
- ...(toolCalls.length > 0 && { toolCalls }),
17
- ...(cancelled && { stopReason: 'cancelled' }),
18
- ...(lengthStop && { stopReason: 'length' })
19
- diff --git a/dist/schemas/completion-event.d.ts b/dist/schemas/completion-event.d.ts
20
- index 7c126fa0750ddc75c5da0a2d54e9468e429a64d8..8207ed48f3ff5c164e99b1a58624449ec4cef1f4 100644
21
- --- a/dist/schemas/completion-event.d.ts
22
- +++ b/dist/schemas/completion-event.d.ts
23
- @@ -5,6 +5,7 @@ export declare const completionStatsSchema: z.ZodObject<{
24
- timeToFirstToken: z.ZodOptional<z.ZodNumber>;
25
- tokensPerSecond: z.ZodOptional<z.ZodNumber>;
26
- promptTokensPerSecond: z.ZodOptional<z.ZodNumber>;
27
- + contextBoundary: z.ZodOptional<z.ZodBoolean>;
28
- cacheTokens: z.ZodOptional<z.ZodNumber>;
29
- promptTokens: z.ZodOptional<z.ZodNumber>;
30
- generatedTokens: z.ZodOptional<z.ZodNumber>;
31
- @@ -63,6 +64,7 @@ export declare const statsEventSchema: z.ZodObject<{
32
- timeToFirstToken: z.ZodOptional<z.ZodNumber>;
33
- tokensPerSecond: z.ZodOptional<z.ZodNumber>;
34
- promptTokensPerSecond: z.ZodOptional<z.ZodNumber>;
35
- + contextBoundary: z.ZodOptional<z.ZodBoolean>;
36
- cacheTokens: z.ZodOptional<z.ZodNumber>;
37
- promptTokens: z.ZodOptional<z.ZodNumber>;
38
- generatedTokens: z.ZodOptional<z.ZodNumber>;
39
- @@ -147,6 +149,7 @@ export declare const completionEventSchema: z.ZodUnion<readonly [z.ZodObject<{
40
- timeToFirstToken: z.ZodOptional<z.ZodNumber>;
41
- tokensPerSecond: z.ZodOptional<z.ZodNumber>;
42
- promptTokensPerSecond: z.ZodOptional<z.ZodNumber>;
43
- + contextBoundary: z.ZodOptional<z.ZodBoolean>;
44
- cacheTokens: z.ZodOptional<z.ZodNumber>;
45
- promptTokens: z.ZodOptional<z.ZodNumber>;
46
- generatedTokens: z.ZodOptional<z.ZodNumber>;
47
- diff --git a/dist/schemas/completion-event.js b/dist/schemas/completion-event.js
48
- index 1ef0d68a9a8cf6f590988272e114ac54ea093614..174c2e25b39291c0858079b87db2de84a1b7ebcd 100644
49
- --- a/dist/schemas/completion-event.js
50
- +++ b/dist/schemas/completion-event.js
51
- @@ -4,6 +4,8 @@ export const completionStatsSchema = z.object({
52
- timeToFirstToken: z.number().optional(),
53
- tokensPerSecond: z.number().optional(),
54
- promptTokensPerSecond: z.number().optional(),
55
- + // qvac-harness patch: the round stopped at the context window, not at the predict cap
56
- + contextBoundary: z.boolean().optional(),
57
- cacheTokens: z.number().optional(),
58
- promptTokens: z.number().optional(),
59
- // Decode count (`llama_perf` `n_eval`) — length / KV-cache budget decisions.