@dexto/agent-management 1.16.6 → 1.17.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/plugins/install-plugin.cjs +2 -0
- package/dist/plugins/install-plugin.d.ts.map +1 -1
- package/dist/plugins/install-plugin.js +2 -0
- package/dist/plugins/local-skills.cjs +2 -0
- package/dist/plugins/local-skills.d.ts.map +1 -1
- package/dist/plugins/local-skills.js +2 -0
- package/dist/plugins/marketplace/error-codes.cjs +1 -0
- package/dist/plugins/marketplace/error-codes.d.ts +1 -0
- package/dist/plugins/marketplace/error-codes.d.ts.map +1 -1
- package/dist/plugins/marketplace/error-codes.js +1 -0
- package/dist/plugins/marketplace/errors.cjs +10 -0
- package/dist/plugins/marketplace/errors.d.ts +3 -0
- package/dist/plugins/marketplace/errors.d.ts.map +1 -1
- package/dist/plugins/marketplace/errors.js +10 -0
- package/dist/plugins/marketplace/install-from-marketplace.cjs +5 -0
- package/dist/plugins/marketplace/install-from-marketplace.d.ts.map +1 -1
- package/dist/plugins/marketplace/install-from-marketplace.js +7 -1
- package/dist/plugins/marketplace/operations.cjs +30 -6
- package/dist/plugins/marketplace/operations.d.ts +6 -0
- package/dist/plugins/marketplace/operations.d.ts.map +1 -1
- package/dist/plugins/marketplace/operations.js +31 -8
- package/dist/plugins/marketplace/schemas.cjs +2 -1
- package/dist/plugins/marketplace/schemas.d.ts.map +1 -1
- package/dist/plugins/marketplace/schemas.js +2 -1
- package/dist/plugins/schemas.cjs +9 -3
- package/dist/plugins/schemas.d.ts +5 -0
- package/dist/plugins/schemas.d.ts.map +1 -1
- package/dist/plugins/schemas.js +7 -2
- package/dist/registry/registry.cjs +6 -3
- package/dist/registry/registry.d.ts +0 -8
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +6 -3
- package/dist/tool-factories/creator-tools/factory.cjs +16 -1
- package/dist/tool-factories/creator-tools/factory.d.ts.map +1 -1
- package/dist/tool-factories/creator-tools/factory.js +16 -1
- package/dist/utils/api-key-store.cjs +3 -2
- package/dist/utils/api-key-store.d.ts.map +1 -1
- package/dist/utils/api-key-store.js +3 -2
- package/dist/utils/env-file.cjs +24 -2
- package/dist/utils/env-file.d.ts +3 -2
- package/dist/utils/env-file.d.ts.map +1 -1
- package/dist/utils/env-file.js +24 -2
- package/dist/utils/path.cjs +75 -11
- package/dist/utils/path.d.ts +14 -1
- package/dist/utils/path.d.ts.map +1 -1
- package/dist/utils/path.js +73 -10
- package/package.json +6 -6
|
@@ -160,9 +160,11 @@ async function installPluginFromPath(sourcePath, options) {
|
|
|
160
160
|
if (!(0, import_fs.existsSync)(parentDir)) {
|
|
161
161
|
(0, import_fs.mkdirSync)(parentDir, { recursive: true });
|
|
162
162
|
}
|
|
163
|
+
const installPathExisted = (0, import_fs.existsSync)(installPath);
|
|
163
164
|
try {
|
|
164
165
|
await (0, import_path.copyDirectory)(absoluteSourcePath, installPath);
|
|
165
166
|
} catch (error) {
|
|
167
|
+
if (!installPathExisted) (0, import_fs.rmSync)(installPath, { recursive: true, force: true });
|
|
166
168
|
throw import_errors.PluginError.installCopyFailed(
|
|
167
169
|
absoluteSourcePath,
|
|
168
170
|
installPath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/install-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EACR,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACvB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,wDAAwD;IACxD,KAAK,EAAE,kBAAkB,CAAC;IAC1B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,oBAAoB,CAsBhE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAiB1E;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC7B,UAAU,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,GACrB,oBAAoB,GAAG,IAAI,CA+C7B;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,oBAAoB,GAC9B,OAAO,CAAC,mBAAmB,CAAC,
|
|
1
|
+
{"version":3,"file":"install-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/install-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EACR,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACvB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,wDAAwD;IACxD,KAAK,EAAE,kBAAkB,CAAC;IAC1B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAErD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,oBAAoB,CAsBhE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAiB1E;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC7B,UAAU,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,GACrB,oBAAoB,GAAG,IAAI,CA+C7B;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,oBAAoB,GAC9B,OAAO,CAAC,mBAAmB,CAAC,CA+H9B"}
|
|
@@ -123,9 +123,11 @@ async function installPluginFromPath(sourcePath, options) {
|
|
|
123
123
|
if (!existsSync(parentDir)) {
|
|
124
124
|
mkdirSync(parentDir, { recursive: true });
|
|
125
125
|
}
|
|
126
|
+
const installPathExisted = existsSync(installPath);
|
|
126
127
|
try {
|
|
127
128
|
await copyDirectory(absoluteSourcePath, installPath);
|
|
128
129
|
} catch (error) {
|
|
130
|
+
if (!installPathExisted) rmSync(installPath, { recursive: true, force: true });
|
|
129
131
|
throw PluginError.installCopyFailed(
|
|
130
132
|
absoluteSourcePath,
|
|
131
133
|
installPath,
|
|
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(local_skills_exports);
|
|
|
36
36
|
var import_node_fs = require("node:fs");
|
|
37
37
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
38
38
|
var import_core = require("@dexto/core");
|
|
39
|
+
var import_path = require("../utils/path.js");
|
|
39
40
|
var import_discover_plugins = require("./discover-plugins.js");
|
|
40
41
|
var import_discover_skills = require("./discover-skills.js");
|
|
41
42
|
var import_load_plugin = require("./load-plugin.js");
|
|
@@ -130,6 +131,7 @@ class LocalSkills {
|
|
|
130
131
|
) ?? null;
|
|
131
132
|
}
|
|
132
133
|
async readSkillFile(root) {
|
|
134
|
+
if (!await (0, import_path.resolvesInside)(import_node_path.default.dirname(root.skillFile), root.skillFile)) return null;
|
|
133
135
|
let instructions;
|
|
134
136
|
try {
|
|
135
137
|
instructions = await import_node_fs.promises.readFile(root.skillFile, "utf8");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-skills.d.ts","sourceRoot":"","sources":["../../src/plugins/local-skills.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"local-skills.d.ts","sourceRoot":"","sources":["../../src/plugins/local-skills.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOxD,MAAM,WAAW,cAAc;IAC3B,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAED,MAAM,WAAW,wBAAwB;IACrC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACzC;AAED,KAAK,oBAAoB,GAAG,IAAI,CAC5B,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAC7D,MAAM,GAAG,WAAW,CACvB,CAAC;AASF,KAAK,uBAAuB,GAAG,CAC3B,aAAa,EAAE,MAAM,GAAG,SAAS,KAChC,SAAS,cAAc,EAAE,GAAG,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAAC;AAEpE;;;;;GAKG;AACH,qBAAa,WAAY,YAAW,MAAM;IAKlC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IALzC,OAAO,CAAC,mBAAmB,CAAqB;IAChD,OAAO,CAAC,qBAAqB,CAAuC;gBAG/C,aAAa,EAAE,uBAAuB,EACtC,oBAAoB,GAAE,MAAM,GAAG,SAAqB;IAGzE;;;OAGG;IACH,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAIzD,6FAA6F;IAC7F,wBAAwB,CAAC,OAAO,EAAE,SAAS,oBAAoB,EAAE,GAAG,IAAI;IAOlE,IAAI,IAAI,OAAO,CAAC,SAAS,YAAY,EAAE,CAAC;IAcxC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAgB/C,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAwCtD,SAAS;YAoBT,aAAa;YA6Bb,wBAAwB;IAgDtC,OAAO,CAAC,gBAAgB;CAG3B;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,WAAW,CAKrF;AAED,qGAAqG;AACrG,wBAAgB,8BAA8B,CAC1C,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,aAAa,GACvB,IAAI,CAGN"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { isSafeRelativeSkillPath, isValidPromptName } from "@dexto/core";
|
|
4
|
+
import { resolvesInside } from "../utils/path.js";
|
|
4
5
|
import { discoverClaudeCodePlugins } from "./discover-plugins.js";
|
|
5
6
|
import { discoverStandaloneSkills } from "./discover-skills.js";
|
|
6
7
|
import { loadClaudeCodePlugin } from "./load-plugin.js";
|
|
@@ -95,6 +96,7 @@ class LocalSkills {
|
|
|
95
96
|
) ?? null;
|
|
96
97
|
}
|
|
97
98
|
async readSkillFile(root) {
|
|
99
|
+
if (!await resolvesInside(path.dirname(root.skillFile), root.skillFile)) return null;
|
|
98
100
|
let instructions;
|
|
99
101
|
try {
|
|
100
102
|
instructions = await fs.readFile(root.skillFile, "utf8");
|
|
@@ -27,6 +27,7 @@ var MarketplaceErrorCode = /* @__PURE__ */ ((MarketplaceErrorCode2) => {
|
|
|
27
27
|
MarketplaceErrorCode2["ADD_ALREADY_EXISTS"] = "marketplace_add_already_exists";
|
|
28
28
|
MarketplaceErrorCode2["ADD_CLONE_FAILED"] = "marketplace_add_clone_failed";
|
|
29
29
|
MarketplaceErrorCode2["ADD_INVALID_SOURCE"] = "marketplace_add_invalid_source";
|
|
30
|
+
MarketplaceErrorCode2["ADD_INVALID_NAME"] = "marketplace_add_invalid_name";
|
|
30
31
|
MarketplaceErrorCode2["ADD_LOCAL_NOT_FOUND"] = "marketplace_add_local_not_found";
|
|
31
32
|
MarketplaceErrorCode2["REMOVE_NOT_FOUND"] = "marketplace_remove_not_found";
|
|
32
33
|
MarketplaceErrorCode2["REMOVE_DELETE_FAILED"] = "marketplace_remove_delete_failed";
|
|
@@ -7,6 +7,7 @@ export declare enum MarketplaceErrorCode {
|
|
|
7
7
|
ADD_ALREADY_EXISTS = "marketplace_add_already_exists",
|
|
8
8
|
ADD_CLONE_FAILED = "marketplace_add_clone_failed",
|
|
9
9
|
ADD_INVALID_SOURCE = "marketplace_add_invalid_source",
|
|
10
|
+
ADD_INVALID_NAME = "marketplace_add_invalid_name",
|
|
10
11
|
ADD_LOCAL_NOT_FOUND = "marketplace_add_local_not_found",
|
|
11
12
|
REMOVE_NOT_FOUND = "marketplace_remove_not_found",
|
|
12
13
|
REMOVE_DELETE_FAILED = "marketplace_remove_delete_failed",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/error-codes.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,oBAAoB;IAE5B,oBAAoB,qCAAqC;IACzD,qBAAqB,sCAAsC;IAG3D,kBAAkB,mCAAmC;IACrD,gBAAgB,iCAAiC;IACjD,kBAAkB,mCAAmC;IACrD,mBAAmB,oCAAoC;IAGvD,gBAAgB,iCAAiC;IACjD,oBAAoB,qCAAqC;IAGzD,gBAAgB,iCAAiC;IACjD,kBAAkB,mCAAmC;IACrD,0BAA0B,2CAA2C;IAGrE,6BAA6B,8CAA8C;IAC3E,wBAAwB,yCAAyC;IACjE,mBAAmB,oCAAoC;IAGvD,WAAW,4BAA4B;CAC1C"}
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/error-codes.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,oBAAoB;IAE5B,oBAAoB,qCAAqC;IACzD,qBAAqB,sCAAsC;IAG3D,kBAAkB,mCAAmC;IACrD,gBAAgB,iCAAiC;IACjD,kBAAkB,mCAAmC;IACrD,gBAAgB,iCAAiC;IACjD,mBAAmB,oCAAoC;IAGvD,gBAAgB,iCAAiC;IACjD,oBAAoB,qCAAqC;IAGzD,gBAAgB,iCAAiC;IACjD,kBAAkB,mCAAmC;IACrD,0BAA0B,2CAA2C;IAGrE,6BAA6B,8CAA8C;IAC3E,wBAAwB,yCAAyC;IACjE,mBAAmB,oCAAoC;IAGvD,WAAW,4BAA4B;CAC1C"}
|
|
@@ -4,6 +4,7 @@ var MarketplaceErrorCode = /* @__PURE__ */ ((MarketplaceErrorCode2) => {
|
|
|
4
4
|
MarketplaceErrorCode2["ADD_ALREADY_EXISTS"] = "marketplace_add_already_exists";
|
|
5
5
|
MarketplaceErrorCode2["ADD_CLONE_FAILED"] = "marketplace_add_clone_failed";
|
|
6
6
|
MarketplaceErrorCode2["ADD_INVALID_SOURCE"] = "marketplace_add_invalid_source";
|
|
7
|
+
MarketplaceErrorCode2["ADD_INVALID_NAME"] = "marketplace_add_invalid_name";
|
|
7
8
|
MarketplaceErrorCode2["ADD_LOCAL_NOT_FOUND"] = "marketplace_add_local_not_found";
|
|
8
9
|
MarketplaceErrorCode2["REMOVE_NOT_FOUND"] = "marketplace_remove_not_found";
|
|
9
10
|
MarketplaceErrorCode2["REMOVE_DELETE_FAILED"] = "marketplace_remove_delete_failed";
|
|
@@ -66,6 +66,16 @@ class MarketplaceError {
|
|
|
66
66
|
"Check the URL is correct and you have network access"
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
|
+
static addInvalidName(name) {
|
|
70
|
+
return new import_core.DextoRuntimeError(
|
|
71
|
+
import_error_codes.MarketplaceErrorCode.ADD_INVALID_NAME,
|
|
72
|
+
import_core.ErrorScope.CONFIG,
|
|
73
|
+
import_core.ErrorType.USER,
|
|
74
|
+
`Invalid marketplace name '${name}'`,
|
|
75
|
+
{ name },
|
|
76
|
+
'Use letters, digits, ".", "_", "-" and spaces, starting with a letter or digit; pass --name to choose one'
|
|
77
|
+
);
|
|
78
|
+
}
|
|
69
79
|
static addInvalidSource(source, reason) {
|
|
70
80
|
return new import_core.DextoRuntimeError(
|
|
71
81
|
import_error_codes.MarketplaceErrorCode.ADD_INVALID_SOURCE,
|
|
@@ -20,6 +20,9 @@ export declare class MarketplaceError {
|
|
|
20
20
|
source: string;
|
|
21
21
|
cause: string;
|
|
22
22
|
}>;
|
|
23
|
+
static addInvalidName(name: string): DextoRuntimeError<{
|
|
24
|
+
name: string;
|
|
25
|
+
}>;
|
|
23
26
|
static addInvalidSource(source: string, reason: string): DextoRuntimeError<{
|
|
24
27
|
source: string;
|
|
25
28
|
reason: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,aAAa,CAAC;AAGvE;;;GAGG;AACH,qBAAa,gBAAgB;IAEzB,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAWrD,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAYtD,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;;;;IAW1D,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAWnD,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAWtD,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM;;;IAYpC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM;;;IAWlC,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;IAYnE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM;;;IAWlC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAWnD,MAAM,CAAC,uBAAuB,CAAC,IAAI,EAAE,MAAM;;;IAY3C,MAAM,CAAC,0BAA0B,CAAC,WAAW,EAAE,MAAM;;;IAWrD,MAAM,CAAC,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;;;;IAYrE,MAAM,CAAC,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAY1D,MAAM,CAAC,UAAU,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;CAU3D"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAyB,MAAM,aAAa,CAAC;AAGvE;;;GAGG;AACH,qBAAa,gBAAgB;IAEzB,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAWrD,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAYtD,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;;;;IAW1D,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAWnD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM;;;IAWlC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAWtD,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM;;;IAYpC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM;;;IAWlC,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;IAYnE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM;;;IAWlC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAWnD,MAAM,CAAC,uBAAuB,CAAC,IAAI,EAAE,MAAM;;;IAY3C,MAAM,CAAC,0BAA0B,CAAC,WAAW,EAAE,MAAM;;;IAWrD,MAAM,CAAC,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;;;;IAYrE,MAAM,CAAC,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;IAY1D,MAAM,CAAC,UAAU,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;CAU3D"}
|
|
@@ -43,6 +43,16 @@ class MarketplaceError {
|
|
|
43
43
|
"Check the URL is correct and you have network access"
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
|
+
static addInvalidName(name) {
|
|
47
|
+
return new DextoRuntimeError(
|
|
48
|
+
MarketplaceErrorCode.ADD_INVALID_NAME,
|
|
49
|
+
ErrorScope.CONFIG,
|
|
50
|
+
ErrorType.USER,
|
|
51
|
+
`Invalid marketplace name '${name}'`,
|
|
52
|
+
{ name },
|
|
53
|
+
'Use letters, digits, ".", "_", "-" and spaces, starting with a letter or digit; pass --name to choose one'
|
|
54
|
+
);
|
|
55
|
+
}
|
|
46
56
|
static addInvalidSource(source, reason) {
|
|
47
57
|
return new DextoRuntimeError(
|
|
48
58
|
MarketplaceErrorCode.ADD_INVALID_SOURCE,
|
|
@@ -104,7 +104,12 @@ async function installPluginFromMarketplace(pluginSpec, options = {}) {
|
|
|
104
104
|
try {
|
|
105
105
|
(0, import_fs.mkdirSync)(cachePath, { recursive: true });
|
|
106
106
|
await (0, import_path.copyDirectory)(plugin.sourcePath, cachePath);
|
|
107
|
+
const unchanged = marketplaceEntry !== null && (0, import_operations.realPathInside)(marketplaceEntry.installLocation, plugin.sourcePath) === plugin.sourcePath;
|
|
108
|
+
if (!unchanged) {
|
|
109
|
+
throw new Error("the plugin directory changed while it was being copied");
|
|
110
|
+
}
|
|
107
111
|
} catch (error) {
|
|
112
|
+
(0, import_fs.rmSync)(cachePath, { recursive: true, force: true });
|
|
108
113
|
throw import_errors.MarketplaceError.installCopyFailed(
|
|
109
114
|
pluginName,
|
|
110
115
|
error instanceof Error ? error.message : String(error)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install-from-marketplace.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/install-from-marketplace.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"install-from-marketplace.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/install-from-marketplace.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH,OAAO,KAAK,EACR,yBAAyB,EACzB,wBAAwB,EACxB,iBAAiB,EACpB,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAY1F;AA0BD;;;;;GAKG;AACH,wBAAsB,4BAA4B,CAC9C,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,yBAA8B,GACxC,OAAO,CAAC,wBAAwB,CAAC,CA0FnC;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACpC,KAAK,EAAE,MAAM,EACb,eAAe,CAAC,EAAE,MAAM,GACzB,iBAAiB,EAAE,CAqBrB"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
|
-
import { existsSync, mkdirSync } from "fs";
|
|
2
|
+
import { existsSync, mkdirSync, rmSync } from "fs";
|
|
3
3
|
import { execSync } from "child_process";
|
|
4
4
|
import { copyDirectory } from "../../utils/path.js";
|
|
5
5
|
import { getMarketplaceCacheDir, getMarketplaceEntry } from "./registry.js";
|
|
6
6
|
import {
|
|
7
7
|
findPluginInMarketplaces,
|
|
8
|
+
realPathInside,
|
|
8
9
|
scanMarketplacePlugins,
|
|
9
10
|
listAllMarketplacePlugins
|
|
10
11
|
} from "./operations.js";
|
|
@@ -73,7 +74,12 @@ async function installPluginFromMarketplace(pluginSpec, options = {}) {
|
|
|
73
74
|
try {
|
|
74
75
|
mkdirSync(cachePath, { recursive: true });
|
|
75
76
|
await copyDirectory(plugin.sourcePath, cachePath);
|
|
77
|
+
const unchanged = marketplaceEntry !== null && realPathInside(marketplaceEntry.installLocation, plugin.sourcePath) === plugin.sourcePath;
|
|
78
|
+
if (!unchanged) {
|
|
79
|
+
throw new Error("the plugin directory changed while it was being copied");
|
|
80
|
+
}
|
|
76
81
|
} catch (error) {
|
|
82
|
+
rmSync(cachePath, { recursive: true, force: true });
|
|
77
83
|
throw MarketplaceError.installCopyFailed(
|
|
78
84
|
pluginName,
|
|
79
85
|
error instanceof Error ? error.message : String(error)
|
|
@@ -34,6 +34,7 @@ __export(operations_exports, {
|
|
|
34
34
|
listAllMarketplacePlugins: () => listAllMarketplacePlugins,
|
|
35
35
|
listMarketplaces: () => listMarketplaces,
|
|
36
36
|
parseMarketplaceSource: () => parseMarketplaceSource,
|
|
37
|
+
realPathInside: () => realPathInside,
|
|
37
38
|
removeMarketplace: () => removeMarketplace,
|
|
38
39
|
scanMarketplacePlugins: () => scanMarketplacePlugins,
|
|
39
40
|
updateMarketplace: () => updateMarketplace
|
|
@@ -45,6 +46,7 @@ var import_child_process = require("child_process");
|
|
|
45
46
|
var import_registry = require("./registry.js");
|
|
46
47
|
var import_errors = require("./errors.js");
|
|
47
48
|
var import_schemas = require("./schemas.js");
|
|
49
|
+
var import_schemas2 = require("../schemas.js");
|
|
48
50
|
var import_validate_plugin = require("../validate-plugin.js");
|
|
49
51
|
function parseMarketplaceSource(source) {
|
|
50
52
|
const trimmed = source.trim();
|
|
@@ -102,6 +104,9 @@ function getGitSha(dir) {
|
|
|
102
104
|
async function addMarketplace(source, options = {}) {
|
|
103
105
|
const parsedSource = parseMarketplaceSource(source);
|
|
104
106
|
const name = options.name || deriveMarketplaceName(parsedSource);
|
|
107
|
+
if (!import_schemas2.SafePluginNameSchema.safeParse(name).success) {
|
|
108
|
+
throw import_errors.MarketplaceError.addInvalidName(name);
|
|
109
|
+
}
|
|
105
110
|
const warnings = [];
|
|
106
111
|
const existing = (0, import_registry.getMarketplaceEntry)(name);
|
|
107
112
|
if (existing) {
|
|
@@ -119,7 +124,7 @@ async function addMarketplace(source, options = {}) {
|
|
|
119
124
|
installLocation = path.join(marketplacesDir, name);
|
|
120
125
|
const cloneUrl = getCloneUrl(parsedSource);
|
|
121
126
|
try {
|
|
122
|
-
(0, import_child_process.
|
|
127
|
+
(0, import_child_process.execFileSync)("git", ["clone", "--", cloneUrl, installLocation], {
|
|
123
128
|
encoding: "utf-8",
|
|
124
129
|
stdio: ["pipe", "pipe", "pipe"]
|
|
125
130
|
});
|
|
@@ -204,7 +209,7 @@ async function updateSingleMarketplace(name) {
|
|
|
204
209
|
warnings.push("Marketplace directory not found, re-cloning");
|
|
205
210
|
const cloneUrl = getCloneUrl(entry.source);
|
|
206
211
|
try {
|
|
207
|
-
(0, import_child_process.
|
|
212
|
+
(0, import_child_process.execFileSync)("git", ["clone", "--", cloneUrl, entry.installLocation], {
|
|
208
213
|
encoding: "utf-8",
|
|
209
214
|
stdio: ["pipe", "pipe", "pipe"]
|
|
210
215
|
});
|
|
@@ -254,6 +259,16 @@ async function updateSingleMarketplace(name) {
|
|
|
254
259
|
function listMarketplaces() {
|
|
255
260
|
return (0, import_registry.getAllMarketplaces)();
|
|
256
261
|
}
|
|
262
|
+
function realPathInside(directory, target) {
|
|
263
|
+
try {
|
|
264
|
+
const realTarget = (0, import_fs.realpathSync)(target);
|
|
265
|
+
const relative = path.relative((0, import_fs.realpathSync)(directory), realTarget);
|
|
266
|
+
const inside = relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
267
|
+
return inside ? realTarget : void 0;
|
|
268
|
+
} catch {
|
|
269
|
+
return void 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
257
272
|
function scanMarketplacePlugins(marketplacePath, marketplaceName) {
|
|
258
273
|
const plugins = [];
|
|
259
274
|
const manifestPath = path.join(marketplacePath, "marketplace.json");
|
|
@@ -266,8 +281,11 @@ function scanMarketplacePlugins(marketplacePath, marketplaceName) {
|
|
|
266
281
|
const manifest = result.data;
|
|
267
282
|
if (manifest.plugins && manifest.plugins.length > 0) {
|
|
268
283
|
for (const plugin of manifest.plugins) {
|
|
269
|
-
const pluginPath =
|
|
270
|
-
|
|
284
|
+
const pluginPath = realPathInside(
|
|
285
|
+
marketplacePath,
|
|
286
|
+
path.resolve(marketplacePath, plugin.source)
|
|
287
|
+
);
|
|
288
|
+
if (pluginPath !== void 0) {
|
|
271
289
|
plugins.push({
|
|
272
290
|
name: plugin.name,
|
|
273
291
|
...plugin.description !== void 0 && {
|
|
@@ -294,7 +312,8 @@ function scanMarketplacePlugins(marketplacePath, marketplaceName) {
|
|
|
294
312
|
const entries = (0, import_fs.readdirSync)(dirPath, { withFileTypes: true });
|
|
295
313
|
for (const entry of entries) {
|
|
296
314
|
if (!entry.isDirectory()) continue;
|
|
297
|
-
const pluginPath = path.join(dirPath, entry.name);
|
|
315
|
+
const pluginPath = realPathInside(marketplacePath, path.join(dirPath, entry.name));
|
|
316
|
+
if (pluginPath === void 0) continue;
|
|
298
317
|
const manifest = (0, import_validate_plugin.tryLoadManifest)(pluginPath);
|
|
299
318
|
if (manifest) {
|
|
300
319
|
plugins.push({
|
|
@@ -317,7 +336,11 @@ function scanMarketplacePlugins(marketplacePath, marketplaceName) {
|
|
|
317
336
|
if (!entry.isDirectory()) continue;
|
|
318
337
|
if (["plugins", "external_plugins", ".git", "node_modules"].includes(entry.name))
|
|
319
338
|
continue;
|
|
320
|
-
const pluginPath =
|
|
339
|
+
const pluginPath = realPathInside(
|
|
340
|
+
marketplacePath,
|
|
341
|
+
path.join(marketplacePath, entry.name)
|
|
342
|
+
);
|
|
343
|
+
if (pluginPath === void 0) continue;
|
|
321
344
|
const manifest = (0, import_validate_plugin.tryLoadManifest)(pluginPath);
|
|
322
345
|
if (manifest) {
|
|
323
346
|
const existing = plugins.find((p) => p.name === manifest.name);
|
|
@@ -368,6 +391,7 @@ function findPluginInMarketplaces(pluginName, marketplaceName) {
|
|
|
368
391
|
listAllMarketplacePlugins,
|
|
369
392
|
listMarketplaces,
|
|
370
393
|
parseMarketplaceSource,
|
|
394
|
+
realPathInside,
|
|
371
395
|
removeMarketplace,
|
|
372
396
|
scanMarketplacePlugins,
|
|
373
397
|
updateMarketplace
|
|
@@ -28,6 +28,12 @@ export declare function updateMarketplace(name?: string): Promise<MarketplaceUpd
|
|
|
28
28
|
* List all registered marketplaces
|
|
29
29
|
*/
|
|
30
30
|
export declare function listMarketplaces(): MarketplaceEntry[];
|
|
31
|
+
/**
|
|
32
|
+
* The real path of `target` when it really lives inside `directory`, after following every
|
|
33
|
+
* symlink on both paths; undefined when it is outside or cannot be resolved (fail closed).
|
|
34
|
+
* Callers use the returned path from then on, so what is copied is what was checked.
|
|
35
|
+
*/
|
|
36
|
+
export declare function realPathInside(directory: string, target: string): string | undefined;
|
|
31
37
|
/**
|
|
32
38
|
* Scan a marketplace directory for plugins
|
|
33
39
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/operations.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/operations.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAiBH,OAAO,KAAK,EACR,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,EAE1B,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CA0BxE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAqBvE;AAgCD;;GAEG;AACH,wBAAsB,cAAc,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,qBAA0B,GACpC,OAAO,CAAC,oBAAoB,CAAC,CAsE/B;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CA6BtF;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAiBzF;AAwFD;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,gBAAgB,EAAE,CAErD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUpF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAClC,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM,GACxB,iBAAiB,EAAE,CAoHrB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,iBAAiB,EAAE,CAY/D;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACpC,UAAU,EAAE,MAAM,EAClB,eAAe,CAAC,EAAE,MAAM,GACzB,iBAAiB,GAAG,IAAI,CAiB1B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
|
-
import { existsSync, readdirSync, readFileSync, rmSync } from "fs";
|
|
3
|
-
import { execSync } from "child_process";
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, rmSync } from "fs";
|
|
3
|
+
import { execFileSync, execSync } from "child_process";
|
|
4
4
|
import {
|
|
5
5
|
getMarketplacesDir,
|
|
6
6
|
addMarketplaceEntry,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "./registry.js";
|
|
12
12
|
import { MarketplaceError } from "./errors.js";
|
|
13
13
|
import { MarketplaceManifestSchema } from "./schemas.js";
|
|
14
|
+
import { SafePluginNameSchema } from "../schemas.js";
|
|
14
15
|
import { tryLoadManifest } from "../validate-plugin.js";
|
|
15
16
|
function parseMarketplaceSource(source) {
|
|
16
17
|
const trimmed = source.trim();
|
|
@@ -68,6 +69,9 @@ function getGitSha(dir) {
|
|
|
68
69
|
async function addMarketplace(source, options = {}) {
|
|
69
70
|
const parsedSource = parseMarketplaceSource(source);
|
|
70
71
|
const name = options.name || deriveMarketplaceName(parsedSource);
|
|
72
|
+
if (!SafePluginNameSchema.safeParse(name).success) {
|
|
73
|
+
throw MarketplaceError.addInvalidName(name);
|
|
74
|
+
}
|
|
71
75
|
const warnings = [];
|
|
72
76
|
const existing = getMarketplaceEntry(name);
|
|
73
77
|
if (existing) {
|
|
@@ -85,7 +89,7 @@ async function addMarketplace(source, options = {}) {
|
|
|
85
89
|
installLocation = path.join(marketplacesDir, name);
|
|
86
90
|
const cloneUrl = getCloneUrl(parsedSource);
|
|
87
91
|
try {
|
|
88
|
-
|
|
92
|
+
execFileSync("git", ["clone", "--", cloneUrl, installLocation], {
|
|
89
93
|
encoding: "utf-8",
|
|
90
94
|
stdio: ["pipe", "pipe", "pipe"]
|
|
91
95
|
});
|
|
@@ -170,7 +174,7 @@ async function updateSingleMarketplace(name) {
|
|
|
170
174
|
warnings.push("Marketplace directory not found, re-cloning");
|
|
171
175
|
const cloneUrl = getCloneUrl(entry.source);
|
|
172
176
|
try {
|
|
173
|
-
|
|
177
|
+
execFileSync("git", ["clone", "--", cloneUrl, entry.installLocation], {
|
|
174
178
|
encoding: "utf-8",
|
|
175
179
|
stdio: ["pipe", "pipe", "pipe"]
|
|
176
180
|
});
|
|
@@ -220,6 +224,16 @@ async function updateSingleMarketplace(name) {
|
|
|
220
224
|
function listMarketplaces() {
|
|
221
225
|
return getAllMarketplaces();
|
|
222
226
|
}
|
|
227
|
+
function realPathInside(directory, target) {
|
|
228
|
+
try {
|
|
229
|
+
const realTarget = realpathSync(target);
|
|
230
|
+
const relative = path.relative(realpathSync(directory), realTarget);
|
|
231
|
+
const inside = relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
232
|
+
return inside ? realTarget : void 0;
|
|
233
|
+
} catch {
|
|
234
|
+
return void 0;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
223
237
|
function scanMarketplacePlugins(marketplacePath, marketplaceName) {
|
|
224
238
|
const plugins = [];
|
|
225
239
|
const manifestPath = path.join(marketplacePath, "marketplace.json");
|
|
@@ -232,8 +246,11 @@ function scanMarketplacePlugins(marketplacePath, marketplaceName) {
|
|
|
232
246
|
const manifest = result.data;
|
|
233
247
|
if (manifest.plugins && manifest.plugins.length > 0) {
|
|
234
248
|
for (const plugin of manifest.plugins) {
|
|
235
|
-
const pluginPath =
|
|
236
|
-
|
|
249
|
+
const pluginPath = realPathInside(
|
|
250
|
+
marketplacePath,
|
|
251
|
+
path.resolve(marketplacePath, plugin.source)
|
|
252
|
+
);
|
|
253
|
+
if (pluginPath !== void 0) {
|
|
237
254
|
plugins.push({
|
|
238
255
|
name: plugin.name,
|
|
239
256
|
...plugin.description !== void 0 && {
|
|
@@ -260,7 +277,8 @@ function scanMarketplacePlugins(marketplacePath, marketplaceName) {
|
|
|
260
277
|
const entries = readdirSync(dirPath, { withFileTypes: true });
|
|
261
278
|
for (const entry of entries) {
|
|
262
279
|
if (!entry.isDirectory()) continue;
|
|
263
|
-
const pluginPath = path.join(dirPath, entry.name);
|
|
280
|
+
const pluginPath = realPathInside(marketplacePath, path.join(dirPath, entry.name));
|
|
281
|
+
if (pluginPath === void 0) continue;
|
|
264
282
|
const manifest = tryLoadManifest(pluginPath);
|
|
265
283
|
if (manifest) {
|
|
266
284
|
plugins.push({
|
|
@@ -283,7 +301,11 @@ function scanMarketplacePlugins(marketplacePath, marketplaceName) {
|
|
|
283
301
|
if (!entry.isDirectory()) continue;
|
|
284
302
|
if (["plugins", "external_plugins", ".git", "node_modules"].includes(entry.name))
|
|
285
303
|
continue;
|
|
286
|
-
const pluginPath =
|
|
304
|
+
const pluginPath = realPathInside(
|
|
305
|
+
marketplacePath,
|
|
306
|
+
path.join(marketplacePath, entry.name)
|
|
307
|
+
);
|
|
308
|
+
if (pluginPath === void 0) continue;
|
|
287
309
|
const manifest = tryLoadManifest(pluginPath);
|
|
288
310
|
if (manifest) {
|
|
289
311
|
const existing = plugins.find((p) => p.name === manifest.name);
|
|
@@ -333,6 +355,7 @@ export {
|
|
|
333
355
|
listAllMarketplacePlugins,
|
|
334
356
|
listMarketplaces,
|
|
335
357
|
parseMarketplaceSource,
|
|
358
|
+
realPathInside,
|
|
336
359
|
removeMarketplace,
|
|
337
360
|
scanMarketplacePlugins,
|
|
338
361
|
updateMarketplace
|
|
@@ -28,6 +28,7 @@ __export(schemas_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(schemas_exports);
|
|
30
30
|
var import_zod = require("zod");
|
|
31
|
+
var import_schemas = require("../schemas.js");
|
|
31
32
|
const MarketplaceSourceSchema = import_zod.z.object({
|
|
32
33
|
type: import_zod.z.enum(["github", "git", "local"]).describe("Type of marketplace source"),
|
|
33
34
|
value: import_zod.z.string().min(1).describe("Source value: owner/repo, git URL, or local path")
|
|
@@ -43,7 +44,7 @@ const KnownMarketplacesFileSchema = import_zod.z.object({
|
|
|
43
44
|
marketplaces: import_zod.z.record(import_zod.z.string(), MarketplaceEntrySchema).default({}).describe("Registered marketplaces by name")
|
|
44
45
|
}).strict();
|
|
45
46
|
const MarketplacePluginEntrySchema = import_zod.z.object({
|
|
46
|
-
name:
|
|
47
|
+
name: import_schemas.SafePluginNameSchema.describe("Plugin name"),
|
|
47
48
|
description: import_zod.z.string().optional().describe("Plugin description"),
|
|
48
49
|
source: import_zod.z.string().describe("Path to plugin within marketplace"),
|
|
49
50
|
category: import_zod.z.string().optional().describe("Plugin category"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/schemas.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/schemas.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;;kBAKvB,CAAC;AAEd;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;kBAOtB,CAAC;AAEd;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;kBAQ3B,CAAC;AAEd;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;;;;iBAQvB,CAAC;AAEnB;;;GAGG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;iBAapB,CAAC;AAEnB;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;kBAQ3B,CAAC;AAEd,eAAO,MAAM,+BAA+B;;;;;;;;kBAM/B,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { SafePluginNameSchema } from "../schemas.js";
|
|
2
3
|
const MarketplaceSourceSchema = z.object({
|
|
3
4
|
type: z.enum(["github", "git", "local"]).describe("Type of marketplace source"),
|
|
4
5
|
value: z.string().min(1).describe("Source value: owner/repo, git URL, or local path")
|
|
@@ -14,7 +15,7 @@ const KnownMarketplacesFileSchema = z.object({
|
|
|
14
15
|
marketplaces: z.record(z.string(), MarketplaceEntrySchema).default({}).describe("Registered marketplaces by name")
|
|
15
16
|
}).strict();
|
|
16
17
|
const MarketplacePluginEntrySchema = z.object({
|
|
17
|
-
name:
|
|
18
|
+
name: SafePluginNameSchema.describe("Plugin name"),
|
|
18
19
|
description: z.string().optional().describe("Plugin description"),
|
|
19
20
|
source: z.string().describe("Path to plugin within marketplace"),
|
|
20
21
|
category: z.string().optional().describe("Plugin category"),
|
package/dist/plugins/schemas.cjs
CHANGED
|
@@ -21,7 +21,8 @@ __export(schemas_exports, {
|
|
|
21
21
|
InstalledPluginEntrySchema: () => InstalledPluginEntrySchema,
|
|
22
22
|
InstalledPluginsFileSchema: () => InstalledPluginsFileSchema,
|
|
23
23
|
PluginMCPConfigSchema: () => PluginMCPConfigSchema,
|
|
24
|
-
PluginManifestSchema: () => PluginManifestSchema
|
|
24
|
+
PluginManifestSchema: () => PluginManifestSchema,
|
|
25
|
+
SafePluginNameSchema: () => SafePluginNameSchema
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(schemas_exports);
|
|
27
28
|
var import_zod = require("zod");
|
|
@@ -32,8 +33,12 @@ const AuthorSchema = import_zod.z.union([
|
|
|
32
33
|
email: import_zod.z.string().optional()
|
|
33
34
|
})
|
|
34
35
|
]);
|
|
36
|
+
const SafePluginNameSchema = import_zod.z.string().regex(
|
|
37
|
+
/^[A-Za-z0-9][A-Za-z0-9._ -]*$/,
|
|
38
|
+
'Name may only contain letters, digits, ".", "_", "-" and spaces, and must start with a letter or digit'
|
|
39
|
+
);
|
|
35
40
|
const PluginManifestSchema = import_zod.z.object({
|
|
36
|
-
name:
|
|
41
|
+
name: SafePluginNameSchema.describe("Unique plugin name (used for namespacing commands)"),
|
|
37
42
|
description: import_zod.z.string().optional().describe("Human-readable plugin description"),
|
|
38
43
|
version: import_zod.z.string().optional().describe("Semantic version (e.g., 1.0.0)"),
|
|
39
44
|
author: AuthorSchema.optional().describe("Plugin author - string or {name, email} object")
|
|
@@ -60,5 +65,6 @@ const InstalledPluginsFileSchema = import_zod.z.object({
|
|
|
60
65
|
InstalledPluginEntrySchema,
|
|
61
66
|
InstalledPluginsFileSchema,
|
|
62
67
|
PluginMCPConfigSchema,
|
|
63
|
-
PluginManifestSchema
|
|
68
|
+
PluginManifestSchema,
|
|
69
|
+
SafePluginNameSchema
|
|
64
70
|
});
|
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
* - .claude-plugin/plugin.json
|
|
6
6
|
*/
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
+
/**
|
|
9
|
+
* A plugin or marketplace name is used as a directory name, so it must be a single safe path
|
|
10
|
+
* segment: no separators and no leading dot.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SafePluginNameSchema: z.ZodString;
|
|
8
13
|
/**
|
|
9
14
|
* Schema for Claude Code plugin.json manifest
|
|
10
15
|
* Uses passthrough to allow unknown fields from Claude Code plugins
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/plugins/schemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;iBAQ2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;iBAQe,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE9E;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;iBAeG,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;iBAQgB,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAExF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/plugins/schemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB;;;GAGG;AACH,eAAO,MAAM,oBAAoB,aAK5B,CAAC;AAEN;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;iBAQ2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;iBAQe,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE9E;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;iBAeG,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;iBAQgB,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAExF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC"}
|
package/dist/plugins/schemas.js
CHANGED
|
@@ -6,8 +6,12 @@ const AuthorSchema = z.union([
|
|
|
6
6
|
email: z.string().optional()
|
|
7
7
|
})
|
|
8
8
|
]);
|
|
9
|
+
const SafePluginNameSchema = z.string().regex(
|
|
10
|
+
/^[A-Za-z0-9][A-Za-z0-9._ -]*$/,
|
|
11
|
+
'Name may only contain letters, digits, ".", "_", "-" and spaces, and must start with a letter or digit'
|
|
12
|
+
);
|
|
9
13
|
const PluginManifestSchema = z.object({
|
|
10
|
-
name:
|
|
14
|
+
name: SafePluginNameSchema.describe("Unique plugin name (used for namespacing commands)"),
|
|
11
15
|
description: z.string().optional().describe("Human-readable plugin description"),
|
|
12
16
|
version: z.string().optional().describe("Semantic version (e.g., 1.0.0)"),
|
|
13
17
|
author: AuthorSchema.optional().describe("Plugin author - string or {name, email} object")
|
|
@@ -33,5 +37,6 @@ export {
|
|
|
33
37
|
InstalledPluginEntrySchema,
|
|
34
38
|
InstalledPluginsFileSchema,
|
|
35
39
|
PluginMCPConfigSchema,
|
|
36
|
-
PluginManifestSchema
|
|
40
|
+
PluginManifestSchema,
|
|
41
|
+
SafePluginNameSchema
|
|
37
42
|
};
|
|
@@ -43,6 +43,9 @@ var import_errors = require("./errors.js");
|
|
|
43
43
|
var import_user_registry = require("./user-registry.js");
|
|
44
44
|
var import_loader = require("../preferences/loader.js");
|
|
45
45
|
let cachedRegistry = null;
|
|
46
|
+
function isOutsideAgentsDir(relativePath) {
|
|
47
|
+
return relativePath === "" || relativePath.startsWith("..") || import_path.default.isAbsolute(relativePath);
|
|
48
|
+
}
|
|
46
49
|
class LocalAgentRegistry {
|
|
47
50
|
_registry = null;
|
|
48
51
|
/**
|
|
@@ -186,7 +189,7 @@ class LocalAgentRegistry {
|
|
|
186
189
|
const globalAgentsDir = (0, import_path2.getDextoGlobalPath)("agents");
|
|
187
190
|
const targetDir = import_path.default.resolve(globalAgentsDir, agentId);
|
|
188
191
|
const relTarget = import_path.default.relative(globalAgentsDir, targetDir);
|
|
189
|
-
if (
|
|
192
|
+
if (isOutsideAgentsDir(relTarget)) {
|
|
190
193
|
throw import_errors.RegistryError.installationFailed(
|
|
191
194
|
agentId,
|
|
192
195
|
"invalid agentId: path traversal detected"
|
|
@@ -246,7 +249,7 @@ class LocalAgentRegistry {
|
|
|
246
249
|
const globalAgentsDir = (0, import_path2.getDextoGlobalPath)("agents");
|
|
247
250
|
const targetDir = import_path.default.resolve(globalAgentsDir, agentId);
|
|
248
251
|
const relTarget = import_path.default.relative(globalAgentsDir, targetDir);
|
|
249
|
-
if (
|
|
252
|
+
if (isOutsideAgentsDir(relTarget)) {
|
|
250
253
|
throw import_errors.RegistryError.installationFailed(
|
|
251
254
|
agentId,
|
|
252
255
|
"invalid agentId: path traversal detected"
|
|
@@ -403,7 +406,7 @@ class LocalAgentRegistry {
|
|
|
403
406
|
const globalAgentsDir = (0, import_path2.getDextoGlobalPath)("agents");
|
|
404
407
|
const agentDir = import_path.default.resolve(globalAgentsDir, agentId);
|
|
405
408
|
const relAgent = import_path.default.relative(globalAgentsDir, agentDir);
|
|
406
|
-
if (
|
|
409
|
+
if (isOutsideAgentsDir(relAgent)) {
|
|
407
410
|
throw import_errors.RegistryError.uninstallationFailed(
|
|
408
411
|
agentId,
|
|
409
412
|
"invalid agentId: path traversal detected"
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { Registry, AgentRegistry, AgentRegistryEntry } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Local agent registry implementation
|
|
4
|
-
* Loads and merges the bundled registry (shipped with the CLI bundle) with the user's custom
|
|
5
|
-
* registry under `~/.dexto`.
|
|
6
|
-
*
|
|
7
|
-
* Hosts (CLI, server, apps) use this to resolve an agent ID to a concrete YAML path, then
|
|
8
|
-
* load/validate that YAML and instantiate a `DextoAgent` from the resolved config.
|
|
9
|
-
*/
|
|
10
2
|
export declare class LocalAgentRegistry implements AgentRegistry {
|
|
11
3
|
private _registry;
|
|
12
4
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry/registry.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,QAAQ,EAER,aAAa,EACb,kBAAkB,EAErB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry/registry.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,QAAQ,EAER,aAAa,EACb,kBAAkB,EAErB,MAAM,YAAY,CAAC;AA6BpB,qBAAa,kBAAmB,YAAW,aAAa;IACpD,OAAO,CAAC,SAAS,CAAyB;IAE1C;;OAEG;IACH,WAAW,IAAI,QAAQ;IAOvB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAyCpB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAKlC;;OAEG;IACH,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC;IAKxD;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAgC7B;;;OAGG;IACH,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;IA0C5D;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgFpD;;;;;;OAMG;IACG,0BAA0B,CAC5B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;KACjB,GACF,OAAO,CAAC,MAAM,CAAC;IAqJlB;;;;;;OAMG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,GAAE,OAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAsCjF;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAsB7C;;OAEG;YACW,sBAAsB;IAYpC;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CA8C/E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,kBAAkB,CAKrD;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAY9E"}
|
|
@@ -16,6 +16,9 @@ import {
|
|
|
16
16
|
} from "./user-registry.js";
|
|
17
17
|
import { loadGlobalPreferences } from "../preferences/loader.js";
|
|
18
18
|
let cachedRegistry = null;
|
|
19
|
+
function isOutsideAgentsDir(relativePath) {
|
|
20
|
+
return relativePath === "" || relativePath.startsWith("..") || path.isAbsolute(relativePath);
|
|
21
|
+
}
|
|
19
22
|
class LocalAgentRegistry {
|
|
20
23
|
_registry = null;
|
|
21
24
|
/**
|
|
@@ -159,7 +162,7 @@ class LocalAgentRegistry {
|
|
|
159
162
|
const globalAgentsDir = getDextoGlobalPath("agents");
|
|
160
163
|
const targetDir = path.resolve(globalAgentsDir, agentId);
|
|
161
164
|
const relTarget = path.relative(globalAgentsDir, targetDir);
|
|
162
|
-
if (
|
|
165
|
+
if (isOutsideAgentsDir(relTarget)) {
|
|
163
166
|
throw RegistryError.installationFailed(
|
|
164
167
|
agentId,
|
|
165
168
|
"invalid agentId: path traversal detected"
|
|
@@ -219,7 +222,7 @@ class LocalAgentRegistry {
|
|
|
219
222
|
const globalAgentsDir = getDextoGlobalPath("agents");
|
|
220
223
|
const targetDir = path.resolve(globalAgentsDir, agentId);
|
|
221
224
|
const relTarget = path.relative(globalAgentsDir, targetDir);
|
|
222
|
-
if (
|
|
225
|
+
if (isOutsideAgentsDir(relTarget)) {
|
|
223
226
|
throw RegistryError.installationFailed(
|
|
224
227
|
agentId,
|
|
225
228
|
"invalid agentId: path traversal detected"
|
|
@@ -376,7 +379,7 @@ class LocalAgentRegistry {
|
|
|
376
379
|
const globalAgentsDir = getDextoGlobalPath("agents");
|
|
377
380
|
const agentDir = path.resolve(globalAgentsDir, agentId);
|
|
378
381
|
const relAgent = path.relative(globalAgentsDir, agentDir);
|
|
379
|
-
if (
|
|
382
|
+
if (isOutsideAgentsDir(relAgent)) {
|
|
380
383
|
throw RegistryError.uninstallationFailed(
|
|
381
384
|
agentId,
|
|
382
385
|
"invalid agentId: path traversal detected"
|
|
@@ -36,6 +36,7 @@ var import_node_path = __toESM(require("node:path"), 1);
|
|
|
36
36
|
var import_core = require("@dexto/core");
|
|
37
37
|
var import_discover_skills = require("../../plugins/discover-skills.js");
|
|
38
38
|
var import_skill_markdown = require("../../plugins/skill-markdown.js");
|
|
39
|
+
var import_path = require("../../utils/path.js");
|
|
39
40
|
var import_schemas = require("./schemas.js");
|
|
40
41
|
var import_zod = require("zod");
|
|
41
42
|
const SkillCreateInputSchema = import_zod.z.object({
|
|
@@ -150,6 +151,18 @@ async function resolveExistingSkillLocation(input, context, toolId) {
|
|
|
150
151
|
skillFile: import_node_path.default.join(skillDir, "SKILL.md")
|
|
151
152
|
};
|
|
152
153
|
}
|
|
154
|
+
async function assertSkillWritesStayInside(baseDir, skillDir, skillFile, toolId) {
|
|
155
|
+
if (await pathExists(skillDir) && !await (0, import_path.resolvesInside)(baseDir, skillDir)) {
|
|
156
|
+
throw import_core.ToolError.validationFailed(
|
|
157
|
+
toolId,
|
|
158
|
+
"skill directory resolves outside the skills root"
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
const fileStat = await import_node_fs.promises.lstat(skillFile).catch(() => void 0);
|
|
162
|
+
if (fileStat?.isSymbolicLink()) {
|
|
163
|
+
throw import_core.ToolError.validationFailed(toolId, "SKILL.md is a link and cannot be written");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
153
166
|
function ensurePathWithinBase(baseDir, targetDir, toolId) {
|
|
154
167
|
const resolvedBase = import_node_path.default.resolve(baseDir);
|
|
155
168
|
const resolvedTarget = import_node_path.default.resolve(targetDir);
|
|
@@ -250,6 +263,7 @@ const creatorToolsFactory = {
|
|
|
250
263
|
const skillDir = import_node_path.default.join(baseDir, skillId);
|
|
251
264
|
ensurePathWithinBase(baseDir, skillDir, "skill_create");
|
|
252
265
|
const skillFile = import_node_path.default.join(skillDir, "SKILL.md");
|
|
266
|
+
await assertSkillWritesStayInside(baseDir, skillDir, skillFile, "skill_create");
|
|
253
267
|
const exists = await pathExists(skillFile);
|
|
254
268
|
if (exists && !resolvedInput.overwrite) {
|
|
255
269
|
throw import_core.ToolError.validationFailed(
|
|
@@ -293,11 +307,12 @@ const creatorToolsFactory = {
|
|
|
293
307
|
context: "skill_update",
|
|
294
308
|
hint: "Use kebab-case skill ids (e.g., release-notes)"
|
|
295
309
|
});
|
|
296
|
-
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
310
|
+
const { baseDir, scope, skillDir, skillFile } = await resolveExistingSkillLocation(
|
|
297
311
|
input,
|
|
298
312
|
context,
|
|
299
313
|
"skill_update"
|
|
300
314
|
);
|
|
315
|
+
await assertSkillWritesStayInside(baseDir, skillDir, skillFile, "skill_update");
|
|
301
316
|
const exists = await pathExists(skillFile);
|
|
302
317
|
if (!exists) {
|
|
303
318
|
throw import_core.ToolError.validationFailed(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/creator-tools/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/tool-factories/creator-tools/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAgBvD,OAAO,EAIH,KAAK,kBAAkB,EAC1B,MAAM,cAAc,CAAC;AAgXtB,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,kBAAkB,CA6S/D,CAAC"}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
getStandaloneSkillPaths
|
|
13
13
|
} from "../../plugins/discover-skills.js";
|
|
14
14
|
import { getSkillFrontmatter } from "../../plugins/skill-markdown.js";
|
|
15
|
+
import { resolvesInside } from "../../utils/path.js";
|
|
15
16
|
import {
|
|
16
17
|
CREATOR_TOOL_NAMES,
|
|
17
18
|
CreatorToolsConfigSchema
|
|
@@ -129,6 +130,18 @@ async function resolveExistingSkillLocation(input, context, toolId) {
|
|
|
129
130
|
skillFile: path.join(skillDir, "SKILL.md")
|
|
130
131
|
};
|
|
131
132
|
}
|
|
133
|
+
async function assertSkillWritesStayInside(baseDir, skillDir, skillFile, toolId) {
|
|
134
|
+
if (await pathExists(skillDir) && !await resolvesInside(baseDir, skillDir)) {
|
|
135
|
+
throw ToolError.validationFailed(
|
|
136
|
+
toolId,
|
|
137
|
+
"skill directory resolves outside the skills root"
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
const fileStat = await fs.lstat(skillFile).catch(() => void 0);
|
|
141
|
+
if (fileStat?.isSymbolicLink()) {
|
|
142
|
+
throw ToolError.validationFailed(toolId, "SKILL.md is a link and cannot be written");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
132
145
|
function ensurePathWithinBase(baseDir, targetDir, toolId) {
|
|
133
146
|
const resolvedBase = path.resolve(baseDir);
|
|
134
147
|
const resolvedTarget = path.resolve(targetDir);
|
|
@@ -229,6 +242,7 @@ const creatorToolsFactory = {
|
|
|
229
242
|
const skillDir = path.join(baseDir, skillId);
|
|
230
243
|
ensurePathWithinBase(baseDir, skillDir, "skill_create");
|
|
231
244
|
const skillFile = path.join(skillDir, "SKILL.md");
|
|
245
|
+
await assertSkillWritesStayInside(baseDir, skillDir, skillFile, "skill_create");
|
|
232
246
|
const exists = await pathExists(skillFile);
|
|
233
247
|
if (exists && !resolvedInput.overwrite) {
|
|
234
248
|
throw ToolError.validationFailed(
|
|
@@ -272,11 +286,12 @@ const creatorToolsFactory = {
|
|
|
272
286
|
context: "skill_update",
|
|
273
287
|
hint: "Use kebab-case skill ids (e.g., release-notes)"
|
|
274
288
|
});
|
|
275
|
-
const { scope, skillFile } = await resolveExistingSkillLocation(
|
|
289
|
+
const { baseDir, scope, skillDir, skillFile } = await resolveExistingSkillLocation(
|
|
276
290
|
input,
|
|
277
291
|
context,
|
|
278
292
|
"skill_update"
|
|
279
293
|
);
|
|
294
|
+
await assertSkillWritesStayInside(baseDir, skillDir, skillFile, "skill_update");
|
|
280
295
|
const exists = await pathExists(skillFile);
|
|
281
296
|
if (!exists) {
|
|
282
297
|
throw ToolError.validationFailed(
|
|
@@ -34,8 +34,9 @@ async function saveProviderApiKey(provider, apiKey, startPath) {
|
|
|
34
34
|
if (!apiKey || !apiKey.trim()) throw new Error("apiKey is required");
|
|
35
35
|
const envVar = (0, import_api_key_resolver.getPrimaryApiKeyEnvVar)(provider);
|
|
36
36
|
const targetEnvPath = (0, import_path.getDextoEnvPath)(startPath);
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const trimmedKey = apiKey.trim();
|
|
38
|
+
await (0, import_env_file.updateEnvFile)(targetEnvPath, { [envVar]: trimmedKey });
|
|
39
|
+
process.env[envVar] = trimmedKey;
|
|
39
40
|
return { envVar, targetEnvPath };
|
|
40
41
|
}
|
|
41
42
|
function getProviderKeyStatus(provider) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key-store.d.ts","sourceRoot":"","sources":["../../src/utils/api-key-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAI7D;;;GAGG;AACH,wBAAsB,kBAAkB,CACpC,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"api-key-store.d.ts","sourceRoot":"","sources":["../../src/utils/api-key-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAI7D;;;GAGG;AACH,wBAAsB,kBAAkB,CACpC,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAapD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,WAAW,GAAG;IACzD,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAClB,CA4CA;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAM9F;AAED;;;GAGG;AACH,eAAO,MAAM,wBAAwB,6CAA8C,CAAC;AAEpF,MAAM,MAAM,qBAAqB,GAAG;IAChC,6DAA6D;IAC7D,oBAAoB,EAAE,OAAO,CAAC;IAC9B,gEAAgE;IAChE,cAAc,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAClC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,cAAc,EAAE,OAAO,EACvB,mBAAmB,EAAE,MAAM,GAAG,SAAS,GACxC,qBAAqB,CA2BvB"}
|
|
@@ -7,8 +7,9 @@ async function saveProviderApiKey(provider, apiKey, startPath) {
|
|
|
7
7
|
if (!apiKey || !apiKey.trim()) throw new Error("apiKey is required");
|
|
8
8
|
const envVar = getPrimaryApiKeyEnvVar(provider);
|
|
9
9
|
const targetEnvPath = getDextoEnvPath(startPath);
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const trimmedKey = apiKey.trim();
|
|
11
|
+
await updateEnvFile(targetEnvPath, { [envVar]: trimmedKey });
|
|
12
|
+
process.env[envVar] = trimmedKey;
|
|
12
13
|
return { envVar, targetEnvPath };
|
|
13
14
|
}
|
|
14
15
|
function getProviderKeyStatus(provider) {
|
package/dist/utils/env-file.cjs
CHANGED
|
@@ -32,8 +32,29 @@ __export(env_file_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(env_file_exports);
|
|
34
34
|
var path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_core = require("@dexto/core");
|
|
35
36
|
var import_node_fs = require("node:fs");
|
|
36
|
-
|
|
37
|
+
function validateUpdates(requested) {
|
|
38
|
+
const updates = {};
|
|
39
|
+
for (const [key, rawValue] of Object.entries(requested)) {
|
|
40
|
+
if (!/^[A-Z_][A-Z0-9_]*$/.test(key)) {
|
|
41
|
+
throw new Error(`Invalid environment variable name: ${key}`);
|
|
42
|
+
}
|
|
43
|
+
const value = rawValue.trim();
|
|
44
|
+
if (/[\r\n]/.test(value)) {
|
|
45
|
+
throw new import_core.DextoRuntimeError(
|
|
46
|
+
"env_value_multiline",
|
|
47
|
+
import_core.ErrorScope.CONFIG,
|
|
48
|
+
import_core.ErrorType.USER,
|
|
49
|
+
`Environment variable ${key} must be a single line`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
updates[key] = value;
|
|
53
|
+
}
|
|
54
|
+
return updates;
|
|
55
|
+
}
|
|
56
|
+
async function updateEnvFile(envFilePath, requested) {
|
|
57
|
+
const updates = validateUpdates(requested);
|
|
37
58
|
await import_node_fs.promises.mkdir(path.dirname(envFilePath), { recursive: true });
|
|
38
59
|
let content = "";
|
|
39
60
|
try {
|
|
@@ -62,7 +83,8 @@ async function updateEnvFile(envFilePath, updates) {
|
|
|
62
83
|
if (updatedLines[updatedLines.length - 1] !== "") {
|
|
63
84
|
updatedLines.push("");
|
|
64
85
|
}
|
|
65
|
-
await import_node_fs.promises.writeFile(envFilePath, updatedLines.join("\n"), "utf8");
|
|
86
|
+
await import_node_fs.promises.writeFile(envFilePath, updatedLines.join("\n"), { encoding: "utf8", mode: 384 });
|
|
87
|
+
await import_node_fs.promises.chmod(envFilePath, 384);
|
|
66
88
|
}
|
|
67
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68
90
|
0 && (module.exports = {
|
package/dist/utils/env-file.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Update a .env file with the provided key-value pairs.
|
|
3
|
-
* Existing keys are updated in place, new keys are appended.
|
|
3
|
+
* Existing keys are updated in place, new keys are appended. Values are trimmed and must be
|
|
4
|
+
* single-line. The file holds secrets, so it is kept readable by its owner only.
|
|
4
5
|
*/
|
|
5
|
-
export declare function updateEnvFile(envFilePath: string,
|
|
6
|
+
export declare function updateEnvFile(envFilePath: string, requested: Record<string, string>): Promise<void>;
|
|
6
7
|
//# sourceMappingURL=env-file.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-file.d.ts","sourceRoot":"","sources":["../../src/utils/env-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env-file.d.ts","sourceRoot":"","sources":["../../src/utils/env-file.ts"],"names":[],"mappings":"AA6BA;;;;GAIG;AACH,wBAAsB,aAAa,CAC/B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,IAAI,CAAC,CA6Cf"}
|
package/dist/utils/env-file.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
|
+
import { DextoRuntimeError, ErrorScope, ErrorType } from "@dexto/core";
|
|
2
3
|
import { promises as fs } from "node:fs";
|
|
3
|
-
|
|
4
|
+
function validateUpdates(requested) {
|
|
5
|
+
const updates = {};
|
|
6
|
+
for (const [key, rawValue] of Object.entries(requested)) {
|
|
7
|
+
if (!/^[A-Z_][A-Z0-9_]*$/.test(key)) {
|
|
8
|
+
throw new Error(`Invalid environment variable name: ${key}`);
|
|
9
|
+
}
|
|
10
|
+
const value = rawValue.trim();
|
|
11
|
+
if (/[\r\n]/.test(value)) {
|
|
12
|
+
throw new DextoRuntimeError(
|
|
13
|
+
"env_value_multiline",
|
|
14
|
+
ErrorScope.CONFIG,
|
|
15
|
+
ErrorType.USER,
|
|
16
|
+
`Environment variable ${key} must be a single line`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
updates[key] = value;
|
|
20
|
+
}
|
|
21
|
+
return updates;
|
|
22
|
+
}
|
|
23
|
+
async function updateEnvFile(envFilePath, requested) {
|
|
24
|
+
const updates = validateUpdates(requested);
|
|
4
25
|
await fs.mkdir(path.dirname(envFilePath), { recursive: true });
|
|
5
26
|
let content = "";
|
|
6
27
|
try {
|
|
@@ -29,7 +50,8 @@ async function updateEnvFile(envFilePath, updates) {
|
|
|
29
50
|
if (updatedLines[updatedLines.length - 1] !== "") {
|
|
30
51
|
updatedLines.push("");
|
|
31
52
|
}
|
|
32
|
-
await fs.writeFile(envFilePath, updatedLines.join("\n"), "utf8");
|
|
53
|
+
await fs.writeFile(envFilePath, updatedLines.join("\n"), { encoding: "utf8", mode: 384 });
|
|
54
|
+
await fs.chmod(envFilePath, 384);
|
|
33
55
|
}
|
|
34
56
|
export {
|
|
35
57
|
updateEnvFile
|
package/dist/utils/path.cjs
CHANGED
|
@@ -36,11 +36,13 @@ __export(path_exports, {
|
|
|
36
36
|
getDextoPackageRoot: () => getDextoPackageRoot,
|
|
37
37
|
getDextoPath: () => getDextoPath,
|
|
38
38
|
isPath: () => isPath,
|
|
39
|
-
resolveBundledScript: () => resolveBundledScript
|
|
39
|
+
resolveBundledScript: () => resolveBundledScript,
|
|
40
|
+
resolvesInside: () => resolvesInside
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(path_exports);
|
|
42
43
|
var path = __toESM(require("path"), 1);
|
|
43
44
|
var import_fs = require("fs");
|
|
45
|
+
var import_promises = require("fs/promises");
|
|
44
46
|
var import_fs2 = require("fs");
|
|
45
47
|
var import_os = require("os");
|
|
46
48
|
var import_module = require("module");
|
|
@@ -100,17 +102,78 @@ function getDextoGlobalPath(type, filename) {
|
|
|
100
102
|
const basePath = path.join((0, import_os.homedir)(), ".dexto", type);
|
|
101
103
|
return filename ? path.join(basePath, filename) : basePath;
|
|
102
104
|
}
|
|
105
|
+
function isInside(root, candidate) {
|
|
106
|
+
const relative = path.relative(root, candidate);
|
|
107
|
+
return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
108
|
+
}
|
|
109
|
+
async function resolvesInside(root, candidate) {
|
|
110
|
+
try {
|
|
111
|
+
const [physicalRoot, physicalCandidate] = await Promise.all([
|
|
112
|
+
import_fs2.promises.realpath(root),
|
|
113
|
+
import_fs2.promises.realpath(candidate)
|
|
114
|
+
]);
|
|
115
|
+
return isInside(physicalRoot, physicalCandidate);
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
103
120
|
async function copyDirectory(src, dest) {
|
|
104
|
-
await import_fs2.promises.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
121
|
+
if ((await import_fs2.promises.lstat(src)).isSymbolicLink()) {
|
|
122
|
+
throw new Error(`Refusing to copy ${src}: the source directory is a symbolic link`);
|
|
123
|
+
}
|
|
124
|
+
const rootReal = await import_fs2.promises.realpath(src);
|
|
125
|
+
await copyDirectoryWithin(src, dest, rootReal);
|
|
126
|
+
}
|
|
127
|
+
const { O_RDONLY, O_DIRECTORY = 0, O_NOFOLLOW = 0, O_NONBLOCK = 0 } = import_promises.constants;
|
|
128
|
+
async function assertOpenedIsInside(opened, target, root) {
|
|
129
|
+
const sameAsOpened = (named) => named.isDirectory() === opened.isDirectory() && named.isFile() === opened.isFile() && named.dev === opened.dev && named.ino === opened.ino;
|
|
130
|
+
const before = await import_fs2.promises.lstat(target, { bigint: true });
|
|
131
|
+
const resolved = await import_fs2.promises.realpath(target);
|
|
132
|
+
const after = await import_fs2.promises.lstat(target, { bigint: true });
|
|
133
|
+
if (!sameAsOpened(before) || !sameAsOpened(after) || !isInside(root, resolved)) {
|
|
134
|
+
throw new Error(`Refusing to copy ${target}: it changed while it was being copied`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function copyDirectoryWithin(src, dest, rootReal) {
|
|
138
|
+
const handle = process.platform === "win32" ? void 0 : await import_fs2.promises.open(src, O_RDONLY | O_DIRECTORY | O_NOFOLLOW);
|
|
139
|
+
try {
|
|
140
|
+
const opened = handle ? await handle.stat({ bigint: true }) : await import_fs2.promises.lstat(src, { bigint: true });
|
|
141
|
+
await assertOpenedIsInside(opened, src, rootReal);
|
|
142
|
+
await import_fs2.promises.mkdir(dest, { recursive: true });
|
|
143
|
+
const names = await import_fs2.promises.readdir(src);
|
|
144
|
+
await assertOpenedIsInside(opened, src, rootReal);
|
|
145
|
+
for (const name of names) {
|
|
146
|
+
const srcPath = path.join(src, name);
|
|
147
|
+
const destPath = path.join(dest, name);
|
|
148
|
+
const entry = await import_fs2.promises.lstat(srcPath);
|
|
149
|
+
if (entry.isSymbolicLink()) {
|
|
150
|
+
const target = await import_fs2.promises.realpath(srcPath).catch(() => void 0);
|
|
151
|
+
if (target === void 0 || !isInside(rootReal, target)) continue;
|
|
152
|
+
if (!(await import_fs2.promises.stat(target)).isFile()) continue;
|
|
153
|
+
await copyFileWithin(target, destPath, rootReal);
|
|
154
|
+
} else if (entry.isDirectory()) {
|
|
155
|
+
await copyDirectoryWithin(srcPath, destPath, rootReal);
|
|
156
|
+
} else if (entry.isFile()) {
|
|
157
|
+
await copyFileWithin(srcPath, destPath, rootReal);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
await assertOpenedIsInside(opened, src, rootReal);
|
|
161
|
+
} finally {
|
|
162
|
+
await handle?.close();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async function copyFileWithin(src, dest, rootReal) {
|
|
166
|
+
const handle = await import_fs2.promises.open(src, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
167
|
+
try {
|
|
168
|
+
const opened = await handle.stat({ bigint: true });
|
|
169
|
+
if (!opened.isFile()) {
|
|
170
|
+
throw new Error(`Refusing to copy ${src}: it is no longer a regular file`);
|
|
113
171
|
}
|
|
172
|
+
await assertOpenedIsInside(opened, src, rootReal);
|
|
173
|
+
await import_fs2.promises.writeFile(dest, handle.createReadStream({ autoClose: false }));
|
|
174
|
+
await import_fs2.promises.chmod(dest, Number(opened.mode & 0o777n));
|
|
175
|
+
} finally {
|
|
176
|
+
await handle.close();
|
|
114
177
|
}
|
|
115
178
|
}
|
|
116
179
|
function isPath(str) {
|
|
@@ -216,5 +279,6 @@ function getDextoEnvPath(startPath = process.cwd()) {
|
|
|
216
279
|
getDextoPackageRoot,
|
|
217
280
|
getDextoPath,
|
|
218
281
|
isPath,
|
|
219
|
-
resolveBundledScript
|
|
282
|
+
resolveBundledScript,
|
|
283
|
+
resolvesInside
|
|
220
284
|
});
|
package/dist/utils/path.d.ts
CHANGED
|
@@ -31,7 +31,20 @@ export declare function getDextoPath(type: string, filename?: string, startPath?
|
|
|
31
31
|
*/
|
|
32
32
|
export declare function getDextoGlobalPath(type: string, filename?: string): string;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* True when `candidate` resolves, after following every link, to `root` or something inside it.
|
|
35
|
+
* A missing path or any resolution error counts as outside.
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolvesInside(root: string, candidate: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Copy entire directory recursively.
|
|
40
|
+
*
|
|
41
|
+
* Links are never followed out of the source, even if someone swaps one in while the copy runs:
|
|
42
|
+
* - The source itself must not be a link (it is refused).
|
|
43
|
+
* - A link that resolves outside `src` is skipped, a link to a directory is skipped, and a link
|
|
44
|
+
* to a file inside `src` is copied as a regular file.
|
|
45
|
+
* - Every directory is opened and checked before and after it is listed, and every file is opened
|
|
46
|
+
* and checked before it is read, so what is copied is what was checked. Any mismatch (a path
|
|
47
|
+
* that now points somewhere else or outside `src`) aborts the whole copy with an error.
|
|
35
48
|
* @param src Source directory path
|
|
36
49
|
* @param dest Destination directory path
|
|
37
50
|
*/
|
package/dist/utils/path.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAiBA;;;;;;GAMG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,SAAS,CAGxD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAuCxF;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAc1E;AAOD;;;GAGG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAUtF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO5E;AAiFD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAW3C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAKhF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAwD/D;AAED;;GAEG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAUhE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,CAkCzE"}
|
package/dist/utils/path.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { existsSync } from "fs";
|
|
3
|
+
import { constants as fsConstants } from "fs/promises";
|
|
3
4
|
import { promises as fs } from "fs";
|
|
4
5
|
import { homedir } from "os";
|
|
5
6
|
import { createRequire } from "module";
|
|
@@ -62,17 +63,78 @@ function getDextoGlobalPath(type, filename) {
|
|
|
62
63
|
const basePath = path.join(homedir(), ".dexto", type);
|
|
63
64
|
return filename ? path.join(basePath, filename) : basePath;
|
|
64
65
|
}
|
|
66
|
+
function isInside(root, candidate) {
|
|
67
|
+
const relative = path.relative(root, candidate);
|
|
68
|
+
return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
69
|
+
}
|
|
70
|
+
async function resolvesInside(root, candidate) {
|
|
71
|
+
try {
|
|
72
|
+
const [physicalRoot, physicalCandidate] = await Promise.all([
|
|
73
|
+
fs.realpath(root),
|
|
74
|
+
fs.realpath(candidate)
|
|
75
|
+
]);
|
|
76
|
+
return isInside(physicalRoot, physicalCandidate);
|
|
77
|
+
} catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
65
81
|
async function copyDirectory(src, dest) {
|
|
66
|
-
await fs.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
if ((await fs.lstat(src)).isSymbolicLink()) {
|
|
83
|
+
throw new Error(`Refusing to copy ${src}: the source directory is a symbolic link`);
|
|
84
|
+
}
|
|
85
|
+
const rootReal = await fs.realpath(src);
|
|
86
|
+
await copyDirectoryWithin(src, dest, rootReal);
|
|
87
|
+
}
|
|
88
|
+
const { O_RDONLY, O_DIRECTORY = 0, O_NOFOLLOW = 0, O_NONBLOCK = 0 } = fsConstants;
|
|
89
|
+
async function assertOpenedIsInside(opened, target, root) {
|
|
90
|
+
const sameAsOpened = (named) => named.isDirectory() === opened.isDirectory() && named.isFile() === opened.isFile() && named.dev === opened.dev && named.ino === opened.ino;
|
|
91
|
+
const before = await fs.lstat(target, { bigint: true });
|
|
92
|
+
const resolved = await fs.realpath(target);
|
|
93
|
+
const after = await fs.lstat(target, { bigint: true });
|
|
94
|
+
if (!sameAsOpened(before) || !sameAsOpened(after) || !isInside(root, resolved)) {
|
|
95
|
+
throw new Error(`Refusing to copy ${target}: it changed while it was being copied`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function copyDirectoryWithin(src, dest, rootReal) {
|
|
99
|
+
const handle = process.platform === "win32" ? void 0 : await fs.open(src, O_RDONLY | O_DIRECTORY | O_NOFOLLOW);
|
|
100
|
+
try {
|
|
101
|
+
const opened = handle ? await handle.stat({ bigint: true }) : await fs.lstat(src, { bigint: true });
|
|
102
|
+
await assertOpenedIsInside(opened, src, rootReal);
|
|
103
|
+
await fs.mkdir(dest, { recursive: true });
|
|
104
|
+
const names = await fs.readdir(src);
|
|
105
|
+
await assertOpenedIsInside(opened, src, rootReal);
|
|
106
|
+
for (const name of names) {
|
|
107
|
+
const srcPath = path.join(src, name);
|
|
108
|
+
const destPath = path.join(dest, name);
|
|
109
|
+
const entry = await fs.lstat(srcPath);
|
|
110
|
+
if (entry.isSymbolicLink()) {
|
|
111
|
+
const target = await fs.realpath(srcPath).catch(() => void 0);
|
|
112
|
+
if (target === void 0 || !isInside(rootReal, target)) continue;
|
|
113
|
+
if (!(await fs.stat(target)).isFile()) continue;
|
|
114
|
+
await copyFileWithin(target, destPath, rootReal);
|
|
115
|
+
} else if (entry.isDirectory()) {
|
|
116
|
+
await copyDirectoryWithin(srcPath, destPath, rootReal);
|
|
117
|
+
} else if (entry.isFile()) {
|
|
118
|
+
await copyFileWithin(srcPath, destPath, rootReal);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
await assertOpenedIsInside(opened, src, rootReal);
|
|
122
|
+
} finally {
|
|
123
|
+
await handle?.close();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async function copyFileWithin(src, dest, rootReal) {
|
|
127
|
+
const handle = await fs.open(src, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
128
|
+
try {
|
|
129
|
+
const opened = await handle.stat({ bigint: true });
|
|
130
|
+
if (!opened.isFile()) {
|
|
131
|
+
throw new Error(`Refusing to copy ${src}: it is no longer a regular file`);
|
|
75
132
|
}
|
|
133
|
+
await assertOpenedIsInside(opened, src, rootReal);
|
|
134
|
+
await fs.writeFile(dest, handle.createReadStream({ autoClose: false }));
|
|
135
|
+
await fs.chmod(dest, Number(opened.mode & 0o777n));
|
|
136
|
+
} finally {
|
|
137
|
+
await handle.close();
|
|
76
138
|
}
|
|
77
139
|
}
|
|
78
140
|
function isPath(str) {
|
|
@@ -177,5 +239,6 @@ export {
|
|
|
177
239
|
getDextoPackageRoot,
|
|
178
240
|
getDextoPath,
|
|
179
241
|
isPath,
|
|
180
|
-
resolveBundledScript
|
|
242
|
+
resolveBundledScript,
|
|
243
|
+
resolvesInside
|
|
181
244
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexto/agent-management",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"yaml": "^2.8.3",
|
|
24
24
|
"zod": "^4.3.6",
|
|
25
|
-
"@dexto/agent-config": "1.
|
|
26
|
-
"@dexto/core": "1.
|
|
27
|
-
"@dexto/llm": "1.
|
|
28
|
-
"@dexto/orchestration": "1.
|
|
29
|
-
"@dexto/tools-builtins": "1.
|
|
25
|
+
"@dexto/agent-config": "1.17.0",
|
|
26
|
+
"@dexto/core": "1.17.0",
|
|
27
|
+
"@dexto/llm": "1.17.0",
|
|
28
|
+
"@dexto/orchestration": "1.17.0",
|
|
29
|
+
"@dexto/tools-builtins": "1.17.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^22.13.5"
|