创建、替换和删除本地文件

通过完整的文件编写计划,审查并应用本地文件和文件夹的更改。

在Linux上使用Altifigence CLI 0.1.9,审查本地文件更改,并将完整计划应用到同一个项目。

创建文件和文件夹

请使用本地项目的绝对路径。本例使用$HOME/alti-projects/demo-project。请以普通用户身份运行命令。审查和应用计划期间,请暂停其他写入操作。

set -euo pipefail
PROJECT="$(cd "$HOME/alti-projects/demo-project" && pwd -P)"
WORK="$(mktemp -d)"
cat > "$WORK/create.json" <<'JSON'
[
  {"kind":"create-directory","path":"notes"},
  {"kind":"create","path":"notes/review.txt","content":"First review\n"}
]
JSON
alti ide workspace file-plan --project "$PROJECT" \
  --request "$WORK/create.json" > "$WORK/create.plan.json"

请确认退出状态为0,然后读取完整计划:

cat "$WORK/create.plan.json"

计划的模式为altifigence.workspace-authoring-plan.v1。请审查changes、observations和request,并保留整份文档。计划中的路径相对于项目。

应用已保存的计划:

alti ide workspace file-apply --project "$PROJECT" \
  --request "$WORK/create.plan.json" > "$WORK/create.receipt.json"
jq '{schema, outcome}' "$WORK/create.receipt.json"

退出状态为0后,选定的回执字段如下:

{
  "schema": "altifigence.workspace-file-receipt.v1",
  "outcome": "committed"
}

替换文件

读取当前文件,并在替换请求中使用其SHA-256。这些示例使用jq准备JSON。

alti ide workspace read --project "$PROJECT" notes/review.txt \
  > "$WORK/current.json"
jq '[{kind:"replace",path:"notes/review.txt",
      expected_sha256:.sha256,content:"Second review\n"}]' \
  "$WORK/current.json" > "$WORK/replace.json"
alti ide workspace file-plan --project "$PROJECT" \
  --request "$WORK/replace.json" > "$WORK/replace.plan.json"
cat "$WORK/replace.plan.json"

审查替换内容,然后应用:

alti ide workspace file-apply --project "$PROJECT" \
  --request "$WORK/replace.plan.json" > "$WORK/replace.receipt.json"
jq '{schema, outcome}' "$WORK/replace.receipt.json"

请确认退出状态为0,且outcome等于committed。

删除文件

再次读取文件以获取当前摘要,然后准备删除:

alti ide workspace read --project "$PROJECT" notes/review.txt \
  > "$WORK/current.json"
jq '[{kind:"delete",path:"notes/review.txt",expected_sha256:.sha256}]' \
  "$WORK/current.json" > "$WORK/delete.json"
alti ide workspace file-plan --project "$PROJECT" \
  --request "$WORK/delete.json" > "$WORK/delete.plan.json"
cat "$WORK/delete.plan.json"

审查删除内容,然后应用:

alti ide workspace file-apply --project "$PROJECT" \
  --request "$WORK/delete.plan.json" > "$WORK/delete.receipt.json"
jq '{schema, outcome}' "$WORK/delete.receipt.json"

请确认退出状态为0,且outcome等于committed。

处理已更改的文件

如果命令报告workspace file precondition changed: notes/review.txt,请重新读取文件。审查当前内容,使用新的sha256准备所需的替换或删除,并在应用前生成和审查新计划。

如果报告authoring plan changed or is stale; generate and review a new plan,请为同一个项目重新生成计划,审查后再应用。

请使用上面的命令保存原生计划。通过全局--json保存的计划位于执行回执的stdout字符串中。请将完整的原生计划传给file-apply。

CLI首次成功操作