@xandreed/plugin-workspace 0.0.0-stage → 0.15.0

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -2
  3. package/dist/bash-tool.adapter.d.ts +15 -0
  4. package/dist/bash-tool.adapter.js +73 -0
  5. package/dist/bash.adapter.d.ts +81 -0
  6. package/dist/bash.adapter.js +112 -0
  7. package/dist/file-system.adapter.d.ts +24 -0
  8. package/dist/file-system.adapter.js +52 -0
  9. package/dist/image-resizer.adapter.d.ts +5 -0
  10. package/dist/image-resizer.adapter.js +68 -0
  11. package/dist/image-resizer.entity.d.ts +23 -0
  12. package/dist/image-resizer.entity.functions.d.ts +15 -0
  13. package/dist/image-resizer.entity.functions.js +4 -0
  14. package/dist/image-resizer.entity.js +7 -0
  15. package/dist/index.d.ts +14 -0
  16. package/dist/index.js +38 -0
  17. package/dist/local-system.entity.d.ts +47 -0
  18. package/dist/local-system.entity.functions.d.ts +53 -0
  19. package/dist/local-system.entity.functions.js +46 -0
  20. package/dist/local-system.entity.js +12 -0
  21. package/dist/plugin.adapter.d.ts +183 -0
  22. package/dist/plugin.adapter.js +38 -0
  23. package/dist/read-tools.adapter.d.ts +39 -0
  24. package/dist/read-tools.adapter.js +109 -0
  25. package/dist/ripgrep.adapter.d.ts +74 -0
  26. package/dist/ripgrep.adapter.js +56 -0
  27. package/dist/ripgrep.entity.d.ts +63 -0
  28. package/dist/ripgrep.entity.functions.d.ts +87 -0
  29. package/dist/ripgrep.entity.functions.js +62 -0
  30. package/dist/ripgrep.entity.js +10 -0
  31. package/dist/shell.entity.functions.d.ts +2 -0
  32. package/dist/shell.entity.functions.js +1 -0
  33. package/dist/skills/skills-directory.adapter.d.ts +68 -0
  34. package/dist/skills/skills-directory.adapter.js +30 -0
  35. package/dist/skills/skills-directory.entity.d.ts +99 -0
  36. package/dist/skills/skills-directory.entity.functions.d.ts +88 -0
  37. package/dist/skills/skills-directory.entity.functions.js +45 -0
  38. package/dist/skills/skills-directory.entity.js +35 -0
  39. package/dist/text-edit.entity.d.ts +32 -0
  40. package/dist/text-edit.entity.functions.d.ts +32 -0
  41. package/dist/text-edit.entity.functions.js +68 -0
  42. package/dist/text-edit.entity.js +15 -0
  43. package/dist/text-search.entity.d.ts +23 -0
  44. package/dist/text-search.entity.functions.d.ts +58 -0
  45. package/dist/text-search.entity.functions.js +30 -0
  46. package/dist/text-search.entity.js +10 -0
  47. package/dist/text-window.entity.d.ts +46 -0
  48. package/dist/text-window.entity.functions.d.ts +54 -0
  49. package/dist/text-window.entity.functions.js +88 -0
  50. package/dist/text-window.entity.js +21 -0
  51. package/dist/workspace-path.entity.d.ts +43 -0
  52. package/dist/workspace-path.entity.functions.d.ts +90 -0
  53. package/dist/workspace-path.entity.functions.js +88 -0
  54. package/dist/workspace-path.entity.js +9 -0
  55. package/dist/workspace-tools.adapter.d.ts +66 -0
  56. package/dist/workspace-tools.adapter.js +60 -0
  57. package/dist/workspace-tools.entity.d.ts +552 -0
  58. package/dist/workspace-tools.entity.functions.d.ts +126 -0
  59. package/dist/workspace-tools.entity.functions.js +180 -0
  60. package/dist/workspace-tools.entity.js +154 -0
  61. package/dist/write-tools.adapter.d.ts +12 -0
  62. package/dist/write-tools.adapter.js +79 -0
  63. package/package.json +30 -4
@@ -0,0 +1,552 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * The seven workspace tools, by the names the model calls them.
4
+ *
5
+ * @public
6
+ */
7
+ export declare const WorkspaceToolName: Schema.Literals<readonly ["read", "write", "edit", "ls", "find", "grep", "bash"]>;
8
+ export type WorkspaceToolName = typeof WorkspaceToolName.Type;
9
+ /**
10
+ * The tools' three skills, by the short names `always` takes: `read`
11
+ * (`workspace.read`: read, ls, find, grep), `edit` (`workspace.edit`: write,
12
+ * edit) and `shell` (`workspace.shell`: bash).
13
+ *
14
+ * @public
15
+ */
16
+ export declare const WorkspaceSkillName: Schema.Literals<readonly ["read", "edit", "shell"]>;
17
+ export type WorkspaceSkillName = typeof WorkspaceSkillName.Type;
18
+ /**
19
+ * The grants the tools that change things need: `write` and `edit` need `fs.write`, `bash` needs `shell.exec`.
20
+ *
21
+ * @public
22
+ */
23
+ export declare const WORKSPACE_PERMISSIONS: {
24
+ readonly write: "fs.write";
25
+ readonly exec: "shell.exec";
26
+ };
27
+ /**
28
+ * How `workspaceToolsPlugin` (and `workspaceTools`) works on the workspace,
29
+ * `SessionEnvironment.workspace`. Flat.
30
+ *
31
+ * - `tools`: the tools to register (all seven by default). A skill whose
32
+ * tools are all left out is left out too.
33
+ * - `always`: the skills active from a turn's first step: `read` by default.
34
+ * `edit` and `shell` here need their grants (`fs.write`, `shell.exec`), or
35
+ * the turn fails with `capability.forbidden`; otherwise the model loads
36
+ * them with `load_skill`, which refuses them without the grants
37
+ * (`PermissionDenied`).
38
+ * - `confine`: refuse paths whose real location (links resolved, through the
39
+ * nearest ancestor that exists) is outside the workspace and extra roots.
40
+ * - `workspaceAccess`: `read` refuses writes in the workspace; `write`
41
+ * permits them. `roots` adds readable or writable directories, absolute
42
+ * or relative to the session's workspace. The longest matching real root
43
+ * decides access. These restrictions apply with `confine`; bash remains
44
+ * unconfined. An extra root that cannot be resolved is skipped and logged.
45
+ * - `protect`: globs, relative to the root, that `write` and `edit` refuse.
46
+ * - `exclude`: names (or, with a `/`, paths relative to the root) `find`
47
+ * and `grep` never enter below the directory they search. Both lists are
48
+ * checked with `compileGlob` when the options are decoded.
49
+ * - `maxLines`, `maxBytes`: the most `read`, `find` and `grep` show at once,
50
+ * and the tail of a command's output `bash` keeps.
51
+ * - `lsEntries`, `findResults`, `grepMatches`: the most entries, paths and
52
+ * matching lines the model gets (a call may ask for fewer).
53
+ * - `grepLineChars`: the displayed line width; builtin also cuts before matching.
54
+ * - `grepEngine`: auto probes for rg once over this machine's pair
55
+ * (`localSystemPlugin`'s FileSystem and Bash), falling back to builtin,
56
+ * and selects builtin over any other pair; ripgrep requires rg over
57
+ * whatever pair the host gives. `grepTimeoutMs` bounds rg commands; the synchronous builtin
58
+ * engine is not time-bounded. `grepIgnoreFiles` honours ignore files in rg
59
+ * only (false searches ignored files too).
60
+ * - `maxFileBytes`: the largest file `read`, `edit` and `grep` load, and
61
+ * the most of a command's output `bash` saves.
62
+ * - `readImages`: `read` returns a PNG, JPEG, GIF or WebP image (by its
63
+ * bytes, whatever its name) as an image the model is sent; `false`
64
+ * reports it as a binary file, as any other. A host whose models read
65
+ * text only (a route without image parts, such as an endpoint without
66
+ * `images`, or memory with `maxMediaChars: 0`) sets `false`: the model
67
+ * would get a label line in the image's place, and the session would
68
+ * still store the bytes.
69
+ * - `imageMaxSide`: with an ImageResizer, fit images to at most this many
70
+ * pixels a side (64 to 8000, default 8000). Without a resizer, read keeps
71
+ * the existing provider-limit behavior.
72
+ * - `fuzzyEdit`: when an edit's text is not found, match it once more over
73
+ * whole lines with whitespace, Unicode compatibility forms and smart
74
+ * quotes normalised (the match must still be unique).
75
+ * - `bashTimeoutMs`, `bashMaxTimeoutMs`: a command's timeout unless the
76
+ * model asks for another, and the most it may ask for.
77
+ * - `bashEnv`: variables every command gets. `bashInheritEnv: true` passes
78
+ * the host's whole environment (provider keys included); otherwise only
79
+ * the names in `bashEnvAllow` (a trailing `*` matches a prefix) pass.
80
+ * `bashSessionEnv` adds `EFFERENT_SESSION_ID`, `EFFERENT_RUN_ID` and
81
+ * `EFFERENT_WORKSPACE`.
82
+ * - `spillDir`: where a command's whole output (its first `maxFileBytes`)
83
+ * is saved once it is longer than `bash` shows (relative to the root;
84
+ * `null` saves nothing), keeping the newest `spillKeep` files.
85
+ * - `progressMs`: how long output is gathered before it is published, as
86
+ * one `tool.progress` event per run of output from one stream.
87
+ * - `environmentSection`, `sectionOrder`: the `workspace.environment`
88
+ * system-prompt section (tier `session`) and its order.
89
+ *
90
+ * @public
91
+ */
92
+ export declare const WorkspaceToolsConfig: Schema.Struct<{
93
+ readonly tools: Schema.$Array<Schema.Literals<readonly ["read", "write", "edit", "ls", "find", "grep", "bash"]>>;
94
+ readonly always: Schema.$Array<Schema.Literals<readonly ["read", "edit", "shell"]>>;
95
+ readonly confine: Schema.Boolean;
96
+ readonly workspaceAccess: Schema.Literals<readonly ["read", "write"]>;
97
+ readonly roots: Schema.$Array<Schema.Struct<{
98
+ readonly path: Schema.NonEmptyString;
99
+ readonly access: Schema.Literals<readonly ["read", "write"]>;
100
+ }>>;
101
+ readonly protect: Schema.$Array<Schema.String>;
102
+ readonly exclude: Schema.$Array<Schema.String>;
103
+ readonly maxLines: Schema.Int;
104
+ readonly maxBytes: Schema.Int;
105
+ readonly lsEntries: Schema.Int;
106
+ readonly findResults: Schema.Int;
107
+ readonly grepMatches: Schema.Int;
108
+ readonly grepLineChars: Schema.Int;
109
+ readonly grepEngine: Schema.Literals<readonly ["auto", "ripgrep", "builtin"]>;
110
+ readonly grepTimeoutMs: Schema.Int;
111
+ readonly grepIgnoreFiles: Schema.Boolean;
112
+ readonly maxFileBytes: Schema.Int;
113
+ readonly readImages: Schema.Boolean;
114
+ readonly imageMaxSide: Schema.Int;
115
+ readonly fuzzyEdit: Schema.Boolean;
116
+ readonly bashTimeoutMs: Schema.Int;
117
+ readonly bashMaxTimeoutMs: Schema.Int;
118
+ readonly bashEnv: Schema.$Record<Schema.String, Schema.String>;
119
+ readonly bashInheritEnv: Schema.Boolean;
120
+ readonly bashEnvAllow: Schema.$Array<Schema.String>;
121
+ readonly bashSessionEnv: Schema.Boolean;
122
+ readonly spillDir: Schema.NullOr<Schema.String>;
123
+ readonly spillKeep: Schema.Int;
124
+ readonly progressMs: Schema.Int;
125
+ readonly environmentSection: Schema.Boolean;
126
+ readonly sectionOrder: Schema.Int;
127
+ }>;
128
+ export type WorkspaceToolsConfig = typeof WorkspaceToolsConfig.Type;
129
+ /** @public */
130
+ export declare const workspaceToolsDefaults: WorkspaceToolsConfig;
131
+ /**
132
+ * `read`: a file's lines from `offset` (1-based, default 1), at most `limit` of them (and never more than the configured window).
133
+ *
134
+ * @public
135
+ */
136
+ export declare const ReadParams: Schema.Struct<{
137
+ readonly path: Schema.String;
138
+ readonly offset: Schema.optionalKey<Schema.Int>;
139
+ readonly limit: Schema.optionalKey<Schema.Int>;
140
+ }>;
141
+ export type ReadParams = typeof ReadParams.Type;
142
+ /**
143
+ * What `read` found: a window of a text file's lines (`next` is the offset
144
+ * to continue from when lines are left; `clipped` when the first line alone
145
+ * was longer than the window's bytes and only its start is shown; `lossy`
146
+ * when the file is not valid UTF-8 and the bytes that are not show as
147
+ * U+FFFD, which `edit` refuses), or a binary file (a NUL byte in its first
148
+ * 8 KB). With `readImages`, a binary file whose bytes are a PNG, JPEG, GIF
149
+ * or WebP image is an `Image` (core's `mediaFromBytes`: the type its bytes
150
+ * are, its size and fingerprint), which the view sends the model as an
151
+ * image of the result; one core refuses (over `MEDIA_LIMITS.imageBytes`,
152
+ * over `MEDIA_LIMITS.maxPixels` a side, or a header without a size) is an
153
+ * `ImageRejected` note: its type, size and why. Any other binary file is
154
+ * `Binary`, with the media type its name suggests.
155
+ *
156
+ * @public
157
+ */
158
+ export declare const ReadResult: Schema.Union<readonly [Schema.TaggedStruct<"Text", {
159
+ readonly path: Schema.String;
160
+ readonly text: Schema.String;
161
+ readonly firstLine: Schema.Int;
162
+ readonly lastLine: Schema.Int;
163
+ readonly totalLines: Schema.Int;
164
+ readonly next: Schema.NullOr<Schema.Int>;
165
+ readonly clipped: Schema.Boolean;
166
+ readonly lossy: Schema.Boolean;
167
+ }>, Schema.TaggedStruct<"Binary", {
168
+ readonly path: Schema.String;
169
+ readonly bytes: Schema.Int;
170
+ readonly mediaType: Schema.NullOr<Schema.String>;
171
+ }>, Schema.TaggedStruct<"Image", {
172
+ readonly path: Schema.String;
173
+ readonly image: Schema.Struct<{
174
+ readonly type: Schema.Literal<"media">;
175
+ readonly mediaType: Schema.Literals<readonly ["image/png", "image/jpeg", "image/gif", "image/webp"]>;
176
+ readonly data: Schema.String;
177
+ readonly fingerprint: Schema.brand<Schema.String, "MediaFingerprint">;
178
+ readonly bytes: Schema.Int;
179
+ readonly name: Schema.optionalKey<Schema.String>;
180
+ readonly alt: Schema.optionalKey<Schema.String>;
181
+ }>;
182
+ /** Source dimensions and size when a resizer supplied the returned image; no original image bytes. */
183
+ readonly original: Schema.optionalKey<Schema.Struct<{
184
+ readonly mediaType: Schema.Literals<readonly ["image/png", "image/jpeg", "image/gif", "image/webp"]>;
185
+ readonly bytes: Schema.Int;
186
+ readonly width: Schema.Int;
187
+ readonly height: Schema.Int;
188
+ }>>;
189
+ }>, Schema.TaggedStruct<"ImageRejected", {
190
+ readonly path: Schema.String;
191
+ readonly mediaType: Schema.Literals<readonly ["image/png", "image/jpeg", "image/gif", "image/webp"]>;
192
+ readonly bytes: Schema.Int;
193
+ readonly reason: Schema.Literals<readonly ["Empty", "InvalidBase64", "UnsupportedType", "TooLarge", "TooManyPixels", "Unreadable", "TooMany", "TooLargeTogether"]>;
194
+ readonly message: Schema.String;
195
+ }>]>;
196
+ export type ReadResult = typeof ReadResult.Type;
197
+ /** @public */
198
+ export declare const WriteParams: Schema.Struct<{
199
+ readonly path: Schema.String;
200
+ readonly content: Schema.String;
201
+ }>;
202
+ export type WriteParams = typeof WriteParams.Type;
203
+ /**
204
+ * What `write` did: how many bytes it wrote, and whether the file is new.
205
+ *
206
+ * @public
207
+ */
208
+ export declare const WriteResult: Schema.Struct<{
209
+ readonly path: Schema.String;
210
+ readonly bytes: Schema.Int;
211
+ readonly created: Schema.Boolean;
212
+ }>;
213
+ export type WriteResult = typeof WriteResult.Type;
214
+ /**
215
+ * One replacement: `oldText` (exactly once in the file) becomes `newText`.
216
+ *
217
+ * @public
218
+ */
219
+ export declare const TextEdit: Schema.Struct<{
220
+ readonly oldText: Schema.String;
221
+ readonly newText: Schema.String;
222
+ }>;
223
+ export type TextEdit = typeof TextEdit.Type;
224
+ /** @public */
225
+ export declare const EditParams: Schema.Struct<{
226
+ readonly path: Schema.String;
227
+ readonly edits: Schema.NonEmptyArray<Schema.Struct<{
228
+ readonly oldText: Schema.String;
229
+ readonly newText: Schema.String;
230
+ }>>;
231
+ }>;
232
+ export type EditParams = typeof EditParams.Type;
233
+ /**
234
+ * What `edit` did: how many blocks it replaced, whether any was found only
235
+ * after normalising, the first changed line, and the change as a unified
236
+ * diff (for a host's UI; the model is shown a one-line summary).
237
+ *
238
+ * @public
239
+ */
240
+ export declare const EditResult: Schema.Struct<{
241
+ readonly path: Schema.String;
242
+ readonly replaced: Schema.Int;
243
+ readonly normalized: Schema.Boolean;
244
+ readonly firstChangedLine: Schema.Int;
245
+ readonly diff: Schema.String;
246
+ }>;
247
+ export type EditResult = typeof EditResult.Type;
248
+ /** @public */
249
+ export declare const LsParams: Schema.Struct<{
250
+ readonly path: Schema.optionalKey<Schema.String>;
251
+ readonly limit: Schema.optionalKey<Schema.Int>;
252
+ }>;
253
+ export type LsParams = typeof LsParams.Type;
254
+ /** @public */
255
+ export declare const LsEntry: Schema.Struct<{
256
+ readonly name: Schema.String;
257
+ readonly kind: Schema.Literals<readonly ["file", "directory", "symlink", "other"]>;
258
+ }>;
259
+ export type LsEntry = typeof LsEntry.Type;
260
+ /**
261
+ * A directory's entries by name, at most the limit of them; `total` counts them all.
262
+ *
263
+ * @public
264
+ */
265
+ export declare const LsResult: Schema.Struct<{
266
+ readonly path: Schema.String;
267
+ readonly entries: Schema.$Array<Schema.Struct<{
268
+ readonly name: Schema.String;
269
+ readonly kind: Schema.Literals<readonly ["file", "directory", "symlink", "other"]>;
270
+ }>>;
271
+ readonly total: Schema.Int;
272
+ }>;
273
+ export type LsResult = typeof LsResult.Type;
274
+ /** @public */
275
+ export declare const FindParams: Schema.Struct<{
276
+ readonly pattern: Schema.String;
277
+ readonly path: Schema.optionalKey<Schema.String>;
278
+ readonly limit: Schema.optionalKey<Schema.Int>;
279
+ }>;
280
+ export type FindParams = typeof FindParams.Type;
281
+ /**
282
+ * The files a glob matched, as paths relative to the workspace root; `truncated` when more matched.
283
+ *
284
+ * @public
285
+ */
286
+ export declare const FindResult: Schema.Struct<{
287
+ readonly pattern: Schema.String;
288
+ readonly path: Schema.String;
289
+ readonly paths: Schema.$Array<Schema.String>;
290
+ readonly truncated: Schema.Boolean;
291
+ }>;
292
+ export type FindResult = typeof FindResult.Type;
293
+ /** @public */
294
+ export declare const GrepParams: Schema.Struct<{
295
+ readonly pattern: Schema.String;
296
+ readonly path: Schema.optionalKey<Schema.String>;
297
+ readonly glob: Schema.optionalKey<Schema.String>;
298
+ readonly ignoreCase: Schema.optionalKey<Schema.Boolean>;
299
+ readonly literal: Schema.optionalKey<Schema.Boolean>;
300
+ readonly context: Schema.optionalKey<Schema.Int>;
301
+ readonly limit: Schema.optionalKey<Schema.Int>;
302
+ }>;
303
+ export type GrepParams = typeof GrepParams.Type;
304
+ /**
305
+ * One line `grep` shows: a matching line, or (`match: false`) a line of context around one. `text` is cut to the configured width.
306
+ *
307
+ * @public
308
+ */
309
+ export declare const GrepLine: Schema.Struct<{
310
+ readonly path: Schema.String;
311
+ readonly line: Schema.Int;
312
+ readonly text: Schema.String;
313
+ readonly match: Schema.Boolean;
314
+ }>;
315
+ export type GrepLine = typeof GrepLine.Type;
316
+ /**
317
+ * A file `grep` could not read, and why (`Permission` when access was denied); its view says why in words.
318
+ *
319
+ * @public
320
+ */
321
+ export declare const GrepUnreadable: Schema.Struct<{
322
+ readonly path: Schema.String;
323
+ readonly reason: Schema.Literals<readonly ["NotFound", "Exists", "IsDirectory", "NotDirectory", "NotEmpty", "Permission", "Invalid", "Io"]>;
324
+ }>;
325
+ export type GrepUnreadable = typeof GrepUnreadable.Type;
326
+ /**
327
+ * What `grep` found: the matching lines (with their context) in walk order,
328
+ * how many lines matched and in how many files, whether it stopped at the
329
+ * limit, how many files it skipped (binary, larger than `maxFileBytes`, or
330
+ * resolving outside the workspace), and the files it could not read
331
+ * (`unreadable`, empty in results stored before it was recorded). `timedOut`
332
+ * marks an incomplete ripgrep search (false in older results). Ripgrep counts
333
+ * only binary skips it reports; files pruned by its walk/size limit are not counted.
334
+ *
335
+ * @public
336
+ */
337
+ export declare const GrepResult: Schema.Struct<{
338
+ readonly pattern: Schema.String;
339
+ readonly path: Schema.String;
340
+ readonly lines: Schema.$Array<Schema.Struct<{
341
+ readonly path: Schema.String;
342
+ readonly line: Schema.Int;
343
+ readonly text: Schema.String;
344
+ readonly match: Schema.Boolean;
345
+ }>>;
346
+ readonly matches: Schema.Int;
347
+ readonly files: Schema.Int;
348
+ readonly truncated: Schema.Boolean;
349
+ readonly skipped: Schema.Int;
350
+ readonly unreadable: Schema.withDecodingDefaultKey<Schema.$Array<Schema.Struct<{
351
+ readonly path: Schema.String;
352
+ readonly reason: Schema.Literals<readonly ["NotFound", "Exists", "IsDirectory", "NotDirectory", "NotEmpty", "Permission", "Invalid", "Io"]>;
353
+ }>>, never>;
354
+ readonly timedOut: Schema.withDecodingDefaultKey<Schema.Boolean, never>;
355
+ }>;
356
+ export type GrepResult = typeof GrepResult.Type;
357
+ /**
358
+ * `bash`: the command, its timeout in seconds, and what to write to its standard input.
359
+ *
360
+ * @public
361
+ */
362
+ export declare const BashParams: Schema.Struct<{
363
+ readonly command: Schema.String;
364
+ readonly timeout: Schema.optionalKey<Schema.Int>;
365
+ readonly stdin: Schema.optionalKey<Schema.String>;
366
+ }>;
367
+ export type BashParams = typeof BashParams.Type;
368
+ /**
369
+ * How a command went: the tail of its output (stdout and stderr in the
370
+ * order they arrived), how it ended, and, when the output was longer than
371
+ * the tail, where the whole of it was saved (`fullOutput`, relative to the
372
+ * workspace root; null when nothing was saved). The file holds at most
373
+ * `maxFileBytes` of the output, its start: `fullOutputCut` when there was
374
+ * more, which was not saved.
375
+ *
376
+ * @public
377
+ */
378
+ export declare const BashToolResult: Schema.Struct<{
379
+ readonly command: Schema.String;
380
+ readonly output: Schema.String;
381
+ readonly exitCode: Schema.NullOr<Schema.Int>;
382
+ readonly signal: Schema.NullOr<Schema.String>;
383
+ readonly termination: Schema.Literals<readonly ["exit", "signal", "timeout", "interrupted"]>;
384
+ readonly truncated: Schema.Boolean;
385
+ readonly totalLines: Schema.Int;
386
+ readonly fullOutput: Schema.NullOr<Schema.String>;
387
+ readonly fullOutputCut: Schema.Boolean;
388
+ readonly durationMs: Schema.Number;
389
+ }>;
390
+ export type BashToolResult = typeof BashToolResult.Type;
391
+ /**
392
+ * The tools' names and schemas, for `onTool` subscriptions (a UI showing `edit` diffs, say).
393
+ *
394
+ * @public
395
+ */
396
+ export declare const workspaceToolSchemas: {
397
+ readonly read: {
398
+ readonly name: "read";
399
+ readonly parametersSchema: Schema.Struct<{
400
+ readonly path: Schema.String;
401
+ readonly offset: Schema.optionalKey<Schema.Int>;
402
+ readonly limit: Schema.optionalKey<Schema.Int>;
403
+ }>;
404
+ readonly successSchema: Schema.Union<readonly [Schema.TaggedStruct<"Text", {
405
+ readonly path: Schema.String;
406
+ readonly text: Schema.String;
407
+ readonly firstLine: Schema.Int;
408
+ readonly lastLine: Schema.Int;
409
+ readonly totalLines: Schema.Int;
410
+ readonly next: Schema.NullOr<Schema.Int>;
411
+ readonly clipped: Schema.Boolean;
412
+ readonly lossy: Schema.Boolean;
413
+ }>, Schema.TaggedStruct<"Binary", {
414
+ readonly path: Schema.String;
415
+ readonly bytes: Schema.Int;
416
+ readonly mediaType: Schema.NullOr<Schema.String>;
417
+ }>, Schema.TaggedStruct<"Image", {
418
+ readonly path: Schema.String;
419
+ readonly image: Schema.Struct<{
420
+ readonly type: Schema.Literal<"media">;
421
+ readonly mediaType: Schema.Literals<readonly ["image/png", "image/jpeg", "image/gif", "image/webp"]>;
422
+ readonly data: Schema.String;
423
+ readonly fingerprint: Schema.brand<Schema.String, "MediaFingerprint">;
424
+ readonly bytes: Schema.Int;
425
+ readonly name: Schema.optionalKey<Schema.String>;
426
+ readonly alt: Schema.optionalKey<Schema.String>;
427
+ }>;
428
+ /** Source dimensions and size when a resizer supplied the returned image; no original image bytes. */
429
+ readonly original: Schema.optionalKey<Schema.Struct<{
430
+ readonly mediaType: Schema.Literals<readonly ["image/png", "image/jpeg", "image/gif", "image/webp"]>;
431
+ readonly bytes: Schema.Int;
432
+ readonly width: Schema.Int;
433
+ readonly height: Schema.Int;
434
+ }>>;
435
+ }>, Schema.TaggedStruct<"ImageRejected", {
436
+ readonly path: Schema.String;
437
+ readonly mediaType: Schema.Literals<readonly ["image/png", "image/jpeg", "image/gif", "image/webp"]>;
438
+ readonly bytes: Schema.Int;
439
+ readonly reason: Schema.Literals<readonly ["Empty", "InvalidBase64", "UnsupportedType", "TooLarge", "TooManyPixels", "Unreadable", "TooMany", "TooLargeTogether"]>;
440
+ readonly message: Schema.String;
441
+ }>]>;
442
+ };
443
+ readonly write: {
444
+ readonly name: "write";
445
+ readonly parametersSchema: Schema.Struct<{
446
+ readonly path: Schema.String;
447
+ readonly content: Schema.String;
448
+ }>;
449
+ readonly successSchema: Schema.Struct<{
450
+ readonly path: Schema.String;
451
+ readonly bytes: Schema.Int;
452
+ readonly created: Schema.Boolean;
453
+ }>;
454
+ };
455
+ readonly edit: {
456
+ readonly name: "edit";
457
+ readonly parametersSchema: Schema.Struct<{
458
+ readonly path: Schema.String;
459
+ readonly edits: Schema.NonEmptyArray<Schema.Struct<{
460
+ readonly oldText: Schema.String;
461
+ readonly newText: Schema.String;
462
+ }>>;
463
+ }>;
464
+ readonly successSchema: Schema.Struct<{
465
+ readonly path: Schema.String;
466
+ readonly replaced: Schema.Int;
467
+ readonly normalized: Schema.Boolean;
468
+ readonly firstChangedLine: Schema.Int;
469
+ readonly diff: Schema.String;
470
+ }>;
471
+ };
472
+ readonly ls: {
473
+ readonly name: "ls";
474
+ readonly parametersSchema: Schema.Struct<{
475
+ readonly path: Schema.optionalKey<Schema.String>;
476
+ readonly limit: Schema.optionalKey<Schema.Int>;
477
+ }>;
478
+ readonly successSchema: Schema.Struct<{
479
+ readonly path: Schema.String;
480
+ readonly entries: Schema.$Array<Schema.Struct<{
481
+ readonly name: Schema.String;
482
+ readonly kind: Schema.Literals<readonly ["file", "directory", "symlink", "other"]>;
483
+ }>>;
484
+ readonly total: Schema.Int;
485
+ }>;
486
+ };
487
+ readonly find: {
488
+ readonly name: "find";
489
+ readonly parametersSchema: Schema.Struct<{
490
+ readonly pattern: Schema.String;
491
+ readonly path: Schema.optionalKey<Schema.String>;
492
+ readonly limit: Schema.optionalKey<Schema.Int>;
493
+ }>;
494
+ readonly successSchema: Schema.Struct<{
495
+ readonly pattern: Schema.String;
496
+ readonly path: Schema.String;
497
+ readonly paths: Schema.$Array<Schema.String>;
498
+ readonly truncated: Schema.Boolean;
499
+ }>;
500
+ };
501
+ readonly grep: {
502
+ readonly name: "grep";
503
+ readonly parametersSchema: Schema.Struct<{
504
+ readonly pattern: Schema.String;
505
+ readonly path: Schema.optionalKey<Schema.String>;
506
+ readonly glob: Schema.optionalKey<Schema.String>;
507
+ readonly ignoreCase: Schema.optionalKey<Schema.Boolean>;
508
+ readonly literal: Schema.optionalKey<Schema.Boolean>;
509
+ readonly context: Schema.optionalKey<Schema.Int>;
510
+ readonly limit: Schema.optionalKey<Schema.Int>;
511
+ }>;
512
+ readonly successSchema: Schema.Struct<{
513
+ readonly pattern: Schema.String;
514
+ readonly path: Schema.String;
515
+ readonly lines: Schema.$Array<Schema.Struct<{
516
+ readonly path: Schema.String;
517
+ readonly line: Schema.Int;
518
+ readonly text: Schema.String;
519
+ readonly match: Schema.Boolean;
520
+ }>>;
521
+ readonly matches: Schema.Int;
522
+ readonly files: Schema.Int;
523
+ readonly truncated: Schema.Boolean;
524
+ readonly skipped: Schema.Int;
525
+ readonly unreadable: Schema.withDecodingDefaultKey<Schema.$Array<Schema.Struct<{
526
+ readonly path: Schema.String;
527
+ readonly reason: Schema.Literals<readonly ["NotFound", "Exists", "IsDirectory", "NotDirectory", "NotEmpty", "Permission", "Invalid", "Io"]>;
528
+ }>>, never>;
529
+ readonly timedOut: Schema.withDecodingDefaultKey<Schema.Boolean, never>;
530
+ }>;
531
+ };
532
+ readonly bash: {
533
+ readonly name: "bash";
534
+ readonly parametersSchema: Schema.Struct<{
535
+ readonly command: Schema.String;
536
+ readonly timeout: Schema.optionalKey<Schema.Int>;
537
+ readonly stdin: Schema.optionalKey<Schema.String>;
538
+ }>;
539
+ readonly successSchema: Schema.Struct<{
540
+ readonly command: Schema.String;
541
+ readonly output: Schema.String;
542
+ readonly exitCode: Schema.NullOr<Schema.Int>;
543
+ readonly signal: Schema.NullOr<Schema.String>;
544
+ readonly termination: Schema.Literals<readonly ["exit", "signal", "timeout", "interrupted"]>;
545
+ readonly truncated: Schema.Boolean;
546
+ readonly totalLines: Schema.Int;
547
+ readonly fullOutput: Schema.NullOr<Schema.String>;
548
+ readonly fullOutputCut: Schema.Boolean;
549
+ readonly durationMs: Schema.Number;
550
+ }>;
551
+ };
552
+ };
@@ -0,0 +1,126 @@
1
+ import { Effect, Option, Schema } from "effect";
2
+ import { ImageResizeError } from "@xandreed/core";
3
+ import type { BashOptions, ImageFitTarget, ImageInput, Media } from "@xandreed/core";
4
+ import type { BashToolResult, EditResult, FindResult, GrepResult, LsResult, ReadResult, WorkspaceSkillName, WorkspaceToolName, WorkspaceToolsConfig, WriteResult } from "./workspace-tools.entity.js";
5
+ /** The skill each tool belongs to, by its short name. */
6
+ export declare const skillOfTool: Readonly<Record<WorkspaceToolName, WorkspaceSkillName>>;
7
+ /**
8
+ * The parameters `read`, `ls`, `find` and `grep` take under `config`: their
9
+ * `limit` goes up to the configured cap (`maxLines`, `lsEntries`,
10
+ * `findResults`, `grepMatches`), so the model is shown the real maximum and
11
+ * a larger one is refused rather than quietly lowered.
12
+ */
13
+ export declare const toolParameters: (config: WorkspaceToolsConfig) => {
14
+ read: Schema.Struct<{
15
+ readonly limit: Schema.optionalKey<Schema.Int>;
16
+ readonly path: Schema.String;
17
+ readonly offset: Schema.optionalKey<Schema.Int>;
18
+ }>;
19
+ ls: Schema.Struct<{
20
+ readonly limit: Schema.optionalKey<Schema.Int>;
21
+ readonly path: Schema.optionalKey<Schema.String>;
22
+ }>;
23
+ find: Schema.Struct<{
24
+ readonly limit: Schema.optionalKey<Schema.Int>;
25
+ readonly pattern: Schema.String;
26
+ readonly path: Schema.optionalKey<Schema.String>;
27
+ }>;
28
+ grep: Schema.Struct<{
29
+ readonly limit: Schema.optionalKey<Schema.Int>;
30
+ readonly pattern: Schema.String;
31
+ readonly path: Schema.optionalKey<Schema.String>;
32
+ readonly glob: Schema.optionalKey<Schema.String>;
33
+ readonly ignoreCase: Schema.optionalKey<Schema.Boolean>;
34
+ readonly literal: Schema.optionalKey<Schema.Boolean>;
35
+ readonly context: Schema.optionalKey<Schema.Int>;
36
+ }>;
37
+ };
38
+ /** What the model is told each tool does, with the configured limits in it. */
39
+ export declare const toolDescriptions: (config: WorkspaceToolsConfig, resizesImages?: boolean) => Readonly<Record<WorkspaceToolName, string>>;
40
+ /** The text of the `workspace.environment` section: where the workspace is and how the enabled tools behave there. */
41
+ export declare const environmentText: (root: string, config: WorkspaceToolsConfig, tools: ReadonlyArray<WorkspaceToolName>) => string;
42
+ /**
43
+ * The environment of a command the bash tool runs: the configured
44
+ * variables, the session's when `bashSessionEnv` is set, and the parent
45
+ * environment through the allowlist (or all of it with `bashInheritEnv`).
46
+ */
47
+ export declare const bashEnvironment: (config: WorkspaceToolsConfig, session: Option.Option<{
48
+ readonly sessionId: string;
49
+ readonly runId: string;
50
+ readonly workspace: string;
51
+ }>) => Pick<BashOptions, "env" | "inheritEnv">;
52
+ /**
53
+ * What `read` returns for a binary file (a NUL byte in its first 8 KB).
54
+ * With `readImages`, bytes that are a PNG, JPEG, GIF or WebP image (sniffed,
55
+ * whatever the name says) become an `Image` through `mediaFromBytes`, named
56
+ * by the path; an image it refuses (over `MEDIA_LIMITS.imageBytes`, over
57
+ * `MEDIA_LIMITS.maxPixels` a side, or a header without a size) is an
58
+ * `ImageRejected` note, without the bytes. Anything else is `Binary`, with
59
+ * `nameType`: the media type the name suggests, as the result carries it
60
+ * (`null` for none; the adapter reads it with `mediaTypeOf`).
61
+ */
62
+ type FitImage = (image: ImageInput, target: ImageFitTarget) => Effect.Effect<Uint8Array, ImageResizeError>;
63
+ export declare const binaryRead: (path: string, bytes: Uint8Array<ArrayBufferLike>, readImages: boolean, nameType: string | null, fit?: Option.Option<FitImage> | undefined, maxSide?: number | undefined) => Effect.Effect<{
64
+ readonly _tag: "Text";
65
+ readonly path: string;
66
+ readonly text: string;
67
+ readonly firstLine: number;
68
+ readonly lastLine: number;
69
+ readonly totalLines: number;
70
+ readonly next: number | null;
71
+ readonly clipped: boolean;
72
+ readonly lossy: boolean;
73
+ } | {
74
+ readonly _tag: "Binary";
75
+ readonly path: string;
76
+ readonly bytes: number;
77
+ readonly mediaType: string | null;
78
+ } | {
79
+ readonly _tag: "Image";
80
+ readonly path: string;
81
+ readonly image: {
82
+ readonly type: "media";
83
+ readonly mediaType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
84
+ readonly data: string;
85
+ readonly fingerprint: string & import("effect/Brand").Brand<"MediaFingerprint">;
86
+ readonly bytes: number;
87
+ readonly name?: string;
88
+ readonly alt?: string;
89
+ };
90
+ readonly original?: {
91
+ readonly mediaType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
92
+ readonly bytes: number;
93
+ readonly width: number;
94
+ readonly height: number;
95
+ };
96
+ } | {
97
+ readonly _tag: "ImageRejected";
98
+ readonly path: string;
99
+ readonly mediaType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
100
+ readonly bytes: number;
101
+ readonly reason: "Empty" | "InvalidBase64" | "UnsupportedType" | "TooLarge" | "TooManyPixels" | "Unreadable" | "TooMany" | "TooLargeTogether";
102
+ readonly message: string;
103
+ }, never, never>;
104
+ /**
105
+ * What the model can do about a file over `maxFileBytes`, which `read`
106
+ * refuses unread: with `readImages`, a file named as a PNG, JPEG, GIF or
107
+ * WebP image is told to read a smaller copy; any other to read parts of it.
108
+ */
109
+ export declare const fileTooLargeHint: (path: string, readImages: boolean) => string;
110
+ /** The images `read`'s view sends with its result: an `Image`'s, once. */
111
+ export declare const readMedia: (result: ReadResult) => ReadonlyArray<Media>;
112
+ export declare const renderRead: (result: ReadResult) => string;
113
+ export declare const compactRead: (result: ReadResult) => string;
114
+ export declare const renderWrite: (result: WriteResult) => string;
115
+ export declare const compactWrite: (result: WriteResult) => string;
116
+ export declare const renderEdit: (result: EditResult) => string;
117
+ export declare const compactEdit: (result: EditResult) => string;
118
+ export declare const renderLs: (result: LsResult) => string;
119
+ export declare const compactLs: (result: LsResult) => string;
120
+ export declare const renderFind: (result: FindResult, maxLines: number, maxBytes: number) => string;
121
+ export declare const compactFind: (result: FindResult) => string;
122
+ export declare const renderGrep: (result: GrepResult, withContext: boolean, maxLines: number, maxBytes: number) => string;
123
+ export declare const compactGrep: (result: GrepResult) => string;
124
+ export declare const renderBash: (result: BashToolResult) => string;
125
+ export declare const compactBash: (result: BashToolResult) => string;
126
+ export {};