@levelcode/sdk 0.2.0 → 0.2.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/dist/common/src/constants/agents.d.ts +2 -2
- package/dist/common/src/types/team-config-schemas.d.ts +4 -0
- package/dist/index.cjs +306 -296
- package/dist/index.cjs.map +19 -19
- package/dist/index.mjs +339 -329
- package/dist/index.mjs.map +19 -19
- package/dist/packages/agent-runtime/src/tools/handlers/list.d.ts +4 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/task-create.d.ts +1 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/task-get.d.ts +1 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/task-list.d.ts +1 -0
- package/dist/packages/agent-runtime/src/tools/handlers/tool/task-update.d.ts +1 -0
- package/dist/sdk/src/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7189,7 +7189,7 @@ var require_uri_all = __commonJS((exports3, module2) => {
|
|
|
7189
7189
|
target.fragment = relative2.fragment;
|
|
7190
7190
|
return target;
|
|
7191
7191
|
}
|
|
7192
|
-
function
|
|
7192
|
+
function resolve3(baseURI, relativeURI, options) {
|
|
7193
7193
|
var schemelessOptions = assign({ scheme: "null" }, options);
|
|
7194
7194
|
return serialize(resolveComponents(parse2(baseURI, schemelessOptions), parse2(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
|
|
7195
7195
|
}
|
|
@@ -7457,7 +7457,7 @@ var require_uri_all = __commonJS((exports3, module2) => {
|
|
|
7457
7457
|
exports4.removeDotSegments = removeDotSegments;
|
|
7458
7458
|
exports4.serialize = serialize;
|
|
7459
7459
|
exports4.resolveComponents = resolveComponents;
|
|
7460
|
-
exports4.resolve =
|
|
7460
|
+
exports4.resolve = resolve3;
|
|
7461
7461
|
exports4.normalize = normalize2;
|
|
7462
7462
|
exports4.equal = equal;
|
|
7463
7463
|
exports4.escapeComponent = escapeComponent;
|
|
@@ -7823,20 +7823,20 @@ var require_resolve = __commonJS((exports3, module2) => {
|
|
|
7823
7823
|
var util = require_util();
|
|
7824
7824
|
var SchemaObject = require_schema_obj();
|
|
7825
7825
|
var traverse = require_json_schema_traverse();
|
|
7826
|
-
module2.exports =
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
function
|
|
7826
|
+
module2.exports = resolve3;
|
|
7827
|
+
resolve3.normalizeId = normalizeId;
|
|
7828
|
+
resolve3.fullPath = getFullPath;
|
|
7829
|
+
resolve3.url = resolveUrl;
|
|
7830
|
+
resolve3.ids = resolveIds;
|
|
7831
|
+
resolve3.inlineRef = inlineRef;
|
|
7832
|
+
resolve3.schema = resolveSchema;
|
|
7833
|
+
function resolve3(compile, root, ref) {
|
|
7834
7834
|
var refVal = this._refs[ref];
|
|
7835
7835
|
if (typeof refVal == "string") {
|
|
7836
7836
|
if (this._refs[refVal])
|
|
7837
7837
|
refVal = this._refs[refVal];
|
|
7838
7838
|
else
|
|
7839
|
-
return
|
|
7839
|
+
return resolve3.call(this, compile, root, refVal);
|
|
7840
7840
|
}
|
|
7841
7841
|
refVal = refVal || this._schemas[ref];
|
|
7842
7842
|
if (refVal instanceof SchemaObject) {
|
|
@@ -8059,7 +8059,7 @@ var require_resolve = __commonJS((exports3, module2) => {
|
|
|
8059
8059
|
|
|
8060
8060
|
// ../node_modules/ajv/lib/compile/error_classes.js
|
|
8061
8061
|
var require_error_classes = __commonJS((exports3, module2) => {
|
|
8062
|
-
var
|
|
8062
|
+
var resolve3 = require_resolve();
|
|
8063
8063
|
module2.exports = {
|
|
8064
8064
|
Validation: errorSubclass(ValidationError),
|
|
8065
8065
|
MissingRef: errorSubclass(MissingRefError)
|
|
@@ -8074,8 +8074,8 @@ var require_error_classes = __commonJS((exports3, module2) => {
|
|
|
8074
8074
|
};
|
|
8075
8075
|
function MissingRefError(baseId, ref, message) {
|
|
8076
8076
|
this.message = message || MissingRefError.message(baseId, ref);
|
|
8077
|
-
this.missingRef =
|
|
8078
|
-
this.missingSchema =
|
|
8077
|
+
this.missingRef = resolve3.url(baseId, ref);
|
|
8078
|
+
this.missingSchema = resolve3.normalizeId(resolve3.fullPath(this.missingRef));
|
|
8079
8079
|
}
|
|
8080
8080
|
function errorSubclass(Subclass) {
|
|
8081
8081
|
Subclass.prototype = Object.create(Error.prototype);
|
|
@@ -8617,7 +8617,7 @@ var require_validate = __commonJS((exports3, module2) => {
|
|
|
8617
8617
|
|
|
8618
8618
|
// ../node_modules/ajv/lib/compile/index.js
|
|
8619
8619
|
var require_compile = __commonJS((exports3, module2) => {
|
|
8620
|
-
var
|
|
8620
|
+
var resolve3 = require_resolve();
|
|
8621
8621
|
var util = require_util();
|
|
8622
8622
|
var errorClasses = require_error_classes();
|
|
8623
8623
|
var stableStringify = require_fast_json_stable_stringify();
|
|
@@ -8677,7 +8677,7 @@ var require_compile = __commonJS((exports3, module2) => {
|
|
|
8677
8677
|
RULES,
|
|
8678
8678
|
validate: validateGenerator,
|
|
8679
8679
|
util,
|
|
8680
|
-
resolve:
|
|
8680
|
+
resolve: resolve3,
|
|
8681
8681
|
resolveRef,
|
|
8682
8682
|
usePattern,
|
|
8683
8683
|
useDefault,
|
|
@@ -8716,7 +8716,7 @@ var require_compile = __commonJS((exports3, module2) => {
|
|
|
8716
8716
|
return validate;
|
|
8717
8717
|
}
|
|
8718
8718
|
function resolveRef(baseId2, ref, isRoot) {
|
|
8719
|
-
ref =
|
|
8719
|
+
ref = resolve3.url(baseId2, ref);
|
|
8720
8720
|
var refIndex = refs[ref];
|
|
8721
8721
|
var _refVal, refCode;
|
|
8722
8722
|
if (refIndex !== undefined) {
|
|
@@ -8733,11 +8733,11 @@ var require_compile = __commonJS((exports3, module2) => {
|
|
|
8733
8733
|
}
|
|
8734
8734
|
}
|
|
8735
8735
|
refCode = addLocalRef(ref);
|
|
8736
|
-
var v2 =
|
|
8736
|
+
var v2 = resolve3.call(self2, localCompile, root, ref);
|
|
8737
8737
|
if (v2 === undefined) {
|
|
8738
8738
|
var localSchema = localRefs && localRefs[ref];
|
|
8739
8739
|
if (localSchema) {
|
|
8740
|
-
v2 =
|
|
8740
|
+
v2 = resolve3.inlineRef(localSchema, opts.inlineRefs) ? localSchema : compile.call(self2, localSchema, root, localRefs, baseId2);
|
|
8741
8741
|
}
|
|
8742
8742
|
}
|
|
8743
8743
|
if (v2 === undefined) {
|
|
@@ -12254,7 +12254,7 @@ var require_data2 = __commonJS((exports3, module2) => {
|
|
|
12254
12254
|
// ../node_modules/ajv/lib/ajv.js
|
|
12255
12255
|
var require_ajv = __commonJS((exports3, module2) => {
|
|
12256
12256
|
var compileSchema = require_compile();
|
|
12257
|
-
var
|
|
12257
|
+
var resolve3 = require_resolve();
|
|
12258
12258
|
var Cache = require_cache();
|
|
12259
12259
|
var SchemaObject = require_schema_obj();
|
|
12260
12260
|
var stableStringify = require_fast_json_stable_stringify();
|
|
@@ -12346,7 +12346,7 @@ var require_ajv = __commonJS((exports3, module2) => {
|
|
|
12346
12346
|
var id = this._getId(schema);
|
|
12347
12347
|
if (id !== undefined && typeof id != "string")
|
|
12348
12348
|
throw new Error("schema id must be string");
|
|
12349
|
-
key =
|
|
12349
|
+
key = resolve3.normalizeId(key || id);
|
|
12350
12350
|
checkUnique(this, key);
|
|
12351
12351
|
this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
|
|
12352
12352
|
return this;
|
|
@@ -12392,7 +12392,7 @@ var require_ajv = __commonJS((exports3, module2) => {
|
|
|
12392
12392
|
}
|
|
12393
12393
|
}
|
|
12394
12394
|
function _getSchemaFragment(self2, ref) {
|
|
12395
|
-
var res =
|
|
12395
|
+
var res = resolve3.schema.call(self2, { schema: {} }, ref);
|
|
12396
12396
|
if (res) {
|
|
12397
12397
|
var { schema, root, baseId } = res;
|
|
12398
12398
|
var v = compileSchema.call(self2, schema, root, undefined, baseId);
|
|
@@ -12408,7 +12408,7 @@ var require_ajv = __commonJS((exports3, module2) => {
|
|
|
12408
12408
|
}
|
|
12409
12409
|
}
|
|
12410
12410
|
function _getSchemaObj(self2, keyRef) {
|
|
12411
|
-
keyRef =
|
|
12411
|
+
keyRef = resolve3.normalizeId(keyRef);
|
|
12412
12412
|
return self2._schemas[keyRef] || self2._refs[keyRef] || self2._fragments[keyRef];
|
|
12413
12413
|
}
|
|
12414
12414
|
function removeSchema(schemaKeyRef) {
|
|
@@ -12436,7 +12436,7 @@ var require_ajv = __commonJS((exports3, module2) => {
|
|
|
12436
12436
|
this._cache.del(cacheKey);
|
|
12437
12437
|
var id = this._getId(schemaKeyRef);
|
|
12438
12438
|
if (id) {
|
|
12439
|
-
id =
|
|
12439
|
+
id = resolve3.normalizeId(id);
|
|
12440
12440
|
delete this._schemas[id];
|
|
12441
12441
|
delete this._refs[id];
|
|
12442
12442
|
}
|
|
@@ -12461,14 +12461,14 @@ var require_ajv = __commonJS((exports3, module2) => {
|
|
|
12461
12461
|
if (cached)
|
|
12462
12462
|
return cached;
|
|
12463
12463
|
shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
|
|
12464
|
-
var id =
|
|
12464
|
+
var id = resolve3.normalizeId(this._getId(schema));
|
|
12465
12465
|
if (id && shouldAddSchema)
|
|
12466
12466
|
checkUnique(this, id);
|
|
12467
12467
|
var willValidate = this._opts.validateSchema !== false && !skipValidation;
|
|
12468
12468
|
var recursiveMeta;
|
|
12469
|
-
if (willValidate && !(recursiveMeta = id && id ==
|
|
12469
|
+
if (willValidate && !(recursiveMeta = id && id == resolve3.normalizeId(schema.$schema)))
|
|
12470
12470
|
this.validateSchema(schema, true);
|
|
12471
|
-
var localRefs =
|
|
12471
|
+
var localRefs = resolve3.ids.call(this, schema);
|
|
12472
12472
|
var schemaObj = new SchemaObject({
|
|
12473
12473
|
id,
|
|
12474
12474
|
schema,
|
|
@@ -12633,7 +12633,7 @@ var require_ajv = __commonJS((exports3, module2) => {
|
|
|
12633
12633
|
var require_windows = __commonJS((exports3, module2) => {
|
|
12634
12634
|
module2.exports = isexe;
|
|
12635
12635
|
isexe.sync = sync;
|
|
12636
|
-
var
|
|
12636
|
+
var fs7 = require("fs");
|
|
12637
12637
|
function checkPathExt(path7, options) {
|
|
12638
12638
|
var pathext = options.pathExt !== undefined ? options.pathExt : process.env.PATHEXT;
|
|
12639
12639
|
if (!pathext) {
|
|
@@ -12658,12 +12658,12 @@ var require_windows = __commonJS((exports3, module2) => {
|
|
|
12658
12658
|
return checkPathExt(path7, options);
|
|
12659
12659
|
}
|
|
12660
12660
|
function isexe(path7, options, cb) {
|
|
12661
|
-
|
|
12661
|
+
fs7.stat(path7, function(er, stat) {
|
|
12662
12662
|
cb(er, er ? false : checkStat(stat, path7, options));
|
|
12663
12663
|
});
|
|
12664
12664
|
}
|
|
12665
12665
|
function sync(path7, options) {
|
|
12666
|
-
return checkStat(
|
|
12666
|
+
return checkStat(fs7.statSync(path7), path7, options);
|
|
12667
12667
|
}
|
|
12668
12668
|
});
|
|
12669
12669
|
|
|
@@ -12671,14 +12671,14 @@ var require_windows = __commonJS((exports3, module2) => {
|
|
|
12671
12671
|
var require_mode = __commonJS((exports3, module2) => {
|
|
12672
12672
|
module2.exports = isexe;
|
|
12673
12673
|
isexe.sync = sync;
|
|
12674
|
-
var
|
|
12674
|
+
var fs7 = require("fs");
|
|
12675
12675
|
function isexe(path7, options, cb) {
|
|
12676
|
-
|
|
12676
|
+
fs7.stat(path7, function(er, stat) {
|
|
12677
12677
|
cb(er, er ? false : checkStat(stat, options));
|
|
12678
12678
|
});
|
|
12679
12679
|
}
|
|
12680
12680
|
function sync(path7, options) {
|
|
12681
|
-
return checkStat(
|
|
12681
|
+
return checkStat(fs7.statSync(path7), options);
|
|
12682
12682
|
}
|
|
12683
12683
|
function checkStat(stat, options) {
|
|
12684
12684
|
return stat.isFile() && checkMode(stat, options);
|
|
@@ -12700,7 +12700,7 @@ var require_mode = __commonJS((exports3, module2) => {
|
|
|
12700
12700
|
|
|
12701
12701
|
// ../node_modules/isexe/index.js
|
|
12702
12702
|
var require_isexe = __commonJS((exports3, module2) => {
|
|
12703
|
-
var
|
|
12703
|
+
var fs7 = require("fs");
|
|
12704
12704
|
var core;
|
|
12705
12705
|
if (process.platform === "win32" || global.TESTING_WINDOWS) {
|
|
12706
12706
|
core = require_windows();
|
|
@@ -12718,12 +12718,12 @@ var require_isexe = __commonJS((exports3, module2) => {
|
|
|
12718
12718
|
if (typeof Promise !== "function") {
|
|
12719
12719
|
throw new TypeError("callback not provided");
|
|
12720
12720
|
}
|
|
12721
|
-
return new Promise(function(
|
|
12721
|
+
return new Promise(function(resolve3, reject) {
|
|
12722
12722
|
isexe(path7, options || {}, function(er, is) {
|
|
12723
12723
|
if (er) {
|
|
12724
12724
|
reject(er);
|
|
12725
12725
|
} else {
|
|
12726
|
-
|
|
12726
|
+
resolve3(is);
|
|
12727
12727
|
}
|
|
12728
12728
|
});
|
|
12729
12729
|
});
|
|
@@ -12785,27 +12785,27 @@ var require_which = __commonJS((exports3, module2) => {
|
|
|
12785
12785
|
opt = {};
|
|
12786
12786
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
12787
12787
|
const found = [];
|
|
12788
|
-
const step = (i) => new Promise((
|
|
12788
|
+
const step = (i) => new Promise((resolve3, reject) => {
|
|
12789
12789
|
if (i === pathEnv.length)
|
|
12790
|
-
return opt.all && found.length ?
|
|
12790
|
+
return opt.all && found.length ? resolve3(found) : reject(getNotFoundError(cmd));
|
|
12791
12791
|
const ppRaw = pathEnv[i];
|
|
12792
12792
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
12793
12793
|
const pCmd = path7.join(pathPart, cmd);
|
|
12794
12794
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
12795
|
-
|
|
12795
|
+
resolve3(subStep(p, i, 0));
|
|
12796
12796
|
});
|
|
12797
|
-
const subStep = (p, i, ii) => new Promise((
|
|
12797
|
+
const subStep = (p, i, ii) => new Promise((resolve3, reject) => {
|
|
12798
12798
|
if (ii === pathExt.length)
|
|
12799
|
-
return
|
|
12799
|
+
return resolve3(step(i + 1));
|
|
12800
12800
|
const ext = pathExt[ii];
|
|
12801
12801
|
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
12802
12802
|
if (!er && is) {
|
|
12803
12803
|
if (opt.all)
|
|
12804
12804
|
found.push(p + ext);
|
|
12805
12805
|
else
|
|
12806
|
-
return
|
|
12806
|
+
return resolve3(p + ext);
|
|
12807
12807
|
}
|
|
12808
|
-
return
|
|
12808
|
+
return resolve3(subStep(p, i, ii + 1));
|
|
12809
12809
|
});
|
|
12810
12810
|
});
|
|
12811
12811
|
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
@@ -12939,16 +12939,16 @@ var require_shebang_command = __commonJS((exports3, module2) => {
|
|
|
12939
12939
|
|
|
12940
12940
|
// ../node_modules/cross-spawn/lib/util/readShebang.js
|
|
12941
12941
|
var require_readShebang = __commonJS((exports3, module2) => {
|
|
12942
|
-
var
|
|
12942
|
+
var fs7 = require("fs");
|
|
12943
12943
|
var shebangCommand = require_shebang_command();
|
|
12944
12944
|
function readShebang(command) {
|
|
12945
12945
|
const size = 150;
|
|
12946
12946
|
const buffer = Buffer.alloc(size);
|
|
12947
12947
|
let fd;
|
|
12948
12948
|
try {
|
|
12949
|
-
fd =
|
|
12950
|
-
|
|
12951
|
-
|
|
12949
|
+
fd = fs7.openSync(command, "r");
|
|
12950
|
+
fs7.readSync(fd, buffer, 0, size, 0);
|
|
12951
|
+
fs7.closeSync(fd);
|
|
12952
12952
|
} catch (e) {}
|
|
12953
12953
|
return shebangCommand(buffer.toString());
|
|
12954
12954
|
}
|
|
@@ -13095,6 +13095,10 @@ __export(exports_src, {
|
|
|
13095
13095
|
setWasmDir: () => setWasmDir,
|
|
13096
13096
|
selectKnowledgeFilePaths: () => selectKnowledgeFilePaths,
|
|
13097
13097
|
selectHighestPriorityKnowledgeFile: () => selectHighestPriorityKnowledgeFile,
|
|
13098
|
+
sdkListTeams: () => sdkListTeams,
|
|
13099
|
+
sdkGetTeamStatus: () => sdkGetTeamStatus,
|
|
13100
|
+
sdkDeleteTeam: () => sdkDeleteTeam,
|
|
13101
|
+
sdkCreateTeam: () => sdkCreateTeam,
|
|
13098
13102
|
saveClaudeOAuthCredentials: () => saveClaudeOAuthCredentials,
|
|
13099
13103
|
sanitizeErrorMessage: () => sanitizeErrorMessage,
|
|
13100
13104
|
runTerminalCommand: () => runTerminalCommand,
|
|
@@ -16995,7 +16999,7 @@ var import_v42 = require("zod/v4");
|
|
|
16995
16999
|
// ../common/src/constants/agents.ts
|
|
16996
17000
|
var AGENT_PERSONAS = {
|
|
16997
17001
|
base: {
|
|
16998
|
-
displayName: "
|
|
17002
|
+
displayName: "Sage the Base Agent",
|
|
16999
17003
|
purpose: "Base agent that orchestrates the full response."
|
|
17000
17004
|
},
|
|
17001
17005
|
ask: {
|
|
@@ -17219,17 +17223,17 @@ var devPhaseSchema = import_zod.z.enum([
|
|
|
17219
17223
|
]);
|
|
17220
17224
|
var teamMemberSchema = import_zod.z.object({
|
|
17221
17225
|
agentId: import_zod.z.string(),
|
|
17222
|
-
name: import_zod.z.string(),
|
|
17226
|
+
name: import_zod.z.string().min(1).max(100).regex(/^[a-zA-Z0-9_-]+$/, "Agent name may only contain letters, numbers, hyphens, and underscores"),
|
|
17223
17227
|
role: teamRoleSchema,
|
|
17224
17228
|
agentType: import_zod.z.string(),
|
|
17225
17229
|
model: import_zod.z.string(),
|
|
17226
17230
|
joinedAt: import_zod.z.number(),
|
|
17227
|
-
status: import_zod.z.enum(["active", "idle", "completed", "failed"]),
|
|
17231
|
+
status: import_zod.z.enum(["active", "idle", "working", "blocked", "completed", "failed"]),
|
|
17228
17232
|
currentTaskId: import_zod.z.string().optional(),
|
|
17229
17233
|
cwd: import_zod.z.string()
|
|
17230
17234
|
});
|
|
17231
17235
|
var teamConfigSchema = import_zod.z.object({
|
|
17232
|
-
name: import_zod.z.string(),
|
|
17236
|
+
name: import_zod.z.string().min(1).max(50).regex(/^[a-zA-Z0-9_-]+$/, "Team name may only contain letters, numbers, hyphens, and underscores"),
|
|
17233
17237
|
description: import_zod.z.string(),
|
|
17234
17238
|
createdAt: import_zod.z.number(),
|
|
17235
17239
|
leadAgentId: import_zod.z.string(),
|
|
@@ -17241,7 +17245,7 @@ var teamConfigSchema = import_zod.z.object({
|
|
|
17241
17245
|
})
|
|
17242
17246
|
});
|
|
17243
17247
|
var teamTaskSchema = import_zod.z.object({
|
|
17244
|
-
id: import_zod.z.string(),
|
|
17248
|
+
id: import_zod.z.string().regex(/^[0-9]+$/, "Task ID must be numeric"),
|
|
17245
17249
|
subject: import_zod.z.string(),
|
|
17246
17250
|
description: import_zod.z.string(),
|
|
17247
17251
|
status: import_zod.z.enum(["pending", "in_progress", "completed", "blocked"]),
|
|
@@ -17331,6 +17335,48 @@ var teamProtocolMessageSchema = import_zod.z.discriminatedUnion("type", [
|
|
|
17331
17335
|
|
|
17332
17336
|
// ../common/src/utils/team-fs.ts
|
|
17333
17337
|
var import_zod2 = require("zod");
|
|
17338
|
+
var TEAM_NAME_RE = /^[a-zA-Z0-9_-]+$/;
|
|
17339
|
+
var TEAM_NAME_MAX = 50;
|
|
17340
|
+
var AGENT_NAME_RE = /^[a-zA-Z0-9_-]+$/;
|
|
17341
|
+
var AGENT_NAME_MAX = 100;
|
|
17342
|
+
var TASK_ID_RE = /^[0-9]+$/;
|
|
17343
|
+
function validateTeamName(teamName) {
|
|
17344
|
+
if (!teamName || typeof teamName !== "string") {
|
|
17345
|
+
throw new Error("Team name is required and must be a string.");
|
|
17346
|
+
}
|
|
17347
|
+
if (teamName.length > TEAM_NAME_MAX) {
|
|
17348
|
+
throw new Error(`Team name must be at most ${TEAM_NAME_MAX} characters.`);
|
|
17349
|
+
}
|
|
17350
|
+
if (!TEAM_NAME_RE.test(teamName)) {
|
|
17351
|
+
throw new Error("Team name may only contain letters, numbers, hyphens, and underscores.");
|
|
17352
|
+
}
|
|
17353
|
+
}
|
|
17354
|
+
function validateAgentName(agentName) {
|
|
17355
|
+
if (!agentName || typeof agentName !== "string") {
|
|
17356
|
+
throw new Error("Agent name is required and must be a string.");
|
|
17357
|
+
}
|
|
17358
|
+
if (agentName.length > AGENT_NAME_MAX) {
|
|
17359
|
+
throw new Error(`Agent name must be at most ${AGENT_NAME_MAX} characters.`);
|
|
17360
|
+
}
|
|
17361
|
+
if (!AGENT_NAME_RE.test(agentName)) {
|
|
17362
|
+
throw new Error("Agent name may only contain letters, numbers, hyphens, and underscores.");
|
|
17363
|
+
}
|
|
17364
|
+
}
|
|
17365
|
+
function validateTaskId(taskId) {
|
|
17366
|
+
if (!taskId || typeof taskId !== "string") {
|
|
17367
|
+
throw new Error("Task ID is required and must be a string.");
|
|
17368
|
+
}
|
|
17369
|
+
if (!TASK_ID_RE.test(taskId)) {
|
|
17370
|
+
throw new Error("Task ID must be numeric.");
|
|
17371
|
+
}
|
|
17372
|
+
}
|
|
17373
|
+
function assertPathContained(resolvedPath, expectedParent) {
|
|
17374
|
+
const normalizedPath = path2.resolve(resolvedPath);
|
|
17375
|
+
const normalizedParent = path2.resolve(expectedParent);
|
|
17376
|
+
if (!normalizedPath.startsWith(normalizedParent + path2.sep) && normalizedPath !== normalizedParent) {
|
|
17377
|
+
throw new Error("Path traversal detected: resolved path escapes the expected directory.");
|
|
17378
|
+
}
|
|
17379
|
+
}
|
|
17334
17380
|
function getConfigRoot() {
|
|
17335
17381
|
return path2.join(os.homedir(), ".config", "levelcode");
|
|
17336
17382
|
}
|
|
@@ -17338,10 +17384,16 @@ function getTeamsDir() {
|
|
|
17338
17384
|
return path2.join(getConfigRoot(), "teams");
|
|
17339
17385
|
}
|
|
17340
17386
|
function getTasksDir(teamName) {
|
|
17341
|
-
|
|
17387
|
+
validateTeamName(teamName);
|
|
17388
|
+
const tasksDir = path2.join(getConfigRoot(), "tasks", teamName);
|
|
17389
|
+
assertPathContained(tasksDir, path2.join(getConfigRoot(), "tasks"));
|
|
17390
|
+
return tasksDir;
|
|
17342
17391
|
}
|
|
17343
17392
|
function getTeamDir(teamName) {
|
|
17344
|
-
|
|
17393
|
+
validateTeamName(teamName);
|
|
17394
|
+
const teamDir = path2.join(getTeamsDir(), teamName);
|
|
17395
|
+
assertPathContained(teamDir, getTeamsDir());
|
|
17396
|
+
return teamDir;
|
|
17345
17397
|
}
|
|
17346
17398
|
function getTeamConfigPath(teamName) {
|
|
17347
17399
|
return path2.join(getTeamDir(teamName), "config.json");
|
|
@@ -17350,10 +17402,16 @@ function getInboxesDir(teamName) {
|
|
|
17350
17402
|
return path2.join(getTeamDir(teamName), "inboxes");
|
|
17351
17403
|
}
|
|
17352
17404
|
function getInboxPath(teamName, agentName) {
|
|
17353
|
-
|
|
17405
|
+
validateAgentName(agentName);
|
|
17406
|
+
const inboxPath = path2.join(getInboxesDir(teamName), `${agentName}.json`);
|
|
17407
|
+
assertPathContained(inboxPath, getInboxesDir(teamName));
|
|
17408
|
+
return inboxPath;
|
|
17354
17409
|
}
|
|
17355
17410
|
function getTaskPath(teamName, taskId) {
|
|
17356
|
-
|
|
17411
|
+
validateTaskId(taskId);
|
|
17412
|
+
const taskPath = path2.join(getTasksDir(teamName), `${taskId}.json`);
|
|
17413
|
+
assertPathContained(taskPath, getTasksDir(teamName));
|
|
17414
|
+
return taskPath;
|
|
17357
17415
|
}
|
|
17358
17416
|
function createTeam(config) {
|
|
17359
17417
|
const teamDir = getTeamDir(config.name);
|
|
@@ -17852,7 +17910,7 @@ var callLevelCodeV1 = async (params2) => {
|
|
|
17852
17910
|
maxRetries: MAX_RETRIES,
|
|
17853
17911
|
nextRetryDelayMs: delay
|
|
17854
17912
|
}, `Web API ${requestName} request failed with retryable status, retrying...`);
|
|
17855
|
-
await new Promise((
|
|
17913
|
+
await new Promise((resolve2) => setTimeout(resolve2, delay));
|
|
17856
17914
|
lastError = err;
|
|
17857
17915
|
continue;
|
|
17858
17916
|
}
|
|
@@ -17876,7 +17934,7 @@ var callLevelCodeV1 = async (params2) => {
|
|
|
17876
17934
|
maxRetries: MAX_RETRIES,
|
|
17877
17935
|
nextRetryDelayMs: delay
|
|
17878
17936
|
}, `Web API ${requestName} network error, retrying...`);
|
|
17879
|
-
await new Promise((
|
|
17937
|
+
await new Promise((resolve2) => setTimeout(resolve2, delay));
|
|
17880
17938
|
continue;
|
|
17881
17939
|
}
|
|
17882
17940
|
logger2.error({
|
|
@@ -22098,13 +22156,13 @@ var coordinator = {
|
|
|
22098
22156
|
"ask_user",
|
|
22099
22157
|
"set_output",
|
|
22100
22158
|
"suggest_followups",
|
|
22101
|
-
"
|
|
22102
|
-
"
|
|
22103
|
-
"
|
|
22104
|
-
"
|
|
22105
|
-
"
|
|
22106
|
-
"
|
|
22107
|
-
"
|
|
22159
|
+
"team_create",
|
|
22160
|
+
"team_delete",
|
|
22161
|
+
"send_message",
|
|
22162
|
+
"task_create",
|
|
22163
|
+
"task_get",
|
|
22164
|
+
"task_update",
|
|
22165
|
+
"task_list"
|
|
22108
22166
|
],
|
|
22109
22167
|
spawnableAgents: [
|
|
22110
22168
|
"manager",
|
|
@@ -22127,7 +22185,7 @@ You lead a team of specialized agents. Your job is to:
|
|
|
22127
22185
|
2. Spawn and assign work to manager and senior-engineer agents.
|
|
22128
22186
|
3. Manage phase transitions (planning -> pre-alpha -> alpha -> beta -> production -> mature).
|
|
22129
22187
|
4. Review and approve plans submitted by managers before implementation begins.
|
|
22130
|
-
5. Monitor progress via
|
|
22188
|
+
5. Monitor progress via task_list / task_get and unblock stuck agents.
|
|
22131
22189
|
6. Communicate decisions and status to the user and to team members.
|
|
22132
22190
|
|
|
22133
22191
|
# Phase Management
|
|
@@ -22143,8 +22201,8 @@ Only advance one phase at a time. Confirm readiness before transitioning.
|
|
|
22143
22201
|
|
|
22144
22202
|
# Coordination Rules
|
|
22145
22203
|
|
|
22146
|
-
- Always create tasks (
|
|
22147
|
-
- Use
|
|
22204
|
+
- Always create tasks (task_create) before assigning work so progress is tracked.
|
|
22205
|
+
- Use send_message to communicate with individual team members. Reserve broadcasts for critical announcements.
|
|
22148
22206
|
- When a manager submits a plan for approval, review it carefully. Approve only if the plan is complete, feasible, and aligned with the objective.
|
|
22149
22207
|
- Spawn managers for large work streams. Spawn senior-engineers directly for focused, well-scoped tasks.
|
|
22150
22208
|
- Sequence dependent work: do not spawn agents in parallel if their outputs depend on each other.
|
|
@@ -22166,9 +22224,9 @@ Only advance one phase at a time. Confirm readiness before transitioning.
|
|
|
22166
22224
|
instructionsPrompt: `Orchestrate the team to complete the user's objective. Follow these steps:
|
|
22167
22225
|
|
|
22168
22226
|
1. **Understand the objective**: Read relevant files and gather context. Spawn researchers if needed.
|
|
22169
|
-
2. **Plan**: Use
|
|
22227
|
+
2. **Plan**: Use task_create to break the work into trackable tasks. Use write_todos for your own step-by-step plan.
|
|
22170
22228
|
3. **Delegate**: Spawn manager agents for large work streams or senior-engineer agents for focused tasks. Provide clear prompts with the task context.
|
|
22171
|
-
4. **Monitor**: Use
|
|
22229
|
+
4. **Monitor**: Use task_list and task_get to track progress. Unblock stuck agents by providing guidance via send_message.
|
|
22172
22230
|
5. **Review**: When agents complete work, verify quality. Spawn code reviewers or commanders to typecheck/test.
|
|
22173
22231
|
6. **Advance phases**: When current phase goals are met, transition to the next phase.
|
|
22174
22232
|
7. **Report**: Summarize what was accomplished to the user. Use suggest_followups for next steps.
|
|
@@ -22228,13 +22286,13 @@ var cto = {
|
|
|
22228
22286
|
"glob",
|
|
22229
22287
|
"list_directory",
|
|
22230
22288
|
"think_deeply",
|
|
22231
|
-
"
|
|
22232
|
-
"
|
|
22233
|
-
"
|
|
22234
|
-
"
|
|
22235
|
-
"
|
|
22236
|
-
"
|
|
22237
|
-
"
|
|
22289
|
+
"team_create",
|
|
22290
|
+
"team_delete",
|
|
22291
|
+
"send_message",
|
|
22292
|
+
"task_create",
|
|
22293
|
+
"task_get",
|
|
22294
|
+
"task_update",
|
|
22295
|
+
"task_list"
|
|
22238
22296
|
],
|
|
22239
22297
|
spawnableAgents: [
|
|
22240
22298
|
"manager",
|
|
@@ -22290,7 +22348,7 @@ When making technical decisions:
|
|
|
22290
22348
|
2. **Analyze strategically**: Spawn a thinker to reason through the strategic implications. Consider both short-term execution and long-term trajectory.
|
|
22291
22349
|
3. **Evaluate options**: For technology or architectural decisions, research alternatives. Use web_search and read_docs to evaluate external options.
|
|
22292
22350
|
4. **Make decisions**: Apply the decision framework. Document criteria, options, tradeoffs, and your reasoning.
|
|
22293
|
-
5. **Plan execution**: Use write_todos and
|
|
22351
|
+
5. **Plan execution**: Use write_todos and task_create to break the strategy into actionable work. Assign work to appropriate teams.
|
|
22294
22352
|
6. **Communicate**: Summarize decisions and their rationale. Use suggest_followups for next steps. Report to the coordinator.
|
|
22295
22353
|
|
|
22296
22354
|
Focus on strategic impact and organizational effectiveness, not implementation details.`,
|
|
@@ -22346,13 +22404,13 @@ var vpEngineering = {
|
|
|
22346
22404
|
"glob",
|
|
22347
22405
|
"list_directory",
|
|
22348
22406
|
"think_deeply",
|
|
22349
|
-
"
|
|
22350
|
-
"
|
|
22351
|
-
"
|
|
22352
|
-
"
|
|
22353
|
-
"
|
|
22354
|
-
"
|
|
22355
|
-
"
|
|
22407
|
+
"team_create",
|
|
22408
|
+
"team_delete",
|
|
22409
|
+
"send_message",
|
|
22410
|
+
"task_create",
|
|
22411
|
+
"task_get",
|
|
22412
|
+
"task_update",
|
|
22413
|
+
"task_list"
|
|
22356
22414
|
],
|
|
22357
22415
|
spawnableAgents: [
|
|
22358
22416
|
"manager",
|
|
@@ -22395,9 +22453,9 @@ You are the VP of Engineering responsible for:
|
|
|
22395
22453
|
|
|
22396
22454
|
1. **Assess the situation**: Read relevant files and spawn researchers to understand the current state of engineering operations, team structure, and delivery status.
|
|
22397
22455
|
2. **Analyze**: Spawn a thinker to reason through the organizational and process implications. Identify root causes of any issues.
|
|
22398
|
-
3. **Plan**: Use write_todos and
|
|
22399
|
-
4. **Organize**: Spawn managers for work streams that need coordination. Use
|
|
22400
|
-
5. **Track and communicate**: Use
|
|
22456
|
+
3. **Plan**: Use write_todos and task_create to create an actionable plan. Define clear milestones and ownership.
|
|
22457
|
+
4. **Organize**: Spawn managers for work streams that need coordination. Use team_create for new teams if needed.
|
|
22458
|
+
5. **Track and communicate**: Use task_list and task_get to monitor progress. Send updates via send_message. Report status to the coordinator.
|
|
22401
22459
|
6. **Report**: Summarize the plan, decisions, and expected outcomes. Use suggest_followups for next steps.
|
|
22402
22460
|
|
|
22403
22461
|
Focus on enabling the team to deliver effectively rather than on implementation details.`,
|
|
@@ -22453,13 +22511,13 @@ var director = {
|
|
|
22453
22511
|
"glob",
|
|
22454
22512
|
"list_directory",
|
|
22455
22513
|
"think_deeply",
|
|
22456
|
-
"
|
|
22457
|
-
"
|
|
22458
|
-
"
|
|
22459
|
-
"
|
|
22460
|
-
"
|
|
22461
|
-
"
|
|
22462
|
-
"
|
|
22514
|
+
"team_create",
|
|
22515
|
+
"team_delete",
|
|
22516
|
+
"send_message",
|
|
22517
|
+
"task_create",
|
|
22518
|
+
"task_get",
|
|
22519
|
+
"task_update",
|
|
22520
|
+
"task_list"
|
|
22463
22521
|
],
|
|
22464
22522
|
spawnableAgents: [
|
|
22465
22523
|
"manager",
|
|
@@ -22500,11 +22558,11 @@ You are a director responsible for:
|
|
|
22500
22558
|
- Escalate decisions that require user input via ask_user.`,
|
|
22501
22559
|
instructionsPrompt: `Address the assigned coordination or strategic planning challenge. Follow these steps:
|
|
22502
22560
|
|
|
22503
|
-
1. **Assess**: Read relevant files and review the current state of all involved teams via
|
|
22561
|
+
1. **Assess**: Read relevant files and review the current state of all involved teams via task_list. Understand what each team is working on and where they stand.
|
|
22504
22562
|
2. **Analyze dependencies**: Spawn a thinker to reason through cross-team dependencies and potential conflicts. Identify the critical path.
|
|
22505
|
-
3. **Plan**: Use write_todos and
|
|
22506
|
-
4. **Coordinate**: Spawn managers for each workstream. Use
|
|
22507
|
-
5. **Monitor**: Track progress via
|
|
22563
|
+
3. **Plan**: Use write_todos and task_create to create a cross-team plan. Define milestones, dependencies, and ownership.
|
|
22564
|
+
4. **Coordinate**: Spawn managers for each workstream. Use send_message to communicate priorities and constraints. Use team_create for new teams if needed.
|
|
22565
|
+
5. **Monitor**: Track progress via task_list and task_get. Identify blockers and resolve them.
|
|
22508
22566
|
6. **Report**: Summarize the plan, team assignments, timeline, and risks. Use suggest_followups for next steps. Report to the coordinator.
|
|
22509
22567
|
|
|
22510
22568
|
Focus on cross-team coordination and delivery, not individual implementation details.`,
|
|
@@ -31522,7 +31580,7 @@ Note: The file tree has been truncated to show a subset of files to fit within t
|
|
|
31522
31580
|
return `
|
|
31523
31581
|
# Project file tree
|
|
31524
31582
|
|
|
31525
|
-
As
|
|
31583
|
+
As Sage, you have access to all the files in the project.
|
|
31526
31584
|
|
|
31527
31585
|
The following is the path to the project on the user's computer. It is also the current working directory for terminal commands:
|
|
31528
31586
|
<project_path>
|
|
@@ -33379,7 +33437,7 @@ var handleTaskCompleted = async ({
|
|
|
33379
33437
|
completedTaskId = task.id;
|
|
33380
33438
|
taskSummary = `Task #${task.id} "${task.subject}" completed by ${agentName}.`;
|
|
33381
33439
|
try {
|
|
33382
|
-
updateTask(teamName, task.id, { status: "completed" });
|
|
33440
|
+
await updateTask(teamName, task.id, { status: "completed" });
|
|
33383
33441
|
} catch (error) {
|
|
33384
33442
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
33385
33443
|
logger2.warn?.(`Failed to mark task ${task.id} as completed: ${errorMessage}`);
|
|
@@ -33653,6 +33711,11 @@ function findCurrentTeamAndAgent(agentId) {
|
|
|
33653
33711
|
return null;
|
|
33654
33712
|
}
|
|
33655
33713
|
function findTeamByName(name) {
|
|
33714
|
+
try {
|
|
33715
|
+
validateTeamName(name);
|
|
33716
|
+
} catch {
|
|
33717
|
+
return null;
|
|
33718
|
+
}
|
|
33656
33719
|
return safeLoadTeamConfig(name);
|
|
33657
33720
|
}
|
|
33658
33721
|
function listAllTeams() {
|
|
@@ -33902,34 +33965,11 @@ var handleSendMessage = async (params2) => {
|
|
|
33902
33965
|
};
|
|
33903
33966
|
|
|
33904
33967
|
// ../packages/agent-runtime/src/tools/handlers/tool/task-create.ts
|
|
33905
|
-
var fs6 = __toESM(require("fs"));
|
|
33906
33968
|
function errorResult2(message) {
|
|
33907
33969
|
return { output: jsonToolResult({ error: message }) };
|
|
33908
33970
|
}
|
|
33909
|
-
function getActiveTeamName2() {
|
|
33910
|
-
let teamsDir;
|
|
33911
|
-
try {
|
|
33912
|
-
teamsDir = getTeamsDir();
|
|
33913
|
-
} catch {
|
|
33914
|
-
return null;
|
|
33915
|
-
}
|
|
33916
|
-
if (!fs6.existsSync(teamsDir)) {
|
|
33917
|
-
return null;
|
|
33918
|
-
}
|
|
33919
|
-
let entries;
|
|
33920
|
-
try {
|
|
33921
|
-
entries = fs6.readdirSync(teamsDir, { withFileTypes: true });
|
|
33922
|
-
} catch {
|
|
33923
|
-
return null;
|
|
33924
|
-
}
|
|
33925
|
-
const teamDirs = entries.filter((e) => e.isDirectory());
|
|
33926
|
-
if (teamDirs.length === 0) {
|
|
33927
|
-
return null;
|
|
33928
|
-
}
|
|
33929
|
-
return teamDirs[0].name;
|
|
33930
|
-
}
|
|
33931
33971
|
var handleTaskCreate = async (params2) => {
|
|
33932
|
-
const { previousToolCallFinished, toolCall } = params2;
|
|
33972
|
+
const { previousToolCallFinished, toolCall, agentStepId: agentStepId2 } = params2;
|
|
33933
33973
|
const { subject, description: description38, activeForm, priority, metadata } = toolCall.input;
|
|
33934
33974
|
await previousToolCallFinished;
|
|
33935
33975
|
if (!subject || typeof subject !== "string" || subject.trim() === "") {
|
|
@@ -33938,10 +33978,16 @@ var handleTaskCreate = async (params2) => {
|
|
|
33938
33978
|
if (!description38 || typeof description38 !== "string" || description38.trim() === "") {
|
|
33939
33979
|
return errorResult2('A non-empty "description" is required to create a task.');
|
|
33940
33980
|
}
|
|
33941
|
-
|
|
33942
|
-
|
|
33943
|
-
|
|
33981
|
+
let teamResult;
|
|
33982
|
+
try {
|
|
33983
|
+
teamResult = findCurrentTeam(agentStepId2);
|
|
33984
|
+
} catch {
|
|
33985
|
+
return errorResult2("Failed to look up team for the current agent. The teams directory may be inaccessible.");
|
|
33986
|
+
}
|
|
33987
|
+
if (!teamResult) {
|
|
33988
|
+
return errorResult2("No active team found. Create a team first using team_create.");
|
|
33944
33989
|
}
|
|
33990
|
+
const teamName = teamResult.teamName;
|
|
33945
33991
|
let existingTasks;
|
|
33946
33992
|
try {
|
|
33947
33993
|
existingTasks = listTasks(teamName);
|
|
@@ -33983,43 +34029,29 @@ var handleTaskCreate = async (params2) => {
|
|
|
33983
34029
|
};
|
|
33984
34030
|
|
|
33985
34031
|
// ../packages/agent-runtime/src/tools/handlers/tool/task-get.ts
|
|
33986
|
-
var fs7 = __toESM(require("fs"));
|
|
33987
34032
|
function errorResult3(message) {
|
|
33988
34033
|
return { output: jsonToolResult({ error: message }) };
|
|
33989
34034
|
}
|
|
33990
|
-
function getActiveTeamName3() {
|
|
33991
|
-
let teamsDir;
|
|
33992
|
-
try {
|
|
33993
|
-
teamsDir = getTeamsDir();
|
|
33994
|
-
} catch {
|
|
33995
|
-
return null;
|
|
33996
|
-
}
|
|
33997
|
-
if (!fs7.existsSync(teamsDir)) {
|
|
33998
|
-
return null;
|
|
33999
|
-
}
|
|
34000
|
-
let entries;
|
|
34001
|
-
try {
|
|
34002
|
-
entries = fs7.readdirSync(teamsDir, { withFileTypes: true });
|
|
34003
|
-
} catch {
|
|
34004
|
-
return null;
|
|
34005
|
-
}
|
|
34006
|
-
const teamDirs = entries.filter((e) => e.isDirectory());
|
|
34007
|
-
if (teamDirs.length === 0) {
|
|
34008
|
-
return null;
|
|
34009
|
-
}
|
|
34010
|
-
return teamDirs[0].name;
|
|
34011
|
-
}
|
|
34012
34035
|
var handleTaskGet = async (params2) => {
|
|
34013
|
-
const { previousToolCallFinished, toolCall } = params2;
|
|
34036
|
+
const { previousToolCallFinished, toolCall, agentStepId: agentStepId2 } = params2;
|
|
34014
34037
|
const { taskId } = toolCall.input;
|
|
34015
34038
|
await previousToolCallFinished;
|
|
34016
34039
|
if (!taskId || typeof taskId !== "string" || taskId.trim() === "") {
|
|
34017
34040
|
return errorResult3('A non-empty "taskId" is required.');
|
|
34018
34041
|
}
|
|
34019
|
-
|
|
34020
|
-
|
|
34021
|
-
return errorResult3("No active team found. Create a team first using TeamCreate.");
|
|
34042
|
+
if (!/^[0-9]+$/.test(taskId)) {
|
|
34043
|
+
return errorResult3("Task ID must be numeric.");
|
|
34022
34044
|
}
|
|
34045
|
+
let teamResult;
|
|
34046
|
+
try {
|
|
34047
|
+
teamResult = findCurrentTeam(agentStepId2);
|
|
34048
|
+
} catch {
|
|
34049
|
+
return errorResult3("Failed to look up team for the current agent. The teams directory may be inaccessible.");
|
|
34050
|
+
}
|
|
34051
|
+
if (!teamResult) {
|
|
34052
|
+
return errorResult3("No active team found. Create a team first using team_create.");
|
|
34053
|
+
}
|
|
34054
|
+
const teamName = teamResult.teamName;
|
|
34023
34055
|
let task;
|
|
34024
34056
|
try {
|
|
34025
34057
|
task = getTask(teamName, taskId);
|
|
@@ -34036,41 +34068,29 @@ var handleTaskGet = async (params2) => {
|
|
|
34036
34068
|
};
|
|
34037
34069
|
|
|
34038
34070
|
// ../packages/agent-runtime/src/tools/handlers/tool/task-list.ts
|
|
34039
|
-
var
|
|
34040
|
-
|
|
34041
|
-
|
|
34042
|
-
|
|
34043
|
-
teamsDir = getTeamsDir();
|
|
34044
|
-
} catch {
|
|
34045
|
-
return null;
|
|
34046
|
-
}
|
|
34047
|
-
if (!fs8.existsSync(teamsDir)) {
|
|
34048
|
-
return null;
|
|
34049
|
-
}
|
|
34050
|
-
let entries;
|
|
34071
|
+
var handleTaskList = async (params2) => {
|
|
34072
|
+
const { previousToolCallFinished, agentStepId: agentStepId2 } = params2;
|
|
34073
|
+
await previousToolCallFinished;
|
|
34074
|
+
let teamResult;
|
|
34051
34075
|
try {
|
|
34052
|
-
|
|
34076
|
+
teamResult = findCurrentTeam(agentStepId2);
|
|
34053
34077
|
} catch {
|
|
34054
|
-
return
|
|
34055
|
-
|
|
34056
|
-
|
|
34057
|
-
|
|
34058
|
-
|
|
34078
|
+
return {
|
|
34079
|
+
output: jsonToolResult({
|
|
34080
|
+
error: "Failed to look up team for the current agent. The teams directory may be inaccessible.",
|
|
34081
|
+
tasks: []
|
|
34082
|
+
})
|
|
34083
|
+
};
|
|
34059
34084
|
}
|
|
34060
|
-
|
|
34061
|
-
}
|
|
34062
|
-
var handleTaskList = async (params2) => {
|
|
34063
|
-
const { previousToolCallFinished } = params2;
|
|
34064
|
-
await previousToolCallFinished;
|
|
34065
|
-
const teamName = getActiveTeamName4();
|
|
34066
|
-
if (!teamName) {
|
|
34085
|
+
if (!teamResult) {
|
|
34067
34086
|
return {
|
|
34068
34087
|
output: jsonToolResult({
|
|
34069
|
-
error: "No active team found. Create a team first using
|
|
34088
|
+
error: "No active team found. Create a team first using team_create.",
|
|
34070
34089
|
tasks: []
|
|
34071
34090
|
})
|
|
34072
34091
|
};
|
|
34073
34092
|
}
|
|
34093
|
+
const teamName = teamResult.teamName;
|
|
34074
34094
|
let tasks;
|
|
34075
34095
|
try {
|
|
34076
34096
|
tasks = listTasks(teamName);
|
|
@@ -34100,36 +34120,14 @@ var handleTaskList = async (params2) => {
|
|
|
34100
34120
|
};
|
|
34101
34121
|
|
|
34102
34122
|
// ../packages/agent-runtime/src/tools/handlers/tool/task-update.ts
|
|
34103
|
-
var
|
|
34123
|
+
var fs6 = __toESM(require("fs"));
|
|
34104
34124
|
var path5 = __toESM(require("path"));
|
|
34105
34125
|
var VALID_STATUSES = ["pending", "in_progress", "completed", "blocked", "deleted"];
|
|
34106
34126
|
function errorResult4(message) {
|
|
34107
34127
|
return { output: jsonToolResult({ error: message }) };
|
|
34108
34128
|
}
|
|
34109
|
-
function getActiveTeamName5() {
|
|
34110
|
-
let teamsDir;
|
|
34111
|
-
try {
|
|
34112
|
-
teamsDir = getTeamsDir();
|
|
34113
|
-
} catch {
|
|
34114
|
-
return null;
|
|
34115
|
-
}
|
|
34116
|
-
if (!fs9.existsSync(teamsDir)) {
|
|
34117
|
-
return null;
|
|
34118
|
-
}
|
|
34119
|
-
let entries;
|
|
34120
|
-
try {
|
|
34121
|
-
entries = fs9.readdirSync(teamsDir, { withFileTypes: true });
|
|
34122
|
-
} catch {
|
|
34123
|
-
return null;
|
|
34124
|
-
}
|
|
34125
|
-
const teamDirs = entries.filter((e) => e.isDirectory());
|
|
34126
|
-
if (teamDirs.length === 0) {
|
|
34127
|
-
return null;
|
|
34128
|
-
}
|
|
34129
|
-
return teamDirs[0].name;
|
|
34130
|
-
}
|
|
34131
34129
|
var handleTaskUpdate = async (params2) => {
|
|
34132
|
-
const { previousToolCallFinished, toolCall, trackEvent: trackEvent2, userId, logger: logger2 } = params2;
|
|
34130
|
+
const { previousToolCallFinished, toolCall, agentStepId: agentStepId2, trackEvent: trackEvent2, userId, logger: logger2 } = params2;
|
|
34133
34131
|
const {
|
|
34134
34132
|
taskId,
|
|
34135
34133
|
status,
|
|
@@ -34146,13 +34144,22 @@ var handleTaskUpdate = async (params2) => {
|
|
|
34146
34144
|
if (!taskId || typeof taskId !== "string" || taskId.trim() === "") {
|
|
34147
34145
|
return errorResult4('A non-empty "taskId" is required.');
|
|
34148
34146
|
}
|
|
34147
|
+
if (!/^[0-9]+$/.test(taskId)) {
|
|
34148
|
+
return errorResult4("Task ID must be numeric.");
|
|
34149
|
+
}
|
|
34149
34150
|
if (status !== undefined && !VALID_STATUSES.includes(status)) {
|
|
34150
34151
|
return errorResult4(`Invalid status "${status}". Expected one of: ${VALID_STATUSES.join(", ")}`);
|
|
34151
34152
|
}
|
|
34152
|
-
|
|
34153
|
-
|
|
34154
|
-
|
|
34153
|
+
let teamResult;
|
|
34154
|
+
try {
|
|
34155
|
+
teamResult = findCurrentTeam(agentStepId2);
|
|
34156
|
+
} catch {
|
|
34157
|
+
return errorResult4("Failed to look up team for the current agent. The teams directory may be inaccessible.");
|
|
34158
|
+
}
|
|
34159
|
+
if (!teamResult) {
|
|
34160
|
+
return errorResult4("No active team found. Create a team first using team_create.");
|
|
34155
34161
|
}
|
|
34162
|
+
const teamName = teamResult.teamName;
|
|
34156
34163
|
let existingTask;
|
|
34157
34164
|
try {
|
|
34158
34165
|
existingTask = getTask(teamName, taskId);
|
|
@@ -34166,8 +34173,8 @@ var handleTaskUpdate = async (params2) => {
|
|
|
34166
34173
|
if (status === "deleted") {
|
|
34167
34174
|
try {
|
|
34168
34175
|
const taskPath = path5.join(getTasksDir(teamName), `${taskId}.json`);
|
|
34169
|
-
if (
|
|
34170
|
-
|
|
34176
|
+
if (fs6.existsSync(taskPath)) {
|
|
34177
|
+
fs6.unlinkSync(taskPath);
|
|
34171
34178
|
}
|
|
34172
34179
|
} catch (error) {
|
|
34173
34180
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -34263,6 +34270,9 @@ var handleTeamCreate = async (params2) => {
|
|
|
34263
34270
|
if (!/^[a-zA-Z0-9_-]+$/.test(team_name)) {
|
|
34264
34271
|
return errorResult5(`Invalid team name "${team_name}". Team names may only contain letters, numbers, hyphens, and underscores.`);
|
|
34265
34272
|
}
|
|
34273
|
+
if (team_name.length > 50) {
|
|
34274
|
+
return errorResult5("Team name must be at most 50 characters.");
|
|
34275
|
+
}
|
|
34266
34276
|
try {
|
|
34267
34277
|
const existing = loadTeamConfig(team_name);
|
|
34268
34278
|
if (existing) {
|
|
@@ -35357,7 +35367,7 @@ async function formatPrompt(params2) {
|
|
|
35357
35367
|
localAgentTemplates: agentTemplates
|
|
35358
35368
|
}) : null;
|
|
35359
35369
|
const toInject = {
|
|
35360
|
-
[PLACEHOLDER2.AGENT_NAME]: () => agentTemplate ? agentTemplate.displayName || "Unknown Agent" : "
|
|
35370
|
+
[PLACEHOLDER2.AGENT_NAME]: () => agentTemplate ? agentTemplate.displayName || "Unknown Agent" : "Sage",
|
|
35361
35371
|
[PLACEHOLDER2.FILE_TREE_PROMPT_SMALL]: () => getProjectFileTreePrompt({
|
|
35362
35372
|
fileContext,
|
|
35363
35373
|
fileTreeTokenBudget: 2500,
|
|
@@ -37472,7 +37482,7 @@ class Protocol {
|
|
|
37472
37482
|
}
|
|
37473
37483
|
request(request, resultSchema, options) {
|
|
37474
37484
|
const { relatedRequestId, resumptionToken, onresumptiontoken } = options !== null && options !== undefined ? options : {};
|
|
37475
|
-
return new Promise((
|
|
37485
|
+
return new Promise((resolve3, reject) => {
|
|
37476
37486
|
var _a, _b, _c, _d, _e, _f;
|
|
37477
37487
|
if (!this._transport) {
|
|
37478
37488
|
reject(new Error("Not connected"));
|
|
@@ -37523,7 +37533,7 @@ class Protocol {
|
|
|
37523
37533
|
}
|
|
37524
37534
|
try {
|
|
37525
37535
|
const result = resultSchema.parse(response.result);
|
|
37526
|
-
|
|
37536
|
+
resolve3(result);
|
|
37527
37537
|
} catch (error) {
|
|
37528
37538
|
reject(error);
|
|
37529
37539
|
}
|
|
@@ -38927,7 +38937,7 @@ class SSEClientTransport {
|
|
|
38927
38937
|
_startOrAuth() {
|
|
38928
38938
|
var _a, _b, _c;
|
|
38929
38939
|
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;
|
|
38930
|
-
return new Promise((
|
|
38940
|
+
return new Promise((resolve3, reject) => {
|
|
38931
38941
|
this._eventSource = new EventSource(this._url.href, {
|
|
38932
38942
|
...this._eventSourceInit,
|
|
38933
38943
|
fetch: async (url, init) => {
|
|
@@ -38947,7 +38957,7 @@ class SSEClientTransport {
|
|
|
38947
38957
|
this._eventSource.onerror = (event) => {
|
|
38948
38958
|
var _a2;
|
|
38949
38959
|
if (event.code === 401 && this._authProvider) {
|
|
38950
|
-
this._authThenStart().then(
|
|
38960
|
+
this._authThenStart().then(resolve3, reject);
|
|
38951
38961
|
return;
|
|
38952
38962
|
}
|
|
38953
38963
|
const error = new SseError(event.code, event.message, event);
|
|
@@ -38969,7 +38979,7 @@ class SSEClientTransport {
|
|
|
38969
38979
|
this.close();
|
|
38970
38980
|
return;
|
|
38971
38981
|
}
|
|
38972
|
-
|
|
38982
|
+
resolve3();
|
|
38973
38983
|
});
|
|
38974
38984
|
this._eventSource.onmessage = (event) => {
|
|
38975
38985
|
var _a2, _b2;
|
|
@@ -39132,7 +39142,7 @@ class StdioClientTransport {
|
|
|
39132
39142
|
if (this._process) {
|
|
39133
39143
|
throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
39134
39144
|
}
|
|
39135
|
-
return new Promise((
|
|
39145
|
+
return new Promise((resolve3, reject) => {
|
|
39136
39146
|
var _a, _b, _c, _d, _e;
|
|
39137
39147
|
this._process = import_cross_spawn.default(this._serverParams.command, (_a = this._serverParams.args) !== null && _a !== undefined ? _a : [], {
|
|
39138
39148
|
env: {
|
|
@@ -39155,7 +39165,7 @@ class StdioClientTransport {
|
|
|
39155
39165
|
(_b2 = this.onerror) === null || _b2 === undefined || _b2.call(this, error);
|
|
39156
39166
|
});
|
|
39157
39167
|
this._process.on("spawn", () => {
|
|
39158
|
-
|
|
39168
|
+
resolve3();
|
|
39159
39169
|
});
|
|
39160
39170
|
this._process.on("close", (_code) => {
|
|
39161
39171
|
var _a2;
|
|
@@ -39210,16 +39220,16 @@ class StdioClientTransport {
|
|
|
39210
39220
|
this._readBuffer.clear();
|
|
39211
39221
|
}
|
|
39212
39222
|
send(message) {
|
|
39213
|
-
return new Promise((
|
|
39223
|
+
return new Promise((resolve3) => {
|
|
39214
39224
|
var _a;
|
|
39215
39225
|
if (!((_a = this._process) === null || _a === undefined ? undefined : _a.stdin)) {
|
|
39216
39226
|
throw new Error("Not connected");
|
|
39217
39227
|
}
|
|
39218
39228
|
const json = serializeMessage(message);
|
|
39219
39229
|
if (this._process.stdin.write(json)) {
|
|
39220
|
-
|
|
39230
|
+
resolve3();
|
|
39221
39231
|
} else {
|
|
39222
|
-
this._process.stdin.once("drain",
|
|
39232
|
+
this._process.stdin.once("drain", resolve3);
|
|
39223
39233
|
}
|
|
39224
39234
|
});
|
|
39225
39235
|
}
|
|
@@ -39972,7 +39982,7 @@ async function fetchWithRetry(url, options, logger2) {
|
|
|
39972
39982
|
}
|
|
39973
39983
|
if (attempt < MAX_RETRIES_PER_MESSAGE) {
|
|
39974
39984
|
logger2?.warn({ status: response.status, attempt: attempt + 1, url: String(url) }, `Retryable HTTP error, retrying in ${backoffDelay}ms`);
|
|
39975
|
-
await new Promise((
|
|
39985
|
+
await new Promise((resolve3) => setTimeout(resolve3, backoffDelay));
|
|
39976
39986
|
backoffDelay = Math.min(backoffDelay * 2, RETRY_BACKOFF_MAX_DELAY_MS);
|
|
39977
39987
|
} else {
|
|
39978
39988
|
return response;
|
|
@@ -39981,7 +39991,7 @@ async function fetchWithRetry(url, options, logger2) {
|
|
|
39981
39991
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
39982
39992
|
if (attempt < MAX_RETRIES_PER_MESSAGE) {
|
|
39983
39993
|
logger2?.warn({ error: getErrorObject(lastError), attempt: attempt + 1, url: String(url) }, `Network error, retrying in ${backoffDelay}ms`);
|
|
39984
|
-
await new Promise((
|
|
39994
|
+
await new Promise((resolve3) => setTimeout(resolve3, backoffDelay));
|
|
39985
39995
|
backoffDelay = Math.min(backoffDelay * 2, RETRY_BACKOFF_MAX_DELAY_MS);
|
|
39986
39996
|
}
|
|
39987
39997
|
}
|
|
@@ -44031,16 +44041,16 @@ var os6 = __toESM(require("os"));
|
|
|
44031
44041
|
var import_path8 = __toESM(require("path"));
|
|
44032
44042
|
|
|
44033
44043
|
// ../packages/code-map/src/parse.ts
|
|
44034
|
-
var
|
|
44044
|
+
var fs10 = __toESM(require("fs"));
|
|
44035
44045
|
var path11 = __toESM(require("path"));
|
|
44036
44046
|
|
|
44037
44047
|
// ../packages/code-map/src/languages.ts
|
|
44038
|
-
var
|
|
44048
|
+
var fs9 = __toESM(require("fs"));
|
|
44039
44049
|
var path10 = __toESM(require("path"));
|
|
44040
44050
|
var import_web_tree_sitter2 = require("web-tree-sitter");
|
|
44041
44051
|
|
|
44042
44052
|
// ../packages/code-map/src/init-node.ts
|
|
44043
|
-
var
|
|
44053
|
+
var fs8 = __toESM(require("fs"));
|
|
44044
44054
|
var path9 = __toESM(require("path"));
|
|
44045
44055
|
var import_web_tree_sitter = require("web-tree-sitter");
|
|
44046
44056
|
async function initTreeSitterForNode() {
|
|
@@ -44048,12 +44058,12 @@ async function initTreeSitterForNode() {
|
|
|
44048
44058
|
locateFile: (name14, scriptDir) => {
|
|
44049
44059
|
if (name14 === "tree-sitter.wasm") {
|
|
44050
44060
|
const fallback = path9.join(scriptDir, name14);
|
|
44051
|
-
if (
|
|
44061
|
+
if (fs8.existsSync(fallback)) {
|
|
44052
44062
|
return fallback;
|
|
44053
44063
|
}
|
|
44054
44064
|
const pkgDir = path9.dirname(require.resolve("web-tree-sitter"));
|
|
44055
44065
|
const wasm = path9.join(pkgDir, "tree-sitter.wasm");
|
|
44056
|
-
if (
|
|
44066
|
+
if (fs8.existsSync(wasm)) {
|
|
44057
44067
|
return wasm;
|
|
44058
44068
|
}
|
|
44059
44069
|
throw new Error(`Internal error: web-tree-sitter/tree-sitter.wasm not found at ${wasm}. Ensure the file is included in your deployment bundle.`);
|
|
@@ -44472,7 +44482,7 @@ async function createLanguageConfig(filePath, runtimeLoader) {
|
|
|
44472
44482
|
const lang = await runtimeLoader.loadLanguage(cfg.wasmFile);
|
|
44473
44483
|
const parser = new import_web_tree_sitter2.Parser;
|
|
44474
44484
|
parser.setLanguage(lang);
|
|
44475
|
-
const queryContent = path10.isAbsolute(cfg.queryPathOrContent) ?
|
|
44485
|
+
const queryContent = path10.isAbsolute(cfg.queryPathOrContent) ? fs9.readFileSync(cfg.queryPathOrContent, "utf8") : cfg.queryPathOrContent;
|
|
44476
44486
|
cfg.language = lang;
|
|
44477
44487
|
cfg.parser = parser;
|
|
44478
44488
|
cfg.query = new import_web_tree_sitter2.Query(lang, queryContent);
|
|
@@ -44578,7 +44588,7 @@ async function getFileTokenScores(projectRoot, filePaths, readFile) {
|
|
|
44578
44588
|
const endTime = Date.now();
|
|
44579
44589
|
console.log(`Parsed ${filePaths.length} files in ${endTime - startTime2}ms`);
|
|
44580
44590
|
try {
|
|
44581
|
-
|
|
44591
|
+
fs10.writeFileSync("../debug/debug-parse.json", JSON.stringify({
|
|
44582
44592
|
tokenCallers,
|
|
44583
44593
|
tokenScores,
|
|
44584
44594
|
fileCallsMap,
|
|
@@ -44591,7 +44601,7 @@ async function getFileTokenScores(projectRoot, filePaths, readFile) {
|
|
|
44591
44601
|
function parseTokens(filePath, languageConfig, readFile) {
|
|
44592
44602
|
const { parser, query } = languageConfig;
|
|
44593
44603
|
try {
|
|
44594
|
-
const sourceCode = readFile ? readFile(filePath) :
|
|
44604
|
+
const sourceCode = readFile ? readFile(filePath) : fs10.readFileSync(filePath, "utf8");
|
|
44595
44605
|
if (sourceCode === null) {
|
|
44596
44606
|
return {
|
|
44597
44607
|
numLines: 0,
|
|
@@ -45076,7 +45086,7 @@ async function computeProjectIndex(cwd, projectFiles) {
|
|
|
45076
45086
|
return { fileTree, fileTokenScores, tokenCallers };
|
|
45077
45087
|
}
|
|
45078
45088
|
function childProcessToPromise(proc) {
|
|
45079
|
-
return new Promise((
|
|
45089
|
+
return new Promise((resolve3, reject) => {
|
|
45080
45090
|
let stdout = "";
|
|
45081
45091
|
let stderr = "";
|
|
45082
45092
|
proc.stdout?.on("data", (data) => {
|
|
@@ -45087,7 +45097,7 @@ function childProcessToPromise(proc) {
|
|
|
45087
45097
|
});
|
|
45088
45098
|
proc.on("close", (code) => {
|
|
45089
45099
|
if (code === 0) {
|
|
45090
|
-
|
|
45100
|
+
resolve3({ stdout, stderr });
|
|
45091
45101
|
} else {
|
|
45092
45102
|
reject(new Error(`Command exited with code ${code}`));
|
|
45093
45103
|
}
|
|
@@ -45123,13 +45133,13 @@ async function getGitChanges(params2) {
|
|
|
45123
45133
|
};
|
|
45124
45134
|
}
|
|
45125
45135
|
async function discoverProjectFiles(params2) {
|
|
45126
|
-
const { cwd, fs:
|
|
45127
|
-
const fileTree = await getProjectFileTree({ projectRoot: cwd, fs:
|
|
45136
|
+
const { cwd, fs: fs13, logger: logger2 } = params2;
|
|
45137
|
+
const fileTree = await getProjectFileTree({ projectRoot: cwd, fs: fs13 });
|
|
45128
45138
|
const filePaths = getAllFilePaths(fileTree);
|
|
45129
45139
|
let error;
|
|
45130
45140
|
const projectFilePromises = Object.fromEntries(filePaths.map((filePath) => [
|
|
45131
45141
|
filePath,
|
|
45132
|
-
|
|
45142
|
+
fs13.readFile(import_path8.default.join(cwd, filePath), "utf8").catch((err) => {
|
|
45133
45143
|
error = err;
|
|
45134
45144
|
return "[ERROR_READING_FILE]";
|
|
45135
45145
|
})
|
|
@@ -45144,12 +45154,12 @@ async function discoverProjectFiles(params2) {
|
|
|
45144
45154
|
return projectFilesResolved;
|
|
45145
45155
|
}
|
|
45146
45156
|
async function loadUserKnowledgeFiles(params2) {
|
|
45147
|
-
const { fs:
|
|
45157
|
+
const { fs: fs13, logger: logger2 } = params2;
|
|
45148
45158
|
const homeDir = params2.homeDir ?? os6.homedir();
|
|
45149
45159
|
const userKnowledgeFiles = {};
|
|
45150
45160
|
let entries;
|
|
45151
45161
|
try {
|
|
45152
|
-
entries = await
|
|
45162
|
+
entries = await fs13.readdir(homeDir);
|
|
45153
45163
|
} catch (error) {
|
|
45154
45164
|
logger2.debug?.({ homeDir, error: getErrorObject(error) }, "Failed to read home directory");
|
|
45155
45165
|
return userKnowledgeFiles;
|
|
@@ -45169,7 +45179,7 @@ async function loadUserKnowledgeFiles(params2) {
|
|
|
45169
45179
|
if (actualFileName) {
|
|
45170
45180
|
const filePath = import_path8.default.join(homeDir, actualFileName);
|
|
45171
45181
|
try {
|
|
45172
|
-
const content = await
|
|
45182
|
+
const content = await fs13.readFile(filePath, "utf8");
|
|
45173
45183
|
const tildeKey = `~/${actualFileName}`;
|
|
45174
45184
|
userKnowledgeFiles[tildeKey] = content;
|
|
45175
45185
|
break;
|
|
@@ -45216,7 +45226,7 @@ async function initialSessionState(params2) {
|
|
|
45216
45226
|
projectFiles,
|
|
45217
45227
|
knowledgeFiles,
|
|
45218
45228
|
userKnowledgeFiles: providedUserKnowledgeFiles,
|
|
45219
|
-
fs:
|
|
45229
|
+
fs: fs13,
|
|
45220
45230
|
spawn: spawn2,
|
|
45221
45231
|
logger: logger2
|
|
45222
45232
|
} = params2;
|
|
@@ -45226,8 +45236,8 @@ async function initialSessionState(params2) {
|
|
|
45226
45236
|
if (!customToolDefinitions) {
|
|
45227
45237
|
customToolDefinitions = [];
|
|
45228
45238
|
}
|
|
45229
|
-
if (!
|
|
45230
|
-
|
|
45239
|
+
if (!fs13) {
|
|
45240
|
+
fs13 = require("fs").promises;
|
|
45231
45241
|
}
|
|
45232
45242
|
if (!spawn2) {
|
|
45233
45243
|
const { spawn: nodeSpawn } = require("child_process");
|
|
@@ -45242,7 +45252,7 @@ async function initialSessionState(params2) {
|
|
|
45242
45252
|
};
|
|
45243
45253
|
}
|
|
45244
45254
|
if (projectFiles === undefined && cwd) {
|
|
45245
|
-
projectFiles = await discoverProjectFiles({ cwd, fs:
|
|
45255
|
+
projectFiles = await discoverProjectFiles({ cwd, fs: fs13, logger: logger2 });
|
|
45246
45256
|
}
|
|
45247
45257
|
if (knowledgeFiles === undefined) {
|
|
45248
45258
|
knowledgeFiles = projectFiles ? deriveKnowledgeFiles(projectFiles) : {};
|
|
@@ -45269,7 +45279,7 @@ async function initialSessionState(params2) {
|
|
|
45269
45279
|
diffCached: "",
|
|
45270
45280
|
lastCommitMessages: ""
|
|
45271
45281
|
};
|
|
45272
|
-
const homeKnowledgeFiles = await loadUserKnowledgeFiles({ fs:
|
|
45282
|
+
const homeKnowledgeFiles = await loadUserKnowledgeFiles({ fs: fs13, logger: logger2 });
|
|
45273
45283
|
const userKnowledgeFiles = {
|
|
45274
45284
|
...homeKnowledgeFiles,
|
|
45275
45285
|
...providedUserKnowledgeFiles
|
|
@@ -45311,7 +45321,7 @@ async function generateInitialRunState({
|
|
|
45311
45321
|
agentDefinitions,
|
|
45312
45322
|
customToolDefinitions,
|
|
45313
45323
|
maxAgentSteps,
|
|
45314
|
-
fs:
|
|
45324
|
+
fs: fs13
|
|
45315
45325
|
}) {
|
|
45316
45326
|
return {
|
|
45317
45327
|
sessionState: await initialSessionState({
|
|
@@ -45322,7 +45332,7 @@ async function generateInitialRunState({
|
|
|
45322
45332
|
agentDefinitions,
|
|
45323
45333
|
customToolDefinitions,
|
|
45324
45334
|
maxAgentSteps,
|
|
45325
|
-
fs:
|
|
45335
|
+
fs: fs13
|
|
45326
45336
|
}),
|
|
45327
45337
|
output: {
|
|
45328
45338
|
type: "error",
|
|
@@ -45457,7 +45467,7 @@ function containsPathTraversal(filePath) {
|
|
|
45457
45467
|
return import_path9.default.isAbsolute(normalized) || normalized.startsWith("..");
|
|
45458
45468
|
}
|
|
45459
45469
|
async function changeFile(params2) {
|
|
45460
|
-
const { parameters, cwd, fs:
|
|
45470
|
+
const { parameters, cwd, fs: fs13 } = params2;
|
|
45461
45471
|
if (containsUpwardTraversal(cwd)) {
|
|
45462
45472
|
throw new Error("cwd contains invalid path traversal");
|
|
45463
45473
|
}
|
|
@@ -45470,7 +45480,7 @@ async function changeFile(params2) {
|
|
|
45470
45480
|
const { created, modified, invalid, patchFailed } = await applyChanges({
|
|
45471
45481
|
projectRoot: cwd,
|
|
45472
45482
|
changes: [fileChange],
|
|
45473
|
-
fs:
|
|
45483
|
+
fs: fs13
|
|
45474
45484
|
});
|
|
45475
45485
|
const results = [];
|
|
45476
45486
|
for (const file of created) {
|
|
@@ -45509,7 +45519,7 @@ async function changeFile(params2) {
|
|
|
45509
45519
|
return [{ type: "json", value: results[0] }];
|
|
45510
45520
|
}
|
|
45511
45521
|
async function applyChanges(params2) {
|
|
45512
|
-
const { projectRoot, changes, fs:
|
|
45522
|
+
const { projectRoot, changes, fs: fs13 } = params2;
|
|
45513
45523
|
const created = [];
|
|
45514
45524
|
const modified = [];
|
|
45515
45525
|
const patchFailed = [];
|
|
@@ -45518,21 +45528,21 @@ async function applyChanges(params2) {
|
|
|
45518
45528
|
const { path: filePath, content, type } = change;
|
|
45519
45529
|
try {
|
|
45520
45530
|
const fullPath = import_path9.default.join(projectRoot, filePath);
|
|
45521
|
-
const exists = await fileExists({ filePath: fullPath, fs:
|
|
45531
|
+
const exists = await fileExists({ filePath: fullPath, fs: fs13 });
|
|
45522
45532
|
if (!exists) {
|
|
45523
45533
|
const dirPath = import_path9.default.dirname(fullPath);
|
|
45524
|
-
await
|
|
45534
|
+
await fs13.mkdir(dirPath, { recursive: true });
|
|
45525
45535
|
}
|
|
45526
45536
|
if (type === "file") {
|
|
45527
|
-
await
|
|
45537
|
+
await fs13.writeFile(fullPath, content);
|
|
45528
45538
|
} else {
|
|
45529
|
-
const oldContent = await
|
|
45539
|
+
const oldContent = await fs13.readFile(fullPath, "utf-8");
|
|
45530
45540
|
const newContent = import_diff4.applyPatch(oldContent, content);
|
|
45531
45541
|
if (newContent === false) {
|
|
45532
45542
|
patchFailed.push(filePath);
|
|
45533
45543
|
continue;
|
|
45534
45544
|
}
|
|
45535
|
-
await
|
|
45545
|
+
await fs13.writeFile(fullPath, newContent);
|
|
45536
45546
|
}
|
|
45537
45547
|
if (exists) {
|
|
45538
45548
|
modified.push(filePath);
|
|
@@ -45549,7 +45559,7 @@ async function applyChanges(params2) {
|
|
|
45549
45559
|
|
|
45550
45560
|
// src/tools/code-search.ts
|
|
45551
45561
|
var import_child_process = require("child_process");
|
|
45552
|
-
var
|
|
45562
|
+
var fs13 = __toESM(require("fs"));
|
|
45553
45563
|
var path16 = __toESM(require("path"));
|
|
45554
45564
|
|
|
45555
45565
|
// ../common/src/util/format-code-search.ts
|
|
@@ -45690,12 +45700,12 @@ function codeSearch({
|
|
|
45690
45700
|
timeoutSeconds = 10,
|
|
45691
45701
|
logger: logger2
|
|
45692
45702
|
}) {
|
|
45693
|
-
return new Promise((
|
|
45703
|
+
return new Promise((resolve4) => {
|
|
45694
45704
|
let isResolved = false;
|
|
45695
45705
|
const projectRoot = path16.resolve(projectPath);
|
|
45696
45706
|
const searchCwd = cwd ? path16.resolve(projectRoot, cwd) : projectRoot;
|
|
45697
45707
|
if (!searchCwd.startsWith(projectRoot + path16.sep) && searchCwd !== projectRoot) {
|
|
45698
|
-
return
|
|
45708
|
+
return resolve4([
|
|
45699
45709
|
{
|
|
45700
45710
|
type: "json",
|
|
45701
45711
|
value: {
|
|
@@ -45707,7 +45717,7 @@ function codeSearch({
|
|
|
45707
45717
|
const flagsArray = (flags || "").split(" ").filter(Boolean).map((token) => token.replace(/^['"]|['"]$/g, ""));
|
|
45708
45718
|
const existingHiddenDirs = INCLUDED_HIDDEN_DIRS.filter((dir) => {
|
|
45709
45719
|
try {
|
|
45710
|
-
return
|
|
45720
|
+
return fs13.statSync(path16.join(searchCwd, dir)).isDirectory();
|
|
45711
45721
|
} catch {
|
|
45712
45722
|
return false;
|
|
45713
45723
|
}
|
|
@@ -45750,7 +45760,7 @@ function codeSearch({
|
|
|
45750
45760
|
clearTimeout(killTimeoutId);
|
|
45751
45761
|
killTimeoutId = null;
|
|
45752
45762
|
}
|
|
45753
|
-
|
|
45763
|
+
resolve4([{ type: "json", value: payload }]);
|
|
45754
45764
|
};
|
|
45755
45765
|
const hardKill = () => {
|
|
45756
45766
|
try {
|
|
@@ -45955,9 +45965,9 @@ ${truncatedFiles.join(`
|
|
|
45955
45965
|
// src/tools/glob.ts
|
|
45956
45966
|
var import_micromatch = __toESM(require("micromatch"));
|
|
45957
45967
|
async function glob(params2) {
|
|
45958
|
-
const { pattern, projectPath, cwd, fs:
|
|
45968
|
+
const { pattern, projectPath, cwd, fs: fs14 } = params2;
|
|
45959
45969
|
try {
|
|
45960
|
-
const fileTree = await getProjectFileTree({ projectRoot: projectPath, fs:
|
|
45970
|
+
const fileTree = await getProjectFileTree({ projectRoot: projectPath, fs: fs14 });
|
|
45961
45971
|
const flattenedNodes = flattenTree(fileTree);
|
|
45962
45972
|
let allFilePaths = flattenedNodes.filter((node) => node.type === "file").map((node) => node.filePath);
|
|
45963
45973
|
if (cwd) {
|
|
@@ -45991,7 +46001,7 @@ async function glob(params2) {
|
|
|
45991
46001
|
// src/tools/list-directory.ts
|
|
45992
46002
|
var path17 = __toESM(require("path"));
|
|
45993
46003
|
async function listDirectory(params2) {
|
|
45994
|
-
const { directoryPath, projectPath, fs:
|
|
46004
|
+
const { directoryPath, projectPath, fs: fs14 } = params2;
|
|
45995
46005
|
try {
|
|
45996
46006
|
const resolvedPath = path17.resolve(projectPath, directoryPath);
|
|
45997
46007
|
if (!resolvedPath.startsWith(projectPath)) {
|
|
@@ -46004,7 +46014,7 @@ async function listDirectory(params2) {
|
|
|
46004
46014
|
}
|
|
46005
46015
|
];
|
|
46006
46016
|
}
|
|
46007
|
-
const entries = await
|
|
46017
|
+
const entries = await fs14.readdir(resolvedPath, {
|
|
46008
46018
|
withFileTypes: true
|
|
46009
46019
|
});
|
|
46010
46020
|
const files = [];
|
|
@@ -46043,7 +46053,7 @@ async function listDirectory(params2) {
|
|
|
46043
46053
|
var import_path11 = __toESM(require("path"));
|
|
46044
46054
|
init_old_constants();
|
|
46045
46055
|
async function getFiles(params2) {
|
|
46046
|
-
const { filePaths, cwd, fs:
|
|
46056
|
+
const { filePaths, cwd, fs: fs14, fileFilter } = params2;
|
|
46047
46057
|
const hasCustomFilter = fileFilter !== undefined;
|
|
46048
46058
|
const result = {};
|
|
46049
46059
|
const MAX_FILE_SIZE = 1024 * 1024;
|
|
@@ -46067,7 +46077,7 @@ async function getFiles(params2) {
|
|
|
46067
46077
|
const ignored = await isFileIgnored({
|
|
46068
46078
|
filePath: relativePath,
|
|
46069
46079
|
projectRoot: cwd,
|
|
46070
|
-
fs:
|
|
46080
|
+
fs: fs14
|
|
46071
46081
|
});
|
|
46072
46082
|
if (ignored) {
|
|
46073
46083
|
result[relativePath] = FILE_READ_STATUS.IGNORED;
|
|
@@ -46075,11 +46085,11 @@ async function getFiles(params2) {
|
|
|
46075
46085
|
}
|
|
46076
46086
|
}
|
|
46077
46087
|
try {
|
|
46078
|
-
const stats = await
|
|
46088
|
+
const stats = await fs14.stat(fullPath);
|
|
46079
46089
|
if (stats.size > MAX_FILE_SIZE) {
|
|
46080
46090
|
result[relativePath] = FILE_READ_STATUS.TOO_LARGE + ` [${(stats.size / (1024 * 1024)).toFixed(2)}MB]`;
|
|
46081
46091
|
} else {
|
|
46082
|
-
const content = await
|
|
46092
|
+
const content = await fs14.readFile(fullPath, "utf8");
|
|
46083
46093
|
result[relativePath] = isExampleFile ? FILE_READ_STATUS.TEMPLATE + `
|
|
46084
46094
|
` + content : content;
|
|
46085
46095
|
}
|
|
@@ -46096,7 +46106,7 @@ async function getFiles(params2) {
|
|
|
46096
46106
|
|
|
46097
46107
|
// src/tools/run-terminal-command.ts
|
|
46098
46108
|
var import_child_process2 = require("child_process");
|
|
46099
|
-
var
|
|
46109
|
+
var fs14 = __toESM(require("fs"));
|
|
46100
46110
|
var os7 = __toESM(require("os"));
|
|
46101
46111
|
var path19 = __toESM(require("path"));
|
|
46102
46112
|
var COMMAND_OUTPUT_LIMIT = 50000;
|
|
@@ -46111,11 +46121,11 @@ var WSL_BASH_PATH_PATTERNS = [
|
|
|
46111
46121
|
];
|
|
46112
46122
|
function findWindowsBash(env2) {
|
|
46113
46123
|
const customPath = env2.LEVELCODE_GIT_BASH_PATH;
|
|
46114
|
-
if (customPath &&
|
|
46124
|
+
if (customPath && fs14.existsSync(customPath)) {
|
|
46115
46125
|
return customPath;
|
|
46116
46126
|
}
|
|
46117
46127
|
for (const commonPath of GIT_BASH_COMMON_PATHS) {
|
|
46118
|
-
if (
|
|
46128
|
+
if (fs14.existsSync(commonPath)) {
|
|
46119
46129
|
return commonPath;
|
|
46120
46130
|
}
|
|
46121
46131
|
}
|
|
@@ -46126,7 +46136,7 @@ function findWindowsBash(env2) {
|
|
|
46126
46136
|
const dirLower = dir.toLowerCase();
|
|
46127
46137
|
const isWslPath = WSL_BASH_PATH_PATTERNS.some((pattern) => dirLower.includes(pattern));
|
|
46128
46138
|
const bashPath = path19.join(dir, "bash.exe");
|
|
46129
|
-
if (
|
|
46139
|
+
if (fs14.existsSync(bashPath)) {
|
|
46130
46140
|
if (isWslPath) {
|
|
46131
46141
|
wslFallbackPaths.push(bashPath);
|
|
46132
46142
|
} else {
|
|
@@ -46134,7 +46144,7 @@ function findWindowsBash(env2) {
|
|
|
46134
46144
|
}
|
|
46135
46145
|
}
|
|
46136
46146
|
const bashPathNoExt = path19.join(dir, "bash");
|
|
46137
|
-
if (
|
|
46147
|
+
if (fs14.existsSync(bashPathNoExt)) {
|
|
46138
46148
|
if (isWslPath) {
|
|
46139
46149
|
wslFallbackPaths.push(bashPathNoExt);
|
|
46140
46150
|
} else {
|
|
@@ -46173,7 +46183,7 @@ function runTerminalCommand({
|
|
|
46173
46183
|
if (process_type === "BACKGROUND") {
|
|
46174
46184
|
throw new Error("BACKGROUND process_type not implemented");
|
|
46175
46185
|
}
|
|
46176
|
-
return new Promise((
|
|
46186
|
+
return new Promise((resolve6, reject) => {
|
|
46177
46187
|
const isWindows = os7.platform() === "win32";
|
|
46178
46188
|
const processEnv2 = {
|
|
46179
46189
|
...getSystemProcessEnv(),
|
|
@@ -46244,7 +46254,7 @@ function runTerminalCommand({
|
|
|
46244
46254
|
...truncatedStderr ? { stderr: truncatedStderr } : {},
|
|
46245
46255
|
...exitCode !== null ? { exitCode } : {}
|
|
46246
46256
|
};
|
|
46247
|
-
|
|
46257
|
+
resolve6([{ type: "json", value: combinedOutput }]);
|
|
46248
46258
|
});
|
|
46249
46259
|
childProcess.on("error", (error) => {
|
|
46250
46260
|
if (processFinished)
|
|
@@ -46314,7 +46324,7 @@ async function runOnce({
|
|
|
46314
46324
|
costMode
|
|
46315
46325
|
}) {
|
|
46316
46326
|
const fsSourceValue = typeof fsSource === "function" ? fsSource() : fsSource;
|
|
46317
|
-
const
|
|
46327
|
+
const fs15 = await fsSourceValue;
|
|
46318
46328
|
let spawn4;
|
|
46319
46329
|
if (spawnSource) {
|
|
46320
46330
|
const spawnSourceValue = await spawnSource;
|
|
@@ -46348,15 +46358,15 @@ async function runOnce({
|
|
|
46348
46358
|
customToolDefinitions,
|
|
46349
46359
|
projectFiles,
|
|
46350
46360
|
maxAgentSteps,
|
|
46351
|
-
fs:
|
|
46361
|
+
fs: fs15,
|
|
46352
46362
|
spawn: spawn4,
|
|
46353
46363
|
logger: logger2
|
|
46354
46364
|
});
|
|
46355
46365
|
}
|
|
46356
|
-
let
|
|
46366
|
+
let resolve6 = () => {};
|
|
46357
46367
|
let _reject = () => {};
|
|
46358
46368
|
const promise = new Promise((res, rej) => {
|
|
46359
|
-
|
|
46369
|
+
resolve6 = res;
|
|
46360
46370
|
_reject = rej;
|
|
46361
46371
|
});
|
|
46362
46372
|
async function onError(error) {
|
|
@@ -46447,7 +46457,7 @@ async function runOnce({
|
|
|
46447
46457
|
overrides: overrideTools ?? {},
|
|
46448
46458
|
customToolDefinitions: customToolDefinitions ? Object.fromEntries(customToolDefinitions.map((def) => [def.toolName, def])) : {},
|
|
46449
46459
|
cwd,
|
|
46450
|
-
fs:
|
|
46460
|
+
fs: fs15,
|
|
46451
46461
|
env: env2
|
|
46452
46462
|
});
|
|
46453
46463
|
},
|
|
@@ -46473,7 +46483,7 @@ async function runOnce({
|
|
|
46473
46483
|
override: overrideTools?.read_files,
|
|
46474
46484
|
fileFilter,
|
|
46475
46485
|
cwd,
|
|
46476
|
-
fs:
|
|
46486
|
+
fs: fs15
|
|
46477
46487
|
}),
|
|
46478
46488
|
requestOptionalFile: async ({ filePath }) => {
|
|
46479
46489
|
const files = await readFiles({
|
|
@@ -46481,7 +46491,7 @@ async function runOnce({
|
|
|
46481
46491
|
override: overrideTools?.read_files,
|
|
46482
46492
|
fileFilter,
|
|
46483
46493
|
cwd,
|
|
46484
|
-
fs:
|
|
46494
|
+
fs: fs15
|
|
46485
46495
|
});
|
|
46486
46496
|
return toOptionalFile(files[filePath] ?? null);
|
|
46487
46497
|
},
|
|
@@ -46501,7 +46511,7 @@ async function runOnce({
|
|
|
46501
46511
|
if (action.type === "prompt-response") {
|
|
46502
46512
|
handlePromptResponse({
|
|
46503
46513
|
action,
|
|
46504
|
-
resolve:
|
|
46514
|
+
resolve: resolve6,
|
|
46505
46515
|
onError,
|
|
46506
46516
|
initialSessionState: sessionState,
|
|
46507
46517
|
signal,
|
|
@@ -46512,7 +46522,7 @@ async function runOnce({
|
|
|
46512
46522
|
if (action.type === "prompt-error") {
|
|
46513
46523
|
handlePromptResponse({
|
|
46514
46524
|
action,
|
|
46515
|
-
resolve:
|
|
46525
|
+
resolve: resolve6,
|
|
46516
46526
|
onError,
|
|
46517
46527
|
initialSessionState: sessionState,
|
|
46518
46528
|
signal,
|
|
@@ -46576,7 +46586,7 @@ async function runOnce({
|
|
|
46576
46586
|
}).catch((error) => {
|
|
46577
46587
|
const errorMessage = error instanceof Error ? error.message : String(error ?? "");
|
|
46578
46588
|
const statusCode = getErrorStatusCode(error);
|
|
46579
|
-
|
|
46589
|
+
resolve6({
|
|
46580
46590
|
sessionState: getCancelledSessionState(errorMessage),
|
|
46581
46591
|
output: {
|
|
46582
46592
|
type: "error",
|
|
@@ -46598,19 +46608,19 @@ async function readFiles({
|
|
|
46598
46608
|
override,
|
|
46599
46609
|
fileFilter,
|
|
46600
46610
|
cwd,
|
|
46601
|
-
fs:
|
|
46611
|
+
fs: fs15
|
|
46602
46612
|
}) {
|
|
46603
46613
|
if (override) {
|
|
46604
46614
|
return await override({ filePaths });
|
|
46605
46615
|
}
|
|
46606
|
-
return getFiles({ filePaths, cwd: requireCwd(cwd, "read_files"), fs:
|
|
46616
|
+
return getFiles({ filePaths, cwd: requireCwd(cwd, "read_files"), fs: fs15, fileFilter });
|
|
46607
46617
|
}
|
|
46608
46618
|
async function handleToolCall({
|
|
46609
46619
|
action,
|
|
46610
46620
|
overrides,
|
|
46611
46621
|
customToolDefinitions,
|
|
46612
46622
|
cwd,
|
|
46613
|
-
fs:
|
|
46623
|
+
fs: fs15,
|
|
46614
46624
|
env: env2
|
|
46615
46625
|
}) {
|
|
46616
46626
|
const toolName39 = action.toolName;
|
|
@@ -46661,7 +46671,7 @@ async function handleToolCall({
|
|
|
46661
46671
|
result = await changeFile({
|
|
46662
46672
|
parameters: input,
|
|
46663
46673
|
cwd: requireCwd(cwd, toolName39),
|
|
46664
|
-
fs:
|
|
46674
|
+
fs: fs15
|
|
46665
46675
|
});
|
|
46666
46676
|
} else if (toolName39 === "run_terminal_command") {
|
|
46667
46677
|
const resolvedCwd = requireCwd(cwd, "run_terminal_command");
|
|
@@ -46679,14 +46689,14 @@ async function handleToolCall({
|
|
|
46679
46689
|
result = await listDirectory({
|
|
46680
46690
|
directoryPath: input.path,
|
|
46681
46691
|
projectPath: requireCwd(cwd, "list_directory"),
|
|
46682
|
-
fs:
|
|
46692
|
+
fs: fs15
|
|
46683
46693
|
});
|
|
46684
46694
|
} else if (toolName39 === "glob") {
|
|
46685
46695
|
result = await glob({
|
|
46686
46696
|
pattern: input.pattern,
|
|
46687
46697
|
projectPath: requireCwd(cwd, "glob"),
|
|
46688
46698
|
cwd: input.cwd,
|
|
46689
|
-
fs:
|
|
46699
|
+
fs: fs15
|
|
46690
46700
|
});
|
|
46691
46701
|
} else if (toolName39 === "run_file_change_hooks") {
|
|
46692
46702
|
result = [
|
|
@@ -46772,7 +46782,7 @@ var extractStatusCodeFromMessage = (errorMessage) => {
|
|
|
46772
46782
|
};
|
|
46773
46783
|
async function handlePromptResponse({
|
|
46774
46784
|
action,
|
|
46775
|
-
resolve:
|
|
46785
|
+
resolve: resolve6,
|
|
46776
46786
|
onError,
|
|
46777
46787
|
initialSessionState: initialSessionState2,
|
|
46778
46788
|
signal,
|
|
@@ -46781,7 +46791,7 @@ async function handlePromptResponse({
|
|
|
46781
46791
|
if (action.type === "prompt-error") {
|
|
46782
46792
|
onError({ message: action.message });
|
|
46783
46793
|
const statusCode = extractStatusCodeFromMessage(action.message);
|
|
46784
|
-
|
|
46794
|
+
resolve6({
|
|
46785
46795
|
sessionState: initialSessionState2,
|
|
46786
46796
|
output: {
|
|
46787
46797
|
type: "error",
|
|
@@ -46799,7 +46809,7 @@ async function handlePromptResponse({
|
|
|
46799
46809
|
].join(`
|
|
46800
46810
|
`);
|
|
46801
46811
|
onError({ message });
|
|
46802
|
-
|
|
46812
|
+
resolve6({
|
|
46803
46813
|
sessionState: initialSessionState2,
|
|
46804
46814
|
output: {
|
|
46805
46815
|
type: "error",
|
|
@@ -46820,12 +46830,12 @@ async function handlePromptResponse({
|
|
|
46820
46830
|
message: "No output from agent"
|
|
46821
46831
|
}
|
|
46822
46832
|
};
|
|
46823
|
-
|
|
46833
|
+
resolve6(state);
|
|
46824
46834
|
} else {
|
|
46825
46835
|
onError({
|
|
46826
46836
|
message: "Internal error: prompt response type not handled"
|
|
46827
46837
|
});
|
|
46828
|
-
|
|
46838
|
+
resolve6({
|
|
46829
46839
|
sessionState: initialSessionState2,
|
|
46830
46840
|
output: {
|
|
46831
46841
|
type: "error",
|
|
@@ -47302,5 +47312,5 @@ function loadMCPConfigSync(options) {
|
|
|
47302
47312
|
return mergedConfig;
|
|
47303
47313
|
}
|
|
47304
47314
|
|
|
47305
|
-
//# debugId=
|
|
47315
|
+
//# debugId=4143A0BA06A1DD8864756E2164756E21
|
|
47306
47316
|
//# sourceMappingURL=index.cjs.map
|