Просмотр исходного кода

feat(command): identify command sources

Brendan Allan 3 недель назад
Родитель
Сommit
3cd894d40a

+ 5 - 1
packages/core/src/command.ts

@@ -85,6 +85,7 @@ export const layer = (options?: ShellSelect.Options) => Layer.effect(
           name: mcpCommandName(prompt.server, prompt.name),
           template: "",
           description: prompt.description,
+          source: "mcp",
         }),
       )
     })
@@ -98,7 +99,10 @@ export const layer = (options?: ShellSelect.Options) => Layer.effect(
         return (yield* mcpCommands()).find((command) => command.name === name)
       }),
       list: Effect.fn("CommandV2.list")(function* () {
-        const commands = Array.from(state.get().commands.values()) as Info[]
+        const commands = Array.from(state.get().commands.values()).map((command) => ({
+          ...command,
+          source: command.source ?? "command" as const,
+        }))
         const names = new Set(commands.map((command) => command.name))
         return [
           ...commands,

+ 1 - 0
packages/core/test/command.test.ts

@@ -59,6 +59,7 @@ describe("CommandV2", () => {
             providerID: ProviderV2.ID.make("anthropic"),
             variant: ModelV2.VariantID.make("high"),
           },
+          source: "command",
         }),
       ])
     }),

+ 3 - 2
packages/core/test/config/command.test.ts

@@ -95,9 +95,10 @@ Review files`,
                 variant: ModelV2.VariantID.make("high"),
               },
               subtask: true,
+              source: "command",
             }),
-            CommandV2.Info.make({ name: "empty", template: "" }),
-            CommandV2.Info.make({ name: "nested/docs", template: "Write docs" }),
+            CommandV2.Info.make({ name: "empty", template: "", source: "command" }),
+            CommandV2.Info.make({ name: "nested/docs", template: "Write docs", source: "command" }),
           ])
 
           yield* Effect.promise(() => fs.writeFile(path.join(tmp.path, "commands", "review.md"), "Review again"))

+ 1 - 0
packages/schema/src/command.ts

@@ -16,6 +16,7 @@ export const Info = Schema.Struct({
   agent: Agent.ID.pipe(optional),
   model: Model.Ref.pipe(optional),
   subtask: Schema.Boolean.pipe(optional),
+  source: Schema.Literals(["command", "mcp"]).pipe(optional),
 }).annotate({ identifier: "Command.Info" })
 
 export const Event = {