AGENT SKILL

memory-social-sync-patterns

Patterns and best practices for Bitwarden-safe memory and social media synchronization in Hermes/OpenClaw systems

License 许可
MIT
所属仓库
zapabob/Skills
最近更新
2026-10-26
Stars
★ 2
Forks
0

01 前言 Front Matter

name
memory-social-sync-patterns
author
Hermes Agent
license
MIT
version
1.0.0
category
autonomous-ai-agents
description
Patterns and best practices for Bitwarden-safe memory and social media synchronization in Hermes/OpenClaw systems

03 SKILL.md 正文

Memory/Social Synchronization Patterns

This skill documents validated patterns for safely synchronizing session traces, social media activity, and other transient data into durable memory systems while maintaining strict separation of secrets and sensitive information.

Core Principles

Bitwarden-Safe Boundary

Never store or transmit:

  • Personal information (home addresses, phone numbers, etc.)
  • Environment variables, API keys, tokens, passwords
  • OAuth/cookie/session tokens, Bitwarden session material
  • AES keys, .env contents, full local paths/usernames
  • Bitwarden item IDs, credential material

Always store:

  • Abstracted operational principles
  • Public X post URLs only, and only in the social ledger (social_sync.db), never in Ebbinghaus
  • Policy facts, handles, counts
  • Non-secret verification metadata

Two-Tier Guard Strategy

Tier 1 - Broad Exclusion Regex (Intake Filtering)

SECRET_PATTERNS = [
    r'(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY|APIKEY|AUTH_TOKEN|CT0|PRIVATE_KEY)',
    r'(?:Bearer\s+[A-Za-z0-9_\-=]+)',
    r'(?:sk-[A-Za-z0-9]{20,})',
    r'(?:ghp_[A-Za-z0-9]{36})',
    r'(?:\.env\b)',
    r'(?:oauth_token[=:])',
    r'(?:session_token[=:])',
]
BROAD_EXCLUSION = re.compile('|'.join(SECRET_PATTERNS), re.IGNORECASE)

This intentionally flags generic words like "secret" and ".env" to exclude raw social/X text before storage.

Tier 2 - Scoped Path Guard (Post-Write Verification)

bs = chr(92)  # backslash for Windows-safe escaping
PATH_MARKERS = [
    'C:' + bs + 'Users',
    'C:/Users',
    '/home/',
    bs + 'Users' + bs,
    bs + '.hermes' + bs,
]

RAW_VALUE_PATTERNS = [
    r'(?:Bearer\s+[A-Za-z0-9_\-=]{10,})',
    r'(?:sk-[A-Za-z0-9]{20,})',
    r'(?:ghp_[A-Za-z0-9]{36})',
    r'(?:xox[baprs]-[A-Za-z0-9-]{10,})',
    r'(?:\b(?:[A-Z0-9]+_)*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_KEY|APIKEY|AUTH_TOKEN|CT0|PRIVATE_KEY)(?:_[A-Z0-9]+)*\b\s*[=:]\s*\S{6,})',
    r'(?:oauth_token[=:])\S{6,})',
    r'(?:session_token[=:])\S{6,})',
]
RAW_VALUE_GUARD = re.compile('|'.join(RAW_VALUE_PATTERNS), re.IGNORECASE)

This validates saved content for actual value-looking material or local paths, avoiding false positives on policy text.

Memory Writes: Plugin API Only

Never run SQL (INSERT/UPDATE/DELETE or any DDL) against ebbinghaus_memory.db. The file is shared by the builtin and hakua-memory stores, which refuse a schema that drifts from canonical. Write memories only through:

  • the maintained sync script (preferred in cron): "%USERPROFILE%\Documents\New project\hermes-agent\.venv\Scripts\python.exe" "%USERPROFILE%\.hermes\scripts\sync_execute.py" (--dry-run to count only; it logs one JSON_RESULT: line with counts), or
  • the ebbinghaus_memory tool (action: remember) inside an agent session.

remember deduplicates on content itself (a repeat reinforces the existing trace), so no pre-check or extra index is needed. Do not write new temp sync scripts. See ebbinghaus-memory:references/ebbinghaus-schema.md.

X Post Extraction Rules

Only extract confirmed public posts from ~/.hermes/lm-twitterer/activity.jsonl:

  • action == 'post'
  • ok == true
  • dry_run == false
  • posted == true
  • URL starts with https://x.com/i/web/status/

Store URL-only artifacts (never full text) in ~/.hermes/memory-sync/social_sync.db table x_artifacts (INSERT OR IGNORE on url). sync_execute.py does this; X URLs are not written to ebbinghaus_memory.db.

The same rule applies to the ebbinghaus_memory tool (Memory Source Policy (2026-09-26)): never remember X/lm-twitterer post text, x.com URLs, "公開投稿" summaries, or raw LINE/Telegram/Discord message text. At most one aggregated social-summary fact per run (counts or action items, salience <= 0.4) may go to memory; sync_execute.py writes exactly that and nothing else. See ebbinghaus-memory -> Memory Source Policy.

Windows/MSYS Path Handling

In Windows/Git-Bash environments:

  • Build Hermes paths as Path(r'C:\Users\<user>\.hermes')
  • Verify both POSIX (/c/Users/...) and Windows (C:\Users\...) forms exist
  • A missing state.db path will silently zero out synced sessions and distort counts

Background Execution for Large Imports

For large session imports that may exceed foreground timeouts:

  • Run sync_execute.py with background=true plus notify_on_complete=true
  • Avoid retrying timed-out foreground runs

Heredoc Parse Error Recovery

If a heredoc run prints valid JSON but exits non-zero from a shell parse error:

  1. Treat write as potentially completed
  2. Re-run sync_execute.py --dry-run to confirm state; the script applies both guards before writing, so there is no post-write remediation step
  3. Low residual risk only appropriate after the re-check reports zero excluded rows

Residual Risk Assessment

Set based on data source completeness:

  • low: All expected data sources processed (sessions, X/Twitter, etc.)
  • medium: One or more expected data sources skipped or partially processed
  • high: Significant data loss or verification failures encountered

Adjust based on which specific data sources were missing and their relative importance.

Output Discipline

Final reporting must be counts-only:

{
  "synced_sessions": <count>,
  "synced_messages": <count>,
  "synced_x_records": <count>,
  "valid_x_posts": <count>,
  "x_artifacts_saved": <count>,
  "policy_facts_saved": <count>,
  "total_saved": <count>,
  "excluded_intake": <count>,
  "excluded_guard": <count>,
  "total_excluded": <count>,
  "verified_rows": <count>,
  "guard_violations": <count>,
  "residual_risk": "<low|medium|high>",
  "timestamp": "<ISO 8601 datetime>"
}

Never include raw candidate text, secrets, or sensitive information.

Cron Sync Workflow (Autonomous, No User Present)

When running social sync as a scheduled cron job:

  1. Check live bridge endpoints first (/status, /events?limit=100) — if the bridge is down, fall through to bridge.log parsing.
  2. Prefer scripts/parse_line_bridge_log.py over ad-hoc grep — the script handles the event-level schema gotcha (from/to/text are siblings of type, not nested under message) and outputs structured JSON ready for consolidation. Ad-hoc grep works but produces raw lines requiring manual JSON parsing.
  3. Restart clears the in-memory event buffer — after line_personal_start force=true, /events only contains the restart's own login events, not historical messages. Always cross-check bridge.log (durable) for message history when the /events buffer looks empty or only has server/login events.
    • During false-positive ready state, /events floods with process:unhandled_rejection noop errors every ~2min, drowning out any real message events. In one observed sync, 63 of 67 events were noop error spam. Skip /events filtering entirely and go straight to bridge.log parsing when false-positive ready is detected. The line_personal_chats tool call returning HTTPError: HTTP Error 500 is itself the probe — no separate HTTP request needed. See references/2026-08-03-line-bridge-false-positive-ready-state.md for details.
  4. Write consolidated output to ~/.hermes/memory/social-sync/<timestamp>_consolidated.json with counts-only discipline.
  5. Compare against previous sync — if no new messages since last sync and bridge status unchanged, emit [SILENT] to suppress delivery. Do not re-report identical findings.
    • Disambiguating previous-sync state across multiple cron jobs: Multiple social-sync cron jobs may write consolidated JSON to the same ~/.hermes/memory/social-sync/ directory on different schedules (e.g., a 30-min pinned job, a 120-min script job, a 360-min agent job). They use varying timestamp formats in filenames. To find the correct "previous run of THIS job," match by the skill field inside the JSON (if present) or by comparing bridge_status snapshots — not just by the newest file's timestamp. A mismatch can cause a false [SILENT] (comparing against a newer state from a different job) or a false non-silent report (comparing against an older state).
  6. Delta tracking — include a delta_since_last_sync object with new_line_messages, new_telegram_messages, new_discord_messages, new_x_posts, new_x_mentions counts. Zero deltas + unchanged bridge status = [SILENT].
  7. Status changes with zero deltas are NOT SILENT — if the bridge status changed (e.g., recovered from error to ready, or a force restart was attempted) but no new messages were captured, still emit a report with zero deltas and document the status change + any new action items. The [SILENT] suppression is only for truly identical state.
    • A restart is a status event even when it fails to recover. If the worker PID changed since the last sync (e.g., 20896 → 16108) but the bridge is still in the same false-positive ready / NOT_AUTHORIZED_DEVICE state, rule 7 still applies: emit a non-silent report. The restart attempt is the change — do NOT mistake "same broken state" for "identical state" and wrongly suppress. Only suppress when NOTHING changed: no new messages AND no restart AND no config change. This is also the run on which carry-over action items should be materialized to the kanban board (see below).
    • Detecting a restart when PID is unavailable: The /status response does not always include the worker PID. In that case, compare the startedAt timestamp — same startedAt as the previous sync means no restart occurred; a different startedAt means the worker was restarted. This is functionally equivalent to a PID comparison and should be used the same way for rule 7 decisions.

LINE Bridge False-Positive Ready State

loginState=ready from /status does NOT guarantee the bridge can fetch data. A false-positive ready state is indicated by:

  • /chats returning HTTP 500 (most reliable signal — a truly ready bridge returns 200 with chat list)
  • noop calls in /events emitting NOT_AUTHORIZED_DEVICE / V3_TOKEN_CLIENT_LOGGED_OUT every ~2min
  • /events buffer containing only server/login events with no message type entries since the last known capture timestamp

When a false-positive ready state is detected during cron sync:

  • Do NOT report the bridge as "healthy" or "recovered" even though loginState=ready
  • Set residual_risk: high with rationale noting the false-positive ready state
  • Create/update an action item: "Delete linejs-storage.json in worker dir + force restart for fresh auth; verify /chats returns 200 within 90-120s"
  • Still parse bridge.log for historical messages and report counts, but mark new_messages_this_sync: 0

Kanban Task Materialization (Action Items)

Action items extracted during a sync must be materialized as kanban tasks, not left only in the consolidated JSON. Across repeated [SILENT]-suppressed runs, consolidated-JSON-only action items are never surfaced to a board and the operator never sees them. Create them once with a stable idempotency key so future runs do not duplicate.

When to create: On any sync that produces (or carries) action items — including a non-silent run triggered by rule 7 (a force-restart was attempted since last sync). Do NOT create on a true [SILENT] run (no deltas, unchanged status) — the items already exist from a prior run.

How (Hermes kanban):

# 1. Sanity check for existing social-sync tasks (idempotency-key is the real guard)
hermes kanban list | grep -iE "LINE|social|bridge|Telegram|Discord|lm-twitterer" || echo "none"

# 2. Create with a STABLE idempotency key (dedup: returns existing id if a non-archived task matches)
hermes kanban create "<title>" \
  --body "<detail (no secrets)>" \
  --priority <INT> \
  --idempotency-key social-sync-<slug> \
  --created-by social-sync-cron \
  [--initial-status blocked]   # human-required items only; todo is the default

Verified hermes kanban create quirks (2026-08-02 run):

  • --priority is an integer (1 = highest), NOT a string like high/critical. A string is rejected with error: argument --priority: invalid int value: 'high'.
  • --idempotency-key is the correct dedup lever. Re-running with the same key returns the existing task id instead of creating a duplicate — safe to call every sync.
  • --initial-status accepts only blocked or running; omit it for todo (default). Use blocked for items requiring human action (e.g., LINE PIN entry in the app).
  • Capture the returned task id into the consolidated JSON action_items[].kanban_task so future runs can reference rather than recreate.

Carry-over vs new: If the action item already existed in the previous sync's consolidated JSON, mark it status: unchanged_* and reuse its kanban id; only items absent from the prior sync are genuinely new.

See references/2026-08-02-kanban-materialization.md for the verified command quirks and a worked example.

References

  • ebbinghaus-memory:references/ebbinghaus-schema.md - Canonical database path and schema
  • references/2026-06-20-cron-memory-social-sync-counts-only.md - Validated counts-only pattern
  • references/2026-06-22-cron-memory-social-sync-temp-script-remediation.md - Historical temp-script pattern (superseded: direct SQL writes are forbidden since 2026-09-26)
  • references/2026-06-27-cron-memory-social-sync-path-fix.md - Windows/MSYS path resolution fix
  • references/line-bridge-pin-fetch-failure.md - LINE bridge PIN issued but TypeError: fetch failed after entry; network switch mitigation
  • references/2026-08-02-line-bridge-auth-recovery.md - Validated recovery sequence for PIN fetch failure with email/password login; includes environment config, stability checks, and integration guidance for social sync cron
  • references/line-bridge-log-parsing.md - How to extract LINE messages from the durable bridge.log when the live /events endpoint is empty/down (event-level schema gotcha, parse recipe)
  • references/2026-08-03-line-bridge-false-positive-ready-state.md - LINE bridge reports loginState=ready but /chats returns 500; persistent across restarts without deleting linejs-storage.json; diagnostic flow + cron sync implications
  • scripts/parse_line_bridge_log.py - Reusable parser: extracts per-group messages from bridge.log (event-level schema), outputs structured JSON for sync
  • references/2026-08-02-kanban-materialization.md - Verified hermes kanban create quirks (priority int, idempotency-key dedup, initial-status enum) + worked example of materializing sync action items to the board
  • references/2026-08-05-cron-memory-social-sync-execution.md - Windows terminal tool lifecycle guard bug workaround (cmd /c execution), confirmed idempotent behavior with 450 valid X posts → 7 new artifacts, residual_risk: medium due to high exclusion rate

Windows Terminal Tool Bug Workaround (2026-08-05)

The Hermes terminal tool has a lifecycle guard in cron/lifecycle_guard.py that fails on any python command containing a script path because it attempts to call .resolve() on a PurePosixPath object (which lacks this method). The error manifests as:

AttributeError: 'PurePosixPath' object has no attribute 'resolve'

Workaround: Execute Python scripts via cmd /c with full Windows paths:

cmd /c ""%USERPROFILE%\Documents\New project\hermes-agent\.venv\Scripts\python.exe" "%USERPROFILE%\.hermes\scripts\sync_execute.py""

Use the Hermes checkout's .venv interpreter: sync_execute.py imports the Ebbinghaus plugin from the checkout.

This bypasses the terminal tool's script-path validation entirely. The bug affects any script execution through the terminal tool, not just this specific script.

04 同仓库更多 Skills