openclaw-packager 0.1.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,193 @@
1
+ "use strict";
2
+ /**
3
+ * Secret detection and stripping for openclaw-packager
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isSecretFile = isSecretFile;
7
+ exports.stripSecrets = stripSecrets;
8
+ exports.createSecretsTemplate = createSecretsTemplate;
9
+ exports.addConfigSecret = addConfigSecret;
10
+ exports.addCredentialFile = addCredentialFile;
11
+ exports.addAgentAuth = addAgentAuth;
12
+ /**
13
+ * Keys that typically contain secrets
14
+ */
15
+ const SECRET_KEYS = new Set([
16
+ 'token',
17
+ 'tokens',
18
+ 'key',
19
+ 'apiKey',
20
+ 'api_key',
21
+ 'apikey',
22
+ 'secret',
23
+ 'password',
24
+ 'credential',
25
+ 'credentials',
26
+ 'auth',
27
+ 'authorization',
28
+ 'accessToken',
29
+ 'access_token',
30
+ 'refreshToken',
31
+ 'refresh_token',
32
+ 'privateKey',
33
+ 'private_key',
34
+ 'clientSecret',
35
+ 'client_secret',
36
+ 'botToken',
37
+ 'bot_token',
38
+ 'webhook',
39
+ 'webhookUrl',
40
+ ]);
41
+ /**
42
+ * Patterns that indicate a value is a secret
43
+ */
44
+ const SECRET_PATTERNS = [
45
+ /^ghu_[a-zA-Z0-9]+$/, // GitHub user token
46
+ /^ghp_[a-zA-Z0-9]+$/, // GitHub personal token
47
+ /^gho_[a-zA-Z0-9]+$/, // GitHub OAuth token
48
+ /^ghs_[a-zA-Z0-9]+$/, // GitHub server token
49
+ /^sk-[a-zA-Z0-9]+$/, // OpenAI/Stripe keys
50
+ /^xoxb-[a-zA-Z0-9-]+$/, // Slack bot token
51
+ /^xoxp-[a-zA-Z0-9-]+$/, // Slack user token
52
+ /^Bearer\s+[a-zA-Z0-9._-]+$/i, // Bearer tokens
53
+ /^[A-Za-z0-9+/]{60,}={0,2}$/, // Base64 blobs > 60 chars
54
+ ];
55
+ /**
56
+ * Files that should be entirely treated as containing secrets
57
+ */
58
+ const SECRET_FILE_PATTERNS = [
59
+ /^credentials\//,
60
+ /auth-profiles\.json$/,
61
+ /token\.json$/,
62
+ /_token\.json$/,
63
+ /secret\.json$/,
64
+ /_secret\.json$/,
65
+ ];
66
+ /**
67
+ * Check if a file path indicates it contains secrets
68
+ */
69
+ function isSecretFile(relativePath) {
70
+ const normalized = relativePath.replace(/\\/g, '/');
71
+ return SECRET_FILE_PATTERNS.some(pattern => pattern.test(normalized));
72
+ }
73
+ /**
74
+ * Check if a key name suggests it contains secrets
75
+ */
76
+ function isSecretKey(key) {
77
+ const lowerKey = key.toLowerCase();
78
+ return SECRET_KEYS.has(lowerKey) ||
79
+ SECRET_KEYS.has(key) ||
80
+ lowerKey.includes('token') ||
81
+ lowerKey.includes('secret') ||
82
+ lowerKey.includes('password') ||
83
+ lowerKey.includes('apikey') ||
84
+ lowerKey.includes('api_key');
85
+ }
86
+ /**
87
+ * Check if a value looks like a secret
88
+ */
89
+ function isSecretValue(value) {
90
+ if (typeof value !== 'string') {
91
+ return false;
92
+ }
93
+ // Check against known patterns
94
+ for (const pattern of SECRET_PATTERNS) {
95
+ if (pattern.test(value)) {
96
+ return true;
97
+ }
98
+ }
99
+ // Long random-looking strings (likely tokens)
100
+ if (value.length > 40 && /^[a-zA-Z0-9+/=_-]+$/.test(value)) {
101
+ return true;
102
+ }
103
+ return false;
104
+ }
105
+ /**
106
+ * Recursively strip secrets from a JSON object
107
+ */
108
+ function stripSecretsFromObject(obj, parentKey, stripped) {
109
+ if (obj === null || obj === undefined) {
110
+ return obj;
111
+ }
112
+ if (Array.isArray(obj)) {
113
+ return obj.map((item, i) => stripSecretsFromObject(item, `${parentKey}[${i}]`, stripped));
114
+ }
115
+ if (typeof obj === 'object') {
116
+ const result = {};
117
+ for (const [key, value] of Object.entries(obj)) {
118
+ const fullKey = parentKey ? `${parentKey}.${key}` : key;
119
+ if (typeof value === 'string') {
120
+ if (isSecretKey(key) || isSecretValue(value)) {
121
+ result[key] = `__OPENCLAW_SECRET__:${key}`;
122
+ stripped.add(fullKey);
123
+ }
124
+ else {
125
+ result[key] = value;
126
+ }
127
+ }
128
+ else {
129
+ result[key] = stripSecretsFromObject(value, fullKey, stripped);
130
+ }
131
+ }
132
+ return result;
133
+ }
134
+ return obj;
135
+ }
136
+ /**
137
+ * Strip secrets from JSON content
138
+ */
139
+ function stripSecrets(content, filePath) {
140
+ try {
141
+ const parsed = JSON.parse(content);
142
+ const stripped = new Set();
143
+ const result = stripSecretsFromObject(parsed, '', stripped);
144
+ return {
145
+ content: JSON.stringify(result, null, 2),
146
+ secretsStripped: stripped.size,
147
+ };
148
+ }
149
+ catch {
150
+ // Not valid JSON, return as-is
151
+ return {
152
+ content,
153
+ secretsStripped: 0,
154
+ };
155
+ }
156
+ }
157
+ /**
158
+ * Create an empty secrets template
159
+ */
160
+ function createSecretsTemplate() {
161
+ return {
162
+ _instructions: 'Fill in these values on your new machine. These secrets were stripped for security.',
163
+ config: {},
164
+ credentials: [],
165
+ agentAuth: {},
166
+ };
167
+ }
168
+ /**
169
+ * Add a config secret to the template
170
+ */
171
+ function addConfigSecret(template, path) {
172
+ template.config[path] = '__OPENCLAW_SECRET__';
173
+ }
174
+ /**
175
+ * Add a credential file to the template
176
+ */
177
+ function addCredentialFile(template, filename) {
178
+ if (!template.credentials.includes(filename)) {
179
+ template.credentials.push(filename);
180
+ }
181
+ }
182
+ /**
183
+ * Add an agent auth entry to the template
184
+ */
185
+ function addAgentAuth(template, agent, authType) {
186
+ if (!template.agentAuth[agent]) {
187
+ template.agentAuth[agent] = [];
188
+ }
189
+ if (!template.agentAuth[agent].includes(authType)) {
190
+ template.agentAuth[agent].push(authType);
191
+ }
192
+ }
193
+ //# sourceMappingURL=secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA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,CAAC;IAAC,MAAM,CAAC;QACP,+BAA+B;QAC/B,OAAO;YACL,OAAO;YACP,eAAe,EAAE,CAAC;SACnB,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB;IACnC,OAAO;QACL,aAAa,EAAE,qFAAqF;QACpG,MAAM,EAAE,EAAE;QACV,WAAW,EAAE,EAAE;QACf,SAAS,EAAE,EAAE;KACd,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,QAAyB,EAAE,IAAY;IACrE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,qBAAqB,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,QAAyB,EAAE,QAAgB;IAC3E,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7C,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,QAAyB,EAAE,KAAa,EAAE,QAAgB;IACrF,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClD,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Shared utilities for openclaw-packager
3
+ */
4
+ import * as fs from 'fs';
5
+ /**
6
+ * Logger that respects stdout mode (no console output when piping to stdout)
7
+ */
8
+ export declare class Logger {
9
+ private stdoutMode;
10
+ constructor(stdoutMode?: boolean);
11
+ log(...args: unknown[]): void;
12
+ error(...args: unknown[]): void;
13
+ info(message: string): void;
14
+ success(message: string): void;
15
+ warn(message: string): void;
16
+ heading(message: string): void;
17
+ }
18
+ /**
19
+ * Recursively walk a directory
20
+ */
21
+ export declare function walkDir(dir: string, relativeTo?: string): AsyncGenerator<{
22
+ path: string;
23
+ relativePath: string;
24
+ stats: fs.Stats;
25
+ }>;
26
+ /**
27
+ * Count files and total size in a directory
28
+ */
29
+ export declare function countDirContents(dir: string, filter?: (path: string) => boolean): {
30
+ files: number;
31
+ size: number;
32
+ };
33
+ /**
34
+ * Ensure a directory exists
35
+ */
36
+ export declare function ensureDir(dir: string): void;
37
+ /**
38
+ * Read JSON file safely
39
+ */
40
+ export declare function readJson<T = unknown>(filePath: string): T | null;
41
+ /**
42
+ * Write JSON file
43
+ */
44
+ export declare function writeJson(filePath: string, data: unknown): void;
45
+ /**
46
+ * Get timestamp for filenames
47
+ */
48
+ export declare function getTimestamp(): string;
49
+ /**
50
+ * Print a table (simple key-value format)
51
+ */
52
+ export declare function printTable(logger: Logger, items: [string, string | number | boolean][]): void;
53
+ /**
54
+ * Deep merge two objects
55
+ */
56
+ export declare function deepMerge<T extends Record<string, unknown>>(target: T, source: Partial<T>, sourceWins?: boolean): T;
package/dist/utils.js ADDED
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ /**
3
+ * Shared utilities for openclaw-packager
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.Logger = void 0;
43
+ exports.walkDir = walkDir;
44
+ exports.countDirContents = countDirContents;
45
+ exports.ensureDir = ensureDir;
46
+ exports.readJson = readJson;
47
+ exports.writeJson = writeJson;
48
+ exports.getTimestamp = getTimestamp;
49
+ exports.printTable = printTable;
50
+ exports.deepMerge = deepMerge;
51
+ const fs = __importStar(require("fs"));
52
+ const path = __importStar(require("path"));
53
+ const chalk_1 = __importDefault(require("chalk"));
54
+ /**
55
+ * Logger that respects stdout mode (no console output when piping to stdout)
56
+ */
57
+ class Logger {
58
+ stdoutMode;
59
+ constructor(stdoutMode = false) {
60
+ this.stdoutMode = stdoutMode;
61
+ }
62
+ log(...args) {
63
+ if (!this.stdoutMode) {
64
+ console.log(...args);
65
+ }
66
+ }
67
+ error(...args) {
68
+ // Always write errors to stderr
69
+ console.error(...args);
70
+ }
71
+ info(message) {
72
+ this.log(chalk_1.default.blue('ℹ'), message);
73
+ }
74
+ success(message) {
75
+ this.log(chalk_1.default.green('✓'), message);
76
+ }
77
+ warn(message) {
78
+ this.log(chalk_1.default.yellow('⚠'), message);
79
+ }
80
+ heading(message) {
81
+ this.log(chalk_1.default.bold.cyan(`\n${message}`));
82
+ }
83
+ }
84
+ exports.Logger = Logger;
85
+ /**
86
+ * Recursively walk a directory
87
+ */
88
+ async function* walkDir(dir, relativeTo) {
89
+ const base = relativeTo || dir;
90
+ let entries;
91
+ try {
92
+ entries = fs.readdirSync(dir, { withFileTypes: true });
93
+ }
94
+ catch {
95
+ return;
96
+ }
97
+ for (const entry of entries) {
98
+ const fullPath = path.join(dir, entry.name);
99
+ const relativePath = path.relative(base, fullPath);
100
+ if (entry.isDirectory()) {
101
+ yield* walkDir(fullPath, base);
102
+ }
103
+ else if (entry.isFile()) {
104
+ try {
105
+ const stats = fs.statSync(fullPath);
106
+ yield { path: fullPath, relativePath, stats };
107
+ }
108
+ catch {
109
+ // Skip files we can't stat
110
+ }
111
+ }
112
+ }
113
+ }
114
+ /**
115
+ * Count files and total size in a directory
116
+ */
117
+ function countDirContents(dir, filter) {
118
+ let files = 0;
119
+ let size = 0;
120
+ const walk = (currentDir) => {
121
+ try {
122
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
123
+ for (const entry of entries) {
124
+ const fullPath = path.join(currentDir, entry.name);
125
+ const relativePath = path.relative(dir, fullPath);
126
+ if (filter && !filter(relativePath)) {
127
+ continue;
128
+ }
129
+ if (entry.isDirectory()) {
130
+ walk(fullPath);
131
+ }
132
+ else if (entry.isFile()) {
133
+ try {
134
+ const stats = fs.statSync(fullPath);
135
+ files++;
136
+ size += stats.size;
137
+ }
138
+ catch {
139
+ // Skip
140
+ }
141
+ }
142
+ }
143
+ }
144
+ catch {
145
+ // Skip
146
+ }
147
+ };
148
+ walk(dir);
149
+ return { files, size };
150
+ }
151
+ /**
152
+ * Ensure a directory exists
153
+ */
154
+ function ensureDir(dir) {
155
+ if (!fs.existsSync(dir)) {
156
+ fs.mkdirSync(dir, { recursive: true });
157
+ }
158
+ }
159
+ /**
160
+ * Read JSON file safely
161
+ */
162
+ function readJson(filePath) {
163
+ try {
164
+ const content = fs.readFileSync(filePath, 'utf-8');
165
+ return JSON.parse(content);
166
+ }
167
+ catch {
168
+ return null;
169
+ }
170
+ }
171
+ /**
172
+ * Write JSON file
173
+ */
174
+ function writeJson(filePath, data) {
175
+ const dir = path.dirname(filePath);
176
+ ensureDir(dir);
177
+ fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
178
+ }
179
+ /**
180
+ * Get timestamp for filenames
181
+ */
182
+ function getTimestamp() {
183
+ const now = new Date();
184
+ return now.toISOString()
185
+ .replace(/[:.]/g, '-')
186
+ .replace('T', '_')
187
+ .slice(0, 19);
188
+ }
189
+ /**
190
+ * Print a table (simple key-value format)
191
+ */
192
+ function printTable(logger, items) {
193
+ const maxKey = Math.max(...items.map(([k]) => k.length));
194
+ for (const [key, value] of items) {
195
+ logger.log(` ${chalk_1.default.dim(key.padEnd(maxKey))} ${value}`);
196
+ }
197
+ }
198
+ /**
199
+ * Deep merge two objects
200
+ */
201
+ function deepMerge(target, source, sourceWins = false) {
202
+ const result = { ...target };
203
+ for (const key of Object.keys(source)) {
204
+ const sourceVal = source[key];
205
+ const targetVal = target[key];
206
+ if (sourceVal === undefined) {
207
+ continue;
208
+ }
209
+ if (typeof sourceVal === 'object' &&
210
+ sourceVal !== null &&
211
+ !Array.isArray(sourceVal) &&
212
+ typeof targetVal === 'object' &&
213
+ targetVal !== null &&
214
+ !Array.isArray(targetVal)) {
215
+ result[key] = deepMerge(targetVal, sourceVal, sourceWins);
216
+ }
217
+ else if (sourceWins || targetVal === undefined) {
218
+ result[key] = sourceVal;
219
+ }
220
+ }
221
+ return result;
222
+ }
223
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CH,0BA6BC;AAKD,4CAqCC;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SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAE9B,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,SAAS;QACX,CAAC;QAED,IACE,OAAO,SAAS,KAAK,QAAQ;YAC7B,SAAS,KAAK,IAAI;YAClB,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;YACzB,OAAO,SAAS,KAAK,QAAQ;YAC7B,SAAS,KAAK,IAAI;YAClB,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EACzB,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CACrB,SAAoC,EACpC,SAAoC,EACpC,UAAU,CACG,CAAC;QAClB,CAAC;aAAM,IAAI,UAAU,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YACjD,MAAM,CAAC,GAAG,CAAC,GAAG,SAAuB,CAAC;QACxC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "openclaw-packager",
3
+ "version": "0.1.0",
4
+ "description": "Export and import OpenClaw bot configurations",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "openclaw-packager": "./dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "keywords": [
14
+ "openclaw",
15
+ "backup",
16
+ "export",
17
+ "import",
18
+ "cli"
19
+ ],
20
+ "author": "",
21
+ "license": "MIT",
22
+ "type": "commonjs",
23
+ "engines": {
24
+ "node": ">=18.0.0"
25
+ },
26
+ "files": [
27
+ "dist/"
28
+ ],
29
+ "devDependencies": {
30
+ "@types/adm-zip": "^0.5.7",
31
+ "@types/archiver": "^7.0.0",
32
+ "@types/node": "^20.0.0",
33
+ "typescript": "^5.0.0"
34
+ },
35
+ "dependencies": {
36
+ "adm-zip": "^0.5.0",
37
+ "archiver": "^7.0.0",
38
+ "chalk": "^4.1.2",
39
+ "commander": "^12.0.0"
40
+ }
41
+ }