@fatagnus/codebuff 1.0.0 → 1.0.1
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/README.md +157 -6
- package/dist/convex.cjs +508 -1681
- package/dist/convex.cjs.map +5 -11
- package/dist/convex.mjs +517 -1690
- package/dist/convex.mjs.map +5 -11
- package/dist/index.cjs +23208 -23176
- package/dist/index.cjs.map +8 -8
- package/dist/index.mjs +23182 -23152
- package/dist/index.mjs.map +8 -8
- package/package.json +1 -1
package/dist/convex.mjs
CHANGED
|
@@ -32507,7 +32507,7 @@ var require_uri_all = __commonJS((exports2, module) => {
|
|
|
32507
32507
|
}
|
|
32508
32508
|
var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
|
|
32509
32509
|
var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === undefined;
|
|
32510
|
-
function
|
|
32510
|
+
function parse(uriString) {
|
|
32511
32511
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
32512
32512
|
var components = {};
|
|
32513
32513
|
var protocol = options.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
|
|
@@ -32672,51 +32672,51 @@ var require_uri_all = __commonJS((exports2, module) => {
|
|
|
32672
32672
|
}
|
|
32673
32673
|
return uriTokens.join("");
|
|
32674
32674
|
}
|
|
32675
|
-
function resolveComponents(base2,
|
|
32675
|
+
function resolveComponents(base2, relative) {
|
|
32676
32676
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
32677
32677
|
var skipNormalization = arguments[3];
|
|
32678
32678
|
var target = {};
|
|
32679
32679
|
if (!skipNormalization) {
|
|
32680
|
-
base2 =
|
|
32681
|
-
|
|
32680
|
+
base2 = parse(serialize(base2, options), options);
|
|
32681
|
+
relative = parse(serialize(relative, options), options);
|
|
32682
32682
|
}
|
|
32683
32683
|
options = options || {};
|
|
32684
|
-
if (!options.tolerant &&
|
|
32685
|
-
target.scheme =
|
|
32686
|
-
target.userinfo =
|
|
32687
|
-
target.host =
|
|
32688
|
-
target.port =
|
|
32689
|
-
target.path = removeDotSegments(
|
|
32690
|
-
target.query =
|
|
32684
|
+
if (!options.tolerant && relative.scheme) {
|
|
32685
|
+
target.scheme = relative.scheme;
|
|
32686
|
+
target.userinfo = relative.userinfo;
|
|
32687
|
+
target.host = relative.host;
|
|
32688
|
+
target.port = relative.port;
|
|
32689
|
+
target.path = removeDotSegments(relative.path || "");
|
|
32690
|
+
target.query = relative.query;
|
|
32691
32691
|
} else {
|
|
32692
|
-
if (
|
|
32693
|
-
target.userinfo =
|
|
32694
|
-
target.host =
|
|
32695
|
-
target.port =
|
|
32696
|
-
target.path = removeDotSegments(
|
|
32697
|
-
target.query =
|
|
32692
|
+
if (relative.userinfo !== undefined || relative.host !== undefined || relative.port !== undefined) {
|
|
32693
|
+
target.userinfo = relative.userinfo;
|
|
32694
|
+
target.host = relative.host;
|
|
32695
|
+
target.port = relative.port;
|
|
32696
|
+
target.path = removeDotSegments(relative.path || "");
|
|
32697
|
+
target.query = relative.query;
|
|
32698
32698
|
} else {
|
|
32699
|
-
if (!
|
|
32699
|
+
if (!relative.path) {
|
|
32700
32700
|
target.path = base2.path;
|
|
32701
|
-
if (
|
|
32702
|
-
target.query =
|
|
32701
|
+
if (relative.query !== undefined) {
|
|
32702
|
+
target.query = relative.query;
|
|
32703
32703
|
} else {
|
|
32704
32704
|
target.query = base2.query;
|
|
32705
32705
|
}
|
|
32706
32706
|
} else {
|
|
32707
|
-
if (
|
|
32708
|
-
target.path = removeDotSegments(
|
|
32707
|
+
if (relative.path.charAt(0) === "/") {
|
|
32708
|
+
target.path = removeDotSegments(relative.path);
|
|
32709
32709
|
} else {
|
|
32710
32710
|
if ((base2.userinfo !== undefined || base2.host !== undefined || base2.port !== undefined) && !base2.path) {
|
|
32711
|
-
target.path = "/" +
|
|
32711
|
+
target.path = "/" + relative.path;
|
|
32712
32712
|
} else if (!base2.path) {
|
|
32713
|
-
target.path =
|
|
32713
|
+
target.path = relative.path;
|
|
32714
32714
|
} else {
|
|
32715
|
-
target.path = base2.path.slice(0, base2.path.lastIndexOf("/") + 1) +
|
|
32715
|
+
target.path = base2.path.slice(0, base2.path.lastIndexOf("/") + 1) + relative.path;
|
|
32716
32716
|
}
|
|
32717
32717
|
target.path = removeDotSegments(target.path);
|
|
32718
32718
|
}
|
|
32719
|
-
target.query =
|
|
32719
|
+
target.query = relative.query;
|
|
32720
32720
|
}
|
|
32721
32721
|
target.userinfo = base2.userinfo;
|
|
32722
32722
|
target.host = base2.host;
|
|
@@ -32724,29 +32724,29 @@ var require_uri_all = __commonJS((exports2, module) => {
|
|
|
32724
32724
|
}
|
|
32725
32725
|
target.scheme = base2.scheme;
|
|
32726
32726
|
}
|
|
32727
|
-
target.fragment =
|
|
32727
|
+
target.fragment = relative.fragment;
|
|
32728
32728
|
return target;
|
|
32729
32729
|
}
|
|
32730
|
-
function
|
|
32730
|
+
function resolve(baseURI, relativeURI, options) {
|
|
32731
32731
|
var schemelessOptions = assign({ scheme: "null" }, options);
|
|
32732
|
-
return serialize(resolveComponents(
|
|
32732
|
+
return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
|
|
32733
32733
|
}
|
|
32734
32734
|
function normalize2(uri, options) {
|
|
32735
32735
|
if (typeof uri === "string") {
|
|
32736
|
-
uri = serialize(
|
|
32736
|
+
uri = serialize(parse(uri, options), options);
|
|
32737
32737
|
} else if (typeOf(uri) === "object") {
|
|
32738
|
-
uri =
|
|
32738
|
+
uri = parse(serialize(uri, options), options);
|
|
32739
32739
|
}
|
|
32740
32740
|
return uri;
|
|
32741
32741
|
}
|
|
32742
32742
|
function equal(uriA, uriB, options) {
|
|
32743
32743
|
if (typeof uriA === "string") {
|
|
32744
|
-
uriA = serialize(
|
|
32744
|
+
uriA = serialize(parse(uriA, options), options);
|
|
32745
32745
|
} else if (typeOf(uriA) === "object") {
|
|
32746
32746
|
uriA = serialize(uriA, options);
|
|
32747
32747
|
}
|
|
32748
32748
|
if (typeof uriB === "string") {
|
|
32749
|
-
uriB = serialize(
|
|
32749
|
+
uriB = serialize(parse(uriB, options), options);
|
|
32750
32750
|
} else if (typeOf(uriB) === "object") {
|
|
32751
32751
|
uriB = serialize(uriB, options);
|
|
32752
32752
|
}
|
|
@@ -32807,8 +32807,8 @@ var require_uri_all = __commonJS((exports2, module) => {
|
|
|
32807
32807
|
wsComponents.secure = undefined;
|
|
32808
32808
|
}
|
|
32809
32809
|
if (wsComponents.resourceName) {
|
|
32810
|
-
var _wsComponents$resourc = wsComponents.resourceName.split("?"), _wsComponents$resourc2 = slicedToArray(_wsComponents$resourc, 2),
|
|
32811
|
-
wsComponents.path =
|
|
32810
|
+
var _wsComponents$resourc = wsComponents.resourceName.split("?"), _wsComponents$resourc2 = slicedToArray(_wsComponents$resourc, 2), path2 = _wsComponents$resourc2[0], query = _wsComponents$resourc2[1];
|
|
32811
|
+
wsComponents.path = path2 && path2 !== "/" ? path2 : undefined;
|
|
32812
32812
|
wsComponents.query = query;
|
|
32813
32813
|
wsComponents.resourceName = undefined;
|
|
32814
32814
|
}
|
|
@@ -32991,11 +32991,11 @@ var require_uri_all = __commonJS((exports2, module) => {
|
|
|
32991
32991
|
exports3.SCHEMES = SCHEMES;
|
|
32992
32992
|
exports3.pctEncChar = pctEncChar;
|
|
32993
32993
|
exports3.pctDecChars = pctDecChars;
|
|
32994
|
-
exports3.parse =
|
|
32994
|
+
exports3.parse = parse;
|
|
32995
32995
|
exports3.removeDotSegments = removeDotSegments;
|
|
32996
32996
|
exports3.serialize = serialize;
|
|
32997
32997
|
exports3.resolveComponents = resolveComponents;
|
|
32998
|
-
exports3.resolve =
|
|
32998
|
+
exports3.resolve = resolve;
|
|
32999
32999
|
exports3.normalize = normalize2;
|
|
33000
33000
|
exports3.equal = equal;
|
|
33001
33001
|
exports3.escapeComponent = escapeComponent;
|
|
@@ -33201,12 +33201,12 @@ var require_util4 = __commonJS((exports2, module) => {
|
|
|
33201
33201
|
return "'" + escapeQuotes(str) + "'";
|
|
33202
33202
|
}
|
|
33203
33203
|
function getPathExpr(currentPath, expr, jsonPointers, isNumber2) {
|
|
33204
|
-
var
|
|
33205
|
-
return joinPaths(currentPath,
|
|
33204
|
+
var path2 = jsonPointers ? "'/' + " + expr + (isNumber2 ? "" : ".replace(/~/g, '~0').replace(/\\//g, '~1')") : isNumber2 ? "'[' + " + expr + " + ']'" : "'[\\'' + " + expr + " + '\\']'";
|
|
33205
|
+
return joinPaths(currentPath, path2);
|
|
33206
33206
|
}
|
|
33207
33207
|
function getPath(currentPath, prop, jsonPointers) {
|
|
33208
|
-
var
|
|
33209
|
-
return joinPaths(currentPath,
|
|
33208
|
+
var path2 = jsonPointers ? toQuotedString("/" + escapeJsonPointer(prop)) : toQuotedString(getProperty(prop));
|
|
33209
|
+
return joinPaths(currentPath, path2);
|
|
33210
33210
|
}
|
|
33211
33211
|
var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
33212
33212
|
var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
@@ -33361,20 +33361,20 @@ var require_resolve = __commonJS((exports2, module) => {
|
|
|
33361
33361
|
var util = require_util4();
|
|
33362
33362
|
var SchemaObject = require_schema_obj();
|
|
33363
33363
|
var traverse = require_json_schema_traverse();
|
|
33364
|
-
module.exports =
|
|
33365
|
-
|
|
33366
|
-
|
|
33367
|
-
|
|
33368
|
-
|
|
33369
|
-
|
|
33370
|
-
|
|
33371
|
-
function
|
|
33364
|
+
module.exports = resolve;
|
|
33365
|
+
resolve.normalizeId = normalizeId;
|
|
33366
|
+
resolve.fullPath = getFullPath;
|
|
33367
|
+
resolve.url = resolveUrl;
|
|
33368
|
+
resolve.ids = resolveIds;
|
|
33369
|
+
resolve.inlineRef = inlineRef;
|
|
33370
|
+
resolve.schema = resolveSchema;
|
|
33371
|
+
function resolve(compile, root, ref) {
|
|
33372
33372
|
var refVal = this._refs[ref];
|
|
33373
33373
|
if (typeof refVal == "string") {
|
|
33374
33374
|
if (this._refs[refVal])
|
|
33375
33375
|
refVal = this._refs[refVal];
|
|
33376
33376
|
else
|
|
33377
|
-
return
|
|
33377
|
+
return resolve.call(this, compile, root, refVal);
|
|
33378
33378
|
}
|
|
33379
33379
|
refVal = refVal || this._schemas[ref];
|
|
33380
33380
|
if (refVal instanceof SchemaObject) {
|
|
@@ -33597,7 +33597,7 @@ var require_resolve = __commonJS((exports2, module) => {
|
|
|
33597
33597
|
|
|
33598
33598
|
// ../node_modules/ajv/lib/compile/error_classes.js
|
|
33599
33599
|
var require_error_classes = __commonJS((exports2, module) => {
|
|
33600
|
-
var
|
|
33600
|
+
var resolve = require_resolve();
|
|
33601
33601
|
module.exports = {
|
|
33602
33602
|
Validation: errorSubclass(ValidationError),
|
|
33603
33603
|
MissingRef: errorSubclass(MissingRefError)
|
|
@@ -33612,8 +33612,8 @@ var require_error_classes = __commonJS((exports2, module) => {
|
|
|
33612
33612
|
};
|
|
33613
33613
|
function MissingRefError(baseId, ref, message) {
|
|
33614
33614
|
this.message = message || MissingRefError.message(baseId, ref);
|
|
33615
|
-
this.missingRef =
|
|
33616
|
-
this.missingSchema =
|
|
33615
|
+
this.missingRef = resolve.url(baseId, ref);
|
|
33616
|
+
this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef));
|
|
33617
33617
|
}
|
|
33618
33618
|
function errorSubclass(Subclass) {
|
|
33619
33619
|
Subclass.prototype = Object.create(Error.prototype);
|
|
@@ -34155,7 +34155,7 @@ var require_validate2 = __commonJS((exports2, module) => {
|
|
|
34155
34155
|
|
|
34156
34156
|
// ../node_modules/ajv/lib/compile/index.js
|
|
34157
34157
|
var require_compile = __commonJS((exports2, module) => {
|
|
34158
|
-
var
|
|
34158
|
+
var resolve = require_resolve();
|
|
34159
34159
|
var util = require_util4();
|
|
34160
34160
|
var errorClasses = require_error_classes();
|
|
34161
34161
|
var stableStringify = require_fast_json_stable_stringify();
|
|
@@ -34215,7 +34215,7 @@ var require_compile = __commonJS((exports2, module) => {
|
|
|
34215
34215
|
RULES,
|
|
34216
34216
|
validate: validateGenerator,
|
|
34217
34217
|
util,
|
|
34218
|
-
resolve
|
|
34218
|
+
resolve,
|
|
34219
34219
|
resolveRef,
|
|
34220
34220
|
usePattern,
|
|
34221
34221
|
useDefault,
|
|
@@ -34254,7 +34254,7 @@ var require_compile = __commonJS((exports2, module) => {
|
|
|
34254
34254
|
return validate;
|
|
34255
34255
|
}
|
|
34256
34256
|
function resolveRef(baseId2, ref, isRoot) {
|
|
34257
|
-
ref =
|
|
34257
|
+
ref = resolve.url(baseId2, ref);
|
|
34258
34258
|
var refIndex = refs[ref];
|
|
34259
34259
|
var _refVal, refCode;
|
|
34260
34260
|
if (refIndex !== undefined) {
|
|
@@ -34271,11 +34271,11 @@ var require_compile = __commonJS((exports2, module) => {
|
|
|
34271
34271
|
}
|
|
34272
34272
|
}
|
|
34273
34273
|
refCode = addLocalRef(ref);
|
|
34274
|
-
var v2 =
|
|
34274
|
+
var v2 = resolve.call(self2, localCompile, root, ref);
|
|
34275
34275
|
if (v2 === undefined) {
|
|
34276
34276
|
var localSchema = localRefs && localRefs[ref];
|
|
34277
34277
|
if (localSchema) {
|
|
34278
|
-
v2 =
|
|
34278
|
+
v2 = resolve.inlineRef(localSchema, opts.inlineRefs) ? localSchema : compile.call(self2, localSchema, root, localRefs, baseId2);
|
|
34279
34279
|
}
|
|
34280
34280
|
}
|
|
34281
34281
|
if (v2 === undefined) {
|
|
@@ -37792,7 +37792,7 @@ var require_data2 = __commonJS((exports2, module) => {
|
|
|
37792
37792
|
// ../node_modules/ajv/lib/ajv.js
|
|
37793
37793
|
var require_ajv = __commonJS((exports2, module) => {
|
|
37794
37794
|
var compileSchema = require_compile();
|
|
37795
|
-
var
|
|
37795
|
+
var resolve = require_resolve();
|
|
37796
37796
|
var Cache = require_cache();
|
|
37797
37797
|
var SchemaObject = require_schema_obj();
|
|
37798
37798
|
var stableStringify = require_fast_json_stable_stringify();
|
|
@@ -37884,7 +37884,7 @@ var require_ajv = __commonJS((exports2, module) => {
|
|
|
37884
37884
|
var id = this._getId(schema);
|
|
37885
37885
|
if (id !== undefined && typeof id != "string")
|
|
37886
37886
|
throw new Error("schema id must be string");
|
|
37887
|
-
key =
|
|
37887
|
+
key = resolve.normalizeId(key || id);
|
|
37888
37888
|
checkUnique(this, key);
|
|
37889
37889
|
this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
|
|
37890
37890
|
return this;
|
|
@@ -37930,7 +37930,7 @@ var require_ajv = __commonJS((exports2, module) => {
|
|
|
37930
37930
|
}
|
|
37931
37931
|
}
|
|
37932
37932
|
function _getSchemaFragment(self2, ref) {
|
|
37933
|
-
var res =
|
|
37933
|
+
var res = resolve.schema.call(self2, { schema: {} }, ref);
|
|
37934
37934
|
if (res) {
|
|
37935
37935
|
var { schema, root, baseId } = res;
|
|
37936
37936
|
var v = compileSchema.call(self2, schema, root, undefined, baseId);
|
|
@@ -37946,7 +37946,7 @@ var require_ajv = __commonJS((exports2, module) => {
|
|
|
37946
37946
|
}
|
|
37947
37947
|
}
|
|
37948
37948
|
function _getSchemaObj(self2, keyRef) {
|
|
37949
|
-
keyRef =
|
|
37949
|
+
keyRef = resolve.normalizeId(keyRef);
|
|
37950
37950
|
return self2._schemas[keyRef] || self2._refs[keyRef] || self2._fragments[keyRef];
|
|
37951
37951
|
}
|
|
37952
37952
|
function removeSchema(schemaKeyRef) {
|
|
@@ -37974,7 +37974,7 @@ var require_ajv = __commonJS((exports2, module) => {
|
|
|
37974
37974
|
this._cache.del(cacheKey);
|
|
37975
37975
|
var id = this._getId(schemaKeyRef);
|
|
37976
37976
|
if (id) {
|
|
37977
|
-
id =
|
|
37977
|
+
id = resolve.normalizeId(id);
|
|
37978
37978
|
delete this._schemas[id];
|
|
37979
37979
|
delete this._refs[id];
|
|
37980
37980
|
}
|
|
@@ -37999,14 +37999,14 @@ var require_ajv = __commonJS((exports2, module) => {
|
|
|
37999
37999
|
if (cached)
|
|
38000
38000
|
return cached;
|
|
38001
38001
|
shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
|
|
38002
|
-
var id =
|
|
38002
|
+
var id = resolve.normalizeId(this._getId(schema));
|
|
38003
38003
|
if (id && shouldAddSchema)
|
|
38004
38004
|
checkUnique(this, id);
|
|
38005
38005
|
var willValidate = this._opts.validateSchema !== false && !skipValidation;
|
|
38006
38006
|
var recursiveMeta;
|
|
38007
|
-
if (willValidate && !(recursiveMeta = id && id ==
|
|
38007
|
+
if (willValidate && !(recursiveMeta = id && id == resolve.normalizeId(schema.$schema)))
|
|
38008
38008
|
this.validateSchema(schema, true);
|
|
38009
|
-
var localRefs =
|
|
38009
|
+
var localRefs = resolve.ids.call(this, schema);
|
|
38010
38010
|
var schemaObj = new SchemaObject({
|
|
38011
38011
|
id,
|
|
38012
38012
|
schema,
|
|
@@ -38172,7 +38172,7 @@ var require_windows = __commonJS((exports2, module) => {
|
|
|
38172
38172
|
module.exports = isexe;
|
|
38173
38173
|
isexe.sync = sync;
|
|
38174
38174
|
var fs = __require("fs");
|
|
38175
|
-
function checkPathExt(
|
|
38175
|
+
function checkPathExt(path2, options) {
|
|
38176
38176
|
var pathext = options.pathExt !== undefined ? options.pathExt : process.env.PATHEXT;
|
|
38177
38177
|
if (!pathext) {
|
|
38178
38178
|
return true;
|
|
@@ -38183,25 +38183,25 @@ var require_windows = __commonJS((exports2, module) => {
|
|
|
38183
38183
|
}
|
|
38184
38184
|
for (var i = 0;i < pathext.length; i++) {
|
|
38185
38185
|
var p = pathext[i].toLowerCase();
|
|
38186
|
-
if (p &&
|
|
38186
|
+
if (p && path2.substr(-p.length).toLowerCase() === p) {
|
|
38187
38187
|
return true;
|
|
38188
38188
|
}
|
|
38189
38189
|
}
|
|
38190
38190
|
return false;
|
|
38191
38191
|
}
|
|
38192
|
-
function checkStat(stat,
|
|
38192
|
+
function checkStat(stat, path2, options) {
|
|
38193
38193
|
if (!stat.isSymbolicLink() && !stat.isFile()) {
|
|
38194
38194
|
return false;
|
|
38195
38195
|
}
|
|
38196
|
-
return checkPathExt(
|
|
38196
|
+
return checkPathExt(path2, options);
|
|
38197
38197
|
}
|
|
38198
|
-
function isexe(
|
|
38199
|
-
fs.stat(
|
|
38200
|
-
cb(er, er ? false : checkStat(stat,
|
|
38198
|
+
function isexe(path2, options, cb) {
|
|
38199
|
+
fs.stat(path2, function(er, stat) {
|
|
38200
|
+
cb(er, er ? false : checkStat(stat, path2, options));
|
|
38201
38201
|
});
|
|
38202
38202
|
}
|
|
38203
|
-
function sync(
|
|
38204
|
-
return checkStat(fs.statSync(
|
|
38203
|
+
function sync(path2, options) {
|
|
38204
|
+
return checkStat(fs.statSync(path2), path2, options);
|
|
38205
38205
|
}
|
|
38206
38206
|
});
|
|
38207
38207
|
|
|
@@ -38210,13 +38210,13 @@ var require_mode = __commonJS((exports2, module) => {
|
|
|
38210
38210
|
module.exports = isexe;
|
|
38211
38211
|
isexe.sync = sync;
|
|
38212
38212
|
var fs = __require("fs");
|
|
38213
|
-
function isexe(
|
|
38214
|
-
fs.stat(
|
|
38213
|
+
function isexe(path2, options, cb) {
|
|
38214
|
+
fs.stat(path2, function(er, stat) {
|
|
38215
38215
|
cb(er, er ? false : checkStat(stat, options));
|
|
38216
38216
|
});
|
|
38217
38217
|
}
|
|
38218
|
-
function sync(
|
|
38219
|
-
return checkStat(fs.statSync(
|
|
38218
|
+
function sync(path2, options) {
|
|
38219
|
+
return checkStat(fs.statSync(path2), options);
|
|
38220
38220
|
}
|
|
38221
38221
|
function checkStat(stat, options) {
|
|
38222
38222
|
return stat.isFile() && checkMode(stat, options);
|
|
@@ -38247,7 +38247,7 @@ var require_isexe = __commonJS((exports2, module) => {
|
|
|
38247
38247
|
}
|
|
38248
38248
|
module.exports = isexe;
|
|
38249
38249
|
isexe.sync = sync;
|
|
38250
|
-
function isexe(
|
|
38250
|
+
function isexe(path2, options, cb) {
|
|
38251
38251
|
if (typeof options === "function") {
|
|
38252
38252
|
cb = options;
|
|
38253
38253
|
options = {};
|
|
@@ -38256,17 +38256,17 @@ var require_isexe = __commonJS((exports2, module) => {
|
|
|
38256
38256
|
if (typeof Promise !== "function") {
|
|
38257
38257
|
throw new TypeError("callback not provided");
|
|
38258
38258
|
}
|
|
38259
|
-
return new Promise(function(
|
|
38260
|
-
isexe(
|
|
38259
|
+
return new Promise(function(resolve, reject) {
|
|
38260
|
+
isexe(path2, options || {}, function(er, is) {
|
|
38261
38261
|
if (er) {
|
|
38262
38262
|
reject(er);
|
|
38263
38263
|
} else {
|
|
38264
|
-
|
|
38264
|
+
resolve(is);
|
|
38265
38265
|
}
|
|
38266
38266
|
});
|
|
38267
38267
|
});
|
|
38268
38268
|
}
|
|
38269
|
-
core(
|
|
38269
|
+
core(path2, options || {}, function(er, is) {
|
|
38270
38270
|
if (er) {
|
|
38271
38271
|
if (er.code === "EACCES" || options && options.ignoreErrors) {
|
|
38272
38272
|
er = null;
|
|
@@ -38276,9 +38276,9 @@ var require_isexe = __commonJS((exports2, module) => {
|
|
|
38276
38276
|
cb(er, is);
|
|
38277
38277
|
});
|
|
38278
38278
|
}
|
|
38279
|
-
function sync(
|
|
38279
|
+
function sync(path2, options) {
|
|
38280
38280
|
try {
|
|
38281
|
-
return core.sync(
|
|
38281
|
+
return core.sync(path2, options || {});
|
|
38282
38282
|
} catch (er) {
|
|
38283
38283
|
if (options && options.ignoreErrors || er.code === "EACCES") {
|
|
38284
38284
|
return false;
|
|
@@ -38292,7 +38292,7 @@ var require_isexe = __commonJS((exports2, module) => {
|
|
|
38292
38292
|
// ../node_modules/which/which.js
|
|
38293
38293
|
var require_which = __commonJS((exports2, module) => {
|
|
38294
38294
|
var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
|
|
38295
|
-
var
|
|
38295
|
+
var path2 = __require("path");
|
|
38296
38296
|
var COLON = isWindows ? ";" : ":";
|
|
38297
38297
|
var isexe = require_isexe();
|
|
38298
38298
|
var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
|
|
@@ -38323,27 +38323,27 @@ var require_which = __commonJS((exports2, module) => {
|
|
|
38323
38323
|
opt = {};
|
|
38324
38324
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
38325
38325
|
const found = [];
|
|
38326
|
-
const step = (i) => new Promise((
|
|
38326
|
+
const step = (i) => new Promise((resolve, reject) => {
|
|
38327
38327
|
if (i === pathEnv.length)
|
|
38328
|
-
return opt.all && found.length ?
|
|
38328
|
+
return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
|
|
38329
38329
|
const ppRaw = pathEnv[i];
|
|
38330
38330
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
38331
|
-
const pCmd =
|
|
38331
|
+
const pCmd = path2.join(pathPart, cmd);
|
|
38332
38332
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
38333
|
-
|
|
38333
|
+
resolve(subStep(p, i, 0));
|
|
38334
38334
|
});
|
|
38335
|
-
const subStep = (p, i, ii) => new Promise((
|
|
38335
|
+
const subStep = (p, i, ii) => new Promise((resolve, reject) => {
|
|
38336
38336
|
if (ii === pathExt.length)
|
|
38337
|
-
return
|
|
38337
|
+
return resolve(step(i + 1));
|
|
38338
38338
|
const ext = pathExt[ii];
|
|
38339
38339
|
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
38340
38340
|
if (!er && is) {
|
|
38341
38341
|
if (opt.all)
|
|
38342
38342
|
found.push(p + ext);
|
|
38343
38343
|
else
|
|
38344
|
-
return
|
|
38344
|
+
return resolve(p + ext);
|
|
38345
38345
|
}
|
|
38346
|
-
return
|
|
38346
|
+
return resolve(subStep(p, i, ii + 1));
|
|
38347
38347
|
});
|
|
38348
38348
|
});
|
|
38349
38349
|
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
@@ -38355,7 +38355,7 @@ var require_which = __commonJS((exports2, module) => {
|
|
|
38355
38355
|
for (let i = 0;i < pathEnv.length; i++) {
|
|
38356
38356
|
const ppRaw = pathEnv[i];
|
|
38357
38357
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
38358
|
-
const pCmd =
|
|
38358
|
+
const pCmd = path2.join(pathPart, cmd);
|
|
38359
38359
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
38360
38360
|
for (let j = 0;j < pathExt.length; j++) {
|
|
38361
38361
|
const cur = p + pathExt[j];
|
|
@@ -38396,7 +38396,7 @@ var require_path_key = __commonJS((exports2, module) => {
|
|
|
38396
38396
|
|
|
38397
38397
|
// ../node_modules/cross-spawn/lib/util/resolveCommand.js
|
|
38398
38398
|
var require_resolveCommand = __commonJS((exports2, module) => {
|
|
38399
|
-
var
|
|
38399
|
+
var path2 = __require("path");
|
|
38400
38400
|
var which = require_which();
|
|
38401
38401
|
var getPathKey = require_path_key();
|
|
38402
38402
|
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
@@ -38413,7 +38413,7 @@ var require_resolveCommand = __commonJS((exports2, module) => {
|
|
|
38413
38413
|
try {
|
|
38414
38414
|
resolved = which.sync(parsed.command, {
|
|
38415
38415
|
path: env2[getPathKey({ env: env2 })],
|
|
38416
|
-
pathExt: withoutPathExt ?
|
|
38416
|
+
pathExt: withoutPathExt ? path2.delimiter : undefined
|
|
38417
38417
|
});
|
|
38418
38418
|
} catch (e) {} finally {
|
|
38419
38419
|
if (shouldSwitchCwd) {
|
|
@@ -38421,7 +38421,7 @@ var require_resolveCommand = __commonJS((exports2, module) => {
|
|
|
38421
38421
|
}
|
|
38422
38422
|
}
|
|
38423
38423
|
if (resolved) {
|
|
38424
|
-
resolved =
|
|
38424
|
+
resolved = path2.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
|
|
38425
38425
|
}
|
|
38426
38426
|
return resolved;
|
|
38427
38427
|
}
|
|
@@ -38466,8 +38466,8 @@ var require_shebang_command = __commonJS((exports2, module) => {
|
|
|
38466
38466
|
if (!match) {
|
|
38467
38467
|
return null;
|
|
38468
38468
|
}
|
|
38469
|
-
const [
|
|
38470
|
-
const binary =
|
|
38469
|
+
const [path2, argument] = match[0].replace(/#! ?/, "").split(" ");
|
|
38470
|
+
const binary = path2.split("/").pop();
|
|
38471
38471
|
if (binary === "env") {
|
|
38472
38472
|
return argument;
|
|
38473
38473
|
}
|
|
@@ -38495,7 +38495,7 @@ var require_readShebang = __commonJS((exports2, module) => {
|
|
|
38495
38495
|
|
|
38496
38496
|
// ../node_modules/cross-spawn/lib/parse.js
|
|
38497
38497
|
var require_parse3 = __commonJS((exports2, module) => {
|
|
38498
|
-
var
|
|
38498
|
+
var path2 = __require("path");
|
|
38499
38499
|
var resolveCommand = require_resolveCommand();
|
|
38500
38500
|
var escape = require_escape();
|
|
38501
38501
|
var readShebang = require_readShebang();
|
|
@@ -38520,7 +38520,7 @@ var require_parse3 = __commonJS((exports2, module) => {
|
|
|
38520
38520
|
const needsShell = !isExecutableRegExp.test(commandFile);
|
|
38521
38521
|
if (parsed.options.forceShell || needsShell) {
|
|
38522
38522
|
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
38523
|
-
parsed.command =
|
|
38523
|
+
parsed.command = path2.normalize(parsed.command);
|
|
38524
38524
|
parsed.command = escape.command(parsed.command);
|
|
38525
38525
|
parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
|
|
38526
38526
|
const shellCommand = [parsed.command].concat(parsed.args).join(" ");
|
|
@@ -38530,7 +38530,7 @@ var require_parse3 = __commonJS((exports2, module) => {
|
|
|
38530
38530
|
}
|
|
38531
38531
|
return parsed;
|
|
38532
38532
|
}
|
|
38533
|
-
function
|
|
38533
|
+
function parse(command, args, options) {
|
|
38534
38534
|
if (args && !Array.isArray(args)) {
|
|
38535
38535
|
options = args;
|
|
38536
38536
|
args = null;
|
|
@@ -38549,7 +38549,7 @@ var require_parse3 = __commonJS((exports2, module) => {
|
|
|
38549
38549
|
};
|
|
38550
38550
|
return options.shell ? parsed : parseNonShell(parsed);
|
|
38551
38551
|
}
|
|
38552
|
-
module.exports =
|
|
38552
|
+
module.exports = parse;
|
|
38553
38553
|
});
|
|
38554
38554
|
|
|
38555
38555
|
// ../node_modules/cross-spawn/lib/enoent.js
|
|
@@ -38602,16 +38602,16 @@ var require_enoent = __commonJS((exports2, module) => {
|
|
|
38602
38602
|
// ../node_modules/cross-spawn/index.js
|
|
38603
38603
|
var require_cross_spawn = __commonJS((exports2, module) => {
|
|
38604
38604
|
var cp = __require("child_process");
|
|
38605
|
-
var
|
|
38605
|
+
var parse = require_parse3();
|
|
38606
38606
|
var enoent = require_enoent();
|
|
38607
38607
|
function spawn(command, args, options) {
|
|
38608
|
-
const parsed =
|
|
38608
|
+
const parsed = parse(command, args, options);
|
|
38609
38609
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
38610
38610
|
enoent.hookChildProcess(spawned, parsed);
|
|
38611
38611
|
return spawned;
|
|
38612
38612
|
}
|
|
38613
38613
|
function spawnSync(command, args, options) {
|
|
38614
|
-
const parsed =
|
|
38614
|
+
const parsed = parse(command, args, options);
|
|
38615
38615
|
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
38616
38616
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
38617
38617
|
return result;
|
|
@@ -38619,7 +38619,7 @@ var require_cross_spawn = __commonJS((exports2, module) => {
|
|
|
38619
38619
|
module.exports = spawn;
|
|
38620
38620
|
module.exports.spawn = spawn;
|
|
38621
38621
|
module.exports.sync = spawnSync;
|
|
38622
|
-
module.exports._parse =
|
|
38622
|
+
module.exports._parse = parse;
|
|
38623
38623
|
module.exports._enoent = enoent;
|
|
38624
38624
|
});
|
|
38625
38625
|
|
|
@@ -46570,8 +46570,6 @@ var import_lodash4 = __toESM(require_lodash(), 1);
|
|
|
46570
46570
|
init_old_constants();
|
|
46571
46571
|
|
|
46572
46572
|
// ../common/src/util/file.ts
|
|
46573
|
-
import * as os from "os";
|
|
46574
|
-
import * as path from "path";
|
|
46575
46573
|
import { z as z58 } from "zod/v4";
|
|
46576
46574
|
var FileTreeNodeSchema = z58.object({
|
|
46577
46575
|
name: z58.string(),
|
|
@@ -46648,9 +46646,9 @@ function printFileTree(nodes, depth = 0) {
|
|
|
46648
46646
|
}
|
|
46649
46647
|
return result;
|
|
46650
46648
|
}
|
|
46651
|
-
function printFileTreeWithTokens(nodes, fileTokenScores,
|
|
46649
|
+
function printFileTreeWithTokens(nodes, fileTokenScores, path = []) {
|
|
46652
46650
|
let result = "";
|
|
46653
|
-
const depth =
|
|
46651
|
+
const depth = path.length;
|
|
46654
46652
|
const indentToken = " ";
|
|
46655
46653
|
const indentation = indentToken.repeat(depth);
|
|
46656
46654
|
const indentationWithFile = indentToken.repeat(depth + 1);
|
|
@@ -46659,8 +46657,8 @@ function printFileTreeWithTokens(nodes, fileTokenScores, path2 = []) {
|
|
|
46659
46657
|
continue;
|
|
46660
46658
|
}
|
|
46661
46659
|
result += `${indentation}${node.name}${node.type === "directory" ? "/" : ""}`;
|
|
46662
|
-
|
|
46663
|
-
const filePath =
|
|
46660
|
+
path.push(node.name);
|
|
46661
|
+
const filePath = path.join("/");
|
|
46664
46662
|
const tokenScores = fileTokenScores[filePath];
|
|
46665
46663
|
if (node.type === "file" && tokenScores) {
|
|
46666
46664
|
const tokens = Object.keys(tokenScores);
|
|
@@ -46672,40 +46670,16 @@ ${indentationWithFile}${tokens.join(" ")}`;
|
|
|
46672
46670
|
result += `
|
|
46673
46671
|
`;
|
|
46674
46672
|
if (node.type === "directory" && node.children) {
|
|
46675
|
-
result += printFileTreeWithTokens(node.children, fileTokenScores,
|
|
46673
|
+
result += printFileTreeWithTokens(node.children, fileTokenScores, path);
|
|
46676
46674
|
}
|
|
46677
|
-
|
|
46675
|
+
path.pop();
|
|
46678
46676
|
}
|
|
46679
46677
|
return result;
|
|
46680
46678
|
}
|
|
46681
|
-
async function fileExists(params2) {
|
|
46682
|
-
const { filePath, fs } = params2;
|
|
46683
|
-
try {
|
|
46684
|
-
await fs.stat(filePath);
|
|
46685
|
-
return true;
|
|
46686
|
-
} catch {
|
|
46687
|
-
return false;
|
|
46688
|
-
}
|
|
46689
|
-
}
|
|
46690
46679
|
var cleanMarkdownCodeBlock = (content) => {
|
|
46691
46680
|
const cleanResponse = content.match(/^```(?:[a-zA-Z]+)?\n([\s\S]*)\n```$/) ? content.replace(/^```(?:[a-zA-Z]+)?\n/, "").replace(/\n```$/, "") : content;
|
|
46692
46681
|
return cleanResponse;
|
|
46693
46682
|
};
|
|
46694
|
-
function isSubdir(fromPath, toPath) {
|
|
46695
|
-
const resolvedFrom = path.resolve(fromPath);
|
|
46696
|
-
const resolvedTo = path.resolve(toPath);
|
|
46697
|
-
if (process.platform === "win32") {
|
|
46698
|
-
const fromDrive = path.parse(resolvedFrom).root.toLowerCase();
|
|
46699
|
-
const toDrive = path.parse(resolvedTo).root.toLowerCase();
|
|
46700
|
-
if (fromDrive !== toDrive) {
|
|
46701
|
-
return false;
|
|
46702
|
-
}
|
|
46703
|
-
}
|
|
46704
|
-
return !path.relative(resolvedFrom, resolvedTo).startsWith("..");
|
|
46705
|
-
}
|
|
46706
|
-
function isValidProjectRoot(dir) {
|
|
46707
|
-
return !isSubdir(dir, os.homedir());
|
|
46708
|
-
}
|
|
46709
46683
|
|
|
46710
46684
|
// ../packages/agent-runtime/src/process-file-block.ts
|
|
46711
46685
|
import { createPatch } from "diff";
|
|
@@ -52031,7 +52005,7 @@ function countTokensJson(text) {
|
|
|
52031
52005
|
// ../packages/agent-runtime/src/process-file-block.ts
|
|
52032
52006
|
async function processFileBlock(params2) {
|
|
52033
52007
|
const {
|
|
52034
|
-
path
|
|
52008
|
+
path,
|
|
52035
52009
|
initialContentPromise,
|
|
52036
52010
|
newContent,
|
|
52037
52011
|
messages,
|
|
@@ -52046,28 +52020,28 @@ async function processFileBlock(params2) {
|
|
|
52046
52020
|
const initialContent = await initialContentPromise;
|
|
52047
52021
|
if (initialContent === null) {
|
|
52048
52022
|
let cleanContent = cleanMarkdownCodeBlock(newContent);
|
|
52049
|
-
if (hasLazyEdit(cleanContent) && !
|
|
52050
|
-
logger2.debug({ path
|
|
52023
|
+
if (hasLazyEdit(cleanContent) && !path.endsWith(".md")) {
|
|
52024
|
+
logger2.debug({ path, newContent }, `processFileBlock: New file contained a lazy edit for ${path}. Aborting.`);
|
|
52051
52025
|
return {
|
|
52052
52026
|
tool: "write_file",
|
|
52053
|
-
path
|
|
52027
|
+
path,
|
|
52054
52028
|
error: "You created a new file with a placeholder comment like `// ... existing code ...` (or equivalent for other languages). Are you sure you have the file path right? You probably meant to modify an existing file instead of providing a path to a new file."
|
|
52055
52029
|
};
|
|
52056
52030
|
}
|
|
52057
|
-
logger2.debug({ path
|
|
52031
|
+
logger2.debug({ path, cleanContent }, `processFileBlock: Created new file ${path}`);
|
|
52058
52032
|
return {
|
|
52059
52033
|
tool: "write_file",
|
|
52060
|
-
path
|
|
52034
|
+
path,
|
|
52061
52035
|
content: cleanContent,
|
|
52062
52036
|
patch: undefined,
|
|
52063
|
-
messages: [`Created new file ${
|
|
52037
|
+
messages: [`Created new file ${path}`]
|
|
52064
52038
|
};
|
|
52065
52039
|
}
|
|
52066
52040
|
if (newContent === initialContent) {
|
|
52067
|
-
logger2.info({ newContent }, `processFileBlock: New was same as old, skipping ${
|
|
52041
|
+
logger2.info({ newContent }, `processFileBlock: New was same as old, skipping ${path}`);
|
|
52068
52042
|
return {
|
|
52069
52043
|
tool: "write_file",
|
|
52070
|
-
path
|
|
52044
|
+
path,
|
|
52071
52045
|
error: "The new content was the same as the old content, skipping."
|
|
52072
52046
|
};
|
|
52073
52047
|
}
|
|
@@ -52088,12 +52062,12 @@ async function processFileBlock(params2) {
|
|
|
52088
52062
|
...params2,
|
|
52089
52063
|
oldContent: normalizedInitialContent,
|
|
52090
52064
|
editSnippet: normalizedEditSnippet,
|
|
52091
|
-
filePath:
|
|
52065
|
+
filePath: path
|
|
52092
52066
|
});
|
|
52093
52067
|
if (!largeFileContent) {
|
|
52094
52068
|
return {
|
|
52095
52069
|
tool: "write_file",
|
|
52096
|
-
path
|
|
52070
|
+
path,
|
|
52097
52071
|
error: "Failed to apply the write file change to this large file. You should try using the str_replace tool instead for large files."
|
|
52098
52072
|
};
|
|
52099
52073
|
}
|
|
@@ -52103,12 +52077,12 @@ async function processFileBlock(params2) {
|
|
|
52103
52077
|
...params2,
|
|
52104
52078
|
initialContent: normalizedInitialContent,
|
|
52105
52079
|
editSnippet: normalizedEditSnippet,
|
|
52106
|
-
filePath:
|
|
52080
|
+
filePath: path,
|
|
52107
52081
|
userMessage: lastUserPrompt
|
|
52108
52082
|
});
|
|
52109
52083
|
const shouldAddPlaceholders = await shouldAddFilePlaceholders({
|
|
52110
52084
|
...params2,
|
|
52111
|
-
filePath:
|
|
52085
|
+
filePath: path,
|
|
52112
52086
|
oldContent: normalizedInitialContent,
|
|
52113
52087
|
rewrittenNewContent: updatedContent,
|
|
52114
52088
|
messageHistory: messages
|
|
@@ -52122,12 +52096,12 @@ ${placeholderComment}`;
|
|
|
52122
52096
|
...params2,
|
|
52123
52097
|
initialContent: normalizedInitialContent,
|
|
52124
52098
|
editSnippet: updatedEditSnippet,
|
|
52125
|
-
filePath:
|
|
52099
|
+
filePath: path,
|
|
52126
52100
|
userMessage: lastUserPrompt
|
|
52127
52101
|
});
|
|
52128
52102
|
}
|
|
52129
52103
|
}
|
|
52130
|
-
let patch = createPatch(
|
|
52104
|
+
let patch = createPatch(path, normalizedInitialContent, updatedContent);
|
|
52131
52105
|
const lines = patch.split(`
|
|
52132
52106
|
`);
|
|
52133
52107
|
const hunkStartIndex = lines.findIndex((line) => line.startsWith("@@"));
|
|
@@ -52137,34 +52111,34 @@ ${placeholderComment}`;
|
|
|
52137
52111
|
} else {
|
|
52138
52112
|
editMessages.push("The new content was the same as the old content, skipping.");
|
|
52139
52113
|
logger2.debug({
|
|
52140
|
-
path
|
|
52114
|
+
path,
|
|
52141
52115
|
initialContent,
|
|
52142
52116
|
changes: newContent,
|
|
52143
52117
|
patch,
|
|
52144
52118
|
editMessages
|
|
52145
|
-
}, `processFileBlock: No change to ${
|
|
52119
|
+
}, `processFileBlock: No change to ${path}`);
|
|
52146
52120
|
return {
|
|
52147
52121
|
tool: "write_file",
|
|
52148
|
-
path
|
|
52122
|
+
path,
|
|
52149
52123
|
error: editMessages.join(`
|
|
52150
52124
|
|
|
52151
52125
|
`)
|
|
52152
52126
|
};
|
|
52153
52127
|
}
|
|
52154
52128
|
logger2.debug({
|
|
52155
|
-
path
|
|
52129
|
+
path,
|
|
52156
52130
|
editSnippet: newContent,
|
|
52157
52131
|
updatedContent,
|
|
52158
52132
|
patch,
|
|
52159
52133
|
editMessages
|
|
52160
|
-
}, `processFileBlock: Updated file ${
|
|
52134
|
+
}, `processFileBlock: Updated file ${path}`);
|
|
52161
52135
|
const patchOriginalLineEndings = patch.replaceAll(`
|
|
52162
52136
|
`, lineEnding);
|
|
52163
52137
|
const updatedContentOriginalLineEndings = updatedContent.replaceAll(`
|
|
52164
52138
|
`, lineEnding);
|
|
52165
52139
|
return {
|
|
52166
52140
|
tool: "write_file",
|
|
52167
|
-
path
|
|
52141
|
+
path,
|
|
52168
52142
|
content: updatedContentOriginalLineEndings,
|
|
52169
52143
|
patch: patchOriginalLineEndings,
|
|
52170
52144
|
messages: editMessages
|
|
@@ -52277,21 +52251,21 @@ var handleWriteFile = async (params2) => {
|
|
|
52277
52251
|
requestOptionalFile,
|
|
52278
52252
|
writeToClient
|
|
52279
52253
|
} = params2;
|
|
52280
|
-
const { path
|
|
52254
|
+
const { path, instructions, content } = toolCall.input;
|
|
52281
52255
|
const fileProcessingPromisesByPath = fileProcessingState2.promisesByPath;
|
|
52282
52256
|
const fileProcessingPromises = fileProcessingState2.allPromises;
|
|
52283
|
-
if (!fileProcessingPromisesByPath[
|
|
52284
|
-
fileProcessingPromisesByPath[
|
|
52257
|
+
if (!fileProcessingPromisesByPath[path]) {
|
|
52258
|
+
fileProcessingPromisesByPath[path] = [];
|
|
52285
52259
|
}
|
|
52286
|
-
const previousPromises = fileProcessingPromisesByPath[
|
|
52260
|
+
const previousPromises = fileProcessingPromisesByPath[path];
|
|
52287
52261
|
const previousEdit = previousPromises[previousPromises.length - 1];
|
|
52288
|
-
const latestContentPromise = previousEdit ? previousEdit.then((maybeResult) => maybeResult && ("content" in maybeResult) ? maybeResult.content : requestOptionalFile({ ...params2, filePath:
|
|
52262
|
+
const latestContentPromise = previousEdit ? previousEdit.then((maybeResult) => maybeResult && ("content" in maybeResult) ? maybeResult.content : requestOptionalFile({ ...params2, filePath: path })) : requestOptionalFile({ ...params2, filePath: path });
|
|
52289
52263
|
const fileContentWithoutStartNewline = content.startsWith(`
|
|
52290
52264
|
`) ? content.slice(1) : content;
|
|
52291
|
-
logger2.debug({ path
|
|
52265
|
+
logger2.debug({ path, content }, `write_file ${path}`);
|
|
52292
52266
|
const newPromise = processFileBlock({
|
|
52293
52267
|
...params2,
|
|
52294
|
-
path
|
|
52268
|
+
path,
|
|
52295
52269
|
instructions,
|
|
52296
52270
|
initialContentPromise: latestContentPromise,
|
|
52297
52271
|
newContent: fileContentWithoutStartNewline,
|
|
@@ -52305,14 +52279,14 @@ var handleWriteFile = async (params2) => {
|
|
|
52305
52279
|
logger2.error(error, "Error processing write_file block");
|
|
52306
52280
|
return {
|
|
52307
52281
|
tool: "write_file",
|
|
52308
|
-
path
|
|
52282
|
+
path,
|
|
52309
52283
|
error: `Error: Failed to process the write_file block. ${typeof error === "string" ? error : error.msg}`
|
|
52310
52284
|
};
|
|
52311
52285
|
}).then(async (fileProcessingResult) => ({
|
|
52312
52286
|
...fileProcessingResult,
|
|
52313
52287
|
toolCallId: toolCall.toolCallId
|
|
52314
52288
|
}));
|
|
52315
|
-
fileProcessingPromisesByPath[
|
|
52289
|
+
fileProcessingPromisesByPath[path].push(newPromise);
|
|
52316
52290
|
fileProcessingPromises.push(newPromise);
|
|
52317
52291
|
await previousToolCallFinished;
|
|
52318
52292
|
return {
|
|
@@ -52343,12 +52317,12 @@ async function postStreamProcessing(toolCall, fileProcessingState2, writeToClien
|
|
|
52343
52317
|
if (errors.length > 1) {
|
|
52344
52318
|
throw new Error(`Internal error: Unexpected number of matching errors for ${JSON.stringify(toolCall)}, found ${errors.length}, expected 1`);
|
|
52345
52319
|
}
|
|
52346
|
-
const { path:
|
|
52320
|
+
const { path: path2, error } = errors[0];
|
|
52347
52321
|
return [
|
|
52348
52322
|
{
|
|
52349
52323
|
type: "json",
|
|
52350
52324
|
value: {
|
|
52351
|
-
file:
|
|
52325
|
+
file: path2,
|
|
52352
52326
|
errorMessage: error
|
|
52353
52327
|
}
|
|
52354
52328
|
}
|
|
@@ -52358,11 +52332,11 @@ async function postStreamProcessing(toolCall, fileProcessingState2, writeToClien
|
|
|
52358
52332
|
if (changes.length !== 1) {
|
|
52359
52333
|
throw new Error(`Internal error: Unexpected number of matching changes for ${JSON.stringify(toolCall)}, found ${changes.length}, expected 1`);
|
|
52360
52334
|
}
|
|
52361
|
-
const { patch, content, path
|
|
52335
|
+
const { patch, content, path } = changes[0];
|
|
52362
52336
|
const clientToolCall = {
|
|
52363
52337
|
toolCallId: toolCall.toolCallId,
|
|
52364
52338
|
toolName: toolCall.tool,
|
|
52365
|
-
input: patch ? { type: "patch", path
|
|
52339
|
+
input: patch ? { type: "patch", path, content: patch } : { type: "file", path, content }
|
|
52366
52340
|
};
|
|
52367
52341
|
return await requestClientToolCall(clientToolCall);
|
|
52368
52342
|
}
|
|
@@ -52377,19 +52351,19 @@ var handleCreatePlan = async (params2) => {
|
|
|
52377
52351
|
requestClientToolCall,
|
|
52378
52352
|
writeToClient
|
|
52379
52353
|
} = params2;
|
|
52380
|
-
const { path
|
|
52354
|
+
const { path, plan } = toolCall.input;
|
|
52381
52355
|
logger2.debug({
|
|
52382
|
-
path
|
|
52356
|
+
path,
|
|
52383
52357
|
plan
|
|
52384
52358
|
}, "Create plan");
|
|
52385
52359
|
const change = {
|
|
52386
52360
|
tool: "create_plan",
|
|
52387
|
-
path
|
|
52361
|
+
path,
|
|
52388
52362
|
content: plan,
|
|
52389
52363
|
messages: [],
|
|
52390
52364
|
toolCallId: toolCall.toolCallId
|
|
52391
52365
|
};
|
|
52392
|
-
fileProcessingState2.promisesByPath[
|
|
52366
|
+
fileProcessingState2.promisesByPath[path].push(Promise.resolve(change));
|
|
52393
52367
|
fileProcessingState2.allPromises.push(Promise.resolve(change));
|
|
52394
52368
|
await previousToolCallFinished;
|
|
52395
52369
|
return {
|
|
@@ -52410,149 +52384,14 @@ import { dirname as dirname2, isAbsolute, normalize } from "path";
|
|
|
52410
52384
|
|
|
52411
52385
|
// ../common/src/project-file-tree.ts
|
|
52412
52386
|
var import_lodash5 = __toESM(require_lodash(), 1);
|
|
52413
|
-
|
|
52414
|
-
import path2 from "path";
|
|
52387
|
+
import path from "path";
|
|
52415
52388
|
import * as ignore from "ignore";
|
|
52416
|
-
var DEFAULT_MAX_FILES = 1e4;
|
|
52417
|
-
async function getProjectFileTree(params2) {
|
|
52418
|
-
const withDefaults = { maxFiles: DEFAULT_MAX_FILES, ...params2 };
|
|
52419
|
-
const { projectRoot, fs } = withDefaults;
|
|
52420
|
-
let { maxFiles } = withDefaults;
|
|
52421
|
-
const start = Date.now();
|
|
52422
|
-
const defaultIgnore = ignore.default();
|
|
52423
|
-
for (const pattern of DEFAULT_IGNORED_PATHS) {
|
|
52424
|
-
defaultIgnore.add(pattern);
|
|
52425
|
-
}
|
|
52426
|
-
if (!isValidProjectRoot(projectRoot)) {
|
|
52427
|
-
defaultIgnore.add(".*");
|
|
52428
|
-
maxFiles = 0;
|
|
52429
|
-
}
|
|
52430
|
-
const root = {
|
|
52431
|
-
name: path2.basename(projectRoot),
|
|
52432
|
-
type: "directory",
|
|
52433
|
-
children: [],
|
|
52434
|
-
filePath: ""
|
|
52435
|
-
};
|
|
52436
|
-
const queue = [
|
|
52437
|
-
{
|
|
52438
|
-
node: root,
|
|
52439
|
-
fullPath: projectRoot,
|
|
52440
|
-
ignore: defaultIgnore
|
|
52441
|
-
}
|
|
52442
|
-
];
|
|
52443
|
-
let totalFiles = 0;
|
|
52444
|
-
while (queue.length > 0 && totalFiles < maxFiles) {
|
|
52445
|
-
const { node, fullPath, ignore: currentIgnore } = queue.shift();
|
|
52446
|
-
const parsedIgnore = await parseGitignore({
|
|
52447
|
-
fullDirPath: fullPath,
|
|
52448
|
-
projectRoot,
|
|
52449
|
-
fs
|
|
52450
|
-
});
|
|
52451
|
-
const mergedIgnore = ignore.default().add(currentIgnore).add(parsedIgnore);
|
|
52452
|
-
try {
|
|
52453
|
-
const files = await fs.readdir(fullPath);
|
|
52454
|
-
for (const file of files) {
|
|
52455
|
-
if (totalFiles >= maxFiles)
|
|
52456
|
-
break;
|
|
52457
|
-
const filePath = path2.join(fullPath, file);
|
|
52458
|
-
const relativeFilePath = path2.relative(projectRoot, filePath);
|
|
52459
|
-
if (mergedIgnore.ignores(relativeFilePath))
|
|
52460
|
-
continue;
|
|
52461
|
-
try {
|
|
52462
|
-
const stats = await fs.stat(filePath);
|
|
52463
|
-
if (stats.isDirectory()) {
|
|
52464
|
-
const childNode = {
|
|
52465
|
-
name: file,
|
|
52466
|
-
type: "directory",
|
|
52467
|
-
children: [],
|
|
52468
|
-
filePath: relativeFilePath
|
|
52469
|
-
};
|
|
52470
|
-
node.children.push(childNode);
|
|
52471
|
-
queue.push({
|
|
52472
|
-
node: childNode,
|
|
52473
|
-
fullPath: filePath,
|
|
52474
|
-
ignore: mergedIgnore
|
|
52475
|
-
});
|
|
52476
|
-
} else {
|
|
52477
|
-
const lastReadTime = stats.atimeMs;
|
|
52478
|
-
node.children.push({
|
|
52479
|
-
name: file,
|
|
52480
|
-
type: "file",
|
|
52481
|
-
lastReadTime,
|
|
52482
|
-
filePath: relativeFilePath
|
|
52483
|
-
});
|
|
52484
|
-
totalFiles++;
|
|
52485
|
-
}
|
|
52486
|
-
} catch (error) {}
|
|
52487
|
-
}
|
|
52488
|
-
} catch (error) {}
|
|
52489
|
-
}
|
|
52490
|
-
return root.children;
|
|
52491
|
-
}
|
|
52492
|
-
function rebaseGitignorePattern(rawPattern, relativeDirPath) {
|
|
52493
|
-
const isNegated = rawPattern.startsWith("!");
|
|
52494
|
-
let pattern = isNegated ? rawPattern.slice(1) : rawPattern;
|
|
52495
|
-
const dirOnly = pattern.endsWith("/");
|
|
52496
|
-
const core = dirOnly ? pattern.slice(0, -1) : pattern;
|
|
52497
|
-
const anchored = core.startsWith("/");
|
|
52498
|
-
const coreNoLead = anchored ? core.slice(1) : core;
|
|
52499
|
-
const hasSlash = coreNoLead.includes("/");
|
|
52500
|
-
const base = relativeDirPath.replace(/\\/g, "/");
|
|
52501
|
-
let rebased;
|
|
52502
|
-
if (anchored) {
|
|
52503
|
-
rebased = base ? `${base}/${coreNoLead}` : coreNoLead;
|
|
52504
|
-
} else if (!hasSlash) {
|
|
52505
|
-
if (base) {
|
|
52506
|
-
rebased = `${base}/**/${coreNoLead}`;
|
|
52507
|
-
} else {
|
|
52508
|
-
rebased = coreNoLead;
|
|
52509
|
-
}
|
|
52510
|
-
} else {
|
|
52511
|
-
rebased = base ? `${base}/${coreNoLead}` : coreNoLead;
|
|
52512
|
-
}
|
|
52513
|
-
if (dirOnly && !rebased.endsWith("/")) {
|
|
52514
|
-
rebased += "/";
|
|
52515
|
-
}
|
|
52516
|
-
rebased = rebased.replace(/\\/g, "/");
|
|
52517
|
-
return isNegated ? `!${rebased}` : rebased;
|
|
52518
|
-
}
|
|
52519
|
-
async function parseGitignore(params2) {
|
|
52520
|
-
const { fullDirPath, projectRoot, fs } = params2;
|
|
52521
|
-
const ig = ignore.default();
|
|
52522
|
-
const relativeDirPath = path2.relative(projectRoot, fullDirPath);
|
|
52523
|
-
const ignoreFiles = [
|
|
52524
|
-
path2.join(fullDirPath, ".gitignore"),
|
|
52525
|
-
path2.join(fullDirPath, ".codebuffignore"),
|
|
52526
|
-
path2.join(fullDirPath, ".manicodeignore")
|
|
52527
|
-
];
|
|
52528
|
-
for (const ignoreFilePath of ignoreFiles) {
|
|
52529
|
-
const ignoreFileExists = await fileExists({ filePath: ignoreFilePath, fs });
|
|
52530
|
-
if (!ignoreFileExists)
|
|
52531
|
-
continue;
|
|
52532
|
-
let ignoreContent;
|
|
52533
|
-
try {
|
|
52534
|
-
ignoreContent = await fs.readFile(ignoreFilePath, "utf8");
|
|
52535
|
-
} catch {
|
|
52536
|
-
continue;
|
|
52537
|
-
}
|
|
52538
|
-
const lines = ignoreContent.split(`
|
|
52539
|
-
`);
|
|
52540
|
-
for (let line of lines) {
|
|
52541
|
-
line = line.trim();
|
|
52542
|
-
if (line === "" || line.startsWith("#"))
|
|
52543
|
-
continue;
|
|
52544
|
-
const finalPattern = rebaseGitignorePattern(line, relativeDirPath);
|
|
52545
|
-
ig.add(finalPattern);
|
|
52546
|
-
}
|
|
52547
|
-
}
|
|
52548
|
-
return ig;
|
|
52549
|
-
}
|
|
52550
52389
|
function getAllFilePaths(nodes, basePath = "") {
|
|
52551
52390
|
return nodes.flatMap((node) => {
|
|
52552
52391
|
if (node.type === "file") {
|
|
52553
|
-
return [
|
|
52392
|
+
return [path.join(basePath, node.name)];
|
|
52554
52393
|
}
|
|
52555
|
-
return getAllFilePaths(node.children || [],
|
|
52394
|
+
return getAllFilePaths(node.children || [], path.join(basePath, node.name));
|
|
52556
52395
|
});
|
|
52557
52396
|
}
|
|
52558
52397
|
function flattenTree(nodes) {
|
|
@@ -53113,9 +52952,9 @@ async function getFileReadingUpdates(params2) {
|
|
|
53113
52952
|
const { requestFiles, requestedFiles } = params2;
|
|
53114
52953
|
const allFilePaths = import_lodash9.uniq(requestedFiles);
|
|
53115
52954
|
const loadedFiles = await requestFiles({ filePaths: allFilePaths });
|
|
53116
|
-
const addedFiles = allFilePaths.filter((
|
|
53117
|
-
path:
|
|
53118
|
-
content: loadedFiles[
|
|
52955
|
+
const addedFiles = allFilePaths.filter((path2) => loadedFiles[path2] != null && loadedFiles[path2] !== undefined).map((path2) => ({
|
|
52956
|
+
path: path2,
|
|
52957
|
+
content: loadedFiles[path2]
|
|
53119
52958
|
}));
|
|
53120
52959
|
return addedFiles;
|
|
53121
52960
|
}
|
|
@@ -53529,7 +53368,7 @@ ${systemInfo.platform === "win32" ? windowsNote + `
|
|
|
53529
53368
|
Shell: ${systemInfo.shell}
|
|
53530
53369
|
|
|
53531
53370
|
<user_shell_config_files>
|
|
53532
|
-
${Object.entries(shellConfigFiles).map(([
|
|
53371
|
+
${Object.entries(shellConfigFiles).map(([path2, content]) => createMarkdownFileBlock(path2, content)).join(`
|
|
53533
53372
|
`)}
|
|
53534
53373
|
${closeXml("user_shell_config_files")}
|
|
53535
53374
|
|
|
@@ -53823,12 +53662,12 @@ function normalizeLineEndings(params2) {
|
|
|
53823
53662
|
`);
|
|
53824
53663
|
}
|
|
53825
53664
|
async function processStrReplace(params2) {
|
|
53826
|
-
const { path:
|
|
53665
|
+
const { path: path2, replacements, initialContentPromise, logger: logger2 } = params2;
|
|
53827
53666
|
const initialContent = await initialContentPromise;
|
|
53828
53667
|
if (initialContent === null) {
|
|
53829
53668
|
return {
|
|
53830
53669
|
tool: "str_replace",
|
|
53831
|
-
path:
|
|
53670
|
+
path: path2,
|
|
53832
53671
|
error: "The file does not exist, skipping. Please use the write_file tool to create the file."
|
|
53833
53672
|
};
|
|
53834
53673
|
}
|
|
@@ -53868,19 +53707,19 @@ async function processStrReplace(params2) {
|
|
|
53868
53707
|
`, lineEnding);
|
|
53869
53708
|
if (initialContent === currentContent) {
|
|
53870
53709
|
logger2.debug({
|
|
53871
|
-
path:
|
|
53710
|
+
path: path2,
|
|
53872
53711
|
initialContent
|
|
53873
|
-
}, `processStrReplace: No change to ${
|
|
53712
|
+
}, `processStrReplace: No change to ${path2}`);
|
|
53874
53713
|
messages.push("No change to the file");
|
|
53875
53714
|
return {
|
|
53876
53715
|
tool: "str_replace",
|
|
53877
|
-
path:
|
|
53716
|
+
path: path2,
|
|
53878
53717
|
error: messages.join(`
|
|
53879
53718
|
|
|
53880
53719
|
`)
|
|
53881
53720
|
};
|
|
53882
53721
|
}
|
|
53883
|
-
let patch = createPatch2(
|
|
53722
|
+
let patch = createPatch2(path2, initialContent, currentContent);
|
|
53884
53723
|
const lines = patch.split(`
|
|
53885
53724
|
`);
|
|
53886
53725
|
const hunkStartIndex = lines.findIndex((line) => line.startsWith("@@"));
|
|
@@ -53890,14 +53729,14 @@ async function processStrReplace(params2) {
|
|
|
53890
53729
|
}
|
|
53891
53730
|
const finalPatch = patch;
|
|
53892
53731
|
logger2.debug({
|
|
53893
|
-
path:
|
|
53732
|
+
path: path2,
|
|
53894
53733
|
newContent: currentContent,
|
|
53895
53734
|
patch: finalPatch,
|
|
53896
53735
|
messages
|
|
53897
|
-
}, `processStrReplace: Updated file ${
|
|
53736
|
+
}, `processStrReplace: Updated file ${path2}`);
|
|
53898
53737
|
return {
|
|
53899
53738
|
tool: "str_replace",
|
|
53900
|
-
path:
|
|
53739
|
+
path: path2,
|
|
53901
53740
|
content: currentContent,
|
|
53902
53741
|
patch: finalPatch,
|
|
53903
53742
|
messages
|
|
@@ -53969,17 +53808,17 @@ var handleProposeStrReplace = async (params2) => {
|
|
|
53969
53808
|
runId,
|
|
53970
53809
|
requestOptionalFile
|
|
53971
53810
|
} = params2;
|
|
53972
|
-
const { path:
|
|
53811
|
+
const { path: path2, replacements } = toolCall.input;
|
|
53973
53812
|
const getProposedOrDiskContent = async () => {
|
|
53974
|
-
const proposedContent = getProposedContent(runId,
|
|
53813
|
+
const proposedContent = getProposedContent(runId, path2);
|
|
53975
53814
|
if (proposedContent !== undefined) {
|
|
53976
53815
|
return proposedContent;
|
|
53977
53816
|
}
|
|
53978
|
-
return requestOptionalFile({ ...params2, filePath:
|
|
53817
|
+
return requestOptionalFile({ ...params2, filePath: path2 });
|
|
53979
53818
|
};
|
|
53980
53819
|
const latestContentPromise = getProposedOrDiskContent();
|
|
53981
53820
|
const strReplaceResultPromise = processStrReplace({
|
|
53982
|
-
path:
|
|
53821
|
+
path: path2,
|
|
53983
53822
|
replacements,
|
|
53984
53823
|
initialContentPromise: latestContentPromise,
|
|
53985
53824
|
logger: logger2
|
|
@@ -53987,11 +53826,11 @@ var handleProposeStrReplace = async (params2) => {
|
|
|
53987
53826
|
logger2.error(error, "Error processing propose_str_replace");
|
|
53988
53827
|
return {
|
|
53989
53828
|
tool: "str_replace",
|
|
53990
|
-
path:
|
|
53829
|
+
path: path2,
|
|
53991
53830
|
error: "Unknown error: Failed to process the propose_str_replace."
|
|
53992
53831
|
};
|
|
53993
53832
|
});
|
|
53994
|
-
setProposedContent(runId,
|
|
53833
|
+
setProposedContent(runId, path2, strReplaceResultPromise.then((result) => ("content" in result) ? result.content : null));
|
|
53995
53834
|
await previousToolCallFinished;
|
|
53996
53835
|
const strReplaceResult = await strReplaceResultPromise;
|
|
53997
53836
|
if ("error" in strReplaceResult) {
|
|
@@ -54000,7 +53839,7 @@ var handleProposeStrReplace = async (params2) => {
|
|
|
54000
53839
|
{
|
|
54001
53840
|
type: "json",
|
|
54002
53841
|
value: {
|
|
54003
|
-
file:
|
|
53842
|
+
file: path2,
|
|
54004
53843
|
errorMessage: strReplaceResult.error
|
|
54005
53844
|
}
|
|
54006
53845
|
}
|
|
@@ -54015,7 +53854,7 @@ var handleProposeStrReplace = async (params2) => {
|
|
|
54015
53854
|
{
|
|
54016
53855
|
type: "json",
|
|
54017
53856
|
value: {
|
|
54018
|
-
file:
|
|
53857
|
+
file: path2,
|
|
54019
53858
|
message,
|
|
54020
53859
|
unifiedDiff: strReplaceResult.patch
|
|
54021
53860
|
}
|
|
@@ -54034,21 +53873,21 @@ var handleProposeWriteFile = async (params2) => {
|
|
|
54034
53873
|
runId,
|
|
54035
53874
|
requestOptionalFile
|
|
54036
53875
|
} = params2;
|
|
54037
|
-
const { path:
|
|
53876
|
+
const { path: path2, content } = toolCall.input;
|
|
54038
53877
|
const getProposedOrDiskContent = async () => {
|
|
54039
|
-
const proposedContent = getProposedContent(runId,
|
|
53878
|
+
const proposedContent = getProposedContent(runId, path2);
|
|
54040
53879
|
if (proposedContent !== undefined) {
|
|
54041
53880
|
return proposedContent;
|
|
54042
53881
|
}
|
|
54043
|
-
return requestOptionalFile({ ...params2, filePath:
|
|
53882
|
+
return requestOptionalFile({ ...params2, filePath: path2 });
|
|
54044
53883
|
};
|
|
54045
53884
|
const initialContent = await getProposedOrDiskContent();
|
|
54046
53885
|
const newContent = content.startsWith(`
|
|
54047
53886
|
`) ? content.slice(1) : content;
|
|
54048
|
-
setProposedContent(runId,
|
|
53887
|
+
setProposedContent(runId, path2, Promise.resolve(newContent));
|
|
54049
53888
|
await previousToolCallFinished;
|
|
54050
53889
|
const oldContent = initialContent ?? "";
|
|
54051
|
-
let patch = createPatch3(
|
|
53890
|
+
let patch = createPatch3(path2, oldContent, newContent);
|
|
54052
53891
|
const lines = patch.split(`
|
|
54053
53892
|
`);
|
|
54054
53893
|
const hunkStartIndex = lines.findIndex((line) => line.startsWith("@@"));
|
|
@@ -54057,13 +53896,13 @@ var handleProposeWriteFile = async (params2) => {
|
|
|
54057
53896
|
`);
|
|
54058
53897
|
}
|
|
54059
53898
|
const isNewFile = initialContent === null;
|
|
54060
|
-
const message = isNewFile ? `Proposed new file ${
|
|
53899
|
+
const message = isNewFile ? `Proposed new file ${path2}` : `Proposed changes to ${path2}`;
|
|
54061
53900
|
return {
|
|
54062
53901
|
output: [
|
|
54063
53902
|
{
|
|
54064
53903
|
type: "json",
|
|
54065
53904
|
value: {
|
|
54066
|
-
file:
|
|
53905
|
+
file: path2,
|
|
54067
53906
|
message,
|
|
54068
53907
|
unifiedDiff: patch
|
|
54069
53908
|
}
|
|
@@ -54794,15 +54633,15 @@ var handleStrReplace = async (params2) => {
|
|
|
54794
54633
|
requestOptionalFile,
|
|
54795
54634
|
writeToClient
|
|
54796
54635
|
} = params2;
|
|
54797
|
-
const { path:
|
|
54798
|
-
if (!fileProcessingState2.promisesByPath[
|
|
54799
|
-
fileProcessingState2.promisesByPath[
|
|
54636
|
+
const { path: path2, replacements } = toolCall.input;
|
|
54637
|
+
if (!fileProcessingState2.promisesByPath[path2]) {
|
|
54638
|
+
fileProcessingState2.promisesByPath[path2] = [];
|
|
54800
54639
|
}
|
|
54801
|
-
const previousPromises = fileProcessingState2.promisesByPath[
|
|
54640
|
+
const previousPromises = fileProcessingState2.promisesByPath[path2];
|
|
54802
54641
|
const previousEdit = previousPromises[previousPromises.length - 1];
|
|
54803
|
-
const latestContentPromise = previousEdit ? previousEdit.then((maybeResult) => maybeResult && ("content" in maybeResult) ? maybeResult.content : requestOptionalFile({ ...params2, filePath:
|
|
54642
|
+
const latestContentPromise = previousEdit ? previousEdit.then((maybeResult) => maybeResult && ("content" in maybeResult) ? maybeResult.content : requestOptionalFile({ ...params2, filePath: path2 })) : requestOptionalFile({ ...params2, filePath: path2 });
|
|
54804
54643
|
const newPromise = processStrReplace({
|
|
54805
|
-
path:
|
|
54644
|
+
path: path2,
|
|
54806
54645
|
replacements,
|
|
54807
54646
|
initialContentPromise: latestContentPromise,
|
|
54808
54647
|
logger: logger2
|
|
@@ -54810,14 +54649,14 @@ var handleStrReplace = async (params2) => {
|
|
|
54810
54649
|
logger2.error(error, "Error processing str_replace block");
|
|
54811
54650
|
return {
|
|
54812
54651
|
tool: "str_replace",
|
|
54813
|
-
path:
|
|
54652
|
+
path: path2,
|
|
54814
54653
|
error: "Unknown error: Failed to process the str_replace block."
|
|
54815
54654
|
};
|
|
54816
54655
|
}).then((fileProcessingResult) => ({
|
|
54817
54656
|
...fileProcessingResult,
|
|
54818
54657
|
toolCallId: toolCall.toolCallId
|
|
54819
54658
|
}));
|
|
54820
|
-
fileProcessingState2.promisesByPath[
|
|
54659
|
+
fileProcessingState2.promisesByPath[path2].push(newPromise);
|
|
54821
54660
|
fileProcessingState2.allPromises.push(newPromise);
|
|
54822
54661
|
await previousToolCallFinished;
|
|
54823
54662
|
const strReplaceResult = await newPromise;
|
|
@@ -55890,10 +55729,10 @@ async function formatPrompt(params2) {
|
|
|
55890
55729
|
[PLACEHOLDER.USER_INPUT_PROMPT]: () => escapeString(lastUserInput ?? ""),
|
|
55891
55730
|
[PLACEHOLDER.INITIAL_AGENT_PROMPT]: () => escapeString(intitialAgentPrompt ?? ""),
|
|
55892
55731
|
[PLACEHOLDER.KNOWLEDGE_FILES_CONTENTS]: () => Object.entries({
|
|
55893
|
-
...Object.fromEntries(Object.entries(fileContext.knowledgeFiles).filter(([
|
|
55732
|
+
...Object.fromEntries(Object.entries(fileContext.knowledgeFiles).filter(([path2]) => ["knowledge.md", "CLAUDE.md"].includes(path2)).map(([path2, content]) => [path2, content.trim()])),
|
|
55894
55733
|
...fileContext.userKnowledgeFiles
|
|
55895
|
-
}).map(([
|
|
55896
|
-
return `\`\`\`${
|
|
55734
|
+
}).map(([path2, content]) => {
|
|
55735
|
+
return `\`\`\`${path2}
|
|
55897
55736
|
${content.trim()}
|
|
55898
55737
|
\`\`\``;
|
|
55899
55738
|
}).join(`
|
|
@@ -57911,7 +57750,7 @@ class Protocol {
|
|
|
57911
57750
|
}
|
|
57912
57751
|
request(request, resultSchema, options) {
|
|
57913
57752
|
const { relatedRequestId, resumptionToken, onresumptiontoken } = options !== null && options !== undefined ? options : {};
|
|
57914
|
-
return new Promise((
|
|
57753
|
+
return new Promise((resolve, reject) => {
|
|
57915
57754
|
var _a, _b, _c, _d, _e, _f;
|
|
57916
57755
|
if (!this._transport) {
|
|
57917
57756
|
reject(new Error("Not connected"));
|
|
@@ -57962,7 +57801,7 @@ class Protocol {
|
|
|
57962
57801
|
}
|
|
57963
57802
|
try {
|
|
57964
57803
|
const result = resultSchema.parse(response.result);
|
|
57965
|
-
|
|
57804
|
+
resolve(result);
|
|
57966
57805
|
} catch (error) {
|
|
57967
57806
|
reject(error);
|
|
57968
57807
|
}
|
|
@@ -59366,7 +59205,7 @@ class SSEClientTransport {
|
|
|
59366
59205
|
_startOrAuth() {
|
|
59367
59206
|
var _a, _b, _c;
|
|
59368
59207
|
const fetchImpl = (_c = (_b = (_a = this === null || this === undefined ? undefined : this._eventSourceInit) === null || _a === undefined ? undefined : _a.fetch) !== null && _b !== undefined ? _b : this._fetch) !== null && _c !== undefined ? _c : fetch;
|
|
59369
|
-
return new Promise((
|
|
59208
|
+
return new Promise((resolve, reject) => {
|
|
59370
59209
|
this._eventSource = new EventSource(this._url.href, {
|
|
59371
59210
|
...this._eventSourceInit,
|
|
59372
59211
|
fetch: async (url, init) => {
|
|
@@ -59386,7 +59225,7 @@ class SSEClientTransport {
|
|
|
59386
59225
|
this._eventSource.onerror = (event) => {
|
|
59387
59226
|
var _a2;
|
|
59388
59227
|
if (event.code === 401 && this._authProvider) {
|
|
59389
|
-
this._authThenStart().then(
|
|
59228
|
+
this._authThenStart().then(resolve, reject);
|
|
59390
59229
|
return;
|
|
59391
59230
|
}
|
|
59392
59231
|
const error = new SseError(event.code, event.message, event);
|
|
@@ -59408,7 +59247,7 @@ class SSEClientTransport {
|
|
|
59408
59247
|
this.close();
|
|
59409
59248
|
return;
|
|
59410
59249
|
}
|
|
59411
|
-
|
|
59250
|
+
resolve();
|
|
59412
59251
|
});
|
|
59413
59252
|
this._eventSource.onmessage = (event) => {
|
|
59414
59253
|
var _a2, _b2;
|
|
@@ -59571,7 +59410,7 @@ class StdioClientTransport {
|
|
|
59571
59410
|
if (this._process) {
|
|
59572
59411
|
throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
59573
59412
|
}
|
|
59574
|
-
return new Promise((
|
|
59413
|
+
return new Promise((resolve, reject) => {
|
|
59575
59414
|
var _a, _b, _c, _d, _e;
|
|
59576
59415
|
this._process = import_cross_spawn.default(this._serverParams.command, (_a = this._serverParams.args) !== null && _a !== undefined ? _a : [], {
|
|
59577
59416
|
env: {
|
|
@@ -59594,7 +59433,7 @@ class StdioClientTransport {
|
|
|
59594
59433
|
(_b2 = this.onerror) === null || _b2 === undefined || _b2.call(this, error);
|
|
59595
59434
|
});
|
|
59596
59435
|
this._process.on("spawn", () => {
|
|
59597
|
-
|
|
59436
|
+
resolve();
|
|
59598
59437
|
});
|
|
59599
59438
|
this._process.on("close", (_code) => {
|
|
59600
59439
|
var _a2;
|
|
@@ -59649,16 +59488,16 @@ class StdioClientTransport {
|
|
|
59649
59488
|
this._readBuffer.clear();
|
|
59650
59489
|
}
|
|
59651
59490
|
send(message) {
|
|
59652
|
-
return new Promise((
|
|
59491
|
+
return new Promise((resolve) => {
|
|
59653
59492
|
var _a;
|
|
59654
59493
|
if (!((_a = this._process) === null || _a === undefined ? undefined : _a.stdin)) {
|
|
59655
59494
|
throw new Error("Not connected");
|
|
59656
59495
|
}
|
|
59657
59496
|
const json = serializeMessage(message);
|
|
59658
59497
|
if (this._process.stdin.write(json)) {
|
|
59659
|
-
|
|
59498
|
+
resolve();
|
|
59660
59499
|
} else {
|
|
59661
|
-
this._process.stdin.once("drain",
|
|
59500
|
+
this._process.stdin.once("drain", resolve);
|
|
59662
59501
|
}
|
|
59663
59502
|
});
|
|
59664
59503
|
}
|
|
@@ -60140,12 +59979,216 @@ async function callMCPTool(clientId, ...args) {
|
|
|
60140
59979
|
|
|
60141
59980
|
// src/convex.ts
|
|
60142
59981
|
init_old_constants();
|
|
60143
|
-
var
|
|
59982
|
+
var import_lodash17 = __toESM(require_lodash(), 1);
|
|
60144
59983
|
|
|
60145
59984
|
// src/constants.ts
|
|
60146
59985
|
var CODEBUFF_BINARY = "codebuff";
|
|
60147
59986
|
var WEBSITE_URL = env.NEXT_PUBLIC_CODEBUFF_APP_URL;
|
|
60148
59987
|
|
|
59988
|
+
// src/convex-session-state.ts
|
|
59989
|
+
import z65 from "zod/v4";
|
|
59990
|
+
function processAgentDefinitions(agentDefinitions) {
|
|
59991
|
+
const processedAgentTemplates = {};
|
|
59992
|
+
agentDefinitions.forEach((definition) => {
|
|
59993
|
+
const processedConfig = { ...definition };
|
|
59994
|
+
if (processedConfig.handleSteps && typeof processedConfig.handleSteps === "function") {
|
|
59995
|
+
processedConfig.handleSteps = processedConfig.handleSteps.toString();
|
|
59996
|
+
}
|
|
59997
|
+
if (processedConfig.id) {
|
|
59998
|
+
processedAgentTemplates[processedConfig.id] = processedConfig;
|
|
59999
|
+
}
|
|
60000
|
+
});
|
|
60001
|
+
return processedAgentTemplates;
|
|
60002
|
+
}
|
|
60003
|
+
function processCustomToolDefinitions(customToolDefinitions) {
|
|
60004
|
+
return Object.fromEntries(customToolDefinitions.map((toolDefinition) => {
|
|
60005
|
+
const jsonSchema = z65.toJSONSchema(toolDefinition.inputSchema, {
|
|
60006
|
+
io: "input"
|
|
60007
|
+
});
|
|
60008
|
+
delete jsonSchema["$schema"];
|
|
60009
|
+
return [
|
|
60010
|
+
toolDefinition.toolName,
|
|
60011
|
+
{
|
|
60012
|
+
inputSchema: jsonSchema,
|
|
60013
|
+
description: toolDefinition.description,
|
|
60014
|
+
endsAgentStep: toolDefinition.endsAgentStep,
|
|
60015
|
+
exampleInputs: toolDefinition.exampleInputs
|
|
60016
|
+
}
|
|
60017
|
+
];
|
|
60018
|
+
}));
|
|
60019
|
+
}
|
|
60020
|
+
function buildFileTree(filePaths) {
|
|
60021
|
+
const tree = {};
|
|
60022
|
+
for (const filePath of filePaths) {
|
|
60023
|
+
const parts = filePath.split("/");
|
|
60024
|
+
for (let i = 0;i < parts.length; i++) {
|
|
60025
|
+
const currentPath = parts.slice(0, i + 1).join("/");
|
|
60026
|
+
const isFile = i === parts.length - 1;
|
|
60027
|
+
if (!tree[currentPath]) {
|
|
60028
|
+
tree[currentPath] = {
|
|
60029
|
+
name: parts[i],
|
|
60030
|
+
type: isFile ? "file" : "directory",
|
|
60031
|
+
filePath: currentPath,
|
|
60032
|
+
children: isFile ? undefined : []
|
|
60033
|
+
};
|
|
60034
|
+
}
|
|
60035
|
+
}
|
|
60036
|
+
}
|
|
60037
|
+
const rootNodes = [];
|
|
60038
|
+
const processed = new Set;
|
|
60039
|
+
for (const [path2, node] of Object.entries(tree)) {
|
|
60040
|
+
if (processed.has(path2))
|
|
60041
|
+
continue;
|
|
60042
|
+
const parentPath = path2.substring(0, path2.lastIndexOf("/"));
|
|
60043
|
+
if (parentPath && tree[parentPath]) {
|
|
60044
|
+
const parent = tree[parentPath];
|
|
60045
|
+
if (parent.children && !parent.children.some((child) => child.filePath === path2)) {
|
|
60046
|
+
parent.children.push(node);
|
|
60047
|
+
}
|
|
60048
|
+
} else {
|
|
60049
|
+
rootNodes.push(node);
|
|
60050
|
+
}
|
|
60051
|
+
processed.add(path2);
|
|
60052
|
+
}
|
|
60053
|
+
function sortNodes(nodes) {
|
|
60054
|
+
nodes.sort((a, b) => {
|
|
60055
|
+
if (a.type !== b.type) {
|
|
60056
|
+
return a.type === "directory" ? -1 : 1;
|
|
60057
|
+
}
|
|
60058
|
+
return a.name.localeCompare(b.name);
|
|
60059
|
+
});
|
|
60060
|
+
for (const node of nodes) {
|
|
60061
|
+
if (node.children) {
|
|
60062
|
+
sortNodes(node.children);
|
|
60063
|
+
}
|
|
60064
|
+
}
|
|
60065
|
+
}
|
|
60066
|
+
sortNodes(rootNodes);
|
|
60067
|
+
return rootNodes;
|
|
60068
|
+
}
|
|
60069
|
+
function selectKnowledgeFilePaths(allFilePaths) {
|
|
60070
|
+
const knowledgeCandidates = allFilePaths.filter((filePath) => {
|
|
60071
|
+
const lowercaseFilePath = filePath.toLowerCase();
|
|
60072
|
+
return lowercaseFilePath.endsWith("knowledge.md") || lowercaseFilePath.endsWith("agents.md") || lowercaseFilePath.endsWith("claude.md");
|
|
60073
|
+
});
|
|
60074
|
+
const byDirectory = new Map;
|
|
60075
|
+
for (const filePath of knowledgeCandidates) {
|
|
60076
|
+
const lastSlash = filePath.lastIndexOf("/");
|
|
60077
|
+
const dir = lastSlash >= 0 ? filePath.substring(0, lastSlash) : "";
|
|
60078
|
+
if (!byDirectory.has(dir)) {
|
|
60079
|
+
byDirectory.set(dir, []);
|
|
60080
|
+
}
|
|
60081
|
+
byDirectory.get(dir).push(filePath);
|
|
60082
|
+
}
|
|
60083
|
+
const selectedFiles = [];
|
|
60084
|
+
for (const files of byDirectory.values()) {
|
|
60085
|
+
const knowledgeMd = files.find((f) => f.toLowerCase().endsWith("knowledge.md"));
|
|
60086
|
+
const agentsMd = files.find((f) => f.toLowerCase().endsWith("agents.md"));
|
|
60087
|
+
const claudeMd = files.find((f) => f.toLowerCase().endsWith("claude.md"));
|
|
60088
|
+
const selectedKnowledgeFile = knowledgeMd || agentsMd || claudeMd;
|
|
60089
|
+
if (selectedKnowledgeFile) {
|
|
60090
|
+
selectedFiles.push(selectedKnowledgeFile);
|
|
60091
|
+
}
|
|
60092
|
+
}
|
|
60093
|
+
return selectedFiles;
|
|
60094
|
+
}
|
|
60095
|
+
function deriveKnowledgeFiles(projectFiles) {
|
|
60096
|
+
const allFilePaths = Object.keys(projectFiles);
|
|
60097
|
+
const selectedFilePaths = selectKnowledgeFilePaths(allFilePaths);
|
|
60098
|
+
const knowledgeFiles = {};
|
|
60099
|
+
for (const filePath of selectedFilePaths) {
|
|
60100
|
+
knowledgeFiles[filePath] = projectFiles[filePath];
|
|
60101
|
+
}
|
|
60102
|
+
return knowledgeFiles;
|
|
60103
|
+
}
|
|
60104
|
+
async function convexInitialSessionState(params2) {
|
|
60105
|
+
const { cwd, maxAgentSteps, fs, spawn: spawn2, logger: logger2 } = params2;
|
|
60106
|
+
let { agentDefinitions, customToolDefinitions, projectFiles, knowledgeFiles } = params2;
|
|
60107
|
+
if (!agentDefinitions) {
|
|
60108
|
+
agentDefinitions = [];
|
|
60109
|
+
}
|
|
60110
|
+
if (!customToolDefinitions) {
|
|
60111
|
+
customToolDefinitions = [];
|
|
60112
|
+
}
|
|
60113
|
+
if (projectFiles === undefined) {
|
|
60114
|
+
projectFiles = {};
|
|
60115
|
+
}
|
|
60116
|
+
if (knowledgeFiles === undefined) {
|
|
60117
|
+
knowledgeFiles = projectFiles ? deriveKnowledgeFiles(projectFiles) : {};
|
|
60118
|
+
}
|
|
60119
|
+
const processedAgentTemplates = agentDefinitions.length > 0 ? processAgentDefinitions(agentDefinitions) : {};
|
|
60120
|
+
const processedCustomToolDefinitions = processCustomToolDefinitions(customToolDefinitions);
|
|
60121
|
+
const filePaths = Object.keys(projectFiles).sort();
|
|
60122
|
+
const fileTree = buildFileTree(filePaths);
|
|
60123
|
+
const fileTokenScores = {};
|
|
60124
|
+
const tokenCallers = {};
|
|
60125
|
+
const gitChanges = {
|
|
60126
|
+
status: "",
|
|
60127
|
+
diff: "",
|
|
60128
|
+
diffCached: "",
|
|
60129
|
+
lastCommitMessages: ""
|
|
60130
|
+
};
|
|
60131
|
+
const initialState = getInitialSessionState({
|
|
60132
|
+
projectRoot: cwd ?? "/convex",
|
|
60133
|
+
cwd: cwd ?? "/convex",
|
|
60134
|
+
fileTree,
|
|
60135
|
+
fileTokenScores,
|
|
60136
|
+
tokenCallers,
|
|
60137
|
+
knowledgeFiles,
|
|
60138
|
+
userKnowledgeFiles: {},
|
|
60139
|
+
agentTemplates: processedAgentTemplates,
|
|
60140
|
+
customToolDefinitions: processedCustomToolDefinitions,
|
|
60141
|
+
gitChanges,
|
|
60142
|
+
changesSinceLastChat: {},
|
|
60143
|
+
shellConfigFiles: {},
|
|
60144
|
+
systemInfo: {
|
|
60145
|
+
platform: "linux",
|
|
60146
|
+
shell: "bash",
|
|
60147
|
+
nodeVersion: process.version,
|
|
60148
|
+
arch: "x64",
|
|
60149
|
+
homedir: "/tmp",
|
|
60150
|
+
cpus: 1
|
|
60151
|
+
}
|
|
60152
|
+
});
|
|
60153
|
+
if (maxAgentSteps) {
|
|
60154
|
+
initialState.mainAgentState.stepsRemaining = maxAgentSteps;
|
|
60155
|
+
}
|
|
60156
|
+
return initialState;
|
|
60157
|
+
}
|
|
60158
|
+
async function convexApplyOverridesToSessionState(cwd, baseSessionState, overrides) {
|
|
60159
|
+
const sessionState = JSON.parse(JSON.stringify(baseSessionState));
|
|
60160
|
+
if (overrides.maxAgentSteps !== undefined) {
|
|
60161
|
+
sessionState.mainAgentState.stepsRemaining = overrides.maxAgentSteps;
|
|
60162
|
+
}
|
|
60163
|
+
if (overrides.projectFiles !== undefined) {
|
|
60164
|
+
const filePaths = Object.keys(overrides.projectFiles).sort();
|
|
60165
|
+
sessionState.fileContext.fileTree = buildFileTree(filePaths);
|
|
60166
|
+
sessionState.fileContext.fileTokenScores = {};
|
|
60167
|
+
sessionState.fileContext.tokenCallers = {};
|
|
60168
|
+
if (overrides.knowledgeFiles === undefined) {
|
|
60169
|
+
sessionState.fileContext.knowledgeFiles = deriveKnowledgeFiles(overrides.projectFiles);
|
|
60170
|
+
}
|
|
60171
|
+
}
|
|
60172
|
+
if (overrides.knowledgeFiles !== undefined) {
|
|
60173
|
+
sessionState.fileContext.knowledgeFiles = overrides.knowledgeFiles;
|
|
60174
|
+
}
|
|
60175
|
+
if (overrides.agentDefinitions !== undefined) {
|
|
60176
|
+
const processedAgentTemplates = processAgentDefinitions(overrides.agentDefinitions);
|
|
60177
|
+
sessionState.fileContext.agentTemplates = {
|
|
60178
|
+
...sessionState.fileContext.agentTemplates,
|
|
60179
|
+
...processedAgentTemplates
|
|
60180
|
+
};
|
|
60181
|
+
}
|
|
60182
|
+
if (overrides.customToolDefinitions !== undefined) {
|
|
60183
|
+
const processedCustomToolDefinitions = processCustomToolDefinitions(overrides.customToolDefinitions);
|
|
60184
|
+
sessionState.fileContext.customToolDefinitions = {
|
|
60185
|
+
...sessionState.fileContext.customToolDefinitions,
|
|
60186
|
+
...processedCustomToolDefinitions
|
|
60187
|
+
};
|
|
60188
|
+
}
|
|
60189
|
+
return sessionState;
|
|
60190
|
+
}
|
|
60191
|
+
|
|
60149
60192
|
// src/error-utils.ts
|
|
60150
60193
|
var RETRYABLE_STATUS_CODES2 = new Set([408, 429, 500, 502, 503, 504]);
|
|
60151
60194
|
function createHttpError(message, statusCode) {
|
|
@@ -60210,7 +60253,7 @@ var getCiEnv = () => ({
|
|
|
60210
60253
|
var ciEnv = getCiEnv();
|
|
60211
60254
|
|
|
60212
60255
|
// src/impl/database.ts
|
|
60213
|
-
import
|
|
60256
|
+
import z66 from "zod/v4";
|
|
60214
60257
|
|
|
60215
60258
|
// src/retry-config.ts
|
|
60216
60259
|
var MAX_RETRIES_PER_MESSAGE = 3;
|
|
@@ -60221,8 +60264,8 @@ var RECONNECTION_RETRY_DELAY_MS = 500;
|
|
|
60221
60264
|
|
|
60222
60265
|
// src/impl/database.ts
|
|
60223
60266
|
var userInfoCache = {};
|
|
60224
|
-
var agentsResponseSchema =
|
|
60225
|
-
version:
|
|
60267
|
+
var agentsResponseSchema = z66.object({
|
|
60268
|
+
version: z66.string(),
|
|
60226
60269
|
data: DynamicAgentTemplateSchema
|
|
60227
60270
|
});
|
|
60228
60271
|
async function fetchWithRetry(url, options, logger2) {
|
|
@@ -60236,7 +60279,7 @@ async function fetchWithRetry(url, options, logger2) {
|
|
|
60236
60279
|
}
|
|
60237
60280
|
if (attempt < MAX_RETRIES_PER_MESSAGE) {
|
|
60238
60281
|
logger2?.warn({ status: response.status, attempt: attempt + 1, url: String(url) }, `Retryable HTTP error, retrying in ${backoffDelay}ms`);
|
|
60239
|
-
await new Promise((
|
|
60282
|
+
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
|
60240
60283
|
backoffDelay = Math.min(backoffDelay * 2, RETRY_BACKOFF_MAX_DELAY_MS);
|
|
60241
60284
|
} else {
|
|
60242
60285
|
return response;
|
|
@@ -60245,7 +60288,7 @@ async function fetchWithRetry(url, options, logger2) {
|
|
|
60245
60288
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
60246
60289
|
if (attempt < MAX_RETRIES_PER_MESSAGE) {
|
|
60247
60290
|
logger2?.warn({ error: getErrorObject(lastError), attempt: attempt + 1, url: String(url) }, `Network error, retrying in ${backoffDelay}ms`);
|
|
60248
|
-
await new Promise((
|
|
60291
|
+
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
|
60249
60292
|
backoffDelay = Math.min(backoffDelay * 2, RETRY_BACKOFF_MAX_DELAY_MS);
|
|
60250
60293
|
}
|
|
60251
60294
|
}
|
|
@@ -60549,7 +60592,7 @@ import {
|
|
|
60549
60592
|
} from "ai";
|
|
60550
60593
|
|
|
60551
60594
|
// src/impl/model-provider.ts
|
|
60552
|
-
import
|
|
60595
|
+
import path3 from "path";
|
|
60553
60596
|
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
60554
60597
|
|
|
60555
60598
|
// ../common/src/constants/byok.ts
|
|
@@ -61309,7 +61352,7 @@ function convertToBase64(value) {
|
|
|
61309
61352
|
}
|
|
61310
61353
|
|
|
61311
61354
|
// ../packages/internal/src/openai-compatible/chat/openai-compatible-chat-language-model.ts
|
|
61312
|
-
import { z as
|
|
61355
|
+
import { z as z69 } from "zod/v4";
|
|
61313
61356
|
|
|
61314
61357
|
// ../packages/internal/src/openai-compatible/chat/convert-to-openai-compatible-chat-messages.ts
|
|
61315
61358
|
function getOpenAIMetadata(message) {
|
|
@@ -61452,21 +61495,21 @@ function mapOpenAICompatibleFinishReason(finishReason) {
|
|
|
61452
61495
|
}
|
|
61453
61496
|
|
|
61454
61497
|
// ../packages/internal/src/openai-compatible/chat/openai-compatible-chat-options.ts
|
|
61455
|
-
import { z as
|
|
61456
|
-
var openaiCompatibleProviderOptions =
|
|
61457
|
-
user:
|
|
61458
|
-
reasoningEffort:
|
|
61459
|
-
textVerbosity:
|
|
61498
|
+
import { z as z67 } from "zod/v4";
|
|
61499
|
+
var openaiCompatibleProviderOptions = z67.object({
|
|
61500
|
+
user: z67.string().optional(),
|
|
61501
|
+
reasoningEffort: z67.string().optional(),
|
|
61502
|
+
textVerbosity: z67.string().optional()
|
|
61460
61503
|
});
|
|
61461
61504
|
|
|
61462
61505
|
// ../packages/internal/src/openai-compatible/openai-compatible-error.ts
|
|
61463
|
-
import { z as
|
|
61464
|
-
var openaiCompatibleErrorDataSchema =
|
|
61465
|
-
error:
|
|
61466
|
-
message:
|
|
61467
|
-
type:
|
|
61468
|
-
param:
|
|
61469
|
-
code:
|
|
61506
|
+
import { z as z68 } from "zod/v4";
|
|
61507
|
+
var openaiCompatibleErrorDataSchema = z68.object({
|
|
61508
|
+
error: z68.object({
|
|
61509
|
+
message: z68.string(),
|
|
61510
|
+
type: z68.string().nullish(),
|
|
61511
|
+
param: z68.any().nullish(),
|
|
61512
|
+
code: z68.union([z68.string(), z68.number()]).nullish()
|
|
61470
61513
|
})
|
|
61471
61514
|
});
|
|
61472
61515
|
var defaultOpenAICompatibleErrorStructure = {
|
|
@@ -61957,62 +62000,62 @@ class OpenAICompatibleChatLanguageModel {
|
|
|
61957
62000
|
};
|
|
61958
62001
|
}
|
|
61959
62002
|
}
|
|
61960
|
-
var openaiCompatibleTokenUsageSchema =
|
|
61961
|
-
prompt_tokens:
|
|
61962
|
-
completion_tokens:
|
|
61963
|
-
total_tokens:
|
|
61964
|
-
prompt_tokens_details:
|
|
61965
|
-
cached_tokens:
|
|
62003
|
+
var openaiCompatibleTokenUsageSchema = z69.object({
|
|
62004
|
+
prompt_tokens: z69.number().nullish(),
|
|
62005
|
+
completion_tokens: z69.number().nullish(),
|
|
62006
|
+
total_tokens: z69.number().nullish(),
|
|
62007
|
+
prompt_tokens_details: z69.object({
|
|
62008
|
+
cached_tokens: z69.number().nullish()
|
|
61966
62009
|
}).nullish(),
|
|
61967
|
-
completion_tokens_details:
|
|
61968
|
-
reasoning_tokens:
|
|
61969
|
-
accepted_prediction_tokens:
|
|
61970
|
-
rejected_prediction_tokens:
|
|
62010
|
+
completion_tokens_details: z69.object({
|
|
62011
|
+
reasoning_tokens: z69.number().nullish(),
|
|
62012
|
+
accepted_prediction_tokens: z69.number().nullish(),
|
|
62013
|
+
rejected_prediction_tokens: z69.number().nullish()
|
|
61971
62014
|
}).nullish()
|
|
61972
62015
|
}).nullish();
|
|
61973
|
-
var OpenAICompatibleChatResponseSchema =
|
|
61974
|
-
id:
|
|
61975
|
-
created:
|
|
61976
|
-
model:
|
|
61977
|
-
choices:
|
|
61978
|
-
message:
|
|
61979
|
-
role:
|
|
61980
|
-
content:
|
|
61981
|
-
reasoning_content:
|
|
61982
|
-
reasoning:
|
|
61983
|
-
tool_calls:
|
|
61984
|
-
id:
|
|
61985
|
-
function:
|
|
61986
|
-
name:
|
|
61987
|
-
arguments:
|
|
62016
|
+
var OpenAICompatibleChatResponseSchema = z69.object({
|
|
62017
|
+
id: z69.string().nullish(),
|
|
62018
|
+
created: z69.number().nullish(),
|
|
62019
|
+
model: z69.string().nullish(),
|
|
62020
|
+
choices: z69.array(z69.object({
|
|
62021
|
+
message: z69.object({
|
|
62022
|
+
role: z69.literal("assistant").nullish(),
|
|
62023
|
+
content: z69.string().nullish(),
|
|
62024
|
+
reasoning_content: z69.string().nullish(),
|
|
62025
|
+
reasoning: z69.string().nullish(),
|
|
62026
|
+
tool_calls: z69.array(z69.object({
|
|
62027
|
+
id: z69.string().nullish(),
|
|
62028
|
+
function: z69.object({
|
|
62029
|
+
name: z69.string(),
|
|
62030
|
+
arguments: z69.string()
|
|
61988
62031
|
})
|
|
61989
62032
|
})).nullish()
|
|
61990
62033
|
}),
|
|
61991
|
-
finish_reason:
|
|
62034
|
+
finish_reason: z69.string().nullish()
|
|
61992
62035
|
})),
|
|
61993
62036
|
usage: openaiCompatibleTokenUsageSchema
|
|
61994
62037
|
});
|
|
61995
|
-
var createOpenAICompatibleChatChunkSchema = (errorSchema) =>
|
|
61996
|
-
|
|
61997
|
-
id:
|
|
61998
|
-
created:
|
|
61999
|
-
model:
|
|
62000
|
-
choices:
|
|
62001
|
-
delta:
|
|
62002
|
-
role:
|
|
62003
|
-
content:
|
|
62004
|
-
reasoning_content:
|
|
62005
|
-
reasoning:
|
|
62006
|
-
tool_calls:
|
|
62007
|
-
index:
|
|
62008
|
-
id:
|
|
62009
|
-
function:
|
|
62010
|
-
name:
|
|
62011
|
-
arguments:
|
|
62038
|
+
var createOpenAICompatibleChatChunkSchema = (errorSchema) => z69.union([
|
|
62039
|
+
z69.object({
|
|
62040
|
+
id: z69.string().nullish(),
|
|
62041
|
+
created: z69.number().nullish(),
|
|
62042
|
+
model: z69.string().nullish(),
|
|
62043
|
+
choices: z69.array(z69.object({
|
|
62044
|
+
delta: z69.object({
|
|
62045
|
+
role: z69.enum(["assistant"]).nullish(),
|
|
62046
|
+
content: z69.string().nullish(),
|
|
62047
|
+
reasoning_content: z69.string().nullish(),
|
|
62048
|
+
reasoning: z69.string().nullish(),
|
|
62049
|
+
tool_calls: z69.array(z69.object({
|
|
62050
|
+
index: z69.number(),
|
|
62051
|
+
id: z69.string().nullish(),
|
|
62052
|
+
function: z69.object({
|
|
62053
|
+
name: z69.string().nullish(),
|
|
62054
|
+
arguments: z69.string().nullish()
|
|
62012
62055
|
})
|
|
62013
62056
|
})).nullish()
|
|
62014
62057
|
}).nullish(),
|
|
62015
|
-
finish_reason:
|
|
62058
|
+
finish_reason: z69.string().nullish()
|
|
62016
62059
|
})),
|
|
62017
62060
|
usage: openaiCompatibleTokenUsageSchema
|
|
62018
62061
|
}),
|
|
@@ -62022,22 +62065,22 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => z68.union([
|
|
|
62022
62065
|
var VERSION2 = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
|
|
62023
62066
|
// src/credentials.ts
|
|
62024
62067
|
import fs from "fs";
|
|
62025
|
-
import
|
|
62026
|
-
import
|
|
62068
|
+
import path2 from "node:path";
|
|
62069
|
+
import os from "os";
|
|
62027
62070
|
|
|
62028
62071
|
// ../common/src/util/credentials.ts
|
|
62029
|
-
import { z as
|
|
62030
|
-
var userSchema =
|
|
62031
|
-
id:
|
|
62032
|
-
email:
|
|
62033
|
-
name:
|
|
62034
|
-
authToken:
|
|
62035
|
-
fingerprintId:
|
|
62036
|
-
fingerprintHash:
|
|
62072
|
+
import { z as z70 } from "zod/v4";
|
|
62073
|
+
var userSchema = z70.object({
|
|
62074
|
+
id: z70.string(),
|
|
62075
|
+
email: z70.string(),
|
|
62076
|
+
name: z70.string().nullable(),
|
|
62077
|
+
authToken: z70.string(),
|
|
62078
|
+
fingerprintId: z70.string(),
|
|
62079
|
+
fingerprintHash: z70.string()
|
|
62037
62080
|
});
|
|
62038
62081
|
|
|
62039
62082
|
// src/credentials.ts
|
|
62040
|
-
import { z as
|
|
62083
|
+
import { z as z71 } from "zod/v4";
|
|
62041
62084
|
|
|
62042
62085
|
// src/env.ts
|
|
62043
62086
|
var getByokOpenrouterApiKeyFromEnv = () => {
|
|
@@ -62048,13 +62091,13 @@ var getClaudeOAuthTokenFromEnv = () => {
|
|
|
62048
62091
|
};
|
|
62049
62092
|
|
|
62050
62093
|
// src/credentials.ts
|
|
62051
|
-
var claudeOAuthSchema =
|
|
62052
|
-
accessToken:
|
|
62053
|
-
refreshToken:
|
|
62054
|
-
expiresAt:
|
|
62055
|
-
connectedAt:
|
|
62094
|
+
var claudeOAuthSchema = z71.object({
|
|
62095
|
+
accessToken: z71.string(),
|
|
62096
|
+
refreshToken: z71.string(),
|
|
62097
|
+
expiresAt: z71.number(),
|
|
62098
|
+
connectedAt: z71.number()
|
|
62056
62099
|
});
|
|
62057
|
-
var credentialsFileSchema =
|
|
62100
|
+
var credentialsFileSchema = z71.object({
|
|
62058
62101
|
default: userSchema.optional(),
|
|
62059
62102
|
claudeOAuth: claudeOAuthSchema.optional()
|
|
62060
62103
|
});
|
|
@@ -62065,10 +62108,10 @@ var ensureDirectoryExistsSync = (dir) => {
|
|
|
62065
62108
|
};
|
|
62066
62109
|
var getConfigDir = (clientEnv = env) => {
|
|
62067
62110
|
const envSuffix = clientEnv.NEXT_PUBLIC_CB_ENVIRONMENT && clientEnv.NEXT_PUBLIC_CB_ENVIRONMENT !== "prod" ? `-${clientEnv.NEXT_PUBLIC_CB_ENVIRONMENT}` : "";
|
|
62068
|
-
return
|
|
62111
|
+
return path2.join(os.homedir(), ".config", `manicode${envSuffix}`);
|
|
62069
62112
|
};
|
|
62070
62113
|
var getCredentialsPath = (clientEnv = env) => {
|
|
62071
|
-
return
|
|
62114
|
+
return path2.join(getConfigDir(clientEnv), "credentials.json");
|
|
62072
62115
|
};
|
|
62073
62116
|
var getClaudeOAuthCredentials = (clientEnv = env) => {
|
|
62074
62117
|
const envToken = getClaudeOAuthTokenFromEnv();
|
|
@@ -62300,7 +62343,7 @@ function createCodebuffBackendModel(apiKey, model) {
|
|
|
62300
62343
|
const openrouterApiKey = getByokOpenrouterApiKeyFromEnv();
|
|
62301
62344
|
return new OpenAICompatibleChatLanguageModel(model, {
|
|
62302
62345
|
provider: "codebuff",
|
|
62303
|
-
url: ({ path: endpoint }) => new URL(
|
|
62346
|
+
url: ({ path: endpoint }) => new URL(path3.join("/api/v1", endpoint), WEBSITE_URL).toString(),
|
|
62304
62347
|
headers: () => ({
|
|
62305
62348
|
Authorization: `Bearer ${apiKey}`,
|
|
62306
62349
|
"user-agent": `ai-sdk/openai-compatible/${VERSION2}/codebuff`,
|
|
@@ -62808,1218 +62851,6 @@ function getAgentRuntimeImpl(params2) {
|
|
|
62808
62851
|
};
|
|
62809
62852
|
}
|
|
62810
62853
|
|
|
62811
|
-
// src/run-state.ts
|
|
62812
|
-
import * as os4 from "os";
|
|
62813
|
-
import path9 from "path";
|
|
62814
|
-
|
|
62815
|
-
// ../packages/code-map/src/parse.ts
|
|
62816
|
-
import * as fs4 from "fs";
|
|
62817
|
-
import * as path7 from "path";
|
|
62818
|
-
|
|
62819
|
-
// ../packages/code-map/src/languages.ts
|
|
62820
|
-
import * as fs3 from "fs";
|
|
62821
|
-
import * as path6 from "path";
|
|
62822
|
-
import { Language, Parser as Parser2, Query } from "web-tree-sitter";
|
|
62823
|
-
|
|
62824
|
-
// ../packages/code-map/src/init-node.ts
|
|
62825
|
-
import * as fs2 from "fs";
|
|
62826
|
-
import * as path5 from "path";
|
|
62827
|
-
import { Parser } from "web-tree-sitter";
|
|
62828
|
-
async function initTreeSitterForNode() {
|
|
62829
|
-
await Parser.init({
|
|
62830
|
-
locateFile: (name14, scriptDir) => {
|
|
62831
|
-
if (name14 === "tree-sitter.wasm") {
|
|
62832
|
-
const fallback = path5.join(scriptDir, name14);
|
|
62833
|
-
if (fs2.existsSync(fallback)) {
|
|
62834
|
-
return fallback;
|
|
62835
|
-
}
|
|
62836
|
-
const pkgDir = path5.dirname(__require.resolve("web-tree-sitter"));
|
|
62837
|
-
const wasm = path5.join(pkgDir, "tree-sitter.wasm");
|
|
62838
|
-
if (fs2.existsSync(wasm)) {
|
|
62839
|
-
return wasm;
|
|
62840
|
-
}
|
|
62841
|
-
throw new Error(`Internal error: web-tree-sitter/tree-sitter.wasm not found at ${wasm}. Ensure the file is included in your deployment bundle.`);
|
|
62842
|
-
}
|
|
62843
|
-
return path5.join(scriptDir, name14);
|
|
62844
|
-
}
|
|
62845
|
-
});
|
|
62846
|
-
}
|
|
62847
|
-
|
|
62848
|
-
// ../packages/code-map/src/tree-sitter-queries/tree-sitter-c_sharp-tags.scm
|
|
62849
|
-
var tree_sitter_c_sharp_tags_default = `(class_declaration
|
|
62850
|
-
name: (identifier) @identifier
|
|
62851
|
-
)
|
|
62852
|
-
|
|
62853
|
-
(interface_declaration
|
|
62854
|
-
name: (identifier) @identifier
|
|
62855
|
-
)
|
|
62856
|
-
|
|
62857
|
-
(method_declaration
|
|
62858
|
-
name: (identifier) @identifier
|
|
62859
|
-
)
|
|
62860
|
-
|
|
62861
|
-
; Method calls
|
|
62862
|
-
(invocation_expression
|
|
62863
|
-
function: (identifier) @call.identifier)
|
|
62864
|
-
|
|
62865
|
-
(invocation_expression
|
|
62866
|
-
function: (member_access_expression
|
|
62867
|
-
name: (identifier) @call.identifier))
|
|
62868
|
-
|
|
62869
|
-
; Constructor calls
|
|
62870
|
-
(object_creation_expression
|
|
62871
|
-
type: (identifier) @call.identifier)`;
|
|
62872
|
-
|
|
62873
|
-
// ../packages/code-map/src/tree-sitter-queries/tree-sitter-cpp-tags.scm
|
|
62874
|
-
var tree_sitter_cpp_tags_default = `(struct_specifier name: (type_identifier) @identifier)
|
|
62875
|
-
|
|
62876
|
-
(declaration type: (union_specifier name: (type_identifier) @identifier))
|
|
62877
|
-
|
|
62878
|
-
(function_declarator declarator: (identifier) @identifier)
|
|
62879
|
-
|
|
62880
|
-
(function_declarator declarator: (field_identifier) @identifier)
|
|
62881
|
-
|
|
62882
|
-
(function_declarator declarator: (qualified_identifier scope: (namespace_identifier) name: (identifier) @identifier))
|
|
62883
|
-
|
|
62884
|
-
(type_definition declarator: (type_identifier) @identifier)
|
|
62885
|
-
|
|
62886
|
-
(enum_specifier name: (type_identifier) @identifier)
|
|
62887
|
-
|
|
62888
|
-
(class_specifier name: (type_identifier) @identifier)
|
|
62889
|
-
|
|
62890
|
-
; Function calls
|
|
62891
|
-
(call_expression
|
|
62892
|
-
function: (identifier) @call.identifier)
|
|
62893
|
-
|
|
62894
|
-
(call_expression
|
|
62895
|
-
function: (field_expression field: (field_identifier) @call.identifier))
|
|
62896
|
-
|
|
62897
|
-
; Constructor calls
|
|
62898
|
-
(class_specifier
|
|
62899
|
-
name: (type_identifier) @call.identifier)
|
|
62900
|
-
|
|
62901
|
-
(new_expression
|
|
62902
|
-
type: (type_identifier) @call.identifier)`;
|
|
62903
|
-
|
|
62904
|
-
// ../packages/code-map/src/tree-sitter-queries/tree-sitter-go-tags.scm
|
|
62905
|
-
var tree_sitter_go_tags_default = `(
|
|
62906
|
-
(comment)*
|
|
62907
|
-
.
|
|
62908
|
-
(function_declaration
|
|
62909
|
-
name: (identifier) @identifier)
|
|
62910
|
-
)
|
|
62911
|
-
|
|
62912
|
-
(
|
|
62913
|
-
(comment)*
|
|
62914
|
-
.
|
|
62915
|
-
(method_declaration
|
|
62916
|
-
name: (field_identifier) @identifier)
|
|
62917
|
-
)
|
|
62918
|
-
|
|
62919
|
-
(type_spec
|
|
62920
|
-
name: (type_identifier) @identifier)
|
|
62921
|
-
|
|
62922
|
-
(type_identifier) @identifier
|
|
62923
|
-
|
|
62924
|
-
(call_expression
|
|
62925
|
-
function: [
|
|
62926
|
-
(identifier) @call.identifier
|
|
62927
|
-
(parenthesized_expression (identifier) @call.identifier)
|
|
62928
|
-
(selector_expression field: (field_identifier) @call.identifier)
|
|
62929
|
-
(parenthesized_expression (selector_expression field: (field_identifier) @call.identifier))
|
|
62930
|
-
])
|
|
62931
|
-
`;
|
|
62932
|
-
|
|
62933
|
-
// ../packages/code-map/src/tree-sitter-queries/tree-sitter-java-tags.scm
|
|
62934
|
-
var tree_sitter_java_tags_default = `(class_declaration
|
|
62935
|
-
name: (identifier) @identifier)
|
|
62936
|
-
|
|
62937
|
-
(interface_declaration
|
|
62938
|
-
name: (identifier) @identifier) @definition.interface
|
|
62939
|
-
|
|
62940
|
-
(method_declaration
|
|
62941
|
-
name: (identifier) @identifier)
|
|
62942
|
-
|
|
62943
|
-
(method_invocation
|
|
62944
|
-
name: (identifier) @call.identifier)
|
|
62945
|
-
|
|
62946
|
-
(type_list
|
|
62947
|
-
(type_identifier) @call.identifier)
|
|
62948
|
-
|
|
62949
|
-
(object_creation_expression
|
|
62950
|
-
type: (type_identifier) @call.identifier)
|
|
62951
|
-
|
|
62952
|
-
(superclass (type_identifier) @call.identifier)
|
|
62953
|
-
`;
|
|
62954
|
-
|
|
62955
|
-
// ../packages/code-map/src/tree-sitter-queries/tree-sitter-javascript-tags.scm
|
|
62956
|
-
var tree_sitter_javascript_tags_default = `(function_declaration name: (identifier) @identifier)
|
|
62957
|
-
(class_declaration name: (identifier) @identifier)
|
|
62958
|
-
(method_definition name: (property_identifier) @identifier)
|
|
62959
|
-
|
|
62960
|
-
(export_statement
|
|
62961
|
-
declaration: (lexical_declaration
|
|
62962
|
-
(variable_declarator
|
|
62963
|
-
name: (identifier) @identifier)))
|
|
62964
|
-
(export_statement
|
|
62965
|
-
declaration: (variable_declaration
|
|
62966
|
-
(variable_declarator
|
|
62967
|
-
name: (identifier) @identifier)))
|
|
62968
|
-
|
|
62969
|
-
(call_expression function: (identifier) @call.identifier)
|
|
62970
|
-
(call_expression function: (member_expression property: (property_identifier) @call.identifier))
|
|
62971
|
-
(new_expression constructor: (identifier) @call.identifier)
|
|
62972
|
-
`;
|
|
62973
|
-
|
|
62974
|
-
// ../packages/code-map/src/tree-sitter-queries/tree-sitter-python-tags.scm
|
|
62975
|
-
var tree_sitter_python_tags_default = `(class_definition
|
|
62976
|
-
name: (identifier) @identifier)
|
|
62977
|
-
|
|
62978
|
-
(function_definition
|
|
62979
|
-
name: (identifier) @identifier)
|
|
62980
|
-
|
|
62981
|
-
(call
|
|
62982
|
-
function: (identifier) @call.identifier)
|
|
62983
|
-
|
|
62984
|
-
(call
|
|
62985
|
-
function: (attribute
|
|
62986
|
-
attribute: (identifier) @call.identifier))
|
|
62987
|
-
`;
|
|
62988
|
-
|
|
62989
|
-
// ../packages/code-map/src/tree-sitter-queries/tree-sitter-ruby-tags.scm
|
|
62990
|
-
var tree_sitter_ruby_tags_default = `; Method definitions
|
|
62991
|
-
|
|
62992
|
-
(
|
|
62993
|
-
[
|
|
62994
|
-
(method
|
|
62995
|
-
name: (_) @identifier)
|
|
62996
|
-
(singleton_method
|
|
62997
|
-
name: (_) @identifier)
|
|
62998
|
-
]
|
|
62999
|
-
)
|
|
63000
|
-
|
|
63001
|
-
(alias
|
|
63002
|
-
name: (_) @identifier)
|
|
63003
|
-
|
|
63004
|
-
; (setter
|
|
63005
|
-
; (identifier) @identifier)
|
|
63006
|
-
|
|
63007
|
-
; Class definitions
|
|
63008
|
-
|
|
63009
|
-
(
|
|
63010
|
-
(comment)*
|
|
63011
|
-
.
|
|
63012
|
-
[
|
|
63013
|
-
(class
|
|
63014
|
-
name: [
|
|
63015
|
-
(constant) @identifier
|
|
63016
|
-
(scope_resolution
|
|
63017
|
-
name: (_) @identifier)
|
|
63018
|
-
])
|
|
63019
|
-
(singleton_class
|
|
63020
|
-
value: [
|
|
63021
|
-
(constant) @identifier
|
|
63022
|
-
(scope_resolution
|
|
63023
|
-
name: (_) @identifier)
|
|
63024
|
-
])
|
|
63025
|
-
]
|
|
63026
|
-
)
|
|
63027
|
-
|
|
63028
|
-
; Module definitions
|
|
63029
|
-
|
|
63030
|
-
(
|
|
63031
|
-
(module
|
|
63032
|
-
name: [
|
|
63033
|
-
(constant) @identifier
|
|
63034
|
-
(scope_resolution
|
|
63035
|
-
name: (_) @identifier)
|
|
63036
|
-
])
|
|
63037
|
-
)
|
|
63038
|
-
|
|
63039
|
-
; Calls
|
|
63040
|
-
|
|
63041
|
-
(call method: (identifier) @call.identifier)
|
|
63042
|
-
|
|
63043
|
-
(
|
|
63044
|
-
[(identifier) (constant)] @call.identifier
|
|
63045
|
-
(#is-not? local)
|
|
63046
|
-
(#not-match? @call.identifier "^(lambda|load|require|require_relative|__FILE__|__LINE__)$")
|
|
63047
|
-
)
|
|
63048
|
-
`;
|
|
63049
|
-
|
|
63050
|
-
// ../packages/code-map/src/tree-sitter-queries/tree-sitter-rust-tags.scm
|
|
63051
|
-
var tree_sitter_rust_tags_default = `(struct_item name: (type_identifier) @identifier)
|
|
63052
|
-
(enum_item name: (type_identifier) @identifier)
|
|
63053
|
-
(union_item name: (type_identifier) @identifier)
|
|
63054
|
-
(type_item name: (type_identifier) @identifier)
|
|
63055
|
-
(trait_item name: (type_identifier) @identifier)
|
|
63056
|
-
(function_item name: (identifier) @identifier)
|
|
63057
|
-
(macro_definition name: (identifier) @identifier)
|
|
63058
|
-
(mod_item name: (identifier) @identifier)
|
|
63059
|
-
(const_item name: (identifier) @identifier)
|
|
63060
|
-
(static_item name: (identifier) @identifier)
|
|
63061
|
-
|
|
63062
|
-
; Function and macro calls
|
|
63063
|
-
(call_expression function: (identifier) @call.identifier)
|
|
63064
|
-
(call_expression function: (field_expression field: (field_identifier) @call.identifier))
|
|
63065
|
-
(macro_invocation macro: (identifier) @call.identifier)
|
|
63066
|
-
|
|
63067
|
-
; Struct instantiation
|
|
63068
|
-
(struct_expression (type_identifier) @call.identifier)
|
|
63069
|
-
|
|
63070
|
-
; Enum variant usage
|
|
63071
|
-
(scoped_identifier path: (identifier) name: (identifier) @call.identifier)
|
|
63072
|
-
|
|
63073
|
-
; implementations
|
|
63074
|
-
|
|
63075
|
-
(impl_item trait: (type_identifier) @call.identifier)
|
|
63076
|
-
(impl_item type: (type_identifier) @call.identifier !trait)`;
|
|
63077
|
-
|
|
63078
|
-
// ../packages/code-map/src/tree-sitter-queries/tree-sitter-typescript-tags.scm
|
|
63079
|
-
var tree_sitter_typescript_tags_default = `(function_declaration name: (identifier) @identifier)
|
|
63080
|
-
(class_declaration name: (type_identifier) @identifier)
|
|
63081
|
-
(interface_declaration name: (type_identifier) @identifier)
|
|
63082
|
-
(method_definition name: (property_identifier) @identifier)
|
|
63083
|
-
|
|
63084
|
-
(export_statement
|
|
63085
|
-
declaration: (function_declaration
|
|
63086
|
-
name: (identifier) @identifier))
|
|
63087
|
-
|
|
63088
|
-
(export_statement
|
|
63089
|
-
declaration: (lexical_declaration
|
|
63090
|
-
(variable_declarator
|
|
63091
|
-
name: (identifier) @identifier)))
|
|
63092
|
-
|
|
63093
|
-
(export_statement
|
|
63094
|
-
declaration: (variable_declaration
|
|
63095
|
-
(variable_declarator
|
|
63096
|
-
name: (identifier) @identifier)))
|
|
63097
|
-
|
|
63098
|
-
(call_expression function: (identifier) @call.identifier)
|
|
63099
|
-
(call_expression function: (member_expression property: (property_identifier) @call.identifier))
|
|
63100
|
-
(new_expression constructor: (identifier) @call.identifier)
|
|
63101
|
-
`;
|
|
63102
|
-
|
|
63103
|
-
// ../packages/code-map/src/utils.ts
|
|
63104
|
-
function getDirnameDynamically() {
|
|
63105
|
-
return new Function(`try { return __dirname; } catch (e) { return undefined; }`)();
|
|
63106
|
-
}
|
|
63107
|
-
|
|
63108
|
-
// ../packages/code-map/src/languages.ts
|
|
63109
|
-
var WASM_FILES = {
|
|
63110
|
-
"tree-sitter-c-sharp.wasm": "tree-sitter-c-sharp.wasm",
|
|
63111
|
-
"tree-sitter-cpp.wasm": "tree-sitter-cpp.wasm",
|
|
63112
|
-
"tree-sitter-go.wasm": "tree-sitter-go.wasm",
|
|
63113
|
-
"tree-sitter-java.wasm": "tree-sitter-java.wasm",
|
|
63114
|
-
"tree-sitter-javascript.wasm": "tree-sitter-javascript.wasm",
|
|
63115
|
-
"tree-sitter-python.wasm": "tree-sitter-python.wasm",
|
|
63116
|
-
"tree-sitter-ruby.wasm": "tree-sitter-ruby.wasm",
|
|
63117
|
-
"tree-sitter-rust.wasm": "tree-sitter-rust.wasm",
|
|
63118
|
-
"tree-sitter-tsx.wasm": "tree-sitter-tsx.wasm",
|
|
63119
|
-
"tree-sitter-typescript.wasm": "tree-sitter-typescript.wasm"
|
|
63120
|
-
};
|
|
63121
|
-
var languageTable = [
|
|
63122
|
-
{
|
|
63123
|
-
extensions: [".ts"],
|
|
63124
|
-
wasmFile: WASM_FILES["tree-sitter-typescript.wasm"],
|
|
63125
|
-
queryPathOrContent: tree_sitter_typescript_tags_default
|
|
63126
|
-
},
|
|
63127
|
-
{
|
|
63128
|
-
extensions: [".tsx"],
|
|
63129
|
-
wasmFile: WASM_FILES["tree-sitter-tsx.wasm"],
|
|
63130
|
-
queryPathOrContent: tree_sitter_typescript_tags_default
|
|
63131
|
-
},
|
|
63132
|
-
{
|
|
63133
|
-
extensions: [".js", ".jsx"],
|
|
63134
|
-
wasmFile: WASM_FILES["tree-sitter-javascript.wasm"],
|
|
63135
|
-
queryPathOrContent: tree_sitter_javascript_tags_default
|
|
63136
|
-
},
|
|
63137
|
-
{
|
|
63138
|
-
extensions: [".py"],
|
|
63139
|
-
wasmFile: WASM_FILES["tree-sitter-python.wasm"],
|
|
63140
|
-
queryPathOrContent: tree_sitter_python_tags_default
|
|
63141
|
-
},
|
|
63142
|
-
{
|
|
63143
|
-
extensions: [".java"],
|
|
63144
|
-
wasmFile: WASM_FILES["tree-sitter-java.wasm"],
|
|
63145
|
-
queryPathOrContent: tree_sitter_java_tags_default
|
|
63146
|
-
},
|
|
63147
|
-
{
|
|
63148
|
-
extensions: [".cs"],
|
|
63149
|
-
wasmFile: WASM_FILES["tree-sitter-c-sharp.wasm"],
|
|
63150
|
-
queryPathOrContent: tree_sitter_c_sharp_tags_default
|
|
63151
|
-
},
|
|
63152
|
-
{
|
|
63153
|
-
extensions: [".cpp", ".hpp"],
|
|
63154
|
-
wasmFile: WASM_FILES["tree-sitter-cpp.wasm"],
|
|
63155
|
-
queryPathOrContent: tree_sitter_cpp_tags_default
|
|
63156
|
-
},
|
|
63157
|
-
{
|
|
63158
|
-
extensions: [".rs"],
|
|
63159
|
-
wasmFile: WASM_FILES["tree-sitter-rust.wasm"],
|
|
63160
|
-
queryPathOrContent: tree_sitter_rust_tags_default
|
|
63161
|
-
},
|
|
63162
|
-
{
|
|
63163
|
-
extensions: [".rb"],
|
|
63164
|
-
wasmFile: WASM_FILES["tree-sitter-ruby.wasm"],
|
|
63165
|
-
queryPathOrContent: tree_sitter_ruby_tags_default
|
|
63166
|
-
},
|
|
63167
|
-
{
|
|
63168
|
-
extensions: [".go"],
|
|
63169
|
-
wasmFile: WASM_FILES["tree-sitter-go.wasm"],
|
|
63170
|
-
queryPathOrContent: tree_sitter_go_tags_default
|
|
63171
|
-
}
|
|
63172
|
-
];
|
|
63173
|
-
var customWasmDir;
|
|
63174
|
-
function getWasmDir() {
|
|
63175
|
-
return customWasmDir;
|
|
63176
|
-
}
|
|
63177
|
-
function resolveWasmPath(wasmFileName) {
|
|
63178
|
-
const customWasmDirPath = getWasmDir();
|
|
63179
|
-
if (customWasmDirPath) {
|
|
63180
|
-
return path6.join(customWasmDirPath, wasmFileName);
|
|
63181
|
-
}
|
|
63182
|
-
const envWasmDir = process.env.CODEBUFF_WASM_DIR;
|
|
63183
|
-
if (envWasmDir) {
|
|
63184
|
-
return path6.join(envWasmDir, wasmFileName);
|
|
63185
|
-
}
|
|
63186
|
-
const moduleDir = (() => {
|
|
63187
|
-
const dirname4 = getDirnameDynamically();
|
|
63188
|
-
if (typeof dirname4 !== "undefined") {
|
|
63189
|
-
return dirname4;
|
|
63190
|
-
}
|
|
63191
|
-
return process.cwd();
|
|
63192
|
-
})();
|
|
63193
|
-
const possiblePaths = [
|
|
63194
|
-
path6.join(moduleDir, "..", "wasm", wasmFileName),
|
|
63195
|
-
path6.join(moduleDir, "wasm", wasmFileName),
|
|
63196
|
-
path6.join(process.cwd(), "dist", "wasm", wasmFileName)
|
|
63197
|
-
];
|
|
63198
|
-
for (const wasmPath of possiblePaths) {
|
|
63199
|
-
try {
|
|
63200
|
-
return wasmPath;
|
|
63201
|
-
} catch {
|
|
63202
|
-
continue;
|
|
63203
|
-
}
|
|
63204
|
-
}
|
|
63205
|
-
return possiblePaths[0];
|
|
63206
|
-
}
|
|
63207
|
-
function tryResolveFromPackage(wasmFileName) {
|
|
63208
|
-
try {
|
|
63209
|
-
return __require.resolve(`@vscode/tree-sitter-wasm/wasm/${wasmFileName}`);
|
|
63210
|
-
} catch {
|
|
63211
|
-
return null;
|
|
63212
|
-
}
|
|
63213
|
-
}
|
|
63214
|
-
|
|
63215
|
-
class UnifiedLanguageLoader {
|
|
63216
|
-
parserReady;
|
|
63217
|
-
constructor() {
|
|
63218
|
-
this.parserReady = initTreeSitterForNode();
|
|
63219
|
-
}
|
|
63220
|
-
async initParser() {
|
|
63221
|
-
await this.parserReady;
|
|
63222
|
-
}
|
|
63223
|
-
async loadLanguage(wasmFile) {
|
|
63224
|
-
let wasmPath = resolveWasmPath(wasmFile);
|
|
63225
|
-
let lang;
|
|
63226
|
-
try {
|
|
63227
|
-
lang = await Language.load(wasmPath);
|
|
63228
|
-
} catch (err) {
|
|
63229
|
-
const fallbackPath = tryResolveFromPackage(wasmFile);
|
|
63230
|
-
if (fallbackPath) {
|
|
63231
|
-
lang = await Language.load(fallbackPath);
|
|
63232
|
-
} else {
|
|
63233
|
-
throw err;
|
|
63234
|
-
}
|
|
63235
|
-
}
|
|
63236
|
-
return lang;
|
|
63237
|
-
}
|
|
63238
|
-
}
|
|
63239
|
-
function findLanguageConfigByExtension(filePath) {
|
|
63240
|
-
const ext = path6.extname(filePath);
|
|
63241
|
-
return languageTable.find((c) => c.extensions.includes(ext));
|
|
63242
|
-
}
|
|
63243
|
-
async function createLanguageConfig(filePath, runtimeLoader) {
|
|
63244
|
-
const cfg = findLanguageConfigByExtension(filePath);
|
|
63245
|
-
if (!cfg) {
|
|
63246
|
-
return;
|
|
63247
|
-
}
|
|
63248
|
-
if (!cfg.parser) {
|
|
63249
|
-
try {
|
|
63250
|
-
await runtimeLoader.initParser();
|
|
63251
|
-
const lang = await runtimeLoader.loadLanguage(cfg.wasmFile);
|
|
63252
|
-
const parser = new Parser2;
|
|
63253
|
-
parser.setLanguage(lang);
|
|
63254
|
-
const queryContent = path6.isAbsolute(cfg.queryPathOrContent) ? fs3.readFileSync(cfg.queryPathOrContent, "utf8") : cfg.queryPathOrContent;
|
|
63255
|
-
cfg.language = lang;
|
|
63256
|
-
cfg.parser = parser;
|
|
63257
|
-
cfg.query = new Query(lang, queryContent);
|
|
63258
|
-
} catch (err) {
|
|
63259
|
-
throw err;
|
|
63260
|
-
}
|
|
63261
|
-
}
|
|
63262
|
-
return cfg;
|
|
63263
|
-
}
|
|
63264
|
-
var unifiedLoader = new UnifiedLanguageLoader;
|
|
63265
|
-
async function getLanguageConfig(filePath) {
|
|
63266
|
-
try {
|
|
63267
|
-
return await createLanguageConfig(filePath, unifiedLoader);
|
|
63268
|
-
} catch (err) {
|
|
63269
|
-
if (DEBUG_PARSING) {
|
|
63270
|
-
console.error("[tree-sitter] Load error for", filePath, err);
|
|
63271
|
-
}
|
|
63272
|
-
return;
|
|
63273
|
-
}
|
|
63274
|
-
}
|
|
63275
|
-
|
|
63276
|
-
// ../packages/code-map/src/parse.ts
|
|
63277
|
-
var DEBUG_PARSING = false;
|
|
63278
|
-
var IGNORE_TOKENS = ["__init__", "__post_init__", "__call__", "constructor"];
|
|
63279
|
-
var MAX_CALLERS = 25;
|
|
63280
|
-
async function getFileTokenScores(projectRoot, filePaths, readFile) {
|
|
63281
|
-
const startTime2 = Date.now();
|
|
63282
|
-
const tokenScores = {};
|
|
63283
|
-
const externalCalls = {};
|
|
63284
|
-
const fileCallsMap = new Map;
|
|
63285
|
-
for (const filePath of filePaths) {
|
|
63286
|
-
const fullPath = path7.join(projectRoot, filePath);
|
|
63287
|
-
const languageConfig = await getLanguageConfig(fullPath);
|
|
63288
|
-
if (languageConfig) {
|
|
63289
|
-
let parseResults;
|
|
63290
|
-
if (readFile) {
|
|
63291
|
-
parseResults = parseTokens(filePath, languageConfig, readFile);
|
|
63292
|
-
} else {
|
|
63293
|
-
parseResults = parseTokens(fullPath, languageConfig);
|
|
63294
|
-
}
|
|
63295
|
-
const { identifiers, calls, numLines } = parseResults;
|
|
63296
|
-
const tokenScoresForFile = {};
|
|
63297
|
-
tokenScores[filePath] = tokenScoresForFile;
|
|
63298
|
-
const dirs = path7.dirname(fullPath).split(path7.sep);
|
|
63299
|
-
const depth = dirs.length;
|
|
63300
|
-
const tokenBaseScore = 0.8 ** depth * Math.sqrt(numLines / (identifiers.length + 1));
|
|
63301
|
-
for (const identifier of identifiers) {
|
|
63302
|
-
if (!IGNORE_TOKENS.includes(identifier)) {
|
|
63303
|
-
tokenScoresForFile[identifier] = tokenBaseScore;
|
|
63304
|
-
}
|
|
63305
|
-
}
|
|
63306
|
-
fileCallsMap.set(filePath, calls);
|
|
63307
|
-
for (const call of calls) {
|
|
63308
|
-
if (!tokenScoresForFile[call]) {
|
|
63309
|
-
externalCalls[call] = (externalCalls[call] ?? 0) + 1;
|
|
63310
|
-
}
|
|
63311
|
-
}
|
|
63312
|
-
}
|
|
63313
|
-
}
|
|
63314
|
-
const tokenDefinitionMap = new Map;
|
|
63315
|
-
const highestScores = new Map;
|
|
63316
|
-
for (const [filePath, scores] of Object.entries(tokenScores)) {
|
|
63317
|
-
for (const [token, score] of Object.entries(scores)) {
|
|
63318
|
-
const currentHighestScore = highestScores.get(token) ?? -Infinity;
|
|
63319
|
-
if (score > currentHighestScore) {
|
|
63320
|
-
highestScores.set(token, score);
|
|
63321
|
-
tokenDefinitionMap.set(token, filePath);
|
|
63322
|
-
}
|
|
63323
|
-
}
|
|
63324
|
-
}
|
|
63325
|
-
const tokenCallers = {};
|
|
63326
|
-
for (const [callingFile, calls] of fileCallsMap.entries()) {
|
|
63327
|
-
for (const call of calls) {
|
|
63328
|
-
const definingFile = tokenDefinitionMap.get(call);
|
|
63329
|
-
if (!definingFile || callingFile === definingFile) {
|
|
63330
|
-
continue;
|
|
63331
|
-
}
|
|
63332
|
-
if (call in {}) {
|
|
63333
|
-
continue;
|
|
63334
|
-
}
|
|
63335
|
-
if (!tokenCallers[definingFile]) {
|
|
63336
|
-
tokenCallers[definingFile] = {};
|
|
63337
|
-
}
|
|
63338
|
-
if (!tokenCallers[definingFile][call]) {
|
|
63339
|
-
tokenCallers[definingFile][call] = [];
|
|
63340
|
-
}
|
|
63341
|
-
const callerFiles = tokenCallers[definingFile][call];
|
|
63342
|
-
if (callerFiles.length < MAX_CALLERS && !callerFiles.includes(callingFile)) {
|
|
63343
|
-
callerFiles.push(callingFile);
|
|
63344
|
-
}
|
|
63345
|
-
}
|
|
63346
|
-
}
|
|
63347
|
-
for (const scores of Object.values(tokenScores)) {
|
|
63348
|
-
for (const token of Object.keys(scores)) {
|
|
63349
|
-
const numCalls = externalCalls[token] ?? 0;
|
|
63350
|
-
if (typeof numCalls !== "number")
|
|
63351
|
-
continue;
|
|
63352
|
-
scores[token] *= 1 + Math.log(1 + numCalls);
|
|
63353
|
-
scores[token] = Math.round(scores[token] * 1000) / 1000;
|
|
63354
|
-
}
|
|
63355
|
-
}
|
|
63356
|
-
if (DEBUG_PARSING) {
|
|
63357
|
-
const endTime = Date.now();
|
|
63358
|
-
console.log(`Parsed ${filePaths.length} files in ${endTime - startTime2}ms`);
|
|
63359
|
-
try {
|
|
63360
|
-
fs4.writeFileSync("../debug/debug-parse.json", JSON.stringify({
|
|
63361
|
-
tokenCallers,
|
|
63362
|
-
tokenScores,
|
|
63363
|
-
fileCallsMap,
|
|
63364
|
-
externalCalls
|
|
63365
|
-
}));
|
|
63366
|
-
} catch {}
|
|
63367
|
-
}
|
|
63368
|
-
return { tokenScores, tokenCallers };
|
|
63369
|
-
}
|
|
63370
|
-
function parseTokens(filePath, languageConfig, readFile) {
|
|
63371
|
-
const { parser, query } = languageConfig;
|
|
63372
|
-
try {
|
|
63373
|
-
const sourceCode = readFile ? readFile(filePath) : fs4.readFileSync(filePath, "utf8");
|
|
63374
|
-
if (sourceCode === null) {
|
|
63375
|
-
return {
|
|
63376
|
-
numLines: 0,
|
|
63377
|
-
identifiers: [],
|
|
63378
|
-
calls: []
|
|
63379
|
-
};
|
|
63380
|
-
}
|
|
63381
|
-
const numLines = sourceCode.match(/\n/g)?.length ?? 0 + 1;
|
|
63382
|
-
if (!parser || !query) {
|
|
63383
|
-
throw new Error("Parser or query not found");
|
|
63384
|
-
}
|
|
63385
|
-
const parseResults = parseFile(parser, query, sourceCode);
|
|
63386
|
-
const identifiers = Array.from(new Set(parseResults.identifier));
|
|
63387
|
-
const calls = Array.from(new Set(parseResults["call.identifier"]));
|
|
63388
|
-
if (DEBUG_PARSING) {
|
|
63389
|
-
console.log(`
|
|
63390
|
-
Parsing ${filePath}:`);
|
|
63391
|
-
console.log("Identifiers:", identifiers);
|
|
63392
|
-
console.log("Calls:", calls);
|
|
63393
|
-
}
|
|
63394
|
-
return {
|
|
63395
|
-
numLines,
|
|
63396
|
-
identifiers: identifiers ?? [],
|
|
63397
|
-
calls: calls ?? []
|
|
63398
|
-
};
|
|
63399
|
-
} catch (e) {
|
|
63400
|
-
if (DEBUG_PARSING) {
|
|
63401
|
-
console.error(`Error parsing query: ${e}`);
|
|
63402
|
-
console.log(filePath);
|
|
63403
|
-
}
|
|
63404
|
-
return {
|
|
63405
|
-
numLines: 0,
|
|
63406
|
-
identifiers: [],
|
|
63407
|
-
calls: []
|
|
63408
|
-
};
|
|
63409
|
-
}
|
|
63410
|
-
}
|
|
63411
|
-
function parseFile(parser, query, sourceCode) {
|
|
63412
|
-
const tree = parser.parse(sourceCode);
|
|
63413
|
-
if (!tree) {
|
|
63414
|
-
return {};
|
|
63415
|
-
}
|
|
63416
|
-
const captures = query.captures(tree.rootNode);
|
|
63417
|
-
const result = {};
|
|
63418
|
-
for (const capture of captures) {
|
|
63419
|
-
const { name: name14, node } = capture;
|
|
63420
|
-
if (!result[name14]) {
|
|
63421
|
-
result[name14] = [];
|
|
63422
|
-
}
|
|
63423
|
-
result[name14].push(node.text);
|
|
63424
|
-
}
|
|
63425
|
-
return result;
|
|
63426
|
-
}
|
|
63427
|
-
|
|
63428
|
-
// src/run-state.ts
|
|
63429
|
-
var import_lodash17 = __toESM(require_lodash(), 1);
|
|
63430
|
-
import z71 from "zod/v4";
|
|
63431
|
-
|
|
63432
|
-
// src/agents/load-agents.ts
|
|
63433
|
-
import fs5 from "fs";
|
|
63434
|
-
import os3 from "os";
|
|
63435
|
-
import path8 from "path";
|
|
63436
|
-
import { pathToFileURL } from "url";
|
|
63437
|
-
|
|
63438
|
-
// src/validate-agents.ts
|
|
63439
|
-
async function validateAgents2(definitions, options) {
|
|
63440
|
-
const agentTemplates = {};
|
|
63441
|
-
for (const [index, definition] of definitions.entries()) {
|
|
63442
|
-
if (!definition) {
|
|
63443
|
-
agentTemplates[`agent_${index}`] = definition;
|
|
63444
|
-
continue;
|
|
63445
|
-
}
|
|
63446
|
-
const key = definition.id ? `${definition.id}_${index}` : `agent_${index}`;
|
|
63447
|
-
agentTemplates[key] = definition;
|
|
63448
|
-
}
|
|
63449
|
-
const logger2 = {
|
|
63450
|
-
debug: () => {},
|
|
63451
|
-
info: () => {},
|
|
63452
|
-
warn: () => {},
|
|
63453
|
-
error: () => {}
|
|
63454
|
-
};
|
|
63455
|
-
let validationErrors = [];
|
|
63456
|
-
if (options?.remote) {
|
|
63457
|
-
const websiteUrl = options.websiteUrl || WEBSITE_URL;
|
|
63458
|
-
try {
|
|
63459
|
-
const response = await fetch(`${websiteUrl}/api/agents/validate`, {
|
|
63460
|
-
method: "POST",
|
|
63461
|
-
headers: {
|
|
63462
|
-
"Content-Type": "application/json"
|
|
63463
|
-
},
|
|
63464
|
-
body: JSON.stringify({ agentDefinitions: definitions })
|
|
63465
|
-
});
|
|
63466
|
-
if (!response.ok) {
|
|
63467
|
-
const errorData = await response.json().catch(() => ({}));
|
|
63468
|
-
const errorMessage = errorData.error || `HTTP ${response.status}: ${response.statusText}`;
|
|
63469
|
-
return {
|
|
63470
|
-
success: false,
|
|
63471
|
-
validationErrors: [
|
|
63472
|
-
{
|
|
63473
|
-
id: "network_error",
|
|
63474
|
-
message: `Failed to validate via API: ${errorMessage}`
|
|
63475
|
-
}
|
|
63476
|
-
],
|
|
63477
|
-
errorCount: 1
|
|
63478
|
-
};
|
|
63479
|
-
}
|
|
63480
|
-
const data = await response.json();
|
|
63481
|
-
validationErrors = data.validationErrors || [];
|
|
63482
|
-
} catch (error) {
|
|
63483
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
63484
|
-
return {
|
|
63485
|
-
success: false,
|
|
63486
|
-
validationErrors: [
|
|
63487
|
-
{
|
|
63488
|
-
id: "network_error",
|
|
63489
|
-
message: `Failed to connect to validation API: ${errorMessage}`
|
|
63490
|
-
}
|
|
63491
|
-
],
|
|
63492
|
-
errorCount: 1
|
|
63493
|
-
};
|
|
63494
|
-
}
|
|
63495
|
-
} else {
|
|
63496
|
-
const result = validateAgents({
|
|
63497
|
-
agentTemplates,
|
|
63498
|
-
logger: logger2
|
|
63499
|
-
});
|
|
63500
|
-
validationErrors = result.validationErrors;
|
|
63501
|
-
}
|
|
63502
|
-
const transformedErrors = validationErrors.map((error) => ({
|
|
63503
|
-
id: error.filePath,
|
|
63504
|
-
message: error.message
|
|
63505
|
-
}));
|
|
63506
|
-
return {
|
|
63507
|
-
success: transformedErrors.length === 0,
|
|
63508
|
-
validationErrors: transformedErrors,
|
|
63509
|
-
errorCount: transformedErrors.length
|
|
63510
|
-
};
|
|
63511
|
-
}
|
|
63512
|
-
|
|
63513
|
-
// src/agents/load-agents.ts
|
|
63514
|
-
function resolveMcpEnv(env2, agentId, mcpServerName) {
|
|
63515
|
-
if (!env2)
|
|
63516
|
-
return {};
|
|
63517
|
-
const resolved = {};
|
|
63518
|
-
for (const [key, value] of Object.entries(env2)) {
|
|
63519
|
-
if (value.startsWith("$")) {
|
|
63520
|
-
const envVarName = value.slice(1);
|
|
63521
|
-
const envName = "env";
|
|
63522
|
-
const envValue = process[envName][envVarName];
|
|
63523
|
-
if (envValue === undefined) {
|
|
63524
|
-
throw new Error(`Missing environment variable '${envVarName}' required by agent '${agentId}' in mcpServers.${mcpServerName}.env.${key}`);
|
|
63525
|
-
}
|
|
63526
|
-
resolved[key] = envValue;
|
|
63527
|
-
} else {
|
|
63528
|
-
resolved[key] = value;
|
|
63529
|
-
}
|
|
63530
|
-
}
|
|
63531
|
-
return resolved;
|
|
63532
|
-
}
|
|
63533
|
-
function resolveAgentMcpEnv(agent) {
|
|
63534
|
-
if (!agent.mcpServers)
|
|
63535
|
-
return;
|
|
63536
|
-
for (const [serverName, config] of Object.entries(agent.mcpServers)) {
|
|
63537
|
-
if ("command" in config && config.env) {
|
|
63538
|
-
config.env = resolveMcpEnv(config.env, agent.id, serverName);
|
|
63539
|
-
}
|
|
63540
|
-
}
|
|
63541
|
-
}
|
|
63542
|
-
var agentFileExtensions = new Set([".ts", ".tsx", ".js", ".mjs", ".cjs"]);
|
|
63543
|
-
var getAllAgentFiles = (dir) => {
|
|
63544
|
-
const files = [];
|
|
63545
|
-
try {
|
|
63546
|
-
const entries = fs5.readdirSync(dir, { withFileTypes: true });
|
|
63547
|
-
for (const entry of entries) {
|
|
63548
|
-
const fullPath = path8.join(dir, entry.name);
|
|
63549
|
-
if (entry.isDirectory()) {
|
|
63550
|
-
files.push(...getAllAgentFiles(fullPath));
|
|
63551
|
-
continue;
|
|
63552
|
-
}
|
|
63553
|
-
const extension = path8.extname(entry.name).toLowerCase();
|
|
63554
|
-
const isAgentFile = entry.isFile() && agentFileExtensions.has(extension) && !entry.name.endsWith(".d.ts") && !entry.name.endsWith(".test.ts");
|
|
63555
|
-
if (isAgentFile) {
|
|
63556
|
-
files.push(fullPath);
|
|
63557
|
-
}
|
|
63558
|
-
}
|
|
63559
|
-
} catch {}
|
|
63560
|
-
return files;
|
|
63561
|
-
};
|
|
63562
|
-
var getDefaultAgentDirs = () => {
|
|
63563
|
-
const cwdAgents = path8.join(process.cwd(), ".agents");
|
|
63564
|
-
const parentAgents = path8.join(process.cwd(), "..", ".agents");
|
|
63565
|
-
const homeAgents = path8.join(os3.homedir(), ".agents");
|
|
63566
|
-
return [cwdAgents, parentAgents, homeAgents];
|
|
63567
|
-
};
|
|
63568
|
-
async function loadLocalAgents({
|
|
63569
|
-
agentsPath,
|
|
63570
|
-
verbose = false,
|
|
63571
|
-
validate = false
|
|
63572
|
-
}) {
|
|
63573
|
-
const agents = {};
|
|
63574
|
-
const agentDirs = agentsPath ? [agentsPath] : getDefaultAgentDirs();
|
|
63575
|
-
const allAgentFiles = agentDirs.flatMap((dir) => getAllAgentFiles(dir));
|
|
63576
|
-
if (allAgentFiles.length === 0) {
|
|
63577
|
-
return validate ? { agents, validationErrors: [] } : agents;
|
|
63578
|
-
}
|
|
63579
|
-
for (const fullPath of allAgentFiles) {
|
|
63580
|
-
try {
|
|
63581
|
-
const agentModule = await importAgentModule(fullPath);
|
|
63582
|
-
if (!agentModule) {
|
|
63583
|
-
continue;
|
|
63584
|
-
}
|
|
63585
|
-
const agentDefinition = agentModule.default ?? agentModule;
|
|
63586
|
-
if (!agentDefinition?.id || !agentDefinition?.model) {
|
|
63587
|
-
if (verbose) {
|
|
63588
|
-
console.error(`Agent definition missing required attributes (id, model): ${fullPath}`);
|
|
63589
|
-
}
|
|
63590
|
-
continue;
|
|
63591
|
-
}
|
|
63592
|
-
const processedAgentDefinition = {
|
|
63593
|
-
...agentDefinition,
|
|
63594
|
-
_sourceFilePath: fullPath
|
|
63595
|
-
};
|
|
63596
|
-
if (agentDefinition.handleSteps) {
|
|
63597
|
-
processedAgentDefinition.handleSteps = agentDefinition.handleSteps.toString();
|
|
63598
|
-
}
|
|
63599
|
-
try {
|
|
63600
|
-
resolveAgentMcpEnv(processedAgentDefinition);
|
|
63601
|
-
} catch (error) {
|
|
63602
|
-
if (verbose) {
|
|
63603
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
63604
|
-
}
|
|
63605
|
-
continue;
|
|
63606
|
-
}
|
|
63607
|
-
agents[processedAgentDefinition.id] = processedAgentDefinition;
|
|
63608
|
-
} catch (error) {
|
|
63609
|
-
if (verbose) {
|
|
63610
|
-
console.error(`Error loading agent from file ${fullPath}:`, error instanceof Error ? error.message : error);
|
|
63611
|
-
}
|
|
63612
|
-
}
|
|
63613
|
-
}
|
|
63614
|
-
if (validate) {
|
|
63615
|
-
const validationErrors = [];
|
|
63616
|
-
if (Object.keys(agents).length > 0) {
|
|
63617
|
-
const result = await validateAgents2(Object.values(agents));
|
|
63618
|
-
if (!result.success) {
|
|
63619
|
-
const errorsByAgentId = new Map;
|
|
63620
|
-
for (const err of result.validationErrors) {
|
|
63621
|
-
const lastUnderscoreIdx = err.id.lastIndexOf("_");
|
|
63622
|
-
const agentId = lastUnderscoreIdx > 0 ? err.id.slice(0, lastUnderscoreIdx) : err.id;
|
|
63623
|
-
if (!errorsByAgentId.has(agentId)) {
|
|
63624
|
-
errorsByAgentId.set(agentId, err.message);
|
|
63625
|
-
}
|
|
63626
|
-
}
|
|
63627
|
-
for (const agentId of Object.keys(agents)) {
|
|
63628
|
-
const errorMessage = errorsByAgentId.get(agentId);
|
|
63629
|
-
if (errorMessage) {
|
|
63630
|
-
const agent = agents[agentId];
|
|
63631
|
-
validationErrors.push({
|
|
63632
|
-
agentId,
|
|
63633
|
-
filePath: agent._sourceFilePath,
|
|
63634
|
-
message: errorMessage
|
|
63635
|
-
});
|
|
63636
|
-
if (verbose) {
|
|
63637
|
-
console.error(`Validation failed for agent '${agentId}': ${errorMessage}`);
|
|
63638
|
-
}
|
|
63639
|
-
delete agents[agentId];
|
|
63640
|
-
}
|
|
63641
|
-
}
|
|
63642
|
-
}
|
|
63643
|
-
}
|
|
63644
|
-
return { agents, validationErrors };
|
|
63645
|
-
}
|
|
63646
|
-
return agents;
|
|
63647
|
-
}
|
|
63648
|
-
async function importAgentModule(fullPath) {
|
|
63649
|
-
const urlVersion = `?update=${Date.now()}`;
|
|
63650
|
-
return import(`${pathToFileURL(fullPath).href}${urlVersion}`);
|
|
63651
|
-
}
|
|
63652
|
-
|
|
63653
|
-
// src/run-state.ts
|
|
63654
|
-
function processAgentDefinitions(agentDefinitions) {
|
|
63655
|
-
const processedAgentTemplates = {};
|
|
63656
|
-
agentDefinitions.forEach((definition) => {
|
|
63657
|
-
const processedConfig = { ...definition };
|
|
63658
|
-
if (processedConfig.handleSteps && typeof processedConfig.handleSteps === "function") {
|
|
63659
|
-
processedConfig.handleSteps = processedConfig.handleSteps.toString();
|
|
63660
|
-
}
|
|
63661
|
-
if (processedConfig.id) {
|
|
63662
|
-
processedAgentTemplates[processedConfig.id] = processedConfig;
|
|
63663
|
-
}
|
|
63664
|
-
});
|
|
63665
|
-
return processedAgentTemplates;
|
|
63666
|
-
}
|
|
63667
|
-
function processCustomToolDefinitions(customToolDefinitions) {
|
|
63668
|
-
return Object.fromEntries(customToolDefinitions.map((toolDefinition) => {
|
|
63669
|
-
const jsonSchema = z71.toJSONSchema(toolDefinition.inputSchema, {
|
|
63670
|
-
io: "input"
|
|
63671
|
-
});
|
|
63672
|
-
delete jsonSchema["$schema"];
|
|
63673
|
-
return [
|
|
63674
|
-
toolDefinition.toolName,
|
|
63675
|
-
{
|
|
63676
|
-
inputSchema: jsonSchema,
|
|
63677
|
-
description: toolDefinition.description,
|
|
63678
|
-
endsAgentStep: toolDefinition.endsAgentStep,
|
|
63679
|
-
exampleInputs: toolDefinition.exampleInputs
|
|
63680
|
-
}
|
|
63681
|
-
];
|
|
63682
|
-
}));
|
|
63683
|
-
}
|
|
63684
|
-
async function computeProjectIndex(cwd, projectFiles) {
|
|
63685
|
-
const filePaths = Object.keys(projectFiles).sort();
|
|
63686
|
-
const fileTree = buildFileTree(filePaths);
|
|
63687
|
-
let fileTokenScores = {};
|
|
63688
|
-
let tokenCallers = {};
|
|
63689
|
-
if (filePaths.length > 0) {
|
|
63690
|
-
try {
|
|
63691
|
-
const tokenData = await getFileTokenScores(cwd, filePaths, (filePath) => projectFiles[filePath] || null);
|
|
63692
|
-
fileTokenScores = tokenData.tokenScores;
|
|
63693
|
-
tokenCallers = tokenData.tokenCallers;
|
|
63694
|
-
} catch (error) {
|
|
63695
|
-
console.warn("Failed to generate parsed symbol scores:", error);
|
|
63696
|
-
}
|
|
63697
|
-
}
|
|
63698
|
-
return { fileTree, fileTokenScores, tokenCallers };
|
|
63699
|
-
}
|
|
63700
|
-
function childProcessToPromise(proc) {
|
|
63701
|
-
return new Promise((resolve2, reject) => {
|
|
63702
|
-
let stdout = "";
|
|
63703
|
-
let stderr = "";
|
|
63704
|
-
proc.stdout?.on("data", (data) => {
|
|
63705
|
-
stdout += data.toString();
|
|
63706
|
-
});
|
|
63707
|
-
proc.stderr?.on("data", (data) => {
|
|
63708
|
-
stderr += data.toString();
|
|
63709
|
-
});
|
|
63710
|
-
proc.on("close", (code) => {
|
|
63711
|
-
if (code === 0) {
|
|
63712
|
-
resolve2({ stdout, stderr });
|
|
63713
|
-
} else {
|
|
63714
|
-
reject(new Error(`Command exited with code ${code}`));
|
|
63715
|
-
}
|
|
63716
|
-
});
|
|
63717
|
-
proc.on("error", reject);
|
|
63718
|
-
});
|
|
63719
|
-
}
|
|
63720
|
-
async function getGitChanges(params2) {
|
|
63721
|
-
const { cwd, spawn: spawn2, logger: logger2 } = params2;
|
|
63722
|
-
const status = childProcessToPromise(spawn2("git", ["status"], { cwd })).then(({ stdout }) => stdout).catch((error) => {
|
|
63723
|
-
logger2.debug?.({ error }, "Failed to get git status");
|
|
63724
|
-
return "";
|
|
63725
|
-
});
|
|
63726
|
-
const diff = childProcessToPromise(spawn2("git", ["diff"], { cwd })).then(({ stdout }) => stdout).catch((error) => {
|
|
63727
|
-
logger2.debug?.({ error }, "Failed to get git diff");
|
|
63728
|
-
return "";
|
|
63729
|
-
});
|
|
63730
|
-
const diffCached = childProcessToPromise(spawn2("git", ["diff", "--cached"], { cwd })).then(({ stdout }) => stdout).catch((error) => {
|
|
63731
|
-
logger2.debug?.({ error }, "Failed to get git diff --cached");
|
|
63732
|
-
return "";
|
|
63733
|
-
});
|
|
63734
|
-
const lastCommitMessages = childProcessToPromise(spawn2("git", ["shortlog", "HEAD~10..HEAD"], { cwd })).then(({ stdout }) => stdout.trim().split(`
|
|
63735
|
-
`).slice(1).reverse().map((line) => line.trim()).join(`
|
|
63736
|
-
`)).catch((error) => {
|
|
63737
|
-
logger2.debug?.({ error }, "Failed to get lastCommitMessages");
|
|
63738
|
-
return "";
|
|
63739
|
-
});
|
|
63740
|
-
return {
|
|
63741
|
-
status: await status,
|
|
63742
|
-
diff: await diff,
|
|
63743
|
-
diffCached: await diffCached,
|
|
63744
|
-
lastCommitMessages: await lastCommitMessages
|
|
63745
|
-
};
|
|
63746
|
-
}
|
|
63747
|
-
async function discoverProjectFiles(params2) {
|
|
63748
|
-
const { cwd, fs: fs6, logger: logger2 } = params2;
|
|
63749
|
-
const fileTree = await getProjectFileTree({ projectRoot: cwd, fs: fs6 });
|
|
63750
|
-
const filePaths = getAllFilePaths(fileTree);
|
|
63751
|
-
let error;
|
|
63752
|
-
const projectFilePromises = Object.fromEntries(filePaths.map((filePath) => [
|
|
63753
|
-
filePath,
|
|
63754
|
-
fs6.readFile(path9.join(cwd, filePath), "utf8").catch((err) => {
|
|
63755
|
-
error = err;
|
|
63756
|
-
return "[ERROR_READING_FILE]";
|
|
63757
|
-
})
|
|
63758
|
-
]));
|
|
63759
|
-
if (error) {
|
|
63760
|
-
logger2.warn({ error: getErrorObject(error) }, "Failed to discover some project files");
|
|
63761
|
-
}
|
|
63762
|
-
const projectFilesResolved = {};
|
|
63763
|
-
for (const [filePath, contentPromise] of Object.entries(projectFilePromises)) {
|
|
63764
|
-
projectFilesResolved[filePath] = await contentPromise;
|
|
63765
|
-
}
|
|
63766
|
-
return projectFilesResolved;
|
|
63767
|
-
}
|
|
63768
|
-
function selectKnowledgeFilePaths(allFilePaths) {
|
|
63769
|
-
const knowledgeCandidates = allFilePaths.filter((filePath) => {
|
|
63770
|
-
const lowercaseFilePath = filePath.toLowerCase();
|
|
63771
|
-
return lowercaseFilePath.endsWith("knowledge.md") || lowercaseFilePath.endsWith("agents.md") || lowercaseFilePath.endsWith("claude.md");
|
|
63772
|
-
});
|
|
63773
|
-
const byDirectory = new Map;
|
|
63774
|
-
for (const filePath of knowledgeCandidates) {
|
|
63775
|
-
const dir = path9.dirname(filePath);
|
|
63776
|
-
if (!byDirectory.has(dir)) {
|
|
63777
|
-
byDirectory.set(dir, []);
|
|
63778
|
-
}
|
|
63779
|
-
byDirectory.get(dir).push(filePath);
|
|
63780
|
-
}
|
|
63781
|
-
const selectedFiles = [];
|
|
63782
|
-
for (const files of byDirectory.values()) {
|
|
63783
|
-
const knowledgeMd = files.find((f) => f.toLowerCase().endsWith("knowledge.md"));
|
|
63784
|
-
const agentsMd = files.find((f) => f.toLowerCase().endsWith("agents.md"));
|
|
63785
|
-
const claudeMd = files.find((f) => f.toLowerCase().endsWith("claude.md"));
|
|
63786
|
-
const selectedKnowledgeFile = knowledgeMd || agentsMd || claudeMd;
|
|
63787
|
-
if (selectedKnowledgeFile) {
|
|
63788
|
-
selectedFiles.push(selectedKnowledgeFile);
|
|
63789
|
-
}
|
|
63790
|
-
}
|
|
63791
|
-
return selectedFiles;
|
|
63792
|
-
}
|
|
63793
|
-
function deriveKnowledgeFiles(projectFiles) {
|
|
63794
|
-
const allFilePaths = Object.keys(projectFiles);
|
|
63795
|
-
const selectedFilePaths = selectKnowledgeFilePaths(allFilePaths);
|
|
63796
|
-
const knowledgeFiles = {};
|
|
63797
|
-
for (const filePath of selectedFilePaths) {
|
|
63798
|
-
knowledgeFiles[filePath] = projectFiles[filePath];
|
|
63799
|
-
}
|
|
63800
|
-
return knowledgeFiles;
|
|
63801
|
-
}
|
|
63802
|
-
async function initialSessionState(params2) {
|
|
63803
|
-
const { cwd, maxAgentSteps } = params2;
|
|
63804
|
-
let {
|
|
63805
|
-
agentDefinitions,
|
|
63806
|
-
customToolDefinitions,
|
|
63807
|
-
projectFiles,
|
|
63808
|
-
knowledgeFiles,
|
|
63809
|
-
fs: fs6,
|
|
63810
|
-
spawn: spawn2,
|
|
63811
|
-
logger: logger2
|
|
63812
|
-
} = params2;
|
|
63813
|
-
if (!agentDefinitions) {
|
|
63814
|
-
agentDefinitions = [];
|
|
63815
|
-
}
|
|
63816
|
-
if (!customToolDefinitions) {
|
|
63817
|
-
customToolDefinitions = [];
|
|
63818
|
-
}
|
|
63819
|
-
if (!fs6) {
|
|
63820
|
-
fs6 = __require("fs").promises;
|
|
63821
|
-
}
|
|
63822
|
-
if (!spawn2) {
|
|
63823
|
-
const { spawn: nodeSpawn } = __require("child_process");
|
|
63824
|
-
spawn2 = nodeSpawn;
|
|
63825
|
-
}
|
|
63826
|
-
if (!logger2) {
|
|
63827
|
-
logger2 = {
|
|
63828
|
-
debug: () => {},
|
|
63829
|
-
info: () => {},
|
|
63830
|
-
warn: () => {},
|
|
63831
|
-
error: () => {}
|
|
63832
|
-
};
|
|
63833
|
-
}
|
|
63834
|
-
if (projectFiles === undefined && cwd) {
|
|
63835
|
-
projectFiles = await discoverProjectFiles({ cwd, fs: fs6, logger: logger2 });
|
|
63836
|
-
}
|
|
63837
|
-
if (knowledgeFiles === undefined) {
|
|
63838
|
-
knowledgeFiles = projectFiles ? deriveKnowledgeFiles(projectFiles) : {};
|
|
63839
|
-
}
|
|
63840
|
-
let processedAgentTemplates = {};
|
|
63841
|
-
if (agentDefinitions && agentDefinitions.length > 0) {
|
|
63842
|
-
processedAgentTemplates = processAgentDefinitions(agentDefinitions);
|
|
63843
|
-
} else {
|
|
63844
|
-
processedAgentTemplates = await loadLocalAgents({ verbose: false });
|
|
63845
|
-
}
|
|
63846
|
-
const processedCustomToolDefinitions = processCustomToolDefinitions(customToolDefinitions);
|
|
63847
|
-
let fileTree = [];
|
|
63848
|
-
let fileTokenScores = {};
|
|
63849
|
-
let tokenCallers = {};
|
|
63850
|
-
if (cwd && projectFiles) {
|
|
63851
|
-
const result = await computeProjectIndex(cwd, projectFiles);
|
|
63852
|
-
fileTree = result.fileTree;
|
|
63853
|
-
fileTokenScores = result.fileTokenScores;
|
|
63854
|
-
tokenCallers = result.tokenCallers;
|
|
63855
|
-
}
|
|
63856
|
-
const gitChanges = cwd ? await getGitChanges({ cwd, spawn: spawn2, logger: logger2 }) : {
|
|
63857
|
-
status: "",
|
|
63858
|
-
diff: "",
|
|
63859
|
-
diffCached: "",
|
|
63860
|
-
lastCommitMessages: ""
|
|
63861
|
-
};
|
|
63862
|
-
const initialState = getInitialSessionState({
|
|
63863
|
-
projectRoot: cwd ?? process.cwd(),
|
|
63864
|
-
cwd: cwd ?? process.cwd(),
|
|
63865
|
-
fileTree,
|
|
63866
|
-
fileTokenScores,
|
|
63867
|
-
tokenCallers,
|
|
63868
|
-
knowledgeFiles,
|
|
63869
|
-
userKnowledgeFiles: {},
|
|
63870
|
-
agentTemplates: processedAgentTemplates,
|
|
63871
|
-
customToolDefinitions: processedCustomToolDefinitions,
|
|
63872
|
-
gitChanges,
|
|
63873
|
-
changesSinceLastChat: {},
|
|
63874
|
-
shellConfigFiles: {},
|
|
63875
|
-
systemInfo: {
|
|
63876
|
-
platform: process.platform,
|
|
63877
|
-
shell: process.platform === "win32" ? "cmd.exe" : "bash",
|
|
63878
|
-
nodeVersion: process.version,
|
|
63879
|
-
arch: process.arch,
|
|
63880
|
-
homedir: os4.homedir(),
|
|
63881
|
-
cpus: os4.cpus().length ?? 1
|
|
63882
|
-
}
|
|
63883
|
-
});
|
|
63884
|
-
if (maxAgentSteps) {
|
|
63885
|
-
initialState.mainAgentState.stepsRemaining = maxAgentSteps;
|
|
63886
|
-
}
|
|
63887
|
-
return initialState;
|
|
63888
|
-
}
|
|
63889
|
-
async function generateInitialRunState({
|
|
63890
|
-
cwd,
|
|
63891
|
-
projectFiles,
|
|
63892
|
-
knowledgeFiles,
|
|
63893
|
-
agentDefinitions,
|
|
63894
|
-
customToolDefinitions,
|
|
63895
|
-
maxAgentSteps,
|
|
63896
|
-
fs: fs6
|
|
63897
|
-
}) {
|
|
63898
|
-
return {
|
|
63899
|
-
sessionState: await initialSessionState({
|
|
63900
|
-
cwd,
|
|
63901
|
-
projectFiles,
|
|
63902
|
-
knowledgeFiles,
|
|
63903
|
-
agentDefinitions,
|
|
63904
|
-
customToolDefinitions,
|
|
63905
|
-
maxAgentSteps,
|
|
63906
|
-
fs: fs6
|
|
63907
|
-
}),
|
|
63908
|
-
output: {
|
|
63909
|
-
type: "error",
|
|
63910
|
-
message: "No output yet"
|
|
63911
|
-
}
|
|
63912
|
-
};
|
|
63913
|
-
}
|
|
63914
|
-
function withAdditionalMessage({
|
|
63915
|
-
runState,
|
|
63916
|
-
message
|
|
63917
|
-
}) {
|
|
63918
|
-
const newRunState = import_lodash17.cloneDeep(runState);
|
|
63919
|
-
if (newRunState.sessionState) {
|
|
63920
|
-
newRunState.sessionState.mainAgentState.messageHistory.push(message);
|
|
63921
|
-
}
|
|
63922
|
-
return newRunState;
|
|
63923
|
-
}
|
|
63924
|
-
function withMessageHistory({
|
|
63925
|
-
runState,
|
|
63926
|
-
messages
|
|
63927
|
-
}) {
|
|
63928
|
-
const newRunState = JSON.parse(JSON.stringify(runState));
|
|
63929
|
-
if (newRunState.sessionState) {
|
|
63930
|
-
newRunState.sessionState.mainAgentState.messageHistory = messages;
|
|
63931
|
-
}
|
|
63932
|
-
return newRunState;
|
|
63933
|
-
}
|
|
63934
|
-
async function applyOverridesToSessionState(cwd, baseSessionState, overrides) {
|
|
63935
|
-
const sessionState = JSON.parse(JSON.stringify(baseSessionState));
|
|
63936
|
-
if (overrides.maxAgentSteps !== undefined) {
|
|
63937
|
-
sessionState.mainAgentState.stepsRemaining = overrides.maxAgentSteps;
|
|
63938
|
-
}
|
|
63939
|
-
if (overrides.projectFiles !== undefined) {
|
|
63940
|
-
if (cwd) {
|
|
63941
|
-
const { fileTree, fileTokenScores, tokenCallers } = await computeProjectIndex(cwd, overrides.projectFiles);
|
|
63942
|
-
sessionState.fileContext.fileTree = fileTree;
|
|
63943
|
-
sessionState.fileContext.fileTokenScores = fileTokenScores;
|
|
63944
|
-
sessionState.fileContext.tokenCallers = tokenCallers;
|
|
63945
|
-
} else {
|
|
63946
|
-
sessionState.fileContext.fileTree = [];
|
|
63947
|
-
sessionState.fileContext.fileTokenScores = {};
|
|
63948
|
-
sessionState.fileContext.tokenCallers = {};
|
|
63949
|
-
}
|
|
63950
|
-
if (overrides.knowledgeFiles === undefined) {
|
|
63951
|
-
sessionState.fileContext.knowledgeFiles = deriveKnowledgeFiles(overrides.projectFiles);
|
|
63952
|
-
}
|
|
63953
|
-
}
|
|
63954
|
-
if (overrides.knowledgeFiles !== undefined) {
|
|
63955
|
-
sessionState.fileContext.knowledgeFiles = overrides.knowledgeFiles;
|
|
63956
|
-
}
|
|
63957
|
-
if (overrides.agentDefinitions !== undefined) {
|
|
63958
|
-
const processedAgentTemplates = processAgentDefinitions(overrides.agentDefinitions);
|
|
63959
|
-
sessionState.fileContext.agentTemplates = {
|
|
63960
|
-
...sessionState.fileContext.agentTemplates,
|
|
63961
|
-
...processedAgentTemplates
|
|
63962
|
-
};
|
|
63963
|
-
}
|
|
63964
|
-
if (overrides.customToolDefinitions !== undefined) {
|
|
63965
|
-
const processedCustomToolDefinitions = processCustomToolDefinitions(overrides.customToolDefinitions);
|
|
63966
|
-
sessionState.fileContext.customToolDefinitions = {
|
|
63967
|
-
...sessionState.fileContext.customToolDefinitions,
|
|
63968
|
-
...processedCustomToolDefinitions
|
|
63969
|
-
};
|
|
63970
|
-
}
|
|
63971
|
-
return sessionState;
|
|
63972
|
-
}
|
|
63973
|
-
function buildFileTree(filePaths) {
|
|
63974
|
-
const tree = {};
|
|
63975
|
-
for (const filePath of filePaths) {
|
|
63976
|
-
const parts = filePath.split("/");
|
|
63977
|
-
for (let i = 0;i < parts.length; i++) {
|
|
63978
|
-
const currentPath = parts.slice(0, i + 1).join("/");
|
|
63979
|
-
const isFile = i === parts.length - 1;
|
|
63980
|
-
if (!tree[currentPath]) {
|
|
63981
|
-
tree[currentPath] = {
|
|
63982
|
-
name: parts[i],
|
|
63983
|
-
type: isFile ? "file" : "directory",
|
|
63984
|
-
filePath: currentPath,
|
|
63985
|
-
children: isFile ? undefined : []
|
|
63986
|
-
};
|
|
63987
|
-
}
|
|
63988
|
-
}
|
|
63989
|
-
}
|
|
63990
|
-
const rootNodes = [];
|
|
63991
|
-
const processed = new Set;
|
|
63992
|
-
for (const [path10, node] of Object.entries(tree)) {
|
|
63993
|
-
if (processed.has(path10))
|
|
63994
|
-
continue;
|
|
63995
|
-
const parentPath = path10.substring(0, path10.lastIndexOf("/"));
|
|
63996
|
-
if (parentPath && tree[parentPath]) {
|
|
63997
|
-
const parent = tree[parentPath];
|
|
63998
|
-
if (parent.children && !parent.children.some((child) => child.filePath === path10)) {
|
|
63999
|
-
parent.children.push(node);
|
|
64000
|
-
}
|
|
64001
|
-
} else {
|
|
64002
|
-
rootNodes.push(node);
|
|
64003
|
-
}
|
|
64004
|
-
processed.add(path10);
|
|
64005
|
-
}
|
|
64006
|
-
function sortNodes(nodes) {
|
|
64007
|
-
nodes.sort((a, b) => {
|
|
64008
|
-
if (a.type !== b.type) {
|
|
64009
|
-
return a.type === "directory" ? -1 : 1;
|
|
64010
|
-
}
|
|
64011
|
-
return a.name.localeCompare(b.name);
|
|
64012
|
-
});
|
|
64013
|
-
for (const node of nodes) {
|
|
64014
|
-
if (node.children) {
|
|
64015
|
-
sortNodes(node.children);
|
|
64016
|
-
}
|
|
64017
|
-
}
|
|
64018
|
-
}
|
|
64019
|
-
sortNodes(rootNodes);
|
|
64020
|
-
return rootNodes;
|
|
64021
|
-
}
|
|
64022
|
-
|
|
64023
62854
|
// src/custom-tool.ts
|
|
64024
62855
|
function getCustomToolDefinition({
|
|
64025
62856
|
toolName: toolName31,
|
|
@@ -64117,19 +62948,19 @@ async function runOnce({
|
|
|
64117
62948
|
extraToolResults,
|
|
64118
62949
|
signal
|
|
64119
62950
|
}) {
|
|
64120
|
-
const
|
|
62951
|
+
const fs2 = createConvexStubFs();
|
|
64121
62952
|
const spawn2 = createConvexStubSpawn();
|
|
64122
62953
|
const preparedContent = wrapContentForUserMessage(content);
|
|
64123
62954
|
let agentId;
|
|
64124
62955
|
if (typeof agent !== "string") {
|
|
64125
|
-
agentDefinitions = [...
|
|
62956
|
+
agentDefinitions = [...import_lodash17.cloneDeep(agentDefinitions) ?? [], agent];
|
|
64126
62957
|
agentId = agent.id;
|
|
64127
62958
|
} else {
|
|
64128
62959
|
agentId = agent;
|
|
64129
62960
|
}
|
|
64130
62961
|
let sessionState;
|
|
64131
62962
|
if (previousRun?.sessionState) {
|
|
64132
|
-
sessionState = await
|
|
62963
|
+
sessionState = await convexApplyOverridesToSessionState(undefined, previousRun.sessionState, {
|
|
64133
62964
|
knowledgeFiles,
|
|
64134
62965
|
agentDefinitions,
|
|
64135
62966
|
customToolDefinitions,
|
|
@@ -64137,21 +62968,21 @@ async function runOnce({
|
|
|
64137
62968
|
maxAgentSteps
|
|
64138
62969
|
});
|
|
64139
62970
|
} else {
|
|
64140
|
-
sessionState = await
|
|
62971
|
+
sessionState = await convexInitialSessionState({
|
|
64141
62972
|
cwd: undefined,
|
|
64142
62973
|
knowledgeFiles,
|
|
64143
62974
|
agentDefinitions,
|
|
64144
62975
|
customToolDefinitions,
|
|
64145
62976
|
projectFiles,
|
|
64146
62977
|
maxAgentSteps,
|
|
64147
|
-
fs:
|
|
62978
|
+
fs: fs2,
|
|
64148
62979
|
spawn: spawn2,
|
|
64149
62980
|
logger: logger2
|
|
64150
62981
|
});
|
|
64151
62982
|
}
|
|
64152
|
-
let
|
|
62983
|
+
let resolve = () => {};
|
|
64153
62984
|
const promise = new Promise((res) => {
|
|
64154
|
-
|
|
62985
|
+
resolve = res;
|
|
64155
62986
|
});
|
|
64156
62987
|
async function onError(error) {
|
|
64157
62988
|
if (handleEvent) {
|
|
@@ -64160,7 +62991,7 @@ async function runOnce({
|
|
|
64160
62991
|
}
|
|
64161
62992
|
let pendingAgentResponse = "";
|
|
64162
62993
|
function getCancelledSessionState(message) {
|
|
64163
|
-
const state =
|
|
62994
|
+
const state = import_lodash17.cloneDeep(sessionState);
|
|
64164
62995
|
state.mainAgentState.messageHistory.push(...getCancelledAdditionalMessages({
|
|
64165
62996
|
prompt: prompt2,
|
|
64166
62997
|
params: params2,
|
|
@@ -64287,7 +63118,7 @@ async function runOnce({
|
|
|
64287
63118
|
if (action.type === "prompt-response") {
|
|
64288
63119
|
handlePromptResponse({
|
|
64289
63120
|
action,
|
|
64290
|
-
resolve
|
|
63121
|
+
resolve,
|
|
64291
63122
|
onError,
|
|
64292
63123
|
initialSessionState: sessionState
|
|
64293
63124
|
});
|
|
@@ -64296,7 +63127,7 @@ async function runOnce({
|
|
|
64296
63127
|
if (action.type === "prompt-error") {
|
|
64297
63128
|
handlePromptResponse({
|
|
64298
63129
|
action,
|
|
64299
|
-
resolve
|
|
63130
|
+
resolve,
|
|
64300
63131
|
onError,
|
|
64301
63132
|
initialSessionState: sessionState
|
|
64302
63133
|
});
|
|
@@ -64333,7 +63164,7 @@ async function runOnce({
|
|
|
64333
63164
|
}
|
|
64334
63165
|
const userId2 = userInfo.id;
|
|
64335
63166
|
signal?.addEventListener("abort", () => {
|
|
64336
|
-
|
|
63167
|
+
resolve(getCancelledRunState());
|
|
64337
63168
|
});
|
|
64338
63169
|
if (signal?.aborted) {
|
|
64339
63170
|
return getCancelledRunState();
|
|
@@ -64361,7 +63192,7 @@ async function runOnce({
|
|
|
64361
63192
|
}).catch((error) => {
|
|
64362
63193
|
const errorMessage = error instanceof Error ? error.message : String(error ?? "");
|
|
64363
63194
|
const statusCode = getErrorStatusCode(error);
|
|
64364
|
-
|
|
63195
|
+
resolve({
|
|
64365
63196
|
sessionState: getCancelledSessionState(errorMessage),
|
|
64366
63197
|
output: {
|
|
64367
63198
|
type: "error",
|
|
@@ -64475,14 +63306,14 @@ async function handleToolCall({
|
|
|
64475
63306
|
}
|
|
64476
63307
|
async function handlePromptResponse({
|
|
64477
63308
|
action,
|
|
64478
|
-
resolve
|
|
63309
|
+
resolve,
|
|
64479
63310
|
onError,
|
|
64480
|
-
initialSessionState
|
|
63311
|
+
initialSessionState
|
|
64481
63312
|
}) {
|
|
64482
63313
|
if (action.type === "prompt-error") {
|
|
64483
63314
|
onError({ message: action.message });
|
|
64484
|
-
|
|
64485
|
-
sessionState:
|
|
63315
|
+
resolve({
|
|
63316
|
+
sessionState: initialSessionState,
|
|
64486
63317
|
output: {
|
|
64487
63318
|
type: "error",
|
|
64488
63319
|
message: action.message
|
|
@@ -64498,8 +63329,8 @@ async function handlePromptResponse({
|
|
|
64498
63329
|
].join(`
|
|
64499
63330
|
`);
|
|
64500
63331
|
onError({ message });
|
|
64501
|
-
|
|
64502
|
-
sessionState:
|
|
63332
|
+
resolve({
|
|
63333
|
+
sessionState: initialSessionState,
|
|
64503
63334
|
output: {
|
|
64504
63335
|
type: "error",
|
|
64505
63336
|
message
|
|
@@ -64515,13 +63346,13 @@ async function handlePromptResponse({
|
|
|
64515
63346
|
message: "No output from agent"
|
|
64516
63347
|
}
|
|
64517
63348
|
};
|
|
64518
|
-
|
|
63349
|
+
resolve(state);
|
|
64519
63350
|
} else {
|
|
64520
63351
|
onError({
|
|
64521
63352
|
message: "Internal error: prompt response type not handled"
|
|
64522
63353
|
});
|
|
64523
|
-
|
|
64524
|
-
sessionState:
|
|
63354
|
+
resolve({
|
|
63355
|
+
sessionState: initialSessionState,
|
|
64525
63356
|
output: {
|
|
64526
63357
|
type: "error",
|
|
64527
63358
|
message: "Internal error: prompt response type not handled"
|
|
@@ -64567,24 +63398,20 @@ Provide a handleEvent function to handle this error.`);
|
|
|
64567
63398
|
}
|
|
64568
63399
|
}
|
|
64569
63400
|
export {
|
|
64570
|
-
withMessageHistory,
|
|
64571
|
-
withAdditionalMessage,
|
|
64572
|
-
selectKnowledgeFilePaths,
|
|
64573
63401
|
sanitizeErrorMessage,
|
|
64574
63402
|
run,
|
|
64575
63403
|
isRetryableStatusCode,
|
|
64576
|
-
initialSessionState,
|
|
64577
63404
|
getErrorStatusCode,
|
|
64578
63405
|
getCustomToolDefinition,
|
|
64579
|
-
generateInitialRunState,
|
|
64580
63406
|
createServerError,
|
|
64581
63407
|
createPaymentRequiredError,
|
|
64582
63408
|
createNetworkError,
|
|
64583
63409
|
createHttpError,
|
|
64584
63410
|
createForbiddenError,
|
|
64585
63411
|
createAuthError,
|
|
63412
|
+
convexInitialSessionState,
|
|
63413
|
+
convexApplyOverridesToSessionState,
|
|
64586
63414
|
buildUserMessageContent,
|
|
64587
|
-
applyOverridesToSessionState,
|
|
64588
63415
|
WEBSITE_URL,
|
|
64589
63416
|
RETRY_BACKOFF_MAX_DELAY_MS,
|
|
64590
63417
|
RETRY_BACKOFF_BASE_DELAY_MS,
|
|
@@ -64600,5 +63427,5 @@ export {
|
|
|
64600
63427
|
CODEBUFF_BINARY
|
|
64601
63428
|
};
|
|
64602
63429
|
|
|
64603
|
-
//# debugId=
|
|
63430
|
+
//# debugId=7642DE831BB7B87F64756E2164756E21
|
|
64604
63431
|
//# sourceMappingURL=convex.mjs.map
|