11import fs from "node:fs/promises" ;
2- import path from "node:path" ;
32import { resolveConfiguredAgentId } from "../agents/agent-scope-config.js" ;
43import { getRuntimeConfig } from "../config/config.js" ;
54import { resolveStateDir } from "../config/paths.js" ;
@@ -18,7 +17,8 @@ import { recordBackupRunOutcome } from "../state/backup-run-records.js";
1817import { listOpenClawRegisteredAgentDatabases } from "../state/openclaw-agent-db.js" ;
1918import { resolveOpenClawAgentSqlitePath } from "../state/openclaw-agent-db.paths.js" ;
2019import { resolveOpenClawStateSqlitePath } from "../state/openclaw-state-db.paths.js" ;
21- import { resolveUserPath , shortenHomePath } from "../utils.js" ;
20+ import { shortenHomePath } from "../utils.js" ;
21+ import { resolveRequiredBackupPath } from "./backup-shared.js" ;
2222
2323type BackupGitCreateOptions = {
2424 repository ?: string ;
@@ -38,14 +38,6 @@ type BackupGitScopeOptions = {
3838export const GIT_BACKUP_PUSH_CREDENTIAL_WARNING =
3939 "Warning: pushed backup history contains credential material; keep the Git remote private." ;
4040
41- function resolveRequiredPath ( value : string | undefined , label : string ) : string {
42- const trimmed = value ?. trim ( ) ;
43- if ( ! trimmed ) {
44- throw new Error ( `Missing required ${ label } value.` ) ;
45- }
46- return path . resolve ( resolveUserPath ( trimmed ) ) ;
47- }
48-
4941async function resolveCreateDatabases ( runtime : RuntimeEnv , options : BackupGitCreateOptions ) {
5042 const normalizedAgents = [
5143 ...new Set (
@@ -151,7 +143,7 @@ export async function backupGitInitCommand(
151143 options : { repository ?: string ; remote ?: string ; json ?: boolean } ,
152144) : Promise < { repositoryPath : string } > {
153145 const result = await initializeGitBackupRepository ( {
154- repositoryPath : resolveRequiredPath ( options . repository , "--repository" ) ,
146+ repositoryPath : resolveRequiredBackupPath ( options . repository , "--repository" ) ,
155147 stateDir : resolveStateDir ( ) ,
156148 remote : options . remote ,
157149 } ) ;
@@ -164,7 +156,7 @@ export async function backupGitInitCommand(
164156}
165157
166158export async function backupGitCreateCommand ( runtime : RuntimeEnv , options : BackupGitCreateOptions ) {
167- const repositoryPath = resolveRequiredPath ( options . repository , "--repository" ) ;
159+ const repositoryPath = resolveRequiredBackupPath ( options . repository , "--repository" ) ;
168160 if ( options . push && ! options . excludeSecrets ) {
169161 runtime . error ( GIT_BACKUP_PUSH_CREDENTIAL_WARNING ) ;
170162 }
@@ -211,7 +203,7 @@ export async function backupGitLogCommand(
211203 runtime : RuntimeEnv ,
212204 options : { repository ?: string ; limit ?: number ; json ?: boolean } ,
213205) {
214- const repositoryPath = resolveRequiredPath ( options . repository , "--repository" ) ;
206+ const repositoryPath = resolveRequiredBackupPath ( options . repository , "--repository" ) ;
215207 const limit = options . limit ?? 20 ;
216208 if ( ! Number . isSafeInteger ( limit ) || limit < 1 ) {
217209 throw new Error ( "--limit must be a positive integer." ) ;
@@ -234,7 +226,7 @@ export async function backupGitVerifyCommand(
234226 options : BackupGitScopeOptions & { repository ?: string ; ref ?: string ; json ?: boolean } ,
235227) {
236228 const result = await verifyGitBackupRef ( {
237- repositoryPath : resolveRequiredPath ( options . repository , "--repository" ) ,
229+ repositoryPath : resolveRequiredBackupPath ( options . repository , "--repository" ) ,
238230 identity : resolveOneIdentity ( options ) ,
239231 ref : options . ref ,
240232 } ) ;
@@ -259,10 +251,10 @@ export async function backupGitRestoreCommand(
259251 } ,
260252) {
261253 const result = await restoreGitBackupRef ( {
262- repositoryPath : resolveRequiredPath ( options . repository , "--repository" ) ,
254+ repositoryPath : resolveRequiredBackupPath ( options . repository , "--repository" ) ,
263255 identity : resolveOneIdentity ( options ) ,
264256 ref : options . ref ,
265- targetPath : resolveRequiredPath ( options . target , "--target" ) ,
257+ targetPath : resolveRequiredBackupPath ( options . target , "--target" ) ,
266258 } ) ;
267259 if ( options . json ) {
268260 writeRuntimeJson ( runtime , result ) ;
0 commit comments