@qvac/harness 1.0.0-rc.6 → 1.0.0-rc.7
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.
- package/CHANGELOG.md +157 -10
- package/README.md +19 -7
- package/dist-lib/index.d.ts +2 -2
- package/dist-lib/index.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +31 -3
- package/dist-lib/lib/capabilities/completion-engine/driver.js +3 -0
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/index.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/round.js +5 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
- package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
- package/dist-lib/lib/capabilities/detect-language.js +14 -2
- package/dist-lib/lib/connect.d.ts +2 -0
- package/dist-lib/lib/connect.js +73 -7
- package/dist-lib/lib/contract-types.d.ts +4 -0
- package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
- package/dist-lib/lib/helpers/require-peers.js +23 -0
- package/dist-lib/lib/models/llm-presets.d.ts +1 -0
- package/dist-lib/lib/models/model-catalog.js +1 -1
- package/dist-lib/lib/models/opencl-cache.js +2 -2
- package/dist-lib/lib/plugins/registry.d.ts +2 -0
- package/dist-lib/lib/plugins/registry.js +4 -0
- package/dist-lib/lib/round-host.d.ts +12 -0
- package/dist-lib/lib/round-host.js +57 -0
- package/dist-lib/lib/round-port.d.ts +24 -0
- package/dist-lib/lib/round-port.js +81 -0
- package/dist-lib/lib/sdk-loader.d.ts +1 -1
- package/dist-lib/lib/sdk-loader.js +30 -6
- package/dist-lib/lib/sdk-storage.d.ts +1 -0
- package/dist-lib/lib/sdk-storage.js +18 -2
- package/dist-lib/lib/serve.js +61 -1
- package/dist-lib/lib/sidecar/index.d.ts +10 -0
- package/dist-lib/lib/sidecar/index.js +35 -3
- package/dist-lib/lib/sidecar/user-plugins.d.ts +1 -0
- package/dist-lib/lib/sidecar/user-plugins.js +1 -1
- package/dist-lib/lib/tools/files/grep.js +113 -15
- package/dist-lib/lib/tools/fs/edit-match.js +75 -7
- package/dist-lib/lib/tools/fs/search.d.ts +1 -1
- package/dist-lib/lib/tools/fs/search.js +2 -1
- package/dist-lib/lib/tools/index.d.ts +2 -1
- package/dist-lib/lib/tools/index.js +2 -2
- package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
- package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
- package/dist-lib/lib/wire.d.ts +13 -0
- package/dist-lib/lib/wire.js +44 -1
- package/dist-lib/plugins/coding/read-only.d.ts +1 -0
- package/dist-lib/plugins/coding/read-only.js +264 -0
- package/dist-lib/plugins/coding/session.d.ts +3 -1
- package/dist-lib/plugins/coding/session.js +19 -2
- package/dist-lib/plugins/egress-proxy/index.d.ts +2 -2
- package/dist-lib/plugins/egress-proxy/index.js +5 -3
- package/dist-lib/plugins/image/index.js +7 -2
- package/dist-lib/plugins/language-hint/index.js +4 -1
- package/dist-lib/plugins/music/index.js +6 -2
- package/dist-lib/plugins/python/index.js +1 -0
- package/dist-lib/plugins/python/loader.d.ts +1 -0
- package/dist-lib/plugins/python/loader.js +8 -0
- package/dist-lib/plugins/quickjs/index.js +4 -0
- package/dist-lib/plugins/quickjs/runtime.js +8 -3
- package/dist-lib/plugins/run-report/index.js +6 -2
- package/dist-lib/plugins/run-report/layout.js +1 -1
- package/dist-lib/plugins/sandbox-vm/index.js +3 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/speech/audio-resample.js +2 -1
- package/dist-lib/plugins/speech/index.d.ts +1 -0
- package/dist-lib/plugins/speech/index.js +8 -1
- package/dist-lib/plugins/speech/speech-runtime.js +3 -3
- package/dist-lib/plugins/translation/index.d.ts +1 -1
- package/dist-lib/plugins/translation/index.js +7 -3
- package/dist-lib/plugins/translation/translate.d.ts +2 -2
- package/dist-lib/plugins/translation/translate.js +7 -8
- package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -2
- package/dist-lib/plugins/walkie-talkie/index.js +13 -5
- package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
- package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
- package/dist-lib/schema/harness.js +13 -4
- package/dist-lib/spec/hrpc/messages.js +205 -151
- package/dist-lib/spec/hyperschema/index.js +205 -151
- package/dist-lib/spec/hyperschema/schema.json +125 -89
- package/dist-lib/spec/hyperschema/types.d.ts +4 -4
- package/package.json +149 -24
|
@@ -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: (
|
|
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
|
|
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) =>
|
|
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
|
|
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 =
|
|
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/
|
|
14
|
-
import('@qvac/
|
|
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/
|
|
28
|
-
import('@qvac/
|
|
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 =
|
|
357
|
+
const loading = loadModule();
|
|
353
358
|
this._module = loading;
|
|
354
359
|
loading.catch(() => this._drop(loading));
|
|
355
360
|
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { randomBytes } from 'crypto';
|
|
2
2
|
import { RunLog } from '../../lib/run-log/index.js';
|
|
3
3
|
import { chain } from './chain.js';
|
|
4
4
|
import { flow } from './flow.js';
|
|
5
5
|
import { layout } from './layout.js';
|
|
6
6
|
import { reportModel } from './model.js';
|
|
7
|
+
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
7
8
|
import { parts, shell } from './page.js';
|
|
9
|
+
PluginRegistry.requirePeers('run-report', {
|
|
10
|
+
elkjs: () => import.meta.resolve('elkjs/lib/elk.bundled.js')
|
|
11
|
+
});
|
|
8
12
|
export class RunReport {
|
|
9
13
|
static record() {
|
|
10
14
|
const hops = [];
|
|
11
|
-
const requestDigestKey =
|
|
15
|
+
const requestDigestKey = randomBytes(32);
|
|
12
16
|
const hopLog = () => {
|
|
13
17
|
const records = [];
|
|
14
18
|
let boot = RunLog.createEngineBoot();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import ELK, {} from 'elkjs/lib/elk.bundled.js';
|
|
2
1
|
const KINDS = { final: 'final', history: 'history' };
|
|
3
2
|
const CHAR = 7.4;
|
|
4
3
|
const LINE = 15;
|
|
@@ -22,6 +21,7 @@ export async function layout(definition, ran) {
|
|
|
22
21
|
const graph = new Graph(definition);
|
|
23
22
|
graph.walk(definition);
|
|
24
23
|
const { nodes, edges } = ran ? only(graph, ran) : graph;
|
|
24
|
+
const { default: ELK } = await import('elkjs/lib/elk.bundled.js');
|
|
25
25
|
const laid = await new ELK().layout({
|
|
26
26
|
id: '__root',
|
|
27
27
|
layoutOptions: OPTIONS,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
2
2
|
import { barevisorSandbox, GuestShell } from './vm-shell.js';
|
|
3
|
+
PluginRegistry.requirePeers('sandbox-vm', {
|
|
4
|
+
barevisor: () => import.meta.resolve('barevisor/sandbox')
|
|
5
|
+
});
|
|
3
6
|
export { WORKDIR_REFUSED } from './vm-shell.js';
|
|
4
7
|
function imageError(image) {
|
|
5
8
|
return image?.kernel && image.initrd
|
|
Binary file
|
|
Binary file
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import { decodeToPcm16kMono, transcodeToWav16kMono } from '#audio-transcode';
|
|
3
2
|
const TARGET_SAMPLE_RATE = 16000;
|
|
4
3
|
const TARGET_CHANNELS = 1;
|
|
5
4
|
const TARGET_BITS_PER_SAMPLE = 16;
|
|
@@ -57,6 +56,7 @@ export async function resampleForTranscription(bytes) {
|
|
|
57
56
|
if (!needsResample(bytes)) {
|
|
58
57
|
return { bytes, transcoded: false };
|
|
59
58
|
}
|
|
59
|
+
const { transcodeToWav16kMono } = await import('#audio-transcode');
|
|
60
60
|
const wav = await transcodeToWav16kMono(bytes);
|
|
61
61
|
return wav ? { bytes: wav, transcoded: true } : { bytes, transcoded: false };
|
|
62
62
|
}
|
|
@@ -79,5 +79,6 @@ export async function* pcmForTranscription(bytes) {
|
|
|
79
79
|
yield pcm;
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
+
const { decodeToPcm16kMono } = await import('#audio-transcode');
|
|
82
83
|
yield* decodeToPcm16kMono(bytes);
|
|
83
84
|
}
|
|
@@ -9,6 +9,7 @@ export declare class Speech implements HarnessPlugin {
|
|
|
9
9
|
readonly addons: {
|
|
10
10
|
'tts-ggml': () => Promise<typeof import("@qvac/tts-ggml/addonLogging")>;
|
|
11
11
|
'asr-ggml': () => Promise<typeof import("@qvac/asr-ggml/addonLogging")>;
|
|
12
|
+
'bare-ffmpeg': () => Promise<typeof import("#audio-transcode")>;
|
|
12
13
|
};
|
|
13
14
|
private readonly _options;
|
|
14
15
|
constructor(options?: SpeechOptions);
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
2
2
|
import { invalidOptions } from './speech-engine.js';
|
|
3
3
|
import { SpeechRuntime } from './speech-runtime.js';
|
|
4
|
+
PluginRegistry.requirePeers('speech', {
|
|
5
|
+
'@qvac/asr-ggml': () => import.meta.resolve('@qvac/asr-ggml/addonLogging'),
|
|
6
|
+
'@qvac/decoder-audio': () => import.meta.resolve('@qvac/decoder-audio'),
|
|
7
|
+
'@qvac/tts-ggml': () => import.meta.resolve('@qvac/tts-ggml/addonLogging'),
|
|
8
|
+
'bare-ffmpeg': () => import.meta.resolve('bare-ffmpeg')
|
|
9
|
+
});
|
|
4
10
|
export class Speech {
|
|
5
11
|
name = 'speech';
|
|
6
12
|
api = PluginRegistry.API_VERSION;
|
|
@@ -8,7 +14,8 @@ export class Speech {
|
|
|
8
14
|
needs = ['models'];
|
|
9
15
|
addons = {
|
|
10
16
|
'tts-ggml': () => import('@qvac/tts-ggml/addonLogging'),
|
|
11
|
-
'asr-ggml': () => import('@qvac/asr-ggml/addonLogging')
|
|
17
|
+
'asr-ggml': () => import('@qvac/asr-ggml/addonLogging'),
|
|
18
|
+
'bare-ffmpeg': () => import('#audio-transcode')
|
|
12
19
|
};
|
|
13
20
|
_options;
|
|
14
21
|
constructor(options = {}) {
|