plugin-agent-orchestrator 1.0.13 → 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 +6 -0
- 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-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.js +8 -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 +154 -11
- 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 +606 -104
- 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 +253 -32
- package/src/client/TracingTab.tsx +277 -213
- 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 +7 -0
- 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-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 +9 -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 +182 -15
- 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 +803 -127
- package/src/server/tools/skill-execute.ts +157 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
const fsystem = require("fs");
|
|
2
|
+
const pth = require("path");
|
|
3
|
+
const Constants = require("./constants");
|
|
4
|
+
const Errors = require("./errors");
|
|
5
|
+
const isWin = typeof process === "object" && "win32" === process.platform;
|
|
6
|
+
|
|
7
|
+
const is_Obj = (obj) => typeof obj === "object" && obj !== null;
|
|
8
|
+
|
|
9
|
+
// generate CRC32 lookup table
|
|
10
|
+
const crcTable = new Uint32Array(256).map((t, c) => {
|
|
11
|
+
for (let k = 0; k < 8; k++) {
|
|
12
|
+
if ((c & 1) !== 0) {
|
|
13
|
+
c = 0xedb88320 ^ (c >>> 1);
|
|
14
|
+
} else {
|
|
15
|
+
c >>>= 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return c >>> 0;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// UTILS functions
|
|
22
|
+
|
|
23
|
+
function Utils(opts) {
|
|
24
|
+
this.sep = pth.sep;
|
|
25
|
+
this.fs = fsystem;
|
|
26
|
+
|
|
27
|
+
if (is_Obj(opts)) {
|
|
28
|
+
// custom filesystem
|
|
29
|
+
if (is_Obj(opts.fs) && typeof opts.fs.statSync === "function") {
|
|
30
|
+
this.fs = opts.fs;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = Utils;
|
|
36
|
+
|
|
37
|
+
// INSTANTIABLE functions
|
|
38
|
+
|
|
39
|
+
Utils.prototype.makeDir = function (/*String*/ folder) {
|
|
40
|
+
const self = this;
|
|
41
|
+
|
|
42
|
+
// Sync - make directories tree
|
|
43
|
+
function mkdirSync(/*String*/ fpath) {
|
|
44
|
+
let resolvedPath = fpath.split(self.sep)[0];
|
|
45
|
+
fpath.split(self.sep).forEach(function (name) {
|
|
46
|
+
if (!name || name.substr(-1, 1) === ":") return;
|
|
47
|
+
resolvedPath += self.sep + name;
|
|
48
|
+
var stat;
|
|
49
|
+
try {
|
|
50
|
+
stat = self.fs.statSync(resolvedPath);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
if (e.message && e.message.startsWith('ENOENT')) {
|
|
53
|
+
self.fs.mkdirSync(resolvedPath);
|
|
54
|
+
} else {
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (stat && stat.isFile()) throw Errors.FILE_IN_THE_WAY(`"${resolvedPath}"`);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
mkdirSync(folder);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
Utils.prototype.writeFileTo = function (/*String*/ path, /*Buffer*/ content, /*Boolean*/ overwrite, /*Number*/ attr) {
|
|
66
|
+
const self = this;
|
|
67
|
+
if (self.fs.existsSync(path)) {
|
|
68
|
+
if (!overwrite) return false; // cannot overwrite
|
|
69
|
+
|
|
70
|
+
var stat = self.fs.statSync(path);
|
|
71
|
+
if (stat.isDirectory()) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
var folder = pth.dirname(path);
|
|
76
|
+
if (!self.fs.existsSync(folder)) {
|
|
77
|
+
self.makeDir(folder);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var fd;
|
|
81
|
+
try {
|
|
82
|
+
fd = self.fs.openSync(path, "w", 0o666); // 0666
|
|
83
|
+
} catch (e) {
|
|
84
|
+
self.fs.chmodSync(path, 0o666);
|
|
85
|
+
fd = self.fs.openSync(path, "w", 0o666);
|
|
86
|
+
}
|
|
87
|
+
if (fd) {
|
|
88
|
+
try {
|
|
89
|
+
self.fs.writeSync(fd, content, 0, content.length, 0);
|
|
90
|
+
} finally {
|
|
91
|
+
self.fs.closeSync(fd);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
self.fs.chmodSync(path, attr || 0o666);
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
Utils.prototype.writeFileToAsync = function (/*String*/ path, /*Buffer*/ content, /*Boolean*/ overwrite, /*Number*/ attr, /*Function*/ callback) {
|
|
99
|
+
if (typeof attr === "function") {
|
|
100
|
+
callback = attr;
|
|
101
|
+
attr = undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const self = this;
|
|
105
|
+
|
|
106
|
+
self.fs.exists(path, function (exist) {
|
|
107
|
+
if (exist && !overwrite) return callback(false);
|
|
108
|
+
|
|
109
|
+
self.fs.stat(path, function (err, stat) {
|
|
110
|
+
if (exist && stat.isDirectory()) {
|
|
111
|
+
return callback(false);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
var folder = pth.dirname(path);
|
|
115
|
+
self.fs.exists(folder, function (exists) {
|
|
116
|
+
if (!exists) self.makeDir(folder);
|
|
117
|
+
|
|
118
|
+
self.fs.open(path, "w", 0o666, function (err, fd) {
|
|
119
|
+
if (err) {
|
|
120
|
+
self.fs.chmod(path, 0o666, function () {
|
|
121
|
+
self.fs.open(path, "w", 0o666, function (err, fd) {
|
|
122
|
+
self.fs.write(fd, content, 0, content.length, 0, function () {
|
|
123
|
+
self.fs.close(fd, function () {
|
|
124
|
+
self.fs.chmod(path, attr || 0o666, function () {
|
|
125
|
+
callback(true);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
} else if (fd) {
|
|
132
|
+
self.fs.write(fd, content, 0, content.length, 0, function () {
|
|
133
|
+
self.fs.close(fd, function () {
|
|
134
|
+
self.fs.chmod(path, attr || 0o666, function () {
|
|
135
|
+
callback(true);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
self.fs.chmod(path, attr || 0o666, function () {
|
|
141
|
+
callback(true);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
Utils.prototype.findFiles = function (/*String*/ path) {
|
|
151
|
+
const self = this;
|
|
152
|
+
|
|
153
|
+
function findSync(/*String*/ dir, /*RegExp*/ pattern, /*Boolean*/ recursive) {
|
|
154
|
+
if (typeof pattern === "boolean") {
|
|
155
|
+
recursive = pattern;
|
|
156
|
+
pattern = undefined;
|
|
157
|
+
}
|
|
158
|
+
let files = [];
|
|
159
|
+
self.fs.readdirSync(dir).forEach(function (file) {
|
|
160
|
+
const path = pth.join(dir, file);
|
|
161
|
+
const stat = self.fs.statSync(path);
|
|
162
|
+
|
|
163
|
+
if (!pattern || pattern.test(path)) {
|
|
164
|
+
files.push(pth.normalize(path) + (stat.isDirectory() ? self.sep : ""));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (stat.isDirectory() && recursive) files = files.concat(findSync(path, pattern, recursive));
|
|
168
|
+
});
|
|
169
|
+
return files;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return findSync(path, undefined, true);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Callback for showing if everything was done.
|
|
177
|
+
*
|
|
178
|
+
* @callback filelistCallback
|
|
179
|
+
* @param {Error} err - Error object
|
|
180
|
+
* @param {string[]} list - was request fully completed
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
*
|
|
185
|
+
* @param {string} dir
|
|
186
|
+
* @param {filelistCallback} cb
|
|
187
|
+
*/
|
|
188
|
+
Utils.prototype.findFilesAsync = function (dir, cb) {
|
|
189
|
+
const self = this;
|
|
190
|
+
let results = [];
|
|
191
|
+
self.fs.readdir(dir, function (err, list) {
|
|
192
|
+
if (err) return cb(err);
|
|
193
|
+
let list_length = list.length;
|
|
194
|
+
if (!list_length) return cb(null, results);
|
|
195
|
+
list.forEach(function (file) {
|
|
196
|
+
file = pth.join(dir, file);
|
|
197
|
+
self.fs.stat(file, function (err, stat) {
|
|
198
|
+
if (err) return cb(err);
|
|
199
|
+
if (stat) {
|
|
200
|
+
results.push(pth.normalize(file) + (stat.isDirectory() ? self.sep : ""));
|
|
201
|
+
if (stat.isDirectory()) {
|
|
202
|
+
self.findFilesAsync(file, function (err, res) {
|
|
203
|
+
if (err) return cb(err);
|
|
204
|
+
results = results.concat(res);
|
|
205
|
+
if (!--list_length) cb(null, results);
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
if (!--list_length) cb(null, results);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
Utils.prototype.getAttributes = function () {};
|
|
217
|
+
|
|
218
|
+
Utils.prototype.setAttributes = function () {};
|
|
219
|
+
|
|
220
|
+
// STATIC functions
|
|
221
|
+
|
|
222
|
+
// crc32 single update (it is part of crc32)
|
|
223
|
+
Utils.crc32update = function (crc, byte) {
|
|
224
|
+
return crcTable[(crc ^ byte) & 0xff] ^ (crc >>> 8);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
Utils.crc32 = function (buf) {
|
|
228
|
+
if (typeof buf === "string") {
|
|
229
|
+
buf = Buffer.from(buf, "utf8");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
let len = buf.length;
|
|
233
|
+
let crc = ~0;
|
|
234
|
+
for (let off = 0; off < len; ) crc = Utils.crc32update(crc, buf[off++]);
|
|
235
|
+
// xor and cast as uint32 number
|
|
236
|
+
return ~crc >>> 0;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
Utils.methodToString = function (/*Number*/ method) {
|
|
240
|
+
switch (method) {
|
|
241
|
+
case Constants.STORED:
|
|
242
|
+
return "STORED (" + method + ")";
|
|
243
|
+
case Constants.DEFLATED:
|
|
244
|
+
return "DEFLATED (" + method + ")";
|
|
245
|
+
default:
|
|
246
|
+
return "UNSUPPORTED (" + method + ")";
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* removes ".." style path elements
|
|
252
|
+
* @param {string} path - fixable path
|
|
253
|
+
* @returns string - fixed filepath
|
|
254
|
+
*/
|
|
255
|
+
Utils.canonical = function (/*string*/ path) {
|
|
256
|
+
if (!path) return "";
|
|
257
|
+
// trick normalize think path is absolute
|
|
258
|
+
const safeSuffix = pth.posix.normalize("/" + path.split("\\").join("/"));
|
|
259
|
+
return pth.join(".", safeSuffix);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* fix file names in achive
|
|
264
|
+
* @param {string} path - fixable path
|
|
265
|
+
* @returns string - fixed filepath
|
|
266
|
+
*/
|
|
267
|
+
|
|
268
|
+
Utils.zipnamefix = function (path) {
|
|
269
|
+
if (!path) return "";
|
|
270
|
+
// trick normalize think path is absolute
|
|
271
|
+
const safeSuffix = pth.posix.normalize("/" + path.split("\\").join("/"));
|
|
272
|
+
return pth.posix.join(".", safeSuffix);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
*
|
|
277
|
+
* @param {Array} arr
|
|
278
|
+
* @param {function} callback
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
Utils.findLast = function (arr, callback) {
|
|
282
|
+
if (!Array.isArray(arr)) throw new TypeError("arr is not array");
|
|
283
|
+
|
|
284
|
+
const len = arr.length >>> 0;
|
|
285
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
286
|
+
if (callback(arr[i], i, arr)) {
|
|
287
|
+
return arr[i];
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return void 0;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// make abolute paths taking prefix as root folder
|
|
294
|
+
Utils.sanitize = function (/*string*/ prefix, /*string*/ name) {
|
|
295
|
+
prefix = pth.resolve(pth.normalize(prefix));
|
|
296
|
+
var parts = name.split("/");
|
|
297
|
+
for (var i = 0, l = parts.length; i < l; i++) {
|
|
298
|
+
var path = pth.normalize(pth.join(prefix, parts.slice(i, l).join(pth.sep)));
|
|
299
|
+
if (path.indexOf(prefix) === 0) {
|
|
300
|
+
return path;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return pth.normalize(pth.join(prefix, pth.basename(name)));
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// converts buffer, Uint8Array, string types to buffer
|
|
307
|
+
Utils.toBuffer = function toBuffer(/*buffer, Uint8Array, string*/ input, /* function */ encoder) {
|
|
308
|
+
if (Buffer.isBuffer(input)) {
|
|
309
|
+
return input;
|
|
310
|
+
} else if (input instanceof Uint8Array) {
|
|
311
|
+
return Buffer.from(input);
|
|
312
|
+
} else {
|
|
313
|
+
// expect string all other values are invalid and return empty buffer
|
|
314
|
+
return typeof input === "string" ? encoder(input) : Buffer.alloc(0);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
Utils.readBigUInt64LE = function (/*Buffer*/ buffer, /*int*/ index) {
|
|
319
|
+
const lo = buffer.readUInt32LE(index);
|
|
320
|
+
const hi = buffer.readUInt32LE(index + 4);
|
|
321
|
+
return hi * 0x100000000 + lo;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
Utils.fromDOS2Date = function (val) {
|
|
325
|
+
return new Date(((val >> 25) & 0x7f) + 1980, Math.max(((val >> 21) & 0x0f) - 1, 0), Math.max((val >> 16) & 0x1f, 1), (val >> 11) & 0x1f, (val >> 5) & 0x3f, (val & 0x1f) << 1);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
Utils.fromDate2DOS = function (val) {
|
|
329
|
+
let date = 0;
|
|
330
|
+
let time = 0;
|
|
331
|
+
if (val.getFullYear() > 1979) {
|
|
332
|
+
date = (((val.getFullYear() - 1980) & 0x7f) << 9) | ((val.getMonth() + 1) << 5) | val.getDate();
|
|
333
|
+
time = (val.getHours() << 11) | (val.getMinutes() << 5) | (val.getSeconds() >> 1);
|
|
334
|
+
}
|
|
335
|
+
return (date << 16) | time;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
Utils.isWin = isWin; // Do we have windows system
|
|
339
|
+
Utils.crcTable = crcTable;
|