@qvac/harness 1.0.0-rc.19 → 1.0.0-rc.20
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 +106 -2
- package/README.md +7 -0
- package/dist-lib/lib/capabilities/agent-ports.js +4 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +3 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +5 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +5 -1
- package/dist-lib/lib/capabilities/completion-engine/driver.js +9 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +3 -1
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +2 -2
- package/dist-lib/lib/capabilities/sdk-tool.js +2 -2
- package/dist-lib/lib/capabilities/tool-turns.d.ts +1 -0
- package/dist-lib/lib/capabilities/tool-turns.js +2 -0
- package/dist-lib/lib/contract/agent.d.ts +2 -0
- package/dist-lib/lib/contract/media.d.ts +7 -0
- package/dist-lib/lib/helpers/run-outcome.d.ts +2 -0
- package/dist-lib/lib/helpers/run-outcome.js +6 -2
- package/dist-lib/lib/machine/completion/types.d.ts +1 -0
- package/dist-lib/lib/machine/index.d.ts +2 -0
- package/dist-lib/lib/machine/index.js +2 -0
- package/dist-lib/lib/media-wire.js +16 -1
- package/dist-lib/lib/models/context-choice.js +8 -1
- package/dist-lib/lib/models/llm-presets.js +27 -1
- package/dist-lib/lib/models/model-catalog-constants.d.ts +2 -2
- package/dist-lib/lib/models/model-catalog-constants.js +3 -4
- package/dist-lib/lib/models/model-catalog.d.ts +4 -2
- package/dist-lib/lib/models/model-catalog.js +29 -11
- package/dist-lib/lib/models/tts-model-default.d.ts +2 -1
- package/dist-lib/lib/models/tts-model-default.js +8 -6
- package/dist-lib/lib/plugins/registry.d.ts +1 -0
- package/dist-lib/lib/plugins/registry.js +7 -4
- package/dist-lib/lib/prompt.d.ts +5 -4
- package/dist-lib/lib/prompt.js +68 -22
- package/dist-lib/lib/residency/completion-runtime.js +6 -1
- package/dist-lib/lib/residency/index.js +1 -0
- package/dist-lib/lib/tools/files/edit-file.d.ts +4 -1
- package/dist-lib/lib/tools/files/edit-file.js +220 -28
- package/dist-lib/lib/tools/files/index.js +3 -1
- package/dist-lib/lib/tools/fs/edit-match.d.ts +22 -0
- package/dist-lib/lib/tools/fs/edit-match.js +337 -45
- package/dist-lib/plugins/coding-guards/index.d.ts +25 -0
- package/dist-lib/plugins/coding-guards/index.js +126 -0
- package/dist-lib/plugins/image/edit-image.d.ts +3 -22
- package/dist-lib/plugins/image/edit-image.js +13 -32
- package/dist-lib/plugins/image/fit.d.ts +31 -0
- package/dist-lib/plugins/image/fit.js +28 -0
- package/dist-lib/plugins/image/generate-image.d.ts +9 -2
- package/dist-lib/plugins/image/generate-image.js +23 -6
- package/dist-lib/plugins/image/index.js +4 -1
- package/dist-lib/plugins/ocr/index.d.ts +1 -1
- package/dist-lib/plugins/ocr/index.js +3 -1
- 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/speech-engine.d.ts +1 -1
- package/dist-lib/plugins/speech/speech-engine.js +10 -5
- package/dist-lib/plugins/speech/speech-text.d.ts +1 -0
- package/dist-lib/plugins/speech/speech-text.js +9 -4
- package/dist-lib/plugins/speech/voice.js +7 -2
- package/package.json +5 -1
|
@@ -1,44 +1,237 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import { errorMessage } from '../../guards.js';
|
|
3
|
-
import { editMatch } from '../fs/edit-match.js';
|
|
2
|
+
import { errorMessage, isRecord } from '../../guards.js';
|
|
3
|
+
import { applyEdits, editMatch } from '../fs/edit-match.js';
|
|
4
4
|
import { defaultRealpath } from '../fs/scope.js';
|
|
5
5
|
import { resolveRooted, rootedArgs, rootedLabel, stringArg } from '../fs/tool-path.js';
|
|
6
6
|
import { writeText } from '../fs/write.js';
|
|
7
|
-
export
|
|
7
|
+
export const EMPTY_OLD_GUIDANCE = 'To add lines use insert_text; to change text put the exact current text in `old`.';
|
|
8
|
+
const QUOTE_LINES = 6;
|
|
9
|
+
const QUOTE_CHARS = 1500;
|
|
10
|
+
function textOf(value) {
|
|
11
|
+
if (typeof value === 'string')
|
|
12
|
+
return value;
|
|
13
|
+
return typeof value === 'number' || typeof value === 'boolean' ? String(value) : null;
|
|
14
|
+
}
|
|
15
|
+
function lineNumberOf(value) {
|
|
16
|
+
if (typeof value === 'number' && Number.isInteger(value))
|
|
17
|
+
return value;
|
|
18
|
+
return typeof value === 'string' && /^\d+$/.test(value.trim()) ? Number(value) : null;
|
|
19
|
+
}
|
|
20
|
+
function insertOf(args) {
|
|
21
|
+
const text = textOf(args.insert);
|
|
22
|
+
if (!text) {
|
|
23
|
+
return 'insert must be the lines to add';
|
|
24
|
+
}
|
|
25
|
+
if (args.after === 'end') {
|
|
26
|
+
return [{ kind: 'edge', text, at: 'end' }];
|
|
27
|
+
}
|
|
28
|
+
const line = lineNumberOf(args.after);
|
|
29
|
+
if (line === null || line < 0) {
|
|
30
|
+
return 'after must be a line number as read_file shows it, 0 for the start, or "end"';
|
|
31
|
+
}
|
|
32
|
+
if (line === 0) {
|
|
33
|
+
return [{ kind: 'edge', text, at: 'start' }];
|
|
34
|
+
}
|
|
35
|
+
const expect = textOf(args.expect);
|
|
36
|
+
if (expect === null) {
|
|
37
|
+
return `expect must be the exact text of line ${line}, as read_file shows it after "${line}| "`;
|
|
38
|
+
}
|
|
39
|
+
return [{ kind: 'line', text, line, expect }];
|
|
40
|
+
}
|
|
41
|
+
function replaceEdit(item, emptyOld) {
|
|
42
|
+
if (typeof item.old !== 'string' || !item.old) {
|
|
43
|
+
return emptyOld;
|
|
44
|
+
}
|
|
45
|
+
if (typeof item.new !== 'string') {
|
|
46
|
+
return 'new must be a string';
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
kind: 'replace',
|
|
50
|
+
old: item.old,
|
|
51
|
+
replacement: item.new,
|
|
52
|
+
replaceAll: item.replaceAll === true
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function listOf(value) {
|
|
56
|
+
if (typeof value !== 'string')
|
|
57
|
+
return value;
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(value);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function replaceOf(args) {
|
|
66
|
+
const edit = replaceEdit(args, 'old must be the text to replace');
|
|
67
|
+
return typeof edit === 'string' ? edit : [edit];
|
|
68
|
+
}
|
|
69
|
+
function editsOf(args) {
|
|
70
|
+
const items = listOf(args.edits);
|
|
71
|
+
if (!Array.isArray(items) || !items.length) {
|
|
72
|
+
return 'edits must be a list of changes, each with old and new';
|
|
73
|
+
}
|
|
74
|
+
const edits = [];
|
|
75
|
+
for (const [index, item] of items.entries()) {
|
|
76
|
+
const edit = isRecord(item)
|
|
77
|
+
? replaceEdit(item, EMPTY_OLD_GUIDANCE)
|
|
78
|
+
: 'each change must be an object';
|
|
79
|
+
if (typeof edit === 'string') {
|
|
80
|
+
return `edit ${index + 1}: ${edit}`;
|
|
81
|
+
}
|
|
82
|
+
edits.push(edit);
|
|
83
|
+
}
|
|
84
|
+
return edits;
|
|
85
|
+
}
|
|
86
|
+
function quoted(sign, text) {
|
|
87
|
+
const lines = text.replace(/\r\n/g, '\n').replace(/\n$/, '').split('\n');
|
|
88
|
+
const shown = lines.slice(0, QUOTE_LINES).map((line) => `${sign} ${line}`);
|
|
89
|
+
return lines.length > QUOTE_LINES
|
|
90
|
+
? [...shown, `${sign} … ${lines.length - QUOTE_LINES} more lines`]
|
|
91
|
+
: shown;
|
|
92
|
+
}
|
|
93
|
+
const ENDS_IN_NEWLINE = /\r?\n$/;
|
|
94
|
+
function newlineNote(sign, text, other) {
|
|
95
|
+
return ENDS_IN_NEWLINE.test(other) && !ENDS_IN_NEWLINE.test(text)
|
|
96
|
+
? [`${sign} \\ no newline at the end of this text`]
|
|
97
|
+
: [];
|
|
98
|
+
}
|
|
99
|
+
function quoteOf(edit) {
|
|
100
|
+
if (edit.kind === 'replace') {
|
|
101
|
+
const what = edit.replaceAll ? 'replace every match' : 'replace';
|
|
102
|
+
return [
|
|
103
|
+
what,
|
|
104
|
+
...quoted('-', edit.old),
|
|
105
|
+
...newlineNote('-', edit.old, edit.replacement),
|
|
106
|
+
...quoted('+', edit.replacement),
|
|
107
|
+
...newlineNote('+', edit.replacement, edit.old)
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
const where = edit.kind === 'edge' ? `insert at the ${edit.at}` : `insert after line ${edit.line}`;
|
|
111
|
+
return [where, ...quoted('+', edit.text)];
|
|
112
|
+
}
|
|
113
|
+
function changed(requested, content, { edits, single }) {
|
|
114
|
+
const [only] = edits;
|
|
115
|
+
if (single && only?.kind === 'replace') {
|
|
116
|
+
const result = editMatch(content, only);
|
|
117
|
+
return result.error
|
|
118
|
+
? { error: result.error }
|
|
119
|
+
: { content: result.content, reply: { edited: requested, replacements: result.count } };
|
|
120
|
+
}
|
|
121
|
+
const result = applyEdits(content, edits);
|
|
122
|
+
if (result.error) {
|
|
123
|
+
return { error: result.error };
|
|
124
|
+
}
|
|
125
|
+
const diff = `--- a/${requested}\n+++ b/${requested}\n${result.diff}`;
|
|
8
126
|
return {
|
|
127
|
+
content: result.content,
|
|
128
|
+
reply: { edited: requested, changes: result.changes, data: { diff } }
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function approvalQuote(args, parse) {
|
|
132
|
+
const edits = parse(args);
|
|
133
|
+
if (typeof edits === 'string') {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const head = `edit ${String(args.path)}: ${edits.length === 1 ? '1 change' : `${edits.length} changes`}`;
|
|
137
|
+
const body = edits.flatMap((edit, index) => edits.length === 1
|
|
138
|
+
? quoteOf(edit)
|
|
139
|
+
: quoteOf(edit).map((line, at) => (at ? line : `${index + 1}. ${line}`)));
|
|
140
|
+
const quote = [head, ...body].join('\n');
|
|
141
|
+
return quote.length > QUOTE_CHARS ? `${quote.slice(0, QUOTE_CHARS - 1)}…` : quote;
|
|
142
|
+
}
|
|
143
|
+
const EDIT_DESCRIPTION = 'Change part of a file in the shared folder: replaces the text in old with new. old must match ' +
|
|
144
|
+
'one place in the file (copy it from read_file, without the line numbers); set replaceAll to ' +
|
|
145
|
+
'change every match. Asks the user first.';
|
|
146
|
+
const INSERT_DESCRIPTION = 'Add lines to a file in the shared folder without replacing any: insert is the lines to add, ' +
|
|
147
|
+
'after the line number read_file shows (0 is the start, "end" the end); for a line number, ' +
|
|
148
|
+
"expect is that line's exact text. Asks the user first.";
|
|
149
|
+
const EDIT_MANY_DESCRIPTION = 'Make several replacements in one file in the shared folder together: edits is a list of ' +
|
|
150
|
+
'{old, new}, each old matched against the file as read before any change. All apply or none ' +
|
|
151
|
+
'do. Asks the user first.';
|
|
152
|
+
const PATH = {
|
|
153
|
+
type: 'string',
|
|
154
|
+
description: 'File path, relative to the shared folder'
|
|
155
|
+
};
|
|
156
|
+
const REPLACE_PROPERTIES = {
|
|
157
|
+
old: { type: 'string', description: 'The exact text to replace' },
|
|
158
|
+
new: { type: 'string', description: 'The text to put in its place' },
|
|
159
|
+
replaceAll: { type: 'boolean', description: 'Replace every match instead of exactly one' }
|
|
160
|
+
};
|
|
161
|
+
const INSERT_PROPERTIES = {
|
|
162
|
+
insert: { type: 'string', description: 'Lines to add' },
|
|
163
|
+
after: {
|
|
164
|
+
type: ['integer', 'string'],
|
|
165
|
+
description: 'Line number to add after, as read_file shows it; 0 is the start, "end" the end'
|
|
166
|
+
},
|
|
167
|
+
expect: { type: 'string', description: 'The exact text of that line' }
|
|
168
|
+
};
|
|
169
|
+
export function createEditFileTool(options = {}) {
|
|
170
|
+
return fileEditTool({
|
|
9
171
|
name: 'edit_file',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
172
|
+
description: EDIT_DESCRIPTION,
|
|
173
|
+
properties: REPLACE_PROPERTIES,
|
|
174
|
+
required: ['path', 'old', 'new'],
|
|
175
|
+
parse: replaceOf
|
|
176
|
+
}, options);
|
|
177
|
+
}
|
|
178
|
+
export function createInsertTextTool(options = {}) {
|
|
179
|
+
return fileEditTool({
|
|
180
|
+
name: 'insert_text',
|
|
181
|
+
description: INSERT_DESCRIPTION,
|
|
182
|
+
properties: INSERT_PROPERTIES,
|
|
183
|
+
required: ['path', 'insert', 'after'],
|
|
184
|
+
parse: insertOf
|
|
185
|
+
}, options);
|
|
186
|
+
}
|
|
187
|
+
export function createEditManyTool(options = {}) {
|
|
188
|
+
return fileEditTool({
|
|
189
|
+
name: 'edit_many',
|
|
190
|
+
description: EDIT_MANY_DESCRIPTION,
|
|
191
|
+
properties: {
|
|
192
|
+
edits: {
|
|
193
|
+
type: 'array',
|
|
194
|
+
items: {
|
|
195
|
+
type: 'object',
|
|
196
|
+
properties: { ...REPLACE_PROPERTIES },
|
|
197
|
+
required: ['old', 'new']
|
|
198
|
+
},
|
|
199
|
+
description: 'The replacements, each {old, new}'
|
|
200
|
+
}
|
|
23
201
|
},
|
|
202
|
+
required: ['path', 'edits'],
|
|
203
|
+
parse: editsOf
|
|
204
|
+
}, options);
|
|
205
|
+
}
|
|
206
|
+
function fileEditTool({ name, description, properties, required, parse }, { realpath = defaultRealpath, deniedRoots }) {
|
|
207
|
+
return {
|
|
208
|
+
name,
|
|
209
|
+
toolset: 'files',
|
|
210
|
+
description,
|
|
211
|
+
parameters: { type: 'object', properties: { path: PATH, ...properties }, required },
|
|
24
212
|
effect: () => 'write',
|
|
25
213
|
autoApprove: false,
|
|
26
214
|
writeRootsRequired: true,
|
|
27
215
|
validate(args) {
|
|
28
216
|
if (!stringArg(args, 'path'))
|
|
29
217
|
return 'path is required';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
return typeof args.new === 'string' ? null : 'new must be a string';
|
|
218
|
+
const edits = parse(args);
|
|
219
|
+
return typeof edits === 'string' ? edits : null;
|
|
34
220
|
},
|
|
35
221
|
paths: (args, ctx) => rootedArgs(args, ctx, ['path']),
|
|
36
222
|
resource: (args, ctx) => ({
|
|
37
223
|
kind: 'file',
|
|
38
224
|
label: rootedLabel('edit', { grants: ctx, paths: [String(args.path)] })
|
|
39
225
|
}),
|
|
226
|
+
quote: name === 'edit_file'
|
|
227
|
+
? undefined
|
|
228
|
+
: (args) => approvalQuote(args, parse),
|
|
40
229
|
async execute(args, ctx) {
|
|
41
230
|
const requested = String(args.path);
|
|
231
|
+
const edits = parse(args);
|
|
232
|
+
if (typeof edits === 'string') {
|
|
233
|
+
return { error: edits };
|
|
234
|
+
}
|
|
42
235
|
const resolved = await resolveRooted(requested, {
|
|
43
236
|
grants: ctx,
|
|
44
237
|
write: true,
|
|
@@ -55,16 +248,15 @@ export function createEditFileTool({ realpath = defaultRealpath, deniedRoots } =
|
|
|
55
248
|
if (entry === null || blob === null) {
|
|
56
249
|
return { error: `no such file: ${requested}` };
|
|
57
250
|
}
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
replaceAll: args.replaceAll === true
|
|
251
|
+
const change = changed(requested, b4a.toString(blob, 'utf8'), {
|
|
252
|
+
edits,
|
|
253
|
+
single: name === 'edit_file'
|
|
62
254
|
});
|
|
63
|
-
if (
|
|
64
|
-
return
|
|
255
|
+
if ('error' in change) {
|
|
256
|
+
return change;
|
|
65
257
|
}
|
|
66
|
-
await writeText(drive, resolved.key,
|
|
67
|
-
return
|
|
258
|
+
await writeText(drive, resolved.key, change.content, { executable: entry.value.executable });
|
|
259
|
+
return change.reply;
|
|
68
260
|
}
|
|
69
261
|
catch (err) {
|
|
70
262
|
return { error: errorMessage(err) };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createEditFileTool } from './edit-file.js';
|
|
1
|
+
import { createEditFileTool, createEditManyTool, createInsertTextTool } from './edit-file.js';
|
|
2
2
|
import { createGlobTool } from './glob.js';
|
|
3
3
|
import { createGrepTool } from './grep.js';
|
|
4
4
|
import { createListDirTool } from './list-dir.js';
|
|
@@ -15,6 +15,8 @@ export function createFileTools(options = {}) {
|
|
|
15
15
|
createGrepTool(options),
|
|
16
16
|
createWriteFileTool(options),
|
|
17
17
|
createEditFileTool(options),
|
|
18
|
+
createInsertTextTool(options),
|
|
19
|
+
createEditManyTool(options),
|
|
18
20
|
createMoveFileTool(options),
|
|
19
21
|
createCopyFileTool(options),
|
|
20
22
|
createMakeDirTool(options),
|
|
@@ -9,3 +9,25 @@ export interface EditMatch {
|
|
|
9
9
|
error: string | null;
|
|
10
10
|
}
|
|
11
11
|
export declare function editMatch(content: string, request: EditRequest): EditMatch;
|
|
12
|
+
export interface ReplaceEdit extends EditRequest {
|
|
13
|
+
readonly kind: 'replace';
|
|
14
|
+
}
|
|
15
|
+
export interface EdgeInsert {
|
|
16
|
+
readonly kind: 'edge';
|
|
17
|
+
readonly text: string;
|
|
18
|
+
readonly at: 'start' | 'end';
|
|
19
|
+
}
|
|
20
|
+
export interface LineInsert {
|
|
21
|
+
readonly kind: 'line';
|
|
22
|
+
readonly text: string;
|
|
23
|
+
readonly line: number;
|
|
24
|
+
readonly expect: string;
|
|
25
|
+
}
|
|
26
|
+
export type TextEdit = ReplaceEdit | EdgeInsert | LineInsert;
|
|
27
|
+
export interface EditsApplied {
|
|
28
|
+
content: string;
|
|
29
|
+
changes: number;
|
|
30
|
+
diff: string;
|
|
31
|
+
error: string | null;
|
|
32
|
+
}
|
|
33
|
+
export declare function applyEdits(content: string, edits: readonly TextEdit[]): EditsApplied;
|