@qvac/harness 1.0.0-rc.5 → 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.
Files changed (123) hide show
  1. package/CHANGELOG.md +245 -23
  2. package/README.md +19 -7
  3. package/dist-lib/index.d.ts +5 -3
  4. package/dist-lib/index.js +43 -2
  5. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -3
  6. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +8 -1
  7. package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +21 -19
  8. package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +11 -4
  9. package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +10 -1
  10. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +9 -3
  11. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +36 -19
  12. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +1 -1
  13. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +9 -11
  14. package/dist-lib/lib/capabilities/completion-engine/driver.js +3 -0
  15. package/dist-lib/lib/capabilities/completion-engine/index.d.ts +4 -1
  16. package/dist-lib/lib/capabilities/completion-engine/index.js +3 -0
  17. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +15 -1
  18. package/dist-lib/lib/capabilities/completion-engine/model-round.js +52 -0
  19. package/dist-lib/lib/capabilities/completion-engine/round.d.ts +3 -3
  20. package/dist-lib/lib/capabilities/completion-engine/round.js +5 -2
  21. package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
  22. package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
  23. package/dist-lib/lib/capabilities/completion-engine/turns.js +14 -4
  24. package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
  25. package/dist-lib/lib/capabilities/detect-language.js +14 -2
  26. package/dist-lib/lib/capabilities/sdk-tool.d.ts +9 -1
  27. package/dist-lib/lib/capabilities/sdk-tool.js +21 -2
  28. package/dist-lib/lib/capabilities/tool-plan.d.ts +4 -0
  29. package/dist-lib/lib/capabilities/tool-plan.js +15 -0
  30. package/dist-lib/lib/connect.d.ts +2 -0
  31. package/dist-lib/lib/connect.js +79 -3
  32. package/dist-lib/lib/contract/run.d.ts +2 -0
  33. package/dist-lib/lib/contract-types.d.ts +5 -0
  34. package/dist-lib/lib/errors.d.ts +4 -0
  35. package/dist-lib/lib/errors.js +6 -0
  36. package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
  37. package/dist-lib/lib/hardware/cpu-placement.js +48 -0
  38. package/dist-lib/lib/helpers/goal-check.d.ts +2 -0
  39. package/dist-lib/lib/helpers/goal-check.js +18 -0
  40. package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
  41. package/dist-lib/lib/helpers/require-peers.js +23 -0
  42. package/dist-lib/lib/machine/completion/actions/completion.js +30 -11
  43. package/dist-lib/lib/machine/completion/context.js +2 -1
  44. package/dist-lib/lib/machine/completion/rules.d.ts +1 -1
  45. package/dist-lib/lib/machine/completion/rules.js +7 -8
  46. package/dist-lib/lib/machine/completion/types.d.ts +1 -0
  47. package/dist-lib/lib/models/llm-presets.d.ts +1 -0
  48. package/dist-lib/lib/models/model-catalog.js +1 -1
  49. package/dist-lib/lib/models/model-pool.d.ts +4 -0
  50. package/dist-lib/lib/models/model-pool.js +4 -1
  51. package/dist-lib/lib/models/opencl-cache.js +2 -2
  52. package/dist-lib/lib/plugins/registry.d.ts +2 -0
  53. package/dist-lib/lib/plugins/registry.js +4 -0
  54. package/dist-lib/lib/prompt.d.ts +2 -1
  55. package/dist-lib/lib/prompt.js +12 -12
  56. package/dist-lib/lib/residency/completion-runtime.d.ts +9 -1
  57. package/dist-lib/lib/residency/completion-runtime.js +29 -26
  58. package/dist-lib/lib/residency/index.d.ts +4 -0
  59. package/dist-lib/lib/residency/index.js +6 -1
  60. package/dist-lib/lib/round-host.d.ts +12 -0
  61. package/dist-lib/lib/round-host.js +57 -0
  62. package/dist-lib/lib/round-port.d.ts +24 -0
  63. package/dist-lib/lib/round-port.js +81 -0
  64. package/dist-lib/lib/sdk-loader.d.ts +1 -1
  65. package/dist-lib/lib/sdk-loader.js +30 -6
  66. package/dist-lib/lib/sdk-storage.d.ts +1 -0
  67. package/dist-lib/lib/sdk-storage.js +18 -2
  68. package/dist-lib/lib/serve.js +68 -6
  69. package/dist-lib/lib/sidecar/index.d.ts +10 -0
  70. package/dist-lib/lib/sidecar/index.js +35 -3
  71. package/dist-lib/lib/sidecar/user-plugins.d.ts +1 -0
  72. package/dist-lib/lib/sidecar/user-plugins.js +1 -1
  73. package/dist-lib/lib/tools/files/grep.js +113 -15
  74. package/dist-lib/lib/tools/fs/edit-match.js +75 -7
  75. package/dist-lib/lib/tools/fs/search.d.ts +1 -1
  76. package/dist-lib/lib/tools/fs/search.js +2 -1
  77. package/dist-lib/lib/tools/http-request.js +1 -0
  78. package/dist-lib/lib/tools/index.d.ts +2 -1
  79. package/dist-lib/lib/tools/index.js +2 -2
  80. package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
  81. package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
  82. package/dist-lib/lib/wire.d.ts +13 -0
  83. package/dist-lib/lib/wire.js +44 -1
  84. package/dist-lib/plugins/coding/read-only.d.ts +1 -0
  85. package/dist-lib/plugins/coding/read-only.js +264 -0
  86. package/dist-lib/plugins/coding/session.d.ts +3 -1
  87. package/dist-lib/plugins/coding/session.js +19 -2
  88. package/dist-lib/plugins/egress-proxy/index.d.ts +2 -2
  89. package/dist-lib/plugins/egress-proxy/index.js +5 -3
  90. package/dist-lib/plugins/image/index.js +7 -2
  91. package/dist-lib/plugins/language-hint/index.js +4 -1
  92. package/dist-lib/plugins/mcp/server.js +1 -1
  93. package/dist-lib/plugins/music/index.js +6 -2
  94. package/dist-lib/plugins/obsidian/readiness.js +2 -2
  95. package/dist-lib/plugins/obsidian/vault-read.js +17 -16
  96. package/dist-lib/plugins/python/index.js +1 -0
  97. package/dist-lib/plugins/python/loader.d.ts +1 -0
  98. package/dist-lib/plugins/python/loader.js +8 -0
  99. package/dist-lib/plugins/quickjs/index.js +4 -0
  100. package/dist-lib/plugins/quickjs/runtime.js +8 -3
  101. package/dist-lib/plugins/run-report/index.js +6 -2
  102. package/dist-lib/plugins/run-report/layout.js +1 -1
  103. package/dist-lib/plugins/sandbox-vm/index.js +3 -0
  104. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  105. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  106. package/dist-lib/plugins/speech/audio-resample.js +2 -1
  107. package/dist-lib/plugins/speech/index.d.ts +1 -0
  108. package/dist-lib/plugins/speech/index.js +8 -1
  109. package/dist-lib/plugins/speech/speech-runtime.js +3 -3
  110. package/dist-lib/plugins/translation/index.d.ts +1 -1
  111. package/dist-lib/plugins/translation/index.js +7 -3
  112. package/dist-lib/plugins/translation/translate.d.ts +2 -2
  113. package/dist-lib/plugins/translation/translate.js +7 -8
  114. package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -2
  115. package/dist-lib/plugins/walkie-talkie/index.js +13 -5
  116. package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
  117. package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
  118. package/dist-lib/schema/harness.js +12 -2
  119. package/dist-lib/spec/hrpc/messages.js +208 -150
  120. package/dist-lib/spec/hyperschema/index.js +208 -150
  121. package/dist-lib/spec/hyperschema/schema.json +125 -84
  122. package/dist-lib/spec/hyperschema/types.d.ts +4 -3
  123. package/package.json +150 -25
@@ -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
  }
@@ -104,5 +104,5 @@ export function serverTool(server, listed, credentialStore) {
104
104
  credentialAllowList
105
105
  }, ctx)
106
106
  };
107
- return server.defer ? { ...tool, defer: true, group: server.name } : tool;
107
+ return server.defer === false ? tool : { ...tool, defer: true, group: server.name };
108
108
  }
@@ -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);
@@ -6,8 +6,8 @@ export const OBSIDIAN_SKILL_NAME = 'obsidian';
6
6
  export const OBSIDIAN_VAULT_PATH_CREDENTIAL_KEY = 'obsidian_vault_path';
7
7
  export const OBSIDIAN_VAULT_MODE_NOTE = [
8
8
  'Runtime note — Obsidian vault file mode is active (a vault folder is configured):',
9
- '- Run vault commands through the `exec` tool, e.g. `obsidian vault info=path`, `obsidian search query="..."`, `obsidian read path="Folder/Note.md"`.',
10
- '- Start with `obsidian vault info=path` to confirm the configured vault.',
9
+ '- Run vault commands through the `exec` tool, e.g. `obsidian files`, `obsidian search query="..."`, `obsidian read path="Folder/Note.md"`.',
10
+ '- To list what is in the vault, run `obsidian files`. `read` takes a note name or a path inside the vault, never the vault folder.',
11
11
  '- `obsidian vaults` returns only the configured vault folder, not every vault in the Obsidian app.',
12
12
  '- App-only actions (open in app, plugin/sync/theme commands) are unavailable in this mode; they require the official Obsidian CLI connected to the running app.'
13
13
  ].join('\n');
@@ -2,6 +2,14 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { HarnessError } from '../../lib/errors.js';
4
4
  import { dailyCandidates, ensureWithinRoot, FRONTMATTER_RE, getArg, listFolders, listMarkdownFiles, parseFrontmatter, readFileText, resolveNotePath, todayStamp } from './vault-paths.js';
5
+ function statOrNull(p) {
6
+ try {
7
+ return fs.statSync(p);
8
+ }
9
+ catch {
10
+ return null;
11
+ }
12
+ }
5
13
  export function handleVault(vaultPath) {
6
14
  return JSON.stringify({ name: path.basename(vaultPath), path: vaultPath });
7
15
  }
@@ -17,9 +25,14 @@ export function handleVaults(vaultPath) {
17
25
  }
18
26
  export function handleRead(vaultPath, args) {
19
27
  const notePath = resolveNotePath(vaultPath, args);
20
- if (!notePath || !fs.existsSync(notePath)) {
28
+ const stat = notePath ? statOrNull(notePath) : null;
29
+ if (!notePath || !stat) {
21
30
  throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
22
31
  }
32
+ if (stat.isDirectory()) {
33
+ const folder = path.relative(path.resolve(vaultPath), notePath).split(path.sep).join('/');
34
+ throw new HarnessError('OBSIDIAN_PATH_IS_FOLDER', [folder]);
35
+ }
23
36
  return readFileText(notePath);
24
37
  }
25
38
  export function handleFiles(vaultPath, args) {
@@ -69,11 +82,7 @@ export function handleSearch(vaultPath, args) {
69
82
  return matches.join('\n') + truncated;
70
83
  }
71
84
  export function handleProperties(vaultPath, args) {
72
- const notePath = resolveNotePath(vaultPath, args);
73
- if (!notePath || !fs.existsSync(notePath)) {
74
- throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
75
- }
76
- return JSON.stringify(parseFrontmatter(readFileText(notePath)), null, 2);
85
+ return JSON.stringify(parseFrontmatter(handleRead(vaultPath, args)), null, 2);
77
86
  }
78
87
  function countTags(tagCounts, content) {
79
88
  for (const match of content.matchAll(/#([a-zA-Z0-9_/-]+)/g)) {
@@ -98,20 +107,12 @@ export function handleTags(vaultPath) {
98
107
  return sorted.map(([tag, count]) => `#${tag} (${count})`).join('\n') || '(no tags)';
99
108
  }
100
109
  export function handleWordcount(vaultPath, args) {
101
- const notePath = resolveNotePath(vaultPath, args);
102
- if (!notePath || !fs.existsSync(notePath)) {
103
- throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
104
- }
105
- const body = readFileText(notePath).replace(FRONTMATTER_RE, '').trim();
110
+ const body = handleRead(vaultPath, args).replace(FRONTMATTER_RE, '').trim();
106
111
  const words = body.split(/\s+/).filter(Boolean).length;
107
112
  return `${words} words`;
108
113
  }
109
114
  export function handleOutline(vaultPath, args) {
110
- const notePath = resolveNotePath(vaultPath, args);
111
- if (!notePath || !fs.existsSync(notePath)) {
112
- throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
113
- }
114
- const headings = readFileText(notePath)
115
+ const headings = handleRead(vaultPath, args)
115
116
  .split('\n')
116
117
  .filter((line) => /^#{1,6}\s/.test(line));
117
118
  return headings.join('\n') || '(no headings)';
@@ -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 {};