Dev Log: Secretary agent, WeChat addon, session log, recipe skills, Zhipu provider
This entry covers two days of work (Apr 10–11). 111 commits across two repos, +18,585 / -1,780 lines.
Secretary Agent
A new background agent that runs on a self-clocking hourly schedule, scanning session history and maintaining three files:
profile.md(global,~/.lingtai-tui/brief/profile.md) — who the human is, their expertise, communication style. Injected into every agent’s system prompt. Hard limit: 5,000 tokens.journal.md(per-project,~/.lingtai-tui/brief/projects/<hash>/journal.md) — rolling summary of current focus, recent activity, key decisions, active agents, pending items. Hard limit: 20,000 tokens.brief.md(per-project) — mechanical concatenation of profile + journal. This is what agents actually read.
Two-phase architecture:
- Observation — each cycle reads ONE hourly history file, distills it into a condensed draft (~200–500 words), submits to library. Library entries survive molts. One file per cycle, round-robin across projects if multiple have backlogs.
- Consolidation — when all pending files are processed, loads all drafts for a project, does a complete rewrite of journal, optionally updates profile, constructs brief, verifies token counts, git-commits everything, deletes consumed drafts. Then waits for next hourly cycle.
Self-clocking: uses email(schedule) to send itself a “briefing cycle” email every hour. Backlog processing uses 5-minute follow-ups. No human intervention needed.
TUI integration:
/secretarycommand — three-mode view (Briefs / Mail / Log) with status header showing last sync time- Ctrl+B force immediate briefing, Ctrl+S suspend secretary, Ctrl+R rebuild and relaunch
/settingsgains a Brief on/off toggle (per-project) — turning it off removes brief injection from the agent’s system prompt- First-run wizard adds secretary confirmation step (defaults to yes)
The briefing skill went through multiple iterations to reach the final two-phase design with molt safety (drafts in library), token verification after every write, git version control in ~/.lingtai-tui/brief/, and memory-append workbench (pin profile + journal as read-only reference during consolidation).
Session Log System
New SessionCache replaces the old verbose.go, making session.jsonl the single source of truth for the TUI chat view.
Architecture: append-only write from three sources (mail, events.jsonl, soul_inquiry.jsonl), deduplicated by (from, ts) key, sorted chronologically. Detects hour boundaries on append — completed hours are automatically dumped as Markdown files for the secretary to read.
Key functions: NewSessionCache(), RebuildFromSources(), IngestMail/Events/Inquiries(), ProjectHash(), BriefFilePath(), dumpCompletedHour(), DumpAllHours().
Migrations:
- m011: on first run, rebuilds session.jsonl from mail/events/inquiries and backfills all history hours to
brief/projects/<hash>/history/ - m012: session.jsonl is now rebuilt from sources on every TUI startup (idempotent, dedup-safe)
Deleted verbose.go (-192 lines) — fully replaced.
Recipe System Upgrades
Recipe-Shipped Skills
Recipes can now include skill directories. On startup, the TUI auto-links them into .skills/ via symlinks. Uninstalling a recipe cleans up stale symlinks.
Language fallback chain: wen → zh → en → root. LinkRecipeSkills() handles bundled recipes first, then custom, then agora imports. PruneStaleSkillSymlinks() removes dead links.
recipe.json Manifest
Each recipe now carries a recipe.json metadata file with name and description, used for picker display. New RecipeInfo struct + LoadRecipeInfo() function. Supports imported recipe detection.
Covenant & Procedures Override
Recipes can override covenant.md and procedures.md per language. Resolved via ResolveCovenantPath() / ResolveProceduresPath() with language fallback.
lingtai-recipe Skill
Self-documenting skill in English and Chinese — agents can query the recipe system’s complete documentation via skills().
Default Recipe
Changed from adaptive to greeter.
Markdown Viewer
Reusable two-panel Bubble Tea component (MarkdownViewerModel) — left entry list + right rendered viewport with keyboard/mouse navigation.
Replaced the skills view and recipe preview implementations. skills.go went from ~284 lines to ~50. Recipe preview in firstrun.go from ~226 lines to ~115.
WeChat Addon
Full implementation of Tencent’s iLink Bot protocol from scratch, spanning both repos.
Kernel (Python — 6 modules)
| Module | What it does |
|---|---|
types.py | Protocol dataclasses — MessageItemType (TEXT/IMAGE/VOICE/FILE/VIDEO), WeixinMessage, serialization functions |
api.py | 5 async HTTP endpoint wrappers — get_qrcode(), poll_qr_status(), get_updates(), send_message(), get_upload_url(), get_config() |
login.py | cli_login() — displays QR in terminal, polls for scan confirmation, saves credentials.json (mode 0600) |
media.py | download_media(), decode_voice() (SILK→WAV via pilk), upload_media(), make_media_item() |
manager.py | WechatManager — daemon thread poll loop, 8 action handlers (send/check/read/reply/search/contacts/add_contact/remove_contact), atomic file writes, thread-safe shared state |
__init__.py | setup() entry point — loads config + credentials, creates manager, registers wechat tool |
21 test functions across 3 test files. Post-audit fixes: async/sync boundary (run_coroutine_threadsafe), stop() deadlock removal, data race protection via threading.Lock, self-echo filtering, text chunking at 4000 chars.
TUI (Go)
lingtai-wechat-setupskill — walks the human through QR code login (no static API keys)wechat.jsoncconfig template with explanatory comments- Registered in
AllAddons, trilingual i18n strings
Zhipu Provider
Full-stack integration of Zhipu GLM-5.1 as an LLM provider.
TUI: registered as preset with OpenAI-compatible API, env var ZHIPU_API_KEY, added to /setup flow and /doctor diagnostics.
Kernel — new services:
ZhipuVisionService— MCP stdio subprocess calling@z_ai/mcp-server, passes file paths (not base64)ZhipuSearchService— HTTP MCP remote callingweb_search_primeendpointresolve_z_ai_mode()— auto-detects ZAI (international) vs ZHIPU (domestic) based on base_url
MCP infrastructure: new HTTPMCPClient class (+182 lines in services/mcp.py) for remote HTTP MCP servers. servers.json now supports "type": "http" alongside stdio.
Kernel Capability Enhancements
Psyche — Memory Append
New memory append action: pin files as read-only references that are re-read on every memory load, survive molts without being baked into memory.md. Primary use: secretary pins profile + journal during consolidation. Token guard at 100k, binary file detection, persisted to system/memory_append.json.
Also fixed schema enum: "character" → "lingtai" to match dispatch table.
Email — Filter Sub-Object
email(check) gains a filter parameter: sort, from, subject, contains (substring), after/before (ISO 8601), unread_only, has_attachments, truncate (preview char limit). Response capped at 10k tokens.
Procedures System Prompt
New first-class procedures section (peer of principle, covenant). Centralizes molt procedure, reduces duplication in tool descriptions.
Refresh Lock Polling
Fixed race condition: /refresh now polls for .agent.lock release (up to 60s) instead of fixed 3s sleep.
System Procedures
Trilingual operational procedures (procedures/en/, zh/, wen/) seeded to all agents via migration m009. Recipes can override per language.
Other
- HuggingFace sync CI — GitHub Action filters binaries via
git-filter-repo, pushes to HF on every main push - MCP skill —
lingtai-mcpskill (141 lines) documenting how to register external MCP servers - TUI recovery — graceful recovery when
~/.lingtai-tuiis deleted, no duplicate admin creation - Capability fallback — availability checks fall back to preset manifest
- Legacy addon warning — m010 migration detects old
~/.lingtai-tui/addons/path - Addon skill path fixes — feishu/imap/telegram SKILL.md config paths corrected
Migrations
| Version | Name | Description |
|---|---|---|
| m009 | procedures | Seed trilingual procedures.md to all agents |
| m010 | legacy_addons_warn | Detect old addon path, print warning |
| m011 | session_backfill | Rebuild session.jsonl, backfill history to brief dir |
| m012 | session_resort | Rebuild session.jsonl from sources on every startup |
Current version: 12