文档目录

本页所有命令、子命令与长选项均直接核对自 artifact-graph CLI 参数解析源码与 artifact-graph --help 输出。所有不带写入说明的查询与检查命令均为只读操作,可在本地终端、Git 钩子与 CI 流水线中安全重跑。

快速查看内置帮助#

任何时候都可以直接向 CLI 请求帮助文本(退出码 0,零文件副作用):

bash
npx artifact-graph --help

全局通用参数 --root <dir> 用于指定目标仓库根目录(省略时默认使用当前工作目录 process.cwd()),--help(或 -h)用于打印用法说明。

顶层命令一览#

初始化、扫描与图校验#

命令用途说明真实调用示例
init在目标目录生成默认 artifact-graph.config.yaml(已存在时报错拒绝覆盖)artifact-graph init --root .
scan扫描全部已配置制品节点与有向边,更新本地 SQLite 图谱缓存artifact-graph scan --root .
validate校验图结构、允许边、场景-PRD 链接索引、可执行测试追溯与可选 E2E 覆盖率阈值artifact-graph validate --root . --format json
doctor只读检查 CLI 路径、Node 版本、better-sqlite3 原生绑定与配置文件结构artifact-graph doctor --root . --format markdown
coverage报告图谱扫描边界与可选发布清单文件的覆盖分类artifact-graph coverage --release-input files.txt --format json
render将全图或指定起点/终点子图导出为 Mermaid 流程图文本artifact-graph render --from feature:ACA1 --format mermaid
next-id按 idRanges 配置计算指定制品类型的下一个可用编号artifact-graph next-id requirement --range main

validate 常用参数:

参数说明
--root <dir>指定待校验的目标项目根目录
--format <json>传入 --format json 输出结构化问题数组(开启覆盖率时输出 { issues, e2eCoverage })
--warning-only存在 error 级别问题时仍返回退出码 0(仅用于本地渐进排查,仍须阅读输出中的 issues)
--include <list>逗号分隔附加检查项,支持 scenario-prd-links,e2e-coverage

图查询、变更影响与上下文组装#

命令用途说明真实调用示例
query在 SQLite 索引上按起点、终点、深度与时间视图查询关联子图artifact-graph query --from feature:ACA1 --depth 2 --view current --format json
impact只读分析工作树、暂存区、基准分支或指定文件列表变更波及的直接与间接制品artifact-graph impact --worktree --format json
context面向单个目标制品抽取确定性上下文清单(默认实现模式)artifact-graph context --target design:auth-flow --mode implementation --format json
packet将目标上下文组装为结构化实现数据包并自动执行完整性校验artifact-graph packet --target design:auth-flow --format json --out packet.json
packet-prompt将实现数据包渲染为可直接发给 AI 执行者的受控字符预算提示词artifact-graph packet-prompt --target design:auth-flow --max-chars 32000 --out prompt.md
packet-audit批量发现或按清单审计多个目标的实现数据包完整性artifact-graph packet-audit --discover --summary-only --format json
packet-prompt-audit批量发现或按清单审计生成的提示词质量与预算合规性artifact-graph packet-prompt-audit --discover --summary-only --format json

目标选择与范围控制常用参数:

参数说明
--target <type:id>通用目标选择器(支持任意开启 target: true 的类型,与旧分型选择器互斥)
--feature <id>选择指定 feature 节点(同类快捷选择器还有 --scenario、--decision、--design、--e2e-test)
--mode <mode>上下文抽取模式:implementation(默认,聚焦实现所需输入)或 full(完整关联集)
--view <view>时间视图过滤:current、planned、history 或 all
--max-per-category <n>限制每个分类最多纳入的制品数量(正整数)
--no-validate仅在 packet 中跳过组装后的内置包结构校验
--packet <path>在 packet-prompt 中直接读取现成 packet.json(与 --target 等选择器互斥)
--max-chars <n>在 packet-prompt 与 packet-prompt-audit 中设定提示词最大字符预算
--generated-at <iso>在 packet-prompt 中显式指定生成时间戳以获得字节级可复现输出
--worktree在 impact(默认)或 version-lock refresh --changed-only 中读取未暂存工作树变更
--staged在 impact 或 version-lock refresh --changed-only 中仅读取 Git 暂存区变更
--base <ref>对比指定 Git 引用(如 main)计算变更路径集合
--paths <p1,p2>在 impact 中直接传入逗号分隔的相对路径列表做假设影响分析
--discover在 packet-audit / packet-prompt-audit 中自动扫描全部可作为 target 的节点(与 --targets-file 互斥)
--targets-file <path>从文件读取待批量审计的 type:id 列表
--out-dir <path>批量审计产物输出目录(未开启 --summary-only 时必填)
--summary-only批量审计仅输出汇总统计,不落盘单目标文件(与 --sample-targets 互斥)
--sample-targets <csv>在 packet-audit 中仅落盘抽样指定的 type:id 目标
--summary-detail <mode>批量审计摘要详略度:full 或 compact
--limit <n>限制批量发现或列表返回条数(packet-audit 中 0 表示不限)

跨仓双向对齐、专业证明与协议校验#

命令用途说明真实调用示例
alignment-audit跨层双向一致性检查:核验单仓 implementationSurface 双锁、高阶 portfolio-allocations.json 四态满足度与子仓 upstream-bindings.jsonartifact-graph alignment-audit --root . --strict --json
alignment-lock在上下游两端文件均存在且已声明对称绑定时,同步刷新双向 SHA-256 摘要artifact-graph alignment-lock --root . --format markdown
trace-version查看单个目标制品关联的全部版本锁条目与新鲜度状态artifact-graph trace-version --target feature:ACA1 --strict-missing-lock
version-index导出全仓制品、实现与验证关系的结构化版本索引 JSONartifact-graph version-index --format json --out version-index.json
refactor-id安全一对一重命名制品 ID(默认 dry-run 预览计划,加 --apply 事务改写)artifact-graph refactor-id --from requirement:R01 --to R10
validate-review-result校验审阅结果 JSON 协议结构、身份独立性与可选目标文件摘要绑定artifact-graph validate-review-result --file review.json --verify-target-digests --format json
generate-e2e-registry生成或用 --check 校验确定性端到端测试注册表artifact-graph generate-e2e-registry --deterministic --check
check-professional只读组合运行 validate、version-lock audit 与 coverage,可选排他写出共同证明文件artifact-graph check-professional --root . --format json
read-proof只读读取并校验一份既有专业证明文件,不重扫目标仓库artifact-graph read-proof --proof-root /abs/dir --proof conclusion.json --format json

对齐、重构与证明专用参数:

参数说明
--portfolio-root <dir>在子仓库执行 alignment-audit 或 alignment-lock 时显式指定高阶规划仓路径
--strict在 alignment-audit 中开启严格阻断(缺锁或下游内部漂移均计为阻断错误)
--json在 alignment-audit / alignment-lock 中等价于 --format json
--apply在 refactor-id 中实际执行白名单位置事务写入并自动重扫验证(省略时仅预览)
--approve-prose <list>在 refactor-id 中显式批准改写正文段落引用(格式 file:line,...)
--file <path>指定待校验的审阅结果 JSON 文件路径
--verify-target-digests核对审阅结果中目标文件的实时磁盘 SHA-256(可跟 JSON 映射、文件路径或与 --targets 配合;兼容同义参数 --expected-target-digests)
--targets <p1,p2>配合 --verify-target-digests 显式指定待核对摘要的目标文件列表
--deterministic在 generate-e2e-registry 中输出固定时间戳的确定性注册表
--check在 generate-e2e-registry 中只读比对磁盘注册表与确定性生成结果是否一致
--conclusion-output <abs>在 check-professional 中排他写出证明 JSON(必须为绝对路径,已存在时绝不覆盖)
--proof-root <dir>在 read-proof 中指定证明文件受控根目录
--proof <relPath>在 read-proof 中指定相对 --proof-root 的证明文件路径

五大子命令族详解#

1. version-lock(关系版本锁)#

bash
artifact-graph version-lock audit [--format json|markdown] [--warning-only] [--strict-missing-lock] [--lock-path <path>]
artifact-graph version-lock refresh (--all | --changed-only (--staged | --worktree | --base <ref>)) [--remove-orphans | --remove-orphan-edge <edgeId>...] [--format json|markdown] [--lock-path <path>]
artifact-graph version-lock update --target <type:id> --source <path> [--verified-by <path,path>] [--lock-path <path>]
artifact-graph version-lock bootstrap [--force] [--lock-path <path>]
参数说明
--strict-missing-lock在 audit 与 trace-version 中将未加锁关系(missing_lock)作为非零退出阻断项
--all在 refresh 中全量重算并更新当前图谱中的全部关系锁(与 --changed-only 互斥)
--changed-only仅刷新受指定 Git 变更模式(--staged / --worktree / --base <ref> 三选一)波及的锁
--remove-orphans在 refresh 时一并移除图中已不存在的孤儿锁(与 --remove-orphan-edge 互斥)
--remove-orphan-edge <id>仅精确移除指定的单条孤儿边(可重复传入多次;若该边仍存活则拒绝删除)
--source <path>在 update 中指定源文件路径(在 inbox add 中则表示想法来源标记)
--verified-by <paths>在 update 中绑定逗号分隔的验证测试文件路径
--lock-path <path>自定义锁文件相对路径(默认读取标准追溯版本锁路径)
--force仅限人工明确授权重建初始基线时配合 bootstrap 使用,严禁用于自动脚本或钩子

2. restructure(受控多文件重组)#

支持记录物理拆分、编号身份拆分与跨文件移动改号。语义拆分决策由技能层完成,CLI 负责只读检查、计划编译、APFS 事务写入与故障恢复:

bash
artifact-graph restructure inspect --root . --input request.json --format json
artifact-graph restructure plan --root . --input mapping.json --format json
artifact-graph restructure apply --root . --plan ../plan.json --confirm-cooperative-writers --format json
artifact-graph restructure recover --root . --plan ../plan.json --confirm-all-participants-stopped --confirm-exclusive-maintenance --format json
artifact-graph restructure prune-recovery --root . --plan ../plan.json --confirm-cooperative-writers --format json
参数说明
--input <path>为 inspect 或 plan 提供请求或映射 JSON 文件
--plan <path>为 apply、recover、prune-recovery 指定保存在写集之外的候选计划 JSON
--confirm-cooperative-writers操作者显式确认当前无非合作并发写者(apply 与 prune-recovery 必填)
--confirm-all-participants-stopped故障恢复时确认所有相关写入进程已停止(须与 --confirm-exclusive-maintenance 同时传入)
--confirm-exclusive-maintenance故障恢复时确认当前处于独占维护窗口

3. contract(契约内核)#

bash
artifact-graph contract list [--contracts-dir <path>] --format json
artifact-graph contract explain --contract <major-id> [--revision-digest <sha256>] [--contracts-dir <path>] --format json
artifact-graph contract validate --contract <major-id> --data <json> [--contracts-dir <path>] --format json
artifact-graph contract normalize --contract <major-id> --data <json> --format json
artifact-graph contract check-policy --contract <major-id> --policy <json> [--contracts-dir <path>] --format json
artifact-graph contract validate-markers --contract <major-id> --markdown <path> [--contracts-dir <path>] --format json
参数说明
--contract <major-id>目标契约主版本标识(如 artifact.spec@1、artifact.e2e-test@1)
--contracts-dir <path>自定义契约目录路径(默认读取内置契约集)
--revision-digest <digest>按精确修订摘要锁定解析契约定义
--data <json>传入待校验或待规范化的 JSON 字符串
--policy <json>传入待执行单调加严兼容性检查的项目策略 JSON 字符串
--markdown <path>传入待校验语义标记(semanticMarkers)的 Markdown 文件路径

4. inbox(轻量需求想法收件箱)#

无需预先创建 artifact-graph.config.yaml,即可随时记录原始想法并与既有需求、用户故事做词法相似度比对:

bash
artifact-graph inbox add "支持审阅报告绑定目标文件哈希" --context "异步评审防串单" --tags review,security
artifact-graph inbox list --status captured --limit 10 --format markdown
artifact-graph inbox match "审阅防串单" --min-score 0.2 --format json
参数说明
--text <text>显式传入想法文本或检索词(也可直接作为位置参数传入)
--context <note>补充想法产生的背景说明
--tags <csv>逗号分隔标签列表(也可重复使用 --tag <tag>)
--inbox <path>自定义收件箱存储文件路径
--status <status>在 inbox list 中按条目状态筛选(如 captured)
--min-score <0..1>在 inbox add / inbox match 中设置近似需求匹配阈值(0 到 1 之间数值)
--created-at <iso>在 inbox add 中指定记录创建时间

5. hooks(受管 Git 钩子安装与卸载)#

bash
artifact-graph hooks install-git [--hook pre-commit|pre-push|all] [--format text|json]
artifact-graph hooks uninstall [--hook pre-commit|pre-push|all] [--format text|json]

--hook 默认值为 all(同时管理 pre-commit 与 pre-push);install-git --uninstall 与 hooks uninstall 等价。

JSON 输出关键字段与退出码约定#

核心 JSON 输出结构#

在自动化流水线中建议统一附加 --format json(或 --json)消费机器可读结构:

  • validate --format json:默认返回 ValidationIssue[] 数组(每项含 code、severity、message、path、line);开启 E2E 覆盖率时返回 { issues, e2eCoverage }。
  • version-lock audit --format json:返回 { totalLocks, fresh, issues },每条异常含 edgeId、status(如 missing_lock、artifact_changed、source_changed、verified_by_changed、orphan_lock、invalid_test_shell)与 remediation 修复建议。
  • alignment-audit --json:返回 { schemaVersion: "1.0", ok, strict, modes, intraRepo, portfolio?, childProject?, issues, summary }。其中 intraRepo 包含 matchedEntries、unclaimedEntries、implementsLocksCount 与 verifiesLocksCount;portfolio.satisfactionSummary 给出 verified_satisfied、traceability_locked、allocated_in_progress、partially_allocated 与 not_applicable 计数。
  • contract ... --format json:成功返回 { ok: true, data },失败返回 { ok: false, error: { code, path, message } } 或 { ok: false, errors }。

退出码约定#

退出码触发场景与自动化处理建议
0命令成功完成且未命中当前严格度下的阻断问题(注意:显式传入 --warning-only 时即使存在 issues 也会返回 0,调用方须解析 JSON 中的 issues 列表)
1检出业务或门禁阻断问题:如图校验存在 error、严格模式下检出 missing_lock 或锁摘要漂移、alignment-audit 存在未认领实现入口或跨仓漂移、doctor 探测到 better-sqlite3 原生绑定不可用、审阅协议校验未通过,或必填业务文件缺失
2命令行参数或枚举取值非法:如 query / context / packet 传入了不支持的 --view 值、impact 同时指定了多个互斥模式或 --format 取值不在允许集合内、check-professional / read-proof / coverage 的 --format 取值非法

遇到具体报错码时,可直接对照 常见报错与维护指南 按步骤恢复。

搜索文档

↑ ↓ 选择 · Enter 跳转Esc 关闭
Artifact Chain 知识站
图表预览