@yonpark/skillhub-cli 0.1.3 → 0.3.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.
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTransientError = isTransientError;
4
+ exports.retryAsync = retryAsync;
5
+ const DEFAULT_MAX_ATTEMPTS = 3;
6
+ const DEFAULT_INITIAL_DELAY_MS = 300;
7
+ const DEFAULT_FACTOR = 3;
8
+ const TRANSIENT_ERROR_CODES = new Set([
9
+ "ECONNRESET",
10
+ "ECONNREFUSED",
11
+ "ETIMEDOUT",
12
+ "EAI_AGAIN",
13
+ "ENOTFOUND",
14
+ "ESOCKETTIMEDOUT",
15
+ "ERR_SOCKET_CONNECTION_TIMEOUT",
16
+ "ABORT_ERR",
17
+ "ERR_STREAM_PREMATURE_CLOSE",
18
+ ]);
19
+ function sleep(ms) {
20
+ return new Promise((resolve) => {
21
+ setTimeout(resolve, ms);
22
+ });
23
+ }
24
+ function getErrorMessage(error) {
25
+ if (error instanceof Error) {
26
+ return error.message;
27
+ }
28
+ return String(error);
29
+ }
30
+ function isTransientError(error) {
31
+ const candidate = error;
32
+ if (typeof candidate.status === "number") {
33
+ return candidate.status === 429 || candidate.status >= 500;
34
+ }
35
+ if (candidate.code && TRANSIENT_ERROR_CODES.has(candidate.code)) {
36
+ return true;
37
+ }
38
+ const message = `${candidate.message ?? ""}`.toLowerCase();
39
+ return (message.includes("timeout") ||
40
+ message.includes("timed out") ||
41
+ message.includes("network") ||
42
+ message.includes("socket hang up") ||
43
+ message.includes("temporarily unavailable") ||
44
+ message.includes("econnreset"));
45
+ }
46
+ async function retryAsync(fn, options = {}) {
47
+ const maxAttempts = options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
48
+ const initialDelayMs = options.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;
49
+ const factor = options.factor ?? DEFAULT_FACTOR;
50
+ const shouldRetry = options.shouldRetry ?? isTransientError;
51
+ let delayMs = initialDelayMs;
52
+ let lastError;
53
+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
54
+ try {
55
+ return await fn();
56
+ }
57
+ catch (error) {
58
+ lastError = error;
59
+ const canRetry = attempt < maxAttempts && shouldRetry(error);
60
+ if (!canRetry) {
61
+ const labelPrefix = options.label ? `${options.label} failed` : "Operation failed";
62
+ throw new Error(`${labelPrefix} after ${attempt} attempt(s): ${getErrorMessage(error)}`);
63
+ }
64
+ await sleep(delayMs);
65
+ delayMs *= factor;
66
+ }
67
+ }
68
+ throw new Error(getErrorMessage(lastError));
69
+ }
package/package.json CHANGED
@@ -1,48 +1,55 @@
1
- {
2
- "name": "@yonpark/skillhub-cli",
3
- "version": "0.1.3",
4
- "description": "SkillHub CLI - sync skills with GitHub Gist",
5
- "bin": {
6
- "skillhub": "bin/skillhub.js"
7
- },
8
- "main": "dist/index.js",
9
- "type": "commonjs",
10
- "scripts": {
11
- "build": "tsc && tsc-alias",
12
- "start": "node dist/index.js",
13
- "prepare": "npm run build"
14
- },
15
- "files": [
16
- "dist",
17
- "bin",
18
- "README.md"
19
- ],
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/yw9142/skillhub-cli.git"
23
- },
24
- "keywords": [
25
- "cli",
26
- "skills",
27
- "agent",
28
- "gist",
29
- "sync"
30
- ],
31
- "author": "",
32
- "license": "MIT",
33
- "engines": {
34
- "node": ">=18.0.0"
35
- },
36
- "dependencies": {
37
- "@octokit/rest": "^20.0.2",
38
- "commander": "^11.1.0",
39
- "conf": "^12.0.0",
40
- "inquirer": "^9.2.12"
41
- },
42
- "devDependencies": {
43
- "@types/node": "^20.11.10",
44
- "@types/inquirer": "^9.0.7",
45
- "tsc-alias": "^1.8.8",
46
- "typescript": "^5.3.3"
47
- }
48
- }
1
+ {
2
+ "name": "@yonpark/skillhub-cli",
3
+ "version": "0.3.0",
4
+ "description": "SkillHub CLI - sync skills with GitHub Gist",
5
+ "bin": {
6
+ "skillhub": "bin/skillhub.js"
7
+ },
8
+ "main": "dist/index.js",
9
+ "type": "commonjs",
10
+ "scripts": {
11
+ "build": "tsc && tsc-alias",
12
+ "prepare": "npm run build",
13
+ "test": "vitest",
14
+ "test:watch": "vitest --watch",
15
+ "test:ci": "vitest run",
16
+ "changeset": "changeset",
17
+ "version-packages": "changeset version",
18
+ "release": "changeset publish --access public"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "bin",
23
+ "README.md"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/yw9142/skillhub-cli.git"
28
+ },
29
+ "keywords": [
30
+ "cli",
31
+ "skills",
32
+ "agent",
33
+ "gist",
34
+ "sync"
35
+ ],
36
+ "author": "",
37
+ "license": "MIT",
38
+ "engines": {
39
+ "node": ">=18.0.0"
40
+ },
41
+ "dependencies": {
42
+ "@octokit/rest": "^20.0.2",
43
+ "commander": "^11.1.0",
44
+ "conf": "^12.0.0",
45
+ "inquirer": "^9.2.12"
46
+ },
47
+ "devDependencies": {
48
+ "@changesets/cli": "^2.29.7",
49
+ "@types/inquirer": "^9.0.7",
50
+ "@types/node": "^20.11.10",
51
+ "tsc-alias": "^1.8.8",
52
+ "typescript": "^5.3.3",
53
+ "vitest": "^2.1.8"
54
+ }
55
+ }