pkg

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Manage MTHDS packages

管理MTHDS包

Initialize, add dependencies, lock, install, update, and validate MTHDS packages using the
mthds
CLI.
使用
mthds
CLI初始化、添加依赖、锁定、安装、更新及验证MTHDS包。

Process

操作流程

Prerequisite: See CLI Prerequisites
前提条件:查看CLI 前提条件

1. Initialize a package

1. 初始化包

Create a
METHODS.toml
manifest:
bash
mthds package init --directory <pkg-dir>
Use
--force
to overwrite an existing manifest:
bash
mthds package init --force --directory <pkg-dir>
创建
METHODS.toml
清单文件:
bash
mthds package init --directory <pkg-dir>
使用
--force
参数覆盖已有的清单文件:
bash
mthds package init --force --directory <pkg-dir>

2. Configure exports

2. 配置导出项

Exports declare which pipes the package makes available to consumers. They are organized by domain in
METHODS.toml
:
toml
[exports.restaurant_analysis]
pipes = ["present_restaurant", "extract_menu", "analyze_menu"]
To configure exports:
  1. Read the
    .mthds
    bundle(s) in the package to find the domain codes and pipe codes defined inside them
  2. Edit
    METHODS.toml
    to add an
    [exports.<domain>]
    section for each domain, listing the pipe codes to export
Rules:
  • The
    main_pipe
    of each bundle is auto-exported — you do not need to list it unless you want to be explicit
  • Concepts are always public and do not need to be listed in exports
  • Each
    [exports.<domain>]
    section requires a
    pipes
    key with a list of pipe code strings
导出项用于声明包向使用者开放的管道。它们在
METHODS.toml
中按领域进行组织:
toml
[exports.restaurant_analysis]
pipes = ["present_restaurant", "extract_menu", "analyze_menu"]
配置导出项的步骤:
  1. 读取包中的
    .mthds
    包文件,找到其中定义的领域代码和管道代码
  2. 编辑
    METHODS.toml
    ,为每个领域添加
    [exports.<domain>]
    章节,并列出要导出的管道代码
规则:
  • 每个包文件的
    main_pipe
    会自动导出——除非你想明确声明,否则无需列出
  • 概念始终是公开的,无需在导出项中列出
  • 每个
    [exports.<domain>]
    章节需要包含
    pipes
    键,其值为管道代码字符串组成的列表

3. Add dependencies

3. 添加依赖

Add a dependency to the manifest:
bash
mthds package add <address> --directory <pkg-dir>
Options:
FlagPurposeExample
--alias
Set a local alias for the dependency
mthds package add github.com/org/repo --alias mylib --directory <pkg-dir>
--version
Pin a specific version
mthds package add github.com/org/repo --version 1.2.0 --directory <pkg-dir>
--path
Use a local path dependency
mthds package add ./local-pkg --path --directory <pkg-dir>
向清单文件中添加依赖:
bash
mthds package add <address> --directory <pkg-dir>
选项:
标志用途示例
--alias
为依赖设置本地别名
mthds package add github.com/org/repo --alias mylib --directory <pkg-dir>
--version
固定依赖的特定版本
mthds package add github.com/org/repo --version 1.2.0 --directory <pkg-dir>
--path
使用本地路径依赖
mthds package add ./local-pkg --path --directory <pkg-dir>

4. Lock dependencies

4. 锁定依赖

Resolve all dependencies and generate a lockfile:
bash
mthds package lock --directory <pkg-dir>
解析所有依赖并生成锁定文件:
bash
mthds package lock --directory <pkg-dir>

5. Install from lockfile

5. 从锁定文件安装

Install dependencies from the existing lockfile:
bash
mthds package install --directory <pkg-dir>
从已有的锁定文件安装依赖:
bash
mthds package install --directory <pkg-dir>

6. Update dependencies

6. 更新依赖

Re-resolve dependencies and update the lockfile:
bash
mthds package update --directory <pkg-dir>
重新解析依赖并更新锁定文件:
bash
mthds package update --directory <pkg-dir>

7. List package manifest

7. 列出包清单

Display the current package manifest:
bash
mthds package list --directory <pkg-dir>
显示当前的包清单:
bash
mthds package list --directory <pkg-dir>

8. Validate package manifest

8. 验证包清单

Validate the
METHODS.toml
package manifest:
bash
mthds package validate --directory <pkg-dir>
Options:
FlagPurposeExample
--all
Validate all packages in the workspace
mthds package validate --all --directory <pkg-dir>
--runner
/
-r
Specify the runner for validation
mthds package validate --all -r pipelex --directory <pkg-dir>
Target a specific package:
bash
mthds package validate <target> --directory <pkg-dir>
Note:
mthds package validate
validates the
METHODS.toml
package manifest. To validate
.mthds
bundle semantics, use
mthds-agent pipelex validate
(see /check skill).
验证
METHODS.toml
包清单:
bash
mthds package validate --directory <pkg-dir>
选项:
标志用途示例
--all
验证工作区中的所有包
mthds package validate --all --directory <pkg-dir>
--runner
/
-r
指定用于验证的运行器
mthds package validate --all -r pipelex --directory <pkg-dir>
指定目标包进行验证:
bash
mthds package validate <target> --directory <pkg-dir>
注意
mthds package validate
用于验证
METHODS.toml
包清单。若要验证
.mthds
包文件的语义,请使用
mthds-agent pipelex validate
(查看/check技能)。

The
--directory
option

--directory
选项

All
mthds package
commands accept
--directory <path>
(short:
-d
) to target a package directory other than the shell's current working directory. This is essential when the agent's CWD differs from the package location.
bash
undefined
所有
mthds package
命令都支持
--directory <path>
(简写:
-d
),用于指定包目录而非当前Shell的工作目录。当Agent的当前工作目录与包所在位置不同时,该选项至关重要。
bash
undefined

From any directory, target a specific package

从任意目录,指定目标包

mthds package init --directory mthds-wip/restaurant_presenter/ mthds package validate --directory mthds-wip/restaurant_presenter/

If `--directory` is omitted, commands default to the current working directory.
mthds package init --directory mthds-wip/restaurant_presenter/ mthds package validate --directory mthds-wip/restaurant_presenter/

若省略`--directory`,命令默认使用当前工作目录。

Common Workflows

常见工作流

Starting a new package:
  1. mthds package init --directory <pkg-dir>
    — create the manifest
  2. Read
    .mthds
    bundles in the package to extract domain codes and pipe codes
  3. Edit
    METHODS.toml
    to set the correct address, description, and
    [exports.<domain>]
    sections
  4. mthds package validate --directory <pkg-dir>
    — validate the manifest
Adding dependencies to an existing package:
  1. mthds package add <address> --directory <pkg-dir>
    — add the dependency
  2. mthds package lock --directory <pkg-dir>
    — resolve and lock
  3. mthds package install --directory <pkg-dir>
    — install from lockfile
Updating dependencies:
  1. mthds package update --directory <pkg-dir>
    — re-resolve and update lockfile
  2. mthds package install --directory <pkg-dir>
    — install updated deps
创建新包:
  1. mthds package init --directory <pkg-dir>
    — 创建清单文件
  2. 读取包中的
    .mthds
    包文件,提取领域代码和管道代码
  3. 编辑
    METHODS.toml
    ,设置正确的地址、描述和
    [exports.<domain>]
    章节
  4. mthds package validate --directory <pkg-dir>
    — 验证清单文件
为已有包添加依赖:
  1. mthds package add <address> --directory <pkg-dir>
    — 添加依赖
  2. mthds package lock --directory <pkg-dir>
    — 解析并锁定依赖
  3. mthds package install --directory <pkg-dir>
    — 从锁定文件安装
更新依赖:
  1. mthds package update --directory <pkg-dir>
    — 重新解析并更新锁定文件
  2. mthds package install --directory <pkg-dir>
    — 安装更新后的依赖

Reference

参考资料

  • CLI Prerequisites — read at skill start to check CLI availability
  • Error Handling — read when CLI returns an error to determine recovery
  • MTHDS Agent Guide — read for CLI command syntax or output format details
  • CLI 前提条件 — 启动技能时查看,检查CLI是否可用
  • 错误处理 — 当CLI返回错误时查看,确定恢复方案
  • MTHDS Agent指南 — 查看CLI命令语法或输出格式详情