clanka 0.7.2 → 0.7.4

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 (54) hide show
  1. package/dist/Acp.d.ts +10 -0
  2. package/dist/Acp.d.ts.map +1 -1
  3. package/dist/Acp.js +1 -2
  4. package/dist/Acp.js.map +1 -1
  5. package/dist/Agent.test.js +78 -0
  6. package/dist/Agent.test.js.map +1 -1
  7. package/dist/AgentExecutor.d.ts +1 -1
  8. package/dist/AgentTools.d.ts +4 -4
  9. package/dist/AgentTools.d.ts.map +1 -1
  10. package/dist/AgentTools.js +5 -2
  11. package/dist/AgentTools.js.map +1 -1
  12. package/dist/GlobalWebSocket.d.ts +15 -0
  13. package/dist/GlobalWebSocket.d.ts.map +1 -0
  14. package/dist/GlobalWebSocket.js +26 -0
  15. package/dist/GlobalWebSocket.js.map +1 -0
  16. package/dist/WebToMarkdown.d.ts.map +1 -1
  17. package/dist/WebToMarkdown.js +8 -4
  18. package/dist/WebToMarkdown.js.map +1 -1
  19. package/dist/bin/Effect-DdkIoNCD.mjs +5058 -0
  20. package/dist/bin/Effect-DdkIoNCD.mjs.map +1 -0
  21. package/dist/bin/{McpClient-D6vFD-wP.mjs → McpClient-CJ0Vugoi.mjs} +582 -2896
  22. package/dist/bin/{McpClient-D6vFD-wP.mjs.map → McpClient-CJ0Vugoi.mjs.map} +1 -1
  23. package/dist/bin/OutputFormatter-DN8OGwuK.mjs +575 -0
  24. package/dist/bin/OutputFormatter-DN8OGwuK.mjs.map +1 -0
  25. package/dist/bin/Schema-BALIXGp7.mjs +5475 -0
  26. package/dist/bin/Schema-BALIXGp7.mjs.map +1 -0
  27. package/dist/bin/{SemanticSearch-D9iZ_Mi9.mjs → SemanticSearch-O6PZBRfd.mjs} +147 -1160
  28. package/dist/bin/{SemanticSearch-D9iZ_Mi9.mjs.map → SemanticSearch-O6PZBRfd.mjs.map} +1 -1
  29. package/dist/bin/Stream-B5ebASRi.mjs +2090 -0
  30. package/dist/bin/Stream-B5ebASRi.mjs.map +1 -0
  31. package/dist/bin/cli.mjs +9629 -41429
  32. package/dist/bin/cli.mjs.map +1 -1
  33. package/dist/bin/index.min-CI3qqohw.mjs +3300 -0
  34. package/dist/bin/index.min-CI3qqohw.mjs.map +1 -0
  35. package/dist/bin/turndown.cjs-usmCKZ4b.mjs +15195 -0
  36. package/dist/bin/turndown.cjs-usmCKZ4b.mjs.map +1 -0
  37. package/dist/cli.js +9 -5
  38. package/dist/cli.js.map +1 -1
  39. package/dist/index.d.ts +4 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +4 -0
  42. package/dist/index.js.map +1 -1
  43. package/package.json +2 -4
  44. package/src/Acp.ts +1 -2
  45. package/src/Agent.test.ts +118 -0
  46. package/src/AgentTools.ts +12 -3
  47. package/src/GlobalWebSocket.ts +40 -0
  48. package/src/WebToMarkdown.ts +17 -7
  49. package/src/cli.ts +14 -5
  50. package/src/index.ts +5 -0
  51. package/dist/bin/Schema-D6y3R-At.mjs +0 -28728
  52. package/dist/bin/Schema-D6y3R-At.mjs.map +0 -1
  53. package/dist/bin/Undici-ChB4UBDa.mjs +0 -28
  54. package/dist/bin/Undici-ChB4UBDa.mjs.map +0 -1
@@ -0,0 +1,575 @@
1
+ import { $n as effect, As as identity, B as fnUntraced, Fn as fail, G as forkIn, It as scope, Xn as pretty$1, Y as gen, _t as onExit, ja as Service, rn as void_, u as asVoid, ys as isTagged } from "./Effect-DdkIoNCD.mjs";
2
+ import { Ct as unbounded, D as map, J as succeed, K as runIntoPubSub, Q as tap, S as fromPubSub, c as die, ct as makeUnsafe, r as catchIf } from "./Stream-B5ebASRi.mjs";
3
+ import os from "node:os";
4
+ import process from "node:process";
5
+ import tty from "node:tty";
6
+ //#region node_modules/.pnpm/chalk@6.0.0/node_modules/chalk/source/utilities.js
7
+ function stringReplaceAll(string, substring, postfix) {
8
+ let index = string.indexOf(substring);
9
+ if (index === -1) return string;
10
+ const substringLength = substring.length;
11
+ let endIndex = 0;
12
+ let returnValue = "";
13
+ do {
14
+ returnValue += string.slice(endIndex, index) + substring + postfix;
15
+ endIndex = index + substringLength;
16
+ index = string.indexOf(substring, endIndex);
17
+ } while (index !== -1);
18
+ returnValue += string.slice(endIndex);
19
+ return returnValue;
20
+ }
21
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
22
+ let endIndex = 0;
23
+ let returnValue = "";
24
+ do {
25
+ const isGotCR = string[index - 1] === "\r";
26
+ returnValue += string.slice(endIndex, isGotCR ? index - 1 : index) + prefix + (isGotCR ? "\r\n" : "\n") + postfix;
27
+ endIndex = index + 1;
28
+ index = string.indexOf("\n", endIndex);
29
+ } while (index !== -1);
30
+ returnValue += string.slice(endIndex);
31
+ return returnValue;
32
+ }
33
+ //#endregion
34
+ //#region node_modules/.pnpm/chalk@6.0.0/node_modules/chalk/source/vendor/ansi-styles/index.js
35
+ const ANSI_BACKGROUND_OFFSET = 10;
36
+ const ANSI_UNDERLINE_OFFSET = 20;
37
+ const wrapAnsi16 = (offset = 0) => (code) => `\u{1B}[${code + offset}m`;
38
+ const wrapAnsi256 = (offset = 0) => (code) => `\u{1B}[${38 + offset};5;${code}m`;
39
+ const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u{1B}[${38 + offset};2;${red};${green};${blue}m`;
40
+ const wrapUnderlineAnsi = (code) => `\u{1B}[58;5;${code < 90 ? code - 30 : code - 90 + 8}m`;
41
+ const styles$1 = {
42
+ modifier: {
43
+ reset: [0, 0],
44
+ bold: [1, 22],
45
+ dim: [2, 22],
46
+ italic: [3, 23],
47
+ underline: [4, 24],
48
+ underlineDouble: ["4:2", 24],
49
+ underlineCurly: ["4:3", 24],
50
+ underlineDotted: ["4:4", 24],
51
+ underlineDashed: ["4:5", 24],
52
+ overline: [53, 55],
53
+ inverse: [7, 27],
54
+ hidden: [8, 28],
55
+ strikethrough: [9, 29]
56
+ },
57
+ color: {
58
+ black: [30, 39],
59
+ red: [31, 39],
60
+ green: [32, 39],
61
+ yellow: [33, 39],
62
+ blue: [34, 39],
63
+ magenta: [35, 39],
64
+ cyan: [36, 39],
65
+ white: [37, 39],
66
+ blackBright: [90, 39],
67
+ gray: [90, 39],
68
+ grey: [90, 39],
69
+ redBright: [91, 39],
70
+ greenBright: [92, 39],
71
+ yellowBright: [93, 39],
72
+ blueBright: [94, 39],
73
+ magentaBright: [95, 39],
74
+ cyanBright: [96, 39],
75
+ whiteBright: [97, 39]
76
+ },
77
+ bgColor: {
78
+ bgBlack: [40, 49],
79
+ bgRed: [41, 49],
80
+ bgGreen: [42, 49],
81
+ bgYellow: [43, 49],
82
+ bgBlue: [44, 49],
83
+ bgMagenta: [45, 49],
84
+ bgCyan: [46, 49],
85
+ bgWhite: [47, 49],
86
+ bgBlackBright: [100, 49],
87
+ bgGray: [100, 49],
88
+ bgGrey: [100, 49],
89
+ bgRedBright: [101, 49],
90
+ bgGreenBright: [102, 49],
91
+ bgYellowBright: [103, 49],
92
+ bgBlueBright: [104, 49],
93
+ bgMagentaBright: [105, 49],
94
+ bgCyanBright: [106, 49],
95
+ bgWhiteBright: [107, 49]
96
+ },
97
+ underlineColor: {
98
+ underlineBlack: ["58;5;0", 59],
99
+ underlineRed: ["58;5;1", 59],
100
+ underlineGreen: ["58;5;2", 59],
101
+ underlineYellow: ["58;5;3", 59],
102
+ underlineBlue: ["58;5;4", 59],
103
+ underlineMagenta: ["58;5;5", 59],
104
+ underlineCyan: ["58;5;6", 59],
105
+ underlineWhite: ["58;5;7", 59],
106
+ underlineBlackBright: ["58;5;8", 59],
107
+ underlineGray: ["58;5;8", 59],
108
+ underlineGrey: ["58;5;8", 59],
109
+ underlineRedBright: ["58;5;9", 59],
110
+ underlineGreenBright: ["58;5;10", 59],
111
+ underlineYellowBright: ["58;5;11", 59],
112
+ underlineBlueBright: ["58;5;12", 59],
113
+ underlineMagentaBright: ["58;5;13", 59],
114
+ underlineCyanBright: ["58;5;14", 59],
115
+ underlineWhiteBright: ["58;5;15", 59]
116
+ }
117
+ };
118
+ const modifierNames = Object.keys(styles$1.modifier);
119
+ const foregroundColorNames = Object.keys(styles$1.color);
120
+ const backgroundColorNames = Object.keys(styles$1.bgColor);
121
+ const underlineColorNames = Object.keys(styles$1.underlineColor);
122
+ const colorNames = [...foregroundColorNames, ...backgroundColorNames];
123
+ function assembleStyles() {
124
+ const codes = new Map();
125
+ for (const [groupName, group] of Object.entries(styles$1)) {
126
+ for (const [styleName, style] of Object.entries(group)) {
127
+ styles$1[styleName] = {
128
+ open: `\u{1B}[${style[0]}m`,
129
+ close: `\u{1B}[${style[1]}m`
130
+ };
131
+ group[styleName] = styles$1[styleName];
132
+ codes.set(Number.parseInt(style[0], 10), style[1]);
133
+ }
134
+ Object.defineProperty(styles$1, groupName, {
135
+ value: group,
136
+ enumerable: false
137
+ });
138
+ }
139
+ Object.defineProperty(styles$1, "codes", {
140
+ value: codes,
141
+ enumerable: false
142
+ });
143
+ styles$1.color.close = "\x1B[39m";
144
+ styles$1.bgColor.close = "\x1B[49m";
145
+ styles$1.underlineColor.close = "\x1B[59m";
146
+ styles$1.color.ansi = wrapAnsi16();
147
+ styles$1.color.ansi256 = wrapAnsi256();
148
+ styles$1.color.ansi16m = wrapAnsi16m();
149
+ styles$1.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
150
+ styles$1.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
151
+ styles$1.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
152
+ styles$1.underlineColor.ansi = wrapUnderlineAnsi;
153
+ styles$1.underlineColor.ansi256 = wrapAnsi256(ANSI_UNDERLINE_OFFSET);
154
+ styles$1.underlineColor.ansi16m = wrapAnsi16m(ANSI_UNDERLINE_OFFSET);
155
+ Object.defineProperties(styles$1, {
156
+ rgbToAnsi256: {
157
+ value(red, green, blue) {
158
+ if (red === green && green === blue) {
159
+ if (red < 8) return 16;
160
+ if (red > 248) return 231;
161
+ return Math.round((red - 8) / 247 * 24) + 232;
162
+ }
163
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
164
+ },
165
+ enumerable: false
166
+ },
167
+ hexToRgb: {
168
+ value(hex) {
169
+ const matches = /[\da-f]{6}|[\da-f]{3}/i.exec(hex.toString(16));
170
+ if (!matches) return [
171
+ 0,
172
+ 0,
173
+ 0
174
+ ];
175
+ let [colorString] = matches;
176
+ if (colorString.length === 3) colorString = [...colorString].map((character) => character + character).join("");
177
+ const integer = Number.parseInt(colorString, 16);
178
+ return [
179
+ integer >> 16 & 255,
180
+ integer >> 8 & 255,
181
+ integer & 255
182
+ ];
183
+ },
184
+ enumerable: false
185
+ },
186
+ hexToAnsi256: {
187
+ value: (hex) => styles$1.rgbToAnsi256(...styles$1.hexToRgb(hex)),
188
+ enumerable: false
189
+ },
190
+ ansi256ToAnsi: {
191
+ value(code) {
192
+ if (code < 8) return 30 + code;
193
+ if (code < 16) return 90 + (code - 8);
194
+ let red;
195
+ let green;
196
+ let blue;
197
+ if (code >= 232) {
198
+ red = ((code - 232) * 10 + 8) / 255;
199
+ green = red;
200
+ blue = red;
201
+ } else {
202
+ code -= 16;
203
+ const remainder = code % 36;
204
+ red = Math.floor(code / 36) / 5;
205
+ green = Math.floor(remainder / 6) / 5;
206
+ blue = remainder % 6 / 5;
207
+ }
208
+ const value = Math.max(red, green, blue) * 2;
209
+ if (value === 0) return 30;
210
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
211
+ if (value === 2) result += 60;
212
+ return result;
213
+ },
214
+ enumerable: false
215
+ },
216
+ rgbToAnsi: {
217
+ value: (red, green, blue) => styles$1.ansi256ToAnsi(styles$1.rgbToAnsi256(red, green, blue)),
218
+ enumerable: false
219
+ },
220
+ hexToAnsi: {
221
+ value: (hex) => styles$1.ansi256ToAnsi(styles$1.hexToAnsi256(hex)),
222
+ enumerable: false
223
+ }
224
+ });
225
+ return styles$1;
226
+ }
227
+ const ansiStyles = assembleStyles();
228
+ //#endregion
229
+ //#region node_modules/.pnpm/chalk@6.0.0/node_modules/chalk/source/vendor/supports-color/index.js
230
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
231
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
232
+ const position = argv.indexOf(prefix + flag);
233
+ const terminatorPosition = argv.indexOf("--");
234
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
235
+ }
236
+ const { env } = process;
237
+ let flagForceColor;
238
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) flagForceColor = 0;
239
+ else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) flagForceColor = 1;
240
+ function hasNumericForceColor() {
241
+ return /^\d+$/.test(env.FORCE_COLOR);
242
+ }
243
+ function envForceColor() {
244
+ if (!("FORCE_COLOR" in env)) return;
245
+ if (env.FORCE_COLOR === "false") return 0;
246
+ if (env.FORCE_COLOR === "true" || env.FORCE_COLOR.length === 0) return 1;
247
+ if (!hasNumericForceColor()) return;
248
+ return Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
249
+ }
250
+ function translateLevel(level) {
251
+ if (level === 0) return false;
252
+ return {
253
+ level,
254
+ hasBasic: true,
255
+ has256: level >= 2,
256
+ has16m: level >= 3
257
+ };
258
+ }
259
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
260
+ const noFlagForceColor = envForceColor();
261
+ if (noFlagForceColor !== void 0) flagForceColor = noFlagForceColor;
262
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
263
+ if (forceColor === 0) return 0;
264
+ if (sniffFlags) {
265
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) return 3;
266
+ if (hasFlag("color=256")) return 2;
267
+ }
268
+ if (forceColor !== void 0 && hasNumericForceColor()) return forceColor;
269
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) return 1;
270
+ if (haveStream && !streamIsTTY && forceColor === void 0) return 0;
271
+ const min = forceColor || 0;
272
+ if (env.TERM === "dumb") return min;
273
+ if (process.platform === "win32") {
274
+ const osRelease = os.release().split(".");
275
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
276
+ return 1;
277
+ }
278
+ if ("CI" in env) {
279
+ if ([
280
+ "GITHUB_ACTIONS",
281
+ "GITEA_ACTIONS",
282
+ "CIRCLECI"
283
+ ].some((key) => key in env)) return 3;
284
+ if ([
285
+ "TRAVIS",
286
+ "APPVEYOR",
287
+ "GITLAB_CI",
288
+ "BUILDKITE",
289
+ "DRONE"
290
+ ].some((sign) => sign in env) || env.CI_NAME === "codeship") return 1;
291
+ return min;
292
+ }
293
+ if ("TEAMCITY_VERSION" in env) return /^(?:9\.0*[1-9]\d*\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
294
+ if (env.COLORTERM === "truecolor") return 3;
295
+ if (env.TERM === "xterm-kitty") return 3;
296
+ if (env.TERM === "xterm-ghostty") return 3;
297
+ if (env.TERM === "wezterm") return 3;
298
+ if ("TERM_PROGRAM" in env) {
299
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".", 1)[0], 10);
300
+ switch (env.TERM_PROGRAM) {
301
+ case "iTerm.app": return version >= 3 ? 3 : 2;
302
+ case "Apple_Terminal": return 2;
303
+ }
304
+ }
305
+ if (/-256(?:color)?$/i.test(env.TERM)) return 2;
306
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) return 1;
307
+ if ("COLORTERM" in env) return 1;
308
+ return min;
309
+ }
310
+ function createSupportsColor(stream, options = {}) {
311
+ return translateLevel(_supportsColor(stream, {
312
+ streamIsTTY: stream && stream.isTTY,
313
+ ...options
314
+ }));
315
+ }
316
+ const supportsColor = {
317
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
318
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
319
+ };
320
+ //#endregion
321
+ //#region node_modules/.pnpm/chalk@6.0.0/node_modules/chalk/source/index.js
322
+ const { stdout: stdoutColor, stderr: stderrColor } = supportsColor;
323
+ const GENERATOR = Symbol("GENERATOR");
324
+ const STYLER = Symbol("STYLER");
325
+ const IS_EMPTY = Symbol("IS_EMPTY");
326
+ const LEVEL = Symbol("LEVEL");
327
+ const styles = Object.create(null);
328
+ const assertValidLevel = (level) => {
329
+ if (!Number.isSafeInteger(level) || level < 0 || level > 3) throw new Error("The `level` should be an integer from 0 to 3");
330
+ };
331
+ const levelDescriptor = {
332
+ enumerable: true,
333
+ get() {
334
+ return this[LEVEL];
335
+ },
336
+ set(level) {
337
+ assertValidLevel(level);
338
+ this[LEVEL] = level;
339
+ }
340
+ };
341
+ const applyOptions = (object, options = {}) => {
342
+ if (options.level !== void 0) assertValidLevel(options.level);
343
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
344
+ object[LEVEL] = options.level === void 0 ? colorLevel : options.level;
345
+ };
346
+ const chalkFactory = (options) => {
347
+ const chalk = (...strings) => strings.join(" ");
348
+ applyOptions(chalk, options);
349
+ Object.setPrototypeOf(chalk, createChalk.prototype);
350
+ return chalk;
351
+ };
352
+ function createChalk(options) {
353
+ return chalkFactory(options);
354
+ }
355
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
356
+ for (const [styleName, style] of Object.entries(ansiStyles)) styles[styleName] = { get() {
357
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
358
+ Object.defineProperty(this, styleName, { value: builder });
359
+ return builder;
360
+ } };
361
+ styles.visible = { get() {
362
+ const builder = createBuilder(this, this[STYLER], true);
363
+ Object.defineProperty(this, "visible", { value: builder });
364
+ return builder;
365
+ } };
366
+ const createModelConverters = (model, type) => {
367
+ const style = ansiStyles[type];
368
+ if (model === "rgb") {
369
+ const ansi = (red, green, blue) => style.ansi(ansiStyles.rgbToAnsi(red, green, blue));
370
+ const ansi256 = (red, green, blue) => style.ansi256(ansiStyles.rgbToAnsi256(red, green, blue));
371
+ return [
372
+ ansi,
373
+ ansi,
374
+ ansi256,
375
+ style.ansi16m
376
+ ];
377
+ }
378
+ if (model === "hex") {
379
+ const ansi = (hex) => style.ansi(ansiStyles.hexToAnsi(hex));
380
+ const ansi256 = (hex) => style.ansi256(ansiStyles.hexToAnsi256(hex));
381
+ return [
382
+ ansi,
383
+ ansi,
384
+ ansi256,
385
+ (hex) => style.ansi16m(...ansiStyles.hexToRgb(hex))
386
+ ];
387
+ }
388
+ const ansi = (code) => style.ansi(ansiStyles.ansi256ToAnsi(code));
389
+ return [
390
+ ansi,
391
+ ansi,
392
+ style.ansi256,
393
+ style.ansi256
394
+ ];
395
+ };
396
+ for (const model of [
397
+ "rgb",
398
+ "hex",
399
+ "ansi256"
400
+ ]) {
401
+ const capitalizedModel = model[0].toUpperCase() + model.slice(1);
402
+ for (const [styleName, type] of [
403
+ [model, "color"],
404
+ ["bg" + capitalizedModel, "bgColor"],
405
+ ["underline" + capitalizedModel, "underlineColor"]
406
+ ]) {
407
+ const { close } = ansiStyles[type];
408
+ const converters = createModelConverters(model, type);
409
+ styles[styleName] = { get() {
410
+ const styleFunction = function(first, second, third) {
411
+ const open = converters[this.level](first, second, third);
412
+ return createBuilder(this, createStyler(open, close, this[STYLER]), this[IS_EMPTY]);
413
+ };
414
+ Object.defineProperty(this, styleName, { value: styleFunction });
415
+ return styleFunction;
416
+ } };
417
+ }
418
+ }
419
+ const proto = Object.defineProperties(() => {}, {
420
+ ...styles,
421
+ level: {
422
+ enumerable: true,
423
+ get() {
424
+ return this[GENERATOR].level;
425
+ },
426
+ set(level) {
427
+ this[GENERATOR].level = level;
428
+ }
429
+ }
430
+ });
431
+ const createStyler = (open, close, parent) => {
432
+ let openAll;
433
+ let closeAll;
434
+ if (parent === void 0) {
435
+ openAll = open;
436
+ closeAll = close;
437
+ } else {
438
+ openAll = parent.openAll + open;
439
+ closeAll = close + parent.closeAll;
440
+ }
441
+ return {
442
+ open,
443
+ close,
444
+ openAll,
445
+ closeAll,
446
+ parent
447
+ };
448
+ };
449
+ const createBuilder = (self, _styler, _isEmpty) => {
450
+ const builder = (...arguments_) => {
451
+ if (arguments_.length === 1) return applyStyle(builder, "" + arguments_[0]);
452
+ if (arguments_.length === 2) return applyStyle(builder, arguments_[0] + " " + arguments_[1]);
453
+ return applyStyle(builder, arguments_.join(" "));
454
+ };
455
+ Object.setPrototypeOf(builder, proto);
456
+ builder[GENERATOR] = self[GENERATOR] ?? self;
457
+ builder[STYLER] = _styler;
458
+ builder[IS_EMPTY] = _isEmpty;
459
+ return builder;
460
+ };
461
+ const applyStyle = (self, string) => {
462
+ if (self[GENERATOR][LEVEL] <= 0 || !string) return self[IS_EMPTY] ? "" : string;
463
+ let styler = self[STYLER];
464
+ if (styler === void 0) return string;
465
+ const { openAll, closeAll } = styler;
466
+ if (string.includes("\x1B")) while (styler !== void 0) {
467
+ string = stringReplaceAll(string, styler.close, styler.open);
468
+ styler = styler.parent;
469
+ }
470
+ const lfIndex = string.indexOf("\n");
471
+ if (lfIndex !== -1) string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
472
+ return openAll + string + closeAll;
473
+ };
474
+ Object.defineProperties(createChalk.prototype, {
475
+ ...styles,
476
+ level: levelDescriptor
477
+ });
478
+ const chalk = createChalk();
479
+ const chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
480
+ //#endregion
481
+ //#region src/OutputFormatter.ts
482
+ const pretty = (options) => {
483
+ const maxLines = typeof options?.outputTruncation === "number" ? options.outputTruncation : 20;
484
+ const truncate = options?.outputTruncation === true || typeof options?.outputTruncation === "number" ? (text) => {
485
+ const lines = text.split("\n");
486
+ if (lines.length > maxLines) return lines.slice(0, maxLines).join("\n") + `\n... (truncated, total ${lines.length} lines)`;
487
+ return text;
488
+ } : identity;
489
+ return (stream) => stream.pipe(map((output) => {
490
+ let prefix = "";
491
+ if (output._tag === "SubagentPart") {
492
+ prefix = chalk.magenta(`Subagent #${output.id}:`) + " ";
493
+ output = output.part;
494
+ }
495
+ switch (output._tag) {
496
+ case "AgentStart": return `${chalkAgentHeading(`${subagentIcon} Agent #${output.id} starting (${output.modelAndProvider})`)}\n\n${promptToString(output.prompt)}\n\n`;
497
+ case "SubagentStart": return `${chalkSubagentHeading(`${subagentIcon} Subagent #${output.id} starting (${output.modelAndProvider})`)}
498
+
499
+ ${chalk.dim(output.prompt)}\n\n`;
500
+ case "SubagentComplete": return `${chalkSubagentHeading(`${subagentIcon} Subagent #${output.id} complete`)}
501
+
502
+ ${output.summary}\n\n`;
503
+ case "ReasoningStart": return prefix + chalkReasoningHeading(`${thinkingIcon} Thinking:`) + " ";
504
+ case "ReasoningDelta": return output.delta;
505
+ case "ReasoningEnd": return "\n\n";
506
+ case "ScriptStart": return `${prefix}${chalkScriptHeading(`${scriptIcon} Executing script`)}\n\n`;
507
+ case "ScriptDelta": return chalk.dim(output.delta);
508
+ case "ScriptEnd": return "\n\n";
509
+ case "ScriptOutput": return `${prefix}${chalkScriptHeading(`${scriptIcon} Script output`)}\n\n${chalk.dim(truncate(output.output))}\n\n`;
510
+ case "ErrorRetry": return `${prefix}${chalk.red(`Error: ${output.error.reason._tag}. Retrying...`)}\n\n${chalk.dim(pretty$1(fail(output.error)))}\n\n`;
511
+ case "Usage": return `${prefix}${chalkInfoHeading(`${infoIcon} Usage:`)} ${numberFormat.format(output.contextTokens)} context / ${numberFormat.format(output.inputTokens)} input / ${numberFormat.format(output.outputTokens)} output\n\n`;
512
+ case "ExecuteOutputCapped": return `${prefix}${chalkInfoHeading(`${infoIcon} Output capped:`)} ${numberFormat.format(output.charsBefore)} chars reduced to ${numberFormat.format(output.charsAfter)}\n\n`;
513
+ case "CompactionStarted": return `${prefix}${chalkInfoHeading(`${infoIcon} Compacting context (${output.reason})...`)}\n\n`;
514
+ case "CompactionEnded": return `${prefix}${chalkInfoHeading(`${infoIcon} Context compacted (${output.reason}):`)} ~${numberFormat.format(output.tokensBefore)} tokens to ~${numberFormat.format(output.tokensAfter)}\n\n`;
515
+ }
516
+ }), catchIf((e) => isTagged(e, "AgentFinished"), (finished) => succeed(`\n${chalk.bold.green(`${doneIcon} Task complete:`)}\n\n${finished.summary}`), (e) => die(e)));
517
+ };
518
+ const promptToString = (prompt) => {
519
+ let textParts = [];
520
+ for (const message of prompt.content) {
521
+ if (message.role !== "user") continue;
522
+ let content = message.content;
523
+ for (const part of content) {
524
+ if (part.type !== "text") continue;
525
+ textParts.push(part.text);
526
+ }
527
+ }
528
+ return textParts.join("\n");
529
+ };
530
+ const numberFormat = new Intl.NumberFormat();
531
+ const chalkAgentHeading = chalk.bold.green;
532
+ const chalkScriptHeading = chalk.bold.blue;
533
+ const chalkSubagentHeading = chalk.bold.magenta;
534
+ const chalkReasoningHeading = chalk.bold.yellow;
535
+ const chalkInfoHeading = chalk.bold.cyan;
536
+ const scriptIcon = "\u{F0BC1}";
537
+ const subagentIcon = "\uEE0D ";
538
+ const thinkingIcon = "\u{F07F6}";
539
+ const doneIcon = "\uEAB2";
540
+ const infoIcon = "\uF05A";
541
+ var Muxer = class extends Service()("clanka/OutputFormatter/Muxer") {};
542
+ const layerMuxer = (formatter) => effect(Muxer, gen(function* () {
543
+ const scope$1 = yield* scope;
544
+ const output = yield* unbounded();
545
+ let agentCount = 0;
546
+ let currentAgentId = null;
547
+ const semaphore = makeUnsafe(1);
548
+ return Muxer.of({
549
+ add(stream) {
550
+ const id = ++agentCount;
551
+ return stream.pipe(tap(fnUntraced(function* (part_) {
552
+ if (currentAgentId === null || id !== currentAgentId) yield* semaphore.take(1);
553
+ switch ((part_._tag === "SubagentPart" ? part_.part : part_)._tag) {
554
+ case "ReasoningStart":
555
+ case "ScriptStart":
556
+ currentAgentId = id;
557
+ break;
558
+ case "ScriptDelta":
559
+ case "ReasoningDelta": break;
560
+ default: currentAgentId = null;
561
+ }
562
+ if (id !== currentAgentId) yield* semaphore.release(1);
563
+ })), formatter, runIntoPubSub(output), onExit(() => {
564
+ if (currentAgentId !== id) return void_;
565
+ currentAgentId = null;
566
+ return semaphore.release(1);
567
+ }), forkIn(scope$1), asVoid);
568
+ },
569
+ output: fromPubSub(output)
570
+ });
571
+ }));
572
+ //#endregion
573
+ export { Muxer, layerMuxer, pretty };
574
+
575
+ //# sourceMappingURL=OutputFormatter-DN8OGwuK.mjs.map