plugin-agent-orchestrator 1.0.6 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -291
- package/dist/client/AIEmployeesContext.d.ts +7 -0
- package/dist/client/OrchestratorSettings.d.ts +2 -1
- package/dist/client/index.js +1 -1
- package/dist/client/plugin.d.ts +1 -0
- package/dist/client/skill-hub/components/ExecutionHistory.d.ts +2 -0
- package/dist/client/skill-hub/components/ExecutionProgress.d.ts +20 -0
- package/dist/client/skill-hub/components/GitSkillImport.d.ts +7 -0
- package/dist/client/skill-hub/components/SkillEditor.d.ts +7 -0
- package/dist/client/skill-hub/components/SkillManager.d.ts +2 -0
- package/dist/client/skill-hub/components/SkillMetrics.d.ts +2 -0
- package/dist/client/skill-hub/components/SkillTestPanel.d.ts +7 -0
- package/dist/client/skill-hub/index.d.ts +10 -0
- package/dist/client/skill-hub/locale.d.ts +3 -0
- package/dist/client/skill-hub/tools/InteractionSchemasProvider.d.ts +19 -0
- package/dist/client/skill-hub/tools/SkillHubCard.d.ts +3 -0
- package/dist/client/skill-hub/utils/jsonFields.d.ts +3 -0
- package/dist/externalVersion.js +6 -6
- package/dist/node_modules/adm-zip/LICENSE +21 -0
- package/dist/node_modules/adm-zip/adm-zip.js +1 -0
- package/dist/node_modules/adm-zip/headers/entryHeader.js +377 -0
- package/dist/node_modules/adm-zip/headers/index.js +2 -0
- package/dist/node_modules/adm-zip/headers/mainHeader.js +130 -0
- package/dist/node_modules/adm-zip/methods/deflater.js +33 -0
- package/dist/node_modules/adm-zip/methods/index.js +3 -0
- package/dist/node_modules/adm-zip/methods/inflater.js +34 -0
- package/dist/node_modules/adm-zip/methods/zipcrypto.js +175 -0
- package/dist/node_modules/adm-zip/package.json +1 -0
- package/dist/node_modules/adm-zip/util/constants.js +142 -0
- package/dist/node_modules/adm-zip/util/decoder.js +5 -0
- package/dist/node_modules/adm-zip/util/errors.js +63 -0
- package/dist/node_modules/adm-zip/util/fattr.js +76 -0
- package/dist/node_modules/adm-zip/util/index.js +5 -0
- package/dist/node_modules/adm-zip/util/utils.js +339 -0
- package/dist/node_modules/adm-zip/zipEntry.js +405 -0
- package/dist/node_modules/adm-zip/zipFile.js +446 -0
- package/dist/node_modules/simple-git/dist/cjs/index.js +7399 -0
- package/dist/node_modules/simple-git/dist/esm/index.js +4745 -0
- package/dist/node_modules/simple-git/dist/esm/package.json +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/api.d.ts +13 -0
- package/dist/node_modules/simple-git/dist/src/lib/args/log-format.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-construct-error.d.ts +15 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-error.d.ts +30 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-plugin-error.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-response-error.d.ts +32 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/task-configuration-error.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/git-factory.d.ts +15 -0
- package/dist/node_modules/simple-git/dist/src/lib/git-logger.d.ts +21 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-branch-delete.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-branch.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-commit.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-diff-summary.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-fetch.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-list-log-summary.d.ts +6 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-merge.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-move.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-pull.d.ts +6 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-push.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-remote-messages.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-remote-objects.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/abort-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/block-unsafe-operations-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/command-config-prefixing-plugin.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/completion-detection.plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/custom-binary.plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/error-detection.plugin.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/index.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/plugin-store.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/progress-monitor-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/simple-git-plugin.d.ts +48 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/spawn-options-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/suffix-paths.plugin.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/timout-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/BranchDeleteSummary.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/BranchSummary.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/CheckIgnore.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/CleanSummary.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/ConfigList.d.ts +13 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/DiffSummary.d.ts +10 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/FileStatusSummary.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/GetRemoteSummary.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/InitSummary.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/MergeSummary.d.ts +16 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/PullSummary.d.ts +25 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/StatusSummary.d.ts +19 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/TagList.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/git-executor-chain.d.ts +25 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/git-executor.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/promise-wrapped.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/scheduler.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/tasks-pending-queue.d.ts +23 -0
- package/dist/node_modules/simple-git/dist/src/lib/simple-git-api.d.ts +20 -0
- package/dist/node_modules/simple-git/dist/src/lib/task-callback.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/apply-patch.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/branch.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/change-working-directory.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/check-ignore.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/check-is-repo.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/checkout.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/clean.d.ts +25 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/clone.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/commit.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/config.d.ts +8 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/count-objects.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff-name-status.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/fetch.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/first-commit.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/grep.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/hash-object.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/init.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/log.d.ts +32 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/merge.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/move.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/pull.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/push.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/remote.d.ts +8 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/reset.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/show.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/stash-list.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/status.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/sub-module.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/tag.d.ts +18 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/task.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/version.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/types/handlers.d.ts +21 -0
- package/dist/node_modules/simple-git/dist/src/lib/types/index.d.ts +136 -0
- package/dist/node_modules/simple-git/dist/src/lib/types/tasks.d.ts +19 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/argument-filters.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/exit-codes.d.ts +10 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/git-output-streams.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/index.d.ts +8 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/line-parser.d.ts +15 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/simple-git-options.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/task-options.d.ts +13 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/task-parser.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/util.d.ts +47 -0
- package/dist/node_modules/simple-git/dist/typings/errors.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/typings/index.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/typings/response.d.ts +556 -0
- package/dist/node_modules/simple-git/dist/typings/simple-git.d.ts +1033 -0
- package/dist/node_modules/simple-git/dist/typings/types.d.ts +22 -0
- package/dist/node_modules/simple-git/node_modules/debug/package.json +64 -0
- package/dist/node_modules/simple-git/node_modules/debug/src/browser.js +272 -0
- package/dist/node_modules/simple-git/node_modules/debug/src/common.js +292 -0
- package/dist/node_modules/simple-git/node_modules/debug/src/index.js +10 -0
- package/dist/node_modules/simple-git/node_modules/debug/src/node.js +263 -0
- package/dist/node_modules/simple-git/package.json +1 -0
- package/dist/node_modules/simple-git/promise.js +17 -0
- package/dist/server/collections/agent-execution-spans.d.ts +9 -0
- package/dist/server/collections/agent-execution-spans.js +152 -0
- package/dist/server/collections/orchestrator-config.js +16 -0
- package/dist/server/collections/orchestrator-logs.js +19 -2
- package/dist/server/collections/skill-definitions.d.ts +3 -0
- package/dist/server/collections/skill-definitions.js +158 -0
- package/dist/server/collections/skill-executions.d.ts +3 -0
- package/dist/server/collections/skill-executions.js +123 -0
- package/dist/server/collections/skill-worker-configs.d.ts +3 -0
- package/dist/server/collections/skill-worker-configs.js +115 -0
- package/dist/server/migrations/20260423000000-add-progress-fields.d.ts +4 -0
- package/dist/server/migrations/20260423000000-add-progress-fields.js +69 -0
- package/dist/server/migrations/20260425000000-add-interaction-schema.d.ts +4 -0
- package/dist/server/migrations/20260425000000-add-interaction-schema.js +61 -0
- package/dist/server/migrations/20260427000000-add-tracing-detail-fields.d.ts +7 -0
- package/dist/server/migrations/20260427000000-add-tracing-detail-fields.js +62 -0
- package/dist/server/migrations/20260427000000-change-packages-to-text.d.ts +4 -0
- package/dist/server/migrations/20260427000000-change-packages-to-text.js +70 -0
- package/dist/server/migrations/20260427000001-change-other-json-to-text.d.ts +4 -0
- package/dist/server/migrations/20260427000001-change-other-json-to-text.js +80 -0
- package/dist/server/migrations/20260429000000-add-llm-fields.d.ts +7 -0
- package/dist/server/migrations/20260429000000-add-llm-fields.js +68 -0
- package/dist/server/migrations/20260429000000-fix-inputargs-json-to-text.d.ts +16 -0
- package/dist/server/migrations/20260429000000-fix-inputargs-json-to-text.js +51 -0
- package/dist/server/migrations/20260503000000-add-orchestrator-trace-fields.d.ts +7 -0
- package/dist/server/migrations/20260503000000-add-orchestrator-trace-fields.js +57 -0
- package/dist/server/plugin.d.ts +3 -0
- package/dist/server/plugin.js +37 -1
- package/dist/server/resources/tracing.js +160 -12
- package/dist/server/services/CodeValidator.d.ts +32 -0
- package/dist/server/services/CodeValidator.js +205 -0
- package/dist/server/services/ExecutionSpanService.d.ts +44 -0
- package/dist/server/services/ExecutionSpanService.js +104 -0
- package/dist/server/services/FileManager.d.ts +28 -0
- package/dist/server/services/FileManager.js +151 -0
- package/dist/server/services/SandboxRunner.d.ts +41 -0
- package/dist/server/services/SandboxRunner.js +167 -0
- package/dist/server/services/SkillManager.d.ts +6 -0
- package/dist/server/services/SkillManager.js +640 -0
- package/dist/server/services/SkillRepositoryService.d.ts +22 -0
- package/dist/server/services/SkillRepositoryService.js +157 -0
- package/dist/server/services/WorkerEnvManager.d.ts +26 -0
- package/dist/server/services/WorkerEnvManager.js +120 -0
- package/dist/server/skill-hub/actions/git-import.d.ts +21 -0
- package/dist/server/skill-hub/actions/git-import.js +413 -0
- package/dist/server/skill-hub/mcp/McpController.d.ts +15 -0
- package/dist/server/skill-hub/mcp/McpController.js +111 -0
- package/dist/server/skill-hub/plugin.d.ts +58 -0
- package/dist/server/skill-hub/plugin.js +694 -0
- package/dist/server/skill-hub/sandbox-config.json +6 -0
- package/dist/server/skill-hub/tasks/SkillExecutionTask.d.ts +14 -0
- package/dist/server/skill-hub/tasks/SkillExecutionTask.js +267 -0
- package/dist/server/skill-hub/utils/json-fields.d.ts +7 -0
- package/dist/server/skill-hub/utils/json-fields.js +88 -0
- package/dist/server/tools/delegate-task.d.ts +4 -0
- package/dist/server/tools/delegate-task.js +832 -119
- package/dist/server/tools/skill-execute.d.ts +36 -0
- package/dist/server/tools/skill-execute.js +167 -0
- package/package.json +3 -1
- package/src/client/AIEmployeeSelect.tsx +1 -3
- package/src/client/AIEmployeesContext.tsx +28 -13
- package/src/client/OrchestratorSettings.tsx +43 -5
- package/src/client/RulesTab.tsx +368 -21
- package/src/client/TracingTab.tsx +316 -102
- package/src/client/plugin.tsx +39 -0
- package/src/client/skill-hub/components/ExecutionHistory.tsx +201 -0
- package/src/client/skill-hub/components/ExecutionProgress.tsx +55 -0
- package/src/client/skill-hub/components/GitSkillImport.tsx +555 -0
- package/src/client/skill-hub/components/SkillEditor.tsx +456 -0
- package/src/client/skill-hub/components/SkillManager.tsx +181 -0
- package/src/client/skill-hub/components/SkillMetrics.tsx +124 -0
- package/src/client/skill-hub/components/SkillTestPanel.tsx +144 -0
- package/src/client/skill-hub/index.tsx +75 -0
- package/src/client/skill-hub/locale.ts +16 -0
- package/src/client/skill-hub/tools/InteractionSchemasProvider.tsx +59 -0
- package/src/client/skill-hub/tools/SkillHubCard.tsx +78 -0
- package/src/client/skill-hub/utils/jsonFields.ts +37 -0
- package/src/server/collections/agent-execution-spans.ts +129 -0
- package/src/server/collections/orchestrator-config.ts +17 -0
- package/src/server/collections/orchestrator-logs.ts +19 -2
- package/src/server/collections/skill-definitions.ts +128 -0
- package/src/server/collections/skill-executions.ts +94 -0
- package/src/server/collections/skill-worker-configs.ts +86 -0
- package/src/server/migrations/20260423000000-add-progress-fields.ts +50 -0
- package/src/server/migrations/20260425000000-add-interaction-schema.ts +35 -0
- package/src/server/migrations/20260427000000-add-tracing-detail-fields.ts +41 -0
- package/src/server/migrations/20260427000000-change-packages-to-text.ts +47 -0
- package/src/server/migrations/20260427000001-change-other-json-to-text.ts +57 -0
- package/src/server/migrations/20260429000000-add-llm-fields.ts +46 -0
- package/src/server/migrations/20260429000000-fix-inputargs-json-to-text.ts +38 -0
- package/src/server/migrations/20260503000000-add-orchestrator-trace-fields.ts +32 -0
- package/src/server/plugin.ts +51 -3
- package/src/server/resources/tracing.ts +187 -16
- package/src/server/services/CodeValidator.ts +159 -0
- package/src/server/services/ExecutionSpanService.ts +106 -0
- package/src/server/services/FileManager.ts +144 -0
- package/src/server/services/SandboxRunner.ts +205 -0
- package/src/server/services/SkillManager.ts +623 -0
- package/src/server/services/SkillRepositoryService.ts +142 -0
- package/src/server/services/WorkerEnvManager.ts +113 -0
- package/src/server/skill-hub/actions/git-import.ts +486 -0
- package/src/server/skill-hub/mcp/McpController.ts +86 -0
- package/src/server/skill-hub/plugin.ts +771 -0
- package/src/server/skill-hub/sandbox-config.json +6 -0
- package/src/server/skill-hub/tasks/SkillExecutionTask.ts +297 -0
- package/src/server/skill-hub/utils/json-fields.ts +57 -0
- package/src/server/tools/delegate-task.ts +1085 -147
- package/src/server/tools/skill-execute.ts +157 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { mkdirSync, readdirSync, statSync, existsSync, rmSync } from 'fs';
|
|
2
|
+
import { resolve, join } from 'path';
|
|
3
|
+
|
|
4
|
+
export interface OutputFileInfo {
|
|
5
|
+
name: string;
|
|
6
|
+
size: number;
|
|
7
|
+
mimeType: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const MIME_MAP: Record<string, string> = {
|
|
11
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
12
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
13
|
+
'.pdf': 'application/pdf',
|
|
14
|
+
'.csv': 'text/csv',
|
|
15
|
+
'.json': 'application/json',
|
|
16
|
+
'.txt': 'text/plain',
|
|
17
|
+
'.png': 'image/png',
|
|
18
|
+
'.jpg': 'image/jpeg',
|
|
19
|
+
'.jpeg': 'image/jpeg',
|
|
20
|
+
'.svg': 'image/svg+xml',
|
|
21
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
22
|
+
'.zip': 'application/zip',
|
|
23
|
+
'.html': 'text/html',
|
|
24
|
+
'.xml': 'application/xml',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function getMimeType(filename: string): string {
|
|
28
|
+
const ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
|
|
29
|
+
return MIME_MAP[ext] || 'application/octet-stream';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class FileManager {
|
|
33
|
+
private executionsDir: string;
|
|
34
|
+
|
|
35
|
+
constructor(private storagePath: string) {
|
|
36
|
+
this.executionsDir = resolve(storagePath, 'executions');
|
|
37
|
+
mkdirSync(this.executionsDir, { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
createExecDir(execId: string): string {
|
|
41
|
+
const dir = resolve(this.executionsDir, execId);
|
|
42
|
+
mkdirSync(dir, { recursive: true });
|
|
43
|
+
mkdirSync(resolve(dir, 'output'), { recursive: true });
|
|
44
|
+
return dir;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getExecDir(execId: string): string {
|
|
48
|
+
return resolve(this.executionsDir, execId);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getOutputDir(execId: string): string {
|
|
52
|
+
return resolve(this.executionsDir, execId, 'output');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns absolute path to an output file, or null if invalid/not found.
|
|
57
|
+
* Includes path traversal protection.
|
|
58
|
+
*/
|
|
59
|
+
getOutputFilePath(execId: string, filename: string): string | null {
|
|
60
|
+
const safeBase = resolve(this.executionsDir, execId, 'output');
|
|
61
|
+
const filePath = resolve(safeBase, filename);
|
|
62
|
+
|
|
63
|
+
// Path traversal protection
|
|
64
|
+
if (!filePath.startsWith(safeBase)) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (!existsSync(filePath)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return filePath;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
listOutputFiles(execId: string): OutputFileInfo[] {
|
|
74
|
+
const outputDir = this.getOutputDir(execId);
|
|
75
|
+
if (!existsSync(outputDir)) return [];
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
return readdirSync(outputDir)
|
|
79
|
+
.filter((name) => {
|
|
80
|
+
const filePath = join(outputDir, name);
|
|
81
|
+
return statSync(filePath).isFile();
|
|
82
|
+
})
|
|
83
|
+
.map((name) => {
|
|
84
|
+
const filePath = join(outputDir, name);
|
|
85
|
+
const stat = statSync(filePath);
|
|
86
|
+
return {
|
|
87
|
+
name,
|
|
88
|
+
size: stat.size,
|
|
89
|
+
mimeType: getMimeType(name),
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
} catch {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getTotalOutputSize(execId: string): number {
|
|
98
|
+
const files = this.listOutputFiles(execId);
|
|
99
|
+
return files.reduce((sum, f) => sum + f.size, 0);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Remove a specific execution directory by execId.
|
|
104
|
+
*/
|
|
105
|
+
removeExecDir(execId: string): void {
|
|
106
|
+
const dirPath = resolve(this.executionsDir, execId);
|
|
107
|
+
if (existsSync(dirPath)) {
|
|
108
|
+
try {
|
|
109
|
+
rmSync(dirPath, { recursive: true, force: true });
|
|
110
|
+
} catch {
|
|
111
|
+
// Skip errors
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Remove execution directories older than maxAgeMs.
|
|
118
|
+
*/
|
|
119
|
+
cleanupOlderThan(maxAgeMs: number): number {
|
|
120
|
+
if (!existsSync(this.executionsDir)) return 0;
|
|
121
|
+
|
|
122
|
+
let cleaned = 0;
|
|
123
|
+
const now = Date.now();
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
for (const dir of readdirSync(this.executionsDir)) {
|
|
127
|
+
const dirPath = resolve(this.executionsDir, dir);
|
|
128
|
+
try {
|
|
129
|
+
const stat = statSync(dirPath);
|
|
130
|
+
if (stat.isDirectory() && now - stat.mtimeMs > maxAgeMs) {
|
|
131
|
+
rmSync(dirPath, { recursive: true, force: true });
|
|
132
|
+
cleaned++;
|
|
133
|
+
}
|
|
134
|
+
} catch {
|
|
135
|
+
// Skip individual dir errors
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} catch {
|
|
139
|
+
// Skip if executionsDir not accessible
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return cleaned;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { exec, ChildProcess, ExecException } from 'child_process';
|
|
2
|
+
import { writeFileSync } from 'fs';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { FileManager, OutputFileInfo } from './FileManager';
|
|
5
|
+
import { CodeValidator } from './CodeValidator';
|
|
6
|
+
|
|
7
|
+
export interface ExecuteOptions {
|
|
8
|
+
language: 'node' | 'python';
|
|
9
|
+
code: string;
|
|
10
|
+
execId: string;
|
|
11
|
+
timeoutSeconds?: number;
|
|
12
|
+
maxOutputSizeMb?: number;
|
|
13
|
+
onProgress?: (progress: ProgressUpdate) => void;
|
|
14
|
+
/** AbortSignal — when aborted, the child process is killed */
|
|
15
|
+
signal?: { addEventListener(event: string, listener: () => void): void };
|
|
16
|
+
/** Package whitelist for import validation (from skillWorkerConfigs) */
|
|
17
|
+
packageWhitelist?: string[];
|
|
18
|
+
/** Optional installed/copied skill package root exposed to the runtime as SKILL_DIR. */
|
|
19
|
+
skillDir?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ProgressUpdate {
|
|
23
|
+
percent: number;
|
|
24
|
+
log: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ExecutionResult {
|
|
28
|
+
success: boolean;
|
|
29
|
+
stdout: string;
|
|
30
|
+
stderr: string;
|
|
31
|
+
files: OutputFileInfo[];
|
|
32
|
+
durationMs: number;
|
|
33
|
+
/** true if execution was canceled by user */
|
|
34
|
+
canceled?: boolean;
|
|
35
|
+
/** true if execution timed out */
|
|
36
|
+
timedOut?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class SandboxRunner {
|
|
40
|
+
private validator = new CodeValidator();
|
|
41
|
+
|
|
42
|
+
private sandboxWorkspace: string;
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
private fileManager: FileManager,
|
|
46
|
+
private logger: any,
|
|
47
|
+
private storagePath: string,
|
|
48
|
+
) {
|
|
49
|
+
this.sandboxWorkspace = resolve(storagePath, 'sandbox-workspace');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async execute(options: ExecuteOptions): Promise<ExecutionResult> {
|
|
53
|
+
const {
|
|
54
|
+
language,
|
|
55
|
+
code,
|
|
56
|
+
execId,
|
|
57
|
+
timeoutSeconds = 60,
|
|
58
|
+
maxOutputSizeMb = 50,
|
|
59
|
+
onProgress,
|
|
60
|
+
signal,
|
|
61
|
+
packageWhitelist,
|
|
62
|
+
skillDir,
|
|
63
|
+
} = options;
|
|
64
|
+
|
|
65
|
+
// 1. Validate code against forbidden patterns
|
|
66
|
+
this.validator.validate(code, language);
|
|
67
|
+
|
|
68
|
+
// 1b. Validate imports against whitelist (if env initialized)
|
|
69
|
+
if (packageWhitelist?.length) {
|
|
70
|
+
this.validator.validateImports(code, language, packageWhitelist);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 2. Prepare workspace
|
|
74
|
+
const workDir = this.fileManager.createExecDir(execId);
|
|
75
|
+
const outputDir = this.fileManager.getOutputDir(execId);
|
|
76
|
+
|
|
77
|
+
const filename = language === 'node' ? 'script.js' : 'script.py';
|
|
78
|
+
const scriptPath = resolve(workDir, filename);
|
|
79
|
+
writeFileSync(scriptPath, code, 'utf-8');
|
|
80
|
+
|
|
81
|
+
onProgress?.({ percent: 20, log: 'Code validated, executing...' });
|
|
82
|
+
|
|
83
|
+
// 3. Build command
|
|
84
|
+
const cmd = language === 'node'
|
|
85
|
+
? `node "${scriptPath}"`
|
|
86
|
+
: `python3 "${scriptPath}"`;
|
|
87
|
+
|
|
88
|
+
// 4. Resolve Node Modules Path using the local sandbox workspace
|
|
89
|
+
const path = require('path');
|
|
90
|
+
const nodePath = path.resolve(this.sandboxWorkspace, 'node_modules');
|
|
91
|
+
const finalNodePath = process.env.NODE_PATH
|
|
92
|
+
? `${nodePath}${path.delimiter}${process.env.NODE_PATH}`
|
|
93
|
+
: nodePath;
|
|
94
|
+
|
|
95
|
+
// 5. Execute via child_process with sanitized env
|
|
96
|
+
const startTime = Date.now();
|
|
97
|
+
let childProc: ChildProcess | null = null;
|
|
98
|
+
let wasCanceled = false;
|
|
99
|
+
|
|
100
|
+
const processResult = await new Promise<{
|
|
101
|
+
exitCode: number;
|
|
102
|
+
stdout: string;
|
|
103
|
+
stderr: string;
|
|
104
|
+
}>((resolveResult) => {
|
|
105
|
+
childProc = exec(
|
|
106
|
+
cmd,
|
|
107
|
+
{
|
|
108
|
+
timeout: timeoutSeconds * 1000,
|
|
109
|
+
maxBuffer: 10 * 1024 * 1024, // 10MB stdout/stderr buffer
|
|
110
|
+
cwd: workDir,
|
|
111
|
+
env: {
|
|
112
|
+
// Sanitized environment — only expose what's necessary
|
|
113
|
+
PATH: process.env.PATH,
|
|
114
|
+
HOME: '/tmp',
|
|
115
|
+
TMPDIR: '/tmp',
|
|
116
|
+
OUTPUT_DIR: outputDir,
|
|
117
|
+
LANG: 'en_US.UTF-8',
|
|
118
|
+
// Node.js
|
|
119
|
+
NODE_PATH: finalNodePath,
|
|
120
|
+
// Python — include bundled packages (svg_to_pptx etc.)
|
|
121
|
+
PYTHONPATH: [
|
|
122
|
+
skillDir ? path.resolve(skillDir, 'scripts') : '',
|
|
123
|
+
path.resolve(this.sandboxWorkspace, 'python_packages'),
|
|
124
|
+
process.env.PYTHONPATH || '',
|
|
125
|
+
].filter(Boolean).join(path.delimiter),
|
|
126
|
+
PYTHONIOENCODING: 'utf-8',
|
|
127
|
+
SKILL_DIR: skillDir || '',
|
|
128
|
+
// DO NOT pass: DB credentials, API keys, APP_KEY, etc.
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
(error: ExecException | null, stdout: string, stderr: string) => {
|
|
132
|
+
let exitCode = 0;
|
|
133
|
+
if (error) {
|
|
134
|
+
if (error.killed) {
|
|
135
|
+
exitCode = -1; // Killed by timeout or abort
|
|
136
|
+
} else {
|
|
137
|
+
exitCode = error.code || 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
resolveResult({
|
|
142
|
+
exitCode,
|
|
143
|
+
stdout: (stdout || '').slice(0, 5000),
|
|
144
|
+
stderr: (stderr || '').slice(0, 2000),
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// 5. Wire abort signal → kill child process
|
|
150
|
+
if (signal) {
|
|
151
|
+
signal.addEventListener('abort', () => {
|
|
152
|
+
wasCanceled = true;
|
|
153
|
+
if (childProc && !childProc.killed) {
|
|
154
|
+
this.logger.info(`[skill-hub] Killing child process for exec ${execId} (user abort)`);
|
|
155
|
+
childProc.kill('SIGTERM');
|
|
156
|
+
// Force kill after 3 seconds if SIGTERM didn't work
|
|
157
|
+
setTimeout(() => {
|
|
158
|
+
if (childProc && !childProc.killed) {
|
|
159
|
+
childProc.kill('SIGKILL');
|
|
160
|
+
}
|
|
161
|
+
}, 3000);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const durationMs = Date.now() - startTime;
|
|
168
|
+
|
|
169
|
+
onProgress?.({ percent: 80, log: wasCanceled ? 'Canceled' : 'Execution completed, collecting files...' });
|
|
170
|
+
|
|
171
|
+
// 6. Collect output files
|
|
172
|
+
const files = this.fileManager.listOutputFiles(execId);
|
|
173
|
+
|
|
174
|
+
// 7. Check output size limit
|
|
175
|
+
const totalSizeBytes = this.fileManager.getTotalOutputSize(execId);
|
|
176
|
+
const maxBytes = maxOutputSizeMb * 1024 * 1024;
|
|
177
|
+
if (totalSizeBytes > maxBytes) {
|
|
178
|
+
this.logger.warn(
|
|
179
|
+
`[skill-hub] Execution ${execId}: output size ${totalSizeBytes} bytes exceeds limit ${maxBytes}`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
onProgress?.({ percent: 100, log: 'Done' });
|
|
184
|
+
|
|
185
|
+
// Detect timeout
|
|
186
|
+
const timedOut = !wasCanceled && processResult.exitCode === -1;
|
|
187
|
+
if (timedOut) {
|
|
188
|
+
processResult.stderr = `Execution timed out after ${timeoutSeconds}s\n${processResult.stderr}`;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (wasCanceled) {
|
|
192
|
+
processResult.stderr = `Execution canceled by user\n${processResult.stderr}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
success: !wasCanceled && !timedOut && processResult.exitCode === 0,
|
|
197
|
+
stdout: processResult.stdout,
|
|
198
|
+
stderr: processResult.stderr,
|
|
199
|
+
files,
|
|
200
|
+
durationMs,
|
|
201
|
+
canceled: wasCanceled,
|
|
202
|
+
timedOut,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|