agentdock-cli 0.4.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,160 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveFrom = resolveFrom;
7
+ exports.safeResolveWithin = safeResolveWithin;
8
+ exports.acquireLock = acquireLock;
9
+ exports.releaseLock = releaseLock;
10
+ exports.ensureDirectory = ensureDirectory;
11
+ exports.copyFileSafe = copyFileSafe;
12
+ exports.writeTextFile = writeTextFile;
13
+ exports.copyDirectoryFiltered = copyDirectoryFiltered;
14
+ exports.copyDirectorySafe = copyDirectorySafe;
15
+ exports.pathExists = pathExists;
16
+ exports.readJsonFile = readJsonFile;
17
+ exports.writeJsonFile = writeJsonFile;
18
+ const promises_1 = __importDefault(require("node:fs/promises"));
19
+ const node_path_1 = __importDefault(require("node:path"));
20
+ const minimatch_1 = require("minimatch");
21
+ function resolveFrom(baseDir, targetPath) {
22
+ return node_path_1.default.resolve(baseDir, targetPath);
23
+ }
24
+ /**
25
+ * Resolve `relativeTarget` against `root` and assert the result stays within `root`.
26
+ * Throws PATH_ESCAPE if it would escape (e.g. destination: ../../../etc/x). Blocks path traversal.
27
+ */
28
+ function safeResolveWithin(root, relativeTarget, label = 'path') {
29
+ const resolvedRoot = node_path_1.default.resolve(root);
30
+ const resolved = node_path_1.default.resolve(resolvedRoot, relativeTarget);
31
+ const inside = resolved === resolvedRoot || resolved.startsWith(resolvedRoot + node_path_1.default.sep);
32
+ if (!inside) {
33
+ throw new Error(`PATH_ESCAPE: ${label} resolves outside the allowed root: ${relativeTarget}`);
34
+ }
35
+ return resolved;
36
+ }
37
+ /**
38
+ * Acquire an exclusive lock file (O_EXCL). Retries until timeout, then throws LOCK_TIMEOUT.
39
+ * Caller MUST call releaseLock in a finally block.
40
+ */
41
+ async function acquireLock(lockPath, timeoutMs = 10000, retryMs = 200) {
42
+ const deadline = Date.now() + timeoutMs;
43
+ for (;;) {
44
+ try {
45
+ return await promises_1.default.open(lockPath, 'wx');
46
+ }
47
+ catch (err) {
48
+ const code = err.code;
49
+ if (code === 'EEXIST') {
50
+ if (Date.now() >= deadline) {
51
+ throw new Error(`LOCK_TIMEOUT: another agentdock process holds the lock at ${lockPath}`);
52
+ }
53
+ await new Promise((resolve) => setTimeout(resolve, retryMs));
54
+ continue;
55
+ }
56
+ throw err;
57
+ }
58
+ }
59
+ }
60
+ async function releaseLock(handle, lockPath) {
61
+ try {
62
+ await handle.close();
63
+ }
64
+ catch {
65
+ /* ignore */
66
+ }
67
+ try {
68
+ await promises_1.default.rm(lockPath, { force: true });
69
+ }
70
+ catch {
71
+ /* ignore */
72
+ }
73
+ }
74
+ async function ensureDirectory(dirPath) {
75
+ await promises_1.default.mkdir(dirPath, { recursive: true });
76
+ }
77
+ async function copyFileSafe(sourcePath, targetPath) {
78
+ await ensureDirectory(node_path_1.default.dirname(targetPath));
79
+ const tmpPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
80
+ await promises_1.default.copyFile(sourcePath, tmpPath);
81
+ await promises_1.default.rename(tmpPath, targetPath);
82
+ }
83
+ async function writeTextFile(targetPath, content) {
84
+ await ensureDirectory(node_path_1.default.dirname(targetPath));
85
+ const tmpPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
86
+ await promises_1.default.writeFile(tmpPath, content, 'utf8');
87
+ await promises_1.default.rename(tmpPath, targetPath);
88
+ }
89
+ async function walkDirectoryWithSymlinkPolicy(currentPath, relativeBase, followSymlinks, visitedRealDirectories = new Set()) {
90
+ const entries = await promises_1.default.readdir(currentPath, { withFileTypes: true });
91
+ const files = [];
92
+ for (const entry of entries) {
93
+ const sourcePath = node_path_1.default.join(currentPath, entry.name);
94
+ const relativePath = node_path_1.default.join(relativeBase, entry.name).replace(/\\/g, '/');
95
+ if (entry.isDirectory()) {
96
+ files.push(...await walkDirectoryWithSymlinkPolicy(sourcePath, relativePath, followSymlinks, visitedRealDirectories));
97
+ continue;
98
+ }
99
+ if (entry.isFile()) {
100
+ files.push({ absolutePath: sourcePath, relativePath });
101
+ continue;
102
+ }
103
+ if (!entry.isSymbolicLink()) {
104
+ continue;
105
+ }
106
+ if (!followSymlinks) {
107
+ continue;
108
+ }
109
+ const resolvedPath = await promises_1.default.realpath(sourcePath);
110
+ const stat = await promises_1.default.stat(resolvedPath);
111
+ if (stat.isDirectory()) {
112
+ if (visitedRealDirectories.has(resolvedPath)) {
113
+ continue;
114
+ }
115
+ visitedRealDirectories.add(resolvedPath);
116
+ files.push(...await walkDirectoryWithSymlinkPolicy(resolvedPath, relativePath, followSymlinks, visitedRealDirectories));
117
+ continue;
118
+ }
119
+ if (stat.isFile()) {
120
+ files.push({ absolutePath: resolvedPath, relativePath });
121
+ }
122
+ }
123
+ return files;
124
+ }
125
+ async function copyDirectoryFiltered(sourcePath, targetPath, include, exclude, followSymlinks = true) {
126
+ const files = await walkDirectoryWithSymlinkPolicy(sourcePath, '', followSymlinks);
127
+ const includePatterns = include?.length ? include : ['**/*'];
128
+ const excludePatterns = exclude ?? [];
129
+ for (const file of files) {
130
+ const isIncluded = includePatterns.some((pattern) => (0, minimatch_1.minimatch)(file.relativePath, pattern, { dot: true }));
131
+ const isExcluded = excludePatterns.some((pattern) => (0, minimatch_1.minimatch)(file.relativePath, pattern, { dot: true }));
132
+ if (!isIncluded || isExcluded) {
133
+ continue;
134
+ }
135
+ await copyFileSafe(file.absolutePath, node_path_1.default.join(targetPath, file.relativePath));
136
+ }
137
+ }
138
+ async function copyDirectorySafe(sourcePath, targetPath, followSymlinks = true) {
139
+ await ensureDirectory(node_path_1.default.dirname(targetPath));
140
+ await promises_1.default.cp(sourcePath, targetPath, { recursive: true, dereference: followSymlinks });
141
+ }
142
+ async function pathExists(targetPath) {
143
+ try {
144
+ await promises_1.default.access(targetPath);
145
+ return true;
146
+ }
147
+ catch {
148
+ return false;
149
+ }
150
+ }
151
+ async function readJsonFile(targetPath) {
152
+ const content = await promises_1.default.readFile(targetPath, 'utf8');
153
+ return JSON.parse(content);
154
+ }
155
+ async function writeJsonFile(targetPath, data) {
156
+ await ensureDirectory(node_path_1.default.dirname(targetPath));
157
+ const tmpPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
158
+ await promises_1.default.writeFile(tmpPath, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
159
+ await promises_1.default.rename(tmpPath, targetPath);
160
+ }
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "agentdock-cli",
3
+ "version": "0.4.0",
4
+ "description": "Migrate, back up, and version your AI coding assistant environment (Claude Code / Codex) — MCP servers, Skills, Agents, Plugins, Hooks, and memory — as a portable, secret-isolated package.",
5
+ "keywords": [
6
+ "claude-code",
7
+ "codex",
8
+ "ai-coding-assistant",
9
+ "dotfiles",
10
+ "environment-migration",
11
+ "backup",
12
+ "versioning",
13
+ "mcp",
14
+ "skills",
15
+ "cli"
16
+ ],
17
+ "type": "commonjs",
18
+ "bin": {
19
+ "agentdock": "dist/src/cli.js"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "scripts": {
30
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node -e \"require('fs').copyFileSync('package.json','dist/package.json')\"",
31
+ "dev": "tsx src/cli.ts",
32
+ "test": "vitest run",
33
+ "cli": "tsx src/cli.ts",
34
+ "prepublishOnly": "npm run build",
35
+ "release:commits": "node scripts/generate-commit-groups.js"
36
+ },
37
+ "dependencies": {
38
+ "ajv": "^8.17.1",
39
+ "diff": "^8.0.4",
40
+ "minimatch": "^10.2.5",
41
+ "smol-toml": "^1.7.0",
42
+ "yaml": "^2.8.1"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^24.6.0",
46
+ "tsx": "^4.20.6",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^3.2.4"
49
+ },
50
+ "author": "spsz831",
51
+ "license": "MIT",
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/spsz831/AgentDock.git"
55
+ },
56
+ "homepage": "https://github.com/spsz831/AgentDock#readme",
57
+ "bugs": {
58
+ "url": "https://github.com/spsz831/AgentDock/issues"
59
+ }
60
+ }