import { join } from 'node:path'; import { tryAcquireRuntimeLock } from '@myclaw163/game-agent-runtime/owner/runtime-lock.js'; import { AuthStore } from './auth.js'; import { getWorkspaceDir } from './init-command.js'; import { getUserDataAccountDir } from './user-data.js'; /** 终端与各客户端共用账号资源;进程退出时操作系统释放写锁。 */ export function acquireAccountResourceLock() { const profile = new AuthStore().getActive(); if (!profile) return; const lock = tryAcquireRuntimeLock(join(getUserDataAccountDir(getWorkspaceDir(), profile), '.resource-lock')); if (!lock) throw new Error('ACCOUNT_RESOURCES_BUSY: another command is using this account’s resources. Retry after it finishes.'); return lock; }