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

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 (93) hide show
  1. package/CHANGELOG.md +175 -10
  2. package/README.md +19 -7
  3. package/dist-lib/index.d.ts +3 -3
  4. package/dist-lib/index.js +1 -1
  5. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +2 -0
  6. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +31 -3
  7. package/dist-lib/lib/capabilities/completion-engine/driver.js +3 -0
  8. package/dist-lib/lib/capabilities/completion-engine/index.d.ts +1 -0
  9. package/dist-lib/lib/capabilities/completion-engine/index.js +1 -0
  10. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +1 -0
  11. package/dist-lib/lib/capabilities/completion-engine/round.js +5 -2
  12. package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
  13. package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
  14. package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
  15. package/dist-lib/lib/capabilities/detect-language.js +14 -2
  16. package/dist-lib/lib/connect.d.ts +2 -0
  17. package/dist-lib/lib/connect.js +73 -7
  18. package/dist-lib/lib/contract/drive.d.ts +2 -2
  19. package/dist-lib/lib/contract-types.d.ts +5 -1
  20. package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
  21. package/dist-lib/lib/helpers/require-peers.js +23 -0
  22. package/dist-lib/lib/models/llm-presets.d.ts +1 -0
  23. package/dist-lib/lib/models/model-catalog.js +1 -1
  24. package/dist-lib/lib/models/opencl-cache.js +2 -2
  25. package/dist-lib/lib/plugins/registry.d.ts +2 -0
  26. package/dist-lib/lib/plugins/registry.js +4 -0
  27. package/dist-lib/lib/round-host.d.ts +12 -0
  28. package/dist-lib/lib/round-host.js +57 -0
  29. package/dist-lib/lib/round-port.d.ts +24 -0
  30. package/dist-lib/lib/round-port.js +81 -0
  31. package/dist-lib/lib/sdk-loader.d.ts +1 -1
  32. package/dist-lib/lib/sdk-loader.js +30 -6
  33. package/dist-lib/lib/sdk-storage.d.ts +1 -0
  34. package/dist-lib/lib/sdk-storage.js +18 -2
  35. package/dist-lib/lib/serve.js +61 -1
  36. package/dist-lib/lib/sidecar/index.d.ts +10 -0
  37. package/dist-lib/lib/sidecar/index.js +35 -3
  38. package/dist-lib/lib/sidecar/user-plugins.d.ts +1 -0
  39. package/dist-lib/lib/sidecar/user-plugins.js +1 -1
  40. package/dist-lib/lib/tools/files/grep.js +113 -15
  41. package/dist-lib/lib/tools/fs/drive.d.ts +1 -16
  42. package/dist-lib/lib/tools/fs/edit-match.js +75 -7
  43. package/dist-lib/lib/tools/fs/remote-protocol.d.ts +23 -1
  44. package/dist-lib/lib/tools/fs/remote-protocol.js +1 -1
  45. package/dist-lib/lib/tools/fs/remote.d.ts +1 -8
  46. package/dist-lib/lib/tools/fs/remote.js +1 -1
  47. package/dist-lib/lib/tools/fs/search.d.ts +1 -1
  48. package/dist-lib/lib/tools/fs/search.js +2 -1
  49. package/dist-lib/lib/tools/index.d.ts +2 -1
  50. package/dist-lib/lib/tools/index.js +2 -2
  51. package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +1 -0
  52. package/dist-lib/lib/tools/skills/frontmatter-parser.js +1 -0
  53. package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
  54. package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
  55. package/dist-lib/lib/wire.d.ts +13 -0
  56. package/dist-lib/lib/wire.js +44 -1
  57. package/dist-lib/plugins/coding/read-only.d.ts +1 -0
  58. package/dist-lib/plugins/coding/read-only.js +264 -0
  59. package/dist-lib/plugins/coding/session.d.ts +3 -1
  60. package/dist-lib/plugins/coding/session.js +19 -2
  61. package/dist-lib/plugins/egress-proxy/index.d.ts +2 -2
  62. package/dist-lib/plugins/egress-proxy/index.js +5 -3
  63. package/dist-lib/plugins/image/index.js +7 -2
  64. package/dist-lib/plugins/language-hint/index.js +4 -1
  65. package/dist-lib/plugins/music/index.js +6 -2
  66. package/dist-lib/plugins/python/index.js +1 -0
  67. package/dist-lib/plugins/python/loader.d.ts +1 -0
  68. package/dist-lib/plugins/python/loader.js +8 -0
  69. package/dist-lib/plugins/quickjs/index.js +4 -0
  70. package/dist-lib/plugins/quickjs/runtime.js +8 -3
  71. package/dist-lib/plugins/run-report/index.js +6 -2
  72. package/dist-lib/plugins/run-report/layout.js +1 -1
  73. package/dist-lib/plugins/sandbox-vm/index.js +3 -0
  74. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  75. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  76. package/dist-lib/plugins/speech/audio-resample.js +2 -1
  77. package/dist-lib/plugins/speech/index.d.ts +1 -0
  78. package/dist-lib/plugins/speech/index.js +8 -1
  79. package/dist-lib/plugins/speech/speech-runtime.js +3 -3
  80. package/dist-lib/plugins/translation/index.d.ts +1 -1
  81. package/dist-lib/plugins/translation/index.js +7 -3
  82. package/dist-lib/plugins/translation/translate.d.ts +2 -2
  83. package/dist-lib/plugins/translation/translate.js +7 -8
  84. package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -2
  85. package/dist-lib/plugins/walkie-talkie/index.js +13 -5
  86. package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
  87. package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
  88. package/dist-lib/schema/harness.js +13 -4
  89. package/dist-lib/spec/hrpc/messages.js +205 -151
  90. package/dist-lib/spec/hyperschema/index.js +205 -151
  91. package/dist-lib/spec/hyperschema/schema.json +125 -89
  92. package/dist-lib/spec/hyperschema/types.d.ts +4 -4
  93. package/package.json +129 -24
@@ -1,6 +1,7 @@
1
1
  import { parseManifestBlock } from './manifest-parse.js';
2
2
  import { isMentionHandle } from './mention-name.js';
3
3
  export { credentialSlots } from './credential-slots.js';
4
+ export { readSetup as readSkillSetup } from './manifest-parse.js';
4
5
  const FRONT_MATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
5
6
  const FIELD_RE = /^([A-Za-z_][\w-]*):(.*)$/;
6
7
  export function parseSkillFrontMatter(raw) {
@@ -10,3 +10,4 @@ export declare const SKILL_STATE: {
10
10
  };
11
11
  export type SkillState = (typeof SKILL_STATE)[keyof typeof SKILL_STATE];
12
12
  export declare function isAvailableState(state: SkillState): boolean;
13
+ export declare function isDeviceSharedCredentialKey(key: string): boolean;
@@ -12,3 +12,7 @@ const AVAILABLE_STATES = new Set([SKILL_STATE.ready]);
12
12
  export function isAvailableState(state) {
13
13
  return AVAILABLE_STATES.has(state);
14
14
  }
15
+ const DEVICE_SHARED_CREDENTIAL_KEYS = new Set(['obsidian_vault_path']);
16
+ export function isDeviceSharedCredentialKey(key) {
17
+ return DEVICE_SHARED_CREDENTIAL_KEYS.has(key);
18
+ }
@@ -1,6 +1,7 @@
1
1
  import type { HarnessEvent } from './contract-types.ts';
2
2
  import type { KnowledgeArtifact, KnowledgeHit, KnowledgeStatus, KnowledgeUpsertResult } from './contract/knowledge.ts';
3
3
  import type { HarnessKnowledgeHit, HarnessKnowledgeStatusResponse, HarnessKnowledgeUpsertRequest, HarnessKnowledgeUpsertResponse } from '../spec/hyperschema/types.d.ts';
4
+ import type { ModelRoundEvent, ModelRoundRequest, ModelRoundResult } from './capabilities/completion-engine/index.ts';
4
5
  export interface WireEvent {
5
6
  runId?: string | null;
6
7
  round?: number | null;
@@ -38,6 +39,13 @@ export interface WireEvent {
38
39
  intent?: string | null;
39
40
  display?: unknown;
40
41
  }
42
+ export interface RoundFailureWire {
43
+ message: string;
44
+ payload: {
45
+ name: string;
46
+ code?: string | number | undefined;
47
+ };
48
+ }
41
49
  export interface WireDownloadEvent {
42
50
  type: string;
43
51
  downloaded?: boolean | null;
@@ -49,6 +57,11 @@ export declare function isPlainWireValue(value: unknown): boolean;
49
57
  export declare function redactedRecoveryFields(source: Record<string, unknown>): Record<string, unknown>;
50
58
  export declare function toWire(event: HarnessEvent): WireEvent;
51
59
  export declare function fromWire(event: WireEvent): HarnessEvent;
60
+ export declare function roundFailureWire(err: unknown): RoundFailureWire;
61
+ export declare function roundFailureFrom(wire: Pick<WireEvent, 'message' | 'payload'>): Error;
62
+ export declare function roundRequestFrom(payload: unknown): ModelRoundRequest;
63
+ export declare function roundResultFrom(wire: Pick<WireEvent, 'message' | 'payload' | 'result'>): ModelRoundResult;
64
+ export declare function roundChunkFrom(payload: unknown): ModelRoundEvent;
52
65
  export declare function toDownloadWire(event: HarnessEvent): WireDownloadEvent;
53
66
  export declare function fromDownloadWire(event: WireDownloadEvent): HarnessEvent;
54
67
  export interface PackedVectors {
@@ -1,5 +1,5 @@
1
1
  import b4a from 'b4a';
2
- import { isRecord } from './guards.js';
2
+ import { errorMessage, isRecord } from './guards.js';
3
3
  function stringField(value) {
4
4
  return typeof value === 'string' ? value : undefined;
5
5
  }
@@ -296,6 +296,49 @@ function fromWirePayload(event) {
296
296
  return { type: event.type };
297
297
  }
298
298
  }
299
+ export function roundFailureWire(err) {
300
+ const { name = 'Error', code } = isRecord(err) ? err : {};
301
+ return {
302
+ message: errorMessage(err),
303
+ payload: {
304
+ name: String(name),
305
+ code: typeof code === 'string' || typeof code === 'number' ? code : undefined
306
+ }
307
+ };
308
+ }
309
+ export function roundFailureFrom(wire) {
310
+ const { name, code } = objectField(wire.payload);
311
+ return Object.assign(new Error(wire.message ?? 'model round failed'), {
312
+ name: typeof name === 'string' ? name : 'Error',
313
+ code
314
+ });
315
+ }
316
+ function isRoundRequest(value) {
317
+ return (isRecord(value) &&
318
+ typeof value.runId === 'string' &&
319
+ typeof value.round === 'number' &&
320
+ typeof value.modelId === 'string' &&
321
+ Array.isArray(value.history));
322
+ }
323
+ export function roundRequestFrom(payload) {
324
+ if (!isRoundRequest(payload)) {
325
+ throw new TypeError('invalid model round request');
326
+ }
327
+ return payload;
328
+ }
329
+ function isRoundResult(value) {
330
+ return isRecord(value) && typeof value.contentText === 'string' && isRecord(value.final);
331
+ }
332
+ export function roundResultFrom(wire) {
333
+ if (isRoundResult(wire.result)) {
334
+ return wire.result;
335
+ }
336
+ throw roundFailureFrom(wire);
337
+ }
338
+ export function roundChunkFrom(payload) {
339
+ const { type, text } = objectField(payload);
340
+ return { type: type === 'thinking' ? 'thinking' : 'content', text: String(text ?? '') };
341
+ }
299
342
  export function toDownloadWire(event) {
300
343
  switch (event.type) {
301
344
  case 'progress': {
@@ -0,0 +1 @@
1
+ export declare function readsOnly(line: string, root?: string): boolean;
@@ -0,0 +1,264 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { ShellLine } from '../../lib/tools/exec/shell-line.js';
4
+ const GREP = {
5
+ short: 'rniIlLcvwxhHoqsEFz',
6
+ valued: 'eABCm',
7
+ long: [
8
+ '--recursive',
9
+ '--line-number',
10
+ '--ignore-case',
11
+ '--files-with-matches',
12
+ '--files-without-match',
13
+ '--count',
14
+ '--invert-match',
15
+ '--word-regexp',
16
+ '--line-regexp',
17
+ '--only-matching',
18
+ '--no-filename',
19
+ '--with-filename',
20
+ '--extended-regexp',
21
+ '--fixed-strings'
22
+ ],
23
+ longValued: [
24
+ '--regexp',
25
+ '--include',
26
+ '--exclude',
27
+ '--exclude-dir',
28
+ '--max-count',
29
+ '--context',
30
+ '--after-context',
31
+ '--before-context',
32
+ '--color',
33
+ '--colour'
34
+ ]
35
+ };
36
+ const LINES = {
37
+ short: 'qv',
38
+ valued: 'nc',
39
+ long: ['--quiet', '--silent', '--verbose'],
40
+ longValued: ['--lines', '--bytes'],
41
+ count: true
42
+ };
43
+ const READERS = {
44
+ cat: { short: 'nbsAEetTuv' },
45
+ head: LINES,
46
+ tail: LINES,
47
+ wc: { short: 'clmwL', long: ['--bytes', '--chars', '--lines', '--words'] },
48
+ ls: { short: 'aAlhRrtS1dFpiogGnuUcCxsQ' },
49
+ pwd: { short: 'LP' },
50
+ echo: { short: 'neE', text: true },
51
+ nl: { valued: 'bvisnw' },
52
+ cut: {
53
+ short: 's',
54
+ valued: 'bcdf',
55
+ longValued: ['--bytes', '--characters', '--delimiter', '--fields']
56
+ },
57
+ tr: { short: 'cdsC', text: true },
58
+ file: { short: 'bLhiz', long: ['--brief', '--mime', '--mime-type'] },
59
+ stat: { short: 'L', valued: 'cf' },
60
+ du: { short: 'shacmkx', valued: 'd', longValued: ['--max-depth'] },
61
+ tree: { short: 'adfisDhpugFnC', valued: 'LIP' },
62
+ diff: { short: 'uqwbBiaty', valued: 'U' },
63
+ grep: GREP,
64
+ egrep: GREP,
65
+ fgrep: GREP,
66
+ rg: {
67
+ short: 'nilcvwoFSsuHNq',
68
+ valued: 'egtTABCmM',
69
+ long: [
70
+ '--hidden',
71
+ '--files',
72
+ '--count',
73
+ '--files-with-matches',
74
+ '--line-number',
75
+ '--ignore-case',
76
+ '--smart-case',
77
+ '--fixed-strings',
78
+ '--word-regexp',
79
+ '--no-ignore',
80
+ '--no-heading',
81
+ '--heading'
82
+ ],
83
+ longValued: [
84
+ '--glob',
85
+ '--type',
86
+ '--type-not',
87
+ '--max-count',
88
+ '--context',
89
+ '--after-context',
90
+ '--before-context',
91
+ '--max-depth',
92
+ '--regexp',
93
+ '--color'
94
+ ]
95
+ },
96
+ uniq: { short: 'cdui', valued: 'fs', most: 1 },
97
+ sort: {
98
+ short: 'nrufbdhgiMVsc',
99
+ valued: 'tk',
100
+ long: [
101
+ '--numeric-sort',
102
+ '--reverse',
103
+ '--unique',
104
+ '--ignore-case',
105
+ '--human-numeric-sort',
106
+ '--version-sort',
107
+ '--stable',
108
+ '--check'
109
+ ],
110
+ longValued: ['--key', '--field-separator']
111
+ },
112
+ sed: { words: sedRange },
113
+ find: { words: findExpression }
114
+ };
115
+ const PRINT_RANGE = /^(\d+|\$)(,(\d+|\$))?p$/;
116
+ function sedRange(words, file) {
117
+ const [flag, range, ...files] = words;
118
+ return (flag === '-n' &&
119
+ PRINT_RANGE.test(range ?? '') &&
120
+ files.every((word) => !word.startsWith('-') && file(word)));
121
+ }
122
+ const FIND_TESTS = new Set([
123
+ '-name',
124
+ '-iname',
125
+ '-path',
126
+ '-ipath',
127
+ '-wholename',
128
+ '-regex',
129
+ '-iregex',
130
+ '-type',
131
+ '-maxdepth',
132
+ '-mindepth',
133
+ '-size',
134
+ '-mtime',
135
+ '-mmin',
136
+ '-newer'
137
+ ]);
138
+ const FIND_FLAGS = new Set([
139
+ '-empty',
140
+ '-print',
141
+ '-print0',
142
+ '-prune',
143
+ '-not',
144
+ '!',
145
+ '(',
146
+ ')',
147
+ '-o',
148
+ '-or',
149
+ '-a',
150
+ '-and'
151
+ ]);
152
+ function findExpression(words, file) {
153
+ const rest = words[0] === '-P' ? words.slice(1) : words;
154
+ const begins = rest.findIndex((word) => word.startsWith('-') || FIND_FLAGS.has(word));
155
+ const starts = begins === -1 ? rest : rest.slice(0, begins);
156
+ let test = null;
157
+ for (const word of begins === -1 ? [] : rest.slice(begins)) {
158
+ if (test !== null) {
159
+ if (test === '-newer' && !file(word)) {
160
+ return false;
161
+ }
162
+ test = null;
163
+ }
164
+ else if (FIND_TESTS.has(word)) {
165
+ test = word;
166
+ }
167
+ else if (!FIND_FLAGS.has(word)) {
168
+ return false;
169
+ }
170
+ }
171
+ return test === null && starts.every(file);
172
+ }
173
+ export function readsOnly(line, root) {
174
+ const parsed = ShellLine.parse(line);
175
+ const stays = root ? resolvesInside(root) : () => true;
176
+ return (parsed.unjudgeable === null &&
177
+ parsed.commands.length > 0 &&
178
+ parsed.commands.every((command) => reader(command, stays)));
179
+ }
180
+ function reader({ argv, expands, assignments, redirects }, stays) {
181
+ const name = argv[0] ?? '';
182
+ const known = Object.hasOwn(READERS, name) ? READERS[name] : undefined;
183
+ if (!known || assignments.length || !redirects.every((r) => harmless(r, stays))) {
184
+ return false;
185
+ }
186
+ if (expands.some(Boolean)) {
187
+ return false;
188
+ }
189
+ const file = (word) => inside(word) && stays(word);
190
+ const words = argv.slice(1);
191
+ if (known.words) {
192
+ return known.words(words, file);
193
+ }
194
+ const operands = operandsOf(known, words);
195
+ return (operands !== null &&
196
+ operands.length <= (known.most ?? Infinity) &&
197
+ (known.text === true || operands.every(file)));
198
+ }
199
+ function operandsOf(known, words) {
200
+ const operands = [];
201
+ let value = false;
202
+ for (const [i, word] of words.entries()) {
203
+ if (value) {
204
+ value = false;
205
+ }
206
+ else if (word === '--') {
207
+ return [...operands, ...words.slice(i + 1)];
208
+ }
209
+ else if (word === '-' || !word.startsWith('-')) {
210
+ operands.push(word);
211
+ }
212
+ else if (!(known.count && /^-\d+$/.test(word))) {
213
+ const taken = word.startsWith('--') ? longFlag(known, word) : shortFlags(known, word);
214
+ if (taken === null) {
215
+ return null;
216
+ }
217
+ value = taken === 1;
218
+ }
219
+ }
220
+ return operands;
221
+ }
222
+ function longFlag(known, word) {
223
+ const at = word.indexOf('=');
224
+ const name = at === -1 ? word : word.slice(0, at);
225
+ if (known.longValued?.includes(name)) {
226
+ return at === -1 ? 1 : 0;
227
+ }
228
+ return at === -1 && known.long?.includes(name) ? 0 : null;
229
+ }
230
+ function shortFlags(known, word) {
231
+ const letters = [...word.slice(1)];
232
+ for (const [i, letter] of letters.entries()) {
233
+ if (known.valued?.includes(letter)) {
234
+ return i === letters.length - 1 ? 1 : 0;
235
+ }
236
+ if (!known.short?.includes(letter)) {
237
+ return null;
238
+ }
239
+ }
240
+ return 0;
241
+ }
242
+ function resolvesInside(root) {
243
+ const real = realpath(root) ?? root;
244
+ return (word) => {
245
+ const target = realpath(path.resolve(root, word));
246
+ return target === null || target === real || target.startsWith(real + path.sep);
247
+ };
248
+ }
249
+ function realpath(file) {
250
+ try {
251
+ return fs.realpathSync(file);
252
+ }
253
+ catch {
254
+ return null;
255
+ }
256
+ }
257
+ function inside(word) {
258
+ return !word.startsWith('/') && !word.startsWith('~') && !word.split('/').includes('..');
259
+ }
260
+ function harmless({ op, target }, stays) {
261
+ return ((op === '<' && inside(target) && stays(target)) ||
262
+ target === '/dev/null' ||
263
+ ((op === '>&' || op === '<&') && /^\d$/.test(target)));
264
+ }
@@ -27,8 +27,9 @@ export declare class CodingSession {
27
27
  private readonly _workspaces;
28
28
  private readonly _runs;
29
29
  private readonly _keys;
30
+ private readonly _moved;
30
31
  constructor(sandbox: SandboxService, deniedRoots?: readonly string[]);
31
- effect(ctx: ToolExecuteContext | undefined): 'read' | 'write';
32
+ effect(ctx: ToolExecuteContext | undefined, args?: Record<string, unknown>): 'read' | 'write';
32
33
  refusal(ctx: ToolExecuteContext | undefined): ToolError | null;
33
34
  workspace(ctx: ToolExecuteContext | undefined): Promise<LocalRoot | ToolError>;
34
35
  policyVersion(): string;
@@ -37,6 +38,7 @@ export declare class CodingSession {
37
38
  workspaceOf(runId: string): Promise<SandboxWorkspace> | null;
38
39
  private _prelude;
39
40
  exec({ workspace, runId, line }: SessionLine, { timeoutMs, signal }?: ExecCall): Promise<SandboxExecResult>;
41
+ private _moves;
40
42
  jobLog(id: string): string;
41
43
  start({ workspace, runId, line }: SessionLine, id: string): Promise<SandboxJob>;
42
44
  execState(workspace: SandboxWorkspace, line: string): Promise<SandboxExecResult>;
@@ -2,6 +2,7 @@ import b4a from 'b4a';
2
2
  import { randomBytes } from 'crypto';
3
3
  import path from 'path';
4
4
  import { Policy } from '../../lib/policy/index.js';
5
+ import { readsOnly } from './read-only.js';
5
6
  import { HarnessError } from '../../lib/errors.js';
6
7
  import { isRecord } from '../../lib/guards.js';
7
8
  import { appendOutput, createCapturedOutput, formatOutput, MAX_OUTPUT_CHARS } from '../../lib/tools/exec/runner.js';
@@ -92,6 +93,7 @@ export class CodingSession {
92
93
  _workspaces;
93
94
  _runs;
94
95
  _keys;
96
+ _moved;
95
97
  constructor(sandbox, deniedRoots = []) {
96
98
  this.sandbox = sandbox;
97
99
  this.deniedRoots = deniedRoots;
@@ -99,8 +101,15 @@ export class CodingSession {
99
101
  this._workspaces = new Map();
100
102
  this._runs = new Map();
101
103
  this._keys = new Map();
104
+ this._moved = new Set();
102
105
  }
103
- effect(ctx) {
106
+ effect(ctx, args) {
107
+ const root = ctx?.fsWriteRoots?.[0];
108
+ const line = args?.command;
109
+ const fresh = !args?.cwd && !this._moved.has(ctx?.runId ?? '');
110
+ if (typeof line === 'string' && fresh && root?.kind === 'local' && readsOnly(line, root.root)) {
111
+ return 'read';
112
+ }
104
113
  return ctx?.planMode || !this.sandbox.isolated ? 'write' : 'read';
105
114
  }
106
115
  refusal(ctx) {
@@ -152,6 +161,7 @@ export class CodingSession {
152
161
  ];
153
162
  }
154
163
  exec({ workspace, runId, line }, { timeoutMs, signal } = {}) {
164
+ this._moves(runId, line);
155
165
  const script = [
156
166
  ...this._prelude(runId),
157
167
  '__qvac_save() {',
@@ -165,10 +175,16 @@ export class CodingSession {
165
175
  ].join('\n');
166
176
  return workspace.exec(script, { cwd: this._runs.get(runId), timeoutMs, signal });
167
177
  }
178
+ _moves(runId, line) {
179
+ if (!readsOnly(line)) {
180
+ this._moved.add(runId);
181
+ }
182
+ }
168
183
  jobLog(id) {
169
184
  return `${STATE_DIR}/jobs/${id}.log`;
170
185
  }
171
186
  start({ workspace, runId, line }, id) {
187
+ this._moves(runId, line);
172
188
  const job = shellQuote(`trap wait EXIT\n${line}`);
173
189
  const script = [...this._prelude(runId), `exec sh -c ${job} > ${this.jobLog(id)} 2>&1`];
174
190
  return workspace.start(script.join('\n'), { cwd: this._runs.get(runId) });
@@ -180,6 +196,7 @@ export class CodingSession {
180
196
  const workspace = this.workspaceOf(runId);
181
197
  this._runs.delete(runId);
182
198
  this._keys.delete(runId);
199
+ this._moved.delete(runId);
183
200
  if (workspace) {
184
201
  const state = this.statePath(runId);
185
202
  await this.execState(await workspace, `rm -f ${state}.env ${state}.cwd ${state}.tmp`);
@@ -262,7 +279,7 @@ export function shellTool(options) {
262
279
  policyVersion: session.policyVersion(),
263
280
  description: SHELL_DESCRIPTION,
264
281
  parameters: SHELL_PARAMETERS,
265
- effect: (_args, ctx) => session.effect(ctx),
282
+ effect: (args, ctx) => session.effect(ctx, args),
266
283
  quote: (args) => (typeof args.command === 'string' ? args.command : null),
267
284
  command: (args) => (typeof args.command === 'string' ? args.command : null),
268
285
  validate(args) {
@@ -1,8 +1,8 @@
1
- import net from 'net';
1
+ import type { Socket } from 'net';
2
2
  import type { HarnessPlugin, PluginSetup } from '../../lib/plugins/index.ts';
3
3
  import { type HostResolver } from '../../lib/tools/url-guard.ts';
4
4
  import type { EgressProxyOptions, EgressProxyService, EgressProxySession } from '../../lib/contract/egress-proxy.ts';
5
- export type Dial = (address: string, port: number) => net.Socket;
5
+ export type Dial = (address: string, port: number) => Socket;
6
6
  export interface EgressProxyPluginOptions {
7
7
  readonly resolveHost?: HostResolver;
8
8
  readonly dial?: Dial;
@@ -1,8 +1,8 @@
1
1
  import b4a from 'b4a';
2
- import net from 'net';
3
2
  import { lookupHost } from '../../lib/dns-lookup.js';
4
3
  import { PluginRegistry } from '../../lib/plugins/index.js';
5
4
  import { resolveOutboundUrl } from '../../lib/tools/url-guard.js';
5
+ PluginRegistry.requirePeers('egress-proxy', { 'bare-net': () => import.meta.resolve('net') });
6
6
  const MAX_HEAD = 64 * 1024;
7
7
  const HEAD_END = '\r\n\r\n';
8
8
  const REASONS = {
@@ -20,7 +20,7 @@ export class EgressProxy {
20
20
  _resolveHost;
21
21
  _dial;
22
22
  _sessions = new Set();
23
- constructor({ resolveHost = lookupHost, dial = (address, port) => net.connect(port, address) } = {}) {
23
+ constructor({ resolveHost = lookupHost, dial } = {}) {
24
24
  this._resolveHost = resolveHost;
25
25
  this._dial = dial;
26
26
  }
@@ -33,9 +33,11 @@ export class EgressProxy {
33
33
  };
34
34
  }
35
35
  async open({ hosts, signal }) {
36
+ const { default: net } = await import('net');
36
37
  const sockets = new Set();
37
38
  const served = {
38
39
  hosts,
40
+ dial: this._dial ?? ((address, port) => net.connect(port, address)),
39
41
  denied: new Set(),
40
42
  track: (socket) => {
41
43
  sockets.add(socket);
@@ -104,7 +106,7 @@ export class EgressProxy {
104
106
  return;
105
107
  }
106
108
  const address = check.addresses?.[0] ?? url.hostname.replace(/^\[(.*)\]$/, '$1');
107
- const upstream = this._dial(address, Number(url.port) || 80);
109
+ const upstream = served.dial(address, Number(url.port) || 80);
108
110
  served.track(upstream);
109
111
  const opening = tunnel ? null : originHead(request, url);
110
112
  splice(client, upstream, { opening, rest: request.rest, host: url.hostname });
@@ -3,6 +3,11 @@ import { retryMemo } from '../../lib/helpers/retry-memo.js';
3
3
  import { PluginRegistry } from '../../lib/plugins/index.js';
4
4
  import { createEditImageTool, loadMediaCodecs } from './edit-image.js';
5
5
  import { createDiffusionRuntime, createGenerateImageTool } from './generate-image.js';
6
+ PluginRegistry.requirePeers('image', {
7
+ '@qvac/diffusion-cpp': () => import.meta.resolve('@qvac/diffusion-cpp/addonLogging'),
8
+ 'bare-image-resample': () => import.meta.resolve('bare-image-resample'),
9
+ 'bare-media': () => import.meta.resolve('bare-media')
10
+ });
6
11
  export { createEditImageTool } from './edit-image.js';
7
12
  export { createDiffusionRuntime, createGenerateImageTool, generationPercentTick, settingsDimension, settingsSteps } from './generate-image.js';
8
13
  function diffusionRuntime(models, model) {
@@ -10,8 +15,8 @@ function diffusionRuntime(models, model) {
10
15
  const sdk = await models.sdk();
11
16
  if (typeof globalThis.Bare !== 'undefined') {
12
17
  const [{ diffusionPlugin }, { registerPlugin }] = await Promise.all([
13
- import('@qvac/sdk/sdcpp-generation/plugin'),
14
- import('@qvac/sdk/plugins')
18
+ import('@qvac/inference/sdcpp-generation/plugin'),
19
+ import('@qvac/inference/plugin-registry')
15
20
  ]);
16
21
  try {
17
22
  registerPlugin(diffusionPlugin);
@@ -1,5 +1,8 @@
1
1
  import { detectLanguage, UNDETERMINED } from '../../lib/capabilities/detect-language.js';
2
2
  import { PluginRegistry } from '../../lib/plugins/index.js';
3
+ PluginRegistry.requirePeers('language-hint', {
4
+ '@qvac/langdetect-text': () => import.meta.resolve('@qvac/langdetect-text')
5
+ });
3
6
  const TIMEOUT_MS = 120_000;
4
7
  export class LanguageHint {
5
8
  name = 'language-hint';
@@ -26,7 +29,7 @@ export class LanguageHint {
26
29
  async _hint(translation, text, options) {
27
30
  if (text.trim().split(/\s+/).length < this._minWords)
28
31
  return;
29
- const [top] = detectLanguage({ text, topK: 2 });
32
+ const [top] = await detectLanguage({ text, topK: 2 });
30
33
  if (!top || top.code === UNDETERMINED || top.code === 'en') {
31
34
  return;
32
35
  }
@@ -2,6 +2,10 @@ import { HarnessError } from '../../lib/errors.js';
2
2
  import { retryMemo } from '../../lib/helpers/retry-memo.js';
3
3
  import { PluginRegistry } from '../../lib/plugins/index.js';
4
4
  import { createGenerateMusicTool, createMusicRuntime } from './generate-music.js';
5
+ PluginRegistry.requirePeers('music', {
6
+ '@qvac/audiogen-ggml': () => import.meta.resolve('@qvac/audiogen-ggml/binding.js'),
7
+ '@qvac/decoder-audio': () => import.meta.resolve('@qvac/decoder-audio')
8
+ });
5
9
  export { audioDurationSeconds, backendDevice, backendName, CPU_FALLBACK_NOTICE, createGenerateMusicTool, createMusicRuntime, gpuFallback, musicPercentTick, pcmToWav, presentStats } from './generate-music.js';
6
10
  export class Music {
7
11
  name = 'music';
@@ -24,8 +28,8 @@ export class Music {
24
28
  const sdk = await models.sdk();
25
29
  if (typeof globalThis.Bare !== 'undefined') {
26
30
  const [{ audioGenPlugin }, { registerPlugin }] = await Promise.all([
27
- import('@qvac/sdk/audiogen-ggml/plugin'),
28
- import('@qvac/sdk/plugins')
31
+ import('@qvac/inference/audiogen-ggml/plugin'),
32
+ import('@qvac/inference/plugin-registry')
29
33
  ]);
30
34
  try {
31
35
  registerPlugin(audioGenPlugin);
@@ -2,6 +2,7 @@ import { PluginRegistry } from '../../lib/plugins/index.js';
2
2
  import { createPythonLanguage } from './language.js';
3
3
  import { closePythonWorker } from './worker/active.js';
4
4
  import { preloadPythonAddons } from './worker/client.js';
5
+ PluginRegistry.requirePeers('python', { pyodide: () => import.meta.resolve('pyodide') });
5
6
  export { runPython } from './pyodide.js';
6
7
  export { planVendoredInstall, vendoredManifest, wheelsDir } from './wheels.js';
7
8
  export { closePythonWorker };
@@ -14,5 +14,6 @@ type PyodideLoadOptions = typeof silentStdio & {
14
14
  packageCacheDir?: string;
15
15
  };
16
16
  export declare function loadPyodideAddons(): Promise<void>;
17
+ export declare function glueIsPatched(src: string): boolean;
17
18
  export declare const defaultLoad: LoadPyodideFn;
18
19
  export {};
@@ -166,8 +166,16 @@ async function importPyodide() {
166
166
  export async function loadPyodideAddons() {
167
167
  await importPyodide();
168
168
  }
169
+ export function glueIsPatched(src) {
170
+ return /function addEmJs\([^)]*\)\{throw /.test(src);
171
+ }
172
+ let warnedUnpatched = false;
169
173
  export const defaultLoad = async () => {
170
174
  const { loadPyodide, createPyodideModule } = await importPyodide();
175
+ if (!warnedUnpatched && !glueIsPatched(String(createPyodideModule))) {
176
+ warnedUnpatched = true;
177
+ console.warn('qvac-harness: pyodide is unpatched, guest Python can run host JS; copy patches/pyodide@314.0.2.patch');
178
+ }
171
179
  const options = pyodideLoadOptions();
172
180
  if (options.packageCacheDir) {
173
181
  seedPackageCache(options.packageCacheDir);
@@ -1,6 +1,10 @@
1
1
  import { PluginRegistry } from '../../lib/plugins/index.js';
2
2
  import { createJavaScriptLanguage } from './language.js';
3
3
  import { Interpreter, MAX_DEADLINE_MS, SLICE_MS } from './runtime.js';
4
+ PluginRegistry.requirePeers('quickjs', {
5
+ '@jitl/quickjs-singlefile-mjs-release-sync': () => import.meta.resolve('@jitl/quickjs-singlefile-mjs-release-sync'),
6
+ 'quickjs-emscripten-core': () => import.meta.resolve('quickjs-emscripten-core')
7
+ });
4
8
  export class QuickJs {
5
9
  static MAX_DEADLINE_MS = MAX_DEADLINE_MS;
6
10
  static SLICE_MS = SLICE_MS;
@@ -1,5 +1,3 @@
1
- import variant from '@jitl/quickjs-singlefile-mjs-release-sync';
2
- import { newQuickJSWASMModuleFromVariant } from 'quickjs-emscripten-core';
3
1
  import { errorMessage, isRecord } from '../../lib/guards.js';
4
2
  import { AbortedError } from '../../lib/helpers/race-abort.js';
5
3
  import { appendOutput, createCapturedOutput, DEFAULT_TIMEOUT_MS, formatOutput, MAX_OUTPUT_CHARS } from '../../lib/tools/exec/runner.js';
@@ -338,6 +336,13 @@ class Script {
338
336
  settle();
339
337
  }
340
338
  }
339
+ async function loadModule() {
340
+ const [{ default: variant }, { newQuickJSWASMModuleFromVariant }] = await Promise.all([
341
+ import('@jitl/quickjs-singlefile-mjs-release-sync'),
342
+ import('quickjs-emscripten-core')
343
+ ]);
344
+ return newQuickJSWASMModuleFromVariant(variant);
345
+ }
341
346
  export class Interpreter {
342
347
  _limits;
343
348
  _module = null;
@@ -349,7 +354,7 @@ export class Interpreter {
349
354
  _load() {
350
355
  if (!this._module) {
351
356
  ensureTextDecoder();
352
- const loading = newQuickJSWASMModuleFromVariant(variant);
357
+ const loading = loadModule();
353
358
  this._module = loading;
354
359
  loading.catch(() => this._drop(loading));
355
360
  }