@qvac/harness 1.0.0-rc.16 → 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 (115) hide show
  1. package/CHANGELOG.md +117 -2
  2. package/dist-lib/index.d.ts +6 -2
  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 +1 -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/loop.d.ts +2 -1
  15. package/dist-lib/lib/capabilities/completion-engine/operations.js +28 -9
  16. package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -2
  17. package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +3 -1
  18. package/dist-lib/lib/capabilities/completion-engine/session.d.ts +1 -0
  19. package/dist-lib/lib/capabilities/completion-engine/session.js +1 -0
  20. package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +2 -1
  21. package/dist-lib/lib/capabilities/completion-engine/turns.js +5 -2
  22. package/dist-lib/lib/capabilities/enhance.js +3 -3
  23. package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -1
  24. package/dist-lib/lib/capabilities/sdk-tool.js +3 -2
  25. package/dist-lib/lib/capabilities/skill-entry.d.ts +9 -1
  26. package/dist-lib/lib/capabilities/skill-entry.js +11 -7
  27. package/dist-lib/lib/capabilities/tool-turns.d.ts +5 -0
  28. package/dist-lib/lib/capabilities/tool-turns.js +24 -27
  29. package/dist-lib/lib/client/index.js +3 -2
  30. package/dist-lib/lib/connect.d.ts +2 -0
  31. package/dist-lib/lib/connect.js +33 -3
  32. package/dist-lib/lib/contract/completion.d.ts +14 -0
  33. package/dist-lib/lib/contract/exec.d.ts +1 -0
  34. package/dist-lib/lib/contract/ocr.d.ts +4 -0
  35. package/dist-lib/lib/contract/run.d.ts +8 -0
  36. package/dist-lib/lib/contract-types.d.ts +4 -1
  37. package/dist-lib/lib/guards.d.ts +2 -0
  38. package/dist-lib/lib/guards.js +7 -0
  39. package/dist-lib/lib/hardware/capability-probe.js +10 -7
  40. package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
  41. package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
  42. package/dist-lib/lib/helpers/completion-params.d.ts +2 -1
  43. package/dist-lib/lib/helpers/completion-params.js +16 -1
  44. package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
  45. package/dist-lib/lib/helpers/control-tokens.js +25 -0
  46. package/dist-lib/lib/machine/completion/actions/completion.js +34 -5
  47. package/dist-lib/lib/machine/completion/actions/tools.js +4 -1
  48. package/dist-lib/lib/machine/completion/rules.d.ts +2 -0
  49. package/dist-lib/lib/machine/completion/rules.js +7 -0
  50. package/dist-lib/lib/machine/completion/types.d.ts +6 -0
  51. package/dist-lib/lib/machine/index.d.ts +2 -1
  52. package/dist-lib/lib/machine/index.js +2 -1
  53. package/dist-lib/lib/no-redirect-fetch-impl.d.ts +1 -1
  54. package/dist-lib/lib/no-redirect-fetch-impl.js +13 -7
  55. package/dist-lib/lib/plugins/registry.d.ts +3 -0
  56. package/dist-lib/lib/plugins/registry.js +15 -1
  57. package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
  58. package/dist-lib/lib/plugins/require-bare.js +13 -0
  59. package/dist-lib/lib/run-log/request-codec.js +2 -2
  60. package/dist-lib/lib/serve.js +38 -1
  61. package/dist-lib/lib/sidecar/index.js +2 -1
  62. package/dist-lib/lib/skills-host/index.js +7 -1
  63. package/dist-lib/lib/spawn.d.ts +2 -0
  64. package/dist-lib/lib/spawn.js +5 -3
  65. package/dist-lib/lib/tools/ask-user.d.ts +2 -0
  66. package/dist-lib/lib/tools/ask-user.js +137 -0
  67. package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
  68. package/dist-lib/lib/tools/attachments/delivered.js +16 -0
  69. package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
  70. package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
  71. package/dist-lib/lib/tools/exec.js +2 -1
  72. package/dist-lib/lib/tools/fs/document-text.js +3 -26
  73. package/dist-lib/lib/tools/http-request/request.d.ts +2 -2
  74. package/dist-lib/lib/tools/http-request/request.js +1 -1
  75. package/dist-lib/lib/tools/http-request.d.ts +1 -0
  76. package/dist-lib/lib/tools/http-request.js +54 -3
  77. package/dist-lib/lib/tools/index.d.ts +2 -1
  78. package/dist-lib/lib/tools/index.js +5 -1
  79. package/dist-lib/lib/tools/office.js +20 -12
  80. package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
  81. package/dist-lib/lib/tools/pdf/pages.js +28 -0
  82. package/dist-lib/lib/tools/pdf.js +24 -9
  83. package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
  84. package/dist-lib/lib/tools/skills/scope-key.js +4 -0
  85. package/dist-lib/lib/tools/web-fetch.js +41 -130
  86. package/dist-lib/plugins/knowledge/index.js +3 -3
  87. package/dist-lib/plugins/mcp/call.js +5 -1
  88. package/dist-lib/plugins/mcp/protocol.d.ts +6 -1
  89. package/dist-lib/plugins/mcp/protocol.js +2 -2
  90. package/dist-lib/plugins/ocr/reading-order.js +151 -4
  91. package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
  92. package/dist-lib/plugins/python/bare-floor.js +2 -0
  93. package/dist-lib/plugins/python/index.d.ts +1 -0
  94. package/dist-lib/plugins/python/index.js +1 -0
  95. package/dist-lib/plugins/python/language.js +9 -8
  96. package/dist-lib/plugins/python/python-adapter.d.ts +4 -0
  97. package/dist-lib/plugins/python/python-adapter.js +26 -0
  98. package/dist-lib/plugins/python/worker/client.js +1 -1
  99. package/dist-lib/plugins/python/worker/entry.js +2 -8
  100. package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
  101. package/dist-lib/plugins/python/worker/preload.js +2 -0
  102. package/dist-lib/plugins/python/worker/spawn.js +1 -1
  103. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  104. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  105. package/dist-lib/plugins/weather/lookup.js +1 -0
  106. package/dist-lib/schema/harness.js +17 -0
  107. package/dist-lib/spec/bind.js +3 -0
  108. package/dist-lib/spec/calls.js +1 -0
  109. package/dist-lib/spec/hrpc/hrpc.json +13 -0
  110. package/dist-lib/spec/hrpc/index.js +15 -3
  111. package/dist-lib/spec/hrpc/messages.js +32 -0
  112. package/dist-lib/spec/hyperschema/index.js +32 -0
  113. package/dist-lib/spec/hyperschema/schema.json +40 -0
  114. package/dist-lib/spec/hyperschema/types.d.ts +12 -0
  115. package/package.json +17 -8
@@ -4,4 +4,7 @@ export declare function endsTurn(token: string): boolean;
4
4
  export declare function controlTokenIndex(text: string): number;
5
5
  export declare function truncateAtControlToken(text: string): string;
6
6
  export declare function stripControlTokens(text: string): string;
7
+ export declare function defuseTemplateTokens(text: string): string;
8
+ export declare function restoreTemplateTokens(text: string): string;
9
+ export declare function mapStrings<Value>(value: Value, map: (text: string) => string): Value;
7
10
  export declare function stopAtControlToken(tokens: AsyncIterable<string>, onStop?: (token: string) => void): AsyncGenerator<string>;
@@ -1,5 +1,6 @@
1
1
  import { firstMarker, markers, strip, truncateAt } from 'asenion/guards';
2
2
  import { scanner } from 'asenion/scan';
3
+ import { isRecord } from '../guards.js';
3
4
  export const STOP_MARKERS = [...markers.controlTokens, ...markers.scaffold];
4
5
  const [SCAFFOLD_OPENING] = markers.scaffold;
5
6
  export const RUNAWAY_STOP_SEQUENCES = [SCAFFOLD_OPENING];
@@ -15,6 +16,30 @@ export function truncateAtControlToken(text) {
15
16
  export function stripControlTokens(text) {
16
17
  return strip(truncateAt(text, markers.scaffold), markers.controlTokens);
17
18
  }
19
+ const TOKEN_REST = String.raw `\|\w+\|>||[^|<>]+|>|(?:start|end)_of_turn>|\/?(?:tool_call|tool_response|think)>|tts_\w+>`;
20
+ const WORD_JOINER = '\u2060';
21
+ const TEMPLATE_TOKEN = new RegExp(`<(?=${TOKEN_REST})`, 'g');
22
+ const DEFUSED_TOKEN = new RegExp(`<${WORD_JOINER}(?=${TOKEN_REST})`, 'g');
23
+ export function defuseTemplateTokens(text) {
24
+ return text.replace(TEMPLATE_TOKEN, `<${WORD_JOINER}`);
25
+ }
26
+ export function restoreTemplateTokens(text) {
27
+ return text.replace(DEFUSED_TOKEN, '<');
28
+ }
29
+ export function mapStrings(value, map) {
30
+ return mapped(value, map);
31
+ }
32
+ function mapped(value, map) {
33
+ if (typeof value === 'string') {
34
+ return map(value);
35
+ }
36
+ if (Array.isArray(value)) {
37
+ return value.map((item) => mapped(item, map));
38
+ }
39
+ return isRecord(value)
40
+ ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, mapped(item, map)]))
41
+ : value;
42
+ }
18
43
  export async function* stopAtControlToken(tokens, onStop) {
19
44
  const safe = scanner({ stop: STOP_MARKERS });
20
45
  for await (const token of tokens) {
@@ -1,6 +1,6 @@
1
1
  import { hasRoundsLeft, stuckResult } from '../guards/retry.js';
2
2
  import { asksChecks, asksDeliverable, asksRun, citesPassed, deliverableAsk, deliverableChecked, existenceOnly, GOAL_CASES_ASK, GOAL_REVIEW_ASK, MAX_GOAL_CHECKS, MAX_PROOF_ASKS, mergeChecks, namedChecks, runAsk } from '../../../helpers/goal-check.js';
3
- import { activate, applyHistorySplice, applySplice, casesDue, checksMet, foldMetrics, goalMet, goalTokensLeft, nudgeWithChecks, nudgeWithPlan, retainFailureResults, settledSince } from '../rules.js';
3
+ import { activate, applyHistorySplice, applySplice, casesDue, checksMet, foldMetrics, goalMet, goalTokensLeft, imagesShownNote, MAX_SHOWN_IMAGES, nudgeWithChecks, nudgeWithPlan, retainFailureResults, settledSince } from '../rules.js';
4
4
  export function startInitialRound({ context, params }) {
5
5
  return applyPreparation(context, params);
6
6
  }
@@ -102,13 +102,32 @@ function closeFailureMemo(context) {
102
102
  }
103
103
  function endToolRound(context, { last = false } = {}) {
104
104
  return {
105
- history: [...context.history, ...continuation(context, { last })],
105
+ history: [
106
+ ...context.history,
107
+ ...showing(continuation(context, { last }), context.shownThisRound ?? [])
108
+ ],
106
109
  steering: [],
107
110
  delivered: context.delivered || context.deliveryEndsRun,
108
111
  deliveredThisRound: false,
109
- deliveryEndsRun: false
112
+ deliveryEndsRun: false,
113
+ shownThisRound: undefined
110
114
  };
111
115
  }
116
+ function showing(turns, images) {
117
+ const last = turns.at(-1);
118
+ const shown = images.slice(0, MAX_SHOWN_IMAGES);
119
+ if (!shown.length || !last || !('role' in last)) {
120
+ return turns;
121
+ }
122
+ return [
123
+ ...turns.slice(0, -1),
124
+ {
125
+ ...last,
126
+ content: `${last.content}\n${imagesShownNote(shown.map(({ fileName }) => fileName))}`,
127
+ attachments: shown.map(({ path }) => ({ path }))
128
+ }
129
+ ];
130
+ }
112
131
  function continuation(context, { last = false } = {}) {
113
132
  const { plan } = context;
114
133
  return context.steering.length
@@ -333,10 +352,20 @@ function swapStandingNudge(context) {
333
352
  if (!last || !standing || !('role' in last) || !('role' in standing)) {
334
353
  return {};
335
354
  }
336
- if (last.role !== 'user' || last.content !== standing.content) {
355
+ if (last.role !== 'user' || !last.content.startsWith(standing.content)) {
356
+ return {};
357
+ }
358
+ const note = last.content.slice(standing.content.length);
359
+ const wrapUp = continuation(context, { last: true });
360
+ if (!note) {
361
+ return { history: [...context.history.slice(0, -1), ...wrapUp] };
362
+ }
363
+ const [turn] = wrapUp;
364
+ if (!last.attachments?.length || wrapUp.length !== 1 || !turn || !('role' in turn)) {
337
365
  return {};
338
366
  }
339
- return { history: [...context.history.slice(0, -1), ...continuation(context, { last: true })] };
367
+ const shown = { ...turn, content: `${turn.content}${note}`, attachments: last.attachments };
368
+ return { history: [...context.history.slice(0, -1), shown] };
340
369
  }
341
370
  export function wrapMuteCompletion(args) {
342
371
  const turns = args.params.cutOff
@@ -148,7 +148,10 @@ function roundResult(context, payload) {
148
148
  return {
149
149
  answer: context.answer ?? payload.answer ?? null,
150
150
  deliveredThisRound: context.deliveredThisRound || payload.delivered === true,
151
- deliveryEndsRun: context.deliveryEndsRun || payload.deliveryEndsRun === true
151
+ deliveryEndsRun: context.deliveryEndsRun || payload.deliveryEndsRun === true,
152
+ shownThisRound: payload.shown
153
+ ? [...(context.shownThisRound ?? []), ...payload.shown]
154
+ : context.shownThisRound
152
155
  };
153
156
  }
154
157
  function unchangedRound(context, payload) {
@@ -9,7 +9,9 @@ export declare const MAX_BLOCKED_REPEATS = 3;
9
9
  export declare const MAX_UNCHANGED_RESULTS = 3;
10
10
  export declare const MAX_ROUND_REPEATS = 3;
11
11
  export declare const MAX_ROUND_CALLS = 32;
12
+ export declare const MAX_SHOWN_IMAGES = 4;
12
13
  export declare function nudgeWithPlan(nudge: string, plan: readonly PlanStep[]): string;
14
+ export declare function imagesShownNote(fileNames: readonly string[]): string;
13
15
  export declare function goalMet(context: Readonly<CompletionContext>): boolean;
14
16
  export declare function casesDue(context: Readonly<CompletionContext>): boolean;
15
17
  export declare function checksMet({ plan, goal }: Readonly<CompletionContext>): boolean;
@@ -15,6 +15,7 @@ export const MAX_BLOCKED_REPEATS = 3;
15
15
  export const MAX_UNCHANGED_RESULTS = 3;
16
16
  export const MAX_ROUND_REPEATS = 3;
17
17
  export const MAX_ROUND_CALLS = 32;
18
+ export const MAX_SHOWN_IMAGES = 4;
18
19
  const PLAN_MARKS = {
19
20
  pending: '[ ]',
20
21
  in_progress: '[>]',
@@ -27,6 +28,12 @@ export function nudgeWithPlan(nudge, plan) {
27
28
  const lines = plan.map(({ step, status }) => `${PLAN_MARKS[status]} ${step}`);
28
29
  return `${nudge}\nPlan:\n${lines.join('\n')}`;
29
30
  }
31
+ export function imagesShownNote(fileNames) {
32
+ const named = fileNames.map((name) => `"${name}"`).join(', ');
33
+ return fileNames.length === 1
34
+ ? `[The image at the start of this turn is ${named}, which a tool above attached. You can see it: use what it shows, with no tool to open it.]`
35
+ : `[The images at the start of this turn are ${named}, which tools above attached. You can see them: use what they show, with no tool to open them.]`;
36
+ }
30
37
  function isDone(step) {
31
38
  return step.status === 'done';
32
39
  }
@@ -131,6 +131,10 @@ export interface ApprovalGate {
131
131
  approver: boolean;
132
132
  call: ApprovalCall;
133
133
  }
134
+ export interface ShownImage {
135
+ path: string;
136
+ fileName: string;
137
+ }
134
138
  export interface ToolDonePayload {
135
139
  deniedKey?: string;
136
140
  webSearch?: boolean;
@@ -155,6 +159,7 @@ export interface ToolDonePayload {
155
159
  answer?: string;
156
160
  delivered?: boolean;
157
161
  deliveryEndsRun?: boolean;
162
+ shown?: ShownImage[];
158
163
  durationMs?: number;
159
164
  activate?: string;
160
165
  plan?: PlanStep[];
@@ -340,6 +345,7 @@ export interface CompletionContext {
340
345
  delivered: boolean;
341
346
  deliveredThisRound: boolean;
342
347
  deliveryEndsRun: boolean;
348
+ shownThisRound?: ShownImage[];
343
349
  activated: string[];
344
350
  outcome: RunOutcome | 'failed' | null;
345
351
  metrics: CompletionMetrics;
@@ -491,9 +491,10 @@ export declare class CompletionMachine {
491
491
  static cutShort: typeof cutShort;
492
492
  static atContextBoundary: typeof atContextBoundary;
493
493
  static MAX_ROUND_CALLS: number;
494
+ static MAX_SHOWN_IMAGES: number;
494
495
  static MAX_ROUND_REPEATS: number;
495
496
  }
496
497
  export type { MachineDefinitionNode } from './definition.ts';
497
498
  export type { EmptyCompletionContextOptions } from './completion/context.ts';
498
499
  export type { CompletionActorLogic, CompletionParent, InvocationInput, Stage } from './completion/ports.ts';
499
- export type { CompletionContext, RunPolicy, CompletionActorOutput, CompletionActorOutputs, EngineEvent } from './completion/types.ts';
500
+ export type { CompletionContext, RunPolicy, CompletionActorOutput, CompletionActorOutputs, EngineEvent, ShownImage } from './completion/types.ts';
@@ -2,7 +2,7 @@ import { goalStatus } from './completion/actions/completion.js';
2
2
  import { PLAN_MODE_REFUSAL } from './completion/actions/tools.js';
3
3
  import { emptyCompletionContext } from './completion/context.js';
4
4
  import { createCompletionMachine } from './completion/machine.js';
5
- import { atContextBoundary, cutOffMessage, cutShort, MAX_ROUND_CALLS, MAX_ROUND_REPEATS, runsUnasked } from './completion/rules.js';
5
+ import { atContextBoundary, cutOffMessage, cutShort, MAX_ROUND_CALLS, MAX_ROUND_REPEATS, MAX_SHOWN_IMAGES, runsUnasked } from './completion/rules.js';
6
6
  import { MACHINE_VERSION } from './completion/version.js';
7
7
  import { completionMachineDefinition, transitionName } from './definition.js';
8
8
  export class CompletionMachine {
@@ -18,5 +18,6 @@ export class CompletionMachine {
18
18
  static cutShort = cutShort;
19
19
  static atContextBoundary = atContextBoundary;
20
20
  static MAX_ROUND_CALLS = MAX_ROUND_CALLS;
21
+ static MAX_SHOWN_IMAGES = MAX_SHOWN_IMAGES;
21
22
  static MAX_ROUND_REPEATS = MAX_ROUND_REPEATS;
22
23
  }
@@ -25,7 +25,7 @@ export interface NoRedirectFetchInit {
25
25
  addEventListener(type: 'abort', listener: () => void): void;
26
26
  };
27
27
  validatedAddresses?: readonly string[] | undefined;
28
- maxBytes?: number;
28
+ maxBytes?: number | ((contentType: string) => number);
29
29
  truncate?: boolean;
30
30
  idleTimeoutMs?: number;
31
31
  }
@@ -32,6 +32,13 @@ export function runNoRedirectFetch(request, url, init = {}) {
32
32
  const method = init.method ?? 'GET';
33
33
  const req = request(url, { method, headers, validatedAddresses: init.validatedAddresses }, (res) => {
34
34
  armIdle();
35
+ const responseHeaders = {};
36
+ for (const [name, value] of Object.entries(res.headers)) {
37
+ responseHeaders[name.toLowerCase()] = String(value);
38
+ }
39
+ const maxBytes = typeof init.maxBytes === 'function'
40
+ ? init.maxBytes(contentTypeOf(responseHeaders))
41
+ : init.maxBytes;
35
42
  const chunks = [];
36
43
  let received = 0;
37
44
  let settled = false;
@@ -40,10 +47,6 @@ export function runNoRedirectFetch(request, url, init = {}) {
40
47
  return;
41
48
  settled = true;
42
49
  const body = b4a.concat(chunks);
43
- const responseHeaders = {};
44
- for (const [name, value] of Object.entries(res.headers)) {
45
- responseHeaders[name.toLowerCase()] = String(value);
46
- }
47
50
  resolve({
48
51
  status: res.statusCode,
49
52
  headers: {
@@ -63,9 +66,9 @@ export function runNoRedirectFetch(request, url, init = {}) {
63
66
  res.on('data', (chunk) => {
64
67
  armIdle();
65
68
  received += chunk.byteLength;
66
- if (init.maxBytes !== undefined && received > init.maxBytes) {
69
+ if (maxBytes !== undefined && received > maxBytes) {
67
70
  if (init.truncate) {
68
- const allowed = chunk.byteLength - (received - init.maxBytes);
71
+ const allowed = chunk.byteLength - (received - maxBytes);
69
72
  if (allowed > 0) {
70
73
  chunks.push(chunk.subarray(0, allowed));
71
74
  }
@@ -73,7 +76,7 @@ export function runNoRedirectFetch(request, url, init = {}) {
73
76
  req.destroy();
74
77
  return;
75
78
  }
76
- const err = new HarnessError('RESPONSE_TOO_LARGE', [init.maxBytes]);
79
+ const err = new HarnessError('RESPONSE_TOO_LARGE', [maxBytes]);
77
80
  req.destroy(err);
78
81
  fail(err);
79
82
  return;
@@ -116,3 +119,6 @@ export function runNoRedirectFetch(request, url, init = {}) {
116
119
  req.end();
117
120
  });
118
121
  }
122
+ function contentTypeOf(headers) {
123
+ return (headers['content-type'] ?? '').split(';')[0]?.trim().toLowerCase() ?? '';
124
+ }
@@ -87,6 +87,8 @@ export declare class PluginRegistry {
87
87
  private readonly _buildsExec;
88
88
  private readonly _deniedRoots;
89
89
  private readonly _loaded;
90
+ private readonly _order;
91
+ private readonly _addons;
90
92
  private readonly _held;
91
93
  private readonly _services;
92
94
  private readonly _cleanupErrors;
@@ -103,6 +105,7 @@ export declare class PluginRegistry {
103
105
  constructor(plugins: readonly HarnessPlugin[], options?: PluginRegistryOptions);
104
106
  static loadAddons(owner: string, addons?: AddonLoaders): Promise<void>;
105
107
  static requirePeers(plugin: string, peers: PeerResolvers): void;
108
+ static requireBare(plugin: string, floor: string): void;
106
109
  start(reserved: Iterable<string>, { fetch, publish }?: PluginStartOptions): Promise<StartedPlugins>;
107
110
  add(plugin: HarnessPlugin): Promise<void>;
108
111
  remove(name: string): Promise<void>;
@@ -3,6 +3,7 @@ import { Policy } from '../policy/index.js';
3
3
  import { canonicalDenyRoots, defaultRealpath } from '../tools/fs/scope.js';
4
4
  import { TOOLSETS } from '../tools/toolsets.js';
5
5
  import { loadAddons } from './addons.js';
6
+ import { requireBare } from './require-bare.js';
6
7
  import { requirePeers } from '../helpers/require-peers.js';
7
8
  import { PluginRuntime } from './runtime.js';
8
9
  const API_VERSION = 1;
@@ -249,6 +250,8 @@ export class PluginRegistry {
249
250
  _buildsExec;
250
251
  _deniedRoots;
251
252
  _loaded = [];
253
+ _order;
254
+ _addons = new Map();
252
255
  _held = [];
253
256
  _services = new Map();
254
257
  _cleanupErrors = [];
@@ -271,6 +274,7 @@ export class PluginRegistry {
271
274
  for (const plugin of order) {
272
275
  validated(plugin);
273
276
  }
277
+ this._order = order;
274
278
  const runtime = new PluginRuntime(order.map((plugin) => this._plugin(plugin, 0, (loaded) => this._loaded.push(loaded))));
275
279
  for (const [name, value] of core) {
276
280
  provideService(runtime.ctx, name, value);
@@ -287,6 +291,9 @@ export class PluginRegistry {
287
291
  static requirePeers(plugin, peers) {
288
292
  requirePeers(`@qvac/harness/plugins/${plugin}`, peers);
289
293
  }
294
+ static requireBare(plugin, floor) {
295
+ requireBare(`@qvac/harness/plugins/${plugin}`, floor);
296
+ }
290
297
  start(reserved, { fetch, publish } = {}) {
291
298
  if (this._closing) {
292
299
  return Promise.reject(new Error('Plugin registry is closing or closed'));
@@ -296,6 +303,11 @@ export class PluginRegistry {
296
303
  this._reserved = new Set(reserved);
297
304
  this._fetch = fetch;
298
305
  this._publish = publish;
306
+ for (const plugin of this._order) {
307
+ const loading = loadAddons(`plugin '${plugin.name}'`, plugin.addons);
308
+ loading.catch(noop);
309
+ this._addons.set(plugin, loading);
310
+ }
299
311
  this._starting = this._runtime.ready().then(() => this._started());
300
312
  return this._starting;
301
313
  }
@@ -392,7 +404,9 @@ export class PluginRegistry {
392
404
  for (const name of plugin.needs ?? []) {
393
405
  readService(ctx, name);
394
406
  }
395
- await loadAddons(`plugin '${plugin.name}'`, plugin.addons);
407
+ const loading = this._addons.get(plugin) ?? loadAddons(`plugin '${plugin.name}'`, plugin.addons);
408
+ this._addons.delete(plugin);
409
+ await loading;
396
410
  const onDispose = (dispose) => this._ownDispose(ctx, plugin.name, dispose);
397
411
  const fetch = this._fetch ? this._fetch(undefined, anywhere) : unfetched;
398
412
  const deniedRoots = Object.freeze(await canonicalDenyRoots(this._deniedRoots, defaultRealpath));
@@ -0,0 +1 @@
1
+ export declare function requireBare(subject: string, floor: string): void;
@@ -0,0 +1,13 @@
1
+ export function requireBare(subject, floor) {
2
+ const running = globalThis.Bare?.version;
3
+ if (running === undefined || !olderThan(running.replace(/^v/, ''), floor)) {
4
+ return;
5
+ }
6
+ throw new Error(`${subject} needs Bare ${floor} or later, and this is Bare ${running}`);
7
+ }
8
+ function olderThan(version, floor) {
9
+ const have = version.split('.').map((part) => parseInt(part, 10));
10
+ const need = floor.split('.').map((part) => parseInt(part, 10));
11
+ const differs = need.findIndex((part, i) => have[i] !== part);
12
+ return differs !== -1 && have[differs] < need[differs];
13
+ }
@@ -1,5 +1,5 @@
1
1
  import crypto from 'crypto';
2
- import { completionParams } from '../helpers/completion-params.js';
2
+ import { sentParams } from '../helpers/completion-params.js';
3
3
  import { isRecord } from '../guards.js';
4
4
  import { compactRequestHistory, materializeRequestHistory } from './history-codec.js';
5
5
  export function toolsRef(tools) {
@@ -58,7 +58,7 @@ export class RequestDecoder {
58
58
  const history = [...this.previous.slice(0, record.keep), ...appended];
59
59
  this.previous = history;
60
60
  const { modelId, generationParams, responseFormat, toolDialect, kvCache } = record.params;
61
- return completionParams({
61
+ return sentParams({
62
62
  modelId,
63
63
  history,
64
64
  tools: record.tools && this.tools(record.tools),
@@ -182,6 +182,9 @@ function startPayloadFrom(value) {
182
182
  if (value.roundCut === true) {
183
183
  payload.roundCut = true;
184
184
  }
185
+ if (value.showImage === true) {
186
+ payload.showImage = true;
187
+ }
185
188
  if (value.runLog === null) {
186
189
  payload.runLog = null;
187
190
  }
@@ -365,6 +368,13 @@ export function serveHarness(stream, harness) {
365
368
  text: await harness.transcribe({ model: model ?? '', audio: audio ?? b4a.alloc(0) })
366
369
  };
367
370
  },
371
+ ocrRead: async ({ width, height, data }) => {
372
+ if (!harness.ocrRead) {
373
+ throw new HarnessError('CAPABILITY_UNSUPPORTED', ['ocr']);
374
+ }
375
+ const image = { width: width ?? 0, height: height ?? 0, data: data ?? b4a.alloc(0) };
376
+ return { text: await harness.ocrRead({ image }) };
377
+ },
368
378
  detectLanguage: async ({ text, topK }) => {
369
379
  if (!harness.detectLanguage) {
370
380
  throw new HarnessError('CAPABILITY_UNSUPPORTED', ['detectLanguage']);
@@ -646,6 +656,7 @@ function completion(harness) {
646
656
  const pending = new Map();
647
657
  const pendingAttach = new Map();
648
658
  const pendingFetch = new Map();
659
+ const pendingShow = new Map();
649
660
  const pendingQuestion = new Map();
650
661
  const pendingDrive = new Map();
651
662
  const pendingRunLog = new Map();
@@ -671,6 +682,10 @@ function completion(harness) {
671
682
  reject(new HarnessError('CLIENT_GONE'));
672
683
  }
673
684
  pendingFetch.clear();
685
+ for (const { reject } of pendingShow.values()) {
686
+ reject(new HarnessError('CLIENT_GONE'));
687
+ }
688
+ pendingShow.clear();
674
689
  for (const { resolve } of pendingQuestion.values()) {
675
690
  resolve(null);
676
691
  }
@@ -735,6 +750,13 @@ function completion(harness) {
735
750
  if (typeof frame.callId !== 'string') {
736
751
  return;
737
752
  }
753
+ const shown = pendingShow.get(frame.callId);
754
+ if (shown) {
755
+ pendingShow.delete(frame.callId);
756
+ return frame.message
757
+ ? shown.reject(new Error(frame.message))
758
+ : shown.resolve(frame.path || null);
759
+ }
738
760
  const waiter = pendingFetch.get(frame.callId);
739
761
  pendingFetch.delete(frame.callId);
740
762
  if (!waiter) {
@@ -984,6 +1006,20 @@ function completion(harness) {
984
1006
  meta: meta === true ? true : undefined
985
1007
  });
986
1008
  }),
1009
+ showImage: startPayload.showImage
1010
+ ? ({ attachmentId }) => controller.signal.aborted
1011
+ ? Promise.reject(new HarnessError('CLIENT_GONE'))
1012
+ : new Promise((resolve, reject) => {
1013
+ const callId = String(calls++);
1014
+ pendingShow.set(callId, { resolve, reject });
1015
+ events.push({
1016
+ type: 'fetch-ask',
1017
+ callId,
1018
+ attachmentId,
1019
+ payload: { show: true }
1020
+ });
1021
+ })
1022
+ : undefined,
987
1023
  progress: (update) => {
988
1024
  events.push(update
989
1025
  ? { type: 'progress', percentage: update.percentage }
@@ -998,7 +1034,8 @@ function completion(harness) {
998
1034
  type: 'question-ask',
999
1035
  callId,
1000
1036
  question: question.question,
1001
- options: question.options
1037
+ options: question.options,
1038
+ payload: question.form
1002
1039
  });
1003
1040
  })
1004
1041
  };
@@ -74,7 +74,8 @@ export class HarnessSidecar {
74
74
  sdkHome: sdkStorage.home,
75
75
  skillsDir,
76
76
  skillCatalog,
77
- credentialStore
77
+ credentialStore,
78
+ ask: argv[15] === '1'
78
79
  });
79
80
  const plugins = this._plugins(pluginContext(argv, { sdkStorage, skillsDir, skillCatalog, credentialStore }));
80
81
  harness = new Harness({
@@ -10,7 +10,7 @@ import { resetCredentialHealth } from '../tools/skills/credential-health.js';
10
10
  import { ensureSkillsOverlayDir } from '../tools/skills/overlay-dir.js';
11
11
  import { copyBaseForEdit, deleteOverlaySkill, listManagedSkills, readSkillFile, writeSkillFile } from '../tools/skills/overlay-crud.js';
12
12
  import { watchSkillsOverlay } from '../tools/skills/overlay-watch.js';
13
- import { deviceSharedKeys, scopeKey } from '../tools/skills/scope-key.js';
13
+ import { deviceSharedKeys, parseScopeKey, scopeKey } from '../tools/skills/scope-key.js';
14
14
  import { settingsScopeKey } from '../tools/skills/skill-settings.js';
15
15
  import { bareRuntime } from '../tools/exec/bare-runtime.js';
16
16
  import { runCommand } from '../tools/exec/runner.js';
@@ -68,6 +68,12 @@ export class SkillsHost {
68
68
  }
69
69
  next.set(storeKey, record);
70
70
  }
71
+ for (const storeKey of previous.keys()) {
72
+ if (!next.has(storeKey)) {
73
+ const { key, agentId, skill } = parseScopeKey(storeKey);
74
+ resetCredentialHealth(key, agentId, skill);
75
+ }
76
+ }
71
77
  this._credentials = next;
72
78
  }
73
79
  setSkillSettings(entries) {
@@ -68,6 +68,7 @@ export interface HarnessChildOptions {
68
68
  llm?: HarnessLlmConfig;
69
69
  knowledge?: HarnessKnowledgeConfig;
70
70
  pluginOptions?: HarnessPluginOptions;
71
+ ask?: boolean;
71
72
  onIpc?: (ipc: StowIpc) => void;
72
73
  logger?: Logger | null;
73
74
  deps?: string[];
@@ -94,6 +95,7 @@ export interface SpawnHarnessOptions {
94
95
  llm?: HarnessLlmConfig;
95
96
  knowledge?: HarnessKnowledgeConfig;
96
97
  pluginOptions?: HarnessPluginOptions;
98
+ ask?: boolean;
97
99
  logger?: Logger | null;
98
100
  }
99
101
  export declare function spawnHarness(opts: SpawnHarnessOptions): RemoteHarness;
@@ -7,7 +7,7 @@ export function harnessChild(entry, opts) {
7
7
  if (opts.logger) {
8
8
  HarnessLog.toHost(opts.logger);
9
9
  }
10
- const { runner, skillsDir, gpuStats, wheelsDir, sdkStorage, embedDevice, embedGpuLayers, embedBatchSize, imageModel, imageClamps, musicModel, musicClamps, llm, knowledge, pluginOptions, onIpc, logger = null, ...spec } = opts;
10
+ const { runner, skillsDir, gpuStats, wheelsDir, sdkStorage, embedDevice, embedGpuLayers, embedBatchSize, imageModel, imageClamps, musicModel, musicClamps, llm, knowledge, pluginOptions, ask, onIpc, logger = null, ...spec } = opts;
11
11
  const embedConfig = createEmbedConfig({
12
12
  device: embedDevice,
13
13
  gpuLayers: embedGpuLayers,
@@ -29,7 +29,8 @@ export function harnessChild(entry, opts) {
29
29
  wheelsDir ?? '',
30
30
  gpuStats === undefined ? '' : JSON.stringify(gpuStats),
31
31
  knowledge ? JSON.stringify(knowledge) : '',
32
- pluginOptions ? JSON.stringify(pluginOptions) : ''
32
+ pluginOptions ? JSON.stringify(pluginOptions) : '',
33
+ ask ? '1' : ''
33
34
  ],
34
35
  logger,
35
36
  create: (ipc) => {
@@ -63,7 +64,8 @@ export function spawnHarness(opts) {
63
64
  opts.wheelsDir ?? '',
64
65
  opts.gpuStats === undefined ? '' : JSON.stringify(opts.gpuStats),
65
66
  opts.knowledge ? JSON.stringify(opts.knowledge) : '',
66
- opts.pluginOptions ? JSON.stringify(opts.pluginOptions) : ''
67
+ opts.pluginOptions ? JSON.stringify(opts.pluginOptions) : '',
68
+ opts.ask ? '1' : ''
67
69
  ], logger);
68
70
  const died = exit.then((code) => new HarnessError('HARNESS_EXITED_BEFORE_READY', [code]));
69
71
  const failure = await Promise.race([ipc.ready.then(() => null), died]);
@@ -0,0 +1,2 @@
1
+ import type { ToolDefinition } from '../contract/index.ts';
2
+ export declare function createAskUserTool(): ToolDefinition;