clanka 0.8.6 → 0.9.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.
- package/dist/Acp.d.ts.map +1 -1
- package/dist/Acp.js +9 -3
- package/dist/Acp.js.map +1 -1
- package/dist/Acp.test.js +72 -1
- package/dist/Acp.test.js.map +1 -1
- package/dist/AcpImage.test.js +1 -0
- package/dist/AcpImage.test.js.map +1 -1
- package/dist/Agent.d.ts +65 -8
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +481 -113
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +77 -4
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentCallerConfig.test.d.ts +2 -0
- package/dist/AgentCallerConfig.test.d.ts.map +1 -0
- package/dist/AgentCallerConfig.test.js +327 -0
- package/dist/AgentCallerConfig.test.js.map +1 -0
- package/dist/AgentExecutor.d.ts +254 -54
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +416 -99
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +201 -31
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentExecutorImage.test.js +2 -1
- package/dist/AgentExecutorImage.test.js.map +1 -1
- package/dist/AgentImage.test.js +5 -1
- package/dist/AgentImage.test.js.map +1 -1
- package/dist/AgentOutput.d.ts +54 -2
- package/dist/AgentOutput.d.ts.map +1 -1
- package/dist/AgentOutput.js +52 -0
- package/dist/AgentOutput.js.map +1 -1
- package/dist/AgentSkills.d.ts +22 -0
- package/dist/AgentSkills.d.ts.map +1 -1
- package/dist/AgentSkills.js +36 -0
- package/dist/AgentSkills.js.map +1 -1
- package/dist/AgentSkills.test.js +2 -0
- package/dist/AgentSkills.test.js.map +1 -1
- package/dist/AgentSubagents.test.d.ts +2 -0
- package/dist/AgentSubagents.test.d.ts.map +1 -0
- package/dist/AgentSubagents.test.js +452 -0
- package/dist/AgentSubagents.test.js.map +1 -0
- package/dist/AgentTools.d.ts +356 -14
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +213 -34
- package/dist/AgentTools.js.map +1 -1
- package/dist/OutputFormatter.d.ts.map +1 -1
- package/dist/OutputFormatter.js +16 -2
- package/dist/OutputFormatter.js.map +1 -1
- package/dist/ToolkitRenderer.d.ts.map +1 -1
- package/dist/ToolkitRenderer.js +6 -1
- package/dist/ToolkitRenderer.js.map +1 -1
- package/dist/bin/{Effect-rADALOOD.mjs → Effect-2jPlJ8eu.mjs} +43 -38
- package/dist/bin/Effect-2jPlJ8eu.mjs.map +1 -0
- package/dist/bin/{McpClient-NazR2OwL.mjs → McpClient-1W508adc.mjs} +3 -3
- package/dist/bin/{McpClient-NazR2OwL.mjs.map → McpClient-1W508adc.mjs.map} +1 -1
- package/dist/bin/{OutputFormatter-BVHbgF2b.mjs → OutputFormatter-DXXKo4E8.mjs} +16 -5
- package/dist/bin/{OutputFormatter-BVHbgF2b.mjs.map → OutputFormatter-DXXKo4E8.mjs.map} +1 -1
- package/dist/bin/{Schema-C7NXAOWA.mjs → Schema-D-7VuCiC.mjs} +2 -2
- package/dist/bin/{Schema-C7NXAOWA.mjs.map → Schema-D-7VuCiC.mjs.map} +1 -1
- package/dist/bin/{SemanticSearch-4Jes3jCl.mjs → SemanticSearch-Cb8aqvGv.mjs} +4 -4
- package/dist/bin/{SemanticSearch-4Jes3jCl.mjs.map → SemanticSearch-Cb8aqvGv.mjs.map} +1 -1
- package/dist/bin/{Stream-CSLA1_GD.mjs → Stream-DEu2tfCV.mjs} +12 -3
- package/dist/bin/Stream-DEu2tfCV.mjs.map +1 -0
- package/dist/bin/cli.mjs +914 -273
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +121 -2
- package/src/Acp.ts +10 -3
- package/src/AcpImage.test.ts +1 -0
- package/src/Agent.test.ts +100 -3
- package/src/Agent.ts +752 -142
- package/src/AgentCallerConfig.test.ts +514 -0
- package/src/AgentExecutor.test.ts +297 -37
- package/src/AgentExecutor.ts +707 -159
- package/src/AgentExecutorImage.test.ts +2 -1
- package/src/AgentImage.test.ts +11 -2
- package/src/AgentOutput.ts +74 -1
- package/src/AgentSkills.test.ts +2 -0
- package/src/AgentSkills.ts +43 -0
- package/src/AgentSubagents.test.ts +758 -0
- package/src/AgentTools.ts +376 -52
- package/src/OutputFormatter.ts +16 -2
- package/src/ToolkitRenderer.ts +7 -1
- package/dist/bin/Effect-rADALOOD.mjs.map +0 -1
- package/dist/bin/Stream-CSLA1_GD.mjs.map +0 -1
package/dist/bin/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --optimize-for-size
|
|
2
|
-
import { $ as interruptible, $a as
|
|
3
|
-
import { $ as
|
|
4
|
-
import { $ as check, $n as assignProperty$1, $t as PropertySignature, A as Option, An as fromInput$1, At as optionalKey, B as TaggedError$1, Bt as withDecodingDefaultKey, Ct as isPropertyNames, D as Null, Dn as InvalidValue$1, Dt as makeFilter, E as NonEmptyString$1, En as transformEffect, Et as make$
|
|
2
|
+
import { $ as interruptible, $a as Service, $i as compose, $s as or, $t as try_, A as effectify, Aa as getOrUndefined$2, An as jittered, Ao as orElse$1, Ar as succeed$4, As as structure, At as request, B as fn, Bn as nextBetween, Br as provide$2, Bs as isNotNull, Bt as service, C as catchTags, Co as isNone, Cr as fresh, Cs as symbol$1, Ct as orElseSucceed, D as contextWith, Da as failVoid, Dn as forever$1, Do as map$8, Dr as orDie$1, Dt as provideService, E as context, Ea as fail$2, En as exponential, Er as mock, Et as provideContext, Fa as succeed$2, Fr as addFinalizerExit, Ft as runSync, G as forkChild, Ga as minutes, Gn as TimeoutError, Go as strictEqual, Hr as MinimumLogLevel, Hs as isNotUndefined, Ht as sleep, I as filterOrFail, Ia as try_$1, Ir as close, J as fromOption, Ja as seconds, Jr as into, Jt as tap, K as forkIn, Ki as sync$1, Kn as UnknownError$1, Ko as Prototype, Kr as doneUnsafe, Ks as isObject, Kt as suspend, L as flatMap$1, La as format$1, Lt as scope, M as exit, Ma as isSuccess$1, Mn as spaced, Mo as some, Mr as unwrap$1, Ms as symbol$2, Mt as retry, N as fail$1, Na as map$6, Nn as toStep, No as toArray, Nr as Scope, Ns as hasProperty, Nt as runFork, On as fromStep, Oo as match$2, Or as provide$3, Ot as raceFirst, P as failCause, Pn as catchDone, Pr as addFinalizer$1, Pt as runForkWith, Q as interrupt, Qa as Reference, Qn as filterInterruptors, Qr as makeUnsafe$2, Qt as tryPromise, R as flatMapEager, Ra as fromInputUnsafe$1, Rr as make$43, Rs as isIterable, Rt as scoped, S as catchTag, Sa as reduce, So as getOrUndefined, Sr as empty$8, St as orDie, T as clockWith, Ta as headUnsafe, To as isSome, Tr as mergeAll, Tt as provide$1, U as forEach$1, Ua as max, Ur as TracerTimingEnabled, Us as isNull, Ut as succeed$1, V as fnUntraced, Va as isFinite, Vn as Done, Vr as CurrentLogAnnotations, Vs as isNotNullish, Vt as serviceOption, W as forever, Wa as millis, Wn as StackTrace, Wr as _await, Ws as isNullish, Wt as succeedNone, X as gen, Xi as DisablePropagation, Xn as done, Xr as isDoneUnsafe, Xs as isTagged, Xt as timeout, Y as fromResult, Ya as toMillis, Yo as PipeInspectableProto, Yr as isDone, Ys as isString, Yt as tapCause, Z as ignore, Za as zero, Zi as ParentSpan, Zn as fail$4, Zr as make$42, Zs as isUndefined, Zt as timeoutOrElse, _ as catchEager, _n as TaggedClass, _o as fromNullishOr, _r as build, _t as onError, a as andThen, aa as empty$5, ac as dual, ai as isFailure, an as useSpan, ao as getOrUndefinedUnsafe, as as withFiber$1, at as logWarning, ba as match$3, bo as getOrNull, br as effectContext, bs as symbolRedactable, bt as onInterrupt, c as as, ca as findLast, cc as memoize, ci as void_$1, cn as whileLoop, co as makeUnsafe$3, cs as getStackTraceLimit, ct as mapBothEager, d as cached, da as headNonEmpty, di as LogToStderr$1, dn as withParentSpan, do as exists, dr as makeFailReason, ds as Class, ea as has, ec as constFalse, ei as die$1, en as undefined_, eo as add, er as findErrorOption, et as isEffect, f as cachedWithTTL, fa as isArrayNonEmpty, fn as withSpan$1, fo as filter$1, fs as NodeInspectSymbol, ft as match$4, ga as last$1, gr as squash, gt as never, h as catchCauseIf, ha as join$1, hn as equalBatchKeys, hr as reasonAnnotations, ht as matchEffect, i as all$1, ia as appendAll, in as updateService, io as getOrUndefined$1, ir as interruptors, it as logInfo, j as ensuring, ja as isFailure$1, ji as forkUnsafe, jn as min, jo as orElseSome, jr as succeedContext, jt as result, k as die, kn as isSchedule, ko as none, kr as provideMerge, kt as repeat, l as asSome, ln as withFiber, lo as merge$2, lr as isTimeoutError, ls as setStackTraceLimit, lt as mapEager, m as catchCause, ma as isReadonlyArrayNonEmpty, mn as zipWith, mo as flatMapNullishOr, mr as pretty, ms as format, mt as matchCauseEffect, na as Array$1, nc as constUndefined, ni as failCause$1, nn as uninterruptibleMask, no as get$2, nr as hasInterrupts, nt as logError, o as annotateCurrentSpan, oa as findFirst, oc as flow, oi as isSuccess, on as void_, oo as getUnsafe, or as isDieReason, ot as makeSpanScoped, p as callback, pa as isCanonicalArrayIndex, pc as pipeArguments, pn as yieldNow, po as flatMap$2, q as forkScoped, qn as annotate$1, qt as sync, r as addFinalizer, rc as constVoid, ri as interrupt$1, rn as updateContext, ro as getOption, rr as hasInterruptsOnly, rt as logFatal, s as annotateLogs, sa as findFirstIndex, sc as identity, si as succeed$3, so as make$41, sr as isFailReason, ss as assignProperty, st as map$5, t as acquireRelease, ta as toPredicate, tc as constTrue, ti as fail$3, tn as uninterruptible, to as empty$6, tr as fromReasons, tt as logDebug, u as asVoid, ua as fromIterable, uc as pipe, ui as ConsoleRef, uo as all, ur as makeDieReason, us as BaseProto, ut as mapError, v as catchFilter, vo as fromUndefinedOr, vr as buildWithScope, vt as onExit, w as catch_, wa as empty$7, wr as merge$3, wt as promise, x as catchReason, xa as of, xo as getOrThrow, xt as option$1, y as catchIf, ya as map$7, yo as getOrElse, yr as effect, ys as redact$1, za as infinity, zn as Random$1, zr as makeUnsafe$1 } from "./Effect-2jPlJ8eu.mjs";
|
|
3
|
+
import { $ as takeUntil, A as mapArrayEffect, At as makeUnsafe$4, B as provideService$1, Bt as toLowerCase, Ct as shutdownUnsafe, D as isStream, Dt as make$44, E as fromReadableStream, F as mkString, Ft as interruptAllAs, G as runForEach, H as runCollect, Ht as round, I as onEnd, J as runLast, K as runForEachArray, L as orDie$2, Lt as join$2, M as mapError$1, Mt as getCurrent, N as merge$4, Nt as interrupt$2, O as map$9, Ot as set$1, P as mergeAll$1, Pt as interruptAll, Q as take$1, R as pipeThroughChannel, Rt as runIn, S as fromIterable$1, St as poll, T as fromQueue, Tt as unbounded, Ut as normalizeNonEmpty, V as run$4, Vt as parse$1, W as runFold, X as succeed$5, Y as splitLines, Z as suspend$1, _ as flattenIterable, _t as make$45, a as catchTags$1, at as mapDone, b as fromChannel$1, bt as offerAllUnsafe, c as die$2, ct as unwrap$2, d as ensuring$1, dt as bounded, et as tap$1, f as fail$5, ft as end, g as flatMap$3, gt as failCauseUnsafe, h as filterMap, ht as failCause$2, i as catchReason$1, it as map$10, j as mapEffect$1, jt as await_, k as mapArray, kt as update, l as drop, lt as make$46, m as filter$2, mt as fail$6, n as callback$1, nt as unwrap$3, o as catch_$1, ot as pipeTo, p as failCause$3, pt as endUnsafe, rt as fromTransform$1, s as decodeText, st as toTransform, t as broadcast, tt as transduce, u as empty$9, ut as makeUnsafe$5, vt as offer, w as fromPull, wt as take, x as fromEffect, xt as offerUnsafe, yt as offerAll, z as provideContext$1, zt as camelToSnake } from "./Stream-DEu2tfCV.mjs";
|
|
4
|
+
import { $ as check, $n as assignProperty$1, $t as PropertySignature, A as Option, An as fromInput$1, At as optionalKey, B as TaggedError$1, Bt as withDecodingDefaultKey, Ct as isPropertyNames, D as Null, Dn as InvalidValue$1, Dt as makeFilter, E as NonEmptyString$1, En as transformEffect, Et as make$48, F as SchemaError, Fn as decode$4, Ft as toEncoded$1, G as URLFromString, Gn as stringOrRedacted, Gt as decodeEffect$1, H as TrueLiterals, Hn as isRedacted, Ht as omit, I as String$5, In as encode, It as toJsonSchemaDocument, J as UndefinedOr, Jn as EncodingError, Jt as Arrays, K as Uint8Array$2, Kn as Clock, Kt as decodeUnknownEffect, L as Struct, Ln as formatIso, Lt as toType, M as OptionFromOptional, Mn as toString, Mt as tag, N as Record, Nn as empty$11, Nt as toCodecJson, O as NullOr, On as Pointer, Ot as mutable, P as Redacted$1, Pn as fromSetCookie, Pt as toCodecStringTree, Qn as taggedEnum, Qt as Objects, R as StructWithRest, Rt as withConstructorDefault, S as MutableJson, St as isPattern, T as NonEmptyArray, Tt as isSchemaError, U as Tuple, Un as make$47, Ut as getReferenceKey, V as TaggedUnion, W as URL$1, Wn as value, Wt as _is, X as Unknown, Xn as TaggedClass$1, Xt as FilterGroup, Y as Union, Yn as Error$1, Yt as Filter, Z as Void, Zn as TaggedError, Zt as Literal$1, _ as Int$1, _n as Transformation, _t as isMaxCodePoints, a as BooleanLiterals, an as isOptional, at as decodeUnknownOption, b as Literal, bn as transformEffect$1, bt as isMinCodePoints, cn as optionalKey$1, ct as encodeTo, d as Defect, dn as resolveDescription, dt as instanceOf, en as Suspend, er as makeEquivalence, et as declare, f as Duration, fn as resolveIdentifier, ft as is, g as Finite, gn as unknown, gt as isLessThanOrEqualTo, h as FalseLiterals, hn as toType$1, ht as isInt, in as isNever, it as decodeUnknownEffect$1, jn as setAll$1, jt as suspend$2, k as Number$2, kn as empty$10, kt as optional$2, ln as replaceChecks, lt as encodeUnknownEffect, m as Exit, mn as toEncoded, mt as isGreaterThanOrEqualTo, n as ArraySchema, nn as applyToSelfOrLastLinkEncoding, nt as decodeSync, o as Class$1, on as mapOrSame, ot as decodeUnknownSync, p as Error$2, pn as string, pt as isFinite$1, q as Uint8ArrayFromBase64, qt as encodeEffect, r as Boolean$4, rn as decodeTo, rt as decodeTo$1, s as DateTimeUtc, sn as null_, st as encodeEffect$1, t as Any, tn as Union$1, tr as map$11, tt as decodeEffect, u as DateTimeUtcFromString, un as resolveAt, ut as fromJsonString, v as Json, vn as passthrough$1, vt as isMaxLength, w as Never, wn as passthrough, wt as isSchema, x as Literals$2, xn as transformOptional, xt as isMinLength, y as JsonObject$1, yn as transform$3, yt as isMaxProperties, z as TaggedClass$2, zn as fromDateUnsafe, zt as withDecodingDefault } from "./Schema-D-7VuCiC.mjs";
|
|
5
5
|
import * as Http from "node:http";
|
|
6
6
|
import * as Https from "node:https";
|
|
7
7
|
import { PassThrough, Readable, Writable } from "node:stream";
|
|
@@ -15,6 +15,7 @@ import * as NodeUrl from "node:url";
|
|
|
15
15
|
import * as readline from "node:readline";
|
|
16
16
|
import * as NodeConsole from "node:console";
|
|
17
17
|
import * as NodeVm from "node:vm";
|
|
18
|
+
import { Worker } from "node:worker_threads";
|
|
18
19
|
//#region \0rolldown/runtime.js
|
|
19
20
|
var __create = Object.create;
|
|
20
21
|
var __defProp = Object.defineProperty;
|
|
@@ -574,8 +575,8 @@ const redact = dual(2, (self, key) => {
|
|
|
574
575
|
const modify = (key) => {
|
|
575
576
|
if (typeof key === "string") {
|
|
576
577
|
const k = key.toLowerCase();
|
|
577
|
-
if (k in self) out[k] = make$
|
|
578
|
-
} else for (const name in self) if (name.search(key) !== -1) out[name] = make$
|
|
578
|
+
if (k in self) out[k] = make$47(self[k]);
|
|
579
|
+
} else for (const name in self) if (name.search(key) !== -1) out[name] = make$47(self[name]);
|
|
579
580
|
};
|
|
580
581
|
if (Array.isArray(key)) for (let i = 0; i < key.length; i++) modify(key[i]);
|
|
581
582
|
else modify(key);
|
|
@@ -859,7 +860,7 @@ const Int = (options) => {
|
|
|
859
860
|
});
|
|
860
861
|
};
|
|
861
862
|
const map$4 = dual(2, (self, f) => flatMap(self, (a) => succeed(f(a))));
|
|
862
|
-
const Password = (options) => basePrompt(options, "password").pipe(map$4(make$
|
|
863
|
+
const Password = (options) => basePrompt(options, "password").pipe(map$4(make$47));
|
|
863
864
|
const run$3 = fnUntraced(function* (self) {
|
|
864
865
|
const terminal = yield* Terminal;
|
|
865
866
|
const input = yield* cached(terminal.readInput);
|
|
@@ -2176,7 +2177,7 @@ const Proto$13 = {
|
|
|
2176
2177
|
return pipeArguments(this, arguments);
|
|
2177
2178
|
}
|
|
2178
2179
|
};
|
|
2179
|
-
function makeWith$
|
|
2180
|
+
function makeWith$3(method, url, urlParams, hash, headers, body) {
|
|
2180
2181
|
const self = Object.create(Proto$13);
|
|
2181
2182
|
self.method = method;
|
|
2182
2183
|
self.url = url;
|
|
@@ -2186,7 +2187,7 @@ function makeWith$2(method, url, urlParams, hash, headers, body) {
|
|
|
2186
2187
|
self.body = body;
|
|
2187
2188
|
return self;
|
|
2188
2189
|
}
|
|
2189
|
-
const empty$2 = makeWith$
|
|
2190
|
+
const empty$2 = makeWith$3("GET", "", empty$10, none(), empty$4, empty$3);
|
|
2190
2191
|
const make$33 = (method) => (url, options) => modify(empty$2, {
|
|
2191
2192
|
method,
|
|
2192
2193
|
url,
|
|
@@ -2205,36 +2206,36 @@ const modify = dual(2, (self, options) => {
|
|
|
2205
2206
|
if (options.acceptJson) result = acceptJson(result);
|
|
2206
2207
|
return result;
|
|
2207
2208
|
});
|
|
2208
|
-
const setMethod = dual(2, (self, method) => makeWith$
|
|
2209
|
-
const setHeader = dual(3, (self, key, value) => makeWith$
|
|
2210
|
-
const setHeaders = dual(2, (self, input) => makeWith$
|
|
2211
|
-
const updateHeaders = dual(2, (self, f) => makeWith$
|
|
2209
|
+
const setMethod = dual(2, (self, method) => makeWith$3(method, self.url, self.urlParams, self.hash, self.headers, self.body));
|
|
2210
|
+
const setHeader = dual(3, (self, key, value) => makeWith$3(self.method, self.url, self.urlParams, self.hash, set(self.headers, key, value), self.body));
|
|
2211
|
+
const setHeaders = dual(2, (self, input) => makeWith$3(self.method, self.url, self.urlParams, self.hash, setAll(self.headers, input), self.body));
|
|
2212
|
+
const updateHeaders = dual(2, (self, f) => makeWith$3(self.method, self.url, self.urlParams, self.hash, f(self.headers), self.body));
|
|
2212
2213
|
const removeHeader = dual(2, (self, key) => updateHeaders(self, remove$1(key)));
|
|
2213
2214
|
const bearerToken = dual(2, (self, token) => setHeader(self, "Authorization", `Bearer ${stringOrRedacted(token)}`));
|
|
2214
2215
|
const accept = dual(2, (self, mediaType) => setHeader(self, "Accept", mediaType));
|
|
2215
2216
|
const acceptJson = accept("application/json");
|
|
2216
2217
|
const setUrl = dual(2, (self, url) => {
|
|
2217
|
-
if (typeof url === "string") return makeWith$
|
|
2218
|
+
if (typeof url === "string") return makeWith$3(self.method, url, self.urlParams, self.hash, self.headers, self.body);
|
|
2218
2219
|
const clone = new URL(url.toString());
|
|
2219
2220
|
const urlParams = fromInput$1(clone.searchParams);
|
|
2220
2221
|
const hash = fromNullishOr(clone.hash === "" ? void 0 : clone.hash.slice(1));
|
|
2221
2222
|
clone.search = "";
|
|
2222
2223
|
clone.hash = "";
|
|
2223
|
-
return makeWith$
|
|
2224
|
+
return makeWith$3(self.method, clone.toString(), urlParams, hash, self.headers, self.body);
|
|
2224
2225
|
});
|
|
2225
2226
|
const prependUrl = dual(2, (self, path) => {
|
|
2226
2227
|
if (path === "") return self;
|
|
2227
|
-
return makeWith$
|
|
2228
|
+
return makeWith$3(self.method, joinSegments(path, self.url), self.urlParams, self.hash, self.headers, self.body);
|
|
2228
2229
|
});
|
|
2229
2230
|
const joinSegments = (first, second) => {
|
|
2230
2231
|
const endsWithSlash = first.endsWith("/");
|
|
2231
2232
|
const startsWithSlash = second.startsWith("/");
|
|
2232
2233
|
return endsWithSlash && startsWithSlash ? first + second.slice(1) : !endsWithSlash && !startsWithSlash ? first + "/" + second : first + second;
|
|
2233
2234
|
};
|
|
2234
|
-
const setUrlParams = dual(2, (self, input) => makeWith$
|
|
2235
|
-
const setHash = dual(2, (self, hash) => makeWith$
|
|
2235
|
+
const setUrlParams = dual(2, (self, input) => makeWith$3(self.method, self.url, setAll$1(self.urlParams, input), self.hash, self.headers, self.body));
|
|
2236
|
+
const setHash = dual(2, (self, hash) => makeWith$3(self.method, self.url, self.urlParams, some(hash), self.headers, self.body));
|
|
2236
2237
|
const setBody = dual(2, (self, body) => {
|
|
2237
|
-
return makeWith$
|
|
2238
|
+
return makeWith$3(self.method, self.url, self.urlParams, self.hash, updateHeaders$1(self.headers, body), body);
|
|
2238
2239
|
});
|
|
2239
2240
|
const bodyJsonUnsafe = dual(2, (self, body) => setBody(self, jsonUnsafe(body)));
|
|
2240
2241
|
const bodyUrlParams = dual(2, (self, input) => setBody(self, urlParams(fromInput$1(input))));
|
|
@@ -2424,10 +2425,10 @@ const addHeaderAttributes = (span, phase, headers, filter, redactedNames) => {
|
|
|
2424
2425
|
const TypeId$20 = "~effect/http/HttpClient";
|
|
2425
2426
|
const isHttpClient = (u) => hasProperty(u, TypeId$20);
|
|
2426
2427
|
const HttpClient = Service("effect/HttpClient");
|
|
2427
|
-
const transform$2 = dual(2, (self, f) => makeWith$
|
|
2428
|
-
const transformResponse = dual(2, (self, f) => makeWith$
|
|
2428
|
+
const transform$2 = dual(2, (self, f) => makeWith$2(flatMap$1((request) => f(self.postprocess(succeed$1(request)), request)), self.preprocess));
|
|
2429
|
+
const transformResponse = dual(2, (self, f) => makeWith$2((request) => f(self.postprocess(request)), self.preprocess));
|
|
2429
2430
|
const filterStatusOk = transformResponse(flatMap$1(filterStatusOk$1));
|
|
2430
|
-
const makeWith$
|
|
2431
|
+
const makeWith$2 = (postprocess, preprocess) => {
|
|
2431
2432
|
const self = Object.create(Proto$12);
|
|
2432
2433
|
self.preprocess = preprocess;
|
|
2433
2434
|
self.postprocess = postprocess;
|
|
@@ -2449,7 +2450,7 @@ const Proto$12 = {
|
|
|
2449
2450
|
return this.execute(make$33(fullMethod)(url, options));
|
|
2450
2451
|
}]))
|
|
2451
2452
|
};
|
|
2452
|
-
const make$32 = (f) => makeWith$
|
|
2453
|
+
const make$32 = (f) => makeWith$2((effect) => flatMap$1(effect, (request) => withFiber((fiber) => {
|
|
2453
2454
|
const scopedController = scopedRequests.get(request);
|
|
2454
2455
|
const controller = scopedController ?? new AbortController();
|
|
2455
2456
|
const urlResult = make$34(request.url, request.urlParams, getOrUndefined(request.hash));
|
|
@@ -2512,8 +2513,8 @@ const endSpanWithStatusError = (fiber, span, request, response) => {
|
|
|
2512
2513
|
}
|
|
2513
2514
|
span.end(fiber.getRef(TracerTimingEnabled) ? fiber.getRef(Clock).currentTimeNanosUnsafe() : BigInt(0), exit);
|
|
2514
2515
|
};
|
|
2515
|
-
const mapRequest = dual(2, (self, f) => makeWith$
|
|
2516
|
-
const mapRequestEffect = dual(2, (self, f) => makeWith$
|
|
2516
|
+
const mapRequest = dual(2, (self, f) => makeWith$2(self.postprocess, (request) => map$5(self.preprocess(request), f)));
|
|
2517
|
+
const mapRequestEffect = dual(2, (self, f) => makeWith$2(self.postprocess, (request) => flatMap$1(self.preprocess(request), f)));
|
|
2517
2518
|
const retryTransient = dual(2, (self, options) => {
|
|
2518
2519
|
const isOnlySchedule = isSchedule(options);
|
|
2519
2520
|
const retryOn = isOnlySchedule ? "errors-and-responses" : options.retryOn ?? "errors-and-responses";
|
|
@@ -2547,7 +2548,7 @@ const withScope = (self) => transform$2(self, (effect, request) => {
|
|
|
2547
2548
|
scopedRequests.set(request, controller);
|
|
2548
2549
|
return andThen(addFinalizer(() => sync(() => controller.abort())), effect);
|
|
2549
2550
|
});
|
|
2550
|
-
const followRedirects = dual((args) => isHttpClient(args[0]), (self, maxRedirects) => makeWith$
|
|
2551
|
+
const followRedirects = dual((args) => isHttpClient(args[0]), (self, maxRedirects) => makeWith$2((request) => {
|
|
2551
2552
|
const loop = (request, redirects) => suspend(() => {
|
|
2552
2553
|
let currentRequest;
|
|
2553
2554
|
return flatMap$1(self.postprocess(map$5(request, (request) => {
|
|
@@ -2775,7 +2776,7 @@ const toArrayBuffer = (readable, options) => {
|
|
|
2775
2776
|
const readableToPullUnsafe = (options) => {
|
|
2776
2777
|
const readable = options.readable;
|
|
2777
2778
|
const closeOnDone = options.closeOnDone ?? true;
|
|
2778
|
-
const exit = options.exit ?? make$
|
|
2779
|
+
const exit = options.exit ?? make$44(void 0);
|
|
2779
2780
|
const latch = options.latch ?? makeUnsafe$4(false);
|
|
2780
2781
|
function onReadable() {
|
|
2781
2782
|
latch.openUnsafe();
|
|
@@ -4369,7 +4370,7 @@ const toConfigCursorAST = memoize((root) => {
|
|
|
4369
4370
|
function schema$1(codec, path) {
|
|
4370
4371
|
const codecStringTree = toCodecStringTree(codec);
|
|
4371
4372
|
const encodedAst = toEncoded(codecStringTree.ast);
|
|
4372
|
-
const decodeCursor = decodeUnknownEffect(make$
|
|
4373
|
+
const decodeCursor = decodeUnknownEffect(make$48(toConfigCursorAST(codecStringTree.ast)));
|
|
4373
4374
|
const localPath = typeof path === "string" ? [path] : path ?? [];
|
|
4374
4375
|
return make$29((provider, pathPrefix) => {
|
|
4375
4376
|
const fullPath = [...pathPrefix, ...localPath];
|
|
@@ -7963,7 +7964,7 @@ const layer$11 = layer$12;
|
|
|
7963
7964
|
const make$22 = fnUntraced(function* (shouldQuit = defaultShouldQuit) {
|
|
7964
7965
|
const stdin = process.stdin;
|
|
7965
7966
|
const stdout = process.stdout;
|
|
7966
|
-
const lines = yield* make$
|
|
7967
|
+
const lines = yield* make$45();
|
|
7967
7968
|
let inputEnded = stdin.readableEnded;
|
|
7968
7969
|
let readlineActive = false;
|
|
7969
7970
|
const onStdinEnd = () => {
|
|
@@ -8006,7 +8007,7 @@ const make$22 = fnUntraced(function* (shouldQuit = defaultShouldQuit) {
|
|
|
8006
8007
|
const columns = sync(() => stdout.columns ?? 0);
|
|
8007
8008
|
const rows = sync(() => stdout.rows ?? 0);
|
|
8008
8009
|
const readInput = gen(function* () {
|
|
8009
|
-
const queue = yield* make$
|
|
8010
|
+
const queue = yield* make$45();
|
|
8010
8011
|
const handleKeypress = (s, k) => {
|
|
8011
8012
|
const userInput = {
|
|
8012
8013
|
input: fromUndefinedOr(s),
|
|
@@ -9471,7 +9472,7 @@ function toCodec(schema) {
|
|
|
9471
9472
|
const encoded = toEncoded(jsonCodec.ast);
|
|
9472
9473
|
const from = transform(encoded);
|
|
9473
9474
|
if (from === encoded) return jsonCodec.ast === schema.ast ? schema : jsonCodec;
|
|
9474
|
-
return make$
|
|
9475
|
+
return make$48(decodeTo(from, jsonCodec.ast, passthrough$1()));
|
|
9475
9476
|
}
|
|
9476
9477
|
function transform(root) {
|
|
9477
9478
|
let cache;
|
|
@@ -10108,7 +10109,7 @@ const Proto$2 = {
|
|
|
10108
10109
|
})));
|
|
10109
10110
|
}
|
|
10110
10111
|
const decodedParams = decodedParamsResult.success;
|
|
10111
|
-
const queue = yield* make$
|
|
10112
|
+
const queue = yield* make$45();
|
|
10112
10113
|
const context = {
|
|
10113
10114
|
toolCallId,
|
|
10114
10115
|
preliminary: (result) => asVoid(offer(queue, {
|
|
@@ -10165,16 +10166,16 @@ const Proto$2 = {
|
|
|
10165
10166
|
return gen({ self: this }, function* () {
|
|
10166
10167
|
const services = yield* context();
|
|
10167
10168
|
const handlers = isEffect(build) ? yield* build : build;
|
|
10168
|
-
const context$
|
|
10169
|
+
const context$2 = new Map();
|
|
10169
10170
|
for (const [name, handler] of Object.entries(handlers)) {
|
|
10170
10171
|
const tool = Object.hasOwn(this.tools, name) ? this.tools[name] : void 0;
|
|
10171
|
-
if (tool !== void 0) context$
|
|
10172
|
+
if (tool !== void 0) context$2.set(tool.id, {
|
|
10172
10173
|
name,
|
|
10173
10174
|
handler,
|
|
10174
10175
|
context: services
|
|
10175
10176
|
});
|
|
10176
10177
|
}
|
|
10177
|
-
return makeUnsafe$3(context$
|
|
10178
|
+
return makeUnsafe$3(context$2);
|
|
10178
10179
|
});
|
|
10179
10180
|
},
|
|
10180
10181
|
toLayer(build) {
|
|
@@ -10578,11 +10579,11 @@ const make$13 = fnUntraced(function* (params) {
|
|
|
10578
10579
|
return void_;
|
|
10579
10580
|
}) : identity)));
|
|
10580
10581
|
}
|
|
10581
|
-
const queue = yield* make$
|
|
10582
|
+
const queue = yield* make$45();
|
|
10582
10583
|
const deferredFinishParts = [];
|
|
10583
10584
|
if (preResolvedStreamParts.length > 0) yield* offerAll(queue, preResolvedStreamParts);
|
|
10584
10585
|
const toolCallFibers = yield* make$17();
|
|
10585
|
-
const toolCallSemaphore = concurrency === "unbounded" ? void 0 : yield* make$
|
|
10586
|
+
const toolCallSemaphore = concurrency === "unbounded" ? void 0 : yield* make$46(concurrency);
|
|
10586
10587
|
const pendingToolCalls = new Map();
|
|
10587
10588
|
const bufferedToolCalls = [];
|
|
10588
10589
|
const handleToolCall = fnUntraced(function* (part) {
|
|
@@ -11629,7 +11630,7 @@ const PromptParams = Struct({
|
|
|
11629
11630
|
sessionId: String$5,
|
|
11630
11631
|
prompt: ArraySchema(ContentBlock)
|
|
11631
11632
|
});
|
|
11632
|
-
const decodeParams = (schema, params) => decodeUnknownEffect$1(schema)(params).pipe(mapError((error) => new RpcError({
|
|
11633
|
+
const decodeParams$1 = (schema, params) => decodeUnknownEffect$1(schema)(params).pipe(mapError((error) => new RpcError({
|
|
11633
11634
|
code: -32602,
|
|
11634
11635
|
message: error.message
|
|
11635
11636
|
})));
|
|
@@ -11747,7 +11748,8 @@ const make$12 = fnUntraced(function* (options) {
|
|
|
11747
11748
|
thoughtLevel: record.thoughtLevel,
|
|
11748
11749
|
agent,
|
|
11749
11750
|
running: void 0,
|
|
11750
|
-
toolCalls: 0
|
|
11751
|
+
toolCalls: 0,
|
|
11752
|
+
announcedSubagents: new Set()
|
|
11751
11753
|
};
|
|
11752
11754
|
sessions.set(id, session);
|
|
11753
11755
|
return session;
|
|
@@ -11889,18 +11891,22 @@ const make$12 = fnUntraced(function* (options) {
|
|
|
11889
11891
|
sessionUpdate: "agent_thought_chunk",
|
|
11890
11892
|
content: textContent(`Retrying after error: ${part.error.message}\n`)
|
|
11891
11893
|
});
|
|
11892
|
-
case "SubagentStart":
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
|
|
11894
|
+
case "SubagentStart": {
|
|
11895
|
+
const announced = session.announcedSubagents.has(part.id);
|
|
11896
|
+
session.announcedSubagents.add(part.id);
|
|
11897
|
+
return update(session.id, {
|
|
11898
|
+
sessionUpdate: announced ? "tool_call_update" : "tool_call",
|
|
11899
|
+
toolCallId: `subagent-${part.id}`,
|
|
11900
|
+
title: `delegate: ${part.prompt.replace(/\s+/g, " ").trim().slice(0, 120)}`,
|
|
11901
|
+
kind: "think",
|
|
11902
|
+
status: "in_progress",
|
|
11903
|
+
rawInput: { prompt: part.prompt }
|
|
11904
|
+
});
|
|
11905
|
+
}
|
|
11900
11906
|
case "SubagentComplete": return update(session.id, {
|
|
11901
11907
|
sessionUpdate: "tool_call_update",
|
|
11902
11908
|
toolCallId: `subagent-${part.id}`,
|
|
11903
|
-
status: "completed",
|
|
11909
|
+
status: part.status === "completed" ? "completed" : "failed",
|
|
11904
11910
|
rawOutput: part.summary,
|
|
11905
11911
|
content: [{
|
|
11906
11912
|
type: "content",
|
|
@@ -11936,7 +11942,7 @@ const make$12 = fnUntraced(function* (options) {
|
|
|
11936
11942
|
}
|
|
11937
11943
|
});
|
|
11938
11944
|
const newSession = fnUntraced(function* (params) {
|
|
11939
|
-
const { cwd, model } = yield* decodeParams(NewSessionParams, params);
|
|
11945
|
+
const { cwd, model } = yield* decodeParams$1(NewSessionParams, params);
|
|
11940
11946
|
const modelId = model ?? options.defaultModel;
|
|
11941
11947
|
const thoughtLevel = options.defaultThoughtLevel;
|
|
11942
11948
|
yield* requireModel(modelId, thoughtLevel);
|
|
@@ -11953,7 +11959,7 @@ const make$12 = fnUntraced(function* (options) {
|
|
|
11953
11959
|
};
|
|
11954
11960
|
});
|
|
11955
11961
|
const loadSession = fnUntraced(function* (params, replay) {
|
|
11956
|
-
const { sessionId, cwd, model } = yield* decodeParams(LoadSessionParams, params);
|
|
11962
|
+
const { sessionId, cwd, model } = yield* decodeParams$1(LoadSessionParams, params);
|
|
11957
11963
|
const existing = sessions.get(sessionId);
|
|
11958
11964
|
if (existing !== void 0) return sessionState(existing);
|
|
11959
11965
|
const record = yield* store.get(sessionId).pipe(mapError((error) => new RpcError({
|
|
@@ -11973,7 +11979,7 @@ const make$12 = fnUntraced(function* (options) {
|
|
|
11973
11979
|
return sessionState(session);
|
|
11974
11980
|
});
|
|
11975
11981
|
const setModel = fnUntraced(function* (params) {
|
|
11976
|
-
const { sessionId, modelId } = yield* decodeParams(SetModelParams, params);
|
|
11982
|
+
const { sessionId, modelId } = yield* decodeParams$1(SetModelParams, params);
|
|
11977
11983
|
const session = yield* getSession(sessionId);
|
|
11978
11984
|
yield* requireModel(modelId, session.thoughtLevel);
|
|
11979
11985
|
session.model = modelId;
|
|
@@ -11981,7 +11987,7 @@ const make$12 = fnUntraced(function* (options) {
|
|
|
11981
11987
|
return {};
|
|
11982
11988
|
});
|
|
11983
11989
|
const setConfigOption = fnUntraced(function* (params) {
|
|
11984
|
-
const { sessionId, value } = yield* decodeParams(SetConfigOptionParams, params);
|
|
11990
|
+
const { sessionId, value } = yield* decodeParams$1(SetConfigOptionParams, params);
|
|
11985
11991
|
const session = yield* getSession(sessionId);
|
|
11986
11992
|
yield* requireModel(session.model, value);
|
|
11987
11993
|
session.thoughtLevel = value;
|
|
@@ -11989,7 +11995,7 @@ const make$12 = fnUntraced(function* (options) {
|
|
|
11989
11995
|
return { configOptions: configOptions(session) };
|
|
11990
11996
|
});
|
|
11991
11997
|
const prompt = fnUntraced(function* (params) {
|
|
11992
|
-
const { sessionId, prompt } = yield* decodeParams(PromptParams, params);
|
|
11998
|
+
const { sessionId, prompt } = yield* decodeParams$1(PromptParams, params);
|
|
11993
11999
|
const session = yield* getSession(sessionId);
|
|
11994
12000
|
if (session.running !== void 0) return yield* new RpcError({
|
|
11995
12001
|
code: -32e3,
|
|
@@ -12006,7 +12012,7 @@ const make$12 = fnUntraced(function* (options) {
|
|
|
12006
12012
|
return yield* toRpcError(exit$1.cause);
|
|
12007
12013
|
});
|
|
12008
12014
|
const cancel = fnUntraced(function* (params) {
|
|
12009
|
-
const { sessionId } = yield* decodeParams(SessionIdParams, params);
|
|
12015
|
+
const { sessionId } = yield* decodeParams$1(SessionIdParams, params);
|
|
12010
12016
|
const running = sessions.get(sessionId)?.running;
|
|
12011
12017
|
if (running !== void 0) yield* interrupt$2(running);
|
|
12012
12018
|
});
|
|
@@ -12058,7 +12064,7 @@ const make$12 = fnUntraced(function* (options) {
|
|
|
12058
12064
|
});
|
|
12059
12065
|
const runStdio = (options) => gen(function* () {
|
|
12060
12066
|
const stdio = yield* Stdio;
|
|
12061
|
-
const output = yield* make$
|
|
12067
|
+
const output = yield* make$45();
|
|
12062
12068
|
const writer = yield* fromQueue(output).pipe(map$9((line) => `${line}\n`), run$4(stdio.stdout()), forkScoped);
|
|
12063
12069
|
const server = yield* make$12({
|
|
12064
12070
|
...options,
|
|
@@ -12413,7 +12419,7 @@ var ExaError = class extends TaggedError$1()("ExaError", { cause: Defect() }) {}
|
|
|
12413
12419
|
const layer$7 = effect(ExaSearch, gen(function* () {
|
|
12414
12420
|
const scope$4 = yield* scope;
|
|
12415
12421
|
const getClient = yield* cachedWithTTL(gen(function* () {
|
|
12416
|
-
const McpClient = yield* tryPromise(() => import("./McpClient-
|
|
12422
|
+
const McpClient = yield* tryPromise(() => import("./McpClient-1W508adc.mjs"));
|
|
12417
12423
|
const context = yield* buildWithScope(McpClient.layer, scope$4);
|
|
12418
12424
|
return get$2(context, McpClient.McpClient);
|
|
12419
12425
|
}), (exit) => isSuccess(exit) ? infinity : zero);
|
|
@@ -12501,8 +12507,49 @@ const maybeRemoveFile = (path) => serviceOption(SemanticSearch).pipe(flatMap$1(m
|
|
|
12501
12507
|
var CurrentDirectory = class extends Service()("clanka/AgentTools/CurrentDirectory") {};
|
|
12502
12508
|
var DirectoryChanger = class extends Service()("clanka/AgentTools/DirectoryChanger") {};
|
|
12503
12509
|
var TaskCompleter = class extends Service()("clanka/AgentTools/TaskCompleter") {};
|
|
12510
|
+
const SubagentStatus = Literals$2([
|
|
12511
|
+
"completed",
|
|
12512
|
+
"running",
|
|
12513
|
+
"failed",
|
|
12514
|
+
"cancelled"
|
|
12515
|
+
]);
|
|
12516
|
+
const SubagentResult = Struct({
|
|
12517
|
+
id: String$5,
|
|
12518
|
+
status: SubagentStatus,
|
|
12519
|
+
output: optional$2(String$5)
|
|
12520
|
+
});
|
|
12521
|
+
const DelegateResult = Struct({
|
|
12522
|
+
...SubagentResult.fields,
|
|
12523
|
+
status: Literals$2(["completed", "running"])
|
|
12524
|
+
});
|
|
12525
|
+
const SubagentInfo = Struct({
|
|
12526
|
+
id: String$5,
|
|
12527
|
+
status: SubagentStatus,
|
|
12528
|
+
prompt: String$5
|
|
12529
|
+
});
|
|
12504
12530
|
var SubagentExecutor = class extends Service()("clanka/AgentTools/SubagentExecutor") {};
|
|
12531
|
+
const subagentsUnavailable = {
|
|
12532
|
+
delegate: () => die(new Error("Sub-agents are not available here")),
|
|
12533
|
+
waitAgents: () => fail$1("Sub-agents are not available here"),
|
|
12534
|
+
messageAgent: () => fail$1("Sub-agents are not available here"),
|
|
12535
|
+
stopAgent: () => fail$1("Sub-agents are not available here"),
|
|
12536
|
+
listAgents: succeed$1([])
|
|
12537
|
+
};
|
|
12505
12538
|
var ImageAttacher = class extends Service()("clanka/AgentTools/ImageAttacher") {};
|
|
12539
|
+
const defaultBashTimeout = minutes(10);
|
|
12540
|
+
var CommandLimits = class extends Reference("clanka/AgentTools/CommandLimits", { defaultValue: () => ({
|
|
12541
|
+
timeout: void 0,
|
|
12542
|
+
outputChars: void 0
|
|
12543
|
+
}) }) {};
|
|
12544
|
+
const makeBashTool = (timeout) => make$16("bash", {
|
|
12545
|
+
description: "Run a bash command and return the output",
|
|
12546
|
+
parameters: Struct({
|
|
12547
|
+
command: String$5,
|
|
12548
|
+
timeoutMs: optional$2(Finite).annotate({ documentation: `Timeout in ms (default and max: ${toMillis(timeout)})` })
|
|
12549
|
+
}).annotate({ identifier: "command" }),
|
|
12550
|
+
success: String$5,
|
|
12551
|
+
dependencies: [CurrentDirectory]
|
|
12552
|
+
});
|
|
12506
12553
|
const globNamesDirectory = (glob) => glob.split("/").slice(0, -1).some((segment) => segment.length > 0 && !/[*?[\]{}]/.test(segment));
|
|
12507
12554
|
const AgentTools = make$14(make$16("changeDirectory", {
|
|
12508
12555
|
description: "Change the executor's working directory to an existing directory and return its absolute path. Relative paths resolve from the current directory without shell expansion. Await this before dependent tools. The change persists across scripts and is shared with delegates using this executor. Startup AGENTS.md, skills, and the semantic-search index root remain fixed. Navigation does not survive a session reload.",
|
|
@@ -12529,9 +12576,39 @@ const AgentTools = make$14(make$16("changeDirectory", {
|
|
|
12529
12576
|
success: String$5,
|
|
12530
12577
|
dependencies: [CurrentDirectory]
|
|
12531
12578
|
}), make$16("delegate", {
|
|
12532
|
-
description: "Delegate a task to another software engineer / sub-agent.
|
|
12533
|
-
parameters:
|
|
12534
|
-
|
|
12579
|
+
description: "Delegate a task to another software engineer / sub-agent. By default it waits for the sub-agent and returns its output. With `background: true` it returns straight away with status \"running\"; the sub-agent keeps working while you take more turns, and its result is sent to you as a <subagent> message when it finishes. Keep the returned id to address the agent later.",
|
|
12580
|
+
parameters: Struct({
|
|
12581
|
+
prompt: String$5,
|
|
12582
|
+
background: optional$2(Boolean$4)
|
|
12583
|
+
}),
|
|
12584
|
+
success: DelegateResult,
|
|
12585
|
+
failure: String$5,
|
|
12586
|
+
dependencies: [SubagentExecutor]
|
|
12587
|
+
}), make$16("waitAgents", {
|
|
12588
|
+
description: "Wait until the given sub-agents have finished, or all of your sub-agents when no ids are passed. A failed agent is returned with status \"failed\" and its error as the output; it does not throw.",
|
|
12589
|
+
parameters: UndefinedOr(ArraySchema(String$5)).annotate({ identifier: "ids" }),
|
|
12590
|
+
success: ArraySchema(SubagentResult),
|
|
12591
|
+
failure: String$5,
|
|
12592
|
+
dependencies: [SubagentExecutor]
|
|
12593
|
+
}), make$16("messageAgent", {
|
|
12594
|
+
description: "Send a message to one of your sub-agents. A running agent receives it as steering; a finished agent starts a new turn on top of its previous conversation. Returns straight away; the result is sent to you as a <subagent> message.",
|
|
12595
|
+
parameters: Struct({
|
|
12596
|
+
id: String$5,
|
|
12597
|
+
message: String$5
|
|
12598
|
+
}),
|
|
12599
|
+
success: SubagentResult,
|
|
12600
|
+
failure: String$5,
|
|
12601
|
+
dependencies: [SubagentExecutor]
|
|
12602
|
+
}), make$16("stopAgent", {
|
|
12603
|
+
description: "Stop one of your sub-agents and every agent it started. Returns its final status.",
|
|
12604
|
+
parameters: String$5.annotate({ identifier: "id" }),
|
|
12605
|
+
success: SubagentResult,
|
|
12606
|
+
failure: String$5,
|
|
12607
|
+
dependencies: [SubagentExecutor]
|
|
12608
|
+
}), make$16("listAgents", {
|
|
12609
|
+
description: "List the sub-agents you have started in this run, with their status.",
|
|
12610
|
+
parameters: Void,
|
|
12611
|
+
success: ArraySchema(SubagentInfo),
|
|
12535
12612
|
dependencies: [SubagentExecutor]
|
|
12536
12613
|
}), make$16("glob", {
|
|
12537
12614
|
description: "Find files matching a glob pattern.",
|
|
@@ -12543,21 +12620,13 @@ const AgentTools = make$14(make$16("changeDirectory", {
|
|
|
12543
12620
|
parameters: ArraySchema(String$5).annotate({ identifier: "args" }),
|
|
12544
12621
|
success: String$5,
|
|
12545
12622
|
dependencies: [CurrentDirectory]
|
|
12546
|
-
}), make$16("
|
|
12547
|
-
description: "Run a bash command and return the output",
|
|
12548
|
-
parameters: Struct({
|
|
12549
|
-
command: String$5,
|
|
12550
|
-
timeoutMs: optional$2(Finite).annotate({ documentation: "Timeout in ms (default: 120000, max 4 minutes)" })
|
|
12551
|
-
}).annotate({ identifier: "command" }),
|
|
12552
|
-
success: String$5,
|
|
12553
|
-
dependencies: [CurrentDirectory]
|
|
12554
|
-
}), make$16("applyPatch", {
|
|
12623
|
+
}), makeBashTool(defaultBashTimeout), make$16("applyPatch", {
|
|
12555
12624
|
description: "Add, update or remove multiple files with a git diff / unified diff / wrapped patch.",
|
|
12556
12625
|
parameters: String$5.annotate({ identifier: "patch" }),
|
|
12557
12626
|
success: String$5,
|
|
12558
12627
|
dependencies: [CurrentDirectory]
|
|
12559
12628
|
}), make$16("writeFile", {
|
|
12560
|
-
description: "Write content to a file, creating parent directories if needed.
|
|
12629
|
+
description: "Write content to a file, creating parent directories if needed.",
|
|
12561
12630
|
parameters: Struct({
|
|
12562
12631
|
path: String$5,
|
|
12563
12632
|
content: String$5
|
|
@@ -12609,14 +12678,18 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
12609
12678
|
const pathService = yield* Path$3;
|
|
12610
12679
|
const webSearch = yield* ExaSearch;
|
|
12611
12680
|
const fetchMarkdown = yield* WebToMarkdown;
|
|
12612
|
-
const execute = fn(function* (command) {
|
|
12681
|
+
const execute = fn(function* (command, _timeout) {
|
|
12682
|
+
const { outputChars } = yield* CommandLimits;
|
|
12613
12683
|
const handle = yield* spawner.spawn(command);
|
|
12614
|
-
return yield* handle.all.pipe(decodeText, mkString, flatMap$1(fnUntraced(function* (output) {
|
|
12684
|
+
return yield* handle.all.pipe(decodeText, outputChars === void 0 ? mkString : collectBounded(outputChars), flatMap$1(fnUntraced(function* (output) {
|
|
12615
12685
|
const exitCode = yield* handle.exitCode;
|
|
12616
12686
|
if (exitCode === 0) return output;
|
|
12617
12687
|
return yield* die(new Error(`Command failed with exit code ${exitCode}: ${output}`));
|
|
12618
12688
|
})));
|
|
12619
|
-
},
|
|
12689
|
+
}, (effect, _command, timeout) => timeout === void 0 ? effect : timeoutOrElse(effect, {
|
|
12690
|
+
duration: timeout,
|
|
12691
|
+
orElse: () => die(new Error(`Command timed out after ${toMillis(timeout)}ms`))
|
|
12692
|
+
}), scoped);
|
|
12620
12693
|
const readImage = fnUntraced(function* (path, extensionType, options) {
|
|
12621
12694
|
if (options.startLine !== void 0 || options.endLine !== void 0) return yield* die(new Error(`startLine / endLine are not supported for images: ${path}`));
|
|
12622
12695
|
const bytes = yield* readBoundedFile(fs, path).pipe(catchReason("PlatformError", "NotFound", () => succeed$1(null)), orDie);
|
|
@@ -12721,7 +12794,9 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
12721
12794
|
return yield* promise(() => import("./index.min-CI3qqohw.mjs").then((Glob) => Glob.glob(pattern, { cwd })));
|
|
12722
12795
|
}),
|
|
12723
12796
|
bash: fn("AgentTools.bash")(function* (options) {
|
|
12724
|
-
const
|
|
12797
|
+
const limits = yield* CommandLimits;
|
|
12798
|
+
const maxMs = toMillis(limits.timeout ?? defaultBashTimeout);
|
|
12799
|
+
const timeoutMs = Math.min(options.timeoutMs ?? maxMs, maxMs);
|
|
12725
12800
|
yield* logInfo(`Calling "bash"`).pipe(annotateLogs({
|
|
12726
12801
|
...options,
|
|
12727
12802
|
timeoutMs
|
|
@@ -12731,10 +12806,7 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
12731
12806
|
cwd,
|
|
12732
12807
|
stdin: "ignore"
|
|
12733
12808
|
});
|
|
12734
|
-
return yield* execute(cmd)
|
|
12735
|
-
duration: timeoutMs,
|
|
12736
|
-
orElse: () => die(new Error(`Command timed out after ${timeoutMs}ms`))
|
|
12737
|
-
}));
|
|
12809
|
+
return yield* execute(cmd, millis(timeoutMs));
|
|
12738
12810
|
}, orDie),
|
|
12739
12811
|
gh: fn("AgentTools.gh")(function* (args) {
|
|
12740
12812
|
yield* logInfo(`Calling "gh"`).pipe(annotateLogs({ args }));
|
|
@@ -12743,7 +12815,8 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
12743
12815
|
cwd,
|
|
12744
12816
|
stdin: "ignore"
|
|
12745
12817
|
});
|
|
12746
|
-
|
|
12818
|
+
const { timeout } = yield* CommandLimits;
|
|
12819
|
+
return yield* execute(cmd, timeout);
|
|
12747
12820
|
}, orDie),
|
|
12748
12821
|
webSearch: fn("AgentTools.webSearch")(function* (options) {
|
|
12749
12822
|
yield* logInfo(`Calling "webSearch"`).pipe(annotateLogs(options));
|
|
@@ -12845,12 +12918,33 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
12845
12918
|
}
|
|
12846
12919
|
return `Success. Updated the following files:\n${out.join("\n")}`;
|
|
12847
12920
|
}, orDie),
|
|
12848
|
-
delegate: fn("AgentTools.delegate")(function* (
|
|
12849
|
-
yield*
|
|
12850
|
-
|
|
12851
|
-
|
|
12852
|
-
|
|
12853
|
-
|
|
12921
|
+
delegate: fn("AgentTools.delegate")(function* (options) {
|
|
12922
|
+
const { prompt, background = false } = yield* decodeDelegate(options);
|
|
12923
|
+
yield* logInfo(`Calling "delegate"`).pipe(annotateLogs({ background }));
|
|
12924
|
+
return yield* (yield* SubagentExecutor).delegate({
|
|
12925
|
+
prompt,
|
|
12926
|
+
background
|
|
12927
|
+
});
|
|
12928
|
+
}),
|
|
12929
|
+
waitAgents: fn("AgentTools.waitAgents")(function* (input) {
|
|
12930
|
+
const ids = yield* decodeWaitAgents(input);
|
|
12931
|
+
yield* logInfo(`Calling "waitAgents"`).pipe(annotateLogs({ ids }));
|
|
12932
|
+
return yield* (yield* SubagentExecutor).waitAgents(ids);
|
|
12933
|
+
}),
|
|
12934
|
+
messageAgent: fn("AgentTools.messageAgent")(function* (input) {
|
|
12935
|
+
const options = yield* decodeMessageAgent(input);
|
|
12936
|
+
yield* logInfo(`Calling "messageAgent"`).pipe(annotateLogs({ id: options.id }));
|
|
12937
|
+
return yield* (yield* SubagentExecutor).messageAgent(options);
|
|
12938
|
+
}),
|
|
12939
|
+
stopAgent: fn("AgentTools.stopAgent")(function* (input) {
|
|
12940
|
+
const id = yield* decodeStopAgent(input);
|
|
12941
|
+
yield* logInfo(`Calling "stopAgent"`).pipe(annotateLogs({ id }));
|
|
12942
|
+
return yield* (yield* SubagentExecutor).stopAgent(id);
|
|
12943
|
+
}),
|
|
12944
|
+
listAgents: fn("AgentTools.listAgents")(function* () {
|
|
12945
|
+
yield* logInfo(`Calling "listAgents"`);
|
|
12946
|
+
return yield* (yield* SubagentExecutor).listAgents;
|
|
12947
|
+
}),
|
|
12854
12948
|
taskComplete: fn("AgentTools.taskComplete")(function* (message) {
|
|
12855
12949
|
if (typeof message !== "string") return yield* fail$1("taskComplete requires a string argument. Pass your final output directly, for example: taskComplete(\"done\").");
|
|
12856
12950
|
yield* (yield* TaskCompleter)(message);
|
|
@@ -12859,6 +12953,35 @@ ${prompt}`);
|
|
|
12859
12953
|
}));
|
|
12860
12954
|
const AgentToolHandlers = AgentToolHandlersNoDeps.pipe(provide$3([layer$7, layer$6]));
|
|
12861
12955
|
const AgentToolHandlersTest = AgentToolHandlersNoDeps.pipe(provide$3([mock(ExaSearch)({}), mock(WebToMarkdown)({})]));
|
|
12956
|
+
const decodeParams = (schema, usage) => {
|
|
12957
|
+
const decode = decodeUnknownEffect$1(schema);
|
|
12958
|
+
return (input) => mapError(decode(input), () => usage);
|
|
12959
|
+
};
|
|
12960
|
+
const decodeDelegate = decodeParams(AgentTools.tools.delegate.parametersSchema, "delegate requires an options object, for example: delegate({ prompt: \"...\" }) or delegate({ prompt: \"...\", background: true }).");
|
|
12961
|
+
const decodeWaitAgents = decodeParams(AgentTools.tools.waitAgents.parametersSchema, "waitAgents takes an optional array of agent ids, for example: waitAgents([\"3\", \"4\"]).");
|
|
12962
|
+
const decodeMessageAgent = decodeParams(AgentTools.tools.messageAgent.parametersSchema, "messageAgent requires an options object, for example: messageAgent({ id: \"3\", message: \"...\" }).");
|
|
12963
|
+
const decodeStopAgent = decodeParams(AgentTools.tools.stopAgent.parametersSchema, "stopAgent requires an agent id, for example: stopAgent(\"3\").");
|
|
12964
|
+
const collectBounded = (maxChars) => (stream) => {
|
|
12965
|
+
const headChars = Math.floor(maxChars / 2);
|
|
12966
|
+
const tailChars = maxChars - headChars;
|
|
12967
|
+
let head = "";
|
|
12968
|
+
let tail = "";
|
|
12969
|
+
let total = 0;
|
|
12970
|
+
return stream.pipe(runForEach((chunk) => sync(() => {
|
|
12971
|
+
total += chunk.length;
|
|
12972
|
+
let rest = chunk;
|
|
12973
|
+
if (head.length < headChars) {
|
|
12974
|
+
const take = headChars - head.length;
|
|
12975
|
+
head += rest.slice(0, take);
|
|
12976
|
+
rest = rest.slice(take);
|
|
12977
|
+
}
|
|
12978
|
+
if (rest.length > 0 && tailChars > 0) tail = (tail + rest).slice(-tailChars);
|
|
12979
|
+
})), map$5(() => {
|
|
12980
|
+
const omitted = total - head.length - tail.length;
|
|
12981
|
+
if (omitted <= 0) return head + tail;
|
|
12982
|
+
return `${head}\n\n[... ${omitted} of ${total} chars omitted from the middle of the output ...]\n\n${tail}`;
|
|
12983
|
+
}));
|
|
12984
|
+
};
|
|
12862
12985
|
var ApplyPatchError = class extends TaggedClass$1("ApplyPatchError") {};
|
|
12863
12986
|
//#endregion
|
|
12864
12987
|
//#region src/TypeBuilder.ts
|
|
@@ -13147,13 +13270,14 @@ var ToolkitRenderer = class ToolkitRenderer extends Service()("clanka/ToolkitRen
|
|
|
13147
13270
|
for (const [name, tool] of Object.entries(tools.tools)) {
|
|
13148
13271
|
const paramName = resolveIdentifier(tool.parametersSchema.ast) ?? "options";
|
|
13149
13272
|
const paramType = render(tool.parametersSchema);
|
|
13150
|
-
const params = paramType === "void" ? "" : `${paramName}: ${paramType}`;
|
|
13273
|
+
const params = paramType === "void" ? "" : paramType.endsWith(optionalSuffix) ? `${paramName}?: ${paramType.slice(0, -optionalSuffix.length)}` : `${paramName}: ${paramType}`;
|
|
13151
13274
|
output.push(`/** ${tool.description} */
|
|
13152
13275
|
declare function ${name}(${params}): Promise<${render(tool.successSchema)}>`);
|
|
13153
13276
|
}
|
|
13154
13277
|
return output.join("\n\n");
|
|
13155
13278
|
}) });
|
|
13156
13279
|
};
|
|
13280
|
+
const optionalSuffix = " | undefined";
|
|
13157
13281
|
//#endregion
|
|
13158
13282
|
//#region src/AgentSkills.ts
|
|
13159
13283
|
const SkillSource = Literals$2(["project", "user"]);
|
|
@@ -13220,6 +13344,24 @@ Relative paths mentioned inside a skill (such as "scripts/" or "references/")
|
|
|
13220
13344
|
are relative to the skill's directory (the parent of SKILL.md); use absolute
|
|
13221
13345
|
paths when accessing them.
|
|
13222
13346
|
|
|
13347
|
+
${entries}`);
|
|
13348
|
+
};
|
|
13349
|
+
var ProvidedSkill = class extends Class$1("ProvidedSkill")({
|
|
13350
|
+
name: String$5,
|
|
13351
|
+
description: String$5,
|
|
13352
|
+
content: String$5
|
|
13353
|
+
}) {};
|
|
13354
|
+
const renderProvidedCatalog = (skills) => {
|
|
13355
|
+
if (skills.length === 0) return none();
|
|
13356
|
+
const entries = skills.map((skill) => `- ${singleLine(skill.name)}: ${singleLine(skill.description)}`).join("\n");
|
|
13357
|
+
return some(`# Skills
|
|
13358
|
+
|
|
13359
|
+
The following skills are available. Each one has instructions for a specific
|
|
13360
|
+
kind of task.
|
|
13361
|
+
|
|
13362
|
+
When a task matches a skill's description, call "readSkill" with its name
|
|
13363
|
+
BEFORE proceeding, then follow the instructions it returns.
|
|
13364
|
+
|
|
13223
13365
|
${entries}`);
|
|
13224
13366
|
};
|
|
13225
13367
|
const Frontmatter = Struct({
|
|
@@ -13290,7 +13432,7 @@ function getStreamSchemas(schema) {
|
|
|
13290
13432
|
}
|
|
13291
13433
|
const schema = declare(isStream);
|
|
13292
13434
|
function Stream(success, error) {
|
|
13293
|
-
return make$
|
|
13435
|
+
return make$48(schema.ast, {
|
|
13294
13436
|
[StreamSchemaTypeId]: StreamSchemaTypeId,
|
|
13295
13437
|
success,
|
|
13296
13438
|
error
|
|
@@ -14653,6 +14795,7 @@ var Capabilities = class extends Class$1("Capabilities")({
|
|
|
14653
14795
|
toolsDts: String$5,
|
|
14654
14796
|
agentsMd: Option(String$5),
|
|
14655
14797
|
supportsSearch: Boolean$4,
|
|
14798
|
+
tools: ArraySchema(String$5),
|
|
14656
14799
|
skills: ArraySchema(Skill).pipe(withDecodingDefaultKey(succeed$1([])), withConstructorDefault(succeed$1([])))
|
|
14657
14800
|
}) {};
|
|
14658
14801
|
const makeLocal = fnUntraced(function* (options) {
|
|
@@ -14666,75 +14809,113 @@ const makeLocal = fnUntraced(function* (options) {
|
|
|
14666
14809
|
currentDirectory = target;
|
|
14667
14810
|
return target;
|
|
14668
14811
|
}, orDie);
|
|
14812
|
+
const commandTimeout = options.limits?.commandTimeout;
|
|
14813
|
+
const commandLimits = {
|
|
14814
|
+
timeout: commandTimeout === void 0 ? void 0 : fromInputUnsafe$1(commandTimeout),
|
|
14815
|
+
outputChars: options.limits?.commandOutputChars
|
|
14816
|
+
};
|
|
14817
|
+
const scriptTimeout = map$8(fromUndefinedOr(options.limits?.scriptTimeout), fromInputUnsafe$1);
|
|
14818
|
+
const excluded = excludedToolNames(options.excludeTools);
|
|
14669
14819
|
const search = yield* serviceOption(SemanticSearch);
|
|
14670
|
-
const
|
|
14671
|
-
const
|
|
14820
|
+
const BuiltInTools = make$14(...Object.values(merge(isSome(search) ? AgentToolsWithSearch : AgentTools, make$14(makeBashTool(commandLimits.timeout ?? defaultBashTimeout))).tools).filter((tool) => !excluded.has(tool.name)));
|
|
14821
|
+
const hasSearch = "search" in BuiltInTools.tools;
|
|
14822
|
+
const AllTools = merge(BuiltInTools, options.tools ?? empty);
|
|
14672
14823
|
const tools = yield* AllTools;
|
|
14673
14824
|
const toolsDts = renderer.render(AllTools);
|
|
14674
14825
|
const services = yield* context();
|
|
14675
|
-
const toolEntries = Object.entries(tools.tools).map(([name, tool]) => {
|
|
14826
|
+
const toolEntries = new Map(Object.entries(tools.tools).map(([name, tool]) => {
|
|
14676
14827
|
const handler = services.mapUnsafe.get(tool.id);
|
|
14677
|
-
return {
|
|
14678
|
-
name,
|
|
14828
|
+
return [name, {
|
|
14679
14829
|
services: merge$2(services, handler.context),
|
|
14680
14830
|
handler: handler.handler
|
|
14681
|
-
};
|
|
14682
|
-
});
|
|
14831
|
+
}];
|
|
14832
|
+
}));
|
|
14833
|
+
const toolNames = Array.from(toolEntries.keys());
|
|
14683
14834
|
if (typeof process !== "undefined") process.on("uncaughtException", () => {});
|
|
14684
14835
|
const execute = fnUntraced(function* (opts) {
|
|
14685
14836
|
const output = yield* unbounded();
|
|
14686
14837
|
const console = yield* makeConsole(output);
|
|
14687
14838
|
const handlerScope = makeUnsafe$1("parallel");
|
|
14688
14839
|
const trackFiber = runIn(handlerScope);
|
|
14689
|
-
const taskServices = empty$6().pipe(add(TaskCompleter, opts.onTaskComplete), add(DirectoryChanger, changeDirectory), add(SubagentExecutor, opts.
|
|
14840
|
+
const taskServices = empty$6().pipe(add(TaskCompleter, opts.onTaskComplete), add(DirectoryChanger, changeDirectory), add(SubagentExecutor, opts.subagents), add(ImageAttacher, opts.onImage), add(CommandLimits, commandLimits), add(Console, console), add(CurrentLogAnnotations, {}), isSome(search) ? add(SemanticSearch, search.value) : identity);
|
|
14690
14841
|
yield* gen(function* () {
|
|
14691
|
-
const
|
|
14692
|
-
|
|
14693
|
-
const
|
|
14694
|
-
|
|
14695
|
-
|
|
14696
|
-
|
|
14697
|
-
|
|
14698
|
-
|
|
14699
|
-
};
|
|
14700
|
-
|
|
14701
|
-
const
|
|
14702
|
-
|
|
14703
|
-
|
|
14704
|
-
|
|
14705
|
-
|
|
14706
|
-
|
|
14707
|
-
|
|
14708
|
-
|
|
14709
|
-
running--;
|
|
14710
|
-
if (exit._tag === "Success") return resolve(exit.value);
|
|
14711
|
-
if (hasInterruptsOnly(exit.cause)) return;
|
|
14712
|
-
reject(squash(exit.cause));
|
|
14713
|
-
});
|
|
14714
|
-
});
|
|
14842
|
+
const source = prepareScript(opts.script);
|
|
14843
|
+
const settled = yield* make$42();
|
|
14844
|
+
const worker = yield* acquireRelease(sync(() => new Worker(workerSource, {
|
|
14845
|
+
eval: true,
|
|
14846
|
+
workerData: {
|
|
14847
|
+
source,
|
|
14848
|
+
tools: [...toolNames, ...Object.keys(opts.loopTools ?? {})]
|
|
14849
|
+
}
|
|
14850
|
+
})), (worker) => promise(() => worker.terminate()));
|
|
14851
|
+
const respond = (id, exit) => {
|
|
14852
|
+
const message = isSuccess(exit) ? {
|
|
14853
|
+
id,
|
|
14854
|
+
ok: true,
|
|
14855
|
+
value: exit.value
|
|
14856
|
+
} : {
|
|
14857
|
+
id,
|
|
14858
|
+
ok: false,
|
|
14859
|
+
failure: toFailure(squash(exit.cause))
|
|
14715
14860
|
};
|
|
14716
|
-
|
|
14717
|
-
|
|
14718
|
-
|
|
14719
|
-
|
|
14720
|
-
|
|
14721
|
-
|
|
14722
|
-
|
|
14723
|
-
|
|
14861
|
+
try {
|
|
14862
|
+
worker.postMessage(message);
|
|
14863
|
+
} catch (error) {
|
|
14864
|
+
worker.postMessage({
|
|
14865
|
+
id,
|
|
14866
|
+
ok: false,
|
|
14867
|
+
failure: toFailure(error)
|
|
14868
|
+
});
|
|
14869
|
+
}
|
|
14870
|
+
};
|
|
14871
|
+
const call = (message) => {
|
|
14872
|
+
const entry = toolEntries.get(message.name);
|
|
14873
|
+
const runFork = runForkWith(add(entry ? merge$2(entry.services, taskServices) : taskServices, CurrentDirectory, currentDirectory));
|
|
14874
|
+
trackFiber(runFork(entry ? entry.handler(message.params, {}) : opts.loopTools[message.name](message.params).pipe(catch_((message) => die(new Error(message)))))).addObserver((exit) => respond(message.id, exit));
|
|
14875
|
+
};
|
|
14876
|
+
worker.on("message", (message) => {
|
|
14877
|
+
switch (message._tag) {
|
|
14878
|
+
case "Output":
|
|
14879
|
+
offerUnsafe(output, message.text);
|
|
14880
|
+
break;
|
|
14881
|
+
case "Call":
|
|
14882
|
+
call(message);
|
|
14883
|
+
break;
|
|
14884
|
+
case "Done":
|
|
14885
|
+
doneUnsafe(settled, void_);
|
|
14886
|
+
break;
|
|
14887
|
+
case "Failed": doneUnsafe(settled, die(fromFailure(message.failure)));
|
|
14888
|
+
}
|
|
14889
|
+
});
|
|
14890
|
+
worker.on("error", (error) => {
|
|
14891
|
+
doneUnsafe(settled, die(error));
|
|
14892
|
+
});
|
|
14893
|
+
worker.on("messageerror", (error) => {
|
|
14894
|
+
doneUnsafe(settled, die(error));
|
|
14895
|
+
});
|
|
14896
|
+
worker.on("exit", (code) => {
|
|
14897
|
+
doneUnsafe(settled, die(new Error(`The script worker exited with code ${code} early`)));
|
|
14898
|
+
});
|
|
14899
|
+
yield* _await(settled);
|
|
14900
|
+
}).pipe(scoped, isSome(scriptTimeout) ? timeoutOrElse({
|
|
14901
|
+
duration: scriptTimeout.value,
|
|
14902
|
+
orElse: () => offer(output, `\nScript timed out: it reached its ${toMillis(scriptTimeout.value)}ms limit and was stopped. Pending tool calls were cancelled.\n`)
|
|
14903
|
+
}) : identity, ensuring(close(handlerScope, void_$1)), catchCause(logFatal), provideService(Console, console), ensuring(end(output)), forkScoped);
|
|
14724
14904
|
return fromQueue(output);
|
|
14725
14905
|
}, unwrap$3);
|
|
14726
14906
|
return AgentExecutor.of({
|
|
14727
14907
|
capabilities: gen(function* () {
|
|
14728
14908
|
const agentsMd = yield* option$1(fs.readFileString(pathService.join(options.directory, "AGENTS.md")));
|
|
14729
|
-
const skills = yield* discover({
|
|
14909
|
+
const skills = "readFile" in tools.tools ? yield* discover({
|
|
14730
14910
|
directory: options.directory,
|
|
14731
14911
|
homeDirectory: homeDirectory(),
|
|
14732
14912
|
hermesHome: fromNullishOr(process.env.HERMES_HOME)
|
|
14733
|
-
}).pipe(provideService(FileSystem, fs), provideService(Path$3, pathService));
|
|
14913
|
+
}).pipe(provideService(FileSystem, fs), provideService(Path$3, pathService)) : [];
|
|
14734
14914
|
return new Capabilities({
|
|
14735
14915
|
toolsDts,
|
|
14736
14916
|
agentsMd,
|
|
14737
14917
|
supportsSearch: hasSearch,
|
|
14918
|
+
tools: Object.keys(tools.tools),
|
|
14738
14919
|
skills
|
|
14739
14920
|
});
|
|
14740
14921
|
}),
|
|
@@ -14744,7 +14925,7 @@ const makeLocal = fnUntraced(function* (options) {
|
|
|
14744
14925
|
if (!tool) return die(new Error(`Unknown tool: ${opts.tool}`));
|
|
14745
14926
|
const handler = services.mapUnsafe.get(tool.id);
|
|
14746
14927
|
if (!handler) return die(new Error(`Unknown tool: ${opts.tool}`));
|
|
14747
|
-
const taskServices = handler.context.pipe(add(TaskCompleter, () => void_), add(CurrentDirectory, currentDirectory), add(DirectoryChanger, changeDirectory), add(SubagentExecutor,
|
|
14928
|
+
const taskServices = handler.context.pipe(add(TaskCompleter, () => void_), add(CurrentDirectory, currentDirectory), add(DirectoryChanger, changeDirectory), add(SubagentExecutor, subagentsUnavailable), add(ImageAttacher, () => void_), add(CommandLimits, commandLimits), add(CurrentLogAnnotations, {}), isSome(search) ? add(SemanticSearch, search.value) : identity);
|
|
14748
14929
|
const encodeSuccess = encodeUnknownEffect(toCodecJson(tool.successSchema));
|
|
14749
14930
|
return pipe(handler.handler(opts.params, {}), flatMap$1(encodeSuccess), provideContext(taskServices), orDie);
|
|
14750
14931
|
})
|
|
@@ -14754,15 +14935,17 @@ const makeRpc = gen(function* () {
|
|
|
14754
14935
|
const client = yield* make$10(Rpcs, { spanPrefix: "AgentExecutorClient" });
|
|
14755
14936
|
return AgentExecutor.of({
|
|
14756
14937
|
capabilities: orDie(client.capabilities()),
|
|
14757
|
-
execute: (opts) => Scope.useSync((scope) => client.execute({
|
|
14938
|
+
execute: (opts) => Scope.useSync((scope) => client.execute({
|
|
14939
|
+
script: opts.script,
|
|
14940
|
+
loopTools: Object.keys(opts.loopTools ?? {})
|
|
14941
|
+
}).pipe(tap$1((part) => {
|
|
14758
14942
|
switch (part._tag) {
|
|
14759
14943
|
case "Text": return void_;
|
|
14760
|
-
case "
|
|
14761
|
-
case "Subagent": {
|
|
14944
|
+
case "Request": {
|
|
14762
14945
|
const id = part.id;
|
|
14763
|
-
return pipe(opts
|
|
14946
|
+
return pipe(handleRequest(opts, part.request), exit, flatMap$1((exit) => client.respond({
|
|
14764
14947
|
id,
|
|
14765
|
-
|
|
14948
|
+
response: exitToResponse(exit)
|
|
14766
14949
|
})), forkIn(scope));
|
|
14767
14950
|
}
|
|
14768
14951
|
case "Image": return opts.onImage({
|
|
@@ -14777,14 +14960,35 @@ const makeRpc = gen(function* () {
|
|
|
14777
14960
|
}
|
|
14778
14961
|
});
|
|
14779
14962
|
});
|
|
14780
|
-
const layerLocal$1 = (options) => effect(AgentExecutor, makeLocal(options)).pipe(provide$3(
|
|
14963
|
+
const layerLocal$1 = (options) => effect(AgentExecutor, withBuiltInHandlers(makeLocal(options))).pipe(provide$3(ToolkitRenderer.layer));
|
|
14781
14964
|
const layerRpc = effect(AgentExecutor, makeRpc);
|
|
14965
|
+
const AgentRequest = TaggedUnion({
|
|
14966
|
+
TaskComplete: { summary: String$5 },
|
|
14967
|
+
Delegate: {
|
|
14968
|
+
prompt: String$5,
|
|
14969
|
+
background: Boolean$4
|
|
14970
|
+
},
|
|
14971
|
+
WaitAgents: { ids: UndefinedOr(ArraySchema(String$5)) },
|
|
14972
|
+
MessageAgent: {
|
|
14973
|
+
id: String$5,
|
|
14974
|
+
message: String$5
|
|
14975
|
+
},
|
|
14976
|
+
StopAgent: { id: String$5 },
|
|
14977
|
+
ListAgents: {},
|
|
14978
|
+
LoopTool: {
|
|
14979
|
+
name: String$5,
|
|
14980
|
+
params: optional$2(Json)
|
|
14981
|
+
}
|
|
14982
|
+
});
|
|
14983
|
+
const AgentResponse = TaggedUnion({
|
|
14984
|
+
Success: { value: Json },
|
|
14985
|
+
Failure: { message: String$5 }
|
|
14986
|
+
});
|
|
14782
14987
|
const ExecuteOutput = TaggedUnion({
|
|
14783
14988
|
Text: { text: String$5 },
|
|
14784
|
-
|
|
14785
|
-
Subagent: {
|
|
14989
|
+
Request: {
|
|
14786
14990
|
id: Finite,
|
|
14787
|
-
|
|
14991
|
+
request: AgentRequest
|
|
14788
14992
|
},
|
|
14789
14993
|
Image: {
|
|
14790
14994
|
fileName: String$5,
|
|
@@ -14792,11 +14996,14 @@ const ExecuteOutput = TaggedUnion({
|
|
|
14792
14996
|
data: Uint8Array$2
|
|
14793
14997
|
}
|
|
14794
14998
|
});
|
|
14795
|
-
var Rpcs = class extends make$9(make$11("capabilities", { success: Capabilities }), make$11("
|
|
14999
|
+
var Rpcs = class extends make$9(make$11("capabilities", { success: Capabilities }), make$11("respond", { payload: {
|
|
14796
15000
|
id: Finite,
|
|
14797
|
-
|
|
15001
|
+
response: AgentResponse
|
|
14798
15002
|
} }), make$11("execute", {
|
|
14799
|
-
payload: Struct({
|
|
15003
|
+
payload: Struct({
|
|
15004
|
+
script: String$5,
|
|
15005
|
+
loopTools: ArraySchema(String$5).pipe(withDecodingDefaultKey(succeed$1([])))
|
|
15006
|
+
}),
|
|
14800
15007
|
success: ExecuteOutput,
|
|
14801
15008
|
stream: true
|
|
14802
15009
|
}), make$11("executeUnsafe", {
|
|
@@ -14806,24 +15013,168 @@ var Rpcs = class extends make$9(make$11("capabilities", { success: Capabilities
|
|
|
14806
15013
|
}),
|
|
14807
15014
|
success: Json
|
|
14808
15015
|
})) {};
|
|
15016
|
+
const handleRequest = (opts, request) => {
|
|
15017
|
+
switch (request._tag) {
|
|
15018
|
+
case "TaskComplete": return opts.onTaskComplete(request.summary);
|
|
15019
|
+
case "Delegate": return opts.subagents.delegate(request);
|
|
15020
|
+
case "WaitAgents": return opts.subagents.waitAgents(request.ids);
|
|
15021
|
+
case "MessageAgent": return opts.subagents.messageAgent(request);
|
|
15022
|
+
case "StopAgent": return opts.subagents.stopAgent(request.id);
|
|
15023
|
+
case "ListAgents": return opts.subagents.listAgents;
|
|
15024
|
+
case "LoopTool": {
|
|
15025
|
+
const handler = opts.loopTools?.[request.name];
|
|
15026
|
+
return handler ? handler(request.params) : fail$1(`Unknown loop-side tool: ${request.name}`);
|
|
15027
|
+
}
|
|
15028
|
+
}
|
|
15029
|
+
};
|
|
15030
|
+
const withBuiltInHandlers = (effect) => flatMap$1(build(AgentToolHandlers), (builtIns) => updateContext(effect, (context) => merge$2(builtIns, context)));
|
|
15031
|
+
const exitToResponse = (exit) => {
|
|
15032
|
+
if (isSuccess(exit)) return {
|
|
15033
|
+
_tag: "Success",
|
|
15034
|
+
value: exit.value ?? null
|
|
15035
|
+
};
|
|
15036
|
+
return {
|
|
15037
|
+
_tag: "Failure",
|
|
15038
|
+
message: errorMessage$1(squash(exit.cause))
|
|
15039
|
+
};
|
|
15040
|
+
};
|
|
15041
|
+
const errorMessage$1 = (error) => typeof error === "string" ? error : error instanceof Error ? error.message : String(error);
|
|
15042
|
+
const excludedToolNames = (excludeTools) => {
|
|
15043
|
+
const names = new Set(excludeTools);
|
|
15044
|
+
if (names.has("delegate")) for (const name of [
|
|
15045
|
+
"waitAgents",
|
|
15046
|
+
"messageAgent",
|
|
15047
|
+
"stopAgent",
|
|
15048
|
+
"listAgents"
|
|
15049
|
+
]) names.add(name);
|
|
15050
|
+
return names;
|
|
15051
|
+
};
|
|
14809
15052
|
const wrapScript = (script) => `async function main() {
|
|
14810
15053
|
${script}
|
|
14811
15054
|
}`;
|
|
14812
|
-
const
|
|
15055
|
+
const prepareScript = (script) => {
|
|
15056
|
+
const source = wrapScript(script);
|
|
14813
15057
|
try {
|
|
14814
|
-
|
|
15058
|
+
new NodeVm.Script(source);
|
|
15059
|
+
return source;
|
|
14815
15060
|
} catch (error) {
|
|
14816
15061
|
if (!(error instanceof SyntaxError)) throw error;
|
|
14817
15062
|
const preprocessed = preprocessScript(script);
|
|
14818
15063
|
if (preprocessed === script) throw error;
|
|
15064
|
+
const preprocessedSource = wrapScript(preprocessed);
|
|
14819
15065
|
try {
|
|
14820
|
-
|
|
15066
|
+
new NodeVm.Script(preprocessedSource);
|
|
15067
|
+
return preprocessedSource;
|
|
14821
15068
|
} catch {
|
|
14822
15069
|
throw error;
|
|
14823
15070
|
}
|
|
14824
15071
|
}
|
|
14825
15072
|
};
|
|
14826
|
-
|
|
15073
|
+
function toFailure(value) {
|
|
15074
|
+
if (Object.prototype.toString.call(value) === "[object Error]") {
|
|
15075
|
+
const error = value;
|
|
15076
|
+
return {
|
|
15077
|
+
_tag: "Error",
|
|
15078
|
+
name: error.name,
|
|
15079
|
+
message: error.message,
|
|
15080
|
+
stack: error.stack
|
|
15081
|
+
};
|
|
15082
|
+
}
|
|
15083
|
+
try {
|
|
15084
|
+
return {
|
|
15085
|
+
_tag: "Value",
|
|
15086
|
+
value: structuredClone(value)
|
|
15087
|
+
};
|
|
15088
|
+
} catch {
|
|
15089
|
+
return {
|
|
15090
|
+
_tag: "Value",
|
|
15091
|
+
value: String(value)
|
|
15092
|
+
};
|
|
15093
|
+
}
|
|
15094
|
+
}
|
|
15095
|
+
function fromFailure(failure) {
|
|
15096
|
+
if (failure._tag === "Value") return failure.value;
|
|
15097
|
+
const error = new Error(failure.message);
|
|
15098
|
+
error.name = failure.name;
|
|
15099
|
+
if (failure.stack !== void 0) error.stack = failure.stack;
|
|
15100
|
+
return error;
|
|
15101
|
+
}
|
|
15102
|
+
function runScriptWorker(load) {
|
|
15103
|
+
const { parentPort, workerData } = load("node:worker_threads");
|
|
15104
|
+
const vm = load("node:vm");
|
|
15105
|
+
const { Console } = load("node:console");
|
|
15106
|
+
const { Writable: WorkerWritable } = load("node:stream");
|
|
15107
|
+
const port = parentPort;
|
|
15108
|
+
const data = workerData;
|
|
15109
|
+
process.on("uncaughtException", () => {});
|
|
15110
|
+
process.on("unhandledRejection", () => {});
|
|
15111
|
+
const post = (message) => port.postMessage(message);
|
|
15112
|
+
const pending = new Map();
|
|
15113
|
+
let nextId = 0;
|
|
15114
|
+
let mainSettled = false;
|
|
15115
|
+
let done = false;
|
|
15116
|
+
const maybeDone = () => {
|
|
15117
|
+
if (done || !mainSettled || pending.size > 0) return;
|
|
15118
|
+
setImmediate(() => {
|
|
15119
|
+
if (done || pending.size > 0) return;
|
|
15120
|
+
done = true;
|
|
15121
|
+
post({ _tag: "Done" });
|
|
15122
|
+
});
|
|
15123
|
+
};
|
|
15124
|
+
port.on("message", (message) => {
|
|
15125
|
+
const call = pending.get(message.id);
|
|
15126
|
+
if (call === void 0) return;
|
|
15127
|
+
pending.delete(message.id);
|
|
15128
|
+
if (message.ok) call.resolve(message.value);
|
|
15129
|
+
else call.reject(fromFailure(message.failure));
|
|
15130
|
+
maybeDone();
|
|
15131
|
+
});
|
|
15132
|
+
const sandbox = {
|
|
15133
|
+
console: new Console({
|
|
15134
|
+
stdout: new WorkerWritable({ write(chunk, _encoding, callback) {
|
|
15135
|
+
post({
|
|
15136
|
+
_tag: "Output",
|
|
15137
|
+
text: String(chunk)
|
|
15138
|
+
});
|
|
15139
|
+
callback();
|
|
15140
|
+
} }),
|
|
15141
|
+
colorMode: false
|
|
15142
|
+
}),
|
|
15143
|
+
fetch,
|
|
15144
|
+
process: void 0
|
|
15145
|
+
};
|
|
15146
|
+
for (const name of data.tools) sandbox[name] = (params) => new Promise((resolve, reject) => {
|
|
15147
|
+
const id = nextId++;
|
|
15148
|
+
pending.set(id, {
|
|
15149
|
+
resolve,
|
|
15150
|
+
reject
|
|
15151
|
+
});
|
|
15152
|
+
try {
|
|
15153
|
+
post({
|
|
15154
|
+
_tag: "Call",
|
|
15155
|
+
id,
|
|
15156
|
+
name,
|
|
15157
|
+
params
|
|
15158
|
+
});
|
|
15159
|
+
} catch (error) {
|
|
15160
|
+
pending.delete(id);
|
|
15161
|
+
reject(error);
|
|
15162
|
+
maybeDone();
|
|
15163
|
+
}
|
|
15164
|
+
});
|
|
15165
|
+
new vm.Script(data.source).runInNewContext(sandbox);
|
|
15166
|
+
sandbox.main().then(() => {
|
|
15167
|
+
mainSettled = true;
|
|
15168
|
+
maybeDone();
|
|
15169
|
+
}, (error) => post({
|
|
15170
|
+
_tag: "Failed",
|
|
15171
|
+
failure: toFailure(error)
|
|
15172
|
+
}));
|
|
15173
|
+
}
|
|
15174
|
+
const workerSource = `${toFailure}
|
|
15175
|
+
${fromFailure}
|
|
15176
|
+
(${runScriptWorker})(require)
|
|
15177
|
+
`;
|
|
14827
15178
|
const homeDirectory = () => {
|
|
14828
15179
|
const fromEnv = process.env.HOME;
|
|
14829
15180
|
if (fromEnv) return some(fromEnv);
|
|
@@ -18684,7 +19035,7 @@ const RequestResolverProto = {
|
|
|
18684
19035
|
}
|
|
18685
19036
|
};
|
|
18686
19037
|
const isRequestResolver = (u) => hasProperty(u, TypeId$3);
|
|
18687
|
-
const makeWith = (options) => {
|
|
19038
|
+
const makeWith$1 = (options) => {
|
|
18688
19039
|
const self = Object.create(RequestResolverProto);
|
|
18689
19040
|
self.batchKey = options.batchKey;
|
|
18690
19041
|
self.preCheck = options.preCheck;
|
|
@@ -18695,13 +19046,13 @@ const makeWith = (options) => {
|
|
|
18695
19046
|
};
|
|
18696
19047
|
const defaultKeyObject = {};
|
|
18697
19048
|
const defaultKey = (_request) => defaultKeyObject;
|
|
18698
|
-
const make$7 = (runAll) => makeWith({
|
|
19049
|
+
const make$7 = (runAll) => makeWith$1({
|
|
18699
19050
|
batchKey: defaultKey,
|
|
18700
19051
|
delay: yieldNow,
|
|
18701
19052
|
collectWhile: constTrue,
|
|
18702
19053
|
runAll
|
|
18703
19054
|
});
|
|
18704
|
-
const makeGrouped = (options) => makeWith({
|
|
19055
|
+
const makeGrouped = (options) => makeWith$1({
|
|
18705
19056
|
batchKey: hashGroupKey(options.key),
|
|
18706
19057
|
delay: yieldNow,
|
|
18707
19058
|
collectWhile: constTrue,
|
|
@@ -18712,18 +19063,18 @@ const hashGroupKey = (get) => {
|
|
|
18712
19063
|
equalBatchKeys.add(batchKey);
|
|
18713
19064
|
return batchKey;
|
|
18714
19065
|
};
|
|
18715
|
-
const setDelay = dual(2, (self, duration) => makeWith({
|
|
19066
|
+
const setDelay = dual(2, (self, duration) => makeWith$1({
|
|
18716
19067
|
...self,
|
|
18717
19068
|
delay: sleep(duration)
|
|
18718
19069
|
}));
|
|
18719
19070
|
const batchN = dual(2, (self, n) => {
|
|
18720
19071
|
const size = normalizeNonEmpty(n);
|
|
18721
|
-
return makeWith({
|
|
19072
|
+
return makeWith$1({
|
|
18722
19073
|
...self,
|
|
18723
19074
|
collectWhile: (requests) => requests.size < size
|
|
18724
19075
|
});
|
|
18725
19076
|
});
|
|
18726
|
-
const withSpan = dual((args) => isRequestResolver(args[0]), (self, name, options) => makeWith({
|
|
19077
|
+
const withSpan = dual((args) => isRequestResolver(args[0]), (self, name, options) => makeWith$1({
|
|
18727
19078
|
...self,
|
|
18728
19079
|
runAll: (entries, key) => suspend(() => {
|
|
18729
19080
|
const opts = typeof options === "function" ? options(entries) : options;
|
|
@@ -21295,7 +21646,8 @@ var SubagentStart = class extends TaggedClass$2()("SubagentStart", {
|
|
|
21295
21646
|
id: Number$2,
|
|
21296
21647
|
prompt: String$5,
|
|
21297
21648
|
model: String$5,
|
|
21298
|
-
provider: String$5
|
|
21649
|
+
provider: String$5,
|
|
21650
|
+
background: Boolean$4.pipe(withDecodingDefaultKey(succeed$1(false)), withConstructorDefault(succeed$1(false)))
|
|
21299
21651
|
}) {
|
|
21300
21652
|
get modelAndProvider() {
|
|
21301
21653
|
return `${this.provider}/${this.model}`;
|
|
@@ -21303,7 +21655,12 @@ var SubagentStart = class extends TaggedClass$2()("SubagentStart", {
|
|
|
21303
21655
|
};
|
|
21304
21656
|
var SubagentComplete = class extends TaggedClass$2()("SubagentComplete", {
|
|
21305
21657
|
id: Number$2,
|
|
21306
|
-
summary: String$5
|
|
21658
|
+
summary: String$5,
|
|
21659
|
+
status: Literals$2([
|
|
21660
|
+
"completed",
|
|
21661
|
+
"failed",
|
|
21662
|
+
"cancelled"
|
|
21663
|
+
]).pipe(withDecodingDefaultKey(succeed$1("completed")), withConstructorDefault(succeed$1("completed")))
|
|
21307
21664
|
}) {};
|
|
21308
21665
|
var ExecuteOutputCapped = class extends TaggedClass$2()("ExecuteOutputCapped", {
|
|
21309
21666
|
charsBefore: Number$2,
|
|
@@ -21334,61 +21691,87 @@ var SubagentPart = class extends TaggedClass$2()("SubagentPart", {
|
|
|
21334
21691
|
id: Number$2,
|
|
21335
21692
|
part: ContentPart
|
|
21336
21693
|
}) {};
|
|
21694
|
+
var HistoryAppended = class extends TaggedClass$2()("HistoryAppended", { messages: ArraySchema(Message) }) {};
|
|
21695
|
+
var HistoryReplaced = class extends TaggedClass$2()("HistoryReplaced", { messages: ArraySchema(Message) }) {};
|
|
21337
21696
|
const Output = Union([
|
|
21338
21697
|
...ContentPart.members,
|
|
21339
21698
|
AgentStart,
|
|
21340
21699
|
SubagentStart,
|
|
21341
21700
|
SubagentComplete,
|
|
21342
|
-
SubagentPart
|
|
21701
|
+
SubagentPart,
|
|
21702
|
+
HistoryAppended,
|
|
21703
|
+
HistoryReplaced
|
|
21343
21704
|
]);
|
|
21344
21705
|
var AgentFinished = class extends TaggedError$1()("AgentFinished", { summary: String$5 }) {};
|
|
21706
|
+
var RetriesExhausted = class extends TaggedError$1()("RetriesExhausted", {
|
|
21707
|
+
retries: Number$2,
|
|
21708
|
+
error: AiError
|
|
21709
|
+
}) {};
|
|
21345
21710
|
//#endregion
|
|
21346
21711
|
//#region src/Agent.ts
|
|
21347
21712
|
const TypeId = "~clanka/Agent";
|
|
21348
21713
|
const Agent = Service("clanka/Agent");
|
|
21349
|
-
const
|
|
21714
|
+
const makeWith = fnUntraced(function* (options) {
|
|
21350
21715
|
const executor = yield* AgentExecutor;
|
|
21351
21716
|
const singleTool = yield* SingleTools.pipe(provide$1(SingleToolHandlers));
|
|
21352
21717
|
const capabilities = yield* executor.capabilities;
|
|
21353
|
-
const
|
|
21354
|
-
|
|
21355
|
-
|
|
21356
|
-
|
|
21357
|
-
|
|
21358
|
-
|
|
21359
|
-
|
|
21360
|
-
|
|
21361
|
-
|
|
21362
|
-
|
|
21363
|
-
|
|
21718
|
+
const loopTools = yield* makeLoopTools({
|
|
21719
|
+
loopTools: options.loopTools,
|
|
21720
|
+
skills: options.skills,
|
|
21721
|
+
executorTools: capabilities.tools
|
|
21722
|
+
});
|
|
21723
|
+
const promptTools = {
|
|
21724
|
+
toolsDts: loopTools.dts === "" ? capabilities.toolsDts : `${capabilities.toolsDts}\n\n${loopTools.dts}`,
|
|
21725
|
+
offers: (name) => capabilities.tools.includes(name),
|
|
21726
|
+
skillsCatalog: options.skills === void 0 ? renderCatalog(capabilities.skills) : renderProvidedCatalog(options.skills)
|
|
21727
|
+
};
|
|
21728
|
+
const rootMailbox = makeMailbox();
|
|
21729
|
+
const agentsMd = options.instructions === void 0 ? map$8(capabilities.agentsMd, renderAgentsMd) : map$8(options.instructions, renderInstructions);
|
|
21364
21730
|
let agentCounter = 0;
|
|
21365
21731
|
const outputBuffer = new Map();
|
|
21366
21732
|
let currentOutputAgent = null;
|
|
21367
|
-
const history = make$
|
|
21733
|
+
const history = make$44(empty$1);
|
|
21368
21734
|
const spawn = fnUntraced(function* (opts) {
|
|
21369
21735
|
const agentId = opts.agentId;
|
|
21370
21736
|
const ai = yield* LanguageModel;
|
|
21371
|
-
const subagentModel = yield* SubagentModel;
|
|
21737
|
+
const subagentModel = yield* serviceOption(SubagentModel);
|
|
21372
21738
|
const modelConfig = yield* AgentModelConfig;
|
|
21373
21739
|
const conversationMode = yield* ConversationMode;
|
|
21374
21740
|
const turnTimeout = yield* TurnTimeout;
|
|
21741
|
+
const maxRetries = yield* MaxRetries;
|
|
21375
21742
|
let finalSummary = none();
|
|
21376
21743
|
let lastContextTokens = void 0;
|
|
21377
21744
|
let sendImages = modelConfig.supportsImages !== false;
|
|
21378
21745
|
const pendingImages = [];
|
|
21379
|
-
const output = yield* make$
|
|
21746
|
+
const output = yield* make$45();
|
|
21380
21747
|
let inputTokens = 0;
|
|
21381
21748
|
let outputTokens = 0;
|
|
21382
21749
|
let cacheRead = 0;
|
|
21383
21750
|
let cacheWrite = 0;
|
|
21384
|
-
const prompt = opts.
|
|
21751
|
+
const prompt = opts.history;
|
|
21752
|
+
const mailbox = opts.mailbox;
|
|
21753
|
+
const appendHistory = (input) => {
|
|
21754
|
+
update(prompt, concat(input));
|
|
21755
|
+
if (!opts.historyEvents) return;
|
|
21756
|
+
const messages = input.content.filter((message) => message.role !== "system");
|
|
21757
|
+
if (messages.length > 0) offerUnsafe(output, new HistoryAppended({ messages }));
|
|
21758
|
+
};
|
|
21759
|
+
const replaceHistory = (next) => {
|
|
21760
|
+
set$1(prompt, next);
|
|
21761
|
+
if (!opts.historyEvents) return;
|
|
21762
|
+
offerUnsafe(output, new HistoryReplaced({ messages: next.content.filter((message) => message.role !== "system") }));
|
|
21763
|
+
};
|
|
21385
21764
|
update(prompt, concat(opts.prompt));
|
|
21386
21765
|
let system = (typeof opts.system === "function" ? opts.system : defaultSystem)({
|
|
21387
|
-
toolInstructions: generateSystemTools(
|
|
21766
|
+
toolInstructions: generateSystemTools(promptTools, conversationMode),
|
|
21388
21767
|
agentsMd: getOrElse(agentsMd, () => "")
|
|
21389
21768
|
});
|
|
21390
21769
|
if (typeof opts.system === "string") system += `\n${opts.system}\n`;
|
|
21391
21770
|
function maybeSend(options) {
|
|
21771
|
+
if (!opts.display) {
|
|
21772
|
+
offerUnsafe(output, options.part);
|
|
21773
|
+
return;
|
|
21774
|
+
}
|
|
21392
21775
|
if (currentOutputAgent === null || currentOutputAgent === opts.agentId) {
|
|
21393
21776
|
offerUnsafe(output, options.part);
|
|
21394
21777
|
if (options.acquire) currentOutputAgent = opts.agentId;
|
|
@@ -21413,48 +21796,194 @@ ${content}
|
|
|
21413
21796
|
}
|
|
21414
21797
|
state.push(options.part);
|
|
21415
21798
|
}
|
|
21416
|
-
const
|
|
21417
|
-
|
|
21799
|
+
const runScope = yield* make$43();
|
|
21800
|
+
const runContext = yield* context();
|
|
21801
|
+
const provideSubagentModel = (effect) => match$2(subagentModel, {
|
|
21802
|
+
onNone: () => effect,
|
|
21803
|
+
onSome: (model) => effect.pipe(provide$1(model), provideService(SubagentModel, model))
|
|
21804
|
+
});
|
|
21805
|
+
const children = new Map();
|
|
21806
|
+
const completions = [];
|
|
21807
|
+
let wakeUp;
|
|
21808
|
+
const notify = () => {
|
|
21809
|
+
const resume = wakeUp;
|
|
21810
|
+
wakeUp = void 0;
|
|
21811
|
+
resume?.();
|
|
21812
|
+
};
|
|
21813
|
+
mailbox.notify = notify;
|
|
21814
|
+
const runningChildren = () => Array$1.from(children.values()).filter((child) => child.turn.status === "running");
|
|
21815
|
+
const hasUndelivered = () => completions.some((turn) => !turn.delivered);
|
|
21816
|
+
const finishTurn = (turn, exit) => sync(() => {
|
|
21817
|
+
if (isSuccess(exit)) {
|
|
21818
|
+
turn.status = "completed";
|
|
21819
|
+
turn.output = exit.value;
|
|
21820
|
+
} else if (hasInterruptsOnly(exit.cause)) turn.status = "cancelled";
|
|
21821
|
+
else {
|
|
21822
|
+
turn.status = "failed";
|
|
21823
|
+
turn.output = causeMessage(exit.cause);
|
|
21824
|
+
}
|
|
21825
|
+
offerUnsafe(output, new SubagentComplete({
|
|
21826
|
+
id: turn.agentId,
|
|
21827
|
+
summary: turn.output ?? "",
|
|
21828
|
+
status: turn.status
|
|
21829
|
+
}));
|
|
21830
|
+
if (!turn.delivered) completions.push(turn);
|
|
21831
|
+
doneUnsafe(turn.done, void_);
|
|
21832
|
+
notify();
|
|
21833
|
+
});
|
|
21834
|
+
const startTurn = fnUntraced(function* (options) {
|
|
21835
|
+
const { child } = options;
|
|
21836
|
+
const turn = child.turn;
|
|
21837
|
+
const display = opts.display && !options.background;
|
|
21418
21838
|
const stream = spawn({
|
|
21419
|
-
agentId: id,
|
|
21420
|
-
prompt: make$20(prompt),
|
|
21839
|
+
agentId: child.id,
|
|
21840
|
+
prompt: make$20(options.prompt),
|
|
21421
21841
|
system: opts.system,
|
|
21422
|
-
|
|
21842
|
+
history: child.history,
|
|
21843
|
+
mailbox: child.mailbox,
|
|
21844
|
+
display,
|
|
21845
|
+
historyEvents: false
|
|
21423
21846
|
});
|
|
21424
|
-
|
|
21425
|
-
|
|
21426
|
-
|
|
21427
|
-
|
|
21428
|
-
|
|
21429
|
-
|
|
21847
|
+
turn.fiber = yield* gen(function* () {
|
|
21848
|
+
maybeSend({
|
|
21849
|
+
agentId: opts.agentId,
|
|
21850
|
+
part: new SubagentStart({
|
|
21851
|
+
id: child.id,
|
|
21852
|
+
prompt: options.label,
|
|
21853
|
+
model: yield* ModelName,
|
|
21854
|
+
provider: yield* ProviderName,
|
|
21855
|
+
background: options.background
|
|
21856
|
+
}),
|
|
21857
|
+
release: true
|
|
21858
|
+
});
|
|
21859
|
+
return yield* stream.pipe(runForEachArray((parts) => {
|
|
21860
|
+
for (const part of parts) switch (part._tag) {
|
|
21861
|
+
case "AgentStart":
|
|
21862
|
+
case "HistoryAppended":
|
|
21863
|
+
case "HistoryReplaced": break;
|
|
21864
|
+
case "SubagentStart":
|
|
21865
|
+
case "SubagentComplete":
|
|
21866
|
+
offerUnsafe(output, part);
|
|
21867
|
+
break;
|
|
21868
|
+
default:
|
|
21869
|
+
if (!display) break;
|
|
21870
|
+
offerUnsafe(output, part._tag === "SubagentPart" ? part : new SubagentPart({
|
|
21871
|
+
id: child.id,
|
|
21872
|
+
part
|
|
21873
|
+
}));
|
|
21874
|
+
}
|
|
21875
|
+
return void_;
|
|
21876
|
+
}), as(""), catchTag("AgentFinished", (finished) => succeed$1(finished.summary)));
|
|
21877
|
+
}).pipe(onExit((exit) => finishTurn(turn, exit)), provideSubagentModel, provideContext(runContext), forkIn(runScope, { startImmediately: true }));
|
|
21878
|
+
});
|
|
21879
|
+
const childResult = ({ id, turn }) => turn.output === void 0 ? {
|
|
21880
|
+
id: String(id),
|
|
21881
|
+
status: turn.status
|
|
21882
|
+
} : {
|
|
21883
|
+
id: String(id),
|
|
21884
|
+
status: turn.status,
|
|
21885
|
+
output: turn.output
|
|
21886
|
+
};
|
|
21887
|
+
const lookupChild = (id) => suspend(() => {
|
|
21888
|
+
const child = children.get(id);
|
|
21889
|
+
return child ? succeed$1(child) : fail$1(`Unknown agent id ${JSON.stringify(id)}. You can only address agents you started; call listAgents() to see them.`);
|
|
21890
|
+
});
|
|
21891
|
+
const subagents = {
|
|
21892
|
+
delegate: fnUntraced(function* ({ prompt, background }) {
|
|
21893
|
+
const agentId = agentCounter++;
|
|
21894
|
+
const child = {
|
|
21895
|
+
id: agentId,
|
|
21430
21896
|
prompt,
|
|
21431
|
-
|
|
21432
|
-
|
|
21433
|
-
|
|
21434
|
-
|
|
21435
|
-
|
|
21436
|
-
|
|
21437
|
-
|
|
21438
|
-
|
|
21439
|
-
|
|
21440
|
-
|
|
21441
|
-
|
|
21442
|
-
|
|
21443
|
-
|
|
21444
|
-
|
|
21445
|
-
|
|
21446
|
-
|
|
21447
|
-
}));
|
|
21448
|
-
}
|
|
21449
|
-
return void_;
|
|
21450
|
-
}), as(""), catchTag("AgentFinished", (finished) => {
|
|
21451
|
-
offerUnsafe(output, new SubagentComplete({
|
|
21897
|
+
history: make$44(empty$1),
|
|
21898
|
+
mailbox: makeMailbox(),
|
|
21899
|
+
turn: makeTurn(agentId, background)
|
|
21900
|
+
};
|
|
21901
|
+
const id = String(child.id);
|
|
21902
|
+
children.set(id, child);
|
|
21903
|
+
const turn = child.turn;
|
|
21904
|
+
yield* startTurn({
|
|
21905
|
+
child,
|
|
21906
|
+
label: prompt,
|
|
21907
|
+
prompt: `You have been asked using the "delegate" function to complete the following task. Try to avoid using the "delegate" function yourself unless strictly necessary:
|
|
21908
|
+
|
|
21909
|
+
${prompt}`,
|
|
21910
|
+
background
|
|
21911
|
+
});
|
|
21912
|
+
if (background) return {
|
|
21452
21913
|
id,
|
|
21453
|
-
|
|
21454
|
-
}
|
|
21455
|
-
|
|
21456
|
-
|
|
21457
|
-
|
|
21914
|
+
status: "running"
|
|
21915
|
+
};
|
|
21916
|
+
yield* _await(turn.done).pipe(onInterrupt(() => interrupt$2(turn.fiber)));
|
|
21917
|
+
if (turn.status !== "completed") return yield* die(new Error(`Sub-agent ${child.id} ${turn.status}${turn.output ? `: ${turn.output}` : ""}`));
|
|
21918
|
+
return {
|
|
21919
|
+
id,
|
|
21920
|
+
status: "completed",
|
|
21921
|
+
output: turn.output ?? ""
|
|
21922
|
+
};
|
|
21923
|
+
}),
|
|
21924
|
+
waitAgents: fnUntraced(function* (ids) {
|
|
21925
|
+
const targets = ids === void 0 ? Array$1.from(children.values()) : yield* forEach$1(ids, lookupChild);
|
|
21926
|
+
while (true) {
|
|
21927
|
+
const running = targets.find((child) => child.turn.status === "running");
|
|
21928
|
+
if (!running) break;
|
|
21929
|
+
yield* _await(running.turn.done);
|
|
21930
|
+
}
|
|
21931
|
+
return targets.map((child) => {
|
|
21932
|
+
child.turn.delivered = true;
|
|
21933
|
+
return childResult(child);
|
|
21934
|
+
});
|
|
21935
|
+
}),
|
|
21936
|
+
messageAgent: fnUntraced(function* ({ id, message }) {
|
|
21937
|
+
const child = yield* lookupChild(id);
|
|
21938
|
+
if (child.turn.status === "running") {
|
|
21939
|
+
child.mailbox.messages.add({
|
|
21940
|
+
message,
|
|
21941
|
+
resume: () => {}
|
|
21942
|
+
});
|
|
21943
|
+
child.mailbox.notify();
|
|
21944
|
+
return childResult(child);
|
|
21945
|
+
}
|
|
21946
|
+
child.turn = makeTurn(child.id, true);
|
|
21947
|
+
yield* startTurn({
|
|
21948
|
+
child,
|
|
21949
|
+
prompt: message,
|
|
21950
|
+
label: message,
|
|
21951
|
+
background: true
|
|
21952
|
+
});
|
|
21953
|
+
return childResult(child);
|
|
21954
|
+
}),
|
|
21955
|
+
stopAgent: fnUntraced(function* (id) {
|
|
21956
|
+
const child = yield* lookupChild(id);
|
|
21957
|
+
const turn = child.turn;
|
|
21958
|
+
turn.delivered = true;
|
|
21959
|
+
if (turn.status === "running") yield* interrupt$2(turn.fiber);
|
|
21960
|
+
return childResult(child);
|
|
21961
|
+
}),
|
|
21962
|
+
listAgents: sync(() => Array$1.from(children.values(), (child) => ({
|
|
21963
|
+
id: String(child.id),
|
|
21964
|
+
status: child.turn.status,
|
|
21965
|
+
prompt: child.prompt
|
|
21966
|
+
})))
|
|
21967
|
+
};
|
|
21968
|
+
const onTaskComplete = (summary) => suspend(() => {
|
|
21969
|
+
const running = runningChildren();
|
|
21970
|
+
if (running.length > 0) {
|
|
21971
|
+
const ids = running.map((child) => JSON.stringify(String(child.id)));
|
|
21972
|
+
return fail$1(`taskComplete was rejected: sub-agents ${ids.join(", ")} are still running. Call waitAgents() to wait for them, or stopAgent(id) to stop them, before calling taskComplete.`);
|
|
21973
|
+
}
|
|
21974
|
+
finalSummary = some(summary);
|
|
21975
|
+
return void_;
|
|
21976
|
+
});
|
|
21977
|
+
const waitForActivity = callback((resume) => {
|
|
21978
|
+
if (mailbox.messages.size > 0 || hasUndelivered() || runningChildren().length === 0) {
|
|
21979
|
+
resume(void_);
|
|
21980
|
+
return;
|
|
21981
|
+
}
|
|
21982
|
+
wakeUp = () => resume(void_);
|
|
21983
|
+
return sync(() => {
|
|
21984
|
+
wakeUp = void 0;
|
|
21985
|
+
});
|
|
21986
|
+
});
|
|
21458
21987
|
const clock = yield* Clock;
|
|
21459
21988
|
const turnTimeoutMs = toMillis(turnTimeout);
|
|
21460
21989
|
let turnExpires = 0;
|
|
@@ -21494,7 +22023,7 @@ ${content}
|
|
|
21494
22023
|
let tokensBefore;
|
|
21495
22024
|
let tokensAfter;
|
|
21496
22025
|
if (isSome(result)) {
|
|
21497
|
-
|
|
22026
|
+
replaceHistory(result.value.prompt);
|
|
21498
22027
|
lastContextTokens = void 0;
|
|
21499
22028
|
tokensBefore = result.value.tokensBefore;
|
|
21500
22029
|
tokensAfter = result.value.tokensAfter;
|
|
@@ -21518,13 +22047,12 @@ ${content}
|
|
|
21518
22047
|
const normalizedScript = stripWrappingCodeFence(script);
|
|
21519
22048
|
const output = yield* pipe(executor.execute({
|
|
21520
22049
|
script: normalizedScript,
|
|
21521
|
-
|
|
21522
|
-
onTaskComplete
|
|
21523
|
-
finalSummary = some(summary);
|
|
21524
|
-
}),
|
|
22050
|
+
subagents,
|
|
22051
|
+
onTaskComplete,
|
|
21525
22052
|
onImage: (image) => sync(() => {
|
|
21526
22053
|
pendingImages.push(image);
|
|
21527
|
-
})
|
|
22054
|
+
}),
|
|
22055
|
+
loopTools: loopTools.handlers
|
|
21528
22056
|
}), mkString);
|
|
21529
22057
|
const capped = capOutput(output);
|
|
21530
22058
|
if (capped.capped) maybeSend({
|
|
@@ -21541,21 +22069,44 @@ ${content}
|
|
|
21541
22069
|
return capped.output;
|
|
21542
22070
|
}, ensuring(toolLatchRelease));
|
|
21543
22071
|
if (!modelConfig.systemPromptTransform) update(prompt, setSystem(system));
|
|
22072
|
+
yield* offer(output, new AgentStart({
|
|
22073
|
+
id: opts.agentId,
|
|
22074
|
+
prompt: opts.prompt,
|
|
22075
|
+
provider: yield* ProviderName,
|
|
22076
|
+
model: yield* ModelName
|
|
22077
|
+
}));
|
|
22078
|
+
if (opts.historyEvents) {
|
|
22079
|
+
const messages = opts.prompt.content.filter((message) => message.role !== "system");
|
|
22080
|
+
if (messages.length > 0) yield* offer(output, new HistoryAppended({ messages }));
|
|
22081
|
+
}
|
|
21544
22082
|
yield* gen(function* () {
|
|
21545
22083
|
while (true) {
|
|
21546
22084
|
if (isSome(finalSummary)) {
|
|
21547
22085
|
yield* fail$6(output, new AgentFinished({ summary: finalSummary.value }));
|
|
21548
22086
|
return;
|
|
21549
22087
|
}
|
|
21550
|
-
if (
|
|
21551
|
-
|
|
22088
|
+
if (mailbox.messages.size > 0) {
|
|
22089
|
+
appendHistory(make$20(Array$1.from(mailbox.messages, ({ message, resume }) => {
|
|
21552
22090
|
resume(void_);
|
|
21553
22091
|
return {
|
|
21554
22092
|
role: "user",
|
|
21555
22093
|
content: message
|
|
21556
22094
|
};
|
|
21557
22095
|
})));
|
|
21558
|
-
|
|
22096
|
+
mailbox.messages.clear();
|
|
22097
|
+
}
|
|
22098
|
+
if (completions.length > 0) {
|
|
22099
|
+
const pushes = completions.splice(0).filter((turn) => {
|
|
22100
|
+
if (turn.delivered) return false;
|
|
22101
|
+
turn.delivered = true;
|
|
22102
|
+
return true;
|
|
22103
|
+
});
|
|
22104
|
+
if (pushes.length > 0) appendHistory(make$20(pushes.map((turn) => ({
|
|
22105
|
+
role: "user",
|
|
22106
|
+
content: `<subagent id="${turn.agentId}" status="${turn.status}">
|
|
22107
|
+
${capOutput(turn.output ?? "").output}
|
|
22108
|
+
</subagent>`
|
|
22109
|
+
}))));
|
|
21559
22110
|
}
|
|
21560
22111
|
yield* compactWithEvents("threshold", compactIfNeeded({
|
|
21561
22112
|
prompt: prompt.current,
|
|
@@ -21570,11 +22121,25 @@ ${content}
|
|
|
21570
22121
|
let reasoningStarted = false;
|
|
21571
22122
|
let hadReasoningDelta = false;
|
|
21572
22123
|
let hadToolCall = false;
|
|
22124
|
+
let retries = 0;
|
|
22125
|
+
let exhaustedBy;
|
|
22126
|
+
const retryOrExhaust = (error) => {
|
|
22127
|
+
if (retries >= maxRetries) {
|
|
22128
|
+
exhaustedBy = error;
|
|
22129
|
+
return false;
|
|
22130
|
+
}
|
|
22131
|
+
retries++;
|
|
22132
|
+
maybeSend({
|
|
22133
|
+
agentId,
|
|
22134
|
+
part: new ErrorRetry({ error })
|
|
22135
|
+
});
|
|
22136
|
+
return true;
|
|
22137
|
+
};
|
|
21573
22138
|
const runModel = pipe(suspend$1(() => ai.streamText({
|
|
21574
22139
|
prompt: sendImages ? prompt.current : stripImages(prompt.current),
|
|
21575
22140
|
toolkit: singleTool
|
|
21576
22141
|
})), takeUntil((part) => {
|
|
21577
|
-
if ((part.type === "text-end" || part.type === "reasoning-end") &&
|
|
22142
|
+
if ((part.type === "text-end" || part.type === "reasoning-end") && mailbox.messages.size > 0) return true;
|
|
21578
22143
|
return false;
|
|
21579
22144
|
}), runForEachArray((parts) => {
|
|
21580
22145
|
response.push(...parts);
|
|
@@ -21639,28 +22204,20 @@ ${content}
|
|
|
21639
22204
|
const attempt = pipe(runModel, raceFirst(turnTimeoutEffect), retry({
|
|
21640
22205
|
while(err) {
|
|
21641
22206
|
if (err._tag === "TimeoutError") {
|
|
21642
|
-
maybeSend({
|
|
21643
|
-
agentId,
|
|
21644
|
-
part: new ErrorRetry({ error: make$18({
|
|
21645
|
-
module: "clanka/Agent",
|
|
21646
|
-
method: "send",
|
|
21647
|
-
reason: new UnknownError({ description: "TurnTimeout was reached" })
|
|
21648
|
-
}) })
|
|
21649
|
-
});
|
|
21650
22207
|
discardAttempt();
|
|
21651
|
-
return
|
|
22208
|
+
return retryOrExhaust(turnTimeoutError);
|
|
21652
22209
|
}
|
|
21653
22210
|
if (isContextLengthError(err)) return false;
|
|
21654
22211
|
if (err.isRetryable) {
|
|
21655
|
-
|
|
21656
|
-
|
|
21657
|
-
|
|
21658
|
-
}
|
|
22212
|
+
if (!retryOrExhaust(err)) {
|
|
22213
|
+
discardAttempt();
|
|
22214
|
+
return false;
|
|
22215
|
+
}
|
|
21659
22216
|
switch (err.reason._tag) {
|
|
21660
22217
|
case "ToolNotFoundError":
|
|
21661
22218
|
case "InvalidOutputError": {
|
|
21662
22219
|
const toAppend = fromResponseParts(response).pipe(concat(`There was an error, please try again using the "execute" tool:\n\n${pretty(fail$4(err))}`));
|
|
21663
|
-
|
|
22220
|
+
appendHistory(toAppend);
|
|
21664
22221
|
}
|
|
21665
22222
|
}
|
|
21666
22223
|
}
|
|
@@ -21668,8 +22225,11 @@ ${content}
|
|
|
21668
22225
|
return err.isRetryable;
|
|
21669
22226
|
},
|
|
21670
22227
|
schedule: retryPolicy
|
|
21671
|
-
}),
|
|
21672
|
-
|
|
22228
|
+
}), catchIf(() => exhaustedBy !== void 0, () => fail$1(new RetriesExhausted({
|
|
22229
|
+
retries,
|
|
22230
|
+
error: exhaustedBy
|
|
22231
|
+
}))), catchTag("TimeoutError", die));
|
|
22232
|
+
const attemptWithImageFallback = attempt.pipe(catchIf((err) => err._tag === "AiError" && sendImages && hasImages(prompt.current) && isUnsupportedImageError(err), (err) => {
|
|
21673
22233
|
sendImages = false;
|
|
21674
22234
|
discardAttempt();
|
|
21675
22235
|
maybeSend({
|
|
@@ -21678,7 +22238,7 @@ ${content}
|
|
|
21678
22238
|
});
|
|
21679
22239
|
return attempt;
|
|
21680
22240
|
}));
|
|
21681
|
-
yield* attemptWithImageFallback.pipe(catchIf((err) => isContextLengthError(err), (err) => gen(function* () {
|
|
22241
|
+
yield* attemptWithImageFallback.pipe(catchIf((err) => err._tag === "AiError" && isContextLengthError(err), (err) => gen(function* () {
|
|
21682
22242
|
discardAttempt();
|
|
21683
22243
|
const compacted = yield* compactWithEvents("overflow", compact({
|
|
21684
22244
|
prompt: prompt.current,
|
|
@@ -21690,12 +22250,18 @@ ${content}
|
|
|
21690
22250
|
}), catchTag("TimeoutError", die)));
|
|
21691
22251
|
return isSome(compacted) ? yield* attemptWithImageFallback : yield* err;
|
|
21692
22252
|
})));
|
|
21693
|
-
|
|
22253
|
+
appendHistory(fromResponseParts(response));
|
|
21694
22254
|
if (pendingImages.length > 0) {
|
|
21695
|
-
|
|
22255
|
+
appendHistory(fromMessages([userMessage(pendingImages)]));
|
|
21696
22256
|
pendingImages.length = 0;
|
|
21697
22257
|
}
|
|
21698
|
-
if (conversationMode && !hadToolCall &&
|
|
22258
|
+
if (conversationMode && !hadToolCall && mailbox.messages.size === 0) {
|
|
22259
|
+
if (runningChildren().length > 0 || hasUndelivered()) {
|
|
22260
|
+
yield* waitForActivity;
|
|
22261
|
+
continue;
|
|
22262
|
+
}
|
|
22263
|
+
finalSummary = some(responseToSummary(response));
|
|
22264
|
+
}
|
|
21699
22265
|
}
|
|
21700
22266
|
}).pipe(provideService(ScriptExecutor, (script) => {
|
|
21701
22267
|
maybeSend({
|
|
@@ -21707,13 +22273,7 @@ ${content}
|
|
|
21707
22273
|
part: new ScriptDelta({ delta: script })
|
|
21708
22274
|
});
|
|
21709
22275
|
return executeScript(script);
|
|
21710
|
-
}), catchCause((cause) => failCause$2(output, cause)), forkScoped);
|
|
21711
|
-
yield* offer(output, new AgentStart({
|
|
21712
|
-
id: opts.agentId,
|
|
21713
|
-
prompt: opts.prompt,
|
|
21714
|
-
provider: yield* ProviderName,
|
|
21715
|
-
model: yield* ModelName
|
|
21716
|
-
}));
|
|
22276
|
+
}), ensuring(close(runScope, void_$1)), catchCause((cause) => failCause$2(output, cause)), forkScoped);
|
|
21717
22277
|
return fromQueue(output);
|
|
21718
22278
|
}, unwrap$3);
|
|
21719
22279
|
const sendLock = makeUnsafe$5(1);
|
|
@@ -21723,7 +22283,11 @@ ${content}
|
|
|
21723
22283
|
send: (options) => spawn({
|
|
21724
22284
|
agentId: agentCounter++,
|
|
21725
22285
|
prompt: make$20(options.prompt),
|
|
21726
|
-
system: options.system
|
|
22286
|
+
system: options.system,
|
|
22287
|
+
history,
|
|
22288
|
+
mailbox: rootMailbox,
|
|
22289
|
+
display: true,
|
|
22290
|
+
historyEvents: true
|
|
21727
22291
|
}).pipe(broadcast({
|
|
21728
22292
|
capacity: "unbounded",
|
|
21729
22293
|
replay: 1
|
|
@@ -21733,30 +22297,85 @@ ${content}
|
|
|
21733
22297
|
message,
|
|
21734
22298
|
resume
|
|
21735
22299
|
};
|
|
21736
|
-
|
|
21737
|
-
|
|
22300
|
+
rootMailbox.messages.add(entry);
|
|
22301
|
+
rootMailbox.notify();
|
|
22302
|
+
return sync(() => rootMailbox.messages.delete(entry));
|
|
21738
22303
|
})
|
|
21739
22304
|
});
|
|
21740
22305
|
});
|
|
22306
|
+
const make$2 = makeWith({});
|
|
22307
|
+
const makeMailbox = () => ({
|
|
22308
|
+
messages: new Set(),
|
|
22309
|
+
notify: () => {}
|
|
22310
|
+
});
|
|
22311
|
+
const makeTurn = (agentId, background) => ({
|
|
22312
|
+
agentId,
|
|
22313
|
+
status: "running",
|
|
22314
|
+
output: void 0,
|
|
22315
|
+
delivered: !background,
|
|
22316
|
+
done: makeUnsafe$2(),
|
|
22317
|
+
fiber: void 0
|
|
22318
|
+
});
|
|
22319
|
+
const causeMessage = (cause) => errorMessage(squash(cause));
|
|
22320
|
+
const turnTimeoutError = make$18({
|
|
22321
|
+
module: "clanka/Agent",
|
|
22322
|
+
method: "send",
|
|
22323
|
+
reason: new UnknownError({ description: "TurnTimeout was reached" })
|
|
22324
|
+
});
|
|
21741
22325
|
const retryPolicy = min([exponential(100, 1.5), spaced(5e3)]).pipe(jittered);
|
|
22326
|
+
const renderAgentsMd = (content) => `# AGENTS.md
|
|
22327
|
+
|
|
22328
|
+
The following instructions are from ./AGENTS.md in the current directory.
|
|
22329
|
+
You do not need to read this file again.
|
|
22330
|
+
|
|
22331
|
+
**ALWAYS follow these instructions when completing tasks**:
|
|
22332
|
+
|
|
22333
|
+
<!-- AGENTS.md start -->
|
|
22334
|
+
${content}
|
|
22335
|
+
<!-- AGENTS.md end -->`;
|
|
22336
|
+
const renderInstructions = (content) => `# Project instructions
|
|
22337
|
+
|
|
22338
|
+
**ALWAYS follow these instructions when completing tasks**:
|
|
22339
|
+
|
|
22340
|
+
<!-- instructions start -->
|
|
22341
|
+
${content}
|
|
22342
|
+
<!-- instructions end -->`;
|
|
21742
22343
|
const defaultSystem = (options) => `You are a world-class software engineer: precise and efficient.
|
|
21743
22344
|
|
|
21744
22345
|
${options.toolInstructions}
|
|
21745
22346
|
|
|
21746
22347
|
${options.agentsMd}
|
|
21747
22348
|
`;
|
|
21748
|
-
const
|
|
22349
|
+
const when = (condition, text) => condition ? text : "";
|
|
22350
|
+
const generateSystemTools = (tools, conversationMode) => `YOU ONLY HAVE ONE TOOL AVAILABLE: "execute", to run javascript code to do your work.
|
|
21749
22351
|
|
|
21750
22352
|
- Use \`console.log\` to print any output you need.
|
|
21751
|
-
- Use top level await.${
|
|
21752
|
-
- Prefer using the "search" function over "rg", unless you are targeting specific files or patterns.`
|
|
21753
|
-
- You can add / update / remove multiple files in one go with "applyPatch".
|
|
21754
|
-
- Avoid passing scripts into the "bash" function, and instead write javascript
|
|
22353
|
+
- Use top level await.${when(tools.offers("search") && tools.offers("rg"), `
|
|
22354
|
+
- Prefer using the "search" function over "rg", unless you are targeting specific files or patterns.`)}${when(tools.offers("applyPatch"), `
|
|
22355
|
+
- You can add / update / remove multiple files in one go with "applyPatch".${when(tools.offers("writeFile"), ` Prefer it over "writeFile" to update existing files.`)}`)}${when(tools.offers("bash"), `
|
|
22356
|
+
- Avoid passing scripts into the "bash" function, and instead write javascript.`)}
|
|
21755
22357
|
- Variables are not shared between executions.
|
|
21756
|
-
- Do not use \`require\`, \`import\`, \`process\`, or any other Node.js apis.${
|
|
22358
|
+
- Do not use \`require\`, \`import\`, \`process\`, or any other Node.js apis.${when(tools.offers("delegate"), `
|
|
22359
|
+
- "delegate" runs a sub-agent and waits for it. Pass \`background: true\` to keep working while it runs: its result is sent to you later as a \`<subagent id="..." status="...">\` message.${when(tools.offers("waitAgents"), ` Use "waitAgents" to wait for the returned id.`)}${when(tools.offers("messageAgent"), ` Use "messageAgent" to send a message to the returned id.`)}${when(tools.offers("stopAgent"), ` Use "stopAgent" to stop the returned id.`)}${when(tools.offers("listAgents"), ` "listAgents" shows the agents you started.`)}`)}${when(!conversationMode, `
|
|
21757
22360
|
|
|
21758
22361
|
When you have fully completed your task, call the "taskComplete" function with the final output.
|
|
21759
|
-
Make sure every detail of the task is done before calling "taskComplete"
|
|
22362
|
+
Make sure every detail of the task is done before calling "taskComplete".${when(tools.offers("delegate"), `
|
|
22363
|
+
Any sub-agents you started must finish first: "taskComplete" fails while they are running.`)}`)}${when(tools.offers("readFile") && tools.offers("ls"), example)}
|
|
22364
|
+
|
|
22365
|
+
These are the functions available to you:
|
|
22366
|
+
|
|
22367
|
+
\`\`\`ts
|
|
22368
|
+
${tools.toolsDts}
|
|
22369
|
+
|
|
22370
|
+
/** The global Fetch API available for making HTTP requests. */
|
|
22371
|
+
declare const fetch: typeof globalThis.fetch
|
|
22372
|
+
\`\`\`${match$2(tools.skillsCatalog, {
|
|
22373
|
+
onNone: () => "",
|
|
22374
|
+
onSome: (catalog) => `
|
|
22375
|
+
|
|
22376
|
+
${catalog}`
|
|
22377
|
+
})}`;
|
|
22378
|
+
const example = `
|
|
21760
22379
|
|
|
21761
22380
|
Here is how you would read a file and list a directory:
|
|
21762
22381
|
|
|
@@ -21783,21 +22402,39 @@ package.json: {
|
|
|
21783
22402
|
"name": "my-project",
|
|
21784
22403
|
"version": "1.0.0"
|
|
21785
22404
|
}
|
|
21786
|
-
|
|
21787
|
-
|
|
21788
|
-
|
|
21789
|
-
|
|
21790
|
-
|
|
21791
|
-
$
|
|
21792
|
-
|
|
21793
|
-
|
|
21794
|
-
|
|
21795
|
-
|
|
21796
|
-
|
|
21797
|
-
|
|
21798
|
-
|
|
21799
|
-
|
|
21800
|
-
|
|
22405
|
+
\`\`\``;
|
|
22406
|
+
const ReadSkillTools = make$14(make$16("readSkill", {
|
|
22407
|
+
description: "Read the instructions of a skill listed under Skills, by its name.",
|
|
22408
|
+
parameters: String$5.annotate({ identifier: "name" }),
|
|
22409
|
+
success: String$5,
|
|
22410
|
+
failure: String$5
|
|
22411
|
+
}));
|
|
22412
|
+
const makeLoopTools = fnUntraced(function* (options) {
|
|
22413
|
+
const skills = options.skills ?? [];
|
|
22414
|
+
const callerTools = Object.keys(options.loopTools?.tools ?? {});
|
|
22415
|
+
const names = skills.length > 0 ? [...callerTools, "readSkill"] : callerTools;
|
|
22416
|
+
for (const name of names) if (options.executorTools.includes(name) || names.indexOf(name) !== names.lastIndexOf(name)) return yield* die(new Error(`Loop-side tool "${name}" clashes with another tool`));
|
|
22417
|
+
const toolkit = merge(options.loopTools ?? empty, skills.length > 0 ? ReadSkillTools : empty);
|
|
22418
|
+
const withHandlers = toolkit;
|
|
22419
|
+
const handled = yield* skills.length > 0 ? withHandlers.pipe(provide$1(ReadSkillTools.toLayer({ readSkill: (name) => {
|
|
22420
|
+
const skill = skills.find((skill) => skill.name === name);
|
|
22421
|
+
return skill ? succeed$1(skill.content) : fail$1(`Unknown skill ${JSON.stringify(name)}. Available skills: ${skills.map((skill) => skill.name).join(", ")}`);
|
|
22422
|
+
} }))) : withHandlers;
|
|
22423
|
+
const context$1 = yield* context();
|
|
22424
|
+
const handlers = {};
|
|
22425
|
+
for (const [name, tool] of Object.entries(handled.tools)) {
|
|
22426
|
+
const encodeSuccess = encodeUnknownEffect(toCodecJson(tool.successSchema));
|
|
22427
|
+
handlers[name] = (params) => handled.handle(name, params).pipe(flatMap$1(runLast), flatMap$1((last) => {
|
|
22428
|
+
if (isNone(last)) return void_;
|
|
22429
|
+
return last.value.isFailure ? fail$1(last.value.result) : encodeSuccess(last.value.result);
|
|
22430
|
+
}), mapError(errorMessage), provideContext(context$1));
|
|
22431
|
+
}
|
|
22432
|
+
return {
|
|
22433
|
+
handlers,
|
|
22434
|
+
dts: (yield* service(ToolkitRenderer).pipe(provide$1(ToolkitRenderer.layer))).render(toolkit)
|
|
22435
|
+
};
|
|
22436
|
+
});
|
|
22437
|
+
const errorMessage = (error) => typeof error === "string" ? error : error instanceof Error ? error.message : JSON.stringify(error) ?? String(error);
|
|
21801
22438
|
var ScriptExecutor = class extends Service()("clanka/Agent/ScriptExecutor") {};
|
|
21802
22439
|
const SingleTools = make$14(make$16("execute", {
|
|
21803
22440
|
description: "Execute javascript code and return the output",
|
|
@@ -21809,7 +22446,8 @@ const SingleToolHandlers = SingleTools.toLayer({ execute: fnUntraced(function* (
|
|
|
21809
22446
|
return yield* (yield* ScriptExecutor)(script);
|
|
21810
22447
|
}) });
|
|
21811
22448
|
const layer$2 = effect(Agent, make$2);
|
|
21812
|
-
const
|
|
22449
|
+
const layerWith = (options) => effect(Agent, makeWith(options));
|
|
22450
|
+
const layerLocal = (options) => layerWith(options).pipe(provide$3(layerLocal$1(options)));
|
|
21813
22451
|
var SubagentModel = class extends Service()("clanka/Agent/SubagentModel") {};
|
|
21814
22452
|
const layerSubagentModel = (layer) => effect(SubagentModel, gen(function* () {
|
|
21815
22453
|
const services = yield* context();
|
|
@@ -21821,6 +22459,9 @@ var ConversationMode = class ConversationMode extends Reference("clanka/Agent/Co
|
|
|
21821
22459
|
var TurnTimeout = class TurnTimeout extends Reference("clanka/Agent/TurnTimeout", { defaultValue: () => minutes(5) }) {
|
|
21822
22460
|
static layer = (timeout) => succeed$4(TurnTimeout, fromInputUnsafe$1(timeout));
|
|
21823
22461
|
};
|
|
22462
|
+
var MaxRetries = class MaxRetries extends Reference("clanka/Agent/MaxRetries", { defaultValue: () => 20 }) {
|
|
22463
|
+
static layer = (retries) => succeed$4(MaxRetries, retries);
|
|
22464
|
+
};
|
|
21824
22465
|
var AgentModelConfig = class AgentModelConfig extends Reference("clanka/Agent/SystemPromptTransform", { defaultValue: () => ({}) }) {
|
|
21825
22466
|
static layer = (options) => succeed$4(AgentModelConfig, options);
|
|
21826
22467
|
};
|
|
@@ -23383,7 +24024,7 @@ const modelWebSocket = (model, options) => make$5("xai", model, mergeAll(layer$3
|
|
|
23383
24024
|
const LogToStderr = LogToStderr$1;
|
|
23384
24025
|
//#endregion
|
|
23385
24026
|
//#region package.json
|
|
23386
|
-
var version$1 = "0.
|
|
24027
|
+
var version$1 = "0.9.0";
|
|
23387
24028
|
//#endregion
|
|
23388
24029
|
//#region src/cli.ts
|
|
23389
24030
|
const version = version$1;
|
|
@@ -23445,7 +24086,7 @@ const Search = (directory) => unwrap$1(gen(function* () {
|
|
|
23445
24086
|
return empty$8;
|
|
23446
24087
|
}
|
|
23447
24088
|
const path = yield* Path$3;
|
|
23448
|
-
return (yield* promise(() => import("./SemanticSearch-
|
|
24089
|
+
return (yield* promise(() => import("./SemanticSearch-Cb8aqvGv.mjs"))).layer({
|
|
23449
24090
|
directory: process.cwd(),
|
|
23450
24091
|
database: path.join(directory, "search.sqlite")
|
|
23451
24092
|
}).pipe(provide$3(model$2("text-embedding-3-small", { dimensions: 1536 })), provide$3(layer$5({ apiKey: apiKey.value })));
|
|
@@ -23469,7 +24110,7 @@ make$28("clanka", {
|
|
|
23469
24110
|
compaction
|
|
23470
24111
|
}).pipe(withHandler(fnUntraced(function* ({ provider, model: modelRaw, semantic, prompt: nonInteractivePrompt }) {
|
|
23471
24112
|
const stdio = yield* Stdio;
|
|
23472
|
-
const OutputFormatter = yield* promise(() => import("./OutputFormatter-
|
|
24113
|
+
const OutputFormatter = yield* promise(() => import("./OutputFormatter-DXXKo4E8.mjs"));
|
|
23473
24114
|
const [model, reasoning] = (yield* match$2(modelRaw, {
|
|
23474
24115
|
onSome: succeed$1,
|
|
23475
24116
|
onNone: () => String$4({
|