memory-init

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Purpose

目标

Initialize the Memory Hub for a project: create
.memory/
skeleton, scan the project, and populate initial knowledge files and catalog.
为项目初始化Memory Hub:创建
.memory/
目录骨架,扫描项目并填充初始知识库文件与目录。

Input

输入

No arguments required. Run from the project root.
无需传入参数。请在项目根目录执行。

Required Flow

必要流程

Step 1: Create skeleton

步骤1:创建目录骨架

bash
memory-hub init
If
ALREADY_INITIALIZED
error, stop and inform the user.
bash
memory-hub init
如果出现
ALREADY_INITIALIZED
错误,停止操作并通知用户。

Step 2: Scan project and generate tech-stack knowledge

步骤2:扫描项目并生成技术栈知识库

  1. Read the project root file listing
  2. Read package manager files (
    package.json
    ,
    pyproject.toml
    ,
    Cargo.toml
    ,
    go.mod
    ,
    pom.xml
    , etc.)
  3. Read entry files (
    main.*
    ,
    index.*
    ,
    app.*
    ,
    server.*
    , etc.)
  4. Read config files (
    .env.example
    ,
    tsconfig.json
    ,
    webpack.config.*
    , etc.)
Generate
tech-stack.md
content and write:
bash
memory-hub write architect tech-stack.md \
  --topic tech-stack --summary "技术栈、关键依赖、使用方式与限制" --mode overwrite <<'EOF'
<generated markdown>
EOF
  1. 读取项目根目录的文件列表
  2. 读取包管理文件(
    package.json
    pyproject.toml
    Cargo.toml
    go.mod
    pom.xml
    等)
  3. 读取入口文件(
    main.*
    index.*
    app.*
    server.*
    等)
  4. 读取配置文件(
    .env.example
    tsconfig.json
    webpack.config.*
    等)
生成
tech-stack.md
内容并写入:
bash
memory-hub write architect tech-stack.md \
  --topic tech-stack --summary "技术栈、关键依赖、使用方式与限制" --mode overwrite <<'EOF'
<generated markdown>
EOF

Step 3: Generate code conventions knowledge

步骤3:生成代码约定知识库

Based on project structure from Step 2, generate
conventions.md
:
bash
memory-hub write dev conventions.md \
  --topic conventions --summary "目录命名规则、模块组织方式、代码约定" --mode overwrite <<'EOF'
<generated markdown>
EOF
基于步骤2得到的项目结构,生成
conventions.md
bash
memory-hub write dev conventions.md \
  --topic conventions --summary "目录命名规则、模块组织方式、代码约定" --mode overwrite <<'EOF'
<generated markdown>
EOF

Step 4: Scan project modules and generate Catalog

步骤4:扫描项目模块并生成目录

Analyze directory structure, identify functional domains and key files, construct JSON:
bash
memory-hub catalog-update <<'EOF'
{"modules": [{"name": "...", "summary": "...", "files": [{"path": "...", "description": "..."}]}]}
EOF
分析目录结构,识别功能领域与关键文件,构建JSON:
bash
memory-hub catalog-update <<'EOF'
{"modules": [{"name": "...", "summary": "...", "files": [{"path": "...", "description": "..."}]}]}
EOF

Step 5: Quality gate

步骤5:质量校验

  1. List
    unknowns
    — files/directories that don't clearly belong to any functional domain
  2. Check
    catalog.repair
    output (auto-triggered by catalog-update):
    • ai_actions
      non-empty → execute self-healing, then run
      memory-hub catalog-repair
      again to confirm cleared
    • manual_actions
      non-empty → report to user
  1. 列出
    unknowns
    — 无法明确归属到任何功能领域的文件/目录
  2. 检查
    catalog.repair
    的输出(由catalog-update自动触发):
    • ai_actions
      非空 → 执行自我修复,然后再次运行
      memory-hub catalog-repair
      确认已清理
    • manual_actions
      非空 → 向用户报告

Step 6: Output summary

步骤6:输出摘要

Report: files created, modules identified, unknowns requiring user confirmation.
报告内容:已创建的文件、已识别的模块、需要用户确认的未知项。

Output

输出

JSON envelope from each command. Final summary to user.
每个命令返回JSON格式结果。最终向用户展示摘要信息。

Error Handling

错误处理

  • ALREADY_INITIALIZED
    → inform user, do not proceed
  • Any command failure → stop and report the error
  • ALREADY_INITIALIZED
    → 通知用户,不再继续执行
  • 任何命令执行失败 → 停止操作并报告错误