@daomar/agentfleet 2.0.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,158 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.OneDriveDetector = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const os = __importStar(require("os"));
40
+ const child_process_1 = require("child_process");
41
+ const provider_selection_1 = require("./provider-selection");
42
+ const i18n_1 = require("./i18n");
43
+ class OneDriveDetector {
44
+ constructor(options = {}) {
45
+ this.platform = options.platform ?? process.platform;
46
+ this.getHomedir = options.homedir ?? os.homedir;
47
+ this.execSyncImpl = options.execSyncImpl ?? child_process_1.execSync;
48
+ this.existsSync = options.existsSync ?? fs.existsSync;
49
+ this.readdirSyncImpl = options.readdirSyncImpl ?? fs.readdirSync;
50
+ this.statSyncImpl = options.statSyncImpl ?? fs.statSync;
51
+ }
52
+ /**
53
+ * Detect all OneDrive sync folders on this machine.
54
+ * Returns the first usable folder path for compatibility with older call sites.
55
+ */
56
+ detect() {
57
+ const accounts = this.detectAccounts();
58
+ if (accounts.length === 0) {
59
+ throw new Error((0, i18n_1.t)('bootstrap.no_onedrive'));
60
+ }
61
+ if (accounts.length > 1) {
62
+ console.warn((0, i18n_1.t)('detector.multiple_accounts') + '\n' +
63
+ accounts.map((account, index) => ` ${index + 1}. ${(0, provider_selection_1.formatOneDriveSelection)(account)}`).join('\n'));
64
+ }
65
+ const selected = accounts[0];
66
+ console.log(`✓ ${(0, i18n_1.t)('detector.detected', { path: selected.path })}`);
67
+ return selected.path;
68
+ }
69
+ detectAccounts() {
70
+ const accounts = [
71
+ ...this.findFromRegistry(),
72
+ ...this.findFromMacCloudStorage(),
73
+ ...this.findFromWellKnownPaths(),
74
+ ];
75
+ const dedupedAccounts = new Map();
76
+ for (const account of accounts) {
77
+ if (!this.existsSync(account.path)) {
78
+ continue;
79
+ }
80
+ const accountKey = account.path.toLowerCase();
81
+ if (!dedupedAccounts.has(accountKey)) {
82
+ dedupedAccounts.set(accountKey, account);
83
+ }
84
+ }
85
+ return Array.from(dedupedAccounts.values());
86
+ }
87
+ findFromRegistry() {
88
+ const accounts = [];
89
+ if (this.platform !== 'win32') {
90
+ return accounts;
91
+ }
92
+ try {
93
+ const regOutput = this.execSyncImpl('reg query "HKCU\\Software\\Microsoft\\OneDrive\\Accounts" /s', { encoding: 'utf-8', timeout: 5000 });
94
+ let currentKey = '';
95
+ for (const line of regOutput.split(/\r?\n/)) {
96
+ const keyMatch = line.match(/^HKEY_CURRENT_USER\\Software\\Microsoft\\OneDrive\\Accounts\\(.+)/i);
97
+ if (keyMatch) {
98
+ currentKey = keyMatch[1];
99
+ continue;
100
+ }
101
+ const valueMatch = line.match(/^\s+UserFolder\s+REG_SZ\s+(.+)/i);
102
+ if (valueMatch && currentKey) {
103
+ const folderPath = valueMatch[1].trim();
104
+ accounts.push(this.createAccount(folderPath, {
105
+ accountKey: currentKey,
106
+ accountName: currentKey.toLowerCase() === 'personal' ? 'Personal' : undefined,
107
+ }));
108
+ }
109
+ }
110
+ }
111
+ catch {
112
+ return [];
113
+ }
114
+ return accounts;
115
+ }
116
+ findFromMacCloudStorage() {
117
+ if (this.platform !== 'darwin') {
118
+ return [];
119
+ }
120
+ return this.scanForOneDrive(this.joinPath(this.getHomedir(), 'Library', 'CloudStorage'));
121
+ }
122
+ findFromWellKnownPaths() {
123
+ return this.scanForOneDrive(this.getHomedir());
124
+ }
125
+ createAccount(folderPath, overrides = {}) {
126
+ const account = (0, provider_selection_1.createOneDriveSelection)(folderPath, overrides);
127
+ return {
128
+ ...account,
129
+ isBusiness: account.accountType === 'business',
130
+ };
131
+ }
132
+ scanForOneDrive(baseDir) {
133
+ const accounts = [];
134
+ try {
135
+ for (const entry of this.readdirSyncImpl(baseDir)) {
136
+ if (!entry.startsWith('OneDrive')) {
137
+ continue;
138
+ }
139
+ const fullPath = this.joinPath(baseDir, entry);
140
+ if (!this.statSyncImpl(fullPath).isDirectory()) {
141
+ continue;
142
+ }
143
+ accounts.push(this.createAccount(fullPath));
144
+ }
145
+ }
146
+ catch {
147
+ return [];
148
+ }
149
+ return accounts;
150
+ }
151
+ joinPath(...segments) {
152
+ return this.platform === 'win32'
153
+ ? path.win32.join(...segments)
154
+ : path.posix.join(...segments);
155
+ }
156
+ }
157
+ exports.OneDriveDetector = OneDriveDetector;
158
+ //# sourceMappingURL=onedrive-detector.js.map
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.inferOneDriveAccountType = inferOneDriveAccountType;
37
+ exports.inferOneDriveAccountName = inferOneDriveAccountName;
38
+ exports.inferOneDriveAccountKey = inferOneDriveAccountKey;
39
+ exports.createOneDriveSelection = createOneDriveSelection;
40
+ exports.normalizeConfig = normalizeConfig;
41
+ exports.selectionFromConfig = selectionFromConfig;
42
+ exports.selectionsEqual = selectionsEqual;
43
+ exports.formatOneDriveSelection = formatOneDriveSelection;
44
+ exports.chooseOneDriveAccount = chooseOneDriveAccount;
45
+ const path = __importStar(require("path"));
46
+ const types_1 = require("../types");
47
+ const i18n_1 = require("./i18n");
48
+ function getPathBasename(onedrivePath) {
49
+ return onedrivePath.includes('\\')
50
+ ? path.win32.basename(onedrivePath)
51
+ : path.posix.basename(onedrivePath);
52
+ }
53
+ function inferOneDriveAccountType(onedrivePath) {
54
+ const baseName = getPathBasename(onedrivePath);
55
+ return /^OneDrive([ -]?Personal)?$/i.test(baseName) ? 'personal' : 'business';
56
+ }
57
+ function inferOneDriveAccountName(onedrivePath, accountType = inferOneDriveAccountType(onedrivePath)) {
58
+ if (accountType === 'personal') {
59
+ return 'Personal';
60
+ }
61
+ const baseName = getPathBasename(onedrivePath);
62
+ if (baseName.startsWith('OneDrive - ')) {
63
+ return baseName.substring('OneDrive - '.length);
64
+ }
65
+ if (baseName.startsWith('OneDrive-')) {
66
+ return baseName.substring('OneDrive-'.length);
67
+ }
68
+ if (baseName.startsWith('OneDrive ')) {
69
+ return baseName.substring('OneDrive '.length);
70
+ }
71
+ return baseName;
72
+ }
73
+ function inferOneDriveAccountKey(onedrivePath, accountType = inferOneDriveAccountType(onedrivePath), accountName = inferOneDriveAccountName(onedrivePath, accountType)) {
74
+ return accountType === 'personal' ? 'Personal' : accountName;
75
+ }
76
+ function createOneDriveSelection(onedrivePath, overrides = {}) {
77
+ const accountType = overrides.accountType ?? inferOneDriveAccountType(onedrivePath);
78
+ const accountName = overrides.accountName ?? inferOneDriveAccountName(onedrivePath, accountType);
79
+ return {
80
+ provider: overrides.provider ?? 'onedrive',
81
+ accountKey: overrides.accountKey ?? inferOneDriveAccountKey(onedrivePath, accountType, accountName),
82
+ accountName,
83
+ accountType,
84
+ path: overrides.path ?? onedrivePath,
85
+ };
86
+ }
87
+ function normalizeConfig(config) {
88
+ const provider = 'onedrive';
89
+ const selection = createOneDriveSelection(config.onedrivePath, {
90
+ provider,
91
+ accountKey: config.onedriveAccountKey,
92
+ accountName: config.onedriveAccountName,
93
+ accountType: config.onedriveAccountType,
94
+ });
95
+ return {
96
+ ...types_1.DEFAULT_CONFIG,
97
+ ...config,
98
+ provider,
99
+ onedrivePath: config.onedrivePath,
100
+ onedriveAccountKey: selection.accountKey,
101
+ onedriveAccountName: selection.accountName,
102
+ onedriveAccountType: selection.accountType,
103
+ hostname: config.hostname,
104
+ };
105
+ }
106
+ function selectionFromConfig(config) {
107
+ return createOneDriveSelection(config.onedrivePath, {
108
+ provider: config.provider,
109
+ accountKey: config.onedriveAccountKey,
110
+ accountName: config.onedriveAccountName,
111
+ accountType: config.onedriveAccountType,
112
+ });
113
+ }
114
+ function selectionsEqual(left, right) {
115
+ return left.provider === right.provider
116
+ && left.path === right.path
117
+ && left.accountKey === right.accountKey
118
+ && left.accountName === right.accountName
119
+ && left.accountType === right.accountType;
120
+ }
121
+ function formatOneDriveSelection(selection) {
122
+ return `${selection.accountName} (${selection.accountType}) → ${selection.path}`;
123
+ }
124
+ async function chooseOneDriveAccount(accounts) {
125
+ if (accounts.length === 0) {
126
+ throw new Error((0, i18n_1.t)('bootstrap.no_onedrive'));
127
+ }
128
+ const selected = accounts[0];
129
+ console.log(`✓ ${(0, i18n_1.t)('bootstrap.selected', { selection: formatOneDriveSelection(selected) })}`);
130
+ return selected;
131
+ }
132
+ //# sourceMappingURL=provider-selection.js.map
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ResultWriter = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const os = __importStar(require("os"));
40
+ const i18n_1 = require("./i18n");
41
+ class ResultWriter {
42
+ constructor(outputDir) {
43
+ this.outputDir = outputDir;
44
+ this.hostname = os.hostname();
45
+ }
46
+ /**
47
+ * Write execution results to the output directory.
48
+ * Creates output/<task-id>/<HOSTNAME>-result.json, <HOSTNAME>-stdout.log, and <HOSTNAME>-stderr.log.
49
+ */
50
+ write(result) {
51
+ const taskOutputDir = path.join(this.outputDir, result.taskId);
52
+ // Create task output directory if it doesn't exist
53
+ if (!fs.existsSync(taskOutputDir)) {
54
+ fs.mkdirSync(taskOutputDir, { recursive: true });
55
+ }
56
+ // Write result metadata
57
+ const resultFile = {
58
+ taskId: result.taskId,
59
+ hostname: this.hostname,
60
+ startedAt: result.startedAt,
61
+ completedAt: result.completedAt,
62
+ exitCode: result.exitCode,
63
+ status: result.status,
64
+ agentCommand: result.agentCommand,
65
+ error: result.error,
66
+ };
67
+ const resultPath = path.join(taskOutputDir, `${this.hostname}-result.json`);
68
+ fs.writeFileSync(resultPath, JSON.stringify(resultFile, null, 2));
69
+ // Write stdout log if non-empty
70
+ if (result.stdout) {
71
+ const stdoutPath = path.join(taskOutputDir, `${this.hostname}-stdout.log`);
72
+ fs.writeFileSync(stdoutPath, result.stdout);
73
+ }
74
+ // Write stderr log if non-empty
75
+ if (result.stderr) {
76
+ const stderrPath = path.join(taskOutputDir, `${this.hostname}-stderr.log`);
77
+ fs.writeFileSync(stderrPath, result.stderr);
78
+ }
79
+ const statusIcon = result.status === 'completed' ? '✅' : result.status === 'timeout' ? '⏰' : '❌';
80
+ console.log(`${statusIcon} ${(0, i18n_1.t)('result.written', { path: taskOutputDir })}`);
81
+ return taskOutputDir;
82
+ }
83
+ }
84
+ exports.ResultWriter = ResultWriter;
85
+ //# sourceMappingURL=result-writer.js.map
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SetupService = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const os = __importStar(require("os"));
40
+ const provider_selection_1 = require("./provider-selection");
41
+ const i18n_1 = require("./i18n");
42
+ const AGENTFLEET_DIR = '.agentfleet';
43
+ const ONEDRIVE_SUBDIR = 'AgentFleet';
44
+ const SYMLINK_TARGETS = ['tasks', 'output'];
45
+ class SetupService {
46
+ constructor(homeDir = os.homedir()) {
47
+ this.homeDir = homeDir;
48
+ this.agentfleetDir = path.join(this.homeDir, AGENTFLEET_DIR);
49
+ }
50
+ getAgentFleetDir() {
51
+ return this.agentfleetDir;
52
+ }
53
+ getTasksDir() {
54
+ return path.join(this.agentfleetDir, 'tasks');
55
+ }
56
+ getOutputDir() {
57
+ return path.join(this.agentfleetDir, 'output');
58
+ }
59
+ getConfigPath() {
60
+ return path.join(this.agentfleetDir, 'config.json');
61
+ }
62
+ getProcessedPath() {
63
+ return path.join(this.agentfleetDir, 'processed.json');
64
+ }
65
+ /**
66
+ * Run full setup: create directories, symlinks, and config.
67
+ * Returns the loaded or created config.
68
+ */
69
+ setup(selection) {
70
+ const onedrivePath = selection.path;
71
+ // 1. Create ~/.agentfleet if it doesn't exist
72
+ if (!fs.existsSync(this.agentfleetDir)) {
73
+ fs.mkdirSync(this.agentfleetDir, { recursive: true });
74
+ console.log(`✓ ${(0, i18n_1.t)('setup.created_dir', { path: this.agentfleetDir })}`);
75
+ }
76
+ // 2. Create OneDrive subdirectories
77
+ const onedriveBase = path.join(onedrivePath, ONEDRIVE_SUBDIR);
78
+ for (const subdir of SYMLINK_TARGETS) {
79
+ const targetDir = path.join(onedriveBase, subdir);
80
+ if (!fs.existsSync(targetDir)) {
81
+ fs.mkdirSync(targetDir, { recursive: true });
82
+ console.log(`✓ ${(0, i18n_1.t)('setup.created_onedrive_dir', { path: targetDir })}`);
83
+ }
84
+ }
85
+ // 3. Create or validate symlinks
86
+ for (const subdir of SYMLINK_TARGETS) {
87
+ const linkPath = path.join(this.agentfleetDir, subdir);
88
+ const targetPath = path.join(onedriveBase, subdir);
89
+ this.ensureSymlink(linkPath, targetPath);
90
+ }
91
+ // 4. Create or load config
92
+ const config = this.ensureConfig(selection);
93
+ // 5. Ensure processed.json exists
94
+ if (!fs.existsSync(this.getProcessedPath())) {
95
+ fs.writeFileSync(this.getProcessedPath(), JSON.stringify({ processedIds: [] }, null, 2));
96
+ }
97
+ return config;
98
+ }
99
+ ensureSymlink(linkPath, targetPath) {
100
+ if (this.pathEntryExists(linkPath)) {
101
+ // Check if it's a symlink/junction pointing to the right place
102
+ try {
103
+ const stats = fs.lstatSync(linkPath);
104
+ if (stats.isSymbolicLink()) {
105
+ const currentTarget = fs.readlinkSync(linkPath);
106
+ if (path.resolve(currentTarget) === path.resolve(targetPath)) {
107
+ console.log(`✓ ${(0, i18n_1.t)('setup.symlink_valid', { link: linkPath, target: targetPath })}`);
108
+ return;
109
+ }
110
+ // Stale symlink — remove and recreate
111
+ console.log(`⟳ ${(0, i18n_1.t)('setup.symlink_stale', { link: linkPath })}`);
112
+ this.removePathEntry(linkPath);
113
+ }
114
+ else {
115
+ // It's a real directory, not a symlink — skip
116
+ console.warn(`⚠ ${(0, i18n_1.t)('setup.symlink_exists_as_dir', { path: linkPath })}`);
117
+ return;
118
+ }
119
+ }
120
+ catch {
121
+ // If we can't read the symlink, remove and recreate
122
+ try {
123
+ this.removePathEntry(linkPath);
124
+ }
125
+ catch {
126
+ /* ignore */
127
+ }
128
+ }
129
+ }
130
+ // Create symlink (or junction as fallback on Windows)
131
+ try {
132
+ fs.symlinkSync(targetPath, linkPath, 'junction');
133
+ console.log(`✓ ${(0, i18n_1.t)('setup.created_junction', { link: linkPath, target: targetPath })}`);
134
+ }
135
+ catch (symlinkErr) {
136
+ try {
137
+ // Fallback: try directory symlink (requires Developer Mode)
138
+ fs.symlinkSync(targetPath, linkPath, 'dir');
139
+ console.log(`✓ ${(0, i18n_1.t)('setup.created_symlink', { link: linkPath, target: targetPath })}`);
140
+ }
141
+ catch {
142
+ throw new Error((0, i18n_1.t)('setup.symlink_failed', { path: linkPath, error: symlinkErr.message }));
143
+ }
144
+ }
145
+ }
146
+ pathEntryExists(targetPath) {
147
+ try {
148
+ fs.lstatSync(targetPath);
149
+ return true;
150
+ }
151
+ catch {
152
+ return false;
153
+ }
154
+ }
155
+ removePathEntry(targetPath) {
156
+ const stats = fs.lstatSync(targetPath);
157
+ if (stats.isSymbolicLink()) {
158
+ fs.unlinkSync(targetPath);
159
+ return;
160
+ }
161
+ fs.rmSync(targetPath, { recursive: true, force: true });
162
+ }
163
+ loadConfig() {
164
+ const configPath = this.getConfigPath();
165
+ if (!fs.existsSync(configPath)) {
166
+ return null;
167
+ }
168
+ try {
169
+ const existing = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
170
+ if (typeof existing.onedrivePath !== 'string' || existing.onedrivePath.length === 0) {
171
+ console.warn(`⚠ ${(0, i18n_1.t)('setup.config_missing_path')}`);
172
+ return null;
173
+ }
174
+ return (0, provider_selection_1.normalizeConfig)({
175
+ ...existing,
176
+ onedrivePath: existing.onedrivePath,
177
+ hostname: existing.hostname ?? os.hostname(),
178
+ });
179
+ }
180
+ catch {
181
+ console.warn(`⚠ ${(0, i18n_1.t)('setup.config_corrupt')}`);
182
+ return null;
183
+ }
184
+ }
185
+ ensureConfig(selection) {
186
+ const configPath = this.getConfigPath();
187
+ const existing = this.loadConfig();
188
+ if (existing) {
189
+ const nextConfig = (0, provider_selection_1.normalizeConfig)({
190
+ ...existing,
191
+ provider: selection.provider,
192
+ onedrivePath: selection.path,
193
+ onedriveAccountKey: selection.accountKey,
194
+ onedriveAccountName: selection.accountName,
195
+ onedriveAccountType: selection.accountType,
196
+ hostname: os.hostname(),
197
+ });
198
+ if (!(0, provider_selection_1.selectionsEqual)((0, provider_selection_1.selectionFromConfig)(existing), selection)) {
199
+ console.log(`⟳ ${(0, i18n_1.t)('setup.onedrive_changed')}`);
200
+ }
201
+ fs.writeFileSync(configPath, JSON.stringify(nextConfig, null, 2));
202
+ console.log(`✓ ${(0, i18n_1.t)('setup.config_loaded', { path: configPath })}`);
203
+ return nextConfig;
204
+ }
205
+ const config = (0, provider_selection_1.normalizeConfig)({
206
+ provider: selection.provider,
207
+ onedrivePath: selection.path,
208
+ onedriveAccountKey: selection.accountKey,
209
+ onedriveAccountName: selection.accountName,
210
+ onedriveAccountType: selection.accountType,
211
+ hostname: os.hostname(),
212
+ });
213
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
214
+ console.log(`✓ ${(0, i18n_1.t)('setup.config_created', { path: configPath })}`);
215
+ return config;
216
+ }
217
+ }
218
+ exports.SetupService = SetupService;
219
+ //# sourceMappingURL=setup.js.map