@qvac/harness 0.8.9 → 0.8.10

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 (114) hide show
  1. package/CHANGELOG.md +62 -1
  2. package/dist-lib/index.d.ts +1 -1
  3. package/dist-lib/index.js +51 -50
  4. package/dist-lib/lib/audio-transcode-bare.js +2 -2
  5. package/dist-lib/lib/capabilities/completion.d.ts +1 -2
  6. package/dist-lib/lib/capabilities/completion.js +29 -25
  7. package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
  8. package/dist-lib/lib/capabilities/voice.js +7 -6
  9. package/dist-lib/lib/connect.js +18 -17
  10. package/dist-lib/lib/errors.d.ts +266 -0
  11. package/dist-lib/lib/errors.js +189 -0
  12. package/dist-lib/lib/helpers/load-stall.d.ts +1 -1
  13. package/dist-lib/lib/helpers/load-stall.js +2 -2
  14. package/dist-lib/lib/helpers/race-abort.d.ts +2 -1
  15. package/dist-lib/lib/helpers/race-abort.js +3 -4
  16. package/dist-lib/lib/hooks/built-in/arg-repair.js +2 -2
  17. package/dist-lib/lib/hooks/pipeline.js +4 -4
  18. package/dist-lib/lib/hooks/run.js +2 -2
  19. package/dist-lib/lib/log.d.ts +26 -2
  20. package/dist-lib/lib/log.js +66 -16
  21. package/dist-lib/lib/models/model-pool.js +11 -6
  22. package/dist-lib/lib/models/model-source.js +3 -2
  23. package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
  24. package/dist-lib/lib/no-redirect-fetch-impl.js +2 -1
  25. package/dist-lib/lib/office/extract.js +4 -3
  26. package/dist-lib/lib/office/index.js +2 -1
  27. package/dist-lib/lib/resolution-detector.js +3 -3
  28. package/dist-lib/lib/rpc-session.js +2 -1
  29. package/dist-lib/lib/sdk-loader.js +2 -2
  30. package/dist-lib/lib/serve.js +33 -29
  31. package/dist-lib/lib/spawn.d.ts +2 -4
  32. package/dist-lib/lib/spawn.js +14 -7
  33. package/dist-lib/lib/tools/edit-image.js +2 -1
  34. package/dist-lib/lib/tools/exec/adapters/python/attachments.js +8 -8
  35. package/dist-lib/lib/tools/exec/adapters/python/guarded-fetch.js +7 -6
  36. package/dist-lib/lib/tools/exec/adapters/python/interrupt-timer.js +2 -2
  37. package/dist-lib/lib/tools/exec/adapters/python/memfs.js +2 -2
  38. package/dist-lib/lib/tools/exec/adapters/python/pyodide.js +8 -8
  39. package/dist-lib/lib/tools/exec/adapters/python/run-session.js +11 -7
  40. package/dist-lib/lib/tools/exec/adapters/python/wheels.js +5 -5
  41. package/dist-lib/lib/tools/exec/adapters/python/worker/active.js +2 -2
  42. package/dist-lib/lib/tools/exec/adapters/python/worker/client.js +9 -8
  43. package/dist-lib/lib/tools/exec/adapters/python/worker/protocol.d.ts +2 -0
  44. package/dist-lib/lib/tools/exec/adapters/python/worker/serve.js +4 -4
  45. package/dist-lib/lib/tools/exec/adapters/python/worker/spawn.d.ts +2 -1
  46. package/dist-lib/lib/tools/exec/adapters/python/worker/spawn.js +2 -1
  47. package/dist-lib/lib/tools/exec/obsidian/note-name.js +2 -1
  48. package/dist-lib/lib/tools/exec/obsidian/safe-path.js +5 -4
  49. package/dist-lib/lib/tools/exec/obsidian/vault-create.js +3 -2
  50. package/dist-lib/lib/tools/exec/obsidian/vault-fs.js +2 -2
  51. package/dist-lib/lib/tools/exec/obsidian/vault-paths.js +3 -2
  52. package/dist-lib/lib/tools/exec/obsidian/vault-read.js +6 -5
  53. package/dist-lib/lib/tools/exec/obsidian/vault-write.js +13 -12
  54. package/dist-lib/lib/tools/exec/runner.js +2 -1
  55. package/dist-lib/lib/tools/files/edit-file.d.ts +3 -0
  56. package/dist-lib/lib/tools/files/edit-file.js +73 -0
  57. package/dist-lib/lib/tools/files/glob.d.ts +3 -0
  58. package/dist-lib/lib/tools/files/glob.js +63 -0
  59. package/dist-lib/lib/tools/files/grep.d.ts +3 -0
  60. package/dist-lib/lib/tools/files/grep.js +114 -0
  61. package/dist-lib/lib/tools/files/index.d.ts +3 -0
  62. package/dist-lib/lib/tools/files/index.js +23 -0
  63. package/dist-lib/lib/tools/files/list-dir.d.ts +5 -0
  64. package/dist-lib/lib/tools/files/list-dir.js +130 -0
  65. package/dist-lib/lib/tools/files/make-dir.d.ts +3 -0
  66. package/dist-lib/lib/tools/files/make-dir.js +47 -0
  67. package/dist-lib/lib/tools/files/read-file.d.ts +3 -0
  68. package/dist-lib/lib/tools/files/read-file.js +103 -0
  69. package/dist-lib/lib/tools/files/transfer.d.ts +4 -0
  70. package/dist-lib/lib/tools/files/transfer.js +82 -0
  71. package/dist-lib/lib/tools/files/trash-file.d.ts +4 -0
  72. package/dist-lib/lib/tools/files/trash-file.js +61 -0
  73. package/dist-lib/lib/tools/files/write-file.d.ts +3 -0
  74. package/dist-lib/lib/tools/files/write-file.js +55 -0
  75. package/dist-lib/lib/tools/fs/document-text.d.ts +2 -0
  76. package/dist-lib/lib/tools/fs/document-text.js +38 -0
  77. package/dist-lib/lib/tools/fs/edit-match.d.ts +11 -0
  78. package/dist-lib/lib/tools/fs/edit-match.js +85 -0
  79. package/dist-lib/lib/tools/fs/remote.d.ts +2 -1
  80. package/dist-lib/lib/tools/fs/remote.js +4 -4
  81. package/dist-lib/lib/tools/fs/scope.d.ts +1 -1
  82. package/dist-lib/lib/tools/fs/scope.js +3 -2
  83. package/dist-lib/lib/tools/fs/targets.d.ts +10 -0
  84. package/dist-lib/lib/tools/fs/targets.js +32 -0
  85. package/dist-lib/lib/tools/fs/tool-path.d.ts +24 -0
  86. package/dist-lib/lib/tools/fs/tool-path.js +58 -0
  87. package/dist-lib/lib/tools/fs/walk.js +3 -3
  88. package/dist-lib/lib/tools/generate-image.d.ts +2 -2
  89. package/dist-lib/lib/tools/generate-image.js +5 -6
  90. package/dist-lib/lib/tools/office.js +2 -1
  91. package/dist-lib/lib/tools/skill.js +2 -1
  92. package/dist-lib/lib/tools/skills/bundled-dir.js +4 -4
  93. package/dist-lib/lib/tools/skills/catalog.js +2 -2
  94. package/dist-lib/lib/tools/skills/credential-health.js +3 -3
  95. package/dist-lib/lib/tools/skills/overlay-crud.js +3 -2
  96. package/dist-lib/lib/tools/translate.d.ts +2 -2
  97. package/dist-lib/lib/tools/translate.js +5 -6
  98. package/dist-lib/lib/tools/weather-lookup/geocode.js +5 -4
  99. package/dist-lib/lib/web-search/engines/bing.js +2 -1
  100. package/dist-lib/lib/web-search/engines/google.js +2 -1
  101. package/dist-lib/lib/web-search/fetch-html.d.ts +5 -5
  102. package/dist-lib/lib/web-search/fetch-html.js +12 -15
  103. package/package.json +66 -24
  104. package/worker/harness-sidecar.mjs +12 -13
  105. package/dist-lib/lib/tools/create-documents.d.ts +0 -3
  106. package/dist-lib/lib/tools/create-documents.js +0 -95
  107. package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
  108. package/dist-lib/lib/tools/edit-documents.js +0 -132
  109. package/dist-lib/lib/tools/file-glob.d.ts +0 -14
  110. package/dist-lib/lib/tools/file-glob.js +0 -118
  111. package/dist-lib/lib/tools/grep.d.ts +0 -5
  112. package/dist-lib/lib/tools/grep.js +0 -184
  113. package/dist-lib/lib/tools/read-files.d.ts +0 -5
  114. package/dist-lib/lib/tools/read-files.js +0 -157
@@ -1,157 +0,0 @@
1
- import { errorMessage, isRecord } from '../guards.js';
2
- import { readLines } from './fs/read.js';
3
- import { isDriveReadTruncated } from './fs/remote.js';
4
- import { canonicalDenyRoots, defaultRealpath, resolveKey } from './fs/scope.js';
5
- export const DEFAULT_READ_CHARS = 8192;
6
- export const MAX_READ_CHARS = 65_536;
7
- function lineIndex(value) {
8
- if (value === undefined || value === null)
9
- return undefined;
10
- const n = Number(value);
11
- if (!Number.isInteger(n) || n < 1) {
12
- return null;
13
- }
14
- return n;
15
- }
16
- function fileRequests(raw) {
17
- if (!Array.isArray(raw) || raw.length === 0)
18
- return null;
19
- const files = [];
20
- for (const entry of raw) {
21
- if (!isRecord(entry) || typeof entry.path !== 'string' || !entry.path.trim()) {
22
- return null;
23
- }
24
- const startLine = lineIndex(entry.startLine);
25
- const endLine = lineIndex(entry.endLine);
26
- if (startLine === null || endLine === null) {
27
- return null;
28
- }
29
- files.push({ path: entry.path, startLine, endLine });
30
- }
31
- return files;
32
- }
33
- async function slice(drive, key, { request, maxChars }) {
34
- const first = request.startLine ?? 1;
35
- const last = request.endLine ?? Infinity;
36
- const kept = [];
37
- let length = 0;
38
- let index = 0;
39
- let capped = false;
40
- try {
41
- for await (const line of readLines(drive, key)) {
42
- if (++index < first)
43
- continue;
44
- if (index > last)
45
- break;
46
- kept.push(line);
47
- length += line.length + (kept.length > 1 ? 1 : 0);
48
- if (length > maxChars) {
49
- break;
50
- }
51
- }
52
- }
53
- catch (err) {
54
- if (!isDriveReadTruncated(err)) {
55
- throw err;
56
- }
57
- capped = true;
58
- }
59
- const text = kept.join('\n');
60
- return text.length > maxChars || capped
61
- ? { content: text.slice(0, maxChars), truncated: true }
62
- : { content: text };
63
- }
64
- export function createReadFilesTool({ realpath = defaultRealpath, deniedRoots } = {}) {
65
- return {
66
- name: 'read_files',
67
- toolset: 'files',
68
- description: 'Read the contents of one or more files inside the granted directories. ' +
69
- 'Optionally slice by 1-indexed line range. Failures are reported per file.',
70
- parameters: {
71
- type: 'object',
72
- properties: {
73
- files: {
74
- type: 'array',
75
- description: 'Files to read',
76
- items: {
77
- type: 'object',
78
- properties: {
79
- path: { type: 'string', description: 'File path' },
80
- startLine: { type: 'number', description: 'Optional 1-indexed first line' },
81
- endLine: { type: 'number', description: 'Optional 1-indexed last line (inclusive)' }
82
- },
83
- required: ['path']
84
- }
85
- },
86
- maxChars: {
87
- type: 'number',
88
- description: `Optional per-file cap in characters (default ${DEFAULT_READ_CHARS}, max ${MAX_READ_CHARS})`
89
- }
90
- },
91
- required: ['files']
92
- },
93
- effect: () => 'read',
94
- stableRead: true,
95
- autoApprove: true,
96
- rootsRequired: true,
97
- validate(rawArgs) {
98
- if (!fileRequests(rawArgs.files)) {
99
- return 'files must be a non-empty array of { path } with optional positive integer startLine/endLine';
100
- }
101
- const maxChars = rawArgs.maxChars;
102
- if (maxChars !== undefined && maxChars !== null) {
103
- const n = Number(maxChars);
104
- if (!Number.isInteger(n) || n <= 0 || n > MAX_READ_CHARS) {
105
- return `maxChars must be a positive integer ≤ ${MAX_READ_CHARS}`;
106
- }
107
- }
108
- return null;
109
- },
110
- resource(args) {
111
- const files = fileRequests(args.files);
112
- if (!files) {
113
- return null;
114
- }
115
- const label = files
116
- .map((f) => f.path)
117
- .slice(0, 3)
118
- .join(', ');
119
- return {
120
- kind: 'file',
121
- label: files.length > 3 ? `${label} (+${files.length - 3} more)` : label
122
- };
123
- },
124
- async execute(rawArgs, ctx) {
125
- const roots = ctx?.fsRoots ?? [];
126
- const requests = fileRequests(rawArgs.files);
127
- if (!requests) {
128
- return { error: 'files must be a non-empty array of { path }' };
129
- }
130
- const maxChars = rawArgs.maxChars ? Number(rawArgs.maxChars) : DEFAULT_READ_CHARS;
131
- const files = [];
132
- const failed = [];
133
- const deny = await canonicalDenyRoots(deniedRoots, realpath);
134
- for (const request of requests) {
135
- const resolved = await resolveKey(request.path, roots, { realpath, deny });
136
- if ('error' in resolved) {
137
- failed.push({ path: request.path, error: resolved.error });
138
- continue;
139
- }
140
- try {
141
- if ((await resolved.root.drive.entry(resolved.key)) === null) {
142
- failed.push({ path: request.path, error: `no such file: ${request.path}` });
143
- continue;
144
- }
145
- files.push({
146
- path: request.path,
147
- ...(await slice(resolved.root.drive, resolved.key, { request, maxChars }))
148
- });
149
- }
150
- catch (err) {
151
- failed.push({ path: request.path, error: errorMessage(err) });
152
- }
153
- }
154
- return { files, failed: failed.length ? failed : undefined };
155
- }
156
- };
157
- }