@gajae-gateway/cli 0.1.8 → 0.2.1

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.
@@ -5,7 +5,6 @@ import {
5
5
  cronMonitor,
6
6
  deliveryOrigin,
7
7
  emitChannels,
8
- emitImportedAxis,
9
8
  emitMonitors,
10
9
  emptyChannelPlan,
11
10
  emptyExtract,
@@ -107,7 +106,6 @@ export async function readHermes(tree: SourceTree, home: string): Promise<Source
107
106
  content: entriesToMarkdown("Long-term memory (imported from Hermes)", memoryText),
108
107
  mtime: info?.mtime,
109
108
  });
110
- emitImportedAxis(extract);
111
109
  }
112
110
 
113
111
  const envPath = join(root, ".env");
package/src/migrate.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { mkdir, readFile, writeFile } from "node:fs/promises";
1
+ import { randomUUID } from "node:crypto";
2
+ import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
2
3
  import { join } from "node:path";
4
+ import { acquireLease, type Lease, LeaseHeldError } from "@gajae-gateway/home";
3
5
  import { detectHermes, readHermes } from "./migrate/hermes";
4
6
  import { detectOpenClaw, readOpenClaw } from "./migrate/openclaw";
5
7
  import {
@@ -23,9 +25,26 @@ export interface MigrateOptions {
23
25
  * reads its configuration, and writes the gajae-way-compatible output.
24
26
  */
25
27
  export async function migrate(options: MigrateOptions): Promise<void> {
26
- const sourceRoot = expandHome(options.source ?? ".");
27
- const targetHome = expandHome(options.target ?? `${process.env.HOME ?? "~"}/.gajaeway`);
28
+ const targetHome = expandHome(options.target ?? process.env.GAJAEWAY_HOME ?? `${process.env.HOME ?? "~"}/.gajaeway`);
29
+ if (options.dryRun) return migrateUnlocked(options, targetHome);
30
+
31
+ let lease: Lease;
32
+ try {
33
+ lease = await acquireLease(targetHome, "memory");
34
+ } catch (error) {
35
+ if (error instanceof LeaseHeldError)
36
+ throw new Error(`${error.message}; stop the gateway first before importing memory data`, { cause: error });
37
+ throw error;
38
+ }
39
+ try {
40
+ await migrateUnlocked(options, targetHome);
41
+ } finally {
42
+ await lease.release();
43
+ }
44
+ }
28
45
 
46
+ async function migrateUnlocked(options: MigrateOptions, targetHome: string): Promise<void> {
47
+ const sourceRoot = expandHome(options.source ?? ".");
29
48
  // Detect source type
30
49
  let sourceType: MigrationSource | undefined;
31
50
  if (await detectHermes(sourceRoot)) {
@@ -109,7 +128,20 @@ export async function migrate(options: MigrateOptions): Promise<void> {
109
128
  for (const file of extract.files) {
110
129
  const filePath = join(targetHome, file.target);
111
130
  await mkdir(join(filePath, ".."), { recursive: true });
112
- await writeFile(filePath, file.content);
131
+ if (file.secret) {
132
+ // Atomic 0600 write for secrets
133
+ const temporary = `${filePath}.${randomUUID()}.tmp`;
134
+ try {
135
+ await writeFile(temporary, file.content, { mode: 0o600 });
136
+ await chmod(temporary, 0o600);
137
+ await rename(temporary, filePath);
138
+ } catch (error) {
139
+ await rm(temporary, { force: true });
140
+ throw error;
141
+ }
142
+ } else {
143
+ await writeFile(filePath, file.content);
144
+ }
113
145
  }
114
146
 
115
147
  // Write merged JSON files