restore-legacy-sessions
Use when ZCode needs to inspect, plan, or execute restoration of old ACP-era ZCode sessions from ~/.zcode/v2/sessions into the new ZCode task/session stores. Trigger when the user wants to choose a previous agent, select a workspace to restore, pick a specific historical conversation, dry-run legacy session migration, or reason about tasks-index.sqlite and ~/.zcode/cli/db/db.sqlite consistency.
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 253
- Forks
- 20
01 前言 Front Matter
- name
- restore-legacy-sessions
- description
- Use when ZCode needs to inspect, plan, or execute restoration of old ACP-era ZCode sessions from ~/.zcode/v2/sessions into the new ZCode task/session stores. Trigger when the user wants to choose a previous agent, select a workspace to restore, pick a specific historical conversation, dry-run legacy session migration, or reason about tasks-index.sqlite and ~/.zcode/cli/db/db.sqlite consistency.
02 资源文件 2
- 脚本scripts/restore-conversation.mjs21.6 KB
- 脚本scripts/scan-legacy-sessions.mjs14.1 KB
03 SKILL.md 正文
Restore Legacy Sessions
Overview
Use this skill to guide old ACP-era ZCode session restoration. The first job is selection, not mutation: identify the source agent, the workspace, and the exact conversation before proposing any write to the new stores.
Stores
- Legacy snapshots:
~/.zcode/v2/sessions/{workspaceHash}/{legacyTaskId}.json - Task index:
~/.zcode/v2/tasks-index.sqlite - New ZCode session DB:
~/.zcode/cli/db/db.sqlite
Use restoredTaskId = meta.acpSessionId || meta.taskId. The legacy snapshot filename and meta.taskId are historical IDs; the app task list often uses meta.acpSessionId as the real task/session ID.
The scan script defaults to the live legacy source ~/.zcode/v2/sessions; pass --legacy-dir <path> only when the user explicitly asks to inspect another source directory.
Restored ACP-era conversations are normal ZCode Agent history, so persisted provider fields must be glm. Treat the snapshot provider as legacy source context only; do not write task-index migration_source or meta_json.migrationSource for these restores. The migrationSource enum is reserved for the existing Claude Code native import path (claudeCode).
Selection Workflow
Resolve script paths relative to this SKILL.md directory. When running from another working directory, use the absolute path to the script inside the plugin cache.
List source agents:
node scripts/scan-legacy-sessions.mjs agents
After the user chooses an agent, list workspaces for that agent:
node scripts/scan-legacy-sessions.mjs workspaces --agent glm
After the user chooses a workspace, list conversations:
node scripts/scan-legacy-sessions.mjs conversations --agent glm --workspace /Users/dev/test/z-m
Use --query <text> to narrow conversations by title, message content, task id, or session id. Use --json when feeding the result into jq or another script.
Presenting Choices
Ask for one choice at a time unless the user already supplied enough filters:
- previous agent/provider
- workspace to restore
- conversation to restore
Show compact numbered options with title, updated time, message count, restoredTaskId, and restore state. If there are many options, show the top 20 by updatedAt and tell the user how to filter with --query.
After the user chooses an exact conversation, run a dry run first:
node scripts/restore-conversation.mjs --snapshot ~/.zcode/v2/sessions/<workspaceHash>/<legacyTaskId>.json --dry-run
Then apply the restore:
node scripts/restore-conversation.mjs --snapshot ~/.zcode/v2/sessions/<workspaceHash>/<legacyTaskId>.json
Restore States
ready: CLI DB and task-index both already contain the restored task id.needs-cli-db: task-index exists, but~/.zcode/cli/db/db.sqlitehas no session row; rebuild the real session from the legacy snapshot.needs-task-index: CLI DB exists, but task-index is missing; backfill task-index only.needs-full-import: both stores are missing; import session history and then index it.
Mutation Rules
Do not write data during selection. Before any apply step:
- Create timestamped backups of
tasks-index.sqliteanddb.sqlite. - Keep writes idempotent; never overwrite a new real session that already contains user continuation messages.
- Preserve task-index
pinned,archived,deleted, andtitle_overridden. - Use
workspaceKey = workspaceIdentity?.trim() || workspacePathfor identity/isolation semantics. - Write task-index
provider = "glm"and CLI messageproviderID = "glm"regardless of the snapshot provider. - Keep
task-index.meta_json.taskId = restoredTaskId; never leave it as the old snapshotmeta.taskId. - Leave task-index
migration_sourceempty for ACP-era restores. If a previous restore wrotelegacy-session, clear it before validating visibility. - Write CLI DB
partrows for visible text and tool calls. The app detail page renders frompart;message.data.contentalone is not enough. - Preserve assistant threading by setting
parentIDto the preceding user message id when possible. - Do not start old ACP runtimes. Restore from snapshots and new ZCode stores only.
For app code changes, update a spec under docs/ before implementation and run pnpm typecheck and pnpm lint.
04 同仓库更多 Skills
plugin-mcp-ping
E2E workspace Plugin skill marker
zcode-configuration-guide
Use when configuring ZCode's extension resources (MCP servers, slash commands, skills, hooks, and plugins) or instruction files such as AGENTS.md in the ZCode client. Explains where each resource is configured at the user and workspace scope, the discovery order, precedence, and merge rules, plus guidance on which location to choose. Use when someone asks how to add an MCP server, command, skill, hook, plugin, or AGENTS.md instructions, where a configuration file lives, why a configuration is not taking effect, or needs routing to a specific diagnostic skill.
diagnosing-skills
Use to diagnose and fix ZCode skill configuration problems in the ZCode client. Applies when a skill is not discovered, is installed but does not trigger automatically, is shadowed by a higher-precedence skill of the same name, is disabled by configuration, has a SKILL.md frontmatter error, fails to load because its description is too long, or disappears because the plugin providing it is disabled. Provides the discovery order, how to inspect skills in the client, common pitfalls, and a step-by-step localization and repair workflow.
diagnosing-plugins
Use to diagnose and fix ZCode plugin and marketplace problems in the ZCode client. Applies when a plugin is not listed, adding a marketplace or installing a plugin fails, a plugin is enabled but its skills or commands are missing, a built-in plugin still appears after being disabled, a plugin is not enabled as expected, a plugin.json manifest has a parse error, a plugin name is invalid, a dependency is unresolved or blocked across marketplaces, or a sensitive configuration value cannot be entered in the interface. Provides the plugin lifecycle, manifest schema, how to manage plugins in the client, and a step-by-step localization and repair workflow.
diagnosing-mcp
Use to diagnose and fix ZCode MCP (Model Context Protocol) server configuration problems in the ZCode client. Applies when an MCP server will not connect, its tools (mcp__server__tool) do not appear, it shows as disabled or failed, connections time out, a command cannot be found, template variables are not expanded, or a server defined in a configuration file has no effect. Provides configuration locations, how to inspect status in Settings, common pitfalls, and a step-by-step localization and repair workflow.
diagnosing-hooks
Use to diagnose and fix ZCode hook configuration problems in the ZCode client. Applies when a hook does not trigger, an event name is wrong, a matcher does not match a tool name, a script is not executable, template variables are not expanded, a timeout unit is mistaken (seconds versus milliseconds), the command and process field styles are mixed, a hook's JSON output fails validation, a hook blocks the session unexpectedly, or configuration-file hooks are not enabled. Provides configuration sources, the hooks.json schema, how to inspect hooks in the client, and a step-by-step localization and repair workflow.