command-doc.ts
This file
Path
packages/agent-kit/src/command-doc.ts
221 lines · 5.5 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–147why, one step back1import {2 Cli,3 Description,4 NeedsApproval,5 ReadOnly,6 Surfaces,7} from "@repo/protocol/contracts";8import type { Contracts } from "@repo/protocol/contracts";9import { Array as Arr, Context, Order, Schema, SchemaAST } from "effect";1011export const CommandDoc = Schema.Struct({12 contract: Schema.optionalKey(Schema.NonEmptyString),13 flags: Schema.Array(Schema.NonEmptyString),14 needsApproval: Schema.Boolean,15 path: Schema.NonEmptyArray(Schema.NonEmptyString),16 positional: Schema.Array(Schema.NonEmptyString),17 readOnly: Schema.Boolean,18 source: Schema.Literals(["contract", "local"]),19 summary: Schema.NonEmptyString,20});2122export type CommandDoc = typeof CommandDoc.Type;2324export const localCommandDocs: readonly CommandDoc[] = [25 {26 flags: [27 "--url",28 "--profile",29 "--token-stdin",30 "--no-browser",31 "--no-git-config",32 "--json",33 ],34 needsApproval: false,35 path: ["login"],36 positional: [],37 readOnly: false,38 source: "local",39 summary: "Sign in to a platform; git and this CLI then use its token.",40 },41 {42 flags: ["--profile", "--json"],43 needsApproval: false,44 path: ["logout"],45 positional: [],46 readOnly: false,47 source: "local",48 summary: "Forget a platform's stored token.",49 },50 {51 contract: "initProject",52 flags: [53 "--project",54 "--import",55 "--branch",56 "--yes",57 "--dry-run",58 "--push",59 "--no-push",60 "--json",61 ],62 needsApproval: true,63 path: ["init"],64 positional: [],65 readOnly: false,66 source: "local",67 summary:68 "Make this repo, or a public HTTPS repo, a project: find its checks, write its config and push.",69 },70 {71 flags: [72 "--ask",73 "--project",74 "--base",75 "--offline",76 "--shape-only",77 "--lane",78 "--dir",79 "--json",80 ],81 needsApproval: false,82 path: ["check"],83 positional: [],84 readOnly: true,85 source: "local",86 summary: "Run the gate's checks on your answer locally, before you push.",87 },88 {89 contract: "landing",90 flags: ["--project", "--json"],91 needsApproval: false,92 path: ["why"],93 positional: ["location"],94 readOnly: true,95 source: "local",96 summary:97 "Explain a line: the ask, the answer and the people that landed it.",98 },99 {100 contract: "setEnv",101 flags: ["--project", "--acknowledge-short", "--yes", "--dry-run", "--json"],102 needsApproval: true,103 path: ["env", "set"],104 positional: ["key"],105 readOnly: false,106 source: "local",107 summary:108 "Set a sensitive env item's value from stdin; nobody can read it back.",109 },110 {111 flags: ["--json"],112 needsApproval: false,113 path: ["hook"],114 positional: ["event"],115 readOnly: true,116 source: "local",117 summary:118 "Answer a harness hook (session-start, pre-tool-use, stop) with the gate's policy.",119 },120 {121 flags: [],122 needsApproval: false,123 path: ["credential"],124 positional: ["operation"],125 readOnly: false,126 source: "local",127 summary:128 "Be git's credential helper: hand git the stored token for a platform.",129 },130 {131 flags: [],132 needsApproval: false,133 path: ["mcp"],134 positional: [],135 readOnly: false,136 source: "local",137 summary: "Serve the platform's tools over MCP on stdio.",138 },139 {140 flags: ["--json"],141 needsApproval: false,142 path: ["schema"],143 positional: ["command"],144 readOnly: true,145 source: "local",146 summary: "Print the JSON Schema of a command's payload.",147 },Wire `today --tui` into the CLI, and keep the decision under the cursor on screenoscabrielbefore adoption368c432
lines 148–158why, one step back148 {149 contract: "today",150 flags: ["--project", "--tui", "--json"],151 needsApproval: false,152 path: ["today"],153 positional: [],154 readOnly: true,155 source: "local",156 summary:157 "Show your Today: the decisions to take, each with its evidence and a safe default; --tui opens it full-screen at a terminal.",158 },Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 159–221why, one step back159];160161const standIns = new Set(162 localCommandDocs.flatMap(({ contract, path }) =>163 contract === undefined ? [] : [path.join(" ")]164 )165);166167const fieldsOf = (ast: SchemaAST.AST) =>168 SchemaAST.isObjects(ast)169 ? ast.propertySignatures.map(({ name }) => String(name))170 : [];171172export const contractCommandDocs = (173 group: typeof Contracts174): readonly CommandDoc[] =>175 [...group.requests.values()].flatMap((rpc) => {176 const { annotations } = rpc;177 const cli = Context.get(annotations, Cli);178 const name = cli.name ?? rpc._tag;179 const [first, ...rest] = name.split(" ");180181 if (182 first === undefined ||183 !Context.get(annotations, Surfaces).includes("cli") ||184 standIns.has(name)185 ) {186 return [];187 }188189 const positional = cli.positional ?? [];190 const readOnly = Context.get(annotations, ReadOnly);191 const needsApproval = Context.get(annotations, NeedsApproval);192193 const flags = fieldsOf(rpc.payloadSchema.ast)194 .filter((field) => !positional.includes(field))195 .map((field) => `--${field}`);196197 return [198 {199 contract: rpc._tag,200 flags: [201 ...flags,202 "--json",203 ...(needsApproval ? ["--yes"] : []),204 ...(readOnly ? [] : ["--dry-run"]),205 ],206 needsApproval,207 path: [first, ...rest],208 positional: [...positional],209 readOnly,210 source: "contract",211 summary: Context.get(annotations, Description),212 },213 ];214 });215216const byWords = Order.mapInput(Order.String, (doc: CommandDoc) =>217 doc.path.join(" ")218);219220export const commandDocs = (group: typeof Contracts): readonly CommandDoc[] =>221 Arr.sort([...contractCommandDocs(group), ...localCommandDocs], byWords);