aggrega edit-document
對文件套用一次有界的結構化編輯,保留它未觸及的每個位元組
概要
aggrega edit-document <edit> <file> [flags]說明
Apply one bounded structured edit to a document in the workspace.
The edit is named first and the document second. One call adds one entry under one container, or sets one scalar, and it can do nothing else:
add-component add a component instance under a components container attach-feature attach a Feature to the node you name wire-edge wire a connection inside one of that node's sockets set-value set one value on that node
There is no edit that deletes, replaces a block you already wrote, reorders anything, or writes bytes you supply verbatim. The edits this command applies are add-component, attach-feature, wire-edge, set-value, and a name outside that set is refused rather than interpreted.
Name the node with --node, once per path segment, from the document root. It is a segment at a time rather than one dotted string because a dot is a legal character in a name you type, so a joined path could address a key nobody wrote and the entry would be created there rather than refused:
aggrega edit-document add-component app.yaml \ --node spec --node components --name web --value example/service
aggrega edit-document wire-edge app.yaml \ --node spec --node components --node web \ --socket database --name db --value spec.components.store
For add-component the path names the components container itself, because the entry being added is the node. For the other three it names the node the edit is about, and the container follows from the edit.
--name is the key the entry is written under: the instance name, the attachment's name, the connection's alias, or the value's key. --value is what that entry carries, and what it means follows from the edit — the entity the entry requests, the node a connection points at, or the scalar a value is set to. It is read as a YAML scalar, so --value 3 sets a number, --value true a boolean, and --value '"3"' the string; omitting it sets nothing at all.
Every byte the edit does not touch survives. The document is parsed only to locate the container and the line its block ends at, so comments, blank lines, quoting style, folded and literal scalars and the trailing-newline shape all carry through, and the nesting step is measured from the document's own indentation rather than imposed. The same request against the same document produces the same bytes.
The result has to be a document you could have typed, and that is what the write is gated on: the composed document is checked against its own kind's schema and reaches disk only if that passes. A request that would produce something the schema refuses is refused, naming the property the schema would not admit and where, and the file is left byte-for-byte as it was — so a refused edit is indistinguishable from one never attempted and you can retry a corrected request against the document you started with.
An entry that is already there, carrying what you asked for, is a no-op. An entry of that name carrying something else is refused rather than replaced.
--dry-run does everything the plain command does except write: the edited document goes to standard output as content, naming the file it is for, and nothing is created — for a caller that puts the result in front of someone before it is saved. Every other behaviour is the write's, the schema gate included, so a request the write would refuse is refused under --dry-run too and its exit code predicts the write's. Without it the document is written.
Whether what you wire is semantically admissible is not decided here. Whether a socket is one the producer declares, or whether a Feature's applicability is satisfied, is what aggrega validate answers.旗標
| 旗標 | 預設 | 說明 |
|---|---|---|
--dry-run | false | 除了寫入之外什麼都做:將編輯後的文件作為內容交回,指出它是為哪個檔案而作,且不建立或修改任何東西。其他所有行為都與寫入相同,包括結構描述的把關。沒有它時,文件會被寫入 |
--name | — | 新項目寫入時所用的鍵:元件實例名稱、附加項目的名稱、連線的別名,或值的鍵 |
--node | [] | 通往此編輯所針對之節點的結構路徑中的一個區段,從文件根開始。每個區段重複一次,由最外層開始。它一次接受一個區段,而不是一條以點連接的路徑,因為點是你輸入的名稱中合法的字元,所以連接起來的路徑可能會指向一個沒有人寫過的鍵 |
--socket | — | 連線所連接於其中的相依性插槽。對 wire-edge 會讀取,其他情況則忽略 |
--value | — | 項目所帶的內容,讀作 YAML 純量。其意義依編輯而定:項目所請求的實體、連線所指向的節點,或值被設定成的純量 |
運作方式
aggrega edit-document <edit> <file> 對你工作區中的文件套用一個結構化編輯,並讓它沒碰到的每個位元組都維持你所寫的原樣。先指定編輯,再指定文件:
aggrega edit-document add-component storefront.aggregate.yaml \ --node spec --node components \ --name checkout --value core/api-server:1.0.0它是為了這樣的情況而存在:你寧可讓檔案被編輯,也不要只被告知該在哪裡編輯。如果你擁有自己的緩衝區與復原歷程,aggrega serve 會回報位置,讓你自己放置文字;而這個命令則是組出項目並寫入。
文件必須是你的工作區所擁有的。 請以相對於工作區根目錄的方式,或以它的絕對路徑來指定;位於工作區之外的文件會被拒絕,不讀取也不寫入,無論它是這樣寫的,還是經由通往工作區之外的連結而到達——指向該檔案的連結,或途中某個作為連結的目錄。編輯在寫回之前會先讀取文件,因此位於這種連結之後的文件,是工作區並不持有的檔案,而拒絕訊息也這麼說:
the document named leads outside the workspace through a link, and an edit is only applied to a document the workspace carries: "shared/storefront.aggregate.yaml"若要編輯保存在別處的文件,請在持有它的工作區中執行命令。語言伺服器與 AI 助理工具的編輯也適用同一條規則,因為三者套用的是同一個編輯。它的文件,是你輸入的路徑中唯一受限於工作區的一個,如工作區邊界所述。
一次呼叫、一個項目,而且集合是封閉的
共有四種編輯,沒有其他:
| 編輯 | 它新增什麼 |
|---|---|
add-component | 元件容器之下的一個元件實例 |
attach-feature | 你指定之節點上的一個 Feature 附加項目 |
wire-edge | 該節點某個相依性插槽內的一條連線 |
set-value | 你指定之節點上的一個值 |
沒有任何編輯會刪除、取代你已寫好的區塊、重新排序任何東西,或寫入你逐字提供的位元組。 這是整個設計,而不是對它的限制:這四種以外的名稱在命令中根本沒有路徑可走,因此它不是換了較窄名稱的檔案寫入器。集合以外的名稱會被拒絕,而不是被解讀。
已經存在、且帶有你所要求內容的項目,是無操作——命令會這樣說明,並且不寫入任何東西:
storefront.aggregate.yaml already carries that entry; nothing was written同名但帶有其他內容的項目會被拒絕,而不是被取代,因為取代你所寫的內容不在這四種之中。
你以路徑一次一個區段來指定節點
--node 對從文件根開始的路徑,每個區段重複一次,由最外層開始:
aggrega edit-document wire-edge storefront.aggregate.yaml \ --node spec --node components --node web \ --socket database --name replica --value store它一次接受一個區段,而不是一條以點連接的路徑,這是刻意的,而理由與正確性有關。 點是你輸入的名稱中合法的字元,所以文件之外沒有任何東西能分辨結構上的點與名稱內的點。連接起來的路徑讀起來會是正確的,卻會指向一個沒有人寫過的鍵——而且因為 add-component 可以建立文件中沒有的容器,項目會落在那個憑空出現的鍵之下,而不是被拒絕。區段消除了這個歧義,而不是把它搬到別處。
對 add-component 而言,路徑指的是元件容器本身,因為被新增的項目就是該節點。對其他三種,路徑指的是編輯所針對的節點,容器則由編輯決定:附加項目放在該節點的 features 之下,連線放在它的 uses 與你指定的插槽之下,值放在它的 values 之下。
--name 是項目寫入時所用的鍵——實例名稱、附加項目的名稱、連線的別名,或值的鍵。--socket 對 wire-edge 會讀取,其他情況則忽略。
值保有其字元所帶的型別
--value 被讀作 YAML 純量,這與你把這些字元直接輸入文件時被讀取的方式相同:
aggrega edit-document set-value storefront.aggregate.yaml \ --node spec --node components --node web --name workers --value 4 values: replicas: 3 workers: 4因此 --value 4 設定的是數字,--value true 是布林值,而 --value '"4"' 是字串 4——引號在這裡表達「這是文字」,與在文件中完全一樣。省略 --value 則完全不設定任何東西。對應表或序列會被拒絕,因為寫入其一就等於新增一個區塊,而那不在這四種編輯之中。
你沒有編輯的一切都會保留,而相同的請求會產生相同的位元組
文件之所以被解析,只是為了找出容器與其區塊結束的那一行;項目是在行的層級上渲染並接合的。註解、空行、引號風格、折疊與字面純量、範本運算式以及結尾換行的形狀,都原封不動地保留,而縮排的階層是從文件自己的縮排量得,而不是強加的——所以項目會落在你已在使用的風格中。
給定相同的文件與相同的請求,每次的位元組都相同。因此你可以比較兩次執行,而審查者會把一次編輯讀成一個差異。
結果必須是你自己也可能輸入的文件
寫入就是以此為把關條件。 組出的文件會依它自己種類的結構描述來檢查——該結構描述是從文件讀出的,而不是由你提供——而只有通過之後,位元組才會寫到磁碟。會產生結構描述所拒絕之內容的請求會被拒絕,並指出結構描述不允許的屬性及其位置:
the edit was refused because the resulting document would not be valid, and nothingwas written: document envelope validation failed (Release, at prod.release.yaml);15:7: spec.components.web.values: … unexpected property: "values"檔案維持逐位元組的原狀,而且寫入本身是原子的,因此被拒絕或中斷的編輯與從未嘗試過的編輯無法區分,你可以針對你一開始的文件重試修正後的請求。這也是為什麼這裡沒有重述任何撰寫規則:要求 Release 文件帶有開發者的值,會被同一個會拒絕手寫文件的結構描述拒絕。
語意上什麼是可接受的,並不在這裡決定。 相依性插槽是否為生產端所宣告的插槽,或某個 Feature 的適用條件是否滿足,屬於建置所執行的解析。因此你可以指定一條此命令從未聽過的連線,而 Aggregate 也可以撰寫其目錄實體沒有預先宣告的插槽;能跨插槽被使用的內容,仍由生產端宣告。當問題是這個時,請執行 aggrega validate 並指定一個 Release。
在儲存之前查看結果
--dry-run 做平常的命令所做的一切,除了寫入:編輯後的文件會作為內容送到標準輸出,指出它是為哪個檔案而作,且不建立任何東西:
aggrega edit-document attach-feature storefront.aggregate.yaml \ --node spec --node components --node web \ --name tls --value core/tls:1.0.0 --dry-rundocuments: - path: storefront.aggregate.yaml content: | # The storefront application. ...沒有它時,文件會被寫入。 預設是寫入,因為這個命令的產物是編輯後的文件,而產生文件的命令就欠你這份文件——沒有說明要如何交付的請求,就是編輯檔案。
其他所有行為都與寫入相同,包括驗證把關。結果會被結構描述拒絕的編輯,在 --dry-run 下同樣被拒絕,指出相同的屬性,並讓檔案維持原狀——因此你從試執行得到的結束代碼,就是寫入會給你的結束代碼。
來自編輯器或 AI 助理的同一個編輯
無論由哪個介面套用編輯,位元組都相同。驅動 aggrega serve 的編輯器在 aggrega/editDocument 取得它,而透過 aggrega mcp 連線的 AI 助理則以此命令在那裡所公開的工具取得它。項目的組出、接合與驗證把關都在同一個地方完成,每個介面都只是通往它的薄入口——所以你在終端機編輯的文件與編輯器為你編輯的文件,逐位元組完全相同。
介面之間唯一不同之處,在於它們讀取哪些位元組。此命令與工作階段方法都讀取磁碟上的檔案,從不讀取未儲存的緩衝區:從緩衝區寫入,會在套用一個項目的名義下,把你尚未儲存的內容放上頁面。請先儲存,再編輯。
範例
在 Aggregate 的頂層新增一個元件實例:
aggrega edit-document add-component storefront.aggregate.yaml \ --node spec --node components --name checkout --value core/api-server:1.0.0將一個 Feature 附加到在子系統內撰寫的元件:
aggrega edit-document attach-feature storefront.aggregate.yaml \ --node spec --node subsystems --node billing --node components --node ledger \ --name audit-log --value core/observability/audit-log:1.0.0在子系統內撰寫的元件上設定一個值:
aggrega edit-document set-value storefront.aggregate.yaml \ --node spec --node subsystems --node billing --node components --node ledger \ --name replicas --value 5在寫入任何內容之前先檢視結果:
aggrega edit-document wire-edge storefront.aggregate.yaml \ --node spec --node components --node web \ --socket cache --name sessions --value redis --dry-run若要在指定容器之前先找出某個項目屬於哪個容器,以及在不套用任何東西的情況下讀取位置,請參閱 aggrega serve。