@alfe.ai/openclaw-sync 0.0.14 → 0.0.16

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.
@@ -1,14 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  require("../ignore.cjs");
3
3
  const require_sync_engine = require("../sync-engine.cjs");
4
- let node_fs_promises = require("node:fs/promises");
5
4
  let node_path = require("node:path");
5
+ let node_fs_promises = require("node:fs/promises");
6
6
  //#region src/cli/index.ts
7
7
  /**
8
8
  * AlfeSync CLI — alfesync command-line interface.
9
9
  *
10
+ * Credentials come from `~/.alfe/config.toml` (set up via `alfe login`).
11
+ * No separate sync init step is required.
12
+ *
10
13
  * Commands:
11
- * init - Initialize AlfeSync in a workspace
14
+ * register - Register this agent with the sync service (one-time)
12
15
  * push - Push local changes to remote
13
16
  * pull - Pull remote changes to local
14
17
  * status - Show sync status and pending changes
@@ -18,59 +21,27 @@ let node_path = require("node:path");
18
21
  */
19
22
  const program = new (require("commander")).Command();
20
23
  program.name("alfesync").description("AlfeSync — agent workspace backup and sync").version("1.0.0");
21
- program.command("init").description("Initialize AlfeSync in the current workspace").option("-t, --token <token>", "Alfe Connect bearer token").option("-u, --api-url <url>", "AlfeSync API URL", "https://api.alfe.ai").option("-a, --agent-id <id>", "Agent ID for this workspace").option("-n, --display-name <name>", "Display name for the agent").action(async (opts) => {
22
- const workspacePath = (0, node_path.resolve)(".");
23
- if (require_sync_engine.isInitialized(workspacePath)) {
24
- console.log("AlfeSync is already initialized in this workspace.");
25
- const existing = await require_sync_engine.readConfig(workspacePath);
26
- if (existing) {
27
- console.log(` Agent: ${existing.agentId}`);
28
- console.log(` API: ${existing.apiUrl}`);
29
- }
30
- return;
31
- }
32
- const token = opts.token ?? process.env.ALFESYNC_TOKEN;
33
- const apiUrl = opts.apiUrl ?? process.env.ALFESYNC_API_URL ?? "https://api.alfe.ai";
34
- const agentId = opts.agentId ?? process.env.ALFESYNC_AGENT_ID;
35
- if (!token) {
36
- console.error("Error: --token is required (or set ALFESYNC_TOKEN env var)");
37
- process.exit(1);
38
- }
39
- if (!agentId) {
40
- console.error("Error: --agent-id is required (or set ALFESYNC_AGENT_ID env var)");
41
- process.exit(1);
42
- }
43
- console.log("Registering agent with AlfeSync...");
44
- const client = require_sync_engine.createApiClient({
45
- apiUrl,
46
- token,
47
- agentId
48
- });
24
+ program.command("register").description("Register this agent with the sync service (one-time)").option("-n, --display-name <name>", "Display name for the agent").action(async (opts) => {
49
25
  try {
50
- const orgId = (await client.registerAgent(opts.displayName ?? agentId)).agent.orgId;
51
- await require_sync_engine.writeConfig({
52
- agentId,
53
- orgId,
54
- token,
55
- workspacePath,
56
- apiUrl
57
- });
58
- console.log("✓ AlfeSync initialized!");
59
- console.log(` Agent: ${agentId}`);
60
- console.log(` Org: ${orgId}`);
61
- console.log(` API: ${apiUrl}`);
62
- console.log(` Workspace: ${workspacePath}`);
63
- console.log("");
64
- console.log("Run 'alfesync push' to sync your workspace.");
26
+ const config = await require_sync_engine.requireConfig();
27
+ const result = await require_sync_engine.createApiClient({
28
+ apiUrl: config.apiUrl,
29
+ token: config.token,
30
+ agentId: config.agentId
31
+ }).registerAgent(opts.displayName ?? config.agentId);
32
+ console.log("✓ Agent registered with AlfeSync");
33
+ console.log(` Agent: ${config.agentId}`);
34
+ console.log(` Org: ${result.agent.orgId}`);
35
+ console.log(` API: ${config.apiUrl}`);
36
+ console.log(` Workspace: ${config.workspacePath}`);
65
37
  } catch (err) {
66
- console.error("Failed to register agent:", err instanceof Error ? err.message : String(err));
38
+ console.error(err instanceof Error ? err.message : String(err));
67
39
  process.exit(1);
68
40
  }
69
41
  });
70
42
  program.command("push").description("Push local changes to remote").option("-q, --quiet", "Suppress output").option("-f, --filter <prefix>", "Only push files matching this prefix").action(async (opts) => {
71
- const workspacePath = (0, node_path.resolve)(".");
72
43
  try {
73
- await (await require_sync_engine.createSyncEngine(workspacePath)).push(void 0, {
44
+ await (await require_sync_engine.createSyncEngine()).push(void 0, {
74
45
  quiet: opts.quiet,
75
46
  filter: opts.filter
76
47
  });
@@ -80,29 +51,23 @@ program.command("push").description("Push local changes to remote").option("-q,
80
51
  }
81
52
  });
82
53
  program.command("pull").description("Pull remote changes to local").option("-q, --quiet", "Suppress output").action(async (opts) => {
83
- const workspacePath = (0, node_path.resolve)(".");
84
54
  try {
85
- await (await require_sync_engine.createSyncEngine(workspacePath)).pull({ quiet: opts.quiet });
55
+ await (await require_sync_engine.createSyncEngine()).pull({ quiet: opts.quiet });
86
56
  } catch (err) {
87
57
  console.error(err instanceof Error ? err.message : String(err));
88
58
  process.exit(1);
89
59
  }
90
60
  });
91
61
  program.command("status").description("Show sync status and pending changes").action(async () => {
92
- const workspacePath = (0, node_path.resolve)(".");
93
62
  try {
94
- const config = await require_sync_engine.readConfig(workspacePath);
95
- if (!config) {
96
- console.log("AlfeSync not initialized. Run: alfesync init");
97
- return;
98
- }
63
+ const config = await require_sync_engine.requireConfig();
99
64
  const client = require_sync_engine.createApiClient({
100
65
  apiUrl: config.apiUrl,
101
66
  token: config.token,
102
67
  agentId: config.agentId
103
68
  });
104
69
  const [localManifest, remoteManifest, stats] = await Promise.all([
105
- require_sync_engine.readManifest(workspacePath),
70
+ require_sync_engine.readManifest(config.workspacePath),
106
71
  client.getManifest(),
107
72
  client.getStats()
108
73
  ]);
@@ -110,7 +75,7 @@ program.command("status").description("Show sync status and pending changes").ac
110
75
  console.log("AlfeSync Status");
111
76
  console.log("═══════════════");
112
77
  console.log(`Agent: ${config.agentId}`);
113
- console.log(`Workspace: ${workspacePath}`);
78
+ console.log(`Workspace: ${config.workspacePath}`);
114
79
  console.log(`API: ${config.apiUrl}`);
115
80
  console.log("");
116
81
  console.log("Storage:");
@@ -146,9 +111,8 @@ program.command("status").description("Show sync status and pending changes").ac
146
111
  }
147
112
  });
148
113
  program.command("conflicts").description("List conflict files in the workspace").action(async () => {
149
- const workspacePath = (0, node_path.resolve)(".");
150
114
  try {
151
- const conflicts = await findConflictFiles(workspacePath);
115
+ const conflicts = await findConflictFiles((await require_sync_engine.requireConfig()).workspacePath);
152
116
  if (conflicts.length === 0) {
153
117
  console.log("No conflict files found.");
154
118
  return;
@@ -161,13 +125,8 @@ program.command("conflicts").description("List conflict files in the workspace")
161
125
  }
162
126
  });
163
127
  program.command("history <file>").description("Show version history for a file").action(async (file) => {
164
- const workspacePath = (0, node_path.resolve)(".");
165
128
  try {
166
- const config = await require_sync_engine.readConfig(workspacePath);
167
- if (!config) {
168
- console.log("AlfeSync not initialized. Run: alfesync init");
169
- return;
170
- }
129
+ const config = await require_sync_engine.requireConfig();
171
130
  const versions = await require_sync_engine.createApiClient({
172
131
  apiUrl: config.apiUrl,
173
132
  token: config.token,
@@ -189,13 +148,8 @@ program.command("history <file>").description("Show version history for a file")
189
148
  }
190
149
  });
191
150
  program.command("restore").description("Restore agent workspace from remote backup").option("-m, --mode <mode>", "Restore mode: full, active, memory", "full").option("-q, --quiet", "Suppress output").action(async (opts) => {
192
- const workspacePath = (0, node_path.resolve)(".");
193
151
  try {
194
- const config = await require_sync_engine.readConfig(workspacePath);
195
- if (!config) {
196
- console.log("AlfeSync not initialized. Run: alfesync init");
197
- return;
198
- }
152
+ const config = await require_sync_engine.requireConfig();
199
153
  const mode = opts.mode;
200
154
  if (![
201
155
  "full",
@@ -221,7 +175,7 @@ program.command("restore").description("Restore agent workspace from remote back
221
175
  const response = await fetch(file.url);
222
176
  if (!response.ok) throw new Error(`HTTP ${String(response.status)}`);
223
177
  const buffer = Buffer.from(await response.arrayBuffer());
224
- const absolutePath = (0, node_path.join)(workspacePath, file.path);
178
+ const absolutePath = (0, node_path.join)(config.workspacePath, file.path);
225
179
  await mkdir(dirname(absolutePath), { recursive: true });
226
180
  await writeFile(absolutePath, buffer);
227
181
  downloaded++;
@@ -240,7 +194,7 @@ async function findConflictFiles(dir, base) {
240
194
  const results = [];
241
195
  const entries = await (0, node_fs_promises.readdir)(dir, { withFileTypes: true });
242
196
  for (const entry of entries) {
243
- if (entry.name === "node_modules" || entry.name === ".git" || entry.name === ".alfesync") continue;
197
+ if (entry.name === "node_modules" || entry.name === ".git") continue;
244
198
  const fullPath = (0, node_path.join)(dir, entry.name);
245
199
  const relativePath = base ? (0, node_path.join)(base, entry.name) : entry.name;
246
200
  if (entry.isDirectory()) {
package/dist/cli/index.js CHANGED
@@ -1,14 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import { g as writeConfig, i as createApiClient, m as readConfig, o as diffManifests, p as isInitialized, s as readManifest, t as createSyncEngine } from "../sync-engine.js";
2
+ import { i as createApiClient, o as diffManifests, p as requireConfig, s as readManifest, t as createSyncEngine } from "../sync-engine.js";
3
+ import { join } from "node:path";
3
4
  import { readdir } from "node:fs/promises";
4
- import { join, resolve } from "node:path";
5
5
  import { Command } from "commander";
6
6
  //#region src/cli/index.ts
7
7
  /**
8
8
  * AlfeSync CLI — alfesync command-line interface.
9
9
  *
10
+ * Credentials come from `~/.alfe/config.toml` (set up via `alfe login`).
11
+ * No separate sync init step is required.
12
+ *
10
13
  * Commands:
11
- * init - Initialize AlfeSync in a workspace
14
+ * register - Register this agent with the sync service (one-time)
12
15
  * push - Push local changes to remote
13
16
  * pull - Pull remote changes to local
14
17
  * status - Show sync status and pending changes
@@ -18,59 +21,27 @@ import { Command } from "commander";
18
21
  */
19
22
  const program = new Command();
20
23
  program.name("alfesync").description("AlfeSync — agent workspace backup and sync").version("1.0.0");
21
- program.command("init").description("Initialize AlfeSync in the current workspace").option("-t, --token <token>", "Alfe Connect bearer token").option("-u, --api-url <url>", "AlfeSync API URL", "https://api.alfe.ai").option("-a, --agent-id <id>", "Agent ID for this workspace").option("-n, --display-name <name>", "Display name for the agent").action(async (opts) => {
22
- const workspacePath = resolve(".");
23
- if (isInitialized(workspacePath)) {
24
- console.log("AlfeSync is already initialized in this workspace.");
25
- const existing = await readConfig(workspacePath);
26
- if (existing) {
27
- console.log(` Agent: ${existing.agentId}`);
28
- console.log(` API: ${existing.apiUrl}`);
29
- }
30
- return;
31
- }
32
- const token = opts.token ?? process.env.ALFESYNC_TOKEN;
33
- const apiUrl = opts.apiUrl ?? process.env.ALFESYNC_API_URL ?? "https://api.alfe.ai";
34
- const agentId = opts.agentId ?? process.env.ALFESYNC_AGENT_ID;
35
- if (!token) {
36
- console.error("Error: --token is required (or set ALFESYNC_TOKEN env var)");
37
- process.exit(1);
38
- }
39
- if (!agentId) {
40
- console.error("Error: --agent-id is required (or set ALFESYNC_AGENT_ID env var)");
41
- process.exit(1);
42
- }
43
- console.log("Registering agent with AlfeSync...");
44
- const client = createApiClient({
45
- apiUrl,
46
- token,
47
- agentId
48
- });
24
+ program.command("register").description("Register this agent with the sync service (one-time)").option("-n, --display-name <name>", "Display name for the agent").action(async (opts) => {
49
25
  try {
50
- const orgId = (await client.registerAgent(opts.displayName ?? agentId)).agent.orgId;
51
- await writeConfig({
52
- agentId,
53
- orgId,
54
- token,
55
- workspacePath,
56
- apiUrl
57
- });
58
- console.log("✓ AlfeSync initialized!");
59
- console.log(` Agent: ${agentId}`);
60
- console.log(` Org: ${orgId}`);
61
- console.log(` API: ${apiUrl}`);
62
- console.log(` Workspace: ${workspacePath}`);
63
- console.log("");
64
- console.log("Run 'alfesync push' to sync your workspace.");
26
+ const config = await requireConfig();
27
+ const result = await createApiClient({
28
+ apiUrl: config.apiUrl,
29
+ token: config.token,
30
+ agentId: config.agentId
31
+ }).registerAgent(opts.displayName ?? config.agentId);
32
+ console.log("✓ Agent registered with AlfeSync");
33
+ console.log(` Agent: ${config.agentId}`);
34
+ console.log(` Org: ${result.agent.orgId}`);
35
+ console.log(` API: ${config.apiUrl}`);
36
+ console.log(` Workspace: ${config.workspacePath}`);
65
37
  } catch (err) {
66
- console.error("Failed to register agent:", err instanceof Error ? err.message : String(err));
38
+ console.error(err instanceof Error ? err.message : String(err));
67
39
  process.exit(1);
68
40
  }
69
41
  });
70
42
  program.command("push").description("Push local changes to remote").option("-q, --quiet", "Suppress output").option("-f, --filter <prefix>", "Only push files matching this prefix").action(async (opts) => {
71
- const workspacePath = resolve(".");
72
43
  try {
73
- await (await createSyncEngine(workspacePath)).push(void 0, {
44
+ await (await createSyncEngine()).push(void 0, {
74
45
  quiet: opts.quiet,
75
46
  filter: opts.filter
76
47
  });
@@ -80,29 +51,23 @@ program.command("push").description("Push local changes to remote").option("-q,
80
51
  }
81
52
  });
82
53
  program.command("pull").description("Pull remote changes to local").option("-q, --quiet", "Suppress output").action(async (opts) => {
83
- const workspacePath = resolve(".");
84
54
  try {
85
- await (await createSyncEngine(workspacePath)).pull({ quiet: opts.quiet });
55
+ await (await createSyncEngine()).pull({ quiet: opts.quiet });
86
56
  } catch (err) {
87
57
  console.error(err instanceof Error ? err.message : String(err));
88
58
  process.exit(1);
89
59
  }
90
60
  });
91
61
  program.command("status").description("Show sync status and pending changes").action(async () => {
92
- const workspacePath = resolve(".");
93
62
  try {
94
- const config = await readConfig(workspacePath);
95
- if (!config) {
96
- console.log("AlfeSync not initialized. Run: alfesync init");
97
- return;
98
- }
63
+ const config = await requireConfig();
99
64
  const client = createApiClient({
100
65
  apiUrl: config.apiUrl,
101
66
  token: config.token,
102
67
  agentId: config.agentId
103
68
  });
104
69
  const [localManifest, remoteManifest, stats] = await Promise.all([
105
- readManifest(workspacePath),
70
+ readManifest(config.workspacePath),
106
71
  client.getManifest(),
107
72
  client.getStats()
108
73
  ]);
@@ -110,7 +75,7 @@ program.command("status").description("Show sync status and pending changes").ac
110
75
  console.log("AlfeSync Status");
111
76
  console.log("═══════════════");
112
77
  console.log(`Agent: ${config.agentId}`);
113
- console.log(`Workspace: ${workspacePath}`);
78
+ console.log(`Workspace: ${config.workspacePath}`);
114
79
  console.log(`API: ${config.apiUrl}`);
115
80
  console.log("");
116
81
  console.log("Storage:");
@@ -146,9 +111,8 @@ program.command("status").description("Show sync status and pending changes").ac
146
111
  }
147
112
  });
148
113
  program.command("conflicts").description("List conflict files in the workspace").action(async () => {
149
- const workspacePath = resolve(".");
150
114
  try {
151
- const conflicts = await findConflictFiles(workspacePath);
115
+ const conflicts = await findConflictFiles((await requireConfig()).workspacePath);
152
116
  if (conflicts.length === 0) {
153
117
  console.log("No conflict files found.");
154
118
  return;
@@ -161,13 +125,8 @@ program.command("conflicts").description("List conflict files in the workspace")
161
125
  }
162
126
  });
163
127
  program.command("history <file>").description("Show version history for a file").action(async (file) => {
164
- const workspacePath = resolve(".");
165
128
  try {
166
- const config = await readConfig(workspacePath);
167
- if (!config) {
168
- console.log("AlfeSync not initialized. Run: alfesync init");
169
- return;
170
- }
129
+ const config = await requireConfig();
171
130
  const versions = await createApiClient({
172
131
  apiUrl: config.apiUrl,
173
132
  token: config.token,
@@ -189,13 +148,8 @@ program.command("history <file>").description("Show version history for a file")
189
148
  }
190
149
  });
191
150
  program.command("restore").description("Restore agent workspace from remote backup").option("-m, --mode <mode>", "Restore mode: full, active, memory", "full").option("-q, --quiet", "Suppress output").action(async (opts) => {
192
- const workspacePath = resolve(".");
193
151
  try {
194
- const config = await readConfig(workspacePath);
195
- if (!config) {
196
- console.log("AlfeSync not initialized. Run: alfesync init");
197
- return;
198
- }
152
+ const config = await requireConfig();
199
153
  const mode = opts.mode;
200
154
  if (![
201
155
  "full",
@@ -221,7 +175,7 @@ program.command("restore").description("Restore agent workspace from remote back
221
175
  const response = await fetch(file.url);
222
176
  if (!response.ok) throw new Error(`HTTP ${String(response.status)}`);
223
177
  const buffer = Buffer.from(await response.arrayBuffer());
224
- const absolutePath = join(workspacePath, file.path);
178
+ const absolutePath = join(config.workspacePath, file.path);
225
179
  await mkdir(dirname(absolutePath), { recursive: true });
226
180
  await writeFile(absolutePath, buffer);
227
181
  downloaded++;
@@ -240,7 +194,7 @@ async function findConflictFiles(dir, base) {
240
194
  const results = [];
241
195
  const entries = await readdir(dir, { withFileTypes: true });
242
196
  for (const entry of entries) {
243
- if (entry.name === "node_modules" || entry.name === ".git" || entry.name === ".alfesync") continue;
197
+ if (entry.name === "node_modules" || entry.name === ".git") continue;
244
198
  const fullPath = join(dir, entry.name);
245
199
  const relativePath = base ? join(base, entry.name) : entry.name;
246
200
  if (entry.isDirectory()) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * AlfeSync CLI — alfesync command-line interface.\n *\n * Commands:\n * init - Initialize AlfeSync in a workspace\n * push - Push local changes to remote\n * pull - Pull remote changes to local\n * status - Show sync status and pending changes\n * conflicts - List conflict files\n * history - Show version history for a file\n * restore - Restore agent workspace from remote\n */\n\nimport { Command } from \"commander\";\nimport { resolve, join } from \"node:path\";\nimport { readdir } from \"node:fs/promises\";\nimport {\n readConfig,\n writeConfig,\n isInitialized,\n} from \"../config.js\";\nimport { createApiClient } from \"../api-client.js\";\nimport { createSyncEngine } from \"../sync-engine.js\";\nimport { readManifest, diffManifests } from \"../manifest.js\";\n\n\nconst program = new Command();\n\nprogram\n .name(\"alfesync\")\n .description(\"AlfeSync — agent workspace backup and sync\")\n .version(\"1.0.0\");\n\n// ─── init ─────────────────────────────────────────────────\n\nprogram\n .command(\"init\")\n .description(\"Initialize AlfeSync in the current workspace\")\n .option(\"-t, --token <token>\", \"Alfe Connect bearer token\")\n .option(\"-u, --api-url <url>\", \"AlfeSync API URL\", \"https://api.alfe.ai\")\n .option(\"-a, --agent-id <id>\", \"Agent ID for this workspace\")\n .option(\"-n, --display-name <name>\", \"Display name for the agent\")\n .action(async (opts: { token?: string; apiUrl?: string; agentId?: string; displayName?: string }) => {\n const workspacePath = resolve(\".\");\n\n if (isInitialized(workspacePath)) {\n console.log(\"AlfeSync is already initialized in this workspace.\");\n const existing = await readConfig(workspacePath);\n if (existing) {\n console.log(` Agent: ${existing.agentId}`);\n console.log(` API: ${existing.apiUrl}`);\n }\n return;\n }\n\n const token = opts.token ?? process.env.ALFESYNC_TOKEN;\n const apiUrl = opts.apiUrl ?? process.env.ALFESYNC_API_URL ?? \"https://api.alfe.ai\";\n const agentId = opts.agentId ?? process.env.ALFESYNC_AGENT_ID;\n\n if (!token) {\n console.error(\n \"Error: --token is required (or set ALFESYNC_TOKEN env var)\",\n );\n process.exit(1);\n }\n if (!agentId) {\n console.error(\n \"Error: --agent-id is required (or set ALFESYNC_AGENT_ID env var)\",\n );\n process.exit(1);\n }\n\n // Register agent with the API\n console.log(\"Registering agent with AlfeSync...\");\n const client = createApiClient({ apiUrl, token, agentId });\n\n try {\n const result = await client.registerAgent(opts.displayName ?? agentId);\n const orgId = result.agent.orgId;\n\n await writeConfig({\n agentId,\n orgId,\n token,\n workspacePath,\n apiUrl,\n });\n\n console.log(\"✓ AlfeSync initialized!\");\n console.log(` Agent: ${agentId}`);\n console.log(` Org: ${orgId}`);\n console.log(` API: ${apiUrl}`);\n console.log(` Workspace: ${workspacePath}`);\n console.log(\"\");\n console.log(\"Run 'alfesync push' to sync your workspace.\");\n } catch (err) {\n console.error(\n \"Failed to register agent:\",\n err instanceof Error ? err.message : String(err),\n );\n process.exit(1);\n }\n });\n\n// ─── push ─────────────────────────────────────────────────\n\nprogram\n .command(\"push\")\n .description(\"Push local changes to remote\")\n .option(\"-q, --quiet\", \"Suppress output\")\n .option(\"-f, --filter <prefix>\", \"Only push files matching this prefix\")\n .action(async (opts: { quiet?: boolean; filter?: string }) => {\n const workspacePath = resolve(\".\");\n\n try {\n const engine = await createSyncEngine(workspacePath);\n await engine.push(undefined, {\n quiet: opts.quiet,\n filter: opts.filter,\n });\n } catch (err) {\n console.error(\n err instanceof Error ? err.message : String(err),\n );\n process.exit(1);\n }\n });\n\n// ─── pull ─────────────────────────────────────────────────\n\nprogram\n .command(\"pull\")\n .description(\"Pull remote changes to local\")\n .option(\"-q, --quiet\", \"Suppress output\")\n .action(async (opts: { quiet?: boolean }) => {\n const workspacePath = resolve(\".\");\n\n try {\n const engine = await createSyncEngine(workspacePath);\n await engine.pull({ quiet: opts.quiet });\n } catch (err) {\n console.error(\n err instanceof Error ? err.message : String(err),\n );\n process.exit(1);\n }\n });\n\n// ─── status ───────────────────────────────────────────────\n\nprogram\n .command(\"status\")\n .description(\"Show sync status and pending changes\")\n .action(async () => {\n const workspacePath = resolve(\".\");\n\n try {\n const config = await readConfig(workspacePath);\n if (!config) {\n console.log(\"AlfeSync not initialized. Run: alfesync init\");\n return;\n }\n\n const client = createApiClient({\n apiUrl: config.apiUrl,\n token: config.token,\n agentId: config.agentId,\n });\n\n const [localManifest, remoteManifest, stats] = await Promise.all([\n readManifest(workspacePath),\n client.getManifest(),\n client.getStats(),\n ]);\n\n const diff = diffManifests(localManifest, remoteManifest);\n\n console.log(\"AlfeSync Status\");\n console.log(\"═══════════════\");\n console.log(`Agent: ${config.agentId}`);\n console.log(`Workspace: ${workspacePath}`);\n console.log(`API: ${config.apiUrl}`);\n console.log(\"\");\n\n console.log(\"Storage:\");\n console.log(\n ` Standard: ${formatBytes(stats.standardBytes)}`,\n );\n console.log(\n ` Glacier IR: ${formatBytes(stats.glacierBytes)}`,\n );\n console.log(` Total files: ${String(stats.fileCount)}`);\n console.log(\n ` Last sync: ${stats.lastSyncAt ?? \"never\"}`,\n );\n console.log(\"\");\n\n console.log(\"Pending Changes:\");\n console.log(` To push: ${String(diff.toPush.length)}`);\n console.log(` To pull: ${String(diff.toPull.length)}`);\n console.log(` Conflicts: ${String(diff.conflicts.length)}`);\n\n if (diff.toPush.length > 0) {\n console.log(\"\");\n console.log(\"Files to push:\");\n for (const p of diff.toPush.slice(0, 20)) {\n console.log(` ↑ ${p}`);\n }\n if (diff.toPush.length > 20) {\n console.log(` ... and ${String(diff.toPush.length - 20)} more`);\n }\n }\n\n if (diff.toPull.length > 0) {\n console.log(\"\");\n console.log(\"Files to pull:\");\n for (const p of diff.toPull.slice(0, 20)) {\n console.log(` ↓ ${p}`);\n }\n if (diff.toPull.length > 20) {\n console.log(` ... and ${String(diff.toPull.length - 20)} more`);\n }\n }\n\n if (diff.conflicts.length > 0) {\n console.log(\"\");\n console.log(\"Conflicts:\");\n for (const p of diff.conflicts) {\n console.log(` ⚡ ${p}`);\n }\n }\n } catch (err) {\n console.error(\n err instanceof Error ? err.message : String(err),\n );\n process.exit(1);\n }\n });\n\n// ─── conflicts ────────────────────────────────────────────\n\nprogram\n .command(\"conflicts\")\n .description(\"List conflict files in the workspace\")\n .action(async () => {\n const workspacePath = resolve(\".\");\n\n try {\n const conflicts = await findConflictFiles(workspacePath);\n if (conflicts.length === 0) {\n console.log(\"No conflict files found.\");\n return;\n }\n\n console.log(`Found ${String(conflicts.length)} conflict file(s):`);\n for (const f of conflicts) {\n console.log(` ⚡ ${f}`);\n }\n } catch (err) {\n console.error(\n err instanceof Error ? err.message : String(err),\n );\n process.exit(1);\n }\n });\n\n// ─── history ──────────────────────────────────────────────\n\nprogram\n .command(\"history <file>\")\n .description(\"Show version history for a file\")\n .action(async (file: string) => {\n const workspacePath = resolve(\".\");\n\n try {\n const config = await readConfig(workspacePath);\n if (!config) {\n console.log(\"AlfeSync not initialized. Run: alfesync init\");\n return;\n }\n\n const client = createApiClient({\n apiUrl: config.apiUrl,\n token: config.token,\n agentId: config.agentId,\n });\n\n const versions = await client.getFileHistory(file);\n if (versions.length === 0) {\n console.log(`No history found for: ${file}`);\n return;\n }\n\n console.log(`Version history for: ${file}`);\n console.log(\"─\".repeat(60));\n for (const v of versions) {\n const marker = v.isLatest ? \" (latest)\" : \"\";\n console.log(\n ` ${v.lastModified} ${formatBytes(v.size)} ${v.versionId.slice(0, 12)}${marker}`,\n );\n }\n } catch (err) {\n console.error(\n err instanceof Error ? err.message : String(err),\n );\n process.exit(1);\n }\n });\n\n// ─── restore ──────────────────────────────────────────────\n\nprogram\n .command(\"restore\")\n .description(\"Restore agent workspace from remote backup\")\n .option(\n \"-m, --mode <mode>\",\n \"Restore mode: full, active, memory\",\n \"full\",\n )\n .option(\"-q, --quiet\", \"Suppress output\")\n .action(async (opts: { mode?: string; quiet?: boolean }) => {\n const workspacePath = resolve(\".\");\n\n try {\n const config = await readConfig(workspacePath);\n if (!config) {\n console.log(\"AlfeSync not initialized. Run: alfesync init\");\n return;\n }\n\n const mode = opts.mode as \"full\" | \"active\" | \"memory\";\n if (![\"full\", \"active\", \"memory\"].includes(mode)) {\n console.error(\"Error: mode must be full, active, or memory\");\n process.exit(1);\n }\n\n const client = createApiClient({\n apiUrl: config.apiUrl,\n token: config.token,\n agentId: config.agentId,\n });\n\n if (!opts.quiet) {\n console.log(`Restoring workspace (mode: ${mode})...`);\n }\n\n const bundle = await client.reconstruct(mode);\n\n if (!opts.quiet) {\n console.log(\n `Downloading ${String(bundle.fileCount)} files (${formatBytes(bundle.totalSize)})...`,\n );\n }\n\n // Download each file from the bundle's presigned URLs\n const { writeFile, mkdir } = await import(\"node:fs/promises\");\n const { dirname } = await import(\"node:path\");\n\n let downloaded = 0;\n let errors = 0;\n\n for (const file of bundle.files) {\n try {\n const response = await fetch(file.url);\n if (!response.ok) {\n throw new Error(`HTTP ${String(response.status)}`);\n }\n\n const buffer = Buffer.from(await response.arrayBuffer());\n const absolutePath = join(workspacePath, file.path);\n await mkdir(dirname(absolutePath), { recursive: true });\n await writeFile(absolutePath, buffer);\n\n downloaded++;\n if (!opts.quiet) {\n console.log(\n ` ↓ ${file.path} (${formatBytes(file.size)})`,\n );\n }\n } catch (err) {\n errors++;\n if (!opts.quiet) {\n console.error(\n ` ✗ ${file.path}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n }\n\n if (!opts.quiet) {\n console.log(\n `\\nRestore complete: ${String(downloaded)} files downloaded, ${String(errors)} errors.`,\n );\n }\n } catch (err) {\n console.error(\n err instanceof Error ? err.message : String(err),\n );\n process.exit(1);\n }\n });\n\n// ─── Helpers ──────────────────────────────────────────────\n\nasync function findConflictFiles(\n dir: string,\n base?: string,\n): Promise<string[]> {\n const results: string[] = [];\n const entries = await readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n if (\n entry.name === \"node_modules\" ||\n entry.name === \".git\" ||\n entry.name === \".alfesync\"\n ) {\n continue;\n }\n\n const fullPath = join(dir, entry.name);\n const relativePath = base\n ? join(base, entry.name)\n : entry.name;\n\n if (entry.isDirectory()) {\n const sub = await findConflictFiles(fullPath, relativePath);\n results.push(...sub);\n } else if (entry.name.includes(\".conflict-\")) {\n results.push(relativePath);\n }\n }\n\n return results;\n}\n\nfunction formatBytes(bytes: number): string {\n if (bytes < 1024) return `${String(bytes)} B`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n if (bytes < 1024 * 1024 * 1024)\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;\n}\n\n// ─── Run ──────────────────────────────────────────────────\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,MAAM,UAAU,IAAI,SAAS;AAE7B,QACG,KAAK,WAAW,CAChB,YAAY,6CAA6C,CACzD,QAAQ,QAAQ;AAInB,QACG,QAAQ,OAAO,CACf,YAAY,+CAA+C,CAC3D,OAAO,uBAAuB,4BAA4B,CAC1D,OAAO,uBAAuB,oBAAoB,sBAAsB,CACxE,OAAO,uBAAuB,8BAA8B,CAC5D,OAAO,6BAA6B,6BAA6B,CACjE,OAAO,OAAO,SAAsF;CACnG,MAAM,gBAAgB,QAAQ,IAAI;AAElC,KAAI,cAAc,cAAc,EAAE;AAChC,UAAQ,IAAI,qDAAqD;EACjE,MAAM,WAAW,MAAM,WAAW,cAAc;AAChD,MAAI,UAAU;AACZ,WAAQ,IAAI,YAAY,SAAS,UAAU;AAC3C,WAAQ,IAAI,YAAY,SAAS,SAAS;;AAE5C;;CAGF,MAAM,QAAQ,KAAK,SAAS,QAAQ,IAAI;CACxC,MAAM,SAAS,KAAK,UAAU,QAAQ,IAAI,oBAAoB;CAC9D,MAAM,UAAU,KAAK,WAAW,QAAQ,IAAI;AAE5C,KAAI,CAAC,OAAO;AACV,UAAQ,MACN,6DACD;AACD,UAAQ,KAAK,EAAE;;AAEjB,KAAI,CAAC,SAAS;AACZ,UAAQ,MACN,mEACD;AACD,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AK,MAAM,SAAS,SAAS;AAC3B,MACE,MAAM,SAAS,kBACf,MAAM,SAAS,UACf,MAAM,SAAS,YAEf;EAGF,MAAM,WAAW,KAAK,KAAK,MAAM,KAAK;EACtC,MAAM,eAAe,OACjB,KAAK,MAAM,MAAM,KAAK,GACtB,MAAM;AAEV,MAAI,MAAM,aAAa,EAAE;GACvB,MAAM,MAAM,MAAM,kBAAkB,UAAU,aAAa;AAC3D,WAAQ,KAAK,GAAG,IAAI;aACX,MAAM,KAAK,SAAS,aAAa,CAC1C,SAAQ,KAAK,aAAa;;AAI9B,QAAO;;AAGT,SAAS,YAAY,OAAuB;AAC1C,KAAI,QAAQ,KAAM,QAAO,GAAG,OAAO,MAAM,CAAC;AAC1C,KAAI,QAAQ,OAAO,KAAM,QAAO,IAAI,QAAQ,MAAM,QAAQ,EAAE,CAAC;AAC7D,KAAI,QAAQ,OAAO,OAAO,KACxB,QAAO,IAAI,SAAS,OAAO,OAAO,QAAQ,EAAE,CAAC;AAC/C,QAAO,IAAI,SAAS,OAAO,OAAO,OAAO,QAAQ,EAAE,CAAC;;AAKtD,QAAQ,OAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * AlfeSync CLI — alfesync command-line interface.\n *\n * Credentials come from `~/.alfe/config.toml` (set up via `alfe login`).\n * No separate sync init step is required.\n *\n * Commands:\n * register - Register this agent with the sync service (one-time)\n * push - Push local changes to remote\n * pull - Pull remote changes to local\n * status - Show sync status and pending changes\n * conflicts - List conflict files\n * history - Show version history for a file\n * restore - Restore agent workspace from remote\n */\n\nimport { Command } from \"commander\";\nimport { join } from \"node:path\";\nimport { readdir } from \"node:fs/promises\";\nimport { requireConfig } from \"../config.js\";\nimport { createApiClient } from \"../api-client.js\";\nimport { createSyncEngine } from \"../sync-engine.js\";\nimport { readManifest, diffManifests } from \"../manifest.js\";\n\n\nconst program = new Command();\n\nprogram\n .name(\"alfesync\")\n .description(\"AlfeSync — agent workspace backup and sync\")\n .version(\"1.0.0\");\n\n// ─── register ─────────────────────────────────────────────\n\nprogram\n .command(\"register\")\n .description(\"Register this agent with the sync service (one-time)\")\n .option(\"-n, --display-name <name>\", \"Display name for the agent\")\n .action(async (opts: { displayName?: string }) => {\n try {\n const config = await requireConfig();\n const client = createApiClient({\n apiUrl: config.apiUrl,\n token: config.token,\n agentId: config.agentId,\n });\n\n const result = await client.registerAgent(opts.displayName ?? config.agentId);\n console.log(\"✓ Agent registered with AlfeSync\");\n console.log(` Agent: ${config.agentId}`);\n console.log(` Org: ${result.agent.orgId}`);\n console.log(` API: ${config.apiUrl}`);\n console.log(` Workspace: ${config.workspacePath}`);\n } catch (err) {\n console.error(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n\n// ─── push ─────────────────────────────────────────────────\n\nprogram\n .command(\"push\")\n .description(\"Push local changes to remote\")\n .option(\"-q, --quiet\", \"Suppress output\")\n .option(\"-f, --filter <prefix>\", \"Only push files matching this prefix\")\n .action(async (opts: { quiet?: boolean; filter?: string }) => {\n try {\n const engine = await createSyncEngine();\n await engine.push(undefined, {\n quiet: opts.quiet,\n filter: opts.filter,\n });\n } catch (err) {\n console.error(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n\n// ─── pull ─────────────────────────────────────────────────\n\nprogram\n .command(\"pull\")\n .description(\"Pull remote changes to local\")\n .option(\"-q, --quiet\", \"Suppress output\")\n .action(async (opts: { quiet?: boolean }) => {\n try {\n const engine = await createSyncEngine();\n await engine.pull({ quiet: opts.quiet });\n } catch (err) {\n console.error(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n\n// ─── status ───────────────────────────────────────────────\n\nprogram\n .command(\"status\")\n .description(\"Show sync status and pending changes\")\n .action(async () => {\n try {\n const config = await requireConfig();\n const client = createApiClient({\n apiUrl: config.apiUrl,\n token: config.token,\n agentId: config.agentId,\n });\n\n const [localManifest, remoteManifest, stats] = await Promise.all([\n readManifest(config.workspacePath),\n client.getManifest(),\n client.getStats(),\n ]);\n\n const diff = diffManifests(localManifest, remoteManifest);\n\n console.log(\"AlfeSync Status\");\n console.log(\"═══════════════\");\n console.log(`Agent: ${config.agentId}`);\n console.log(`Workspace: ${config.workspacePath}`);\n console.log(`API: ${config.apiUrl}`);\n console.log(\"\");\n\n console.log(\"Storage:\");\n console.log(` Standard: ${formatBytes(stats.standardBytes)}`);\n console.log(` Glacier IR: ${formatBytes(stats.glacierBytes)}`);\n console.log(` Total files: ${String(stats.fileCount)}`);\n console.log(` Last sync: ${stats.lastSyncAt ?? \"never\"}`);\n console.log(\"\");\n\n console.log(\"Pending Changes:\");\n console.log(` To push: ${String(diff.toPush.length)}`);\n console.log(` To pull: ${String(diff.toPull.length)}`);\n console.log(` Conflicts: ${String(diff.conflicts.length)}`);\n\n if (diff.toPush.length > 0) {\n console.log(\"\");\n console.log(\"Files to push:\");\n for (const p of diff.toPush.slice(0, 20)) {\n console.log(` ↑ ${p}`);\n }\n if (diff.toPush.length > 20) {\n console.log(` ... and ${String(diff.toPush.length - 20)} more`);\n }\n }\n\n if (diff.toPull.length > 0) {\n console.log(\"\");\n console.log(\"Files to pull:\");\n for (const p of diff.toPull.slice(0, 20)) {\n console.log(` ↓ ${p}`);\n }\n if (diff.toPull.length > 20) {\n console.log(` ... and ${String(diff.toPull.length - 20)} more`);\n }\n }\n\n if (diff.conflicts.length > 0) {\n console.log(\"\");\n console.log(\"Conflicts:\");\n for (const p of diff.conflicts) {\n console.log(` ⚡ ${p}`);\n }\n }\n } catch (err) {\n console.error(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n\n// ─── conflicts ────────────────────────────────────────────\n\nprogram\n .command(\"conflicts\")\n .description(\"List conflict files in the workspace\")\n .action(async () => {\n try {\n const config = await requireConfig();\n const conflicts = await findConflictFiles(config.workspacePath);\n if (conflicts.length === 0) {\n console.log(\"No conflict files found.\");\n return;\n }\n\n console.log(`Found ${String(conflicts.length)} conflict file(s):`);\n for (const f of conflicts) {\n console.log(` ⚡ ${f}`);\n }\n } catch (err) {\n console.error(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n\n// ─── history ──────────────────────────────────────────────\n\nprogram\n .command(\"history <file>\")\n .description(\"Show version history for a file\")\n .action(async (file: string) => {\n try {\n const config = await requireConfig();\n const client = createApiClient({\n apiUrl: config.apiUrl,\n token: config.token,\n agentId: config.agentId,\n });\n\n const versions = await client.getFileHistory(file);\n if (versions.length === 0) {\n console.log(`No history found for: ${file}`);\n return;\n }\n\n console.log(`Version history for: ${file}`);\n console.log(\"─\".repeat(60));\n for (const v of versions) {\n const marker = v.isLatest ? \" (latest)\" : \"\";\n console.log(\n ` ${v.lastModified} ${formatBytes(v.size)} ${v.versionId.slice(0, 12)}${marker}`,\n );\n }\n } catch (err) {\n console.error(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n\n// ─── restore ──────────────────────────────────────────────\n\nprogram\n .command(\"restore\")\n .description(\"Restore agent workspace from remote backup\")\n .option(\n \"-m, --mode <mode>\",\n \"Restore mode: full, active, memory\",\n \"full\",\n )\n .option(\"-q, --quiet\", \"Suppress output\")\n .action(async (opts: { mode?: string; quiet?: boolean }) => {\n try {\n const config = await requireConfig();\n const mode = opts.mode as \"full\" | \"active\" | \"memory\";\n if (![\"full\", \"active\", \"memory\"].includes(mode)) {\n console.error(\"Error: mode must be full, active, or memory\");\n process.exit(1);\n }\n\n const client = createApiClient({\n apiUrl: config.apiUrl,\n token: config.token,\n agentId: config.agentId,\n });\n\n if (!opts.quiet) {\n console.log(`Restoring workspace (mode: ${mode})...`);\n }\n\n const bundle = await client.reconstruct(mode);\n\n if (!opts.quiet) {\n console.log(\n `Downloading ${String(bundle.fileCount)} files (${formatBytes(bundle.totalSize)})...`,\n );\n }\n\n // Download each file from the bundle's presigned URLs\n const { writeFile, mkdir } = await import(\"node:fs/promises\");\n const { dirname } = await import(\"node:path\");\n\n let downloaded = 0;\n let errors = 0;\n\n for (const file of bundle.files) {\n try {\n const response = await fetch(file.url);\n if (!response.ok) {\n throw new Error(`HTTP ${String(response.status)}`);\n }\n\n const buffer = Buffer.from(await response.arrayBuffer());\n const absolutePath = join(config.workspacePath, file.path);\n await mkdir(dirname(absolutePath), { recursive: true });\n await writeFile(absolutePath, buffer);\n\n downloaded++;\n if (!opts.quiet) {\n console.log(` ↓ ${file.path} (${formatBytes(file.size)})`);\n }\n } catch (err) {\n errors++;\n if (!opts.quiet) {\n console.error(\n ` ✗ ${file.path}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n }\n\n if (!opts.quiet) {\n console.log(\n `\\nRestore complete: ${String(downloaded)} files downloaded, ${String(errors)} errors.`,\n );\n }\n } catch (err) {\n console.error(err instanceof Error ? err.message : String(err));\n process.exit(1);\n }\n });\n\n// ─── Helpers ──────────────────────────────────────────────\n\nasync function findConflictFiles(\n dir: string,\n base?: string,\n): Promise<string[]> {\n const results: string[] = [];\n const entries = await readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n if (\n entry.name === \"node_modules\" ||\n entry.name === \".git\"\n ) {\n continue;\n }\n\n const fullPath = join(dir, entry.name);\n const relativePath = base\n ? join(base, entry.name)\n : entry.name;\n\n if (entry.isDirectory()) {\n const sub = await findConflictFiles(fullPath, relativePath);\n results.push(...sub);\n } else if (entry.name.includes(\".conflict-\")) {\n results.push(relativePath);\n }\n }\n\n return results;\n}\n\nfunction formatBytes(bytes: number): string {\n if (bytes < 1024) return `${String(bytes)} B`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n if (bytes < 1024 * 1024 * 1024)\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;\n}\n\n// ─── Run ──────────────────────────────────────────────────\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,UAAU,IAAI,SAAS;AAE7B,QACG,KAAK,WAAW,CAChB,YA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AS,aAAa,CAC1C,SAAQ,KAAK,aAAa;;AAI9B,QAAO;;AAGT,SAAS,YAAY,OAAuB;AAC1C,KAAI,QAAQ,KAAM,QAAO,GAAG,OAAO,MAAM,CAAC;AAC1C,KAAI,QAAQ,OAAO,KAAM,QAAO,IAAI,QAAQ,MAAM,QAAQ,EAAE,CAAC;AAC7D,KAAI,QAAQ,OAAO,OAAO,KACxB,QAAO,IAAI,SAAS,OAAO,OAAO,QAAQ,EAAE,CAAC;AAC/C,QAAO,IAAI,SAAS,OAAO,OAAO,OAAO,QAAQ,EAAE,CAAC;;AAKtD,QAAQ,OAAO"}
package/dist/ignore.cjs CHANGED
@@ -29,9 +29,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  enumerable: true
30
30
  }) : target, mod));
31
31
  //#endregion
32
- let node_fs_promises = require("node:fs/promises");
33
- let node_fs = require("node:fs");
34
32
  let node_path = require("node:path");
33
+ let node_fs = require("node:fs");
34
+ let node_fs_promises = require("node:fs/promises");
35
35
  let micromatch = require("micromatch");
36
36
  micromatch = __toESM(micromatch);
37
37
  //#region src/ignore.ts
package/dist/ignore.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "node:module";
2
- import { readFile } from "node:fs/promises";
3
- import { existsSync } from "node:fs";
4
2
  import { join } from "node:path";
3
+ import { existsSync } from "node:fs";
4
+ import { readFile } from "node:fs/promises";
5
5
  import micromatch from "micromatch";
6
6
  //#region \0rolldown/runtime.js
7
7
  var __defProp = Object.defineProperty;