aggrega draft
為實體種類草擬起始文件,或將可執行的範例寫入新目錄
概要
aggrega draft <kind> [name] | --example <name> [dir] | --example --list [flags]說明
Draft a starter document for an entity kind from its schema, or write one of the documentation's runnable examples into a new directory.
Drafting a starter document
The kind is the lowercase-hyphenated schema token — for example component, aggregate, release, recipe, manifest, or feature. Run aggrega get-schema --list to print the whole set; a token no schema answers to is refused with that set in the message, so a typo is corrected without a second lookup.
The document is derived from that kind's own contract and from nothing else. It carries exactly the fields that kind's schema requires, with the fixed apiVersion and kind filled in and a placeholder everywhere a value is needed. It is not a worked example: there is no namespace, no category, no label set and no commented suggestion of what people usually write, because a catalog decides those for itself and a starter document that guessed at them would teach a requirement that does not exist.
The optional name seeds metadata.name for a kind whose schema requires one. Every other required value is left as a placeholder to fill in.
Nothing is written to disk. The document goes to standard output, so a redirect decides where it lands:
aggrega draft component my-service > my-service.yaml
The same starter document is served to an assistant by the draft tool that aggrega mcp exposes, which returns these bytes alongside a machine-readable payload; this command is the terminal route to the same drafting.
Writing a runnable example
With --example, the argument is the name of one of the runnable examples the documentation publishes, and the command writes that example's files into a new directory — the second argument, or a directory named after the example in the current directory when there is none — then prints the commands the example's own page gives for building it:
aggrega draft --example redis-cache
The directory must not exist yet, or must be empty; a directory holding anything is refused and left as it is. With --list, the command prints every example there is, each with its level and the first sentence of its page, and writes nothing:
aggrega draft --example --list
The examples are read from the documentation bundle published for this version of aggrega on the default registry — or, where none is published for it, the newest one published for an earlier version. It is kept in the cache every project on this machine shares, so a second example needs no second download. It is fetched through the same network settings as every other registry read, and verified against this workspace's signature policy before it is kept or read; a bundle that does not verify is refused, never used. Offline, an example is written only from a copy already cached on this machine.
An example's files are written only as files and directories inside the directory named: a bundle carrying an entry that would land outside it, or a link, is refused whole and nothing is written.
The draft tool that aggrega mcp exposes, and the editor's language server that aggrega serve runs, write and list the examples on the same terms, with the directory named relative to the workspace root, and answer with the files written and these same commands.旗標
| 旗標 | 預設 | 說明 |
|---|---|---|
--example | false | 將引數所指名的可執行範例,從已簽署的文件套組中讀出,寫入一個新目錄 |
--list | false | 與 —example 並用時,印出文件發布的每個可執行範例,且不寫入任何東西 |
運作方式
這個命令有兩種形式。aggrega draft <kind> 會根據某個種類的結構描述草擬一份起始文件並印出它,這是本節與接下來三節所描述的。aggrega draft --example <name> 則改為把文件的可執行範例之一寫入新目錄——請見從可執行範例開始。
aggrega draft <kind> 會把一個實體種類的起始文件印到標準輸出。該文件恰好帶有該種類的結構描述所要求的欄位:apiVersion 與 kind 已填好,因為結構描述固定了它們,而其他每個必要的值都留作佔位符,等你取代。
選用的 [name] 會為結構描述要求名稱的種類設定 metadata.name:
aggrega draft component my-serviceapiVersion: aggrega.ai/v1beta1kind: Componentmetadata: name: my-service version: "" labels: component.aggrega.ai/type: ""spec: {}種類是小寫、以連字號相連的結構描述權杖——component、aggregate、release、recipe、manifest、feature,以及其餘的。aggrega get-schema --list 會印出整個集合,而沒有任何結構描述對應的權杖會被拒絕,訊息中附帶該集合,所以打錯字不必再查一次就能更正。
它交回什麼,以及不交回什麼
**文件來自種類自己的契約,不來自其他任何東西。**它不是實作範例。沒有命名空間、沒有類別、沒有替你填好的標籤值,也沒有人們通常會寫什麼的註解建議——因為這些都不是編譯器所要求的。目錄自行選擇它的命名、它的類別與它的目錄配置;結構描述決定欄位,而結構描述是這個命令唯一讀取的東西。一份對其餘部分加以猜測的起始文件,會教你一條並不存在的規則。
**草擬不會寫入任何檔案。**文件會送到標準輸出,所以由重新導向決定它落在哪裡,而且沒有任何東西會在你沒有要求的情況下於磁碟上被取代:
aggrega draft component my-service > my-service.yaml**它不是完成的實體,這就是佔位符的意思。**空的必要值不是值,所以對原樣輸出的文件執行 aggrega validate 會拒絕它,並一次指名每個仍待補上的佔位符,各附它所需的內容——上方是版本與元件型別:
Entity: my-service.yamlKind: Component[E0215] document envelope validation failed: 2 placeholders still owed in my-service.yaml; an empty required value is not a value, so each of these needs one before the document validates: 5:3: metadata.version takes a semantic version, such as 1.0.0 7:5: metadata.labels.component.aggrega.ai/type takes one of: server, worker, task, function, stateful-server, resource每個值需要什麼,是從種類自己的結構描述讀取的:結構描述列出時它所接受的值、要求時的語意化版本,以及其他情況下結構描述自己對該欄位的描述。補上這些值,同一個命令就會接受該文件。它的形狀完全不必改變,因為形狀就來自結構描述。
**即使結構描述會接受空值,仍有值待補。**草擬出的 Recipe 或 FeatureRecipe 帶有空的 capability 與 implements。它們的結構描述允許空字串,但空的並未指名任何提供者與任何型別,所以 aggrega validate 會把兩者都指名為仍待補上,直到你填入為止。這種判讀屬於驗證單一實體檔案:整個目錄的執行、aggrega validate --release 與 aggrega build 都不套用它。它涵蓋什麼,請見仍待補上的佔位符。草擬出的 Recipe 也不宣告其結構描述要求至少有一個的任何輸入種類——source、valuesMapping、workload 或 artifacts——因為哪一個合適由你選擇,所以 aggrega validate 會拒絕它的 spec,直到你加入其中之一。
來自 AI 助理或編輯器的同一份文件
無論由哪個介面要求,起始文件的位元組都相同。透過 aggrega mcp 連線的 AI 助理以 draft 工具取得它,該工具會將文件以文字回傳,並附上機器可讀的酬載。驅動 aggrega serve 的編輯器則在 aggrega/scaffoldEntity 取得它。文件只從結構描述衍生一次,因此你在終端機草擬的文件與 AI 助理為你草擬的文件,逐位元組完全相同。
撰寫與列出可執行範例也在相同的介面上,欄位名稱沿用命令自己的用語。傳送 draft 工具或 aggrega/scaffoldEntity,以 example 取代 kind 來寫出一個範例,以 dir 指定相對於工作區根目錄的新目錄——若未傳送,則是以範例命名、位於該處的目錄——並單獨傳送 list: true 以取得所有範例的回覆。範例讀自同一個套件,以同一份原則驗證,並由同一套解壓縮寫出,因此檔案與接下來的命令和在終端機上相同,拒絕的情況也相同:已有內容的目錄、通往目錄之外的項目或連結、你的原則不接受的套件、沒有任何快取的離線工作區。回答是結構化的:列表時為 examples,每個項目有其 name、level 與 summary;寫出時為 example、dir、files(寫出的檔案,相對於 dir)、next(範例頁面給出的命令),以及 version(讀取範例所用的文件版本)。draft 工具對寫出的回答還包含 output_dir,也就是目錄所在之處——在標準輸入與輸出上為完整路徑,因此以相對於它看不到的工作區來命名的 AI 助理也能讀到範例寫到哪裡,而在 HTTP 上則是相對於工作區根目錄。draft 工具的文字是此命令印出的說明,在與 dir 不同時,結尾會加上一行指出該位置。同時傳送兩種形式的欄位——例如 kind 加 example——會在讀取任何東西之前,以相同的文字在兩邊同樣被拒絕。編輯器在請求的 workspaceRoot 中指明範例形式的工作區,而 dir 必須是留在其內、且不會經由連結通往其外的相對路徑;在 HTTP 上,工具也會把 dir 限制在它所服務的工作區內,而在標準輸入與輸出上,它照原樣接受 dir,如同接受每個路徑一樣。功能索引將 draft 工具回報為會寫入,因為有該形式;而在另一個處理程序中執行此命令的 cli-draft 也同樣回報為會寫入。
從可執行範例開始
文件附有可執行範例——每個範例都是一個目錄,內含一個 Aggregate、它的 Releases 與其建置所需的其他內容,並附一個說明如何建置的頁面。--example 會將其中一個寫入新目錄,讓你從可運作的專案開始,而不是從空白開始:
aggrega draft --example redis-cacheWrote the example redis-cache into redis-cache (12 files).
Next:
cd redis-cache # Local development (Docker Compose), no authentication aggrega build --release release-compose.yaml --auto-pull ...
Its page, redis-cache/README.md, explains what it shows.它寫出什麼,以及寫在哪裡。 範例的檔案,依文件所附的樣子,寫入你以第二個引數指定的目錄——若未指定,則寫入在你執行命令的資料夾中、以範例命名的目錄。該目錄必須尚不存在,或必須是空的。其他情況一律拒絕,並讓它維持原狀:內含檔案的目錄、位於該路徑上的檔案,或連結。上層尚不存在的目錄會被建立。範例的檔案不會留在任何其他地方,而且在全部寫好之前不會有任何一個就位:它們先寫在一旁,待全部到齊後才一併移入。
它接著印出的命令,是範例自己的頁面所給的命令:在 cd 進入該目錄之後,頁面 ## Build 標題下第一個 sh、bash 或 shell 區塊,連同註解,照頁面所寫。若範例的頁面沒有這樣的區塊,則改回答其頁面的路徑。
有哪些範例。 --list 依文件教學的順序,每個範例印出一次——它的名稱、其頁面宣告的等級,以及頁面的第一句——並且不寫入任何東西:
aggrega draft --example --listEXAMPLE LEVEL DESCRIPTION...redis-cache start This lean example compiles a single **Redis** in-memory cache (Redis wire protocol) from one Developer-authored `Aggregate` to two realizations....這份清單就是文件自己的範例清單,與範例並列發布,名為依產品與能力列出的範例。套件中沒有該名稱的範例時會被拒絕,並指引你使用 --list,且不寫入任何東西。
範例來自哪裡。 它們讀自文件套件——已發布文件的簽署封存檔,aggrega explain 也從中讀取逐步說明——發布在你工作區的預設登錄庫上。讀取的套件是為你正在執行的 aggrega 版本發布的那一個。若該版本沒有發布,則使用為較早發行版本發布的最新一個,並且命令會在標準錯誤上說明:
note: no documentation is published for 0.9.1; the examples are read from the documentation published for 0.9.0, the newest before it從某個發行版本之後再多出數個提交所建置的 aggrega——其 aggrega version 讀起來像 0.9.0-12-g1a2b3c4d——會讀取它所接續之發行版本的文件,此處為 0.9.0,若該版本沒有發布,則讀取較早的版本。從某個預先發行版本(例如候選發行版本)之後再多出數個提交所建置的版本——其 aggrega version 讀起來像 0.9.0-rc.6-4-gc9db2f597——會讀取該預先發行版本的文件,此處為 0.9.0-rc.6,或者在該版本未發布時,讀取在它之前發布的最新一個,包括較早的預先發行版本。任何其他建置,只有在它本身就是該預先發行版本時,才會讀取預先發行版本的文件。沒有標示任何發行版本編號的建置,只讀取它自己版本的文件,否則不讀。aggrega explain 以相同的方式選擇它讀取逐步說明的套件。
若你的版本沒有發布,而最新的較早版本所用的格式是此版本的 aggrega 已不再讀取的——例如在候選發行版本自己的文件發布之前就執行了它——命令會拒絕,並在一句話中說出這兩件事,且不寫入任何東西:
[E0137] hub.aggrega.ai/docs/aggrega-docs publishes no documentation bundle for 0.9.1-rc.1, and the newest earlier one, 0.8.11, is in a format this version of aggrega no longer reads, so the examples cannot be read它在使用前會先驗證。 套件透過與其他所有登錄庫讀取相同的網路設定取得,並且在保留之前,會依你的工作區對該登錄庫的簽章原則檢查其簽章——在讀取本機上已有的副本之前也會再檢查一次,因此另一個專案較寬鬆的原則所放入的副本,不會在你的原則下被使用。你的原則不接受的套件會被拒絕,且不寫入任何東西。
每台機器只取得一次。 套件保存在該機器上每個 Aggrega 專案共用的快取中——參見 aggrega cache——因此第二個範例或第二個專案不需要再次下載,而且在兩者讀取同一版本時,aggrega explain 讀取的是同一份副本。
離線時,只讀取已快取的內容。 在離線工作區中不會取得任何東西:範例是從機器上已有、且你的原則允許的副本寫出——此版本的副本,否則是已快取的最新較早版本——若都沒有,命令便以每個網路讀取都會給出的離線拒絕訊息拒絕,並說明如何允許使用網路。
帶有意外內容的套件會整個被拒絕。 套件來自登錄庫,因此解壓縮不信任其版面配置的任何事:名稱會落在你指定的目錄之外或套件之外的項目,以及屬於連結或檔案與目錄以外任何東西的項目,各自都會使整個範例被拒絕,並指出該項目,且不寫入任何東西。範例中的可執行檔案仍保持可執行。
會讀取工作區的設定。 預設登錄庫與簽章原則皆來自其中,因此當設定檔是通往工作區之外的連結時,範例形式會被停止,如同它會停止每個讀取設定的其他命令——參見工作區邊界。
範例
草擬一個未命名的 Release 並在終端機上閱讀:
aggrega draft release將一個 Recipe 直接草擬到檔案中:
aggrega draft recipe postgres-helm > postgres-helm.yaml在填入任何內容之前,先檢查你還欠缺什麼:
aggrega draft component my-service > my-service.yamlaggrega validate my-service.yaml查看有哪些可執行範例,再將其中一個寫入你選擇的目錄:
aggrega draft --example --listaggrega draft --example redis-cache my-cache關於此命令開啟的撰寫循環——草擬形狀、填入預留位置、驗證——請參閱撰寫 Aggrega 檔案。