Files
Hermes-ui/packages/server/src/services/hermes/hermes-cli.ts
T
ekko 884b6973e3 Release v0.5.8 (#424)
* fix: add missing i18n key and unify session data source (#408)

- Add `chat.sessionNotFound` translation key to all 8 locales
- Fix history page data source inconsistency:
  - Change `getHermesSession` to prioritize database over CLI
  - Now consistent with `listHermesSessions` behavior
  - Prevents "session in list but detail not found" issue
- Update CI workflow to trigger on base branch PRs
- Remove debug log from sessions-db

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: filter special characters and emoji in speech playback (#409)

- Update extractReadableText to filter special characters like *#
- Only keep common punctuation marks for speech synthesis
- Remove emoji, symbols, and special unicode characters
- Improve text-to-speech readability

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: add drawer panel with mobile sidebar support and customizable button (#412)

* feat: add drawer panel with mobile sidebar support

- Add DrawerPanel component with Terminal and Files tabs
- Extract TerminalPanel and FilesPanel from existing views
- Add mobile sidebar toggle functionality with overlay
- Add rainbow breathing light effect to drawer button
- Remove Tools section from AppSidebar (Terminal/Files entries)
- Add i18n support for drawer and file tree
- Optimize mobile button layout and spacing
- Fix z-index hierarchy for proper layering
- Add responsive sidebar behavior (PC: always visible, Mobile: toggle)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: customize drawer button with arc rainbow border

- Change drawer button to semi-circle shape贴着右边
- Add arrow icon pointing left (向左箭头)
- Add rainbow border from top to bottom through semi-circle arc
- Slow down animation from 4s to 8s for smoother effect
- Move drawer button wrapper to messages area only (not贯穿header和input)
- Add semi-transparent accent color background to button

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: resolve profile switching state sync issue (#414) (#415)

* fix: resolve profile switching state sync issue (#414)

Fix bug where switching to a different profile would still show the
old profile name in the UI and prevent switching back to default.

Root cause:
- Frontend relied entirely on fetchProfiles() return value to set
  activeProfileName
- Backend Hermes CLI may return stale active flag due to timing
  issues between profile use and profile list commands
- This caused frontend to display wrong profile and prevented
  switching back to default

Solution:
- Immediately set activeProfileName when switchProfile API succeeds
- Don't rely solely on listProfiles() result which may have stale data
- Use activeProfileName instead of activeProfile?.name in ProfileSelector

Changes:
- profiles store: Set activeProfileName immediately after successful switch
- ProfileSelector: Use activeProfileName computed property
- Add test to verify activeProfileName updates on switch

Fixes #414

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refine: improve error handling for profile switching failures

Add proper error handling for edge cases:
- If fetchProfiles() fails after successful switch, keep the updated
  activeProfileName (don't let fetchProfiles failure undo the switch)
- Add test cases to verify:
  1. API failure doesn't change state
  2. fetchProfiles failure doesn't affect successful switch

This ensures the UI remains consistent even when profile list refresh
fails after a successful profile switch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refine: add rollback mechanism for profile switching verification

Add backend verification after profile switch:
- Save old activeProfileName before setting new value
- After fetchProfiles, verify backend reports expected active profile
- If backend reports different profile, rollback frontend state and return false
- This handles edge case where API returns 200 but backend didn't actually switch

Test cases:
-  Normal switch: updates and verifies successfully
-  API failure: doesn't change state
-  fetchProfiles failure: assumes success (API returned 200)
-  Backend verification fails: rolls back to old profile

This ensures frontend state always matches backend reality, even in
edge cases where hermes profile use succeeded but gateway/cleanup
steps failed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refine: add user feedback for profile operations

Improve user experience with success/error messages:
- ProfileSelector: Add error message when switch fails
- ProfileCard: Add success message before reload on switch
- ProfileSelector: Use async/await for better error handling
- ProfileCard: Add 500ms delay before reload to show success message

Before: Silent failures, no feedback
After: Clear success/error messages for all operations

Example feedback:
- Success: "已切换到配置 qinghe"
- Failure: "切换配置失败,网关可能需要手动重启"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs: update frontend changelog for v0.5.7 (#419)

* docs: update frontend changelog for v0.5.7

- Update changelog.ts with v0.5.7 release date and changes
- Add i18n translation keys for all languages (en, zh, de, es, fr, ja, ko, pt)
- Include v0.5.7 changelog entries:
  - Optimize context compression and session sync
  - Add startup delays to prevent database race conditions

Changes:
- packages/client/src/data/changelog.ts: Update v0.5.7 entry
- packages/client/src/i18n/locales/*.ts: Add changelog translation section

This enables the changelog modal in the UI to display v0.5.7 release notes.

* feat: add v0.5.7 changelog translations to all supported languages

Add new_0_5_7_1, new_0_5_7_2, and new_0_5_7_3 changelog entries to all
locale files (en, zh, de, es, fr, ja, ko, pt) with proper translations
for each language.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: remove duplicate changelog sections causing syntax errors

Remove duplicate changelog object sections that were causing TypeScript
syntax errors in all locale files (en, zh, de, es, fr, ja, ko, pt).
The actual changelog entries are already correctly placed in the main
changelog section of each file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: add v0.5.8 changelog and fix profile parsing issue

Add v0.5.8 changelog entries based on PRs merged since v0.5.7:
- Drawer panel with mobile sidebar support (#412)
- Profile switching state sync fix (#414)
- Speech playback special character filtering (#409)
- Missing i18n key and session data source unification (#408)
- Vite build optimization for faster Docker builds (#403)

Also fix issue #417: Profile names with long hyphenated names fail
to parse in profile list regex. Change \s{2,} to \s+ to handle
compressed column spacing when profile names are long.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: remove enter key submit from profile creation and rename modals

Remove @keyup.enter handlers from NInput components in:
- ProfileCreateModal: prevent accidental profile creation when pressing enter
- ProfileRenameModal: prevent accidental profile rename when pressing enter

Users must now explicitly click the confirm button to submit, preventing
unintended profile operations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: allow free text input for profile names

Remove frontend character filtering from profile creation and rename
modals. Users can now input any characters including spaces and
uppercase letters to test backend Hermes CLI validation.

Changes:
- ProfileCreateModal: Remove toLowerCase() and character filtering
- ProfileRenameModal: Remove toLowerCase() and character filtering
- Use v-model:value binding instead of :value with @input

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: improve error handling for profile creation

Display backend error messages when profile creation fails instead of
generic "failed" message. This helps users understand why their
profile name was rejected (e.g., invalid characters).

Changes:
- API layer: Capture and return error messages from backend
- ProfileCreateModal: Display specific error message from backend

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: add profile name validation with i18n support

Add client-side validation for profile names to prevent invalid input
before sending to backend. Only lowercase letters, numbers, underscores,
and hyphens are allowed.

Changes:
- ProfileCreateModal: Add input validation with real-time feedback
- ProfileRenameModal: Add input validation with real-time feedback
- Add nameValidation i18n key for all 8 languages
- Filter invalid characters on input and show warning message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: revert profile parsing regex changes

Revert the regex changes in hermes-cli.ts and gateway-manager.ts
back to requiring \s{2,} (at least 2 spaces). Since frontend now
validates profile names to only allow lowercase letters, numbers,
underscores, and hyphens, the relaxed regex is no longer needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: revert profile parsing regex changes

Revert the regex changes in gateway-manager.ts and hermes-cli.ts
back to requiring \s{2,} (at least 2 spaces). Since frontend now
validates profile names to only allow lowercase letters, numbers,
underscores, and hyphens, the relaxed regex is no longer needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: remove tooltip from drawer button

Remove the NTooltip wrapper from the floating drawer button.
The "Terminal & Files" tooltip is no longer shown on hover.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* Update assets images (#421)

Updated two asset images in the client package.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* chore: bump version to 0.5.8

Release v0.5.8

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: improve profile list parsing to handle long profile names (#425)

Fixed issue #423 where long profile names caused parsing failures.

Changes:
- gateway-manager.ts: Use `.+?` instead of `\S+` to match profile names, allowing names that overflow table column width
- hermes-cli.ts: Use `\s+` instead of `\s{2,}` for first delimiter to handle cases where long profile names reduce spacing to 1 space

The regex now correctly parses profile output even when profile names are long enough to compress table formatting, ensuring all profiles appear in the UI regardless of name length.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 22:24:57 +08:00

594 lines
16 KiB
TypeScript

import { execFile, spawn } from 'child_process'
import { existsSync } from 'fs'
import { promisify } from 'util'
import { logger } from '../logger'
const execFileAsync = promisify(execFile)
const execOpts = { windowsHide: true }
const isDocker = existsSync('/.dockerenv')
function resolveHermesBin(): string {
const envBin = process.env.HERMES_BIN?.trim()
if (envBin) return envBin
return 'hermes'
}
const HERMES_BIN = resolveHermesBin()
export interface HermesSession {
id: string
source: string
user_id: string | null
model: string
title: string | null
started_at: number
ended_at: number | null
end_reason: string | null
message_count: number
tool_call_count: number
input_tokens: number
output_tokens: number
cache_read_tokens: number
cache_write_tokens: number
reasoning_tokens: number
billing_provider: string | null
estimated_cost_usd: number
actual_cost_usd: number | null
cost_status: string
messages?: any[]
}
export interface HermesSessionFull {
id: string
source: string
user_id: string | null
model: string
title: string | null
started_at: number
ended_at: number | null
end_reason: string | null
message_count: number
tool_call_count: number
input_tokens: number
output_tokens: number
cache_read_tokens?: number
cache_write_tokens?: number
reasoning_tokens?: number
billing_provider: string | null
estimated_cost_usd: number
actual_cost_usd?: number | null
cost_status?: string
messages?: any[]
system_prompt?: string
model_config?: string
cost_source?: string
pricing_version?: string | null
[key: string]: any
}
function parseSessionExport(stdout: string): HermesSessionFull[] {
const lines = stdout.trim().split('\n').filter(Boolean)
const sessions: HermesSessionFull[] = []
for (const line of lines) {
try {
const raw: HermesSessionFull = JSON.parse(line)
sessions.push(raw)
} catch {
// Skip non-JSON lines such as "Session 'x' not found."
}
}
return sessions
}
export async function exportSessionsRaw(source?: string): Promise<HermesSessionFull[]> {
const args = ['sessions', 'export', '-']
if (source) args.push('--source', source)
try {
const { stdout } = await execFileAsync(HERMES_BIN, args, {
maxBuffer: 50 * 1024 * 1024, // 50MB
timeout: 30000,
...execOpts,
})
return parseSessionExport(stdout)
} catch (err: any) {
logger.error(err, 'Hermes CLI: sessions export failed')
throw new Error(`Failed to list sessions: ${err.message}`)
}
}
/**
* List sessions from Hermes CLI (without messages)
*/
export async function listSessions(source?: string, limit?: number): Promise<HermesSession[]> {
const raws = await exportSessionsRaw(source)
const sessions: HermesSession[] = []
for (const raw of raws) {
let title = raw.title
if (!title && raw.messages) {
const firstUser = raw.messages.find((m: any) => m.role === 'user')
if (firstUser?.content) {
const t = String(firstUser.content).slice(0, 40)
title = t + (String(firstUser.content).length > 40 ? '...' : '')
}
}
sessions.push({
id: raw.id,
source: raw.source,
user_id: raw.user_id,
model: raw.model,
title,
started_at: raw.started_at,
ended_at: raw.ended_at,
end_reason: raw.end_reason,
message_count: raw.message_count,
tool_call_count: raw.tool_call_count,
input_tokens: raw.input_tokens,
output_tokens: raw.output_tokens,
cache_read_tokens: raw.cache_read_tokens || 0,
cache_write_tokens: raw.cache_write_tokens || 0,
reasoning_tokens: raw.reasoning_tokens || 0,
billing_provider: raw.billing_provider,
estimated_cost_usd: raw.estimated_cost_usd,
actual_cost_usd: raw.actual_cost_usd ?? null,
cost_status: raw.cost_status || '',
})
}
// Sort by started_at descending
sessions.sort((a, b) => b.started_at - a.started_at)
if (limit && limit > 0) {
return sessions.slice(0, limit)
}
return sessions
}
/**
* Get a single session with messages from Hermes CLI
*/
export async function getSession(id: string): Promise<HermesSession | null> {
const args = ['sessions', 'export', '-', '--session-id', id]
try {
const { stdout } = await execFileAsync(HERMES_BIN, args, {
maxBuffer: 50 * 1024 * 1024,
timeout: 30000,
...execOpts,
})
const raws = parseSessionExport(stdout)
if (raws.length === 0) return null
const raw: HermesSessionFull = raws[0]
return {
id: raw.id,
source: raw.source,
user_id: raw.user_id,
model: raw.model,
title: raw.title,
started_at: raw.started_at,
ended_at: raw.ended_at,
end_reason: raw.end_reason,
message_count: raw.message_count,
tool_call_count: raw.tool_call_count,
input_tokens: raw.input_tokens,
output_tokens: raw.output_tokens,
cache_read_tokens: raw.cache_read_tokens || 0,
cache_write_tokens: raw.cache_write_tokens || 0,
reasoning_tokens: raw.reasoning_tokens || 0,
billing_provider: raw.billing_provider,
estimated_cost_usd: raw.estimated_cost_usd,
actual_cost_usd: raw.actual_cost_usd ?? null,
cost_status: raw.cost_status || '',
messages: raw.messages,
}
} catch (err: any) {
if (err.code === 1 || err.status === 1) return null
logger.error(err, 'Hermes CLI: session export failed')
throw new Error(`Failed to get session: ${err.message}`)
}
}
/**
* Delete a session from Hermes CLI
*/
export async function deleteSession(id: string): Promise<boolean> {
try {
await execFileAsync(HERMES_BIN, ['sessions', 'delete', id, '--yes'], {
timeout: 10000,
...execOpts,
})
return true
} catch (err: any) {
logger.error(err, 'Hermes CLI: session delete failed')
return false
}
}
/**
* Rename a session title via Hermes CLI
*/
export async function renameSession(id: string, title: string): Promise<boolean> {
try {
await execFileAsync(HERMES_BIN, ['sessions', 'rename', id, title], {
timeout: 10000,
...execOpts,
})
return true
} catch (err: any) {
logger.error(err, 'Hermes CLI: session rename failed')
return false
}
}
export interface LogFileInfo {
name: string
size: string
modified: string
}
/**
* Get Hermes version
*/
export async function getVersion(): Promise<string> {
try {
const { stdout } = await execFileAsync(HERMES_BIN, ['--version'], { timeout: 5000, ...execOpts })
return stdout.trim()
} catch {
return ''
}
}
/**
* Start Hermes gateway (uses launchd/systemd)
*/
export async function startGateway(): Promise<string> {
if (isDocker) {
const pid = await startGatewayBackground()
return pid ? `Gateway started (PID: ${pid})` : 'Gateway start triggered'
}
const { stdout, stderr } = await execFileAsync(HERMES_BIN, ['gateway', 'start'], {
timeout: 30000,
...execOpts,
})
return stdout || stderr
}
/**
* Start Hermes gateway in background (for WSL where launchd/systemd is unavailable)
* Uses "hermes gateway run" as a detached background process
*/
export async function startGatewayBackground(): Promise<number | null> {
const child = spawn(HERMES_BIN, ['gateway', 'run'], {
detached: true,
stdio: 'ignore',
windowsHide: true,
})
child.unref()
return child.pid ?? null
}
/**
* Restart Hermes gateway
*/
export async function restartGateway(): Promise<string> {
if (isDocker) {
try { await stopGateway() } catch { }
const pid = await startGatewayBackground()
return pid ? `Gateway restarted (PID: ${pid})` : 'Gateway restart triggered'
}
const { stdout, stderr } = await execFileAsync(HERMES_BIN, ['gateway', 'restart'], {
timeout: 30000,
...execOpts,
})
return stdout || stderr
}
/**
* Stop Hermes gateway
*/
export async function stopGateway(): Promise<string> {
const { stdout, stderr } = await execFileAsync(HERMES_BIN, ['gateway', 'stop'], {
timeout: 30000,
...execOpts,
})
return stdout || stderr
}
/**
* List available log files
*/
export async function listLogFiles(): Promise<LogFileInfo[]> {
try {
const { stdout } = await execFileAsync(HERMES_BIN, ['logs', 'list'], {
timeout: 10000,
...execOpts,
})
const files: LogFileInfo[] = []
const lines = stdout.trim().split('\n').filter(l => l.includes('.log'))
for (const line of lines) {
const match = line.match(/^\s+(\S+)\s+([\d.]+\w+)\s+(.+)$/)
if (match) {
const rawName = match[1]
const name = rawName.replace(/\.log$/, '')
if (['agent', 'errors', 'gateway'].includes(name)) {
files.push({ name, size: match[2], modified: match[3].trim() })
}
}
}
return files
} catch (err: any) {
logger.error(err, 'Hermes CLI: logs list failed')
return []
}
}
/**
* Read log lines
*/
export async function readLogs(
logName: string = 'agent',
lines: number = 100,
level?: string,
session?: string,
since?: string,
): Promise<string> {
const args = ['logs', logName, '-n', String(lines)]
if (level) args.push('--level', level)
if (session) args.push('--session', session)
if (since) args.push('--since', since)
try {
const { stdout } = await execFileAsync(HERMES_BIN, args, {
maxBuffer: 10 * 1024 * 1024,
timeout: 15000,
...execOpts,
})
return stdout
} catch (err: any) {
logger.error(err, 'Hermes CLI: logs read failed')
throw new Error(`Failed to read logs: ${err.message}`)
}
}
// ─── Profile management ──────────────────────────────────────
export interface HermesProfile {
name: string
active: boolean
model: string
gateway: string
alias: string
}
export interface HermesProfileDetail {
name: string
path: string
model: string
provider: string
gateway: string
skills: number
hasEnv: boolean
hasSoulMd: boolean
}
/**
* List all profiles
*/
export async function listProfiles(): Promise<HermesProfile[]> {
try {
const { stdout } = await execFileAsync(HERMES_BIN, ['profile', 'list'], {
timeout: 10000,
...execOpts,
})
const lines = stdout.trim().split('\n').filter(Boolean)
const profiles: HermesProfile[] = []
// Skip header lines (starts with " Profile" or " ─")
for (const line of lines) {
if (line.startsWith(' Profile') || line.match(/^ ─/)) continue
const match = line.match(/^\s+(◆)?(.+?)\s+(\S+)\s{2,}(\S+)\s{2,}(.*)$/)
if (match) {
profiles.push({
name: match[2],
active: !!match[1],
model: match[3],
gateway: match[4],
alias: match[5].trim() === '—' ? '' : match[5].trim(),
})
}
}
return profiles
} catch (err: any) {
logger.error(err, 'Hermes CLI: profile list failed')
throw new Error(`Failed to list profiles: ${err.message}`)
}
}
/**
* Get profile details
*/
export async function getProfile(name: string): Promise<HermesProfileDetail> {
try {
const { stdout } = await execFileAsync(HERMES_BIN, ['profile', 'show', name], {
timeout: 10000,
...execOpts,
})
const result: Record<string, string> = {}
for (const line of stdout.trim().split('\n')) {
const match = line.match(/^(\w[\w\s]*?):\s+(.+)$/)
if (match) {
result[match[1].trim().toLowerCase().replace(/\s+/g, '_')] = match[2].trim()
}
}
const modelFull = result.model || ''
const providerMatch = modelFull.match(/\((.+)\)/)
const model = providerMatch ? modelFull.replace(/\s*\(.+\)/, '').trim() : modelFull
return {
name: result.profile || name,
path: result.path || '',
model,
provider: providerMatch ? providerMatch[1] : '',
gateway: result.gateway || '',
skills: parseInt(result.skills || '0', 10),
hasEnv: result['.env'] === 'exists',
hasSoulMd: result.soul_md === 'exists',
}
} catch (err: any) {
if (err.code === 1 || err.status === 1) {
throw new Error(`Profile "${name}" not found`)
}
logger.error(err, 'Hermes CLI: profile show failed')
throw new Error(`Failed to get profile: ${err.message}`)
}
}
/**
* Create a new profile
*/
export async function createProfile(name: string, clone?: boolean): Promise<string> {
const args = ['profile', 'create', name]
if (clone) args.push('--clone')
try {
const { stdout, stderr } = await execFileAsync(HERMES_BIN, args, {
timeout: 15000,
...execOpts,
})
return stdout || stderr
} catch (err: any) {
logger.error(err, 'Hermes CLI: profile create failed')
throw new Error(`Failed to create profile: ${err.message}`)
}
}
/**
* Delete a profile
*/
export async function deleteProfile(name: string): Promise<boolean> {
try {
await execFileAsync(HERMES_BIN, ['profile', 'delete', name, '--yes'], {
timeout: 10000,
...execOpts,
})
return true
} catch (err: any) {
logger.error(err, 'Hermes CLI: profile delete failed')
return false
}
}
/**
* Rename a profile
*/
export async function renameProfile(oldName: string, newName: string): Promise<boolean> {
try {
await execFileAsync(HERMES_BIN, ['profile', 'rename', oldName, newName], {
timeout: 10000,
...execOpts,
})
return true
} catch (err: any) {
logger.error(err, 'Hermes CLI: profile rename failed')
return false
}
}
/**
* Switch active profile
*/
export async function useProfile(name: string): Promise<string> {
try {
const { stdout, stderr } = await execFileAsync(HERMES_BIN, ['profile', 'use', name], {
timeout: 10000,
...execOpts,
})
return stdout || stderr
} catch (err: any) {
logger.error(err, 'Hermes CLI: profile use failed')
throw new Error(`Failed to switch profile: ${err.message}`)
}
}
/**
* Export profile to archive
*/
export async function exportProfile(name: string, outputPath?: string): Promise<string> {
const args = ['profile', 'export', name]
if (outputPath) args.push('--output', outputPath)
try {
const { stdout, stderr } = await execFileAsync(HERMES_BIN, args, {
timeout: 60000,
...execOpts,
})
return stdout || stderr
} catch (err: any) {
logger.error(err, 'Hermes CLI: profile export failed')
throw new Error(`Failed to export profile: ${err.message}`)
}
}
/**
* Run hermes setup --non-interactive --reset to generate default config for current profile
*/
export async function setupReset(): Promise<string> {
try {
const { stdout, stderr } = await execFileAsync(HERMES_BIN, ['setup', '--non-interactive', '--reset'], {
timeout: 30000,
...execOpts,
})
return stdout || stderr
} catch (err: any) {
logger.error(err, 'Hermes CLI: setup reset failed')
throw new Error(`Failed to reset config: ${err.message}`)
}
}
/**
* Import profile from archive
*/
export async function importProfile(archivePath: string, name?: string): Promise<string> {
const args = ['profile', 'import', archivePath]
if (name) args.push('--name', name)
try {
const { stdout, stderr } = await execFileAsync(HERMES_BIN, args, {
timeout: 60000,
...execOpts,
})
return stdout || stderr
} catch (err: any) {
logger.error(err, 'Hermes CLI: profile import failed')
throw new Error(`Failed to import profile: ${err.message}`)
}
}
/**
* Pin or unpin a skill via hermes curator
*/
export async function pinSkill(name: string, pinned: boolean): Promise<string> {
const subcmd = pinned ? 'pin' : 'unpin'
try {
const { stdout, stderr } = await execFileAsync(HERMES_BIN, ['curator', subcmd, name], {
timeout: 15000,
...execOpts,
})
return stdout || stderr
} catch (err: any) {
logger.error(err, `Hermes CLI: curator ${subcmd} failed`)
throw new Error(`Failed to ${subcmd} skill: ${err.message}`)
}
}