@exulu/backend 5.14.0 → 5.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-QU67ANL5.js → chunk-2FDGX6WH.js} +2152 -1393
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-UT7TOLLD.js → convert-exulu-tools-to-ai-sdk-tools-UYF2OK7F.js} +1 -1
- package/dist/index.cjs +1990 -1146
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +41 -3
- package/ee/invoke-skills/artifact-filter.test.ts +42 -1
- package/ee/invoke-skills/artifact-filter.ts +37 -0
- package/ee/invoke-skills/create-sandbox.env.test.ts +7 -1
- package/ee/invoke-skills/create-sandbox.readonly-skills.sandbox.test.ts +221 -0
- package/ee/invoke-skills/create-sandbox.readonly-skills.test.ts +290 -0
- package/ee/invoke-skills/create-sandbox.run-command.test.ts +135 -0
- package/ee/invoke-skills/create-sandbox.skill-actions.test.ts +176 -0
- package/ee/invoke-skills/create-sandbox.ts +268 -88
- package/ee/invoke-skills/safe-fs.test.ts +59 -1
- package/ee/invoke-skills/safe-fs.ts +61 -2
- package/ee/invoke-skills/skill-actions/load.test.ts +88 -0
- package/ee/invoke-skills/skill-actions/load.ts +107 -0
- package/ee/invoke-skills/skill-actions/schema.test.ts +72 -0
- package/ee/invoke-skills/skill-actions/schema.ts +97 -0
- package/ee/invoke-skills/skill-actions/tool.test.ts +464 -0
- package/ee/invoke-skills/skill-actions/tool.ts +415 -0
- package/package.json +2 -1
|
@@ -599,7 +599,7 @@ var ExuluTool = class _ExuluTool {
|
|
|
599
599
|
name,
|
|
600
600
|
description,
|
|
601
601
|
category,
|
|
602
|
-
inputSchema,
|
|
602
|
+
inputSchema: inputSchema2,
|
|
603
603
|
type,
|
|
604
604
|
execute,
|
|
605
605
|
config,
|
|
@@ -628,11 +628,11 @@ var ExuluTool = class _ExuluTool {
|
|
|
628
628
|
this.category = category || "default";
|
|
629
629
|
this.name = name;
|
|
630
630
|
this.description = description;
|
|
631
|
-
this.inputSchema =
|
|
631
|
+
this.inputSchema = inputSchema2;
|
|
632
632
|
this.type = type;
|
|
633
633
|
this.tool = tool({
|
|
634
634
|
description,
|
|
635
|
-
inputSchema:
|
|
635
|
+
inputSchema: inputSchema2 || z.object({}),
|
|
636
636
|
execute: authentication2 ? wrapExecuteWithAuth(id, authentication2, execute) : execute
|
|
637
637
|
});
|
|
638
638
|
}
|
|
@@ -669,7 +669,7 @@ var ExuluTool = class _ExuluTool {
|
|
|
669
669
|
if (!agent) {
|
|
670
670
|
throw new Error("Agent not found.");
|
|
671
671
|
}
|
|
672
|
-
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-
|
|
672
|
+
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-UYF2OK7F.js");
|
|
673
673
|
const tools = await convertExuluToolsToAiSdkTools2(
|
|
674
674
|
[this],
|
|
675
675
|
[],
|
|
@@ -3945,7 +3945,7 @@ function sanitizeToolName(name) {
|
|
|
3945
3945
|
}
|
|
3946
3946
|
|
|
3947
3947
|
// src/templates/tools/convert-exulu-tools-to-ai-sdk-tools.ts
|
|
3948
|
-
import { randomUUID as
|
|
3948
|
+
import { randomUUID as randomUUID9 } from "crypto";
|
|
3949
3949
|
|
|
3950
3950
|
// types/enums/statistics.ts
|
|
3951
3951
|
var STATISTICS_TYPE_ENUM = {
|
|
@@ -4459,7 +4459,7 @@ var uploadFile = async (file, fileName, config, options = {}, user, customBucket
|
|
|
4459
4459
|
if (error.name === "SignatureDoesNotMatch" || error.name === "InvalidAccessKeyId" || error.name === "AccessDenied") {
|
|
4460
4460
|
if (attempt < maxRetries) {
|
|
4461
4461
|
const backoffMs = Math.pow(2, attempt) * 1e3;
|
|
4462
|
-
await new Promise((
|
|
4462
|
+
await new Promise((resolve5) => setTimeout(resolve5, backoffMs));
|
|
4463
4463
|
s3Client = void 0;
|
|
4464
4464
|
getS3Client(config);
|
|
4465
4465
|
continue;
|
|
@@ -6570,14 +6570,14 @@ function randomizedPCA(rows, dims, k, seed, iterations) {
|
|
|
6570
6570
|
for (const row of rows) {
|
|
6571
6571
|
const centered = new Float64Array(dims);
|
|
6572
6572
|
for (let d = 0; d < dims; d += 1) centered[d] = (row[d] ?? 0) - (mean[d] ?? 0);
|
|
6573
|
-
const
|
|
6573
|
+
const z24 = new Float64Array(basis.length);
|
|
6574
6574
|
for (const [b, vec] of basis.entries()) {
|
|
6575
6575
|
let dot = 0;
|
|
6576
6576
|
for (let d = 0; d < dims; d += 1) dot += (centered[d] ?? 0) * (vec[d] ?? 0);
|
|
6577
|
-
|
|
6577
|
+
z24[b] = dot;
|
|
6578
6578
|
}
|
|
6579
6579
|
for (const [b, target] of next.entries()) {
|
|
6580
|
-
const scale =
|
|
6580
|
+
const scale = z24[b] ?? 0;
|
|
6581
6581
|
if (scale === 0) continue;
|
|
6582
6582
|
for (let d = 0; d < dims; d += 1) target[d] = (target[d] ?? 0) + (centered[d] ?? 0) * scale;
|
|
6583
6583
|
}
|
|
@@ -6675,12 +6675,12 @@ function ridgeFit(Z, Y, lambda) {
|
|
|
6675
6675
|
});
|
|
6676
6676
|
return { map, intercept };
|
|
6677
6677
|
}
|
|
6678
|
-
function applyMap(
|
|
6678
|
+
function applyMap(z24, map, intercept) {
|
|
6679
6679
|
const out = [];
|
|
6680
6680
|
for (let j = 0; j < 3; j += 1) {
|
|
6681
6681
|
let v = intercept[j] ?? 0;
|
|
6682
6682
|
const row = map[j] ?? [];
|
|
6683
|
-
for (let d = 0; d < row.length; d += 1) v += (row[d] ?? 0) * (
|
|
6683
|
+
for (let d = 0; d < row.length; d += 1) v += (row[d] ?? 0) * (z24[d] ?? 0);
|
|
6684
6684
|
out.push(Number.isFinite(v) ? v : 0);
|
|
6685
6685
|
}
|
|
6686
6686
|
return [out[0] ?? 0, out[1] ?? 0, out[2] ?? 0];
|
|
@@ -6703,8 +6703,8 @@ function fitResidual(Z, Y, map, intercept) {
|
|
|
6703
6703
|
for (let i = 0; i < Z.length; i += 1) {
|
|
6704
6704
|
const zi = Z[i] ?? [];
|
|
6705
6705
|
const yi = Y[i] ?? [];
|
|
6706
|
-
const [x, y,
|
|
6707
|
-
total += Math.hypot(x - finite(yi[0]), y - finite(yi[1]),
|
|
6706
|
+
const [x, y, z24] = applyMap(zi, map, intercept);
|
|
6707
|
+
total += Math.hypot(x - finite(yi[0]), y - finite(yi[1]), z24 - finite(yi[2]));
|
|
6708
6708
|
}
|
|
6709
6709
|
return finite(total / Z.length);
|
|
6710
6710
|
}
|
|
@@ -6844,8 +6844,8 @@ async function chunkCoordinates({
|
|
|
6844
6844
|
}
|
|
6845
6845
|
return null;
|
|
6846
6846
|
}
|
|
6847
|
-
const [x, y,
|
|
6848
|
-
return { x, y, z:
|
|
6847
|
+
const [x, y, z24] = applyMap(projectComponents(l2normalize(v), mean, basis), projection.map, projection.intercept);
|
|
6848
|
+
return { x, y, z: z24 };
|
|
6849
6849
|
});
|
|
6850
6850
|
} catch (e) {
|
|
6851
6851
|
console.error("[EXULU] could not compute chunk coordinates", e instanceof Error ? e.message : String(e));
|
|
@@ -6931,8 +6931,8 @@ var captureCodeEmbedder = (context) => {
|
|
|
6931
6931
|
};
|
|
6932
6932
|
var codeEmbedderFor = (context) => codeEmbedders.has(context) ? codeEmbedders.get(context) : context.embedder;
|
|
6933
6933
|
var contextEmbedderInfoFor = async (context, deps = {}) => {
|
|
6934
|
-
const
|
|
6935
|
-
return
|
|
6934
|
+
const resolve5 = deps.resolve ?? resolveContextEmbedder;
|
|
6935
|
+
return resolve5({ id: context.id, embedder: codeEmbedderFor(context) });
|
|
6936
6936
|
};
|
|
6937
6937
|
var willEmbedOnQueue = async (context, overrideQueue) => {
|
|
6938
6938
|
if (overrideQueue) {
|
|
@@ -6941,11 +6941,11 @@ var willEmbedOnQueue = async (context, overrideQueue) => {
|
|
|
6941
6941
|
return Boolean(await codeEmbedderFor(context)?.queue);
|
|
6942
6942
|
};
|
|
6943
6943
|
var hydrateContextEmbedders = async (contexts, deps = {}) => {
|
|
6944
|
-
const { resolve:
|
|
6944
|
+
const { resolve: resolve5, modelInfo, queues } = { ...defaultDeps(), ...deps };
|
|
6945
6945
|
for (const context of contexts) {
|
|
6946
6946
|
try {
|
|
6947
6947
|
const codeEmbedder = captureCodeEmbedder(context);
|
|
6948
|
-
const info = await
|
|
6948
|
+
const info = await resolve5({ id: context.id, embedder: codeEmbedder });
|
|
6949
6949
|
if (info.source !== "database" || !info.databaseModel) {
|
|
6950
6950
|
context.embedder = codeEmbedder;
|
|
6951
6951
|
continue;
|
|
@@ -10344,6 +10344,14 @@ var agentsSchema = {
|
|
|
10344
10344
|
name: "welcomemessage",
|
|
10345
10345
|
type: "text"
|
|
10346
10346
|
},
|
|
10347
|
+
{
|
|
10348
|
+
// The welcome message in further languages: { "<locale>": "<text>" },
|
|
10349
|
+
// e.g. { "de": "Hallo …" }. `welcomemessage` stays the default (English,
|
|
10350
|
+
// and any language without an entry). Read through welcomeTranslations()
|
|
10351
|
+
// in public-agents.ts. Auto-ALTERed on boot.
|
|
10352
|
+
name: "welcomemessage_translations",
|
|
10353
|
+
type: "json"
|
|
10354
|
+
},
|
|
10347
10355
|
{
|
|
10348
10356
|
name: "instructions",
|
|
10349
10357
|
type: "text"
|
|
@@ -12139,10 +12147,10 @@ var projectRow = (record, fields, explicit) => {
|
|
|
12139
12147
|
}
|
|
12140
12148
|
return out;
|
|
12141
12149
|
};
|
|
12142
|
-
var clampLimit = (raw) => {
|
|
12150
|
+
var clampLimit = (raw, max = FIND_MAX_LIMIT) => {
|
|
12143
12151
|
const asNumber = typeof raw === "number" || typeof raw === "string" && raw.trim() !== "" ? Math.floor(Number(raw)) : Number.NaN;
|
|
12144
12152
|
if (!Number.isFinite(asNumber) || asNumber <= 0) return FIND_DEFAULT_LIMIT;
|
|
12145
|
-
return Math.min(asNumber,
|
|
12153
|
+
return Math.min(asNumber, max);
|
|
12146
12154
|
};
|
|
12147
12155
|
var validateWhere = (filterable, where, contextName) => {
|
|
12148
12156
|
const names = new Set(filterable.map((f) => f.name));
|
|
@@ -12241,14 +12249,102 @@ var checkItemReadAccess = async (context, record, user) => {
|
|
|
12241
12249
|
const grant = await db.from("rbac").where({ entity, target_resource_id: record.id, access_type: "Team", team_id: teamId }).first();
|
|
12242
12250
|
return !!grant;
|
|
12243
12251
|
};
|
|
12252
|
+
var readContextItem = async (context, args, caller, deps = {}) => {
|
|
12253
|
+
const { user } = caller;
|
|
12254
|
+
const NOT_FOUND = itemNotFoundMessage(context, "read");
|
|
12255
|
+
const checkAccess = deps.checkAccess ?? checkItemReadAccess;
|
|
12256
|
+
const readable = readableContextFields(context);
|
|
12257
|
+
if (treatAsGuest(caller.req, user)) {
|
|
12258
|
+
return { ok: false, message: NOT_FOUND };
|
|
12259
|
+
}
|
|
12260
|
+
if (!args.id && !args.external_id) {
|
|
12261
|
+
return { ok: false, message: "Provide the id or external_id of the item to read." };
|
|
12262
|
+
}
|
|
12263
|
+
const selection = resolveFields(readable, args.fields, context.name);
|
|
12264
|
+
if ("error" in selection) {
|
|
12265
|
+
return { ok: false, message: selection.error };
|
|
12266
|
+
}
|
|
12267
|
+
try {
|
|
12268
|
+
const record = await context.getItem({
|
|
12269
|
+
item: { id: args.id, external_id: args.external_id }
|
|
12270
|
+
});
|
|
12271
|
+
if (!record?.id) {
|
|
12272
|
+
return { ok: false, message: NOT_FOUND };
|
|
12273
|
+
}
|
|
12274
|
+
if (!await checkAccess(context, record, user)) {
|
|
12275
|
+
return { ok: false, message: NOT_FOUND };
|
|
12276
|
+
}
|
|
12277
|
+
const explicit = Array.isArray(args.fields) && args.fields.length > 0;
|
|
12278
|
+
return { ok: true, item: projectRow(record, selection.fields, explicit) };
|
|
12279
|
+
} catch (error) {
|
|
12280
|
+
console.error(`[EXULU] Error reading item in context ${context.id}`, error);
|
|
12281
|
+
return {
|
|
12282
|
+
ok: false,
|
|
12283
|
+
message: `Failed to read the item in "${context.name}": ${error instanceof Error ? error.message : String(error)}`
|
|
12284
|
+
};
|
|
12285
|
+
}
|
|
12286
|
+
};
|
|
12287
|
+
var runFind = async (context, args, caller, probeTruncation) => {
|
|
12288
|
+
const { user } = caller;
|
|
12289
|
+
const readable = readableContextFields(context);
|
|
12290
|
+
const filterable = readable.filter((field) => !field.isFile);
|
|
12291
|
+
const findDefaults = readable.filter((field) => field.findDefault);
|
|
12292
|
+
const limit = clampLimit(args.limit, args.maxLimit ?? FIND_MAX_LIMIT);
|
|
12293
|
+
if (treatAsGuest(caller.req, user)) {
|
|
12294
|
+
return { ok: true, items: [], limit, truncated: false };
|
|
12295
|
+
}
|
|
12296
|
+
const requested = Array.isArray(args.fields) && args.fields.length > 0 ? args.fields : void 0;
|
|
12297
|
+
const selection = resolveFields(requested ? readable : findDefaults, requested, context.name);
|
|
12298
|
+
if ("error" in selection) {
|
|
12299
|
+
return { ok: false, message: selection.error };
|
|
12300
|
+
}
|
|
12301
|
+
const where = args.where && typeof args.where === "object" && !Array.isArray(args.where) ? args.where : void 0;
|
|
12302
|
+
if (where && Object.keys(where).length > 0) {
|
|
12303
|
+
const whereError = validateWhere(filterable, where, context.name);
|
|
12304
|
+
if (whereError) {
|
|
12305
|
+
return { ok: false, message: whereError };
|
|
12306
|
+
}
|
|
12307
|
+
}
|
|
12308
|
+
try {
|
|
12309
|
+
const rows = await context.getItems({
|
|
12310
|
+
filters: where && Object.keys(where).length > 0 ? [whereByColumn(filterable, where)] : [],
|
|
12311
|
+
fields: selectList(selection.fields),
|
|
12312
|
+
user,
|
|
12313
|
+
// A user's role can be the bare id string as well as an object;
|
|
12314
|
+
// `user.role?.id` on a string silently yields undefined, which knex
|
|
12315
|
+
// then refuses as an undefined binding (fix round 1, F3).
|
|
12316
|
+
role: typeof user.role === "string" ? user.role : user.role?.id,
|
|
12317
|
+
// One extra row tells "exactly limit match" from "more match".
|
|
12318
|
+
limit: probeTruncation ? limit + 1 : limit
|
|
12319
|
+
});
|
|
12320
|
+
const truncated = probeTruncation && rows.length > limit;
|
|
12321
|
+
return { ok: true, items: truncated ? rows.slice(0, limit) : rows, limit, truncated };
|
|
12322
|
+
} catch (error) {
|
|
12323
|
+
if (error instanceof UnknownFilterPathError) {
|
|
12324
|
+
console.warn(
|
|
12325
|
+
`[EXULU] find_${contextToolSegment(context)}_items refused an unknown json filter path:`,
|
|
12326
|
+
error.message
|
|
12327
|
+
);
|
|
12328
|
+
const field = filterable.find((candidate) => candidate.column === error.field);
|
|
12329
|
+
return {
|
|
12330
|
+
ok: false,
|
|
12331
|
+
message: field && field.name !== error.field ? new UnknownFilterPathError(field.name, error.offendingPaths, error.validPaths).message : error.message
|
|
12332
|
+
};
|
|
12333
|
+
}
|
|
12334
|
+
console.error(`[EXULU] Error finding items in context ${context.id}`, error);
|
|
12335
|
+
return {
|
|
12336
|
+
ok: false,
|
|
12337
|
+
message: `Failed to find items in "${context.name}": ${error instanceof Error ? error.message : String(error)}`
|
|
12338
|
+
};
|
|
12339
|
+
}
|
|
12340
|
+
};
|
|
12341
|
+
var findContextItems = (context, args, caller) => runFind(context, args, caller, true);
|
|
12244
12342
|
var createContextReadTools = (context, deps = {}) => {
|
|
12245
12343
|
const segment = contextToolSegment(context);
|
|
12246
12344
|
const contextLabel = context.description ? ` ${context.description}` : "";
|
|
12247
12345
|
const readable = readableContextFields(context);
|
|
12248
12346
|
const filterable = readable.filter((field) => !field.isFile);
|
|
12249
12347
|
const findDefaults = readable.filter((field) => field.findDefault);
|
|
12250
|
-
const NOT_FOUND = itemNotFoundMessage(context, "read");
|
|
12251
|
-
const checkAccess = deps.checkAccess ?? checkItemReadAccess;
|
|
12252
12348
|
const fieldsInput = (defaults) => z12.array(z12.string()).optional().describe(
|
|
12253
12349
|
`Which fields to return \u2014 "id" is always returned whether you name it or not. Omitted, ${defaults}. Available: ${nameList(readable)}.`
|
|
12254
12350
|
);
|
|
@@ -12266,37 +12362,13 @@ var createContextReadTools = (context, deps = {}) => {
|
|
|
12266
12362
|
config: [],
|
|
12267
12363
|
needsApproval: false,
|
|
12268
12364
|
execute: async (params) => {
|
|
12269
|
-
const
|
|
12270
|
-
|
|
12271
|
-
|
|
12272
|
-
|
|
12273
|
-
|
|
12274
|
-
|
|
12275
|
-
}
|
|
12276
|
-
const selection = resolveFields(readable, params.fields, context.name);
|
|
12277
|
-
if ("error" in selection) {
|
|
12278
|
-
return { result: selection.error };
|
|
12279
|
-
}
|
|
12280
|
-
try {
|
|
12281
|
-
const record = await context.getItem({
|
|
12282
|
-
item: { id: params.id, external_id: params.external_id }
|
|
12283
|
-
});
|
|
12284
|
-
if (!record?.id) {
|
|
12285
|
-
return { result: NOT_FOUND };
|
|
12286
|
-
}
|
|
12287
|
-
if (!await checkAccess(context, record, user)) {
|
|
12288
|
-
return { result: NOT_FOUND };
|
|
12289
|
-
}
|
|
12290
|
-
const explicit = Array.isArray(params.fields) && params.fields.length > 0;
|
|
12291
|
-
return {
|
|
12292
|
-
result: `Item: ${JSON.stringify(projectRow(record, selection.fields, explicit))}`
|
|
12293
|
-
};
|
|
12294
|
-
} catch (error) {
|
|
12295
|
-
console.error(`[EXULU] Error reading item in context ${context.id}`, error);
|
|
12296
|
-
return {
|
|
12297
|
-
result: `Failed to read the item in "${context.name}": ${error instanceof Error ? error.message : String(error)}`
|
|
12298
|
-
};
|
|
12299
|
-
}
|
|
12365
|
+
const outcome = await readContextItem(
|
|
12366
|
+
context,
|
|
12367
|
+
{ id: params.id, external_id: params.external_id, fields: params.fields },
|
|
12368
|
+
{ user: params.user, req: params.req },
|
|
12369
|
+
deps
|
|
12370
|
+
);
|
|
12371
|
+
return { result: outcome.ok ? `Item: ${JSON.stringify(outcome.item)}` : outcome.message };
|
|
12300
12372
|
}
|
|
12301
12373
|
});
|
|
12302
12374
|
const findTool = new ExuluTool({
|
|
@@ -12317,48 +12389,14 @@ var createContextReadTools = (context, deps = {}) => {
|
|
|
12317
12389
|
config: [],
|
|
12318
12390
|
needsApproval: false,
|
|
12319
12391
|
execute: async (params) => {
|
|
12320
|
-
const
|
|
12321
|
-
|
|
12322
|
-
|
|
12323
|
-
|
|
12324
|
-
|
|
12325
|
-
|
|
12326
|
-
|
|
12327
|
-
|
|
12328
|
-
return { result: selection.error };
|
|
12329
|
-
}
|
|
12330
|
-
const where = params.where && typeof params.where === "object" && !Array.isArray(params.where) ? params.where : void 0;
|
|
12331
|
-
if (where && Object.keys(where).length > 0) {
|
|
12332
|
-
const whereError = validateWhere(filterable, where, context.name);
|
|
12333
|
-
if (whereError) {
|
|
12334
|
-
return { result: whereError };
|
|
12335
|
-
}
|
|
12336
|
-
}
|
|
12337
|
-
try {
|
|
12338
|
-
const items = await context.getItems({
|
|
12339
|
-
filters: where && Object.keys(where).length > 0 ? [whereByColumn(filterable, where)] : [],
|
|
12340
|
-
fields: selectList(selection.fields),
|
|
12341
|
-
user,
|
|
12342
|
-
// A user's role can be the bare id string as well as an object;
|
|
12343
|
-
// `user.role?.id` on a string silently yields undefined, which knex
|
|
12344
|
-
// then refuses as an undefined binding (fix round 1, F3).
|
|
12345
|
-
role: typeof user.role === "string" ? user.role : user.role?.id,
|
|
12346
|
-
limit
|
|
12347
|
-
});
|
|
12348
|
-
return { result: `Found ${items.length} item(s): ${JSON.stringify(items)}` };
|
|
12349
|
-
} catch (error) {
|
|
12350
|
-
if (error instanceof UnknownFilterPathError) {
|
|
12351
|
-
console.warn(`[EXULU] ${findTool.id} refused an unknown json filter path:`, error.message);
|
|
12352
|
-
const field = filterable.find((candidate) => candidate.column === error.field);
|
|
12353
|
-
return {
|
|
12354
|
-
result: field && field.name !== error.field ? new UnknownFilterPathError(field.name, error.offendingPaths, error.validPaths).message : error.message
|
|
12355
|
-
};
|
|
12356
|
-
}
|
|
12357
|
-
console.error(`[EXULU] Error finding items in context ${context.id}`, error);
|
|
12358
|
-
return {
|
|
12359
|
-
result: `Failed to find items in "${context.name}": ${error instanceof Error ? error.message : String(error)}`
|
|
12360
|
-
};
|
|
12361
|
-
}
|
|
12392
|
+
const outcome = await runFind(
|
|
12393
|
+
context,
|
|
12394
|
+
{ where: params.where, limit: params.limit, fields: params.fields },
|
|
12395
|
+
{ user: params.user, req: params.req },
|
|
12396
|
+
false
|
|
12397
|
+
);
|
|
12398
|
+
if (!outcome.ok) return { result: outcome.message };
|
|
12399
|
+
return { result: `Found ${outcome.items.length} item(s): ${JSON.stringify(outcome.items)}` };
|
|
12362
12400
|
}
|
|
12363
12401
|
});
|
|
12364
12402
|
return [getTool, findTool];
|
|
@@ -12770,6 +12808,7 @@ var RBACResolver = async (db, entityName, resourceId, rights_mode) => {
|
|
|
12770
12808
|
};
|
|
12771
12809
|
|
|
12772
12810
|
// ee/invoke-skills/artifact-filter.ts
|
|
12811
|
+
var ACTION_INPUTS_DIR = ".exulu-inputs";
|
|
12773
12812
|
var IGNORED_SEGMENTS = /* @__PURE__ */ new Set([
|
|
12774
12813
|
"venv",
|
|
12775
12814
|
".venv",
|
|
@@ -12782,11 +12821,16 @@ var IGNORED_SEGMENTS = /* @__PURE__ */ new Set([
|
|
|
12782
12821
|
".git",
|
|
12783
12822
|
".pytest_cache",
|
|
12784
12823
|
".mypy_cache",
|
|
12785
|
-
".ipynb_checkpoints"
|
|
12824
|
+
".ipynb_checkpoints",
|
|
12825
|
+
// Input files the platform writes for a skill action run; never session artifacts.
|
|
12826
|
+
ACTION_INPUTS_DIR
|
|
12786
12827
|
]);
|
|
12787
12828
|
function isIgnoredArtifactPath(relativePath) {
|
|
12788
12829
|
return relativePath.split(/[\\/]+/).some((segment) => IGNORED_SEGMENTS.has(segment));
|
|
12789
12830
|
}
|
|
12831
|
+
function isActionInputsPath(relativePath) {
|
|
12832
|
+
return relativePath.split(/[\\/]+/).some((segment) => segment === ACTION_INPUTS_DIR);
|
|
12833
|
+
}
|
|
12790
12834
|
var DEFAULT_ARTIFACT_CAP = 50;
|
|
12791
12835
|
function capArtifacts(artifacts, max = DEFAULT_ARTIFACT_CAP) {
|
|
12792
12836
|
if (artifacts.length <= max) return { kept: artifacts, omitted: 0 };
|
|
@@ -12795,6 +12839,21 @@ function capArtifacts(artifacts, max = DEFAULT_ARTIFACT_CAP) {
|
|
|
12795
12839
|
function needsDownload(localSize, remoteSize) {
|
|
12796
12840
|
return localSize === void 0 || localSize !== remoteSize;
|
|
12797
12841
|
}
|
|
12842
|
+
var ARTIFACTS_BLOCK_HEADER = "[exulu-artifacts]";
|
|
12843
|
+
var ARTIFACTS_BLOCK_SEPARATOR = `
|
|
12844
|
+
|
|
12845
|
+
${ARTIFACTS_BLOCK_HEADER}
|
|
12846
|
+
`;
|
|
12847
|
+
function appendArtifactsBlock(stdout, entryLines) {
|
|
12848
|
+
if (entryLines.length === 0) return stdout;
|
|
12849
|
+
return `${stdout}${ARTIFACTS_BLOCK_SEPARATOR}${entryLines.join("\n")}`;
|
|
12850
|
+
}
|
|
12851
|
+
function splitArtifactsBlock(stdout, hasBlock) {
|
|
12852
|
+
if (!hasBlock) return { output: stdout, block: "" };
|
|
12853
|
+
const at = stdout.lastIndexOf(ARTIFACTS_BLOCK_SEPARATOR);
|
|
12854
|
+
if (at < 0) return { output: stdout, block: "" };
|
|
12855
|
+
return { output: stdout.slice(0, at), block: stdout.slice(at) };
|
|
12856
|
+
}
|
|
12798
12857
|
|
|
12799
12858
|
// src/exulu/shared-artifacts.ts
|
|
12800
12859
|
import bcrypt2 from "bcryptjs";
|
|
@@ -13933,16 +13992,42 @@ var createSaveToProjectTool = ({
|
|
|
13933
13992
|
|
|
13934
13993
|
// src/templates/tools/skill-author-tools.ts
|
|
13935
13994
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
13936
|
-
import { z as
|
|
13995
|
+
import { z as z17 } from "zod";
|
|
13937
13996
|
|
|
13938
13997
|
// src/skills/skill-access.ts
|
|
13939
13998
|
async function resolveSkillByName(db, name) {
|
|
13940
13999
|
const row = await db("skills").where({ name }).first();
|
|
13941
14000
|
return row ?? null;
|
|
13942
14001
|
}
|
|
14002
|
+
async function canWritePublicSkill(db, skill, user) {
|
|
14003
|
+
if (!user) return false;
|
|
14004
|
+
if (user.super_admin === true) return true;
|
|
14005
|
+
if (user.type === "api" && (!user.scope_mode || user.scope_mode === "admin")) return true;
|
|
14006
|
+
if (sameEntityId(skill.created_by, user.id)) return true;
|
|
14007
|
+
const rbac = await RBACResolver(db, "skill", skill.id, "public");
|
|
14008
|
+
const granted = (list, subject) => subject != null && (list ?? []).some((g) => sameEntityId(g.id, subject) && g.rights === "write");
|
|
14009
|
+
const role = user.role;
|
|
14010
|
+
const team = user.team;
|
|
14011
|
+
return granted(rbac.users, user.id) || granted(rbac.roles, role?.id ?? role) || granted(rbac.teams, team?.id ?? team);
|
|
14012
|
+
}
|
|
13943
14013
|
async function canAccessSkill(db, skill, action, user) {
|
|
14014
|
+
if (action === "write" && skill.rights_mode === "public") {
|
|
14015
|
+
return canWritePublicSkill(db, skill, user);
|
|
14016
|
+
}
|
|
13944
14017
|
const rbac = await RBACResolver(db, "skill", skill.id, skill.rights_mode || "private");
|
|
13945
|
-
|
|
14018
|
+
const allowed = await checkRecordAccess({ ...skill, RBAC: rbac }, action, user);
|
|
14019
|
+
if (allowed || action === "write") return allowed;
|
|
14020
|
+
return canAccessSkill(db, skill, "write", user);
|
|
14021
|
+
}
|
|
14022
|
+
async function ensureSkillWrite(db, skill, user, res) {
|
|
14023
|
+
if (await canAccessSkill(db, skill, "write", user)) return true;
|
|
14024
|
+
res.status(403).json({ detail: "You don't have write access to this skill." });
|
|
14025
|
+
return false;
|
|
14026
|
+
}
|
|
14027
|
+
async function ensureSkillRead(db, skill, user, res) {
|
|
14028
|
+
if (await canAccessSkill(db, skill, "read", user)) return true;
|
|
14029
|
+
res.status(404).json({ detail: "Skill not found." });
|
|
14030
|
+
return false;
|
|
13946
14031
|
}
|
|
13947
14032
|
async function filterReadableSkills(db, skills, user) {
|
|
13948
14033
|
const out = [];
|
|
@@ -13995,6 +14080,169 @@ async function parseSkillFrontmatter(zipBytes) {
|
|
|
13995
14080
|
return { name: fm.name, description: fm.description };
|
|
13996
14081
|
}
|
|
13997
14082
|
|
|
14083
|
+
// src/skills/authoring-limits.ts
|
|
14084
|
+
var MAX_FILES = 100;
|
|
14085
|
+
var MAX_FILE_BYTES = 200 * 1024;
|
|
14086
|
+
|
|
14087
|
+
// ee/invoke-skills/skill-actions/schema.ts
|
|
14088
|
+
import { parse as parse2 } from "yaml";
|
|
14089
|
+
import { z as z16 } from "zod";
|
|
14090
|
+
var ACTIONS_FILE = "actions.yaml";
|
|
14091
|
+
var ACTIONS_MAX_BYTES = 64 * 1024;
|
|
14092
|
+
var MAX_ACTIONS = 20;
|
|
14093
|
+
var NAME = /^[a-z][a-z0-9_]{0,39}$/;
|
|
14094
|
+
var nameMessage = "must match ^[a-z][a-z0-9_]{0,39}$";
|
|
14095
|
+
var inputSchema = z16.discriminatedUnion("type", [
|
|
14096
|
+
z16.strictObject({
|
|
14097
|
+
type: z16.literal("item"),
|
|
14098
|
+
context: z16.string().min(1),
|
|
14099
|
+
fields: z16.array(z16.string()).optional(),
|
|
14100
|
+
description: z16.string().optional()
|
|
14101
|
+
}),
|
|
14102
|
+
z16.strictObject({
|
|
14103
|
+
type: z16.literal("items"),
|
|
14104
|
+
context: z16.string().min(1),
|
|
14105
|
+
fields: z16.array(z16.string()).optional(),
|
|
14106
|
+
where: z16.record(z16.string(), z16.unknown()).optional(),
|
|
14107
|
+
description: z16.string().optional()
|
|
14108
|
+
}),
|
|
14109
|
+
z16.strictObject({
|
|
14110
|
+
type: z16.literal("text"),
|
|
14111
|
+
required: z16.boolean().default(true),
|
|
14112
|
+
description: z16.string().optional()
|
|
14113
|
+
})
|
|
14114
|
+
]);
|
|
14115
|
+
var actionSchema = z16.strictObject({
|
|
14116
|
+
description: z16.string().min(1),
|
|
14117
|
+
run: z16.string().min(1),
|
|
14118
|
+
timeout_seconds: z16.number().int().min(1).max(300).default(60),
|
|
14119
|
+
inputs: z16.record(z16.string().regex(NAME, nameMessage), inputSchema).default({})
|
|
14120
|
+
}).transform(({ timeout_seconds, ...rest }) => ({
|
|
14121
|
+
description: rest.description,
|
|
14122
|
+
run: rest.run,
|
|
14123
|
+
timeoutSeconds: timeout_seconds,
|
|
14124
|
+
inputs: rest.inputs
|
|
14125
|
+
}));
|
|
14126
|
+
var fileSchema = z16.strictObject({
|
|
14127
|
+
version: z16.literal(1),
|
|
14128
|
+
actions: z16.record(z16.string().regex(NAME, nameMessage), actionSchema).refine((a) => Object.keys(a).length <= MAX_ACTIONS, {
|
|
14129
|
+
message: `at most ${MAX_ACTIONS} actions per skill`
|
|
14130
|
+
})
|
|
14131
|
+
});
|
|
14132
|
+
var parseActionsYaml = (text) => {
|
|
14133
|
+
try {
|
|
14134
|
+
if (Buffer.byteLength(text, "utf8") > ACTIONS_MAX_BYTES) {
|
|
14135
|
+
return { ok: false, error: `${ACTIONS_FILE} exceeds ${ACTIONS_MAX_BYTES} bytes` };
|
|
14136
|
+
}
|
|
14137
|
+
let raw;
|
|
14138
|
+
try {
|
|
14139
|
+
raw = parse2(text);
|
|
14140
|
+
} catch (e) {
|
|
14141
|
+
return { ok: false, error: `invalid YAML: ${e?.message ?? String(e)}` };
|
|
14142
|
+
}
|
|
14143
|
+
const result = fileSchema.safeParse(raw);
|
|
14144
|
+
if (!result.success) {
|
|
14145
|
+
const issue = result.error.issues[0];
|
|
14146
|
+
const path3 = issue?.path.length ? issue.path.join(".") : "(root)";
|
|
14147
|
+
return { ok: false, error: `${path3}: ${issue?.message ?? "invalid"}` };
|
|
14148
|
+
}
|
|
14149
|
+
return { ok: true, actions: result.data.actions };
|
|
14150
|
+
} catch (e) {
|
|
14151
|
+
return { ok: false, error: e?.message ?? String(e) };
|
|
14152
|
+
}
|
|
14153
|
+
};
|
|
14154
|
+
|
|
14155
|
+
// src/skills/authoring-guide.ts
|
|
14156
|
+
var ACTIONS_EDIT_NO_EFFECT = "Editing, replacing or deleting `skills/<name>/" + ACTIONS_FILE + "` inside a running session has no effect on which actions exist or what they read.";
|
|
14157
|
+
var SKILL_FOLDER_READ_ONLY = "The skill's own folder `skills/<name>/` is read-only in a session: nothing run in the sandbox can create, change, delete or rename files there, so a script writes its output to the working directory (the session directory). A skill changes only when a new version is saved; the session picks it up on the next turn or a reload of the skills.";
|
|
14158
|
+
var SKILL_FOLDER_READ_ONLY_DEGRADED = "On a host where the platform runs commands without a kernel sandbox (degraded mode), only the writeFile tool refuses that folder; shell commands and actions are not confined there.";
|
|
14159
|
+
var SKILL_AUTHORING_GUIDE = `# Writing skills for this platform
|
|
14160
|
+
|
|
14161
|
+
A skill is a folder of files. The format is the standard Agent Skills format and stays portable; this guide covers only what differs here.
|
|
14162
|
+
|
|
14163
|
+
## 1. What stays standard
|
|
14164
|
+
- \`SKILL.md\` starts with front matter that carries only \`name\` and \`description\`. Put no platform-specific keys there.
|
|
14165
|
+
- Instructions, reference files and scripts are ordinary files in the folder.
|
|
14166
|
+
|
|
14167
|
+
## 2. Where scripts run
|
|
14168
|
+
- In the session sandbox, in the same working directory as the chat's other files (the session directory). The skill's own files are in \`skills/<name>/\` below it, so address scripts as \`skills/<name>/scripts/x.py\`.
|
|
14169
|
+
- ${SKILL_FOLDER_READ_ONLY} ${SKILL_FOLDER_READ_ONLY_DEGRADED}
|
|
14170
|
+
- The sandbox is configured to allow no network access. Do not write scripts that download or call anything.
|
|
14171
|
+
- Environment: the backend's declared secrets are removed from the environment and variables an administrator has explicitly granted to skills are added under their own name (skipped if the name is not a plain POSIX name or collides with an existing variable). The rest of the process environment passes through, so do not rely on any other variable being present or absent. Never hard-code credentials; tell the user which variable the skill expects.
|
|
14172
|
+
- Interpreters: \`python3\` resolves to the platform's Python virtual environment when one is available; when npm is found, globally installed npm packages can be \`require()\`d from CommonJS scripts (\`NODE_PATH\` is set; ES \`import\` ignores it). Do not assume any particular package: check with a quick import or \`npm ls -g\`, and say in SKILL.md what the skill needs.
|
|
14173
|
+
|
|
14174
|
+
## 3. Files a script creates
|
|
14175
|
+
- When the session has a user and file uploads are configured, new or changed files under the session directory (not under \`skills/\`) are uploaded, and the command output ends with an \`${ARTIFACTS_BLOCK_HEADER}\` block listing each as \`path: URL\`.
|
|
14176
|
+
- Give the user exactly that URL. Never link a relative path or invent one.
|
|
14177
|
+
- At most 50 files are listed per command. Dependency and cache directories (e.g. \`venv\`, \`node_modules\`, \`__pycache__\`, \`.cache\`, \`.git\`) are not listed; do not install packages into the session directory. Never write output into \`$EXULU_INPUTS_DIR\`: it is deleted after the run and never uploaded.
|
|
14178
|
+
|
|
14179
|
+
## 4. Platform data
|
|
14180
|
+
- A script cannot fetch knowledge-base data itself (no network, no credentials). Never copy item data into a file by retyping it; it gets corrupted and truncated.
|
|
14181
|
+
- A small lookup: the agent uses the read tools \`get_<context>_item\` and \`find_<context>_items\` directly and reasons over the result.
|
|
14182
|
+
- Anything a script must process: declare an action (next section). The platform reads the data with the current user's rights and hands it to the script as files.
|
|
14183
|
+
|
|
14184
|
+
## 5. actions.yaml
|
|
14185
|
+
\`${ACTIONS_FILE}\` at the skill root (at most ${ACTIONS_MAX_BYTES} bytes) declares what the agent may start. The agent starts one with the tool \`run_skill_action\` and the arguments \`skill\`, \`action\` and \`inputs\` (an object keyed by input name).
|
|
14186
|
+
|
|
14187
|
+
Keys: \`version: 1\` (required); \`actions\` (required, at most ${MAX_ACTIONS}); per action \`description\` (required), \`run\` (required, the shell command, run from the session directory; the caller can never change it), \`timeout_seconds\` (1-300, default 60), \`inputs\`. Action and input names match \`^[a-z][a-z0-9_]{0,39}$\`. Unknown keys are errors.
|
|
14188
|
+
|
|
14189
|
+
Input types:
|
|
14190
|
+
- \`item\`: keys \`type\`, \`context\` (required, the exact context id; the tool-name segment in \`get_<context>_item\` is sanitised and shortened, so it can differ from the id), \`fields\` (optional list of field names to include), \`description\`. The caller passes an item id string or \`{ "external_id": "..." }\`. The script finds \`<name>.json\` with the item.
|
|
14191
|
+
- \`items\`: keys \`type\`, \`context\`, \`fields\`, \`where\` (optional fixed filter in the syntax of \`find_<context>_items\`: \`{ field: { operator: value } }\` with the operators eq, ne, in, contains, gte, lte; unknown fields or operators are refused, and per field type: \`contains\` is refused on number, boolean, date and uuid fields, \`gte\` and \`lte\` on json and uuid fields (so not on \`id\`); eq, ne and in are always allowed. It is combined with the caller's filter; a field filtered here cannot be filtered again by the caller), \`description\`. The caller passes \`{ "where": {...}, "limit": n }\` or nothing (default limit 50, maximum 500). The script finds \`<name>.json\` as \`{ "items": [...], "limit": n, "truncated": true|false }\`. Archived items are included unless the fixed \`where\` excludes them with \`archived: { eq: false }\`.
|
|
14192
|
+
- \`text\`: keys \`type\`, \`required\` (default true), \`description\`. The caller passes a string of at most 10000 characters. The text inputs that were given arrive together in \`args.json\` as an object by input name; the file is missing when none was given (an optional text input left out). Do not name an \`item\` or \`items\` input \`args\`: the action then cannot run.
|
|
14193
|
+
|
|
14194
|
+
About \`fields\`: an \`item\` input without it returns every readable field, including createdAt, rights_mode, archived and file fields; an \`items\` input returns only id, updatedAt, name, description, tags, external_id and the context's non-file fields (name any other field to get it). A \`file\` field arrives as its storage key, never its content, and the script cannot fetch it. Fields whose value is null are left out unless \`fields\` names them.
|
|
14195
|
+
|
|
14196
|
+
In the script: \`$EXULU_INPUTS_DIR\` is the directory holding those files (it exists only while the command runs); \`$EXULU_SKILL_DIR\` is the skill's own folder. Values from the caller never reach the shell command, only these files.
|
|
14197
|
+
|
|
14198
|
+
Which contexts an action may read: only those the agent could read with its own tools in the same turn. That is the knowledge bases whose read tools the agent has (the knowledge-base editor setup), the knowledge bases its context search covers (all except those switched off there), or otherwise, in a project, the knowledge bases of the project's items. The agent's memory is never readable. An action that names any other context is refused when started, with the message that the knowledge base is not connected to the agent.
|
|
14199
|
+
|
|
14200
|
+
When the file is read: the platform takes \`${ACTIONS_FILE}\` from the saved skill version, when that version is downloaded into the session (the first turn, the first turn after a new version is saved, or a reload of the skills). ${ACTIONS_EDIT_NO_EFFECT} Save a new version instead; it is picked up on the next turn. Scripts still run from the session copy in \`skills/<name>/\`.
|
|
14201
|
+
|
|
14202
|
+
Invalid file: a skill whose saved \`${ACTIONS_FILE}\` is invalid is ignored (its actions are not offered and the agent is shown the reason), and this authoring tool refuses to save one.
|
|
14203
|
+
|
|
14204
|
+
Example:
|
|
14205
|
+
|
|
14206
|
+
\`\`\`yaml
|
|
14207
|
+
version: 1
|
|
14208
|
+
actions:
|
|
14209
|
+
summarize_contract:
|
|
14210
|
+
description: Build a one-page summary of a contract and the recent amendments.
|
|
14211
|
+
run: python3 "$EXULU_SKILL_DIR/scripts/summarize.py"
|
|
14212
|
+
timeout_seconds: 120
|
|
14213
|
+
inputs:
|
|
14214
|
+
contract:
|
|
14215
|
+
type: item
|
|
14216
|
+
context: contracts
|
|
14217
|
+
fields: [name, content]
|
|
14218
|
+
description: The contract to summarize.
|
|
14219
|
+
amendments:
|
|
14220
|
+
type: items
|
|
14221
|
+
context: amendments
|
|
14222
|
+
where: { status: { eq: active }, archived: { eq: false } }
|
|
14223
|
+
focus:
|
|
14224
|
+
type: text
|
|
14225
|
+
required: false
|
|
14226
|
+
description: A topic to emphasise.
|
|
14227
|
+
\`\`\`
|
|
14228
|
+
|
|
14229
|
+
\`\`\`python
|
|
14230
|
+
import json, os
|
|
14231
|
+
d = os.environ["EXULU_INPUTS_DIR"]
|
|
14232
|
+
contract = json.load(open(os.path.join(d, "contract.json")))
|
|
14233
|
+
amendments = json.load(open(os.path.join(d, "amendments.json")))["items"]
|
|
14234
|
+
args_path = os.path.join(d, "args.json")
|
|
14235
|
+
focus = json.load(open(args_path)).get("focus") if os.path.exists(args_path) else None
|
|
14236
|
+
\`\`\`
|
|
14237
|
+
|
|
14238
|
+
## 6. Stay usable elsewhere
|
|
14239
|
+
Describe in SKILL.md a manual path that works without actions (for example: read the item with the read tools and follow the same steps by hand). Other hosts ignore \`${ACTIONS_FILE}\`, and on this platform an agent may not have the action available (the agent has no sandbox or the file is invalid; an action whose knowledge base is not connected is listed but refused when called).
|
|
14240
|
+
|
|
14241
|
+
## 7. Limits
|
|
14242
|
+
- At most ${MAX_FILES} files per call to the authoring tools, each at most ${MAX_FILE_BYTES / 1024} KB; the \`${ACTIONS_FILE}\` limit is ${ACTIONS_MAX_BYTES / 1024} KB.
|
|
14243
|
+
- A file path is relative, at most 200 characters, with no \`..\`, empty segments or control characters.
|
|
14244
|
+
`;
|
|
14245
|
+
|
|
13998
14246
|
// src/templates/tools/skill-author-config.ts
|
|
13999
14247
|
var SKILL_AUTHOR_TOOL_ID = "skill_author";
|
|
14000
14248
|
var asBool = (v, fallback) => {
|
|
@@ -14034,12 +14282,11 @@ var SKILL_AUTHOR_PROMPT = [
|
|
|
14034
14282
|
"Offer a skill only after the user has finished a complex, multi-step piece of work that is likely to recur \u2014 typically one that produced files, documents, code, a report or a structured analysis, or a multi-step retrieval they run regularly.",
|
|
14035
14283
|
"Do not offer it for a single question against a knowledge base, a quick lookup, or a one-off correction; a correction or a preference belongs in memory, not in a skill.",
|
|
14036
14284
|
"When you offer, say in one sentence what the skill would capture and ask. The user confirms the name, the description and who may see it on a card before anything is created; never ask about visibility yourself unless the user raised it, and never claim a skill exists or changed until the tool returns skill_created or skill_updated.",
|
|
14285
|
+
"Skills on this platform differ from other hosts (where scripts run, what they can reach, how they read knowledge-base data): call skill_guide before writing or changing a skill that contains scripts or needs platform data.",
|
|
14037
14286
|
"Write a skill as a SKILL.md with frontmatter (name, description) and clear steps, plus reference files only where they add something the model would otherwise have to guess."
|
|
14038
14287
|
].join(" ");
|
|
14039
14288
|
|
|
14040
14289
|
// src/templates/tools/skill-author-tools.ts
|
|
14041
|
-
var MAX_FILES = 100;
|
|
14042
|
-
var MAX_FILE_BYTES = 200 * 1024;
|
|
14043
14290
|
var MAX_READ_BYTES = 60 * 1024;
|
|
14044
14291
|
var defaultIo = () => ({
|
|
14045
14292
|
upload: (bytes, key, config, contentType) => uploadFile(bytes, key, config, { contentType }, void 0, void 0, true),
|
|
@@ -14105,6 +14352,12 @@ var normalizeFiles = (raw) => {
|
|
|
14105
14352
|
}
|
|
14106
14353
|
return { files };
|
|
14107
14354
|
};
|
|
14355
|
+
var actionsFileError = (files) => {
|
|
14356
|
+
const file = files.find((f) => f.path === ACTIONS_FILE);
|
|
14357
|
+
if (!file) return null;
|
|
14358
|
+
const parsed = parseActionsYaml(file.content);
|
|
14359
|
+
return parsed.ok ? null : err2(`${ACTIONS_FILE} is invalid: ${parsed.error}. Nothing was saved; fix the file and call the tool again (skill_guide describes the format).`);
|
|
14360
|
+
};
|
|
14108
14361
|
var createSkillAuthorTools = (agent, deps = {}) => {
|
|
14109
14362
|
const config = parseSkillAuthorConfig(agent.tools);
|
|
14110
14363
|
if (!config.enabled) return [];
|
|
@@ -14123,7 +14376,7 @@ var createSkillAuthorTools = (agent, deps = {}) => {
|
|
|
14123
14376
|
config: [],
|
|
14124
14377
|
needsApproval: false,
|
|
14125
14378
|
description: "List the skills in this instance's library that the current user may read: name, description and current version. Use it before creating a skill to avoid duplicates, and before updating one.",
|
|
14126
|
-
inputSchema:
|
|
14379
|
+
inputSchema: z17.object({ query: z17.string().optional().describe("Optional substring to filter by name or description") }),
|
|
14127
14380
|
execute: async (params) => {
|
|
14128
14381
|
const { user } = params;
|
|
14129
14382
|
if (!user?.id) return err2("Skills require a signed-in user.");
|
|
@@ -14149,9 +14402,9 @@ var createSkillAuthorTools = (agent, deps = {}) => {
|
|
|
14149
14402
|
config: [],
|
|
14150
14403
|
needsApproval: false,
|
|
14151
14404
|
description: "Read a skill the user may access: its file list and the content of SKILL.md, or of one file by path. Use it before updating a skill so you change only what must change.",
|
|
14152
|
-
inputSchema:
|
|
14153
|
-
skill:
|
|
14154
|
-
path:
|
|
14405
|
+
inputSchema: z17.object({
|
|
14406
|
+
skill: z17.string().describe("The skill's name or id"),
|
|
14407
|
+
path: z17.string().optional().describe("A file path inside the skill to read instead of SKILL.md")
|
|
14155
14408
|
}),
|
|
14156
14409
|
execute: async (params) => {
|
|
14157
14410
|
const { user, exuluConfig } = params;
|
|
@@ -14185,6 +14438,19 @@ ${content}`
|
|
|
14185
14438
|
}
|
|
14186
14439
|
})
|
|
14187
14440
|
);
|
|
14441
|
+
tools.push(
|
|
14442
|
+
new ExuluTool({
|
|
14443
|
+
id: "skill_guide",
|
|
14444
|
+
name: "skill_guide",
|
|
14445
|
+
category,
|
|
14446
|
+
type: "function",
|
|
14447
|
+
config: [],
|
|
14448
|
+
needsApproval: false,
|
|
14449
|
+
description: "Read how skills on this platform differ from other hosts: where scripts run, what they can reach, how files come back, how to read knowledge-base data (actions.yaml). Call it before writing or changing a skill that contains scripts or needs platform data.",
|
|
14450
|
+
inputSchema: z17.object({}),
|
|
14451
|
+
execute: async () => ({ type: "skill_guide", result: SKILL_AUTHORING_GUIDE })
|
|
14452
|
+
})
|
|
14453
|
+
);
|
|
14188
14454
|
if (config.create) {
|
|
14189
14455
|
tools.push(
|
|
14190
14456
|
new ExuluTool({
|
|
@@ -14196,10 +14462,10 @@ ${content}`
|
|
|
14196
14462
|
needsApproval: !config.skipApproval,
|
|
14197
14463
|
needsApprovalFn: approvalFn,
|
|
14198
14464
|
description: "Propose a NEW skill from a procedure the user just completed. Give it a short name, a one-line description, and its files: a SKILL.md with frontmatter and clear steps, plus reference files only where useful. The user confirms name, description and visibility on a card before anything is created; never claim it exists until this tool returns skill_created.",
|
|
14199
|
-
inputSchema:
|
|
14200
|
-
name:
|
|
14201
|
-
description:
|
|
14202
|
-
files:
|
|
14465
|
+
inputSchema: z17.object({
|
|
14466
|
+
name: z17.string().describe("Short, specific skill name (e.g. 'quarterly-report-from-crm')"),
|
|
14467
|
+
description: z17.string().describe("One line: what the skill does and when to use it"),
|
|
14468
|
+
files: z17.array(z17.object({ path: z17.string().describe("Relative path inside the skill, e.g. SKILL.md or references/checklist.md"), content: z17.string() })).min(1).describe("The skill's files; SKILL.md is required")
|
|
14203
14469
|
}),
|
|
14204
14470
|
execute: async (params) => {
|
|
14205
14471
|
const { user, exuluConfig } = params;
|
|
@@ -14212,6 +14478,8 @@ ${content}`
|
|
|
14212
14478
|
const parsed = normalizeFiles(params.files);
|
|
14213
14479
|
if ("error" in parsed) return err2(parsed.error);
|
|
14214
14480
|
const files = parsed.files;
|
|
14481
|
+
const invalidActions = actionsFileError(files);
|
|
14482
|
+
if (invalidActions) return invalidActions;
|
|
14215
14483
|
const skillMd = files.find((f) => f.path === "SKILL.md");
|
|
14216
14484
|
if (!skillMd) return err2("A skill needs a SKILL.md at its root.");
|
|
14217
14485
|
skillMd.content = ensureFrontmatter(skillMd.content, name, description);
|
|
@@ -14265,12 +14533,12 @@ ${content}`
|
|
|
14265
14533
|
needsApproval: !config.skipApproval,
|
|
14266
14534
|
needsApprovalFn: approvalFn,
|
|
14267
14535
|
description: "Publish a new version of an existing skill the user may write: pass only the files to add or replace (full content each) and, optionally, paths to remove. Unchanged files carry over. Read the skill first with skill_read. The user confirms on a card; never claim the change happened until this tool returns skill_updated.",
|
|
14268
|
-
inputSchema:
|
|
14269
|
-
skill:
|
|
14270
|
-
files:
|
|
14271
|
-
deletePaths:
|
|
14272
|
-
description:
|
|
14273
|
-
label:
|
|
14536
|
+
inputSchema: z17.object({
|
|
14537
|
+
skill: z17.string().describe("The skill's name or id"),
|
|
14538
|
+
files: z17.array(z17.object({ path: z17.string(), content: z17.string() })).optional().describe("Files to add or replace, full content each"),
|
|
14539
|
+
deletePaths: z17.array(z17.string()).optional().describe("Paths to remove in the new version"),
|
|
14540
|
+
description: z17.string().optional().describe("A new one-line description, if it changed"),
|
|
14541
|
+
label: z17.string().optional().describe("A short label for this version, e.g. 'Added the review checklist'")
|
|
14274
14542
|
}),
|
|
14275
14543
|
execute: async (params) => {
|
|
14276
14544
|
const { user, exuluConfig } = params;
|
|
@@ -14285,6 +14553,8 @@ ${content}`
|
|
|
14285
14553
|
const parsed = normalizeFiles(params.files);
|
|
14286
14554
|
if ("error" in parsed) return err2(parsed.error);
|
|
14287
14555
|
const changes = parsed.files;
|
|
14556
|
+
const invalidActions = actionsFileError(changes);
|
|
14557
|
+
if (invalidActions) return invalidActions;
|
|
14288
14558
|
const removals = [];
|
|
14289
14559
|
for (const raw of Array.isArray(params.deletePaths) ? params.deletePaths : []) {
|
|
14290
14560
|
const p = safeSkillPath(raw);
|
|
@@ -14347,7 +14617,7 @@ var createSkillAuthorPickerTool = () => new ExuluTool({
|
|
|
14347
14617
|
category: "default",
|
|
14348
14618
|
description: "Let this agent create skills and publish new versions of existing ones from the chat, with the user's consent on a card. Adds a system-prompt hint to offer a skill only after complex, recurring, multi-step work \u2014 never for a single question or correction.",
|
|
14349
14619
|
type: "function",
|
|
14350
|
-
inputSchema:
|
|
14620
|
+
inputSchema: z17.object({}),
|
|
14351
14621
|
config: [
|
|
14352
14622
|
{ name: "create", description: "The agent may propose new skills.", type: "boolean", default: true },
|
|
14353
14623
|
{ name: "update", description: "The agent may publish new versions of skills the user can write.", type: "boolean", default: true },
|
|
@@ -14360,1277 +14630,1638 @@ var collectSkillAuthorTools = (agent, deps = {}) => {
|
|
|
14360
14630
|
return createSkillAuthorTools(agent, deps);
|
|
14361
14631
|
};
|
|
14362
14632
|
|
|
14363
|
-
// ee/invoke-skills/
|
|
14364
|
-
import {
|
|
14365
|
-
SandboxManager
|
|
14366
|
-
} from "@anthropic-ai/sandbox-runtime";
|
|
14367
|
-
import { mkdir as mkdir3, rm as rm2, readdir as readdir2, stat, lstat as lstat3 } from "fs/promises";
|
|
14368
|
-
import { existsSync as existsSync4 } from "fs";
|
|
14369
|
-
import { join as join4, dirname as dirname3, resolve as resolve3, relative, posix } from "path";
|
|
14370
|
-
import { exec as exec2, spawn } from "child_process";
|
|
14371
|
-
import { promisify as promisify3 } from "util";
|
|
14372
|
-
|
|
14373
|
-
// src/exulu/system-dependencies.ts
|
|
14374
|
-
import { exec } from "child_process";
|
|
14375
|
-
import { existsSync as existsSync2 } from "fs";
|
|
14633
|
+
// ee/invoke-skills/skill-actions/load.ts
|
|
14376
14634
|
import { join } from "path";
|
|
14377
|
-
|
|
14378
|
-
|
|
14379
|
-
|
|
14380
|
-
|
|
14381
|
-
|
|
14382
|
-
displayName: "Pandoc",
|
|
14383
|
-
purpose: "docx skill: text extraction and tracked-changes conversion",
|
|
14384
|
-
installHints: {
|
|
14385
|
-
debian: "apt-get install -y pandoc",
|
|
14386
|
-
macos: "brew install pandoc"
|
|
14387
|
-
}
|
|
14388
|
-
},
|
|
14389
|
-
{
|
|
14390
|
-
check: { kind: "binary", binary: "soffice" },
|
|
14391
|
-
displayName: "LibreOffice",
|
|
14392
|
-
purpose: "docx skill: converting .docx documents to PDF for visual analysis",
|
|
14393
|
-
installHints: {
|
|
14394
|
-
debian: "apt-get install -y libreoffice",
|
|
14395
|
-
macos: "brew install --cask libreoffice"
|
|
14635
|
+
var declarationFromBytes = (bytes) => {
|
|
14636
|
+
if (bytes === void 0) return { kind: "none" };
|
|
14637
|
+
try {
|
|
14638
|
+
if (bytes.length > ACTIONS_MAX_BYTES) {
|
|
14639
|
+
return { kind: "problem", error: `${ACTIONS_FILE} exceeds ${ACTIONS_MAX_BYTES} bytes` };
|
|
14396
14640
|
}
|
|
14397
|
-
|
|
14398
|
-
|
|
14399
|
-
|
|
14400
|
-
|
|
14401
|
-
|
|
14402
|
-
|
|
14403
|
-
|
|
14404
|
-
|
|
14641
|
+
const parsed = parseActionsYaml(bytes.toString("utf8"));
|
|
14642
|
+
return parsed.ok ? { kind: "ok", actions: parsed.actions } : { kind: "problem", error: parsed.error };
|
|
14643
|
+
} catch (err3) {
|
|
14644
|
+
return {
|
|
14645
|
+
kind: "problem",
|
|
14646
|
+
error: `${ACTIONS_FILE} could not be loaded: ${err3 instanceof Error ? err3.message : String(err3)}`
|
|
14647
|
+
};
|
|
14648
|
+
}
|
|
14649
|
+
};
|
|
14650
|
+
var isPlainName = (name) => typeof name === "string" && name !== "" && name !== "." && name !== ".." && !name.includes("/") && !name.includes("\\") && !name.includes("\0") && !name.includes("..");
|
|
14651
|
+
var loadSkillActions = (sessionDir, skills, pinned) => {
|
|
14652
|
+
const result = { bySkill: {}, problems: [] };
|
|
14653
|
+
for (const skill of skills) {
|
|
14654
|
+
const pin = pinned.get(skill.id);
|
|
14655
|
+
if (!pin || pin.version !== skill.current_version || pin.name !== skill.name) continue;
|
|
14656
|
+
const { declaration } = pin;
|
|
14657
|
+
if (declaration.kind === "none") continue;
|
|
14658
|
+
if (!isPlainName(skill.name)) {
|
|
14659
|
+
result.problems.push({
|
|
14660
|
+
skill: String(skill.name),
|
|
14661
|
+
error: `the skill's name contains a path separator or "..", so it cannot declare actions`
|
|
14662
|
+
});
|
|
14663
|
+
continue;
|
|
14405
14664
|
}
|
|
14406
|
-
|
|
14407
|
-
|
|
14408
|
-
|
|
14409
|
-
displayName: "Poppler (pdftotext)",
|
|
14410
|
-
purpose: "parse_document tool: extracting page-marked text from PDFs",
|
|
14411
|
-
installHints: {
|
|
14412
|
-
debian: "apt-get install -y poppler-utils",
|
|
14413
|
-
macos: "brew install poppler"
|
|
14665
|
+
if (declaration.kind === "problem") {
|
|
14666
|
+
result.problems.push({ skill: skill.name, error: declaration.error });
|
|
14667
|
+
continue;
|
|
14414
14668
|
}
|
|
14415
|
-
|
|
14416
|
-
|
|
14417
|
-
|
|
14418
|
-
|
|
14419
|
-
|
|
14420
|
-
|
|
14421
|
-
|
|
14422
|
-
|
|
14669
|
+
result.bySkill[skill.name] = { skillDir: join(sessionDir, "skills", skill.name), actions: declaration.actions };
|
|
14670
|
+
}
|
|
14671
|
+
return result;
|
|
14672
|
+
};
|
|
14673
|
+
var describeActions = (loaded) => {
|
|
14674
|
+
const lines = [];
|
|
14675
|
+
for (const [skill, { actions }] of Object.entries(loaded.bySkill)) {
|
|
14676
|
+
for (const [actionName, action] of Object.entries(actions)) {
|
|
14677
|
+
lines.push(`${skill} / ${actionName} \u2014 ${action.description}`);
|
|
14678
|
+
for (const [inputName, input] of Object.entries(action.inputs)) {
|
|
14679
|
+
let qualifiers = input.type;
|
|
14680
|
+
if (input.type === "item" || input.type === "items") qualifiers += `, context ${input.context}`;
|
|
14681
|
+
if (input.type === "text" && !input.required) qualifiers += ", optional";
|
|
14682
|
+
lines.push(` ${inputName} (${qualifiers})${input.description ? ` \u2014 ${input.description}` : ""}`);
|
|
14683
|
+
}
|
|
14423
14684
|
}
|
|
14424
14685
|
}
|
|
14425
|
-
|
|
14426
|
-
|
|
14427
|
-
|
|
14428
|
-
|
|
14686
|
+
for (const p of loaded.problems) lines.push(`skill "${p.skill}": actions.yaml ignored \u2014 ${p.error}`);
|
|
14687
|
+
return lines.join("\n");
|
|
14688
|
+
};
|
|
14689
|
+
|
|
14690
|
+
// ee/invoke-skills/skill-actions/tool.ts
|
|
14691
|
+
import { randomUUID as randomUUID6 } from "crypto";
|
|
14692
|
+
import { mkdir as mkdir3 } from "fs/promises";
|
|
14693
|
+
import { join as join4 } from "path";
|
|
14694
|
+
import { z as z18 } from "zod";
|
|
14695
|
+
|
|
14696
|
+
// ee/invoke-skills/safe-fs.ts
|
|
14697
|
+
import { constants } from "fs";
|
|
14698
|
+
import { lstat as lstat2, mkdir as mkdir2, open, readlink, realpath, rename as rename2, unlink, writeFile as writeFile2 } from "fs/promises";
|
|
14699
|
+
import { randomBytes as randomBytes3 } from "crypto";
|
|
14700
|
+
|
|
14701
|
+
// ee/invoke-skills/project-sync.ts
|
|
14702
|
+
import { lstat, mkdir, readdir, readFile, rename, rm, writeFile } from "fs/promises";
|
|
14703
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
14704
|
+
import { basename, dirname, join as join2, resolve as resolve2, sep } from "path";
|
|
14705
|
+
import { execFile } from "child_process";
|
|
14706
|
+
import { promisify } from "util";
|
|
14707
|
+
function planProjectSync(remote, local) {
|
|
14708
|
+
const localSizes = new Map(local.map((e) => [e.name, e.size]));
|
|
14709
|
+
const remoteNames = new Set(remote.map((e) => e.name));
|
|
14710
|
+
return {
|
|
14711
|
+
download: remote.filter((e) => localSizes.get(e.name) !== e.size).map((e) => e.name),
|
|
14712
|
+
remove: local.filter((e) => !remoteNames.has(e.name)).map((e) => e.name)
|
|
14713
|
+
};
|
|
14714
|
+
}
|
|
14715
|
+
function projectSyncMarkerPath(sessionDir) {
|
|
14716
|
+
return join2(dirname(sessionDir), ".project-sync", basename(sessionDir));
|
|
14717
|
+
}
|
|
14718
|
+
async function readMarker(sessionDir) {
|
|
14429
14719
|
try {
|
|
14430
|
-
|
|
14431
|
-
cachedNpmGlobalRoot = stdout.trim() || null;
|
|
14720
|
+
return (await readFile(projectSyncMarkerPath(sessionDir), "utf8")).trim() || null;
|
|
14432
14721
|
} catch {
|
|
14433
|
-
|
|
14722
|
+
return null;
|
|
14434
14723
|
}
|
|
14435
|
-
return cachedNpmGlobalRoot;
|
|
14436
14724
|
}
|
|
14437
|
-
async function
|
|
14438
|
-
|
|
14439
|
-
|
|
14440
|
-
|
|
14441
|
-
|
|
14442
|
-
|
|
14443
|
-
|
|
14444
|
-
|
|
14445
|
-
|
|
14446
|
-
|
|
14447
|
-
|
|
14448
|
-
|
|
14449
|
-
|
|
14450
|
-
|
|
14725
|
+
async function clearProjectSyncMarker(sessionDir) {
|
|
14726
|
+
await rm(projectSyncMarkerPath(sessionDir), { force: true });
|
|
14727
|
+
}
|
|
14728
|
+
var isFlatName = (name) => !!name && !name.includes("/") && !name.includes("\\") && name !== "." && name !== "..";
|
|
14729
|
+
var HELPER_KINDS = [".project-staging", ".project-trash"];
|
|
14730
|
+
var helperRoot = (sessionDir, kind) => join2(dirname(sessionDir), kind);
|
|
14731
|
+
var helperPath = (sessionDir, kind) => join2(helperRoot(sessionDir, kind), `${basename(sessionDir)}-${randomBytes2(8).toString("hex")}`);
|
|
14732
|
+
var execFileAsync = promisify(execFile);
|
|
14733
|
+
async function removeTreeSafely(path3, sessionDir) {
|
|
14734
|
+
const target = resolve2(path3);
|
|
14735
|
+
const inside = HELPER_KINDS.some((kind) => {
|
|
14736
|
+
const root = resolve2(helperRoot(sessionDir, kind));
|
|
14737
|
+
return target.startsWith(root + sep) && !target.slice(root.length + 1).includes(sep);
|
|
14738
|
+
});
|
|
14739
|
+
if (!inside) {
|
|
14740
|
+
console.error(`[SKILLS] Refusing to remove ${path3}: not a project staging or trash directory.`);
|
|
14741
|
+
return false;
|
|
14742
|
+
}
|
|
14743
|
+
try {
|
|
14744
|
+
await execFileAsync("rm", ["-rf", "--", target]);
|
|
14745
|
+
return true;
|
|
14746
|
+
} catch (err3) {
|
|
14747
|
+
console.error(`[SKILLS] Failed to remove ${target}; leaving it for a later sweep.`, err3);
|
|
14748
|
+
return false;
|
|
14749
|
+
}
|
|
14750
|
+
}
|
|
14751
|
+
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
14752
|
+
async function sweepStaleHelpers(sessionDir) {
|
|
14753
|
+
const prefix = `${basename(sessionDir)}-`;
|
|
14754
|
+
for (const kind of HELPER_KINDS) {
|
|
14755
|
+
const root = helperRoot(sessionDir, kind);
|
|
14756
|
+
let names;
|
|
14757
|
+
try {
|
|
14758
|
+
names = await readdir(root);
|
|
14759
|
+
} catch {
|
|
14760
|
+
continue;
|
|
14761
|
+
}
|
|
14762
|
+
for (const name of names) {
|
|
14763
|
+
if (!name.startsWith(prefix)) continue;
|
|
14764
|
+
const st = await lstat(join2(root, name)).catch(() => null);
|
|
14765
|
+
if (st && Date.now() - st.mtimeMs > DAY_MS) await removeTreeSafely(join2(root, name), sessionDir);
|
|
14451
14766
|
}
|
|
14452
14767
|
}
|
|
14453
14768
|
}
|
|
14454
|
-
|
|
14455
|
-
|
|
14456
|
-
|
|
14457
|
-
|
|
14458
|
-
|
|
14459
|
-
|
|
14460
|
-
|
|
14461
|
-
|
|
14462
|
-
|
|
14463
|
-
|
|
14769
|
+
var errCode = (err3) => err3?.code;
|
|
14770
|
+
async function moveAway(dir, sessionDir) {
|
|
14771
|
+
const trash = helperPath(sessionDir, ".project-trash");
|
|
14772
|
+
await mkdir(dirname(trash), { recursive: true });
|
|
14773
|
+
try {
|
|
14774
|
+
await rename(dir, trash);
|
|
14775
|
+
return trash;
|
|
14776
|
+
} catch (err3) {
|
|
14777
|
+
if (errCode(err3) === "ENOENT") return null;
|
|
14778
|
+
throw err3;
|
|
14779
|
+
}
|
|
14464
14780
|
}
|
|
14465
|
-
function
|
|
14466
|
-
|
|
14467
|
-
return ` - ${dep.displayName} (${probeLabel}) \u2014 ${dep.purpose}
|
|
14468
|
-
Debian/Ubuntu: ${dep.installHints.debian}
|
|
14469
|
-
macOS: ${dep.installHints.macos}`;
|
|
14781
|
+
async function discard(path3, sessionDir) {
|
|
14782
|
+
if (path3) await removeTreeSafely(path3, sessionDir);
|
|
14470
14783
|
}
|
|
14471
|
-
async function
|
|
14472
|
-
|
|
14473
|
-
|
|
14474
|
-
|
|
14475
|
-
|
|
14476
|
-
|
|
14477
|
-
|
|
14478
|
-
|
|
14479
|
-
|
|
14784
|
+
async function discardEntry(path3, sessionDir) {
|
|
14785
|
+
await discard(await moveAway(path3, sessionDir), sessionDir);
|
|
14786
|
+
}
|
|
14787
|
+
async function syncProjectDir(args) {
|
|
14788
|
+
const { sessionDir, projectId, config } = args;
|
|
14789
|
+
const dir = join2(sessionDir, PROJECT_DIR);
|
|
14790
|
+
const previous = await readMarker(sessionDir);
|
|
14791
|
+
if (!projectId) {
|
|
14792
|
+
if (previous !== null) {
|
|
14793
|
+
await discard(await moveAway(dir, sessionDir), sessionDir);
|
|
14794
|
+
await clearProjectSyncMarker(sessionDir);
|
|
14795
|
+
}
|
|
14796
|
+
return;
|
|
14797
|
+
}
|
|
14798
|
+
if (!config.fileUploads) {
|
|
14799
|
+
console.warn(`[SKILLS] File uploads are not configured; project files are not synced into ${sessionDir}.`);
|
|
14800
|
+
return;
|
|
14801
|
+
}
|
|
14802
|
+
const { projectPrefix } = projectFilePrefix(projectId);
|
|
14803
|
+
const remote = /* @__PURE__ */ new Map();
|
|
14804
|
+
try {
|
|
14805
|
+
for (const obj of await listS3ObjectsByPrefix(projectPrefix, config)) {
|
|
14806
|
+
const idx = obj.key.indexOf(projectPrefix);
|
|
14807
|
+
const name = idx >= 0 ? obj.key.slice(idx + projectPrefix.length) : "";
|
|
14808
|
+
if (!isFlatName(name)) continue;
|
|
14809
|
+
remote.set(name, { size: obj.size, key: obj.key });
|
|
14810
|
+
}
|
|
14811
|
+
} catch (err3) {
|
|
14812
|
+
console.error(`[SKILLS] Failed to list project files for project ${projectId}; keeping the local copy.`, err3);
|
|
14813
|
+
return;
|
|
14814
|
+
}
|
|
14815
|
+
await sweepStaleHelpers(sessionDir);
|
|
14816
|
+
await mkdir(dirname(projectSyncMarkerPath(sessionDir)), { recursive: true });
|
|
14817
|
+
await writeFile(projectSyncMarkerPath(sessionDir), projectId);
|
|
14818
|
+
const trashes = [];
|
|
14819
|
+
const staging = helperPath(sessionDir, ".project-staging");
|
|
14820
|
+
let installed = false;
|
|
14821
|
+
try {
|
|
14822
|
+
const old = await moveAway(dir, sessionDir);
|
|
14823
|
+
trashes.push(old);
|
|
14824
|
+
await mkdir(dirname(staging), { recursive: true });
|
|
14825
|
+
await mkdir(staging);
|
|
14826
|
+
const local = [];
|
|
14827
|
+
const oldStat = old && previous === projectId ? await lstat(old).catch(() => null) : null;
|
|
14828
|
+
if (old && oldStat?.isDirectory()) {
|
|
14829
|
+
for (const name of await readdir(old)) {
|
|
14830
|
+
const st = await lstat(join2(old, name)).catch(() => null);
|
|
14831
|
+
if (!st?.isFile() || remote.get(name)?.size !== st.size) continue;
|
|
14832
|
+
await rename(join2(old, name), join2(staging, name));
|
|
14833
|
+
const moved = await lstat(join2(staging, name)).catch(() => null);
|
|
14834
|
+
if (!moved?.isFile()) {
|
|
14835
|
+
await rename(join2(staging, name), join2(old, `.rejected-${randomBytes2(4).toString("hex")}`)).catch(() => {
|
|
14836
|
+
});
|
|
14837
|
+
continue;
|
|
14838
|
+
}
|
|
14839
|
+
local.push({ name, size: moved.size });
|
|
14840
|
+
}
|
|
14841
|
+
}
|
|
14842
|
+
const plan = planProjectSync(
|
|
14843
|
+
[...remote].map(([name, r]) => ({ name, size: r.size })),
|
|
14844
|
+
local
|
|
14480
14845
|
);
|
|
14846
|
+
for (const name of plan.download) {
|
|
14847
|
+
try {
|
|
14848
|
+
const bytes = await getS3ObjectBytes(remote.get(name).key, config);
|
|
14849
|
+
await writeFile(join2(staging, name), bytes, { flag: "wx" });
|
|
14850
|
+
} catch (err3) {
|
|
14851
|
+
console.error(`[SKILLS] Failed to sync project file ${name} (project ${projectId}); continuing.`, err3);
|
|
14852
|
+
}
|
|
14853
|
+
}
|
|
14854
|
+
for (let attempt = 0; attempt < 2 && !installed; attempt++) {
|
|
14855
|
+
try {
|
|
14856
|
+
await rename(staging, dir);
|
|
14857
|
+
installed = true;
|
|
14858
|
+
} catch (err3) {
|
|
14859
|
+
const code = errCode(err3);
|
|
14860
|
+
if (attempt === 0 && (code === "EEXIST" || code === "ENOTEMPTY" || code === "ENOTDIR" || code === "EISDIR")) {
|
|
14861
|
+
trashes.push(await moveAway(dir, sessionDir));
|
|
14862
|
+
continue;
|
|
14863
|
+
}
|
|
14864
|
+
console.error(`[SKILLS] Could not install the project folder for session ${sessionDir}; skipping this turn.`, err3);
|
|
14865
|
+
break;
|
|
14866
|
+
}
|
|
14867
|
+
}
|
|
14868
|
+
} catch (err3) {
|
|
14869
|
+
console.error(`[SKILLS] Project sync failed for project ${projectId}; continuing.`, err3);
|
|
14870
|
+
} finally {
|
|
14871
|
+
if (!installed) await discard(staging, sessionDir);
|
|
14872
|
+
for (const t of trashes) await discard(t, sessionDir);
|
|
14873
|
+
}
|
|
14874
|
+
}
|
|
14875
|
+
async function resolveSandboxProjectId(args, deps) {
|
|
14876
|
+
const { projectId, ownerId } = args;
|
|
14877
|
+
if (!projectId || ownerId == null) return null;
|
|
14878
|
+
try {
|
|
14879
|
+
const project = await deps.getProject(projectId);
|
|
14880
|
+
if (!project) return null;
|
|
14881
|
+
const owner = args.owner && String(args.owner.id) === String(ownerId) ? args.owner : await deps.getUser(ownerId);
|
|
14882
|
+
if (!owner) return null;
|
|
14883
|
+
const rbac = await deps.getRbac(project);
|
|
14884
|
+
const allowed = hasProjectAccess({ project, rbac, user: owner, want: "read" });
|
|
14885
|
+
return allowed ? String(project.id) : null;
|
|
14886
|
+
} catch (err3) {
|
|
14887
|
+
console.error(`[SKILLS] Failed to resolve project ${projectId} for the session sandbox; continuing without project files.`, err3);
|
|
14888
|
+
return null;
|
|
14481
14889
|
}
|
|
14482
|
-
console.warn(
|
|
14483
|
-
`[EXULU] ${body}
|
|
14484
|
-
Set requireSystemDependencies=true in ExuluConfig to make this fatal at startup.`
|
|
14485
|
-
);
|
|
14486
14890
|
}
|
|
14487
14891
|
|
|
14488
|
-
//
|
|
14489
|
-
|
|
14490
|
-
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
|
|
14494
|
-
|
|
14495
|
-
LITELLM_DATABASE_URL: "secret",
|
|
14496
|
-
COMPANION_S3_SECRET: "secret",
|
|
14497
|
-
COMPANION_S3_KEY: "secret",
|
|
14498
|
-
ANTHROPIC_API_KEY: "secret",
|
|
14499
|
-
GEMINI_API_KEY: "secret",
|
|
14500
|
-
PERPLEXITY_API_KEY: "secret",
|
|
14501
|
-
RECALL_API_KEY: "secret",
|
|
14502
|
-
JIRA_CLIENT_SECRET: "secret",
|
|
14503
|
-
GOOGLE_CLIENT_SECRET: "secret",
|
|
14504
|
-
REDIS_PASSWORD: "secret",
|
|
14505
|
-
NPM_TOKEN: "secret",
|
|
14506
|
-
// Found via `rg process\.env\.[A-Z0-9_]+ src ee` (Step 3 of the task brief):
|
|
14507
|
-
EXULU_API_KEY: "secret",
|
|
14508
|
-
// auth header for remote LiteLLM client mode (resolve-model.ts)
|
|
14509
|
-
INTERNAL_SECRET: "secret",
|
|
14510
|
-
// compared against an internal-request header (src/auth/auth.ts)
|
|
14511
|
-
RECALL_WORKSPACE_VERIFICATION_SECRET: "secret",
|
|
14512
|
-
// verifies inbound Recall webhook signatures
|
|
14513
|
-
SMTP_PASSWORD: "secret",
|
|
14514
|
-
// EXULU_ENTERPRISE_LICENSE: the check (ee/entitlements.ts) only tests a
|
|
14515
|
-
// string prefix, not a cryptographic signature, so it is closer to a
|
|
14516
|
-
// capability token than a password — but knowing it still unlocks
|
|
14517
|
-
// enterprise entitlements, so classified secret per the fail-safe rule.
|
|
14518
|
-
EXULU_ENTERPRISE_LICENSE: "secret",
|
|
14519
|
-
// POSTGRES_DB_USER / REDIS_USER / SMTP_USER: a username alone grants
|
|
14520
|
-
// nothing without its paired password. Classified secret anyway — the
|
|
14521
|
-
// design's claim is "a skill never sees the platform's own credentials",
|
|
14522
|
-
// and a username is half of one. No skill has a legitimate need for the
|
|
14523
|
-
// platform's database, cache, or mail identity; an admin can expose one
|
|
14524
|
-
// deliberately as a platform variable if that ever changes.
|
|
14525
|
-
POSTGRES_DB_USER: "secret",
|
|
14526
|
-
REDIS_USER: "secret",
|
|
14527
|
-
SMTP_USER: "secret",
|
|
14528
|
-
// --- deployment credentials the consumer app reads on our behalf.
|
|
14529
|
-
// `@exulu/backend` is a library: these never appear as `process.env.<NAME>` in
|
|
14530
|
-
// src/ or ee/, so the code scan cannot see them — they come from the
|
|
14531
|
-
// Server/Worker rows of mintlify-docs/self-hosting/environment-variables.mdx
|
|
14532
|
-
// and from config.litellm.yaml's `os.environ/` directives. They were reaching
|
|
14533
|
-
// every skill until this block existed.
|
|
14534
|
-
//
|
|
14535
|
-
// VERTEX_CREDENTIALS_PATH is worse than a leaked string: it is a filesystem
|
|
14536
|
-
// path to a GCP service-account JSON, and in bwrap mode the sandbox binds /
|
|
14537
|
-
// read-only with only ~ denied, so a skill can read the key file at the
|
|
14538
|
-
// documented ./vertex-auth.json. Stripping the path does not make that file
|
|
14539
|
-
// unreadable — it removes the pointer every tool follows, which is as far as
|
|
14540
|
-
// this layer reaches.
|
|
14541
|
-
VERTEX_CREDENTIALS_PATH: "secret",
|
|
14542
|
-
GOOGLE_VERTEX_CREDENTIALS_JSON: "secret",
|
|
14543
|
-
// inline service-account JSON, same credential without the file
|
|
14544
|
-
// A GCP project id is not a password, but it is half of the Vertex identity
|
|
14545
|
-
// and no skill has a legitimate need for it — same reasoning as
|
|
14546
|
-
// POSTGRES_DB_USER above.
|
|
14547
|
-
GOOGLE_VERTEX_PROJECT: "secret",
|
|
14548
|
-
COHERE_API_KEY: "secret",
|
|
14549
|
-
// reranker provider key (os.environ/COHERE_API_KEY)
|
|
14550
|
-
OPENAI_API_KEY: "secret",
|
|
14551
|
-
// TTS / model provider key
|
|
14552
|
-
AZURE_API_KEY_EU: "secret",
|
|
14553
|
-
// image-generation provider key
|
|
14554
|
-
SIGNOZ_ACCESS_TOKEN: "secret",
|
|
14555
|
-
// OTLP ingest token; read via ExuluOtel's parameter object, invisible to the code scan
|
|
14556
|
-
HF_AUTH_TOKEN: "secret",
|
|
14557
|
-
// HuggingFace token for pyannote diarization; documented as Whisper-container-only, stripped here fail-safe
|
|
14558
|
-
LITELLM_API_KEY: "secret",
|
|
14559
|
-
// supervisor-populated proxy key handed to the bundled LiteLLM UI
|
|
14560
|
-
// --- runtime: paths, locales, feature flags, hostnames, ports, log levels.
|
|
14561
|
-
// Only changes behaviour.
|
|
14562
|
-
PATH: "runtime",
|
|
14563
|
-
HOME: "runtime",
|
|
14564
|
-
LANG: "runtime",
|
|
14565
|
-
TZ: "runtime",
|
|
14566
|
-
TMPDIR: "runtime",
|
|
14567
|
-
NODE_ENV: "runtime",
|
|
14568
|
-
PORT: "runtime",
|
|
14569
|
-
DEBUG: "runtime",
|
|
14570
|
-
BACKEND: "runtime",
|
|
14571
|
-
FRONTEND: "runtime",
|
|
14572
|
-
// Found via `rg process\.env\.[A-Z0-9_]+ src ee` (Step 3 of the task brief):
|
|
14573
|
-
AUTH_MODE: "runtime",
|
|
14574
|
-
// "password" | "otp" mode selector, echoed by GET /config
|
|
14575
|
-
// Platform fallback model for POST /claims/check when the request names no
|
|
14576
|
-
// model and no agent config supplies one. It is a model IDENTIFIER, not a
|
|
14577
|
-
// credential: knowing the string grants access to nothing, because reaching
|
|
14578
|
-
// that model still needs the deployment's own proxy credentials
|
|
14579
|
-
// (LITELLM_MASTER_KEY / EXULU_API_KEY, both classified secret) and passes
|
|
14580
|
-
// through resolveModel's catalog. All it changes is which model a check
|
|
14581
|
-
// runs on — behaviour, which is this class's definition. Same reasoning as
|
|
14582
|
-
// EXULU_ENTITY_EXTRACTION_MODEL, TRANSCRIPTION_MODEL and TTS_MODEL below.
|
|
14583
|
-
CLAIM_CHECK_DEFAULT_MODEL: "runtime",
|
|
14584
|
-
// Request deadline (ms) for POST /claims/check, overriding routes.ts's
|
|
14585
|
-
// 60,000 default. A number of milliseconds is a setting, not a credential —
|
|
14586
|
-
// knowing it grants no access, it only changes how long the handler waits
|
|
14587
|
-
// before cancelling and returning 504. Same reasoning as
|
|
14588
|
-
// CLAIM_CHECK_DEFAULT_MODEL above.
|
|
14589
|
-
CLAIM_CHECK_TIMEOUT_MS: "runtime",
|
|
14590
|
-
DISABLE_SCHEMA_UPDATE: "runtime",
|
|
14591
|
-
// LiteLLM child-process flag
|
|
14592
|
-
EXULU_ENTITY_EXTRACTION_MODEL: "runtime",
|
|
14593
|
-
// Request-rate ceilings for external users, classified exactly as their
|
|
14594
|
-
// guest counterparts below: a number of requests is a setting, not a
|
|
14595
|
-
// credential. Arrived with the external-rate-limit PR, which predates this
|
|
14596
|
-
// inventory and so could not have classified them itself.
|
|
14597
|
-
EXULU_EXTERNAL_RATE_PER_HOUR: "runtime",
|
|
14598
|
-
EXULU_EXTERNAL_RATE_PER_MINUTE: "runtime",
|
|
14599
|
-
EXULU_GUEST_MAX_MESSAGE_CHARS: "runtime",
|
|
14600
|
-
EXULU_GUEST_MAX_TOTAL_CHARS: "runtime",
|
|
14601
|
-
EXULU_GUEST_RATE_PER_HOUR: "runtime",
|
|
14602
|
-
EXULU_GUEST_RATE_PER_MINUTE: "runtime",
|
|
14603
|
-
EXULU_REQUIRE_SANDBOX: "runtime",
|
|
14604
|
-
EXULU_TRUST_PROXY: "runtime",
|
|
14605
|
-
EXULU_USE_LITELLM: "runtime",
|
|
14606
|
-
EXULU_VS_TIMING: "runtime",
|
|
14607
|
-
LITELLM_BASE_URL: "runtime",
|
|
14608
|
-
LITELLM_CONFIG_PATH: "runtime",
|
|
14609
|
-
LITELLM_HOST: "runtime",
|
|
14610
|
-
LITELLM_PORT: "runtime",
|
|
14611
|
-
LITELLM_UI_PATH: "runtime",
|
|
14612
|
-
NEXT_PUBLIC_AGENT_VISUALIZATION: "runtime",
|
|
14613
|
-
POSTGRES_DB_HOST: "runtime",
|
|
14614
|
-
POSTGRES_DB_NAME: "runtime",
|
|
14615
|
-
POSTGRES_DB_PORT: "runtime",
|
|
14616
|
-
POSTGRES_DB_SSL: "runtime",
|
|
14617
|
-
PUBLIC_API_BASE_URL: "runtime",
|
|
14618
|
-
RECALL_REGION: "runtime",
|
|
14619
|
-
RECALL_RECORDING_RETENTION_HOURS: "runtime",
|
|
14620
|
-
RECALL_STORE_VIDEO_LOCALLY: "runtime",
|
|
14621
|
-
REDIS_HOST: "runtime",
|
|
14622
|
-
REDIS_PORT: "runtime",
|
|
14623
|
-
SERVER_ROOT_PATH: "runtime",
|
|
14624
|
-
// OTLP endpoints, not credentials — the token above is the credential. They
|
|
14625
|
-
// are credential-SHAPED (`_URL`), so they need a line here for the
|
|
14626
|
-
// documentation reconciliation test to pass; `runtime` is the honest answer.
|
|
14627
|
-
SIGNOZ_TRACES_URL: "runtime",
|
|
14628
|
-
SIGNOZ_LOGS_URL: "runtime",
|
|
14629
|
-
SMTP_FROM: "runtime",
|
|
14630
|
-
SMTP_HOST: "runtime",
|
|
14631
|
-
SMTP_PORT: "runtime",
|
|
14632
|
-
SMTP_SECURE: "runtime",
|
|
14633
|
-
TOTAL_MAX_RECORDINGS_DURATION_PER_MONTH: "runtime",
|
|
14634
|
-
TRANSCRIPTION_MODEL: "runtime",
|
|
14635
|
-
TRANSCRIPTION_SERVER: "runtime",
|
|
14636
|
-
TTS_MODEL: "runtime",
|
|
14637
|
-
TTS_VOICE: "runtime",
|
|
14638
|
-
WHISPER_HOST: "runtime",
|
|
14639
|
-
WHISPER_PORT: "runtime"
|
|
14892
|
+
// ee/invoke-skills/safe-fs.ts
|
|
14893
|
+
import { basename as basename2, dirname as dirname2, isAbsolute, join as join3, resolve as resolve3, sep as sep2 } from "path";
|
|
14894
|
+
var UnsafeSessionPathError = class extends Error {
|
|
14895
|
+
constructor(message) {
|
|
14896
|
+
super(message);
|
|
14897
|
+
this.name = "UnsafeSessionPathError";
|
|
14898
|
+
}
|
|
14640
14899
|
};
|
|
14641
|
-
var
|
|
14642
|
-
var
|
|
14643
|
-
|
|
14644
|
-
|
|
14645
|
-
|
|
14646
|
-
|
|
14647
|
-
|
|
14648
|
-
|
|
14649
|
-
|
|
14650
|
-
|
|
14651
|
-
|
|
14652
|
-
|
|
14653
|
-
}
|
|
14654
|
-
|
|
14655
|
-
|
|
14656
|
-
|
|
14657
|
-
|
|
14658
|
-
|
|
14659
|
-
|
|
14660
|
-
|
|
14900
|
+
var errCode2 = (err3) => err3?.code;
|
|
14901
|
+
var isInside = (root, path3) => path3 === root || path3.startsWith(root + sep2);
|
|
14902
|
+
async function readRegularFileInside(sessionDir, path3) {
|
|
14903
|
+
const skip = (why) => {
|
|
14904
|
+
console.warn(`[SKILLS] Not reading ${path3} back from the sandbox: ${why}.`);
|
|
14905
|
+
return null;
|
|
14906
|
+
};
|
|
14907
|
+
let root;
|
|
14908
|
+
let parent;
|
|
14909
|
+
try {
|
|
14910
|
+
root = await realpath(sessionDir);
|
|
14911
|
+
parent = await realpath(dirname2(path3));
|
|
14912
|
+
} catch {
|
|
14913
|
+
return skip("path does not resolve");
|
|
14914
|
+
}
|
|
14915
|
+
if (!isInside(root, parent)) return skip("it resolves outside the session directory");
|
|
14916
|
+
let handle;
|
|
14917
|
+
try {
|
|
14918
|
+
handle = await open(
|
|
14919
|
+
path3,
|
|
14920
|
+
constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK | constants.O_NOCTTY
|
|
14921
|
+
);
|
|
14922
|
+
} catch (err3) {
|
|
14923
|
+
return skip(errCode2(err3) === "ELOOP" ? "it is a symbolic link" : `open failed (${errCode2(err3) ?? "unknown"})`);
|
|
14924
|
+
}
|
|
14925
|
+
try {
|
|
14926
|
+
const st = await handle.stat();
|
|
14927
|
+
if (!st.isFile()) return skip("it is not a regular file");
|
|
14928
|
+
if (st.size > MAX_ADOPT_UPLOAD_BYTES) {
|
|
14929
|
+
return skip(`it is larger than the ${MAX_ADOPT_UPLOAD_BYTES / (1024 * 1024)}MB upload limit (${st.size} bytes)`);
|
|
14661
14930
|
}
|
|
14662
|
-
|
|
14931
|
+
const fdPath = await readlink(`/proc/self/fd/${handle.fd}`).catch(() => null);
|
|
14932
|
+
if (fdPath !== null) {
|
|
14933
|
+
if (!isInside(root, fdPath)) return skip("it resolves outside the session directory");
|
|
14934
|
+
} else {
|
|
14935
|
+
const again = await realpath(dirname2(path3)).catch(() => null);
|
|
14936
|
+
if (again === null || !isInside(root, again)) return skip("it resolves outside the session directory");
|
|
14937
|
+
}
|
|
14938
|
+
const chunks = [];
|
|
14939
|
+
let total = 0;
|
|
14940
|
+
const chunkSize = Math.min(Math.max(st.size + 1, 64 * 1024), 1024 * 1024);
|
|
14941
|
+
for (; ; ) {
|
|
14942
|
+
const chunk = Buffer.allocUnsafe(chunkSize);
|
|
14943
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.length, null);
|
|
14944
|
+
if (bytesRead === 0) break;
|
|
14945
|
+
total += bytesRead;
|
|
14946
|
+
if (total > MAX_ADOPT_UPLOAD_BYTES) return skip("it grew past the upload limit while being read");
|
|
14947
|
+
chunks.push(chunk.subarray(0, bytesRead));
|
|
14948
|
+
}
|
|
14949
|
+
return Buffer.concat(chunks, total);
|
|
14950
|
+
} finally {
|
|
14951
|
+
await handle.close().catch(() => {
|
|
14952
|
+
});
|
|
14663
14953
|
}
|
|
14664
|
-
|
|
14665
|
-
|
|
14666
|
-
|
|
14667
|
-
|
|
14668
|
-
|
|
14669
|
-
|
|
14670
|
-
|
|
14954
|
+
}
|
|
14955
|
+
function safeSegments(relativePath) {
|
|
14956
|
+
if (!relativePath || isAbsolute(relativePath) || relativePath.includes("\\")) {
|
|
14957
|
+
throw new UnsafeSessionPathError(`Refusing path "${relativePath}": not a plain relative path.`);
|
|
14958
|
+
}
|
|
14959
|
+
const segments = relativePath.split("/").filter((s) => s !== "" && s !== ".");
|
|
14960
|
+
if (segments.length === 0 || segments.includes("..")) {
|
|
14961
|
+
throw new UnsafeSessionPathError(`Refusing path "${relativePath}": it contains a ".." segment or no file name.`);
|
|
14962
|
+
}
|
|
14963
|
+
return segments;
|
|
14964
|
+
}
|
|
14965
|
+
async function ensureDirInside(sessionDir, segments) {
|
|
14966
|
+
const root = await realpath(sessionDir);
|
|
14967
|
+
let current = sessionDir;
|
|
14968
|
+
for (const segment of segments) {
|
|
14969
|
+
current = join3(current, segment);
|
|
14970
|
+
let st = await lstat2(current).catch((err3) => errCode2(err3) === "ENOENT" ? null : Promise.reject(err3));
|
|
14971
|
+
if (!st) {
|
|
14972
|
+
try {
|
|
14973
|
+
await mkdir2(current);
|
|
14974
|
+
} catch (err3) {
|
|
14975
|
+
if (errCode2(err3) !== "EEXIST") throw err3;
|
|
14976
|
+
}
|
|
14977
|
+
st = await lstat2(current);
|
|
14978
|
+
}
|
|
14979
|
+
if (!st.isDirectory()) {
|
|
14980
|
+
throw new UnsafeSessionPathError(`Refusing to write under ${current}: it is not a real directory.`);
|
|
14671
14981
|
}
|
|
14672
|
-
env[name] = value;
|
|
14673
|
-
grantedNames.push(name);
|
|
14674
14982
|
}
|
|
14675
|
-
|
|
14676
|
-
|
|
14677
|
-
|
|
14678
|
-
|
|
14679
|
-
|
|
14680
|
-
skippedNames: skippedNames.sort()
|
|
14681
|
-
};
|
|
14682
|
-
};
|
|
14683
|
-
|
|
14684
|
-
// ee/invoke-skills/binary-file-guard.ts
|
|
14685
|
-
var BINARY_DOCUMENT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
14686
|
-
".pdf",
|
|
14687
|
-
".doc",
|
|
14688
|
-
".docx",
|
|
14689
|
-
".xls",
|
|
14690
|
-
".xlsx",
|
|
14691
|
-
".ppt",
|
|
14692
|
-
".pptx",
|
|
14693
|
-
".odt",
|
|
14694
|
-
".ods",
|
|
14695
|
-
".odp",
|
|
14696
|
-
".zip",
|
|
14697
|
-
".gz",
|
|
14698
|
-
".png",
|
|
14699
|
-
".jpg",
|
|
14700
|
-
".jpeg",
|
|
14701
|
-
".gif",
|
|
14702
|
-
".bmp",
|
|
14703
|
-
".tif",
|
|
14704
|
-
".tiff",
|
|
14705
|
-
".webp"
|
|
14706
|
-
]);
|
|
14707
|
-
function isBinaryDocumentPath(path3) {
|
|
14708
|
-
const dot = path3.lastIndexOf(".");
|
|
14709
|
-
if (dot < 0) return false;
|
|
14710
|
-
return BINARY_DOCUMENT_EXTENSIONS.has(path3.slice(dot).toLowerCase());
|
|
14983
|
+
const real = await realpath(current);
|
|
14984
|
+
if (!isInside(root, real)) {
|
|
14985
|
+
throw new UnsafeSessionPathError(`Refusing to write under ${current}: it resolves outside the session directory.`);
|
|
14986
|
+
}
|
|
14987
|
+
return current;
|
|
14711
14988
|
}
|
|
14712
|
-
function
|
|
14713
|
-
|
|
14989
|
+
async function writeFileInside(sessionDir, relativePath, bytes, opts = {}) {
|
|
14990
|
+
const segments = safeSegments(relativePath);
|
|
14991
|
+
const name = segments[segments.length - 1];
|
|
14992
|
+
const parent = await ensureDirInside(sessionDir, segments.slice(0, -1));
|
|
14993
|
+
const destination = join3(parent, name);
|
|
14994
|
+
if (opts.notUnder !== void 0 && await landsInside(sessionDir, destination, opts.notUnder)) {
|
|
14995
|
+
throw new UnsafeSessionPathError(`Refusing to write ${destination}: it lands in ${opts.notUnder}/.`);
|
|
14996
|
+
}
|
|
14997
|
+
const temp = join3(parent, `.exulu-write-${randomBytes3(8).toString("hex")}`);
|
|
14998
|
+
await writeFile2(temp, bytes, { flag: "wx" });
|
|
14999
|
+
try {
|
|
15000
|
+
await rename2(temp, destination);
|
|
15001
|
+
} catch (err3) {
|
|
15002
|
+
await unlink(temp).catch(() => {
|
|
15003
|
+
});
|
|
15004
|
+
throw err3;
|
|
15005
|
+
}
|
|
15006
|
+
return destination;
|
|
14714
15007
|
}
|
|
14715
|
-
function
|
|
14716
|
-
|
|
15008
|
+
async function ensureRealDirectory(sessionDir, relativeDir) {
|
|
15009
|
+
const segments = safeSegments(relativeDir);
|
|
15010
|
+
let current = sessionDir;
|
|
15011
|
+
for (const segment of segments) {
|
|
15012
|
+
current = join3(current, segment);
|
|
15013
|
+
const st = await lstat2(current).catch(() => null);
|
|
15014
|
+
if (st && !st.isDirectory()) {
|
|
15015
|
+
console.warn(`[SKILLS] ${current} is not a real directory; replacing it.`);
|
|
15016
|
+
await unlink(current);
|
|
15017
|
+
}
|
|
15018
|
+
}
|
|
15019
|
+
return ensureDirInside(sessionDir, segments);
|
|
14717
15020
|
}
|
|
14718
|
-
|
|
14719
|
-
|
|
14720
|
-
|
|
14721
|
-
|
|
14722
|
-
|
|
14723
|
-
|
|
14724
|
-
)
|
|
14725
|
-
|
|
14726
|
-
var selectGrantedVariables = (rows) => {
|
|
14727
|
-
const out = {};
|
|
14728
|
-
for (const row of rows) {
|
|
14729
|
-
if (!row?.name) continue;
|
|
14730
|
-
if (row.allow_skill_access !== true) continue;
|
|
14731
|
-
if (row.name.startsWith("_")) continue;
|
|
14732
|
-
if (row.name.includes("=")) continue;
|
|
14733
|
-
if (typeof row.value !== "string") continue;
|
|
14734
|
-
out[row.name] = row.value;
|
|
15021
|
+
async function removeEntryInside(sessionDir, relativePath) {
|
|
15022
|
+
const segments = safeSegments(relativePath);
|
|
15023
|
+
const target = join3(sessionDir, ...segments);
|
|
15024
|
+
const root = await realpath(sessionDir);
|
|
15025
|
+
const parentReal = await realpath(dirname2(target)).catch(() => null);
|
|
15026
|
+
if (parentReal === null) return;
|
|
15027
|
+
if (!isInside(root, parentReal)) {
|
|
15028
|
+
throw new UnsafeSessionPathError(`Refusing to remove ${target}: its parent resolves outside the session directory.`);
|
|
14735
15029
|
}
|
|
14736
|
-
|
|
14737
|
-
|
|
14738
|
-
|
|
14739
|
-
|
|
14740
|
-
|
|
14741
|
-
var OS_ENVIRON_DIRECTIVE = /os\.environ\/([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
14742
|
-
var parseOsEnvironNames = (yamlText) => {
|
|
14743
|
-
const found = /* @__PURE__ */ new Set();
|
|
14744
|
-
for (const match of yamlText.matchAll(OS_ENVIRON_DIRECTIVE)) {
|
|
14745
|
-
const name = match[1];
|
|
14746
|
-
if (!name) continue;
|
|
14747
|
-
if (ENV_CLASSIFICATION[name] === "runtime") continue;
|
|
14748
|
-
found.add(name);
|
|
15030
|
+
const st = await lstat2(target).catch(() => null);
|
|
15031
|
+
if (!st) return;
|
|
15032
|
+
if (!st.isDirectory()) {
|
|
15033
|
+
await unlink(target);
|
|
15034
|
+
return;
|
|
14749
15035
|
}
|
|
14750
|
-
|
|
14751
|
-
}
|
|
14752
|
-
var
|
|
15036
|
+
await discardEntry(target, sessionDir);
|
|
15037
|
+
}
|
|
15038
|
+
var MAX_LINK_HOPS = 40;
|
|
15039
|
+
async function realLocation(path3, hops = { n: 0 }) {
|
|
14753
15040
|
try {
|
|
14754
|
-
|
|
14755
|
-
return parseOsEnvironNames(readFileSync2(configPath, "utf8"));
|
|
15041
|
+
return await realpath(path3);
|
|
14756
15042
|
} catch (err3) {
|
|
14757
|
-
|
|
14758
|
-
`[SKILLS] Could not read LiteLLM config at ${configPath} to collect os.environ/ credential names; the skill environment falls back to the static secret inventory.`,
|
|
14759
|
-
err3
|
|
14760
|
-
);
|
|
14761
|
-
return [];
|
|
15043
|
+
if (errCode2(err3) !== "ENOENT") throw err3;
|
|
14762
15044
|
}
|
|
14763
|
-
|
|
14764
|
-
|
|
14765
|
-
|
|
14766
|
-
|
|
14767
|
-
import path from "path";
|
|
14768
|
-
var normalizePrefix = (p) => {
|
|
14769
|
-
const raw = (p ?? "audit").trim().replace(/^\/+|\/+$/g, "");
|
|
14770
|
-
return `${raw || "audit"}/`;
|
|
14771
|
-
};
|
|
14772
|
-
var hasAllS3Fields = (t) => !!t && !!t.s3region && !!t.s3key && !!t.s3secret && !!t.s3Bucket;
|
|
14773
|
-
var resolveAuditConfig = (config) => {
|
|
14774
|
-
const a = config.audit;
|
|
14775
|
-
if (!a || a.enabled !== true) return null;
|
|
14776
|
-
const dedicated = hasAllS3Fields(a.s3);
|
|
14777
|
-
const source = dedicated ? a.s3 : config.fileUploads;
|
|
14778
|
-
if (!hasAllS3Fields(source)) {
|
|
14779
|
-
throw new Error(
|
|
14780
|
-
"[EXULU] audit.enabled is true but no S3 target is configured. Set config.audit.s3 or config.fileUploads."
|
|
14781
|
-
);
|
|
15045
|
+
const st = await lstat2(path3).catch((err3) => errCode2(err3) === "ENOENT" ? null : Promise.reject(err3));
|
|
15046
|
+
if (st?.isSymbolicLink()) {
|
|
15047
|
+
if (++hops.n > MAX_LINK_HOPS) throw Object.assign(new Error(`Too many links resolving ${path3}`), { code: "ELOOP" });
|
|
15048
|
+
return realLocation(resolve3(dirname2(path3), await readlink(path3)), hops);
|
|
14782
15049
|
}
|
|
14783
|
-
|
|
14784
|
-
|
|
15050
|
+
const parent = dirname2(path3);
|
|
15051
|
+
if (parent === path3) return path3;
|
|
15052
|
+
return join3(await realLocation(parent, hops), basename2(path3));
|
|
15053
|
+
}
|
|
15054
|
+
async function landsInside(sessionDir, path3, relativeDir) {
|
|
15055
|
+
const segments = safeSegments(relativeDir);
|
|
15056
|
+
try {
|
|
15057
|
+
const entry = await realLocation(join3(sessionDir, ...segments));
|
|
15058
|
+
const target = await realLocation(resolve3(path3));
|
|
15059
|
+
return isInside(entry, target);
|
|
15060
|
+
} catch (err3) {
|
|
15061
|
+
return errCode2(err3) !== "ENOTDIR";
|
|
14785
15062
|
}
|
|
14786
|
-
|
|
14787
|
-
return {
|
|
14788
|
-
target: {
|
|
14789
|
-
s3region: source.s3region,
|
|
14790
|
-
s3key: source.s3key,
|
|
14791
|
-
s3secret: source.s3secret,
|
|
14792
|
-
s3Bucket: source.s3Bucket,
|
|
14793
|
-
s3prefix: normalizePrefix(source.s3prefix),
|
|
14794
|
-
...source.s3endpoint ? { s3endpoint: source.s3endpoint } : {}
|
|
14795
|
-
},
|
|
14796
|
-
retentionDays: a.retentionDays,
|
|
14797
|
-
manageLifecycle: a.manageLifecycle ?? !usingSharedFileUploadsBucket,
|
|
14798
|
-
usingSharedFileUploadsBucket,
|
|
14799
|
-
spoolDir: a.spoolDir ?? path.join(os.tmpdir(), "exulu-audit-spool"),
|
|
14800
|
-
flush: {
|
|
14801
|
-
maxRecords: a.flush?.maxRecords ?? 100,
|
|
14802
|
-
maxIntervalMs: a.flush?.maxIntervalMs ?? 5e3
|
|
14803
|
-
},
|
|
14804
|
-
payload: {
|
|
14805
|
-
maxBytes: a.payload?.maxBytes ?? 32768,
|
|
14806
|
-
captureOutput: a.payload?.captureOutput ?? true,
|
|
14807
|
-
redactKeys: a.payload?.redactKeys ?? []
|
|
14808
|
-
},
|
|
14809
|
-
failureMode: a.failureMode ?? "open",
|
|
14810
|
-
toolCalls: {
|
|
14811
|
-
enabled: a.sources?.toolCalls?.enabled ?? true,
|
|
14812
|
-
include: a.sources?.toolCalls?.include ?? [],
|
|
14813
|
-
exclude: a.sources?.toolCalls?.exclude ?? []
|
|
14814
|
-
},
|
|
14815
|
-
skillSandbox: {
|
|
14816
|
-
enabled: a.sources?.skillSandbox?.enabled ?? false
|
|
14817
|
-
}
|
|
14818
|
-
};
|
|
14819
|
-
};
|
|
15063
|
+
}
|
|
14820
15064
|
|
|
14821
|
-
//
|
|
14822
|
-
|
|
14823
|
-
|
|
14824
|
-
|
|
14825
|
-
|
|
14826
|
-
|
|
14827
|
-
|
|
14828
|
-
var
|
|
14829
|
-
var
|
|
14830
|
-
|
|
14831
|
-
|
|
14832
|
-
|
|
14833
|
-
|
|
14834
|
-
|
|
14835
|
-
|
|
14836
|
-
|
|
14837
|
-
|
|
14838
|
-
|
|
14839
|
-
|
|
14840
|
-
|
|
14841
|
-
|
|
14842
|
-
|
|
14843
|
-
|
|
14844
|
-
|
|
14845
|
-
|
|
14846
|
-
|
|
14847
|
-
|
|
14848
|
-
|
|
14849
|
-
|
|
14850
|
-
|
|
14851
|
-
return
|
|
14852
|
-
|
|
14853
|
-
|
|
14854
|
-
|
|
14855
|
-
|
|
15065
|
+
// ee/invoke-skills/skill-actions/tool.ts
|
|
15066
|
+
var RUN_SKILL_ACTION_TOOL_ID = "run_skill_action";
|
|
15067
|
+
var TEXT_MAX_CHARS = 1e4;
|
|
15068
|
+
var ITEMS_DEFAULT_LIMIT = 50;
|
|
15069
|
+
var ITEMS_MAX_LIMIT = 500;
|
|
15070
|
+
var ARGS_FILE_STEM = "args";
|
|
15071
|
+
var isPlainObject3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15072
|
+
var listOrNone = (names) => names.length ? names.join(", ") : "(none)";
|
|
15073
|
+
var createRunSkillActionTool = (deps) => {
|
|
15074
|
+
const { handle, loaded, contexts, connectedContextIds, truncate, resultCharLimit } = deps;
|
|
15075
|
+
const description = `Run a declared action of a skill. The platform reads the knowledge-base items the action needs with the current user's rights, hands them to the skill's script as files, runs the script in the session sandbox and returns its exit code and output (files it creates come back as download links). Pass ids, filters and text only in \`inputs\`. Item inputs take an id string or { external_id }; items inputs take { where?, limit? } (default ${ITEMS_DEFAULT_LIMIT}, max ${ITEMS_MAX_LIMIT}); text inputs take a string (max ${TEXT_MAX_CHARS} characters). Available actions:
|
|
15076
|
+
` + describeActions(loaded);
|
|
15077
|
+
return new ExuluTool({
|
|
15078
|
+
id: RUN_SKILL_ACTION_TOOL_ID,
|
|
15079
|
+
name: RUN_SKILL_ACTION_TOOL_ID,
|
|
15080
|
+
category: "skills",
|
|
15081
|
+
description,
|
|
15082
|
+
type: "function",
|
|
15083
|
+
inputSchema: z18.object({
|
|
15084
|
+
skill: z18.string().describe("The skill's name, as listed in this description."),
|
|
15085
|
+
action: z18.string().describe("The action's name within that skill."),
|
|
15086
|
+
inputs: z18.record(z18.string(), z18.unknown()).optional().describe("The action's inputs by name, as listed in this description.")
|
|
15087
|
+
}),
|
|
15088
|
+
config: [],
|
|
15089
|
+
needsApproval: false,
|
|
15090
|
+
execute: async (params) => {
|
|
15091
|
+
const refuse = (message) => ({ result: `Not run: ${message}` });
|
|
15092
|
+
const skillName = params?.skill;
|
|
15093
|
+
const actionName = params?.action;
|
|
15094
|
+
if (typeof skillName !== "string" || !Object.hasOwn(loaded.bySkill, skillName)) {
|
|
15095
|
+
return refuse(
|
|
15096
|
+
`unknown skill "${String(skillName)}". Available: ${listOrNone(Object.keys(loaded.bySkill))}.`
|
|
15097
|
+
);
|
|
15098
|
+
}
|
|
15099
|
+
const skill = loaded.bySkill[skillName];
|
|
15100
|
+
if (typeof actionName !== "string" || !Object.hasOwn(skill.actions, actionName)) {
|
|
15101
|
+
return refuse(
|
|
15102
|
+
`unknown action "${String(actionName)}" for skill "${skillName}". Available: ${listOrNone(Object.keys(skill.actions))}.`
|
|
15103
|
+
);
|
|
15104
|
+
}
|
|
15105
|
+
const action = skill.actions[actionName];
|
|
15106
|
+
const label = `${skillName} / ${actionName}`;
|
|
15107
|
+
const declaredNames = Object.keys(action.inputs);
|
|
15108
|
+
const inputList = `Inputs of ${label}: ${listOrNone(declaredNames)}.`;
|
|
15109
|
+
const given = params?.inputs === void 0 || params?.inputs === null ? {} : params.inputs;
|
|
15110
|
+
if (!isPlainObject3(given)) {
|
|
15111
|
+
return refuse(`inputs must be an object keyed by input name. ${inputList}`);
|
|
15112
|
+
}
|
|
15113
|
+
for (const key of Object.keys(given)) {
|
|
15114
|
+
if (!Object.hasOwn(action.inputs, key)) {
|
|
15115
|
+
return refuse(`unknown input "${key}". ${inputList}`);
|
|
15116
|
+
}
|
|
15117
|
+
}
|
|
15118
|
+
const argsInput = Object.hasOwn(action.inputs, ARGS_FILE_STEM) ? action.inputs[ARGS_FILE_STEM] : void 0;
|
|
15119
|
+
if (argsInput && argsInput.type !== "text") {
|
|
15120
|
+
return refuse(
|
|
15121
|
+
`${label} cannot run: its ${argsInput.type} input is named "${ARGS_FILE_STEM}", which collides with ${ARGS_FILE_STEM}.json (the file of the text inputs). The skill's actions.yaml must rename it.`
|
|
15122
|
+
);
|
|
15123
|
+
}
|
|
15124
|
+
const resolved = [];
|
|
15125
|
+
for (const [name, input] of Object.entries(action.inputs)) {
|
|
15126
|
+
const value = Object.hasOwn(given, name) ? given[name] : void 0;
|
|
15127
|
+
if (input.type === "text") {
|
|
15128
|
+
if (value === void 0 || value === null) {
|
|
15129
|
+
if (input.required) return refuse(`input "${name}" is required. ${inputList}`);
|
|
15130
|
+
continue;
|
|
15131
|
+
}
|
|
15132
|
+
if (typeof value !== "string") return refuse(`input "${name}" must be a string.`);
|
|
15133
|
+
if (value.length > TEXT_MAX_CHARS) {
|
|
15134
|
+
return refuse(`input "${name}" is ${value.length} characters long; the maximum is ${TEXT_MAX_CHARS}.`);
|
|
15135
|
+
}
|
|
15136
|
+
resolved.push({ name, type: "text", value });
|
|
14856
15137
|
continue;
|
|
14857
15138
|
}
|
|
14858
|
-
|
|
15139
|
+
const context = contexts.find((c) => c.id === input.context);
|
|
15140
|
+
if (!connectedContextIds.has(input.context) || !context) {
|
|
15141
|
+
return refuse(
|
|
15142
|
+
`input "${name}" reads the knowledge base "${input.context}", which is not connected to this agent.`
|
|
15143
|
+
);
|
|
15144
|
+
}
|
|
15145
|
+
if (input.type === "item") {
|
|
15146
|
+
if (value === void 0 || value === null) return refuse(`input "${name}" is required. ${inputList}`);
|
|
15147
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
15148
|
+
resolved.push({ name, type: "item", context, input, ref: { id: value } });
|
|
15149
|
+
} else if (isPlainObject3(value) && Object.keys(value).length === 1 && typeof value.external_id === "string" && value.external_id.trim() !== "") {
|
|
15150
|
+
resolved.push({ name, type: "item", context, input, ref: { external_id: value.external_id } });
|
|
15151
|
+
} else {
|
|
15152
|
+
return refuse(`input "${name}" must be an item id (a non-empty string) or { "external_id": "<id>" }.`);
|
|
15153
|
+
}
|
|
15154
|
+
continue;
|
|
15155
|
+
}
|
|
15156
|
+
if (value !== void 0 && value !== null && !isPlainObject3(value)) {
|
|
15157
|
+
return refuse(`input "${name}" must be { "where"?: {...}, "limit"?: number } or omitted.`);
|
|
15158
|
+
}
|
|
15159
|
+
const spec = value ?? {};
|
|
15160
|
+
const surplus = Object.keys(spec).filter((k) => k !== "where" && k !== "limit");
|
|
15161
|
+
if (surplus.length) {
|
|
15162
|
+
return refuse(`input "${name}" has unknown key "${surplus[0]}"; it takes only "where" and "limit".`);
|
|
15163
|
+
}
|
|
15164
|
+
if (spec.where !== void 0 && !isPlainObject3(spec.where)) {
|
|
15165
|
+
return refuse(`input "${name}": "where" must be an object of field filters.`);
|
|
15166
|
+
}
|
|
15167
|
+
if (spec.limit !== void 0 && !(typeof spec.limit === "number" && Number.isInteger(spec.limit) && spec.limit >= 1)) {
|
|
15168
|
+
return refuse(`input "${name}": "limit" must be a whole number of at least 1 (maximum ${ITEMS_MAX_LIMIT}).`);
|
|
15169
|
+
}
|
|
15170
|
+
const fixed = input.where ?? {};
|
|
15171
|
+
const callerWhere = spec.where ?? {};
|
|
15172
|
+
const clash = Object.keys(callerWhere).find((k) => Object.hasOwn(fixed, k));
|
|
15173
|
+
if (clash) {
|
|
15174
|
+
return refuse(
|
|
15175
|
+
`input "${name}": the field "${clash}" is already filtered by the action itself and cannot be filtered again.`
|
|
15176
|
+
);
|
|
15177
|
+
}
|
|
15178
|
+
const where = { ...fixed, ...callerWhere };
|
|
15179
|
+
resolved.push({
|
|
15180
|
+
name,
|
|
15181
|
+
type: "items",
|
|
15182
|
+
context,
|
|
15183
|
+
input,
|
|
15184
|
+
where: Object.keys(where).length ? where : void 0,
|
|
15185
|
+
limit: spec.limit
|
|
15186
|
+
});
|
|
15187
|
+
}
|
|
15188
|
+
const caller = { user: params?.user, req: params?.req };
|
|
15189
|
+
const files = [];
|
|
15190
|
+
const warnings = [];
|
|
15191
|
+
const textArgs = {};
|
|
15192
|
+
for (const r of resolved) {
|
|
15193
|
+
if (r.type === "text") {
|
|
15194
|
+
textArgs[r.name] = r.value;
|
|
15195
|
+
continue;
|
|
15196
|
+
}
|
|
15197
|
+
if (r.type === "item") {
|
|
15198
|
+
const outcome2 = await readContextItem(r.context, { ...r.ref, fields: r.input.fields }, caller);
|
|
15199
|
+
if (!outcome2.ok) return refuse(`input "${r.name}": ${outcome2.message}`);
|
|
15200
|
+
files.push({ file: `${r.name}.json`, content: outcome2.item });
|
|
15201
|
+
continue;
|
|
15202
|
+
}
|
|
15203
|
+
const outcome = await findContextItems(
|
|
15204
|
+
r.context,
|
|
15205
|
+
{ where: r.where, limit: r.limit ?? ITEMS_DEFAULT_LIMIT, maxLimit: ITEMS_MAX_LIMIT, fields: r.input.fields },
|
|
15206
|
+
caller
|
|
15207
|
+
);
|
|
15208
|
+
if (!outcome.ok) return refuse(`input "${r.name}": ${outcome.message}`);
|
|
15209
|
+
files.push({
|
|
15210
|
+
file: `${r.name}.json`,
|
|
15211
|
+
content: { items: outcome.items, limit: outcome.limit, truncated: outcome.truncated }
|
|
15212
|
+
});
|
|
15213
|
+
if (outcome.truncated) warnings.push(`warning: input "${r.name}" was cut at ${outcome.limit} items`);
|
|
15214
|
+
}
|
|
15215
|
+
if (resolved.some((r) => r.type === "text")) {
|
|
15216
|
+
files.push({ file: `${ARGS_FILE_STEM}.json`, content: textArgs });
|
|
15217
|
+
}
|
|
15218
|
+
const sessionDir = handle.sessionDir;
|
|
15219
|
+
const runId = randomUUID6();
|
|
15220
|
+
const runRelative = `${ACTION_INPUTS_DIR}/${runId}`;
|
|
15221
|
+
try {
|
|
15222
|
+
const parent = await ensureRealDirectory(sessionDir, ACTION_INPUTS_DIR);
|
|
15223
|
+
await mkdir3(join4(parent, runId), { mode: 448 });
|
|
15224
|
+
for (const { file, content } of files) {
|
|
15225
|
+
await writeFileInside(sessionDir, `${runRelative}/${file}`, JSON.stringify(content));
|
|
15226
|
+
}
|
|
15227
|
+
const outcome = await handle.runCommand(action.run, {
|
|
15228
|
+
extraEnv: {
|
|
15229
|
+
EXULU_INPUTS_DIR: join4(sessionDir, runRelative),
|
|
15230
|
+
EXULU_SKILL_DIR: skill.skillDir
|
|
15231
|
+
},
|
|
15232
|
+
timeoutMs: action.timeoutSeconds * 1e3
|
|
15233
|
+
});
|
|
15234
|
+
const fixed = [`exit_code: ${outcome.exitCode}`];
|
|
15235
|
+
if (outcome.timedOut) fixed.push(`timed out after ${action.timeoutSeconds}s`);
|
|
15236
|
+
fixed.push(...warnings);
|
|
15237
|
+
const { output, block } = splitArtifactsBlock(
|
|
15238
|
+
outcome.stdout ?? "",
|
|
15239
|
+
(outcome.artifacts ?? []).some((a) => a.url)
|
|
15240
|
+
);
|
|
15241
|
+
return {
|
|
15242
|
+
result: fitResult({
|
|
15243
|
+
fixed,
|
|
15244
|
+
stdout: output,
|
|
15245
|
+
artifactsBlock: block,
|
|
15246
|
+
stderr: outcome.stderr ?? "",
|
|
15247
|
+
truncate,
|
|
15248
|
+
limit: resultCharLimit
|
|
15249
|
+
})
|
|
15250
|
+
};
|
|
15251
|
+
} finally {
|
|
15252
|
+
await removeEntryInside(sessionDir, runRelative).catch(
|
|
15253
|
+
(err3) => console.error(`[SKILLS] Could not remove the action inputs directory ${runRelative}:`, err3)
|
|
15254
|
+
);
|
|
14859
15255
|
}
|
|
14860
15256
|
}
|
|
14861
|
-
|
|
14862
|
-
};
|
|
14863
|
-
const getLifecycle = async () => c.send(new GetBucketLifecycleConfigurationCommand({ Bucket: target.s3Bucket }));
|
|
14864
|
-
const putLifecycle = async (config) => {
|
|
14865
|
-
await c.send(
|
|
14866
|
-
new PutBucketLifecycleConfigurationCommand({
|
|
14867
|
-
Bucket: target.s3Bucket,
|
|
14868
|
-
LifecycleConfiguration: config
|
|
14869
|
-
})
|
|
14870
|
-
);
|
|
14871
|
-
};
|
|
14872
|
-
return { putNdjson, getLifecycle, putLifecycle };
|
|
14873
|
-
};
|
|
14874
|
-
|
|
14875
|
-
// src/exulu/audit/lifecycle.ts
|
|
14876
|
-
var AUDIT_LIFECYCLE_RULE_ID = "exulu-audit-retention";
|
|
14877
|
-
var buildRule = (prefix, retentionDays) => ({
|
|
14878
|
-
ID: AUDIT_LIFECYCLE_RULE_ID,
|
|
14879
|
-
Filter: { Prefix: prefix },
|
|
14880
|
-
Status: "Enabled",
|
|
14881
|
-
Expiration: { Days: retentionDays }
|
|
14882
|
-
});
|
|
14883
|
-
var applyRetentionLifecycle = async (writer, opts) => {
|
|
14884
|
-
const rule = buildRule(opts.prefix, opts.retentionDays);
|
|
14885
|
-
const config = { Rules: [rule] };
|
|
14886
|
-
if (!opts.manage) {
|
|
14887
|
-
console.warn(
|
|
14888
|
-
`[EXULU] audit retention: not managing the S3 lifecycle for this bucket. Apply this rule manually:
|
|
14889
|
-
${JSON.stringify(config, null, 2)}`
|
|
14890
|
-
);
|
|
14891
|
-
return;
|
|
14892
|
-
}
|
|
14893
|
-
try {
|
|
14894
|
-
let existing = [];
|
|
14895
|
-
try {
|
|
14896
|
-
const current = await writer.getLifecycle();
|
|
14897
|
-
existing = (current?.Rules ?? []).filter((r) => r.ID !== AUDIT_LIFECYCLE_RULE_ID);
|
|
14898
|
-
} catch (error) {
|
|
14899
|
-
if (error?.name !== "NoSuchLifecycleConfiguration") throw error;
|
|
14900
|
-
}
|
|
14901
|
-
await writer.putLifecycle({ Rules: [...existing, rule] });
|
|
14902
|
-
console.log(`[EXULU] audit retention: S3 lifecycle set to expire "${opts.prefix}" after ${opts.retentionDays} days.`);
|
|
14903
|
-
} catch (error) {
|
|
14904
|
-
console.warn(
|
|
14905
|
-
`[EXULU] audit retention: could not set the S3 lifecycle (${error?.name ?? "error"}). Apply this rule manually:
|
|
14906
|
-
${JSON.stringify(config, null, 2)}`
|
|
14907
|
-
);
|
|
14908
|
-
}
|
|
15257
|
+
});
|
|
14909
15258
|
};
|
|
14910
|
-
|
|
14911
|
-
|
|
14912
|
-
|
|
14913
|
-
|
|
14914
|
-
|
|
14915
|
-
|
|
14916
|
-
|
|
14917
|
-
|
|
14918
|
-
|
|
14919
|
-
|
|
14920
|
-
|
|
14921
|
-
|
|
14922
|
-
|
|
14923
|
-
|
|
14924
|
-
|
|
14925
|
-
|
|
14926
|
-
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
|
|
15259
|
+
var RESULT_MARGIN_CHARS = 256;
|
|
15260
|
+
var STDERR_SHARE = 0.3;
|
|
15261
|
+
var fitResult = (p) => {
|
|
15262
|
+
const assemble = (out, err3) => [...p.fixed, `stdout:
|
|
15263
|
+
${out}${p.artifactsBlock}`, `stderr:
|
|
15264
|
+
${err3}`].join("\n");
|
|
15265
|
+
const size = (text) => JSON.stringify({ result: text }).length;
|
|
15266
|
+
const full = assemble(p.stdout, p.stderr);
|
|
15267
|
+
if (size(full) <= p.limit) return full;
|
|
15268
|
+
const room = p.limit - size(assemble("", "")) - RESULT_MARGIN_CHARS;
|
|
15269
|
+
if (room <= 0) return assemble("", "");
|
|
15270
|
+
let errBudget = Math.min(p.stderr.length, Math.floor(room * STDERR_SHARE));
|
|
15271
|
+
let outBudget = Math.min(p.stdout.length, room - errBudget);
|
|
15272
|
+
errBudget = Math.min(p.stderr.length, room - outBudget);
|
|
15273
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
15274
|
+
const out = p.stdout.length <= outBudget ? p.stdout : p.truncate(p.stdout, "stdout", Math.max(1, outBudget));
|
|
15275
|
+
const err3 = p.stderr.length <= errBudget ? p.stderr : p.truncate(p.stderr, "stderr", Math.max(1, errBudget));
|
|
15276
|
+
const text = assemble(out, err3);
|
|
15277
|
+
const over = size(text) - p.limit;
|
|
15278
|
+
if (over <= 0) return text;
|
|
15279
|
+
const outCut = out !== p.stdout;
|
|
15280
|
+
const errCut = err3 !== p.stderr;
|
|
15281
|
+
const total = (outCut ? outBudget : 0) + (errCut ? errBudget : 0);
|
|
15282
|
+
const scale = Math.max(0, (total - over - RESULT_MARGIN_CHARS) / Math.max(1, total)) * 0.9;
|
|
15283
|
+
if (outCut) outBudget = Math.floor(outBudget * scale);
|
|
15284
|
+
if (errCut) errBudget = Math.floor(errBudget * scale);
|
|
15285
|
+
}
|
|
15286
|
+
return assemble("", "");
|
|
15287
|
+
};
|
|
15288
|
+
var disabledSearchContexts = (searchConfig) => {
|
|
15289
|
+
const row = Array.isArray(searchConfig?.config) ? searchConfig.config.find((c) => c?.name === "knowledge_bases") : void 0;
|
|
15290
|
+
let raw;
|
|
15291
|
+
if (row?.variable) {
|
|
15292
|
+
if (row.type !== "json" && row.type !== "string") return null;
|
|
15293
|
+
raw = row.variable;
|
|
15294
|
+
} else {
|
|
15295
|
+
raw = row?.value;
|
|
14930
15296
|
}
|
|
14931
|
-
|
|
14932
|
-
|
|
14933
|
-
|
|
14934
|
-
|
|
14935
|
-
|
|
14936
|
-
|
|
14937
|
-
|
|
14938
|
-
|
|
15297
|
+
if (raw === void 0 || raw === null) return /* @__PURE__ */ new Set();
|
|
15298
|
+
if (typeof raw === "string") {
|
|
15299
|
+
if (raw.trim() === "") return /* @__PURE__ */ new Set();
|
|
15300
|
+
try {
|
|
15301
|
+
raw = JSON.parse(raw);
|
|
15302
|
+
} catch {
|
|
15303
|
+
return null;
|
|
15304
|
+
}
|
|
14939
15305
|
}
|
|
14940
|
-
|
|
14941
|
-
|
|
14942
|
-
|
|
14943
|
-
|
|
14944
|
-
|
|
14945
|
-
|
|
14946
|
-
return `${this.cfg.target.s3prefix}dt=${dt}/${pad(d.getUTCHours())}/${d.getTime()}-${randomUUID6()}.ndjson`;
|
|
15306
|
+
if (!isPlainObject3(raw)) return null;
|
|
15307
|
+
const disabled = /* @__PURE__ */ new Set();
|
|
15308
|
+
for (const [contextId, profile] of Object.entries(raw)) {
|
|
15309
|
+
if (!isPlainObject3(profile)) return null;
|
|
15310
|
+
if (profile.enabled !== void 0 && typeof profile.enabled !== "boolean") return null;
|
|
15311
|
+
if (profile.enabled === false) disabled.add(contextId);
|
|
14947
15312
|
}
|
|
14948
|
-
|
|
14949
|
-
|
|
15313
|
+
return disabled;
|
|
15314
|
+
};
|
|
15315
|
+
var deriveConnectedContextIds = (args) => {
|
|
15316
|
+
const ids = /* @__PURE__ */ new Set();
|
|
15317
|
+
for (const id of args.editorContextIds) {
|
|
15318
|
+
const segment = contextToolSegment({ id });
|
|
15319
|
+
const readToolIds = [`get_${segment}_item`, `find_${segment}_items`];
|
|
15320
|
+
if (readToolIds.some((toolId) => !args.disabledToolIds?.has(toolId))) ids.add(id);
|
|
14950
15321
|
}
|
|
14951
|
-
|
|
14952
|
-
|
|
14953
|
-
if (
|
|
14954
|
-
|
|
14955
|
-
} else if (!this.timer) {
|
|
14956
|
-
this.timer = setTimeout(() => void this.flush(), this.cfg.flush.maxIntervalMs);
|
|
14957
|
-
this.timer.unref?.();
|
|
15322
|
+
if (args.agenticSearch) {
|
|
15323
|
+
const disabled = disabledSearchContexts(args.agenticSearch.config);
|
|
15324
|
+
if (disabled) {
|
|
15325
|
+
for (const id of args.contextIds) if (!disabled.has(id)) ids.add(id);
|
|
14958
15326
|
}
|
|
15327
|
+
} else if (args.projectSearchContextIds) {
|
|
15328
|
+
for (const id of args.projectSearchContextIds) ids.add(id);
|
|
14959
15329
|
}
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
14963
|
-
|
|
15330
|
+
if (args.memoryContextId) ids.delete(args.memoryContextId);
|
|
15331
|
+
return ids;
|
|
15332
|
+
};
|
|
15333
|
+
|
|
15334
|
+
// ee/invoke-skills/create-sandbox.ts
|
|
15335
|
+
import {
|
|
15336
|
+
SandboxManager
|
|
15337
|
+
} from "@anthropic-ai/sandbox-runtime";
|
|
15338
|
+
import { mkdir as mkdir4, rm as rm2, readdir as readdir2, stat, lstat as lstat3 } from "fs/promises";
|
|
15339
|
+
import { existsSync as existsSync4 } from "fs";
|
|
15340
|
+
import { join as join6, dirname as dirname3, resolve as resolve4, relative, posix } from "path";
|
|
15341
|
+
import { exec as exec2, spawn } from "child_process";
|
|
15342
|
+
import { promisify as promisify3 } from "util";
|
|
15343
|
+
|
|
15344
|
+
// src/exulu/system-dependencies.ts
|
|
15345
|
+
import { exec } from "child_process";
|
|
15346
|
+
import { existsSync as existsSync2 } from "fs";
|
|
15347
|
+
import { join as join5 } from "path";
|
|
15348
|
+
import { promisify as promisify2 } from "util";
|
|
15349
|
+
var execAsync = promisify2(exec);
|
|
15350
|
+
var REQUIRED_SYSTEM_DEPENDENCIES = [
|
|
15351
|
+
{
|
|
15352
|
+
check: { kind: "binary", binary: "pandoc" },
|
|
15353
|
+
displayName: "Pandoc",
|
|
15354
|
+
purpose: "docx skill: text extraction and tracked-changes conversion",
|
|
15355
|
+
installHints: {
|
|
15356
|
+
debian: "apt-get install -y pandoc",
|
|
15357
|
+
macos: "brew install pandoc"
|
|
14964
15358
|
}
|
|
14965
|
-
|
|
14966
|
-
|
|
14967
|
-
|
|
14968
|
-
|
|
14969
|
-
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
15359
|
+
},
|
|
15360
|
+
{
|
|
15361
|
+
check: { kind: "binary", binary: "soffice" },
|
|
15362
|
+
displayName: "LibreOffice",
|
|
15363
|
+
purpose: "docx skill: converting .docx documents to PDF for visual analysis",
|
|
15364
|
+
installHints: {
|
|
15365
|
+
debian: "apt-get install -y libreoffice",
|
|
15366
|
+
macos: "brew install --cask libreoffice"
|
|
15367
|
+
}
|
|
15368
|
+
},
|
|
15369
|
+
{
|
|
15370
|
+
check: { kind: "binary", binary: "pdftoppm" },
|
|
15371
|
+
displayName: "Poppler (pdftoppm)",
|
|
15372
|
+
purpose: "docx skill: converting PDF pages to images",
|
|
15373
|
+
installHints: {
|
|
15374
|
+
debian: "apt-get install -y poppler-utils",
|
|
15375
|
+
macos: "brew install poppler"
|
|
15376
|
+
}
|
|
15377
|
+
},
|
|
15378
|
+
{
|
|
15379
|
+
check: { kind: "binary", binary: "pdftotext" },
|
|
15380
|
+
displayName: "Poppler (pdftotext)",
|
|
15381
|
+
purpose: "parse_document tool: extracting page-marked text from PDFs",
|
|
15382
|
+
installHints: {
|
|
15383
|
+
debian: "apt-get install -y poppler-utils",
|
|
15384
|
+
macos: "brew install poppler"
|
|
15385
|
+
}
|
|
15386
|
+
},
|
|
15387
|
+
{
|
|
15388
|
+
check: { kind: "npm-global", packageName: "docx" },
|
|
15389
|
+
displayName: "docx (npm global)",
|
|
15390
|
+
purpose: "docx skill: programmatically constructing new .docx documents",
|
|
15391
|
+
installHints: {
|
|
15392
|
+
debian: "npm install -g docx",
|
|
15393
|
+
macos: "npm install -g docx"
|
|
14980
15394
|
}
|
|
14981
15395
|
}
|
|
14982
|
-
|
|
14983
|
-
|
|
14984
|
-
|
|
15396
|
+
];
|
|
15397
|
+
var cachedNpmGlobalRoot;
|
|
15398
|
+
async function getNpmGlobalRoot() {
|
|
15399
|
+
if (cachedNpmGlobalRoot !== void 0) return cachedNpmGlobalRoot;
|
|
15400
|
+
try {
|
|
15401
|
+
const { stdout } = await execAsync("npm root -g", { shell: "/bin/sh" });
|
|
15402
|
+
cachedNpmGlobalRoot = stdout.trim() || null;
|
|
15403
|
+
} catch {
|
|
15404
|
+
cachedNpmGlobalRoot = null;
|
|
15405
|
+
}
|
|
15406
|
+
return cachedNpmGlobalRoot;
|
|
15407
|
+
}
|
|
15408
|
+
async function probeDependency(dep) {
|
|
15409
|
+
switch (dep.check.kind) {
|
|
15410
|
+
case "binary": {
|
|
14985
15411
|
try {
|
|
14986
|
-
|
|
14987
|
-
|
|
14988
|
-
await this.spool.remove(name);
|
|
15412
|
+
await execAsync(`command -v ${dep.check.binary}`, { shell: "/bin/sh" });
|
|
15413
|
+
return true;
|
|
14989
15414
|
} catch {
|
|
14990
|
-
return;
|
|
15415
|
+
return false;
|
|
14991
15416
|
}
|
|
14992
15417
|
}
|
|
15418
|
+
case "npm-global": {
|
|
15419
|
+
const root = await getNpmGlobalRoot();
|
|
15420
|
+
if (!root) return false;
|
|
15421
|
+
return existsSync2(join5(root, dep.check.packageName));
|
|
15422
|
+
}
|
|
14993
15423
|
}
|
|
14994
|
-
|
|
14995
|
-
|
|
14996
|
-
|
|
14997
|
-
|
|
14998
|
-
|
|
15424
|
+
}
|
|
15425
|
+
async function checkSystemDependencies() {
|
|
15426
|
+
const probes = await Promise.all(
|
|
15427
|
+
REQUIRED_SYSTEM_DEPENDENCIES.map(async (dep) => ({
|
|
15428
|
+
dep,
|
|
15429
|
+
present: await probeDependency(dep)
|
|
15430
|
+
}))
|
|
15431
|
+
);
|
|
15432
|
+
return {
|
|
15433
|
+
missing: probes.filter((p) => !p.present).map((p) => p.dep)
|
|
15434
|
+
};
|
|
15435
|
+
}
|
|
15436
|
+
function formatMissing(dep) {
|
|
15437
|
+
const probeLabel = dep.check.kind === "binary" ? dep.check.binary : `npm:${dep.check.packageName} (global)`;
|
|
15438
|
+
return ` - ${dep.displayName} (${probeLabel}) \u2014 ${dep.purpose}
|
|
15439
|
+
Debian/Ubuntu: ${dep.installHints.debian}
|
|
15440
|
+
macOS: ${dep.installHints.macos}`;
|
|
15441
|
+
}
|
|
15442
|
+
async function reportSystemDependencies(opts) {
|
|
15443
|
+
const { missing } = await checkSystemDependencies();
|
|
15444
|
+
if (missing.length === 0) return;
|
|
15445
|
+
const body = `${missing.length} system dependency check(s) failed:
|
|
15446
|
+
` + missing.map(formatMissing).join("\n");
|
|
15447
|
+
if (opts.requireSystemDependencies) {
|
|
15448
|
+
throw new Error(
|
|
15449
|
+
`[EXULU] Required system dependencies are missing. Install them and restart, or set requireSystemDependencies=false in ExuluConfig to downgrade to a warning.
|
|
15450
|
+
${body}`
|
|
15451
|
+
);
|
|
14999
15452
|
}
|
|
15000
|
-
|
|
15453
|
+
console.warn(
|
|
15454
|
+
`[EXULU] ${body}
|
|
15455
|
+
Set requireSystemDependencies=true in ExuluConfig to make this fatal at startup.`
|
|
15456
|
+
);
|
|
15457
|
+
}
|
|
15001
15458
|
|
|
15002
|
-
// src/exulu/
|
|
15003
|
-
var
|
|
15004
|
-
|
|
15005
|
-
|
|
15459
|
+
// src/exulu/skill-env/inventory.ts
|
|
15460
|
+
var ENV_CLASSIFICATION = {
|
|
15461
|
+
// --- secrets: credentials, tokens, signing/verification secrets, keys.
|
|
15462
|
+
// Knowing the value grants access to something.
|
|
15463
|
+
NEXTAUTH_SECRET: "secret",
|
|
15464
|
+
POSTGRES_DB_PASSWORD: "secret",
|
|
15465
|
+
LITELLM_MASTER_KEY: "secret",
|
|
15466
|
+
LITELLM_DATABASE_URL: "secret",
|
|
15467
|
+
COMPANION_S3_SECRET: "secret",
|
|
15468
|
+
COMPANION_S3_KEY: "secret",
|
|
15469
|
+
ANTHROPIC_API_KEY: "secret",
|
|
15470
|
+
GEMINI_API_KEY: "secret",
|
|
15471
|
+
PERPLEXITY_API_KEY: "secret",
|
|
15472
|
+
RECALL_API_KEY: "secret",
|
|
15473
|
+
JIRA_CLIENT_SECRET: "secret",
|
|
15474
|
+
GOOGLE_CLIENT_SECRET: "secret",
|
|
15475
|
+
REDIS_PASSWORD: "secret",
|
|
15476
|
+
NPM_TOKEN: "secret",
|
|
15477
|
+
// Found via `rg process\.env\.[A-Z0-9_]+ src ee` (Step 3 of the task brief):
|
|
15478
|
+
EXULU_API_KEY: "secret",
|
|
15479
|
+
// auth header for remote LiteLLM client mode (resolve-model.ts)
|
|
15480
|
+
INTERNAL_SECRET: "secret",
|
|
15481
|
+
// compared against an internal-request header (src/auth/auth.ts)
|
|
15482
|
+
RECALL_WORKSPACE_VERIFICATION_SECRET: "secret",
|
|
15483
|
+
// verifies inbound Recall webhook signatures
|
|
15484
|
+
SMTP_PASSWORD: "secret",
|
|
15485
|
+
// EXULU_ENTERPRISE_LICENSE: the check (ee/entitlements.ts) only tests a
|
|
15486
|
+
// string prefix, not a cryptographic signature, so it is closer to a
|
|
15487
|
+
// capability token than a password — but knowing it still unlocks
|
|
15488
|
+
// enterprise entitlements, so classified secret per the fail-safe rule.
|
|
15489
|
+
EXULU_ENTERPRISE_LICENSE: "secret",
|
|
15490
|
+
// POSTGRES_DB_USER / REDIS_USER / SMTP_USER: a username alone grants
|
|
15491
|
+
// nothing without its paired password. Classified secret anyway — the
|
|
15492
|
+
// design's claim is "a skill never sees the platform's own credentials",
|
|
15493
|
+
// and a username is half of one. No skill has a legitimate need for the
|
|
15494
|
+
// platform's database, cache, or mail identity; an admin can expose one
|
|
15495
|
+
// deliberately as a platform variable if that ever changes.
|
|
15496
|
+
POSTGRES_DB_USER: "secret",
|
|
15497
|
+
REDIS_USER: "secret",
|
|
15498
|
+
SMTP_USER: "secret",
|
|
15499
|
+
// --- deployment credentials the consumer app reads on our behalf.
|
|
15500
|
+
// `@exulu/backend` is a library: these never appear as `process.env.<NAME>` in
|
|
15501
|
+
// src/ or ee/, so the code scan cannot see them — they come from the
|
|
15502
|
+
// Server/Worker rows of mintlify-docs/self-hosting/environment-variables.mdx
|
|
15503
|
+
// and from config.litellm.yaml's `os.environ/` directives. They were reaching
|
|
15504
|
+
// every skill until this block existed.
|
|
15505
|
+
//
|
|
15506
|
+
// VERTEX_CREDENTIALS_PATH is worse than a leaked string: it is a filesystem
|
|
15507
|
+
// path to a GCP service-account JSON, and in bwrap mode the sandbox binds /
|
|
15508
|
+
// read-only with only ~ denied, so a skill can read the key file at the
|
|
15509
|
+
// documented ./vertex-auth.json. Stripping the path does not make that file
|
|
15510
|
+
// unreadable — it removes the pointer every tool follows, which is as far as
|
|
15511
|
+
// this layer reaches.
|
|
15512
|
+
VERTEX_CREDENTIALS_PATH: "secret",
|
|
15513
|
+
GOOGLE_VERTEX_CREDENTIALS_JSON: "secret",
|
|
15514
|
+
// inline service-account JSON, same credential without the file
|
|
15515
|
+
// A GCP project id is not a password, but it is half of the Vertex identity
|
|
15516
|
+
// and no skill has a legitimate need for it — same reasoning as
|
|
15517
|
+
// POSTGRES_DB_USER above.
|
|
15518
|
+
GOOGLE_VERTEX_PROJECT: "secret",
|
|
15519
|
+
COHERE_API_KEY: "secret",
|
|
15520
|
+
// reranker provider key (os.environ/COHERE_API_KEY)
|
|
15521
|
+
OPENAI_API_KEY: "secret",
|
|
15522
|
+
// TTS / model provider key
|
|
15523
|
+
AZURE_API_KEY_EU: "secret",
|
|
15524
|
+
// image-generation provider key
|
|
15525
|
+
SIGNOZ_ACCESS_TOKEN: "secret",
|
|
15526
|
+
// OTLP ingest token; read via ExuluOtel's parameter object, invisible to the code scan
|
|
15527
|
+
HF_AUTH_TOKEN: "secret",
|
|
15528
|
+
// HuggingFace token for pyannote diarization; documented as Whisper-container-only, stripped here fail-safe
|
|
15529
|
+
LITELLM_API_KEY: "secret",
|
|
15530
|
+
// supervisor-populated proxy key handed to the bundled LiteLLM UI
|
|
15531
|
+
// --- runtime: paths, locales, feature flags, hostnames, ports, log levels.
|
|
15532
|
+
// Only changes behaviour.
|
|
15533
|
+
PATH: "runtime",
|
|
15534
|
+
HOME: "runtime",
|
|
15535
|
+
LANG: "runtime",
|
|
15536
|
+
TZ: "runtime",
|
|
15537
|
+
TMPDIR: "runtime",
|
|
15538
|
+
NODE_ENV: "runtime",
|
|
15539
|
+
PORT: "runtime",
|
|
15540
|
+
DEBUG: "runtime",
|
|
15541
|
+
BACKEND: "runtime",
|
|
15542
|
+
FRONTEND: "runtime",
|
|
15543
|
+
// Found via `rg process\.env\.[A-Z0-9_]+ src ee` (Step 3 of the task brief):
|
|
15544
|
+
AUTH_MODE: "runtime",
|
|
15545
|
+
// "password" | "otp" mode selector, echoed by GET /config
|
|
15546
|
+
// Platform fallback model for POST /claims/check when the request names no
|
|
15547
|
+
// model and no agent config supplies one. It is a model IDENTIFIER, not a
|
|
15548
|
+
// credential: knowing the string grants access to nothing, because reaching
|
|
15549
|
+
// that model still needs the deployment's own proxy credentials
|
|
15550
|
+
// (LITELLM_MASTER_KEY / EXULU_API_KEY, both classified secret) and passes
|
|
15551
|
+
// through resolveModel's catalog. All it changes is which model a check
|
|
15552
|
+
// runs on — behaviour, which is this class's definition. Same reasoning as
|
|
15553
|
+
// EXULU_ENTITY_EXTRACTION_MODEL, TRANSCRIPTION_MODEL and TTS_MODEL below.
|
|
15554
|
+
CLAIM_CHECK_DEFAULT_MODEL: "runtime",
|
|
15555
|
+
// Request deadline (ms) for POST /claims/check, overriding routes.ts's
|
|
15556
|
+
// 60,000 default. A number of milliseconds is a setting, not a credential —
|
|
15557
|
+
// knowing it grants no access, it only changes how long the handler waits
|
|
15558
|
+
// before cancelling and returning 504. Same reasoning as
|
|
15559
|
+
// CLAIM_CHECK_DEFAULT_MODEL above.
|
|
15560
|
+
CLAIM_CHECK_TIMEOUT_MS: "runtime",
|
|
15561
|
+
DISABLE_SCHEMA_UPDATE: "runtime",
|
|
15562
|
+
// LiteLLM child-process flag
|
|
15563
|
+
EXULU_ENTITY_EXTRACTION_MODEL: "runtime",
|
|
15564
|
+
// Request-rate ceilings for external users, classified exactly as their
|
|
15565
|
+
// guest counterparts below: a number of requests is a setting, not a
|
|
15566
|
+
// credential. Arrived with the external-rate-limit PR, which predates this
|
|
15567
|
+
// inventory and so could not have classified them itself.
|
|
15568
|
+
EXULU_EXTERNAL_RATE_PER_HOUR: "runtime",
|
|
15569
|
+
EXULU_EXTERNAL_RATE_PER_MINUTE: "runtime",
|
|
15570
|
+
EXULU_GUEST_MAX_MESSAGE_CHARS: "runtime",
|
|
15571
|
+
EXULU_GUEST_MAX_TOTAL_CHARS: "runtime",
|
|
15572
|
+
EXULU_GUEST_RATE_PER_HOUR: "runtime",
|
|
15573
|
+
EXULU_GUEST_RATE_PER_MINUTE: "runtime",
|
|
15574
|
+
EXULU_REQUIRE_SANDBOX: "runtime",
|
|
15575
|
+
EXULU_TRUST_PROXY: "runtime",
|
|
15576
|
+
EXULU_USE_LITELLM: "runtime",
|
|
15577
|
+
EXULU_VS_TIMING: "runtime",
|
|
15578
|
+
LITELLM_BASE_URL: "runtime",
|
|
15579
|
+
LITELLM_CONFIG_PATH: "runtime",
|
|
15580
|
+
LITELLM_HOST: "runtime",
|
|
15581
|
+
LITELLM_PORT: "runtime",
|
|
15582
|
+
LITELLM_UI_PATH: "runtime",
|
|
15583
|
+
NEXT_PUBLIC_AGENT_VISUALIZATION: "runtime",
|
|
15584
|
+
POSTGRES_DB_HOST: "runtime",
|
|
15585
|
+
POSTGRES_DB_NAME: "runtime",
|
|
15586
|
+
POSTGRES_DB_PORT: "runtime",
|
|
15587
|
+
POSTGRES_DB_SSL: "runtime",
|
|
15588
|
+
PUBLIC_API_BASE_URL: "runtime",
|
|
15589
|
+
RECALL_REGION: "runtime",
|
|
15590
|
+
RECALL_RECORDING_RETENTION_HOURS: "runtime",
|
|
15591
|
+
RECALL_STORE_VIDEO_LOCALLY: "runtime",
|
|
15592
|
+
REDIS_HOST: "runtime",
|
|
15593
|
+
REDIS_PORT: "runtime",
|
|
15594
|
+
SERVER_ROOT_PATH: "runtime",
|
|
15595
|
+
// OTLP endpoints, not credentials — the token above is the credential. They
|
|
15596
|
+
// are credential-SHAPED (`_URL`), so they need a line here for the
|
|
15597
|
+
// documentation reconciliation test to pass; `runtime` is the honest answer.
|
|
15598
|
+
SIGNOZ_TRACES_URL: "runtime",
|
|
15599
|
+
SIGNOZ_LOGS_URL: "runtime",
|
|
15600
|
+
SMTP_FROM: "runtime",
|
|
15601
|
+
SMTP_HOST: "runtime",
|
|
15602
|
+
SMTP_PORT: "runtime",
|
|
15603
|
+
SMTP_SECURE: "runtime",
|
|
15604
|
+
TOTAL_MAX_RECORDINGS_DURATION_PER_MONTH: "runtime",
|
|
15605
|
+
TRANSCRIPTION_MODEL: "runtime",
|
|
15606
|
+
TRANSCRIPTION_SERVER: "runtime",
|
|
15607
|
+
TTS_MODEL: "runtime",
|
|
15608
|
+
TTS_VOICE: "runtime",
|
|
15609
|
+
WHISPER_HOST: "runtime",
|
|
15610
|
+
WHISPER_PORT: "runtime"
|
|
15006
15611
|
};
|
|
15612
|
+
var isSecretEnvName = (name) => ENV_CLASSIFICATION[name] === "secret";
|
|
15613
|
+
var SECRET_SHAPED_ENV_NAME = /(SECRET|PASSWORD|TOKEN|_KEY|CREDENTIAL|PRIVATE|_URL|_URI|_DSN|_PASS\b|PWD|APIKEY|LICENSE)/i;
|
|
15614
|
+
var isSecretShapedEnvName = (name) => SECRET_SHAPED_ENV_NAME.test(name);
|
|
15615
|
+
var findUnclassifiedSecretShaped = (env) => Object.keys(env).filter((n) => isSecretShapedEnvName(n) && !(n in ENV_CLASSIFICATION)).sort();
|
|
15007
15616
|
|
|
15008
|
-
//
|
|
15009
|
-
var
|
|
15010
|
-
|
|
15011
|
-
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15020
|
-
|
|
15021
|
-
|
|
15022
|
-
"req",
|
|
15023
|
-
"model",
|
|
15024
|
-
"contexts",
|
|
15025
|
-
"upload",
|
|
15026
|
-
"memory",
|
|
15027
|
-
"exuluConfig",
|
|
15028
|
-
"toolVariablesConfig",
|
|
15029
|
-
"allExuluTools",
|
|
15030
|
-
"currentTools",
|
|
15031
|
-
"sessionItems",
|
|
15032
|
-
"audit"
|
|
15033
|
-
]);
|
|
15034
|
-
var isSecretKey = (key, extra) => {
|
|
15035
|
-
const k = key.toLowerCase();
|
|
15036
|
-
if (extra.some((e) => k.includes(e.toLowerCase()))) return true;
|
|
15037
|
-
return SECRET_KEY_DENYLIST.some((term) => k.includes(term));
|
|
15038
|
-
};
|
|
15039
|
-
var redact = (value, redactKeys, seen) => {
|
|
15040
|
-
if (value === null || typeof value !== "object") return value;
|
|
15041
|
-
if (seen.has(value)) return "[circular]";
|
|
15042
|
-
seen.add(value);
|
|
15043
|
-
if (Array.isArray(value)) return value.map((v) => redact(v, redactKeys, seen));
|
|
15044
|
-
const out = {};
|
|
15045
|
-
for (const [key, val] of Object.entries(value)) {
|
|
15046
|
-
if (FRAMEWORK_INTERNAL_KEYS.has(key)) continue;
|
|
15047
|
-
if (isSecretKey(key, redactKeys)) {
|
|
15048
|
-
if (val !== null && typeof val === "object") {
|
|
15049
|
-
out[key] = "[redacted]";
|
|
15050
|
-
}
|
|
15617
|
+
// ee/invoke-skills/skill-env.ts
|
|
15618
|
+
var POSIX_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
15619
|
+
var buildSkillEnv = ({
|
|
15620
|
+
processEnv,
|
|
15621
|
+
grantedVariables,
|
|
15622
|
+
overrides = {},
|
|
15623
|
+
extraSecretNames = []
|
|
15624
|
+
}) => {
|
|
15625
|
+
const env = {};
|
|
15626
|
+
const strippedSecretNames = [];
|
|
15627
|
+
const extraSecrets = new Set(extraSecretNames);
|
|
15628
|
+
for (const [name, value] of Object.entries(processEnv)) {
|
|
15629
|
+
if (isSecretEnvName(name) || extraSecrets.has(name)) {
|
|
15630
|
+
strippedSecretNames.push(name);
|
|
15051
15631
|
continue;
|
|
15052
15632
|
}
|
|
15053
|
-
|
|
15054
|
-
}
|
|
15055
|
-
return out;
|
|
15056
|
-
};
|
|
15057
|
-
var sanitizeData = (value, opts) => {
|
|
15058
|
-
let cleaned;
|
|
15059
|
-
try {
|
|
15060
|
-
cleaned = redact(value, opts.redactKeys ?? [], /* @__PURE__ */ new WeakSet());
|
|
15061
|
-
} catch {
|
|
15062
|
-
cleaned = "[unserializable]";
|
|
15633
|
+
env[name] = value;
|
|
15063
15634
|
}
|
|
15064
|
-
|
|
15065
|
-
|
|
15066
|
-
|
|
15067
|
-
|
|
15068
|
-
|
|
15635
|
+
const baseKeys = new Set(Object.keys(env));
|
|
15636
|
+
const grantedNames = [];
|
|
15637
|
+
const skippedNames = [];
|
|
15638
|
+
for (const [name, value] of Object.entries(grantedVariables)) {
|
|
15639
|
+
if (!POSIX_NAME.test(name) || baseKeys.has(name)) {
|
|
15640
|
+
skippedNames.push(name);
|
|
15641
|
+
continue;
|
|
15642
|
+
}
|
|
15643
|
+
env[name] = value;
|
|
15644
|
+
grantedNames.push(name);
|
|
15069
15645
|
}
|
|
15070
|
-
|
|
15646
|
+
Object.assign(env, overrides);
|
|
15071
15647
|
return {
|
|
15072
|
-
|
|
15073
|
-
|
|
15648
|
+
env,
|
|
15649
|
+
strippedSecretNames: strippedSecretNames.sort(),
|
|
15650
|
+
grantedNames: grantedNames.sort(),
|
|
15651
|
+
skippedNames: skippedNames.sort()
|
|
15074
15652
|
};
|
|
15075
15653
|
};
|
|
15076
15654
|
|
|
15077
|
-
//
|
|
15078
|
-
var
|
|
15079
|
-
|
|
15080
|
-
|
|
15081
|
-
|
|
15082
|
-
|
|
15083
|
-
|
|
15084
|
-
|
|
15085
|
-
|
|
15086
|
-
|
|
15087
|
-
|
|
15088
|
-
|
|
15089
|
-
|
|
15090
|
-
|
|
15091
|
-
|
|
15092
|
-
|
|
15093
|
-
|
|
15094
|
-
|
|
15095
|
-
|
|
15096
|
-
|
|
15097
|
-
|
|
15098
|
-
|
|
15099
|
-
|
|
15655
|
+
// ee/invoke-skills/binary-file-guard.ts
|
|
15656
|
+
var BINARY_DOCUMENT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
15657
|
+
".pdf",
|
|
15658
|
+
".doc",
|
|
15659
|
+
".docx",
|
|
15660
|
+
".xls",
|
|
15661
|
+
".xlsx",
|
|
15662
|
+
".ppt",
|
|
15663
|
+
".pptx",
|
|
15664
|
+
".odt",
|
|
15665
|
+
".ods",
|
|
15666
|
+
".odp",
|
|
15667
|
+
".zip",
|
|
15668
|
+
".gz",
|
|
15669
|
+
".png",
|
|
15670
|
+
".jpg",
|
|
15671
|
+
".jpeg",
|
|
15672
|
+
".gif",
|
|
15673
|
+
".bmp",
|
|
15674
|
+
".tif",
|
|
15675
|
+
".tiff",
|
|
15676
|
+
".webp"
|
|
15677
|
+
]);
|
|
15678
|
+
function isBinaryDocumentPath(path3) {
|
|
15679
|
+
const dot = path3.lastIndexOf(".");
|
|
15680
|
+
if (dot < 0) return false;
|
|
15681
|
+
return BINARY_DOCUMENT_EXTENSIONS.has(path3.slice(dot).toLowerCase());
|
|
15682
|
+
}
|
|
15683
|
+
function looksBinary(content) {
|
|
15684
|
+
return content.slice(0, 8192).includes("\0");
|
|
15685
|
+
}
|
|
15686
|
+
function binaryReadHint(path3) {
|
|
15687
|
+
return `"${path3}" is a binary file \u2014 readFile would return raw bytes that cannot be interpreted and would flood the context. The text of mail attachments is already in the conversation (the <file file name=\u2026> block); for other documents use parse_document to extract the text first, then read within that extracted text.`;
|
|
15688
|
+
}
|
|
15100
15689
|
|
|
15101
|
-
//
|
|
15102
|
-
var
|
|
15103
|
-
var
|
|
15104
|
-
|
|
15105
|
-
|
|
15106
|
-
|
|
15107
|
-
|
|
15108
|
-
var
|
|
15109
|
-
const
|
|
15110
|
-
const
|
|
15111
|
-
|
|
15112
|
-
|
|
15113
|
-
|
|
15114
|
-
|
|
15115
|
-
|
|
15116
|
-
|
|
15117
|
-
data.output = output.value;
|
|
15118
|
-
if (output.truncated) truncated.output = true;
|
|
15119
|
-
}
|
|
15120
|
-
let credential;
|
|
15121
|
-
if (ctx.tool.authentication && ctx.user?.id != null) {
|
|
15122
|
-
credential = await describeCredentialIdentity(
|
|
15123
|
-
ctx.tool.authentication,
|
|
15124
|
-
Number(ctx.user.id),
|
|
15125
|
-
ctx.tool.id
|
|
15126
|
-
);
|
|
15690
|
+
// ee/invoke-skills/variable-grants.ts
|
|
15691
|
+
var selectRowsToDecrypt = (rows) => rows.filter((row) => Boolean(row?.name) && row.allow_skill_access === true);
|
|
15692
|
+
var deriveWithheldNames = (rows, granted) => [
|
|
15693
|
+
...new Set(
|
|
15694
|
+
rows.filter((row) => Boolean(row?.name)).map((row) => row.name).filter((name) => !(name in granted))
|
|
15695
|
+
)
|
|
15696
|
+
].sort();
|
|
15697
|
+
var selectGrantedVariables = (rows) => {
|
|
15698
|
+
const out = {};
|
|
15699
|
+
for (const row of rows) {
|
|
15700
|
+
if (!row?.name) continue;
|
|
15701
|
+
if (row.allow_skill_access !== true) continue;
|
|
15702
|
+
if (row.name.startsWith("_")) continue;
|
|
15703
|
+
if (row.name.includes("=")) continue;
|
|
15704
|
+
if (typeof row.value !== "string") continue;
|
|
15705
|
+
out[row.name] = row.value;
|
|
15127
15706
|
}
|
|
15128
|
-
|
|
15129
|
-
return {
|
|
15130
|
-
v: 1,
|
|
15131
|
-
ts: nowIso(),
|
|
15132
|
-
type: AUDIT_EVENT_TYPES.TOOL_CALL,
|
|
15133
|
-
actor: {
|
|
15134
|
-
kind: "user",
|
|
15135
|
-
userId: str(ctx.user?.id),
|
|
15136
|
-
email: ctx.user?.email,
|
|
15137
|
-
roleId: str(ctx.user?.role?.id),
|
|
15138
|
-
projectId: ctx.projectId
|
|
15139
|
-
},
|
|
15140
|
-
context: {
|
|
15141
|
-
sessionId: ctx.sessionID,
|
|
15142
|
-
agentId: ctx.agent?.id,
|
|
15143
|
-
agentName: ctx.agent?.name,
|
|
15144
|
-
toolCallId: ctx.toolCallId
|
|
15145
|
-
},
|
|
15146
|
-
target: { kind: "tool", id: ctx.tool.id, name: ctx.tool.name, category: ctx.tool.category, builtin: ctx.builtin },
|
|
15147
|
-
...ctx.client ? { client: ctx.client } : {},
|
|
15148
|
-
...credential ? { credential } : {},
|
|
15149
|
-
status,
|
|
15150
|
-
...status === "error" ? { error: { name: err3?.name, message: String(err3?.message ?? err3 ?? "unknown error") } } : {},
|
|
15151
|
-
data,
|
|
15152
|
-
durationMs: ctx.durationMs,
|
|
15153
|
-
...Object.keys(truncated).length ? { truncated } : {}
|
|
15154
|
-
};
|
|
15707
|
+
return out;
|
|
15155
15708
|
};
|
|
15156
15709
|
|
|
15157
|
-
// src/exulu/
|
|
15158
|
-
|
|
15159
|
-
|
|
15160
|
-
|
|
15161
|
-
|
|
15162
|
-
|
|
15163
|
-
|
|
15164
|
-
|
|
15165
|
-
|
|
15166
|
-
|
|
15167
|
-
},
|
|
15168
|
-
flush: async () => {
|
|
15169
|
-
},
|
|
15170
|
-
close: async () => {
|
|
15710
|
+
// src/exulu/litellm/os-environ-names.ts
|
|
15711
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
15712
|
+
var OS_ENVIRON_DIRECTIVE = /os\.environ\/([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
15713
|
+
var parseOsEnvironNames = (yamlText) => {
|
|
15714
|
+
const found = /* @__PURE__ */ new Set();
|
|
15715
|
+
for (const match of yamlText.matchAll(OS_ENVIRON_DIRECTIVE)) {
|
|
15716
|
+
const name = match[1];
|
|
15717
|
+
if (!name) continue;
|
|
15718
|
+
if (ENV_CLASSIFICATION[name] === "runtime") continue;
|
|
15719
|
+
found.add(name);
|
|
15171
15720
|
}
|
|
15721
|
+
return [...found].sort();
|
|
15172
15722
|
};
|
|
15173
|
-
var
|
|
15174
|
-
|
|
15175
|
-
|
|
15176
|
-
|
|
15177
|
-
|
|
15178
|
-
|
|
15179
|
-
|
|
15180
|
-
|
|
15181
|
-
|
|
15182
|
-
|
|
15183
|
-
sink;
|
|
15184
|
-
lifecycleWriter() {
|
|
15185
|
-
return createAuditS3Writer(this.resolved.target);
|
|
15186
|
-
}
|
|
15187
|
-
isBuiltin(id) {
|
|
15188
|
-
return this.builtinToolIds.has(id);
|
|
15189
|
-
}
|
|
15190
|
-
shouldAuditTool(id) {
|
|
15191
|
-
const t = this.resolved.toolCalls;
|
|
15192
|
-
if (!t.enabled) return false;
|
|
15193
|
-
if (t.exclude.includes(id)) return false;
|
|
15194
|
-
if (t.include.length > 0) return t.include.includes(id);
|
|
15195
|
-
return true;
|
|
15196
|
-
}
|
|
15197
|
-
shouldAuditSkillSandbox() {
|
|
15198
|
-
return this.resolved.skillSandbox.enabled;
|
|
15199
|
-
}
|
|
15200
|
-
record(event) {
|
|
15201
|
-
this.sink.record(event);
|
|
15202
|
-
}
|
|
15203
|
-
async recordToolCall(ctx) {
|
|
15204
|
-
const event = await buildToolCallEvent(ctx, {
|
|
15205
|
-
maxBytes: this.resolved.payload.maxBytes,
|
|
15206
|
-
captureOutput: this.resolved.payload.captureOutput,
|
|
15207
|
-
redactKeys: this.resolved.payload.redactKeys
|
|
15208
|
-
});
|
|
15209
|
-
if (this.failClosed) await this.sink.recordDurable(event);
|
|
15210
|
-
else this.sink.record(event);
|
|
15211
|
-
}
|
|
15212
|
-
flush() {
|
|
15213
|
-
return this.sink.flush();
|
|
15214
|
-
}
|
|
15215
|
-
close() {
|
|
15216
|
-
return this.sink.close();
|
|
15217
|
-
}
|
|
15218
|
-
get resolvedConfig() {
|
|
15219
|
-
return this.resolved;
|
|
15723
|
+
var readLiteLLMOsEnvironNames = (configPath = resolveLiteLLMConfigPath()) => {
|
|
15724
|
+
try {
|
|
15725
|
+
if (!existsSync3(configPath)) return [];
|
|
15726
|
+
return parseOsEnvironNames(readFileSync2(configPath, "utf8"));
|
|
15727
|
+
} catch (err3) {
|
|
15728
|
+
console.warn(
|
|
15729
|
+
`[SKILLS] Could not read LiteLLM config at ${configPath} to collect os.environ/ credential names; the skill environment falls back to the static secret inventory.`,
|
|
15730
|
+
err3
|
|
15731
|
+
);
|
|
15732
|
+
return [];
|
|
15220
15733
|
}
|
|
15221
15734
|
};
|
|
15222
|
-
|
|
15223
|
-
|
|
15224
|
-
|
|
15225
|
-
|
|
15226
|
-
|
|
15227
|
-
|
|
15228
|
-
|
|
15229
|
-
if (!_instance) _instance = build(config, /* @__PURE__ */ new Set());
|
|
15230
|
-
return _instance;
|
|
15735
|
+
|
|
15736
|
+
// src/exulu/audit/config.ts
|
|
15737
|
+
import os from "os";
|
|
15738
|
+
import path from "path";
|
|
15739
|
+
var normalizePrefix = (p) => {
|
|
15740
|
+
const raw = (p ?? "audit").trim().replace(/^\/+|\/+$/g, "");
|
|
15741
|
+
return `${raw || "audit"}/`;
|
|
15231
15742
|
};
|
|
15232
|
-
var
|
|
15233
|
-
|
|
15234
|
-
|
|
15235
|
-
|
|
15236
|
-
|
|
15237
|
-
|
|
15238
|
-
|
|
15239
|
-
|
|
15240
|
-
|
|
15241
|
-
|
|
15242
|
-
process.off("SIGTERM", _signalClose);
|
|
15243
|
-
process.off("SIGINT", _signalClose);
|
|
15244
|
-
}
|
|
15245
|
-
const close = () => {
|
|
15246
|
-
void _instance?.close();
|
|
15247
|
-
};
|
|
15248
|
-
_signalClose = close;
|
|
15249
|
-
process.on("SIGTERM", close);
|
|
15250
|
-
process.on("SIGINT", close);
|
|
15743
|
+
var hasAllS3Fields = (t) => !!t && !!t.s3region && !!t.s3key && !!t.s3secret && !!t.s3Bucket;
|
|
15744
|
+
var resolveAuditConfig = (config) => {
|
|
15745
|
+
const a = config.audit;
|
|
15746
|
+
if (!a || a.enabled !== true) return null;
|
|
15747
|
+
const dedicated = hasAllS3Fields(a.s3);
|
|
15748
|
+
const source = dedicated ? a.s3 : config.fileUploads;
|
|
15749
|
+
if (!hasAllS3Fields(source)) {
|
|
15750
|
+
throw new Error(
|
|
15751
|
+
"[EXULU] audit.enabled is true but no S3 target is configured. Set config.audit.s3 or config.fileUploads."
|
|
15752
|
+
);
|
|
15251
15753
|
}
|
|
15252
|
-
|
|
15253
|
-
};
|
|
15254
|
-
|
|
15255
|
-
|
|
15256
|
-
var str2 = (v) => v === void 0 || v === null ? void 0 : String(v);
|
|
15257
|
-
var buildSkillSandboxEvent = (ctx, opts = {}) => {
|
|
15258
|
-
const nowIso = opts.nowIso ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
15754
|
+
if (!Number.isInteger(a.retentionDays) || a.retentionDays <= 0) {
|
|
15755
|
+
throw new Error(`[EXULU] audit.retentionDays must be a positive integer, got ${a.retentionDays}.`);
|
|
15756
|
+
}
|
|
15757
|
+
const usingSharedFileUploadsBucket = !dedicated;
|
|
15259
15758
|
return {
|
|
15260
|
-
|
|
15261
|
-
|
|
15262
|
-
|
|
15263
|
-
|
|
15264
|
-
|
|
15265
|
-
|
|
15266
|
-
|
|
15267
|
-
roleId: str2(ctx.user?.role?.id),
|
|
15268
|
-
projectId: ctx.projectId
|
|
15759
|
+
target: {
|
|
15760
|
+
s3region: source.s3region,
|
|
15761
|
+
s3key: source.s3key,
|
|
15762
|
+
s3secret: source.s3secret,
|
|
15763
|
+
s3Bucket: source.s3Bucket,
|
|
15764
|
+
s3prefix: normalizePrefix(source.s3prefix),
|
|
15765
|
+
...source.s3endpoint ? { s3endpoint: source.s3endpoint } : {}
|
|
15269
15766
|
},
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
|
|
15273
|
-
|
|
15767
|
+
retentionDays: a.retentionDays,
|
|
15768
|
+
manageLifecycle: a.manageLifecycle ?? !usingSharedFileUploadsBucket,
|
|
15769
|
+
usingSharedFileUploadsBucket,
|
|
15770
|
+
spoolDir: a.spoolDir ?? path.join(os.tmpdir(), "exulu-audit-spool"),
|
|
15771
|
+
flush: {
|
|
15772
|
+
maxRecords: a.flush?.maxRecords ?? 100,
|
|
15773
|
+
maxIntervalMs: a.flush?.maxIntervalMs ?? 5e3
|
|
15274
15774
|
},
|
|
15275
|
-
|
|
15276
|
-
|
|
15277
|
-
|
|
15278
|
-
|
|
15279
|
-
grantedVariableNames: ctx.grantedNames,
|
|
15280
|
-
withheldVariableNames: ctx.withheldNames,
|
|
15281
|
-
skippedVariableNames: ctx.skippedNames,
|
|
15282
|
-
strippedSecretCount: ctx.strippedSecretCount,
|
|
15283
|
-
degradedSandbox: ctx.degradedSandbox
|
|
15775
|
+
payload: {
|
|
15776
|
+
maxBytes: a.payload?.maxBytes ?? 32768,
|
|
15777
|
+
captureOutput: a.payload?.captureOutput ?? true,
|
|
15778
|
+
redactKeys: a.payload?.redactKeys ?? []
|
|
15284
15779
|
},
|
|
15285
|
-
|
|
15780
|
+
failureMode: a.failureMode ?? "open",
|
|
15781
|
+
toolCalls: {
|
|
15782
|
+
enabled: a.sources?.toolCalls?.enabled ?? true,
|
|
15783
|
+
include: a.sources?.toolCalls?.include ?? [],
|
|
15784
|
+
exclude: a.sources?.toolCalls?.exclude ?? []
|
|
15785
|
+
},
|
|
15786
|
+
skillSandbox: {
|
|
15787
|
+
enabled: a.sources?.skillSandbox?.enabled ?? false
|
|
15788
|
+
}
|
|
15789
|
+
};
|
|
15790
|
+
};
|
|
15791
|
+
|
|
15792
|
+
// src/exulu/audit/s3-writer.ts
|
|
15793
|
+
import {
|
|
15794
|
+
S3Client as S3Client2,
|
|
15795
|
+
PutObjectCommand as PutObjectCommand2,
|
|
15796
|
+
GetBucketLifecycleConfigurationCommand,
|
|
15797
|
+
PutBucketLifecycleConfigurationCommand
|
|
15798
|
+
} from "@aws-sdk/client-s3";
|
|
15799
|
+
var RETRYABLE = /* @__PURE__ */ new Set(["SignatureDoesNotMatch", "InvalidAccessKeyId", "AccessDenied"]);
|
|
15800
|
+
var buildAuditS3Client = (t) => new S3Client2({
|
|
15801
|
+
region: t.s3region,
|
|
15802
|
+
...t.s3endpoint ? { forcePathStyle: true, endpoint: t.s3endpoint } : {},
|
|
15803
|
+
credentials: { accessKeyId: t.s3key, secretAccessKey: t.s3secret },
|
|
15804
|
+
requestChecksumCalculation: "WHEN_REQUIRED",
|
|
15805
|
+
responseChecksumValidation: "WHEN_REQUIRED"
|
|
15806
|
+
});
|
|
15807
|
+
var createAuditS3Writer = (target, client, opts) => {
|
|
15808
|
+
const c = client ?? buildAuditS3Client(target);
|
|
15809
|
+
const maxRetries = opts?.maxRetries ?? 3;
|
|
15810
|
+
const backoffMs = opts?.backoffMs ?? ((attempt) => Math.pow(2, attempt) * 1e3);
|
|
15811
|
+
const putNdjson = async (key, body) => {
|
|
15812
|
+
let lastError = null;
|
|
15813
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
15814
|
+
const command = new PutObjectCommand2({
|
|
15815
|
+
Bucket: target.s3Bucket,
|
|
15816
|
+
Key: key,
|
|
15817
|
+
Body: Buffer.from(body, "utf8"),
|
|
15818
|
+
ContentType: "application/x-ndjson"
|
|
15819
|
+
});
|
|
15820
|
+
try {
|
|
15821
|
+
await c.send(command);
|
|
15822
|
+
return;
|
|
15823
|
+
} catch (error) {
|
|
15824
|
+
lastError = error;
|
|
15825
|
+
if (RETRYABLE.has(error?.name) && attempt < maxRetries) {
|
|
15826
|
+
await new Promise((r) => setTimeout(r, backoffMs(attempt)));
|
|
15827
|
+
continue;
|
|
15828
|
+
}
|
|
15829
|
+
throw error;
|
|
15830
|
+
}
|
|
15831
|
+
}
|
|
15832
|
+
if (lastError) throw lastError;
|
|
15833
|
+
};
|
|
15834
|
+
const getLifecycle = async () => c.send(new GetBucketLifecycleConfigurationCommand({ Bucket: target.s3Bucket }));
|
|
15835
|
+
const putLifecycle = async (config) => {
|
|
15836
|
+
await c.send(
|
|
15837
|
+
new PutBucketLifecycleConfigurationCommand({
|
|
15838
|
+
Bucket: target.s3Bucket,
|
|
15839
|
+
LifecycleConfiguration: config
|
|
15840
|
+
})
|
|
15841
|
+
);
|
|
15286
15842
|
};
|
|
15843
|
+
return { putNdjson, getLifecycle, putLifecycle };
|
|
15287
15844
|
};
|
|
15288
15845
|
|
|
15289
|
-
//
|
|
15290
|
-
|
|
15291
|
-
|
|
15292
|
-
|
|
15293
|
-
|
|
15294
|
-
|
|
15295
|
-
|
|
15296
|
-
|
|
15297
|
-
|
|
15298
|
-
|
|
15299
|
-
|
|
15300
|
-
|
|
15301
|
-
|
|
15302
|
-
|
|
15303
|
-
|
|
15304
|
-
|
|
15305
|
-
|
|
15306
|
-
remove: local.filter((e) => !remoteNames.has(e.name)).map((e) => e.name)
|
|
15307
|
-
};
|
|
15308
|
-
}
|
|
15309
|
-
function projectSyncMarkerPath(sessionDir) {
|
|
15310
|
-
return join2(dirname(sessionDir), ".project-sync", basename(sessionDir));
|
|
15311
|
-
}
|
|
15312
|
-
async function readMarker(sessionDir) {
|
|
15313
|
-
try {
|
|
15314
|
-
return (await readFile(projectSyncMarkerPath(sessionDir), "utf8")).trim() || null;
|
|
15315
|
-
} catch {
|
|
15316
|
-
return null;
|
|
15317
|
-
}
|
|
15318
|
-
}
|
|
15319
|
-
async function clearProjectSyncMarker(sessionDir) {
|
|
15320
|
-
await rm(projectSyncMarkerPath(sessionDir), { force: true });
|
|
15321
|
-
}
|
|
15322
|
-
var isFlatName = (name) => !!name && !name.includes("/") && !name.includes("\\") && name !== "." && name !== "..";
|
|
15323
|
-
var HELPER_KINDS = [".project-staging", ".project-trash"];
|
|
15324
|
-
var helperRoot = (sessionDir, kind) => join2(dirname(sessionDir), kind);
|
|
15325
|
-
var helperPath = (sessionDir, kind) => join2(helperRoot(sessionDir, kind), `${basename(sessionDir)}-${randomBytes2(8).toString("hex")}`);
|
|
15326
|
-
var execFileAsync = promisify2(execFile);
|
|
15327
|
-
async function removeTreeSafely(path3, sessionDir) {
|
|
15328
|
-
const target = resolve2(path3);
|
|
15329
|
-
const inside = HELPER_KINDS.some((kind) => {
|
|
15330
|
-
const root = resolve2(helperRoot(sessionDir, kind));
|
|
15331
|
-
return target.startsWith(root + sep) && !target.slice(root.length + 1).includes(sep);
|
|
15332
|
-
});
|
|
15333
|
-
if (!inside) {
|
|
15334
|
-
console.error(`[SKILLS] Refusing to remove ${path3}: not a project staging or trash directory.`);
|
|
15335
|
-
return false;
|
|
15846
|
+
// src/exulu/audit/lifecycle.ts
|
|
15847
|
+
var AUDIT_LIFECYCLE_RULE_ID = "exulu-audit-retention";
|
|
15848
|
+
var buildRule = (prefix, retentionDays) => ({
|
|
15849
|
+
ID: AUDIT_LIFECYCLE_RULE_ID,
|
|
15850
|
+
Filter: { Prefix: prefix },
|
|
15851
|
+
Status: "Enabled",
|
|
15852
|
+
Expiration: { Days: retentionDays }
|
|
15853
|
+
});
|
|
15854
|
+
var applyRetentionLifecycle = async (writer, opts) => {
|
|
15855
|
+
const rule = buildRule(opts.prefix, opts.retentionDays);
|
|
15856
|
+
const config = { Rules: [rule] };
|
|
15857
|
+
if (!opts.manage) {
|
|
15858
|
+
console.warn(
|
|
15859
|
+
`[EXULU] audit retention: not managing the S3 lifecycle for this bucket. Apply this rule manually:
|
|
15860
|
+
${JSON.stringify(config, null, 2)}`
|
|
15861
|
+
);
|
|
15862
|
+
return;
|
|
15336
15863
|
}
|
|
15337
15864
|
try {
|
|
15338
|
-
|
|
15339
|
-
|
|
15340
|
-
|
|
15341
|
-
|
|
15342
|
-
|
|
15865
|
+
let existing = [];
|
|
15866
|
+
try {
|
|
15867
|
+
const current = await writer.getLifecycle();
|
|
15868
|
+
existing = (current?.Rules ?? []).filter((r) => r.ID !== AUDIT_LIFECYCLE_RULE_ID);
|
|
15869
|
+
} catch (error) {
|
|
15870
|
+
if (error?.name !== "NoSuchLifecycleConfiguration") throw error;
|
|
15871
|
+
}
|
|
15872
|
+
await writer.putLifecycle({ Rules: [...existing, rule] });
|
|
15873
|
+
console.log(`[EXULU] audit retention: S3 lifecycle set to expire "${opts.prefix}" after ${opts.retentionDays} days.`);
|
|
15874
|
+
} catch (error) {
|
|
15875
|
+
console.warn(
|
|
15876
|
+
`[EXULU] audit retention: could not set the S3 lifecycle (${error?.name ?? "error"}). Apply this rule manually:
|
|
15877
|
+
${JSON.stringify(config, null, 2)}`
|
|
15878
|
+
);
|
|
15343
15879
|
}
|
|
15344
|
-
}
|
|
15345
|
-
|
|
15346
|
-
|
|
15347
|
-
|
|
15348
|
-
|
|
15349
|
-
|
|
15350
|
-
|
|
15880
|
+
};
|
|
15881
|
+
|
|
15882
|
+
// src/exulu/audit/sink.ts
|
|
15883
|
+
import { randomUUID as randomUUID7 } from "crypto";
|
|
15884
|
+
import { promises as fs } from "fs";
|
|
15885
|
+
import path2 from "path";
|
|
15886
|
+
var createFsSpoolStore = (dir) => ({
|
|
15887
|
+
write: async (name, body) => {
|
|
15888
|
+
await fs.mkdir(dir, { recursive: true });
|
|
15889
|
+
await fs.writeFile(path2.join(dir, name), body, "utf8");
|
|
15890
|
+
},
|
|
15891
|
+
list: async () => {
|
|
15351
15892
|
try {
|
|
15352
|
-
|
|
15893
|
+
return (await fs.readdir(dir)).filter((f) => f.endsWith(".ndjson"));
|
|
15353
15894
|
} catch {
|
|
15354
|
-
|
|
15355
|
-
}
|
|
15356
|
-
for (const name of names) {
|
|
15357
|
-
if (!name.startsWith(prefix)) continue;
|
|
15358
|
-
const st = await lstat(join2(root, name)).catch(() => null);
|
|
15359
|
-
if (st && Date.now() - st.mtimeMs > DAY_MS) await removeTreeSafely(join2(root, name), sessionDir);
|
|
15895
|
+
return [];
|
|
15360
15896
|
}
|
|
15897
|
+
},
|
|
15898
|
+
read: async (name) => fs.readFile(path2.join(dir, name), "utf8"),
|
|
15899
|
+
remove: async (name) => {
|
|
15900
|
+
await fs.rm(path2.join(dir, name), { force: true });
|
|
15361
15901
|
}
|
|
15362
|
-
}
|
|
15363
|
-
var
|
|
15364
|
-
|
|
15365
|
-
|
|
15366
|
-
|
|
15367
|
-
|
|
15368
|
-
|
|
15369
|
-
|
|
15370
|
-
} catch (err3) {
|
|
15371
|
-
if (errCode(err3) === "ENOENT") return null;
|
|
15372
|
-
throw err3;
|
|
15902
|
+
});
|
|
15903
|
+
var pad = (n) => String(n).padStart(2, "0");
|
|
15904
|
+
var AuditSink = class {
|
|
15905
|
+
constructor(cfg, writer, spool, opts) {
|
|
15906
|
+
this.cfg = cfg;
|
|
15907
|
+
this.writer = writer;
|
|
15908
|
+
this.spool = spool;
|
|
15909
|
+
this.now = opts?.now ?? (() => /* @__PURE__ */ new Date());
|
|
15373
15910
|
}
|
|
15374
|
-
|
|
15375
|
-
|
|
15376
|
-
|
|
15377
|
-
|
|
15378
|
-
|
|
15379
|
-
|
|
15380
|
-
}
|
|
15381
|
-
async function syncProjectDir(args) {
|
|
15382
|
-
const { sessionDir, projectId, config } = args;
|
|
15383
|
-
const dir = join2(sessionDir, PROJECT_DIR);
|
|
15384
|
-
const previous = await readMarker(sessionDir);
|
|
15385
|
-
if (!projectId) {
|
|
15386
|
-
if (previous !== null) {
|
|
15387
|
-
await discard(await moveAway(dir, sessionDir), sessionDir);
|
|
15388
|
-
await clearProjectSyncMarker(sessionDir);
|
|
15389
|
-
}
|
|
15390
|
-
return;
|
|
15911
|
+
buffer = [];
|
|
15912
|
+
timer = null;
|
|
15913
|
+
now;
|
|
15914
|
+
objectKey() {
|
|
15915
|
+
const d = this.now();
|
|
15916
|
+
const dt = `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
|
|
15917
|
+
return `${this.cfg.target.s3prefix}dt=${dt}/${pad(d.getUTCHours())}/${d.getTime()}-${randomUUID7()}.ndjson`;
|
|
15391
15918
|
}
|
|
15392
|
-
|
|
15393
|
-
|
|
15394
|
-
return;
|
|
15919
|
+
serialize(events) {
|
|
15920
|
+
return events.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
15395
15921
|
}
|
|
15396
|
-
|
|
15397
|
-
|
|
15398
|
-
|
|
15399
|
-
|
|
15400
|
-
|
|
15401
|
-
|
|
15402
|
-
|
|
15403
|
-
remote.set(name, { size: obj.size, key: obj.key });
|
|
15922
|
+
record(event) {
|
|
15923
|
+
this.buffer.push(event);
|
|
15924
|
+
if (this.buffer.length >= this.cfg.flush.maxRecords) {
|
|
15925
|
+
void this.flush();
|
|
15926
|
+
} else if (!this.timer) {
|
|
15927
|
+
this.timer = setTimeout(() => void this.flush(), this.cfg.flush.maxIntervalMs);
|
|
15928
|
+
this.timer.unref?.();
|
|
15404
15929
|
}
|
|
15405
|
-
} catch (err3) {
|
|
15406
|
-
console.error(`[SKILLS] Failed to list project files for project ${projectId}; keeping the local copy.`, err3);
|
|
15407
|
-
return;
|
|
15408
15930
|
}
|
|
15409
|
-
|
|
15410
|
-
|
|
15411
|
-
|
|
15412
|
-
|
|
15413
|
-
|
|
15414
|
-
|
|
15415
|
-
|
|
15416
|
-
|
|
15417
|
-
|
|
15418
|
-
|
|
15419
|
-
|
|
15420
|
-
|
|
15421
|
-
|
|
15422
|
-
|
|
15423
|
-
|
|
15424
|
-
|
|
15425
|
-
|
|
15426
|
-
|
|
15427
|
-
|
|
15428
|
-
if (!moved?.isFile()) {
|
|
15429
|
-
await rename(join2(staging, name), join2(old, `.rejected-${randomBytes2(4).toString("hex")}`)).catch(() => {
|
|
15430
|
-
});
|
|
15431
|
-
continue;
|
|
15432
|
-
}
|
|
15433
|
-
local.push({ name, size: moved.size });
|
|
15931
|
+
async flush() {
|
|
15932
|
+
if (this.timer) {
|
|
15933
|
+
clearTimeout(this.timer);
|
|
15934
|
+
this.timer = null;
|
|
15935
|
+
}
|
|
15936
|
+
if (this.buffer.length === 0) return;
|
|
15937
|
+
const batch = this.buffer;
|
|
15938
|
+
this.buffer = [];
|
|
15939
|
+
const body = this.serialize(batch);
|
|
15940
|
+
try {
|
|
15941
|
+
await this.writer.putNdjson(this.objectKey(), body);
|
|
15942
|
+
await this.drainSpool();
|
|
15943
|
+
} catch (error) {
|
|
15944
|
+
const name = `${Date.now()}-${randomUUID7()}.ndjson`;
|
|
15945
|
+
try {
|
|
15946
|
+
await this.spool.write(name, body);
|
|
15947
|
+
console.warn(`[EXULU] audit: S3 write failed, spooled ${batch.length} record(s) to disk (${name}).`, error);
|
|
15948
|
+
} catch (spoolError) {
|
|
15949
|
+
console.error(`[EXULU] audit: S3 write AND local spool failed \u2014 ${batch.length} record(s) lost.`, spoolError);
|
|
15434
15950
|
}
|
|
15435
15951
|
}
|
|
15436
|
-
|
|
15437
|
-
|
|
15438
|
-
|
|
15439
|
-
)
|
|
15440
|
-
for (const name of plan.download) {
|
|
15952
|
+
}
|
|
15953
|
+
async drainSpool() {
|
|
15954
|
+
const names = await this.spool.list();
|
|
15955
|
+
for (const name of names) {
|
|
15441
15956
|
try {
|
|
15442
|
-
const
|
|
15443
|
-
await
|
|
15444
|
-
|
|
15445
|
-
|
|
15957
|
+
const body = await this.spool.read(name);
|
|
15958
|
+
await this.writer.putNdjson(this.objectKey(), body);
|
|
15959
|
+
await this.spool.remove(name);
|
|
15960
|
+
} catch {
|
|
15961
|
+
return;
|
|
15446
15962
|
}
|
|
15447
15963
|
}
|
|
15448
|
-
|
|
15449
|
-
|
|
15450
|
-
|
|
15451
|
-
|
|
15452
|
-
|
|
15453
|
-
|
|
15454
|
-
|
|
15455
|
-
|
|
15456
|
-
|
|
15457
|
-
|
|
15458
|
-
|
|
15459
|
-
|
|
15964
|
+
}
|
|
15965
|
+
async recordDurable(event) {
|
|
15966
|
+
await this.writer.putNdjson(this.objectKey(), this.serialize([event]));
|
|
15967
|
+
}
|
|
15968
|
+
async close() {
|
|
15969
|
+
await this.flush();
|
|
15970
|
+
}
|
|
15971
|
+
};
|
|
15972
|
+
|
|
15973
|
+
// src/exulu/audit/event.ts
|
|
15974
|
+
var AUDIT_EVENT_TYPES = {
|
|
15975
|
+
TOOL_CALL: "tool.call",
|
|
15976
|
+
SKILL_SANDBOX_CREATED: "skill.sandbox.created"
|
|
15977
|
+
};
|
|
15978
|
+
|
|
15979
|
+
// src/exulu/audit/redact.ts
|
|
15980
|
+
var SECRET_KEY_DENYLIST = [
|
|
15981
|
+
"oauth",
|
|
15982
|
+
"credentials",
|
|
15983
|
+
"accesstoken",
|
|
15984
|
+
"refreshtoken",
|
|
15985
|
+
"password",
|
|
15986
|
+
"secret",
|
|
15987
|
+
"token",
|
|
15988
|
+
"apikey",
|
|
15989
|
+
"authorization",
|
|
15990
|
+
"nonce"
|
|
15991
|
+
];
|
|
15992
|
+
var FRAMEWORK_INTERNAL_KEYS = /* @__PURE__ */ new Set([
|
|
15993
|
+
"req",
|
|
15994
|
+
"model",
|
|
15995
|
+
"contexts",
|
|
15996
|
+
"upload",
|
|
15997
|
+
"memory",
|
|
15998
|
+
"exuluConfig",
|
|
15999
|
+
"toolVariablesConfig",
|
|
16000
|
+
"allExuluTools",
|
|
16001
|
+
"currentTools",
|
|
16002
|
+
"sessionItems",
|
|
16003
|
+
"audit"
|
|
16004
|
+
]);
|
|
16005
|
+
var isSecretKey = (key, extra) => {
|
|
16006
|
+
const k = key.toLowerCase();
|
|
16007
|
+
if (extra.some((e) => k.includes(e.toLowerCase()))) return true;
|
|
16008
|
+
return SECRET_KEY_DENYLIST.some((term) => k.includes(term));
|
|
16009
|
+
};
|
|
16010
|
+
var redact = (value, redactKeys, seen) => {
|
|
16011
|
+
if (value === null || typeof value !== "object") return value;
|
|
16012
|
+
if (seen.has(value)) return "[circular]";
|
|
16013
|
+
seen.add(value);
|
|
16014
|
+
if (Array.isArray(value)) return value.map((v) => redact(v, redactKeys, seen));
|
|
16015
|
+
const out = {};
|
|
16016
|
+
for (const [key, val] of Object.entries(value)) {
|
|
16017
|
+
if (FRAMEWORK_INTERNAL_KEYS.has(key)) continue;
|
|
16018
|
+
if (isSecretKey(key, redactKeys)) {
|
|
16019
|
+
if (val !== null && typeof val === "object") {
|
|
16020
|
+
out[key] = "[redacted]";
|
|
15460
16021
|
}
|
|
16022
|
+
continue;
|
|
15461
16023
|
}
|
|
15462
|
-
|
|
15463
|
-
console.error(`[SKILLS] Project sync failed for project ${projectId}; continuing.`, err3);
|
|
15464
|
-
} finally {
|
|
15465
|
-
if (!installed) await discard(staging, sessionDir);
|
|
15466
|
-
for (const t of trashes) await discard(t, sessionDir);
|
|
16024
|
+
out[key] = redact(val, redactKeys, seen);
|
|
15467
16025
|
}
|
|
15468
|
-
|
|
15469
|
-
|
|
15470
|
-
|
|
15471
|
-
|
|
16026
|
+
return out;
|
|
16027
|
+
};
|
|
16028
|
+
var sanitizeData = (value, opts) => {
|
|
16029
|
+
let cleaned;
|
|
15472
16030
|
try {
|
|
15473
|
-
|
|
15474
|
-
|
|
15475
|
-
|
|
15476
|
-
if (!owner) return null;
|
|
15477
|
-
const rbac = await deps.getRbac(project);
|
|
15478
|
-
const allowed = hasProjectAccess({ project, rbac, user: owner, want: "read" });
|
|
15479
|
-
return allowed ? String(project.id) : null;
|
|
15480
|
-
} catch (err3) {
|
|
15481
|
-
console.error(`[SKILLS] Failed to resolve project ${projectId} for the session sandbox; continuing without project files.`, err3);
|
|
15482
|
-
return null;
|
|
16031
|
+
cleaned = redact(value, opts.redactKeys ?? [], /* @__PURE__ */ new WeakSet());
|
|
16032
|
+
} catch {
|
|
16033
|
+
cleaned = "[unserializable]";
|
|
15483
16034
|
}
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
|
|
15489
|
-
import { randomBytes as randomBytes3 } from "crypto";
|
|
15490
|
-
import { dirname as dirname2, isAbsolute, join as join3, sep as sep2 } from "path";
|
|
15491
|
-
var UnsafeSessionPathError = class extends Error {
|
|
15492
|
-
constructor(message) {
|
|
15493
|
-
super(message);
|
|
15494
|
-
this.name = "UnsafeSessionPathError";
|
|
16035
|
+
let serialized;
|
|
16036
|
+
try {
|
|
16037
|
+
serialized = JSON.stringify(cleaned) ?? "";
|
|
16038
|
+
} catch {
|
|
16039
|
+
return { value: "[unserializable]", truncated: false };
|
|
15495
16040
|
}
|
|
16041
|
+
if (serialized.length <= opts.maxBytes) return { value: cleaned, truncated: false };
|
|
16042
|
+
return {
|
|
16043
|
+
value: { _truncated: true, preview: serialized.slice(0, opts.maxBytes) },
|
|
16044
|
+
truncated: true
|
|
16045
|
+
};
|
|
15496
16046
|
};
|
|
15497
|
-
|
|
15498
|
-
|
|
15499
|
-
async
|
|
15500
|
-
const
|
|
15501
|
-
|
|
15502
|
-
|
|
16047
|
+
|
|
16048
|
+
// src/exulu/auth/describe.ts
|
|
16049
|
+
var describeCredentialIdentity = async (auth, userId, toolId) => {
|
|
16050
|
+
const provider = providerKeyFor(toolId ?? auth.provider, auth);
|
|
16051
|
+
const base = {
|
|
16052
|
+
provider,
|
|
16053
|
+
authType: auth.authType,
|
|
16054
|
+
account: String(userId)
|
|
15503
16055
|
};
|
|
15504
|
-
|
|
15505
|
-
let parent;
|
|
16056
|
+
if (auth.authType !== "oauth") return base;
|
|
15506
16057
|
try {
|
|
15507
|
-
|
|
15508
|
-
|
|
15509
|
-
|
|
15510
|
-
return
|
|
16058
|
+
const row = await credentialStore.get(provider, userId);
|
|
16059
|
+
if (!row || row.authType !== "oauth") return base;
|
|
16060
|
+
const { scopes, expiresAt } = row.data;
|
|
16061
|
+
return {
|
|
16062
|
+
...base,
|
|
16063
|
+
...scopes ? { scopes: scopes.split(" ").filter(Boolean) } : {},
|
|
16064
|
+
...expiresAt !== void 0 ? { expiresAt } : {}
|
|
16065
|
+
};
|
|
16066
|
+
} catch (error) {
|
|
16067
|
+
console.error(`[EXULU] describeCredentialIdentity failed for provider "${provider}":`, error);
|
|
16068
|
+
return base;
|
|
15511
16069
|
}
|
|
15512
|
-
|
|
15513
|
-
|
|
15514
|
-
|
|
15515
|
-
|
|
15516
|
-
|
|
15517
|
-
|
|
16070
|
+
};
|
|
16071
|
+
|
|
16072
|
+
// src/exulu/audit/emitters/tool-call.ts
|
|
16073
|
+
var str = (v) => v === void 0 || v === null ? void 0 : String(v);
|
|
16074
|
+
var isAuthShortCircuit = (output) => {
|
|
16075
|
+
if (!output || typeof output !== "object") return false;
|
|
16076
|
+
const o = output;
|
|
16077
|
+
return !!o.credentialRequest || !!o.oauth?.authorizationUrl;
|
|
16078
|
+
};
|
|
16079
|
+
var buildToolCallEvent = async (ctx, opts) => {
|
|
16080
|
+
const nowIso = opts.nowIso ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
16081
|
+
const status = ctx.status === "error" ? "error" : isAuthShortCircuit(ctx.output) ? "auth_required" : "ok";
|
|
16082
|
+
const input = sanitizeData(ctx.input, { maxBytes: opts.maxBytes, redactKeys: opts.redactKeys });
|
|
16083
|
+
const data = { input: input.value };
|
|
16084
|
+
const truncated = {};
|
|
16085
|
+
if (input.truncated) truncated.input = true;
|
|
16086
|
+
if (opts.captureOutput && status !== "auth_required") {
|
|
16087
|
+
const output = sanitizeData(ctx.output, { maxBytes: opts.maxBytes, redactKeys: opts.redactKeys });
|
|
16088
|
+
data.output = output.value;
|
|
16089
|
+
if (output.truncated) truncated.output = true;
|
|
16090
|
+
}
|
|
16091
|
+
let credential;
|
|
16092
|
+
if (ctx.tool.authentication && ctx.user?.id != null) {
|
|
16093
|
+
credential = await describeCredentialIdentity(
|
|
16094
|
+
ctx.tool.authentication,
|
|
16095
|
+
Number(ctx.user.id),
|
|
16096
|
+
ctx.tool.id
|
|
15518
16097
|
);
|
|
15519
|
-
} catch (err3) {
|
|
15520
|
-
return skip(errCode2(err3) === "ELOOP" ? "it is a symbolic link" : `open failed (${errCode2(err3) ?? "unknown"})`);
|
|
15521
16098
|
}
|
|
15522
|
-
|
|
15523
|
-
|
|
15524
|
-
|
|
15525
|
-
|
|
15526
|
-
|
|
15527
|
-
|
|
15528
|
-
|
|
15529
|
-
|
|
15530
|
-
|
|
15531
|
-
|
|
15532
|
-
|
|
15533
|
-
|
|
15534
|
-
|
|
15535
|
-
|
|
15536
|
-
|
|
15537
|
-
|
|
15538
|
-
|
|
15539
|
-
|
|
15540
|
-
|
|
15541
|
-
|
|
15542
|
-
|
|
15543
|
-
|
|
15544
|
-
|
|
15545
|
-
|
|
15546
|
-
|
|
15547
|
-
|
|
15548
|
-
|
|
15549
|
-
|
|
16099
|
+
const err3 = ctx.error;
|
|
16100
|
+
return {
|
|
16101
|
+
v: 1,
|
|
16102
|
+
ts: nowIso(),
|
|
16103
|
+
type: AUDIT_EVENT_TYPES.TOOL_CALL,
|
|
16104
|
+
actor: {
|
|
16105
|
+
kind: "user",
|
|
16106
|
+
userId: str(ctx.user?.id),
|
|
16107
|
+
email: ctx.user?.email,
|
|
16108
|
+
roleId: str(ctx.user?.role?.id),
|
|
16109
|
+
projectId: ctx.projectId
|
|
16110
|
+
},
|
|
16111
|
+
context: {
|
|
16112
|
+
sessionId: ctx.sessionID,
|
|
16113
|
+
agentId: ctx.agent?.id,
|
|
16114
|
+
agentName: ctx.agent?.name,
|
|
16115
|
+
toolCallId: ctx.toolCallId
|
|
16116
|
+
},
|
|
16117
|
+
target: { kind: "tool", id: ctx.tool.id, name: ctx.tool.name, category: ctx.tool.category, builtin: ctx.builtin },
|
|
16118
|
+
...ctx.client ? { client: ctx.client } : {},
|
|
16119
|
+
...credential ? { credential } : {},
|
|
16120
|
+
status,
|
|
16121
|
+
...status === "error" ? { error: { name: err3?.name, message: String(err3?.message ?? err3 ?? "unknown error") } } : {},
|
|
16122
|
+
data,
|
|
16123
|
+
durationMs: ctx.durationMs,
|
|
16124
|
+
...Object.keys(truncated).length ? { truncated } : {}
|
|
16125
|
+
};
|
|
16126
|
+
};
|
|
16127
|
+
|
|
16128
|
+
// src/exulu/audit/logger.ts
|
|
16129
|
+
var noop = {
|
|
16130
|
+
enabled: false,
|
|
16131
|
+
failClosed: false,
|
|
16132
|
+
isBuiltin: () => false,
|
|
16133
|
+
shouldAuditTool: () => false,
|
|
16134
|
+
shouldAuditSkillSandbox: () => false,
|
|
16135
|
+
record: () => {
|
|
16136
|
+
},
|
|
16137
|
+
recordToolCall: async () => {
|
|
16138
|
+
},
|
|
16139
|
+
flush: async () => {
|
|
16140
|
+
},
|
|
16141
|
+
close: async () => {
|
|
16142
|
+
}
|
|
16143
|
+
};
|
|
16144
|
+
var RealAuditLogger = class {
|
|
16145
|
+
constructor(resolved, builtinToolIds) {
|
|
16146
|
+
this.resolved = resolved;
|
|
16147
|
+
this.builtinToolIds = builtinToolIds;
|
|
16148
|
+
this.failClosed = resolved.failureMode === "closed";
|
|
16149
|
+
const writer = createAuditS3Writer(resolved.target);
|
|
16150
|
+
this.sink = new AuditSink(resolved, writer, createFsSpoolStore(resolved.spoolDir));
|
|
15550
16151
|
}
|
|
15551
|
-
|
|
15552
|
-
|
|
15553
|
-
|
|
15554
|
-
|
|
16152
|
+
enabled = true;
|
|
16153
|
+
failClosed;
|
|
16154
|
+
sink;
|
|
16155
|
+
lifecycleWriter() {
|
|
16156
|
+
return createAuditS3Writer(this.resolved.target);
|
|
15555
16157
|
}
|
|
15556
|
-
|
|
15557
|
-
|
|
15558
|
-
throw new UnsafeSessionPathError(`Refusing path "${relativePath}": it contains a ".." segment or no file name.`);
|
|
16158
|
+
isBuiltin(id) {
|
|
16159
|
+
return this.builtinToolIds.has(id);
|
|
15559
16160
|
}
|
|
15560
|
-
|
|
15561
|
-
|
|
15562
|
-
|
|
15563
|
-
|
|
15564
|
-
|
|
15565
|
-
|
|
15566
|
-
current = join3(current, segment);
|
|
15567
|
-
let st = await lstat2(current).catch((err3) => errCode2(err3) === "ENOENT" ? null : Promise.reject(err3));
|
|
15568
|
-
if (!st) {
|
|
15569
|
-
try {
|
|
15570
|
-
await mkdir2(current);
|
|
15571
|
-
} catch (err3) {
|
|
15572
|
-
if (errCode2(err3) !== "EEXIST") throw err3;
|
|
15573
|
-
}
|
|
15574
|
-
st = await lstat2(current);
|
|
15575
|
-
}
|
|
15576
|
-
if (!st.isDirectory()) {
|
|
15577
|
-
throw new UnsafeSessionPathError(`Refusing to write under ${current}: it is not a real directory.`);
|
|
15578
|
-
}
|
|
16161
|
+
shouldAuditTool(id) {
|
|
16162
|
+
const t = this.resolved.toolCalls;
|
|
16163
|
+
if (!t.enabled) return false;
|
|
16164
|
+
if (t.exclude.includes(id)) return false;
|
|
16165
|
+
if (t.include.length > 0) return t.include.includes(id);
|
|
16166
|
+
return true;
|
|
15579
16167
|
}
|
|
15580
|
-
|
|
15581
|
-
|
|
15582
|
-
throw new UnsafeSessionPathError(`Refusing to write under ${current}: it resolves outside the session directory.`);
|
|
16168
|
+
shouldAuditSkillSandbox() {
|
|
16169
|
+
return this.resolved.skillSandbox.enabled;
|
|
15583
16170
|
}
|
|
15584
|
-
|
|
15585
|
-
|
|
15586
|
-
|
|
15587
|
-
|
|
15588
|
-
|
|
15589
|
-
|
|
15590
|
-
|
|
15591
|
-
|
|
15592
|
-
await writeFile2(temp, bytes, { flag: "wx" });
|
|
15593
|
-
try {
|
|
15594
|
-
await rename2(temp, destination);
|
|
15595
|
-
} catch (err3) {
|
|
15596
|
-
await unlink(temp).catch(() => {
|
|
16171
|
+
record(event) {
|
|
16172
|
+
this.sink.record(event);
|
|
16173
|
+
}
|
|
16174
|
+
async recordToolCall(ctx) {
|
|
16175
|
+
const event = await buildToolCallEvent(ctx, {
|
|
16176
|
+
maxBytes: this.resolved.payload.maxBytes,
|
|
16177
|
+
captureOutput: this.resolved.payload.captureOutput,
|
|
16178
|
+
redactKeys: this.resolved.payload.redactKeys
|
|
15597
16179
|
});
|
|
15598
|
-
|
|
16180
|
+
if (this.failClosed) await this.sink.recordDurable(event);
|
|
16181
|
+
else this.sink.record(event);
|
|
15599
16182
|
}
|
|
15600
|
-
|
|
15601
|
-
|
|
15602
|
-
async function ensureRealDirectory(sessionDir, relativeDir) {
|
|
15603
|
-
const segments = safeSegments(relativeDir);
|
|
15604
|
-
let current = sessionDir;
|
|
15605
|
-
for (const segment of segments) {
|
|
15606
|
-
current = join3(current, segment);
|
|
15607
|
-
const st = await lstat2(current).catch(() => null);
|
|
15608
|
-
if (st && !st.isDirectory()) {
|
|
15609
|
-
console.warn(`[SKILLS] ${current} is not a real directory; replacing it.`);
|
|
15610
|
-
await unlink(current);
|
|
15611
|
-
}
|
|
16183
|
+
flush() {
|
|
16184
|
+
return this.sink.flush();
|
|
15612
16185
|
}
|
|
15613
|
-
|
|
15614
|
-
|
|
15615
|
-
async function removeEntryInside(sessionDir, relativePath) {
|
|
15616
|
-
const segments = safeSegments(relativePath);
|
|
15617
|
-
const target = join3(sessionDir, ...segments);
|
|
15618
|
-
const root = await realpath(sessionDir);
|
|
15619
|
-
const parentReal = await realpath(dirname2(target)).catch(() => null);
|
|
15620
|
-
if (parentReal === null) return;
|
|
15621
|
-
if (!isInside(root, parentReal)) {
|
|
15622
|
-
throw new UnsafeSessionPathError(`Refusing to remove ${target}: its parent resolves outside the session directory.`);
|
|
16186
|
+
close() {
|
|
16187
|
+
return this.sink.close();
|
|
15623
16188
|
}
|
|
15624
|
-
|
|
15625
|
-
|
|
15626
|
-
if (!st.isDirectory()) {
|
|
15627
|
-
await unlink(target);
|
|
15628
|
-
return;
|
|
16189
|
+
get resolvedConfig() {
|
|
16190
|
+
return this.resolved;
|
|
15629
16191
|
}
|
|
15630
|
-
|
|
15631
|
-
|
|
16192
|
+
};
|
|
16193
|
+
var _instance;
|
|
16194
|
+
var _signalClose;
|
|
16195
|
+
var build = (config, builtinToolIds) => {
|
|
16196
|
+
const resolved = resolveAuditConfig(config);
|
|
16197
|
+
return resolved ? new RealAuditLogger(resolved, builtinToolIds) : noop;
|
|
16198
|
+
};
|
|
16199
|
+
var getAuditLogger = (config) => {
|
|
16200
|
+
if (!_instance) _instance = build(config, /* @__PURE__ */ new Set());
|
|
16201
|
+
return _instance;
|
|
16202
|
+
};
|
|
16203
|
+
var initAudit = async (config, opts) => {
|
|
16204
|
+
_instance = build(config, opts?.builtinToolIds ?? /* @__PURE__ */ new Set());
|
|
16205
|
+
if (_instance instanceof RealAuditLogger) {
|
|
16206
|
+
const r = _instance.resolvedConfig;
|
|
16207
|
+
await applyRetentionLifecycle(_instance.lifecycleWriter(), {
|
|
16208
|
+
prefix: r.target.s3prefix,
|
|
16209
|
+
retentionDays: r.retentionDays,
|
|
16210
|
+
manage: r.manageLifecycle
|
|
16211
|
+
});
|
|
16212
|
+
if (_signalClose) {
|
|
16213
|
+
process.off("SIGTERM", _signalClose);
|
|
16214
|
+
process.off("SIGINT", _signalClose);
|
|
16215
|
+
}
|
|
16216
|
+
const close = () => {
|
|
16217
|
+
void _instance?.close();
|
|
16218
|
+
};
|
|
16219
|
+
_signalClose = close;
|
|
16220
|
+
process.on("SIGTERM", close);
|
|
16221
|
+
process.on("SIGINT", close);
|
|
16222
|
+
}
|
|
16223
|
+
return _instance;
|
|
16224
|
+
};
|
|
16225
|
+
|
|
16226
|
+
// src/exulu/audit/emitters/skill-sandbox.ts
|
|
16227
|
+
var str2 = (v) => v === void 0 || v === null ? void 0 : String(v);
|
|
16228
|
+
var buildSkillSandboxEvent = (ctx, opts = {}) => {
|
|
16229
|
+
const nowIso = opts.nowIso ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
16230
|
+
return {
|
|
16231
|
+
v: 1,
|
|
16232
|
+
ts: nowIso(),
|
|
16233
|
+
type: AUDIT_EVENT_TYPES.SKILL_SANDBOX_CREATED,
|
|
16234
|
+
actor: {
|
|
16235
|
+
kind: "agent",
|
|
16236
|
+
userId: str2(ctx.user?.id),
|
|
16237
|
+
email: ctx.user?.email,
|
|
16238
|
+
roleId: str2(ctx.user?.role?.id),
|
|
16239
|
+
projectId: ctx.projectId
|
|
16240
|
+
},
|
|
16241
|
+
context: {
|
|
16242
|
+
sessionId: ctx.sessionID,
|
|
16243
|
+
agentId: ctx.agent?.id,
|
|
16244
|
+
agentName: ctx.agent?.name
|
|
16245
|
+
},
|
|
16246
|
+
target: { kind: "skill_sandbox", id: ctx.sessionID },
|
|
16247
|
+
status: "ok",
|
|
16248
|
+
data: {
|
|
16249
|
+
skills: ctx.skills.map((s) => ({ id: s.id, name: s.name, version: s.version })),
|
|
16250
|
+
grantedVariableNames: ctx.grantedNames,
|
|
16251
|
+
withheldVariableNames: ctx.withheldNames,
|
|
16252
|
+
skippedVariableNames: ctx.skippedNames,
|
|
16253
|
+
strippedSecretCount: ctx.strippedSecretCount,
|
|
16254
|
+
degradedSandbox: ctx.degradedSandbox
|
|
16255
|
+
},
|
|
16256
|
+
client: ctx.client
|
|
16257
|
+
};
|
|
16258
|
+
};
|
|
15632
16259
|
|
|
15633
16260
|
// ee/invoke-skills/create-sandbox.ts
|
|
16261
|
+
import { createBashTool } from "bash-tool";
|
|
16262
|
+
import { tool as tool2 } from "ai";
|
|
16263
|
+
import { z as z19 } from "zod";
|
|
16264
|
+
import CryptoJS3 from "crypto-js";
|
|
15634
16265
|
var getAllExuluVariables = async () => {
|
|
15635
16266
|
const { db } = await postgresClient();
|
|
15636
16267
|
const rows = await db.from("variables").select("*");
|
|
@@ -15660,8 +16291,8 @@ var backendSecretFiles = () => {
|
|
|
15660
16291
|
const names = [".env", ".env.local", ".env.production", ".env.production.local"];
|
|
15661
16292
|
const paths = /* @__PURE__ */ new Set();
|
|
15662
16293
|
for (const name of names) {
|
|
15663
|
-
paths.add(
|
|
15664
|
-
paths.add(
|
|
16294
|
+
paths.add(join6(cwd, name));
|
|
16295
|
+
paths.add(join6("/app", name));
|
|
15665
16296
|
}
|
|
15666
16297
|
return [...paths];
|
|
15667
16298
|
};
|
|
@@ -15686,18 +16317,18 @@ function probeSandboxSupport() {
|
|
|
15686
16317
|
if (process.platform !== "linux") {
|
|
15687
16318
|
return { canSandbox: false, reason: `Unsupported platform: ${process.platform}` };
|
|
15688
16319
|
}
|
|
15689
|
-
return await new Promise((
|
|
16320
|
+
return await new Promise((resolve5) => {
|
|
15690
16321
|
const child = spawn("bwrap", ["--dev-bind", "/", "/", "--", "/bin/true"], { env: {} });
|
|
15691
16322
|
let stderr = "";
|
|
15692
16323
|
child.stderr.on("data", (chunk) => {
|
|
15693
16324
|
stderr += chunk.toString();
|
|
15694
16325
|
});
|
|
15695
16326
|
child.on("error", (err3) => {
|
|
15696
|
-
|
|
16327
|
+
resolve5({ canSandbox: false, reason: `bwrap not executable: ${err3.message}` });
|
|
15697
16328
|
});
|
|
15698
16329
|
child.on("exit", (code) => {
|
|
15699
|
-
if (code === 0)
|
|
15700
|
-
else
|
|
16330
|
+
if (code === 0) resolve5({ canSandbox: true });
|
|
16331
|
+
else resolve5({ canSandbox: false, reason: stderr.trim() || `bwrap exited ${code}` });
|
|
15701
16332
|
});
|
|
15702
16333
|
});
|
|
15703
16334
|
})();
|
|
@@ -15734,11 +16365,13 @@ async function downloadSkill(skill, skillsDirectory, config) {
|
|
|
15734
16365
|
}
|
|
15735
16366
|
const sessionDir = dirname3(skillsDirectory);
|
|
15736
16367
|
await ensureRealDirectory(sessionDir, `skills/${skill.name}`);
|
|
16368
|
+
let actionsBytes;
|
|
15737
16369
|
for (const file of files) {
|
|
15738
16370
|
const prefixIndex = file.key.indexOf(versionPrefix);
|
|
15739
16371
|
const relativePath = prefixIndex >= 0 ? file.key.slice(prefixIndex + versionPrefix.length) : file.key;
|
|
15740
16372
|
if (!relativePath) continue;
|
|
15741
16373
|
const bytes = await getS3ObjectBytes(file.key, config);
|
|
16374
|
+
if (relativePath === ACTIONS_FILE) actionsBytes = Buffer.from(bytes);
|
|
15742
16375
|
try {
|
|
15743
16376
|
await writeFileInside(sessionDir, `skills/${skill.name}/${relativePath}`, bytes);
|
|
15744
16377
|
} catch (err3) {
|
|
@@ -15746,16 +16379,29 @@ async function downloadSkill(skill, skillsDirectory, config) {
|
|
|
15746
16379
|
console.error(`[SKILLS] Skipping skill file ${file.key}: ${err3.message}`);
|
|
15747
16380
|
}
|
|
15748
16381
|
}
|
|
16382
|
+
return actionsBytes;
|
|
16383
|
+
}
|
|
16384
|
+
async function installSkill(skill, skillsDirectory, config, skillActions) {
|
|
16385
|
+
skillActions.delete(skill.id);
|
|
16386
|
+
const actionsBytes = await downloadSkill(skill, skillsDirectory, config);
|
|
16387
|
+
skillActions.set(skill.id, {
|
|
16388
|
+
skillId: skill.id,
|
|
16389
|
+
name: skill.name,
|
|
16390
|
+
version: skill.current_version,
|
|
16391
|
+
declaration: declarationFromBytes(actionsBytes)
|
|
16392
|
+
});
|
|
15749
16393
|
}
|
|
15750
16394
|
async function removeInstalledSkill(skillsDirectory, skillName) {
|
|
15751
16395
|
const sessionDir = dirname3(skillsDirectory);
|
|
15752
16396
|
await ensureRealDirectory(sessionDir, "skills");
|
|
15753
16397
|
await removeEntryInside(sessionDir, `skills/${skillName}`);
|
|
15754
16398
|
}
|
|
16399
|
+
var SKILLS_READ_ONLY_MESSAGE = (path3) => `writeFile refused: "${path3}" is inside the skills/ folder, which is read-only in a session. Write your files to the session directory instead (e.g. "./out/report.md"). A skill changes only when a new version of it is saved (skill_update or the skill editor); the session picks it up on the next turn or a reload of the skills.`;
|
|
15755
16400
|
function isArtifactPath(absPath, sessionDir, opts = {}) {
|
|
15756
|
-
const resolved =
|
|
16401
|
+
const resolved = resolve4(absPath);
|
|
15757
16402
|
const rel = relative(sessionDir, resolved);
|
|
15758
16403
|
if (!rel || rel.startsWith("..")) return false;
|
|
16404
|
+
if (isActionInputsPath(rel)) return false;
|
|
15759
16405
|
const first = rel.split("/")[0];
|
|
15760
16406
|
if (opts.hasProject && first === PROJECT_DIR) return false;
|
|
15761
16407
|
return first !== "skills";
|
|
@@ -15784,11 +16430,16 @@ function resolveSessionPath(inputPath, sessionDir) {
|
|
|
15784
16430
|
const resolved = posix.resolve(sessionDir, sessionRelative);
|
|
15785
16431
|
if (resolved !== sessionDir && !resolved.startsWith(sessionDir + "/")) {
|
|
15786
16432
|
throw new Error(
|
|
15787
|
-
`Path "${inputPath}" resolves outside the session directory. Use a path inside "${sessionDir}" (relative paths recommended, e.g. "skills/<name>/SKILL.md").`
|
|
16433
|
+
`Path "${inputPath}" resolves outside the session directory. Use a path inside "${sessionDir}" (relative paths recommended, e.g. "out/report.md", or "skills/<name>/SKILL.md" to read a skill).`
|
|
15788
16434
|
);
|
|
15789
16435
|
}
|
|
15790
16436
|
return resolved;
|
|
15791
16437
|
}
|
|
16438
|
+
async function landsInSkills(sessionDir, localPath, key) {
|
|
16439
|
+
if (!await landsInside(sessionDir, localPath, "skills")) return false;
|
|
16440
|
+
console.warn(`[SKILLS] Not writing session file ${key} into the session: it lands in skills/, which only a saved skill version fills.`);
|
|
16441
|
+
return true;
|
|
16442
|
+
}
|
|
15792
16443
|
async function restoreArtifactsFromS3(sessionDir, sessionId, userId, config, opts = {}) {
|
|
15793
16444
|
const userPrefix = `user_${userId}/sessions/${sessionId}/`;
|
|
15794
16445
|
let objects;
|
|
@@ -15811,7 +16462,8 @@ async function restoreArtifactsFromS3(sessionDir, sessionId, userId, config, opt
|
|
|
15811
16462
|
if (!relativePath) continue;
|
|
15812
16463
|
if (isIgnoredArtifactPath(relativePath)) continue;
|
|
15813
16464
|
if (opts.skipProjectDir && relativePath.split("/")[0] === PROJECT_DIR) continue;
|
|
15814
|
-
const localPath =
|
|
16465
|
+
const localPath = join6(sessionDir, relativePath);
|
|
16466
|
+
if (await landsInSkills(sessionDir, localPath, obj.key)) continue;
|
|
15815
16467
|
if (opts.onlyMissing) {
|
|
15816
16468
|
let localSize;
|
|
15817
16469
|
try {
|
|
@@ -15824,7 +16476,7 @@ async function restoreArtifactsFromS3(sessionDir, sessionId, userId, config, opt
|
|
|
15824
16476
|
}
|
|
15825
16477
|
try {
|
|
15826
16478
|
const bytes = await getS3ObjectBytes(obj.key, config);
|
|
15827
|
-
await writeFileInside(sessionDir, relativePath, bytes);
|
|
16479
|
+
await writeFileInside(sessionDir, relativePath, bytes, { notUnder: "skills" });
|
|
15828
16480
|
} catch (err3) {
|
|
15829
16481
|
console.error(
|
|
15830
16482
|
`[SKILLS] Failed to restore artifact ${obj.key} -> ${localPath}; continuing.`,
|
|
@@ -15835,7 +16487,7 @@ async function restoreArtifactsFromS3(sessionDir, sessionId, userId, config, opt
|
|
|
15835
16487
|
}
|
|
15836
16488
|
async function downloadKeyIntoSandbox(opts) {
|
|
15837
16489
|
const { sessionId, userId, fullS3Key, config } = opts;
|
|
15838
|
-
const sessionDir =
|
|
16490
|
+
const sessionDir = join6("/tmp", "exulu-sessions", sessionId);
|
|
15839
16491
|
if (!existsSync4(sessionDir)) {
|
|
15840
16492
|
return { written: false };
|
|
15841
16493
|
}
|
|
@@ -15848,8 +16500,9 @@ async function downloadKeyIntoSandbox(opts) {
|
|
|
15848
16500
|
}
|
|
15849
16501
|
const relativePath = fullS3Key.slice(idx + userPrefix.length);
|
|
15850
16502
|
if (!relativePath) return { written: false };
|
|
16503
|
+
if (await landsInSkills(sessionDir, join6(sessionDir, relativePath), fullS3Key)) return { written: false };
|
|
15851
16504
|
const bytes = await getS3ObjectBytes(fullS3Key, config);
|
|
15852
|
-
const localPath = await writeFileInside(sessionDir, relativePath, bytes);
|
|
16505
|
+
const localPath = await writeFileInside(sessionDir, relativePath, bytes, { notUnder: "skills" });
|
|
15853
16506
|
return { written: true, localPath };
|
|
15854
16507
|
}
|
|
15855
16508
|
async function resolvePythonVenvPath() {
|
|
@@ -15864,11 +16517,11 @@ async function resolvePythonVenvPath() {
|
|
|
15864
16517
|
async function refreshSessionSkills(sessionId, skills, config) {
|
|
15865
16518
|
const cached = sandboxCache.get(sessionId);
|
|
15866
16519
|
if (!cached) return { refreshed: 0, sandbox: false };
|
|
15867
|
-
const skillsDirectory =
|
|
16520
|
+
const skillsDirectory = join6(cached.handle.sessionDir, "skills");
|
|
15868
16521
|
let refreshed = 0;
|
|
15869
16522
|
for (const skill of skills) {
|
|
15870
16523
|
await removeInstalledSkill(skillsDirectory, skill.name);
|
|
15871
|
-
await
|
|
16524
|
+
await installSkill(skill, skillsDirectory, config, cached.skillActions);
|
|
15872
16525
|
cached.installedSkills.set(skill.id, skill.current_version);
|
|
15873
16526
|
refreshed++;
|
|
15874
16527
|
}
|
|
@@ -15886,14 +16539,14 @@ async function createSessionSandbox(sessionId, skills, config, userId, agent, op
|
|
|
15886
16539
|
};
|
|
15887
16540
|
if (cached) {
|
|
15888
16541
|
cached.projectState.projectId = projectId;
|
|
15889
|
-
const skillsDirectory2 =
|
|
16542
|
+
const skillsDirectory2 = join6(cached.handle.sessionDir, "skills");
|
|
15890
16543
|
for (const skill of skills) {
|
|
15891
16544
|
const installedVersion = cached.installedSkills.get(skill.id);
|
|
15892
16545
|
if (installedVersion === skill.current_version) continue;
|
|
15893
16546
|
if (installedVersion !== void 0) {
|
|
15894
16547
|
await removeInstalledSkill(skillsDirectory2, skill.name);
|
|
15895
16548
|
}
|
|
15896
|
-
await
|
|
16549
|
+
await installSkill(skill, skillsDirectory2, config, cached.skillActions);
|
|
15897
16550
|
cached.installedSkills.set(skill.id, skill.current_version);
|
|
15898
16551
|
}
|
|
15899
16552
|
if (userId && config.fileUploads) {
|
|
@@ -15909,13 +16562,15 @@ async function createSessionSandbox(sessionId, skills, config, userId, agent, op
|
|
|
15909
16562
|
await syncProject(cached.handle.sessionDir);
|
|
15910
16563
|
return cached.handle;
|
|
15911
16564
|
}
|
|
15912
|
-
const sessionDir =
|
|
16565
|
+
const sessionDir = join6("/tmp", "exulu-sessions", sessionId);
|
|
15913
16566
|
const dirExisted = existsSync4(sessionDir);
|
|
15914
|
-
await
|
|
15915
|
-
const skillsDirectory =
|
|
16567
|
+
await mkdir4(sessionDir, { recursive: true });
|
|
16568
|
+
const skillsDirectory = join6(sessionDir, "skills");
|
|
16569
|
+
await ensureRealDirectory(sessionDir, "skills");
|
|
15916
16570
|
const installedSkills = /* @__PURE__ */ new Map();
|
|
16571
|
+
const skillActions = /* @__PURE__ */ new Map();
|
|
15917
16572
|
for (const skill of skills) {
|
|
15918
|
-
await
|
|
16573
|
+
await installSkill(skill, skillsDirectory, config, skillActions);
|
|
15919
16574
|
installedSkills.set(skill.id, skill.current_version);
|
|
15920
16575
|
}
|
|
15921
16576
|
const persistenceEnabled = !!(userId && config.fileUploads);
|
|
@@ -15989,7 +16644,21 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
15989
16644
|
...pythonVenvPath ? [pythonVenvPath] : []
|
|
15990
16645
|
],
|
|
15991
16646
|
allowWrite: [sessionDir],
|
|
15992
|
-
|
|
16647
|
+
// Skill folders are read-only inside the sandbox; only the platform (this
|
|
16648
|
+
// process: download, version re-sync, reload, removal) writes them. A script
|
|
16649
|
+
// runs with the rights of whoever triggers it — in a shared session another
|
|
16650
|
+
// speaker — so nothing run in the sandbox may change what a later run executes.
|
|
16651
|
+
// The runtime layers this deny over the session-dir allow:
|
|
16652
|
+
// - macOS (seatbelt): `deny file-write*` + `deny file-write-unlink` on the
|
|
16653
|
+
// subpath come after the allow (later rules win), and unlink of each
|
|
16654
|
+
// ancestor is denied, so a rename of skills/ or a skill's folder fails too.
|
|
16655
|
+
// - Linux (bwrap): `--ro-bind skills skills` after the session-dir `--bind`;
|
|
16656
|
+
// writes get EROFS, renaming the mount point EBUSY, links into it EXDEV.
|
|
16657
|
+
// Paths are resolved through symlinks when each command is wrapped, which is
|
|
16658
|
+
// why skills/ is created above before the first command.
|
|
16659
|
+
// Not enforced in degraded mode (useDirectExec): nothing is. The writeFile
|
|
16660
|
+
// tool refuses skills/ paths itself; bash and runCommand cannot be confined.
|
|
16661
|
+
denyWrite: [skillsDirectory]
|
|
15993
16662
|
}
|
|
15994
16663
|
};
|
|
15995
16664
|
let configuredVariables = {};
|
|
@@ -16010,7 +16679,7 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
16010
16679
|
extraSecretNames: litellmConfigSecretNames(),
|
|
16011
16680
|
overrides: {
|
|
16012
16681
|
...npmGlobalRoot ? { NODE_PATH: npmGlobalRoot } : {},
|
|
16013
|
-
...pythonVenvPath ? { PATH: `${
|
|
16682
|
+
...pythonVenvPath ? { PATH: `${join6(pythonVenvPath, "bin")}:${process.env.PATH ?? ""}`, VIRTUAL_ENV: pythonVenvPath } : {}
|
|
16014
16683
|
}
|
|
16015
16684
|
});
|
|
16016
16685
|
if (skippedNames.length) {
|
|
@@ -16090,7 +16759,7 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
16090
16759
|
if (!persistenceEnabled || !isArtifactPath(absPath, sessionDir, { hasProject })) {
|
|
16091
16760
|
return {};
|
|
16092
16761
|
}
|
|
16093
|
-
const rel = relative(sessionDir,
|
|
16762
|
+
const rel = relative(sessionDir, resolve4(absPath));
|
|
16094
16763
|
const s3Key = artifactS3Key(sessionId, rel);
|
|
16095
16764
|
const out = {};
|
|
16096
16765
|
try {
|
|
@@ -16119,6 +16788,11 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
16119
16788
|
}
|
|
16120
16789
|
async function writeFilesInternal(files, hasProject = hasProjectNow()) {
|
|
16121
16790
|
const results = [];
|
|
16791
|
+
for (const file of files) {
|
|
16792
|
+
if (await landsInside(sessionDir, file.path, "skills")) {
|
|
16793
|
+
throw new Error(SKILLS_READ_ONLY_MESSAGE(file.path));
|
|
16794
|
+
}
|
|
16795
|
+
}
|
|
16122
16796
|
for (const file of files) {
|
|
16123
16797
|
const wrapped = await wrapIfNeeded(
|
|
16124
16798
|
`mkdir -p ${shellQuote(dirname3(file.path))} && cat > ${shellQuote(file.path)}`
|
|
@@ -16151,8 +16825,8 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
16151
16825
|
}
|
|
16152
16826
|
async function snapshotSessionArtifacts(hasProject) {
|
|
16153
16827
|
const map = /* @__PURE__ */ new Map();
|
|
16154
|
-
const skillsDir =
|
|
16155
|
-
const projectDir = hasProject ?
|
|
16828
|
+
const skillsDir = join6(sessionDir, "skills");
|
|
16829
|
+
const projectDir = hasProject ? join6(sessionDir, PROJECT_DIR) : null;
|
|
16156
16830
|
const walk = async (dir) => {
|
|
16157
16831
|
let entries;
|
|
16158
16832
|
try {
|
|
@@ -16161,7 +16835,7 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
16161
16835
|
return;
|
|
16162
16836
|
}
|
|
16163
16837
|
for (const entry of entries) {
|
|
16164
|
-
const full =
|
|
16838
|
+
const full = join6(dir, entry.name);
|
|
16165
16839
|
if (full === skillsDir) continue;
|
|
16166
16840
|
if (projectDir !== null && full === projectDir) continue;
|
|
16167
16841
|
if (isIgnoredArtifactPath(relative(sessionDir, full))) continue;
|
|
@@ -16187,10 +16861,10 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
16187
16861
|
destination: sessionDir
|
|
16188
16862
|
});
|
|
16189
16863
|
const writeFileTool = tool2({
|
|
16190
|
-
description: 'Write content to a file in the sandbox. Creates parent directories if needed. Paths are always resolved against the session sandbox root \u2014 both relative paths ("
|
|
16191
|
-
inputSchema:
|
|
16192
|
-
path:
|
|
16193
|
-
content:
|
|
16864
|
+
description: 'Write content to a file in the sandbox. Creates parent directories if needed. Paths are always resolved against the session sandbox root \u2014 both relative paths ("report.md", "out/report.md") and leading-slash paths ("/out/report.md") work and reach the same file. The skills/ folder is read-only: a path inside it is refused. A skill changes only when a new version of it is saved (skill_update or the skill editor); write your own files to the session directory. When the path is under the session artifact tree, the file is also uploaded to S3 and a short-lived presigned URL is returned in the tool output.',
|
|
16865
|
+
inputSchema: z19.object({
|
|
16866
|
+
path: z19.string().describe("The path where the file should be written. Relative paths and leading-slash paths are both resolved against the session sandbox root."),
|
|
16867
|
+
content: z19.string().describe("The content to write to the file")
|
|
16194
16868
|
}),
|
|
16195
16869
|
execute: async ({ path: path3, content }) => {
|
|
16196
16870
|
const hasProject = hasProjectNow();
|
|
@@ -16210,8 +16884,8 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
16210
16884
|
});
|
|
16211
16885
|
const readFileTool = tool2({
|
|
16212
16886
|
description: 'Read the contents of a file from the sandbox. Paths are always resolved against the session sandbox root \u2014 both relative paths ("skills/<Skill name>/SKILL.md") and leading-slash paths ("/skills/<Skill name>/SKILL.md") work and reach the same file. Skills live in a folder per skill: "skills/<Skill name>/SKILL.md", never "skills/<Skill name>.md". If the file does not exist, the error message is surfaced verbatim.',
|
|
16213
|
-
inputSchema:
|
|
16214
|
-
path:
|
|
16887
|
+
inputSchema: z19.object({
|
|
16888
|
+
path: z19.string().describe("The path of the file to read. Relative paths and leading-slash paths are both resolved against the session sandbox root.")
|
|
16215
16889
|
}),
|
|
16216
16890
|
execute: async ({ path: path3 }) => {
|
|
16217
16891
|
const resolvedPath = resolveSessionPath(path3, sessionDir);
|
|
@@ -16225,77 +16899,123 @@ Probe error: ${probe.reason ?? "(no detail)"}`
|
|
|
16225
16899
|
return { content };
|
|
16226
16900
|
}
|
|
16227
16901
|
});
|
|
16902
|
+
async function runWithArtifactMirroring(execute) {
|
|
16903
|
+
const hasProject = hasProjectNow();
|
|
16904
|
+
const before = persistenceEnabled ? await snapshotSessionArtifacts(hasProject) : null;
|
|
16905
|
+
const result = await execute();
|
|
16906
|
+
const artifacts = [];
|
|
16907
|
+
if (persistenceEnabled && before) {
|
|
16908
|
+
const skipProject = hasProject || hasProjectNow();
|
|
16909
|
+
const after = await snapshotSessionArtifacts(skipProject);
|
|
16910
|
+
const changedPaths = [];
|
|
16911
|
+
for (const [path3, mtime] of after) {
|
|
16912
|
+
const beforeMtime = before.get(path3);
|
|
16913
|
+
if (beforeMtime === void 0 || beforeMtime < mtime) {
|
|
16914
|
+
changedPaths.push(path3);
|
|
16915
|
+
}
|
|
16916
|
+
}
|
|
16917
|
+
for (const path3 of changedPaths) {
|
|
16918
|
+
try {
|
|
16919
|
+
const content = await readRegularFileInside(sessionDir, path3);
|
|
16920
|
+
if (content === null) continue;
|
|
16921
|
+
const persisted = await persistArtifactToS3(path3, content, skipProject);
|
|
16922
|
+
artifacts.push({
|
|
16923
|
+
path: path3,
|
|
16924
|
+
relativePath: relative(sessionDir, path3),
|
|
16925
|
+
key: persisted.key,
|
|
16926
|
+
url: persisted.url
|
|
16927
|
+
});
|
|
16928
|
+
} catch (err3) {
|
|
16929
|
+
console.error(
|
|
16930
|
+
`[SKILLS] Failed to mirror bash-produced artifact ${path3} to S3; continuing.`,
|
|
16931
|
+
err3
|
|
16932
|
+
);
|
|
16933
|
+
}
|
|
16934
|
+
}
|
|
16935
|
+
}
|
|
16936
|
+
let stdout = result?.stdout ?? "";
|
|
16937
|
+
const { kept, omitted } = capArtifacts(artifacts);
|
|
16938
|
+
const withUrls = kept.filter((a) => a.url);
|
|
16939
|
+
if (withUrls.length > 0) {
|
|
16940
|
+
const lines = [];
|
|
16941
|
+
for (const a of withUrls) {
|
|
16942
|
+
lines.push(` ${a.relativePath}: ${a.url}`);
|
|
16943
|
+
}
|
|
16944
|
+
if (omitted > 0) {
|
|
16945
|
+
lines.push(` \u2026 ${omitted} more file(s) were created and mirrored but are not listed here.`);
|
|
16946
|
+
}
|
|
16947
|
+
stdout = appendArtifactsBlock(stdout, lines);
|
|
16948
|
+
}
|
|
16949
|
+
return {
|
|
16950
|
+
...result,
|
|
16951
|
+
stdout,
|
|
16952
|
+
artifacts: kept,
|
|
16953
|
+
...omitted > 0 ? { artifactsOmitted: omitted } : {}
|
|
16954
|
+
};
|
|
16955
|
+
}
|
|
16228
16956
|
const originalBashTool = tools.bash;
|
|
16229
16957
|
const bashTool = tool2({
|
|
16230
16958
|
description: originalBashTool.description ?? "",
|
|
16231
|
-
inputSchema:
|
|
16232
|
-
command:
|
|
16959
|
+
inputSchema: z19.object({
|
|
16960
|
+
command: z19.string().describe("The bash command to execute.")
|
|
16233
16961
|
}),
|
|
16234
16962
|
execute: async (args, opts2) => {
|
|
16235
|
-
const hasProject = hasProjectNow();
|
|
16236
|
-
const before = persistenceEnabled ? await snapshotSessionArtifacts(hasProject) : null;
|
|
16237
16963
|
const originalExecute = originalBashTool.execute;
|
|
16238
16964
|
if (!originalExecute) {
|
|
16239
16965
|
throw new Error("bash tool execute is undefined");
|
|
16240
16966
|
}
|
|
16241
|
-
|
|
16242
|
-
|
|
16243
|
-
|
|
16244
|
-
|
|
16245
|
-
|
|
16246
|
-
|
|
16247
|
-
|
|
16248
|
-
|
|
16249
|
-
|
|
16250
|
-
|
|
16251
|
-
|
|
16252
|
-
|
|
16253
|
-
|
|
16967
|
+
return runWithArtifactMirroring(() => originalExecute(args, opts2));
|
|
16968
|
+
}
|
|
16969
|
+
});
|
|
16970
|
+
const runCommand = (command, options = {}) => runWithArtifactMirroring(async () => {
|
|
16971
|
+
const wrapped = await wrapIfNeeded(`cd ${shellQuote(sessionDir)} && ${command}`);
|
|
16972
|
+
const callEnv = { ...sandboxedExecEnv, ...options.extraEnv ?? {} };
|
|
16973
|
+
return await new Promise((resolvePromise) => {
|
|
16974
|
+
const child = spawn("/bin/bash", ["-c", wrapped], { env: callEnv, cwd: sessionDir, detached: true });
|
|
16975
|
+
let stdout = "";
|
|
16976
|
+
let stderr = "";
|
|
16977
|
+
let timedOut = false;
|
|
16978
|
+
let settled = false;
|
|
16979
|
+
let timer;
|
|
16980
|
+
const append = (cur, chunk) => cur.length >= EXEC_MAX_BUFFER ? cur : (cur + chunk).slice(0, EXEC_MAX_BUFFER);
|
|
16981
|
+
child.stdout?.setEncoding("utf8");
|
|
16982
|
+
child.stderr?.setEncoding("utf8");
|
|
16983
|
+
child.stdout?.on("data", (c) => {
|
|
16984
|
+
stdout = append(stdout, c);
|
|
16985
|
+
});
|
|
16986
|
+
child.stderr?.on("data", (c) => {
|
|
16987
|
+
stderr = append(stderr, c);
|
|
16988
|
+
});
|
|
16989
|
+
const finish = (exitCode) => {
|
|
16990
|
+
if (settled) return;
|
|
16991
|
+
settled = true;
|
|
16992
|
+
if (timer) clearTimeout(timer);
|
|
16993
|
+
resolvePromise({ stdout, stderr, exitCode: timedOut ? 124 : exitCode, timedOut });
|
|
16994
|
+
};
|
|
16995
|
+
if (options.timeoutMs !== void 0 && options.timeoutMs > 0) {
|
|
16996
|
+
timer = setTimeout(() => {
|
|
16997
|
+
timedOut = true;
|
|
16254
16998
|
try {
|
|
16255
|
-
|
|
16256
|
-
|
|
16257
|
-
|
|
16258
|
-
artifacts.push({
|
|
16259
|
-
path: path3,
|
|
16260
|
-
relativePath: relative(sessionDir, path3),
|
|
16261
|
-
key: persisted.key,
|
|
16262
|
-
url: persisted.url
|
|
16263
|
-
});
|
|
16264
|
-
} catch (err3) {
|
|
16265
|
-
console.error(
|
|
16266
|
-
`[SKILLS] Failed to mirror bash-produced artifact ${path3} to S3; continuing.`,
|
|
16267
|
-
err3
|
|
16268
|
-
);
|
|
16999
|
+
if (child.pid) process.kill(-child.pid, "SIGKILL");
|
|
17000
|
+
} catch {
|
|
17001
|
+
child.kill("SIGKILL");
|
|
16269
17002
|
}
|
|
16270
|
-
}
|
|
16271
|
-
}
|
|
16272
|
-
let stdout = result?.stdout ?? "";
|
|
16273
|
-
const { kept, omitted } = capArtifacts(artifacts);
|
|
16274
|
-
const withUrls = kept.filter((a) => a.url);
|
|
16275
|
-
if (withUrls.length > 0) {
|
|
16276
|
-
const lines = ["", "[exulu-artifacts]"];
|
|
16277
|
-
for (const a of withUrls) {
|
|
16278
|
-
lines.push(` ${a.relativePath}: ${a.url}`);
|
|
16279
|
-
}
|
|
16280
|
-
if (omitted > 0) {
|
|
16281
|
-
lines.push(` \u2026 ${omitted} more file(s) were created and mirrored but are not listed here.`);
|
|
16282
|
-
}
|
|
16283
|
-
stdout = `${stdout}
|
|
16284
|
-
${lines.join("\n")}`;
|
|
17003
|
+
}, options.timeoutMs);
|
|
16285
17004
|
}
|
|
16286
|
-
|
|
16287
|
-
|
|
16288
|
-
|
|
16289
|
-
|
|
16290
|
-
|
|
16291
|
-
|
|
16292
|
-
}
|
|
17005
|
+
child.on("error", (err3) => {
|
|
17006
|
+
stderr = `${stderr}${err3.message}`;
|
|
17007
|
+
finish(1);
|
|
17008
|
+
});
|
|
17009
|
+
child.on("close", (code, signal) => finish(typeof code === "number" ? code : signal ? 128 : 1));
|
|
17010
|
+
});
|
|
16293
17011
|
});
|
|
16294
17012
|
const wrappedTools = { ...tools, bash: bashTool, readFile: readFileTool, writeFile: writeFileTool };
|
|
16295
17013
|
const handle = {
|
|
16296
17014
|
sessionDir,
|
|
16297
17015
|
tools: wrappedTools,
|
|
16298
17016
|
wrapCommand: (command) => wrapIfNeeded(command),
|
|
17017
|
+
runCommand,
|
|
17018
|
+
skillActions,
|
|
16299
17019
|
cleanup: async () => {
|
|
16300
17020
|
sandboxCache.delete(sessionId);
|
|
16301
17021
|
if (!useDirectExec) {
|
|
@@ -16305,7 +17025,7 @@ ${lines.join("\n")}`;
|
|
|
16305
17025
|
await clearProjectSyncMarker(sessionDir);
|
|
16306
17026
|
}
|
|
16307
17027
|
};
|
|
16308
|
-
sandboxCache.set(sessionId, { handle, installedSkills, projectState });
|
|
17028
|
+
sandboxCache.set(sessionId, { handle, installedSkills, skillActions, projectState });
|
|
16309
17029
|
return handle;
|
|
16310
17030
|
}
|
|
16311
17031
|
|
|
@@ -16437,7 +17157,7 @@ function buildSaveSessionFile(args) {
|
|
|
16437
17157
|
}
|
|
16438
17158
|
|
|
16439
17159
|
// src/templates/tools/routine-status-tool.ts
|
|
16440
|
-
import { z as
|
|
17160
|
+
import { z as z20 } from "zod";
|
|
16441
17161
|
var SET_ROUTINE_STATUS_TOOL_ID = "set_routine_status";
|
|
16442
17162
|
function createRoutineStatusTool(handle) {
|
|
16443
17163
|
if (!handle || handle.statuses.length === 0) return void 0;
|
|
@@ -16450,8 +17170,8 @@ function createRoutineStatusTool(handle) {
|
|
|
16450
17170
|
category: "routines",
|
|
16451
17171
|
type: "function",
|
|
16452
17172
|
needsApproval: false,
|
|
16453
|
-
inputSchema:
|
|
16454
|
-
status:
|
|
17173
|
+
inputSchema: z20.object({
|
|
17174
|
+
status: z20.enum(keys).describe("The work status key to set.")
|
|
16455
17175
|
}),
|
|
16456
17176
|
config: [],
|
|
16457
17177
|
execute: async ({ status }) => {
|
|
@@ -16491,7 +17211,7 @@ var truncateToolOutput = (output, maxContextLength, toolName, tailFraction = 0.1
|
|
|
16491
17211
|
};
|
|
16492
17212
|
|
|
16493
17213
|
// src/exulu/tool-output-offload.ts
|
|
16494
|
-
import { randomUUID as
|
|
17214
|
+
import { randomUUID as randomUUID8 } from "crypto";
|
|
16495
17215
|
|
|
16496
17216
|
// src/exulu/context-budget.ts
|
|
16497
17217
|
var DEFAULT_CONTEXT_WINDOW = 128e3;
|
|
@@ -16595,7 +17315,7 @@ var PREVIEW_CHARS = 4e3;
|
|
|
16595
17315
|
var storeAsSessionFile = async (serialized, ctx) => {
|
|
16596
17316
|
if (!ctx.sessionID || !ctx.exuluConfig?.fileUploads) return void 0;
|
|
16597
17317
|
const safeTool = ctx.toolName.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 40);
|
|
16598
|
-
const name = `tool-output-${safeTool}-${
|
|
17318
|
+
const name = `tool-output-${safeTool}-${randomUUID8().slice(0, 8)}.txt`;
|
|
16599
17319
|
try {
|
|
16600
17320
|
await uploadFile(
|
|
16601
17321
|
Buffer.from(serialized, "utf-8"),
|
|
@@ -16663,7 +17383,7 @@ var buildAuthToolModelOutput = (tool3) => ({ output }) => {
|
|
|
16663
17383
|
};
|
|
16664
17384
|
|
|
16665
17385
|
// src/templates/tools/session-file-read-tool.ts
|
|
16666
|
-
import { z as
|
|
17386
|
+
import { z as z21 } from "zod";
|
|
16667
17387
|
|
|
16668
17388
|
// src/templates/tools/resolve-file-key.ts
|
|
16669
17389
|
var NO_PROJECT_FILES_ERROR = "This session has no project files.";
|
|
@@ -16744,10 +17464,10 @@ var createSessionFileReadTool = ({
|
|
|
16744
17464
|
name: SESSION_FILE_READ_TOOL_NAME,
|
|
16745
17465
|
needsApproval: false,
|
|
16746
17466
|
description: "Read a line range from a file stored in this session's files \u2014 including offloaded tool outputs (tool-output-*.txt) and uploaded documents. Use offset (1-based line number) and limit to page through large files instead of reading everything at once. Files of the session's project are addressed as `project/<name>` and are read-only.",
|
|
16747
|
-
inputSchema:
|
|
16748
|
-
filename:
|
|
16749
|
-
offset:
|
|
16750
|
-
limit:
|
|
17467
|
+
inputSchema: z21.object({
|
|
17468
|
+
filename: z21.string().describe('Exact session file name as referenced in a truncation notice, e.g. "tool-output-web_search-a1b2c3d4.txt"'),
|
|
17469
|
+
offset: z21.number().int().min(1).optional().describe("1-based first line to read (default 1)"),
|
|
17470
|
+
limit: z21.number().int().min(1).max(1e3).optional().describe(`Number of lines to read (default ${DEFAULT_LIMIT})`)
|
|
16751
17471
|
}),
|
|
16752
17472
|
type: "function",
|
|
16753
17473
|
category: "session",
|
|
@@ -16760,7 +17480,7 @@ var createSessionFileReadTool = ({
|
|
|
16760
17480
|
};
|
|
16761
17481
|
|
|
16762
17482
|
// src/templates/tools/parse-document-tool.ts
|
|
16763
|
-
import { z as
|
|
17483
|
+
import { z as z22 } from "zod";
|
|
16764
17484
|
import { extname as extname2 } from "path";
|
|
16765
17485
|
import { parseOfficeAsync as parseOfficeAsync2 } from "officeparser";
|
|
16766
17486
|
|
|
@@ -16770,7 +17490,7 @@ import { promisify as promisify4 } from "util";
|
|
|
16770
17490
|
import { existsSync as existsSync5 } from "fs";
|
|
16771
17491
|
import { mkdtemp, readdir as readdir3, readFile as readFile2, rm as rm3, writeFile as writeFile3 } from "fs/promises";
|
|
16772
17492
|
import { tmpdir } from "os";
|
|
16773
|
-
import { join as
|
|
17493
|
+
import { join as join7 } from "path";
|
|
16774
17494
|
var execFileAsync2 = promisify4(execFile2);
|
|
16775
17495
|
var MAX_STDOUT_BYTES = 64 * 1024 * 1024;
|
|
16776
17496
|
var LEGACY_OFFICE_CONVERSION_TARGETS = {
|
|
@@ -16787,9 +17507,9 @@ async function convertLegacyOfficeToModern(bytes, ext) {
|
|
|
16787
17507
|
if (!target) {
|
|
16788
17508
|
throw new Error(`No modern-format conversion target registered for "${ext}"`);
|
|
16789
17509
|
}
|
|
16790
|
-
const dir = await mkdtemp(
|
|
17510
|
+
const dir = await mkdtemp(join7(tmpdir(), "exulu-officeconv-"));
|
|
16791
17511
|
try {
|
|
16792
|
-
const inputPath =
|
|
17512
|
+
const inputPath = join7(dir, `input${ext}`);
|
|
16793
17513
|
await writeFile3(inputPath, bytes);
|
|
16794
17514
|
try {
|
|
16795
17515
|
await execFileAsync2(
|
|
@@ -16802,7 +17522,7 @@ async function convertLegacyOfficeToModern(bytes, ext) {
|
|
|
16802
17522
|
`LibreOffice could not convert the legacy "${ext}" file to ${target}: ` + (err3 instanceof Error ? err3.message : String(err3))
|
|
16803
17523
|
);
|
|
16804
17524
|
}
|
|
16805
|
-
const outputPath =
|
|
17525
|
+
const outputPath = join7(dir, `input.${target}`);
|
|
16806
17526
|
if (!existsSync5(outputPath)) {
|
|
16807
17527
|
throw new Error(`LibreOffice produced no output converting "${ext}" to ${target}`);
|
|
16808
17528
|
}
|
|
@@ -16812,9 +17532,9 @@ async function convertLegacyOfficeToModern(bytes, ext) {
|
|
|
16812
17532
|
}
|
|
16813
17533
|
}
|
|
16814
17534
|
async function pdfToText(pdf) {
|
|
16815
|
-
const dir = await mkdtemp(
|
|
17535
|
+
const dir = await mkdtemp(join7(tmpdir(), "exulu-parse-"));
|
|
16816
17536
|
try {
|
|
16817
|
-
const inputPath =
|
|
17537
|
+
const inputPath = join7(dir, "input.pdf");
|
|
16818
17538
|
await writeFile3(inputPath, pdf);
|
|
16819
17539
|
const { stdout } = await execFileAsync2("pdftotext", ["-layout", inputPath, "-"], {
|
|
16820
17540
|
timeout: 6e4,
|
|
@@ -16826,9 +17546,9 @@ async function pdfToText(pdf) {
|
|
|
16826
17546
|
}
|
|
16827
17547
|
}
|
|
16828
17548
|
async function pdfPageCount(pdf) {
|
|
16829
|
-
const dir = await mkdtemp(
|
|
17549
|
+
const dir = await mkdtemp(join7(tmpdir(), "exulu-pdfinfo-"));
|
|
16830
17550
|
try {
|
|
16831
|
-
const inputPath =
|
|
17551
|
+
const inputPath = join7(dir, "input.pdf");
|
|
16832
17552
|
await writeFile3(inputPath, pdf);
|
|
16833
17553
|
const { stdout } = await execFileAsync2("pdfinfo", [inputPath], { timeout: 3e4, maxBuffer: 1e6 });
|
|
16834
17554
|
const match = /^Pages:\s+(\d+)/m.exec(stdout);
|
|
@@ -16839,14 +17559,14 @@ async function pdfPageCount(pdf) {
|
|
|
16839
17559
|
}
|
|
16840
17560
|
}
|
|
16841
17561
|
async function renderPdfPageToPng(pdf, page, scaleTo) {
|
|
16842
|
-
const dir = await mkdtemp(
|
|
17562
|
+
const dir = await mkdtemp(join7(tmpdir(), "exulu-render-"));
|
|
16843
17563
|
try {
|
|
16844
|
-
const inputPath =
|
|
17564
|
+
const inputPath = join7(dir, "input.pdf");
|
|
16845
17565
|
await writeFile3(inputPath, pdf);
|
|
16846
17566
|
try {
|
|
16847
17567
|
await execFileAsync2(
|
|
16848
17568
|
"pdftoppm",
|
|
16849
|
-
["-png", "-f", String(page), "-l", String(page), "-scale-to", String(scaleTo), inputPath,
|
|
17569
|
+
["-png", "-f", String(page), "-l", String(page), "-scale-to", String(scaleTo), inputPath, join7(dir, "page")],
|
|
16850
17570
|
{ timeout: 6e4, maxBuffer: MAX_STDOUT_BYTES }
|
|
16851
17571
|
);
|
|
16852
17572
|
} catch (err3) {
|
|
@@ -16855,7 +17575,7 @@ async function renderPdfPageToPng(pdf, page, scaleTo) {
|
|
|
16855
17575
|
}
|
|
16856
17576
|
const produced = (await readdir3(dir)).find((f) => f.startsWith("page") && f.endsWith(".png"));
|
|
16857
17577
|
if (!produced) return null;
|
|
16858
|
-
return await readFile2(
|
|
17578
|
+
return await readFile2(join7(dir, produced));
|
|
16859
17579
|
} finally {
|
|
16860
17580
|
await rm3(dir, { recursive: true, force: true });
|
|
16861
17581
|
}
|
|
@@ -17412,8 +18132,8 @@ ${text.trim()}`).join("\n")
|
|
|
17412
18132
|
while (true) {
|
|
17413
18133
|
while (queue.length > 0) yield queue.shift();
|
|
17414
18134
|
if (finished) break;
|
|
17415
|
-
await new Promise((
|
|
17416
|
-
wake =
|
|
18135
|
+
await new Promise((resolve5) => {
|
|
18136
|
+
wake = resolve5;
|
|
17417
18137
|
});
|
|
17418
18138
|
wake = void 0;
|
|
17419
18139
|
}
|
|
@@ -17430,11 +18150,11 @@ ${text.trim()}`).join("\n")
|
|
|
17430
18150
|
// Without a document processor the tool reads the text layer only: say so, and keep the
|
|
17431
18151
|
// original wording so existing deployments see no change beyond the reuse sentence.
|
|
17432
18152
|
description: exuluConfig.attachments?.documentProcessor ? "Extract the text of an uploaded PDF or Office document from this session's files, with \"--- page N ---\" markers for PDFs so you can locate content by page. Results are stored and reused, so reading the same document again is fast, but the first read of a long document can take minutes. To SEE a page or an image inside a document, use view_document_page. Files of the session's project are addressed as `project/<name>` and are read-only." : "Extract the text of an uploaded PDF or Office document from this session's files, with \"--- page N ---\" markers for PDFs so you can locate content by page. Free and fast (no OCR): works only on documents with a real text layer. To SEE a page or an image inside a document, use view_document_page. Extracted text is stored and reused, so reading the same document again is fast. Files of the session's project are addressed as `project/<name>` and are read-only.",
|
|
17433
|
-
inputSchema:
|
|
17434
|
-
filename:
|
|
17435
|
-
pages:
|
|
17436
|
-
offset:
|
|
17437
|
-
limit:
|
|
18153
|
+
inputSchema: z22.object({
|
|
18154
|
+
filename: z22.string().describe('Exact session file name, e.g. "report.pdf"'),
|
|
18155
|
+
pages: z22.string().optional().describe('PDF page or range to extract, e.g. "2" or "1-5" (default: all pages) (PDF only)'),
|
|
18156
|
+
offset: z22.number().int().min(1).optional().describe("1-based first output line to read (default 1)"),
|
|
18157
|
+
limit: z22.number().int().min(1).max(1e3).optional().describe(`Number of lines to read (default ${DEFAULT_LIMIT2})`)
|
|
17438
18158
|
}),
|
|
17439
18159
|
type: "function",
|
|
17440
18160
|
category: "session",
|
|
@@ -17447,19 +18167,19 @@ ${text.trim()}`).join("\n")
|
|
|
17447
18167
|
};
|
|
17448
18168
|
|
|
17449
18169
|
// src/templates/tools/view-document-page-tool.ts
|
|
17450
|
-
import { z as
|
|
18170
|
+
import { z as z23 } from "zod";
|
|
17451
18171
|
import { extname as extname4 } from "path";
|
|
17452
18172
|
|
|
17453
18173
|
// src/sessions/pdf-preview-cache.ts
|
|
17454
18174
|
import { exec as exec3 } from "child_process";
|
|
17455
18175
|
import { existsSync as existsSync6 } from "fs";
|
|
17456
|
-
import { mkdir as
|
|
17457
|
-
import { extname as extname3, join as
|
|
18176
|
+
import { mkdir as mkdir5, readFile as readFile3, rename as rename3, rm as rm4, writeFile as writeFile4 } from "fs/promises";
|
|
18177
|
+
import { extname as extname3, join as join8 } from "path";
|
|
17458
18178
|
import { promisify as promisify5 } from "util";
|
|
17459
18179
|
var execAsync3 = promisify5(exec3);
|
|
17460
18180
|
var CACHE_ROOT = "/tmp/exulu-pdf-cache";
|
|
17461
|
-
var CACHE_IN =
|
|
17462
|
-
var CACHE_OUT =
|
|
18181
|
+
var CACHE_IN = join8(CACHE_ROOT, "_in");
|
|
18182
|
+
var CACHE_OUT = join8(CACHE_ROOT, "_out");
|
|
17463
18183
|
var inFlight2 = /* @__PURE__ */ new Map();
|
|
17464
18184
|
var PreviewRenderError = class extends Error {
|
|
17465
18185
|
constructor(message) {
|
|
@@ -17476,7 +18196,7 @@ async function getPdfPreviewBytes(opts) {
|
|
|
17476
18196
|
if (!safeEtag) {
|
|
17477
18197
|
throw new PreviewRenderError(`Invalid ETag for ${sourceKey}`);
|
|
17478
18198
|
}
|
|
17479
|
-
const cachedPath =
|
|
18199
|
+
const cachedPath = join8(CACHE_ROOT, `${safeEtag}.pdf`);
|
|
17480
18200
|
if (existsSync6(cachedPath)) {
|
|
17481
18201
|
return readFile3(cachedPath);
|
|
17482
18202
|
}
|
|
@@ -17484,11 +18204,11 @@ async function getPdfPreviewBytes(opts) {
|
|
|
17484
18204
|
if (existing) return existing;
|
|
17485
18205
|
const promise = (async () => {
|
|
17486
18206
|
try {
|
|
17487
|
-
await
|
|
17488
|
-
await
|
|
18207
|
+
await mkdir5(CACHE_IN, { recursive: true });
|
|
18208
|
+
await mkdir5(CACHE_OUT, { recursive: true });
|
|
17489
18209
|
const ext = (extname3(sourceKey) || ".docx").toLowerCase();
|
|
17490
|
-
const inputPath =
|
|
17491
|
-
const outputPath =
|
|
18210
|
+
const inputPath = join8(CACHE_IN, `${safeEtag}${ext}`);
|
|
18211
|
+
const outputPath = join8(CACHE_OUT, `${safeEtag}.pdf`);
|
|
17492
18212
|
try {
|
|
17493
18213
|
const bytes = await getS3ObjectBytes(sourceKey, config);
|
|
17494
18214
|
await writeFile4(inputPath, bytes);
|
|
@@ -17722,9 +18442,9 @@ var createViewDocumentPageTool = ({
|
|
|
17722
18442
|
name: VIEW_DOCUMENT_PAGE_TOOL_NAME,
|
|
17723
18443
|
needsApproval: false,
|
|
17724
18444
|
description: "LOOK at a page of an uploaded PDF/Office document, or at an uploaded image, from this session's files. The rendered image is attached as a user message directly after this tool result so you can visually analyze photos, charts, scans, and layouts. Use parse_document first to find which page you need. Requires a vision-capable model. Files of the session's project are addressed as `project/<name>` and are read-only.",
|
|
17725
|
-
inputSchema:
|
|
17726
|
-
filename:
|
|
17727
|
-
page:
|
|
18445
|
+
inputSchema: z23.object({
|
|
18446
|
+
filename: z23.string().describe('Exact session file name, e.g. "report.pdf" or "screenshot.png"'),
|
|
18447
|
+
page: z23.number().int().min(1).optional().describe("Page number to render (default 1; ignored for image files)")
|
|
17728
18448
|
}),
|
|
17729
18449
|
type: "function",
|
|
17730
18450
|
category: "session",
|
|
@@ -17773,7 +18493,7 @@ var isReadingProgress = (value) => {
|
|
|
17773
18493
|
return typeof v.filename === "string" && typeof v.pagesDone === "number" && typeof v.pagesTotal === "number";
|
|
17774
18494
|
};
|
|
17775
18495
|
var OUTPUT_OFFLOAD_EXEMPT_TOOL_IDS = /* @__PURE__ */ new Set(["agentic_context_search"]);
|
|
17776
|
-
var generateS3Key = (filename) => `${
|
|
18496
|
+
var generateS3Key = (filename) => `${randomUUID9()}-${filename}`;
|
|
17777
18497
|
var s3Client2;
|
|
17778
18498
|
var hydrateVariables = async (tool3) => {
|
|
17779
18499
|
const { db } = await postgresClient();
|
|
@@ -17971,6 +18691,8 @@ var convertExuluToolsToAiSdkTools = async (currentTools, currentSkills, approved
|
|
|
17971
18691
|
if (viewDocumentPageTool && !disabled.has(viewDocumentPageTool.id)) {
|
|
17972
18692
|
currentTools.push(viewDocumentPageTool);
|
|
17973
18693
|
}
|
|
18694
|
+
let agenticSearchActive = false;
|
|
18695
|
+
let projectSearchContextIds;
|
|
17974
18696
|
console.log("[EXULU] Creating agentic search tool", contexts?.length, model);
|
|
17975
18697
|
if (contexts?.length && model && !disabled.has("agentic_context_search")) {
|
|
17976
18698
|
const index = currentTools.findIndex((tool3) => tool3.id === "agentic_context_search");
|
|
@@ -17988,6 +18710,7 @@ var convertExuluToolsToAiSdkTools = async (currentTools, currentSkills, approved
|
|
|
17988
18710
|
projectScope
|
|
17989
18711
|
});
|
|
17990
18712
|
if (agenticSearchTool) {
|
|
18713
|
+
agenticSearchActive = true;
|
|
17991
18714
|
currentTools[index] = {
|
|
17992
18715
|
...currentTools[index],
|
|
17993
18716
|
// important to keep the original tool config
|
|
@@ -18016,6 +18739,7 @@ var convertExuluToolsToAiSdkTools = async (currentTools, currentSkills, approved
|
|
|
18016
18739
|
projectScope
|
|
18017
18740
|
});
|
|
18018
18741
|
if (projectSearchTool) {
|
|
18742
|
+
projectSearchContextIds = scopedContexts.map((c) => c.id);
|
|
18019
18743
|
currentTools.push(projectSearchTool);
|
|
18020
18744
|
}
|
|
18021
18745
|
}
|
|
@@ -18026,6 +18750,38 @@ var convertExuluToolsToAiSdkTools = async (currentTools, currentSkills, approved
|
|
|
18026
18750
|
currentTools.splice(currentTools.indexOf(agenticSearchTool), 1);
|
|
18027
18751
|
}
|
|
18028
18752
|
}
|
|
18753
|
+
if (sharedSessionSandbox && !disabled.has(RUN_SKILL_ACTION_TOOL_ID)) {
|
|
18754
|
+
const loadedActions = loadSkillActions(
|
|
18755
|
+
sharedSessionSandbox.sessionDir,
|
|
18756
|
+
currentSkills ?? [],
|
|
18757
|
+
sharedSessionSandbox.skillActions
|
|
18758
|
+
);
|
|
18759
|
+
const hasActions = Object.values(loadedActions.bySkill).some((s) => Object.keys(s.actions).length > 0);
|
|
18760
|
+
if (hasActions || loadedActions.problems.length > 0) {
|
|
18761
|
+
const contextIds = contexts.map((c) => c.id);
|
|
18762
|
+
const editor = parseKbEditorConfig(agent?.tools);
|
|
18763
|
+
const sandbox = sharedSessionSandbox;
|
|
18764
|
+
currentTools.push(
|
|
18765
|
+
createRunSkillActionTool({
|
|
18766
|
+
handle: sandbox,
|
|
18767
|
+
loaded: loadedActions,
|
|
18768
|
+
contexts,
|
|
18769
|
+
connectedContextIds: deriveConnectedContextIds({
|
|
18770
|
+
contextIds,
|
|
18771
|
+
memoryContextId: agent?.memory,
|
|
18772
|
+
editorContextIds: editor.enabled ? Object.keys(editor.knowledgeBases).filter((id) => contextIds.includes(id)) : [],
|
|
18773
|
+
disabledToolIds: disabled,
|
|
18774
|
+
agenticSearch: agenticSearchActive ? { config: configs?.find((c) => c.id === "agentic_context_search") } : void 0,
|
|
18775
|
+
projectSearchContextIds
|
|
18776
|
+
}),
|
|
18777
|
+
// Same head/tail rules as the bash wrapper below; the tool hands each stream
|
|
18778
|
+
// its share of the guard's cap so the whole result (links included) fits.
|
|
18779
|
+
truncate: (text, kind, charLimit) => kind === "stdout" ? truncateToolOutput(text, budget.contextWindow, RUN_SKILL_ACTION_TOOL_ID, 0.1, charLimit) : truncateToolOutput(text, budget.contextWindow, `${RUN_SKILL_ACTION_TOOL_ID} stderr`, 0.4, charLimit),
|
|
18780
|
+
resultCharLimit: toolOutputCharLimit
|
|
18781
|
+
})
|
|
18782
|
+
);
|
|
18783
|
+
}
|
|
18784
|
+
}
|
|
18029
18785
|
const sanitizedTools = currentTools ? currentTools.map((tool3) => ({
|
|
18030
18786
|
...tool3,
|
|
18031
18787
|
name: sanitizeToolName(tool3.name)
|
|
@@ -18485,7 +19241,10 @@ export {
|
|
|
18485
19241
|
createCreateProjectPickerTool,
|
|
18486
19242
|
canRegisterSaveToProject,
|
|
18487
19243
|
resolveSkillByName,
|
|
19244
|
+
canWritePublicSkill,
|
|
18488
19245
|
canAccessSkill,
|
|
19246
|
+
ensureSkillWrite,
|
|
19247
|
+
ensureSkillRead,
|
|
18489
19248
|
filterReadableSkills,
|
|
18490
19249
|
parseFrontmatter,
|
|
18491
19250
|
parseSkillFrontmatter,
|