@chef.extension/agent 0.0.0-alpha.0 → 0.0.0-stage

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,3 @@
1
- # @chef.extension/agent
1
+ # Temporary Holding Version
2
2
 
3
- Run Claude Code and Codex agents in Chef tasks.
4
-
5
- Alpha release. Install with `npm install @chef.extension/agent@alpha`.
6
-
7
- See https://github.com/Rowenin/alchemy-chef for usage and documentation.
3
+ This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
package/package.json CHANGED
@@ -1,40 +1,6 @@
1
1
  {
2
2
  "name": "@chef.extension/agent",
3
- "version": "0.0.0-alpha.0",
4
- "description": "Run Claude Code and Codex agents in Chef tasks.",
5
- "type": "module",
6
- "files": [
7
- "dist",
8
- "ui"
9
- ],
10
- "exports": {
11
- ".": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/index.js"
14
- },
15
- "./package.json": "./package.json",
16
- "./*": {
17
- "types": "./dist/*.d.ts",
18
- "default": "./dist/*.js"
19
- }
20
- },
21
- "engines": {
22
- "node": ">=22.22.3 <23 || >=24.11.1 <25 || >=25.1.0"
23
- },
24
- "publishConfig": {
25
- "access": "public",
26
- "tag": "alpha"
27
- },
28
- "dependencies": {
29
- "@anthropic-ai/claude-agent-sdk": "0.3.323",
30
- "@openai/codex-sdk": "0.169.0",
31
- "effect": "4.1.4"
32
- },
33
- "peerDependencies": {
34
- "@chef.run/core": ">=0.1.0-alpha.1 <0.1.0"
35
- },
36
- "repository": {
37
- "type": "git",
38
- "url": "git+https://github.com/Rowenin/alchemy-chef.git"
39
- }
3
+ "version": "0.0.0-stage",
4
+ "stub": true,
5
+ "description": "Temporary package placeholder for staged publishing"
40
6
  }
package/dist/Claude.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import { type Access, type Harness } from "./Harness.ts";
2
- export interface ClaudeOptions {
3
- /** An Anthropic model id, e.g. `claude-opus-5-5`. */
4
- readonly model: string;
5
- readonly effort?: "low" | "medium" | "high" | "xhigh" | "max";
6
- /** @default "read-only" */
7
- readonly access?: Access;
8
- /** Tools the agent may use without asking, in Claude Code's rule syntax, e.g. `Bash(gh pr view:*)`. */
9
- readonly allowedTools?: ReadonlyArray<string>;
10
- readonly maxTurns?: number;
11
- /** Which settings files to load; `project` brings in the repository's CLAUDE.md. @default ["project"] */
12
- readonly settingSources?: ReadonlyArray<"user" | "project" | "local">;
13
- /** The `claude` executable. @default `CHEF_AGENT_CLAUDE_PATH`, then `claude` on the PATH */
14
- readonly executable?: string;
15
- }
16
- /** Claude Code through the Claude Agent SDK, authenticated however the runner's Claude Code is. */
17
- export declare const claude: (options: ClaudeOptions) => Harness;
package/dist/Claude.js DELETED
@@ -1,75 +0,0 @@
1
- import { Effect } from "effect";
2
- import { AgentFailed, failure, findExecutable, } from "./Harness.js";
3
- const permissions = {
4
- "read-only": { permissionMode: "dontAsk" },
5
- "workspace-write": { permissionMode: "acceptEdits" },
6
- full: { permissionMode: "bypassPermissions", allowDangerouslySkipPermissions: true },
7
- };
8
- const queryOptions = (executable, options, request, abortController) => ({
9
- model: options.model,
10
- abortController,
11
- ...permissions[options.access ?? "read-only"],
12
- settingSources: [...(options.settingSources ?? ["project"])],
13
- ...(options.effort === undefined ? {} : { effort: options.effort }),
14
- ...(options.allowedTools === undefined ? {} : { allowedTools: [...options.allowedTools] }),
15
- ...(options.maxTurns === undefined ? {} : { maxTurns: options.maxTurns }),
16
- ...(executable === undefined ? {} : { pathToClaudeCodeExecutable: executable }),
17
- ...(request.cwd === undefined ? {} : { cwd: request.cwd }),
18
- ...(request.session === undefined ? {} : { resume: request.session }),
19
- ...(request.instructions === undefined
20
- ? {}
21
- : { systemPrompt: { type: "preset", preset: "claude_code", append: request.instructions } }),
22
- ...(request.outputSchema === undefined
23
- ? {}
24
- : { outputFormat: { type: "json_schema", schema: { ...request.outputSchema } } }),
25
- });
26
- /** Claude Code through the Claude Agent SDK, authenticated however the runner's Claude Code is. */
27
- export const claude = (options) => ({
28
- name: "claude",
29
- model: options.model,
30
- turn: (request) => Effect.gen(function* () {
31
- const sdk = yield* Effect.tryPromise({
32
- try: () => import("@anthropic-ai/claude-agent-sdk"),
33
- catch: failure("claude"),
34
- });
35
- const result = yield* Effect.tryPromise({
36
- try: async (signal) => {
37
- const abortController = new AbortController();
38
- signal.addEventListener("abort", () => abortController.abort(), { once: true });
39
- let last;
40
- for await (const message of sdk.query({
41
- prompt: request.prompt,
42
- options: queryOptions(findExecutable(options.executable, "CHEF_AGENT_CLAUDE_PATH", "claude"), options, request, abortController),
43
- })) {
44
- if (message.type === "result")
45
- last = message;
46
- }
47
- return last;
48
- },
49
- catch: failure("claude"),
50
- });
51
- if (result === undefined)
52
- return yield* new AgentFailed({
53
- harness: "claude",
54
- message: "Claude Code ended without a result",
55
- });
56
- if (result.subtype !== "success" || result.is_error)
57
- return yield* new AgentFailed({
58
- harness: "claude",
59
- message: result.subtype === "success"
60
- ? result.result
61
- : `${result.subtype}: ${result.errors.join("; ")}`,
62
- });
63
- return {
64
- session: result.session_id,
65
- text: result.result,
66
- structured: result.structured_output,
67
- usage: {
68
- inputTokens: result.usage.input_tokens,
69
- cachedInputTokens: result.usage.cache_read_input_tokens,
70
- outputTokens: result.usage.output_tokens,
71
- costUsd: result.total_cost_usd,
72
- },
73
- };
74
- }),
75
- });
package/dist/Codex.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { ModelReasoningEffort } from "@openai/codex-sdk";
2
- import { type Access, type Harness } from "./Harness.ts";
3
- export interface CodexOptions {
4
- /** An OpenAI model id, e.g. `gpt-6-astra`. */
5
- readonly model: string;
6
- readonly effort?: ModelReasoningEffort;
7
- /** @default "read-only" */
8
- readonly access?: Access;
9
- /** @default false */
10
- readonly network?: boolean;
11
- /** The `codex` executable. @default `CHEF_AGENT_CODEX_PATH`, then `codex` on the PATH */
12
- readonly executable?: string;
13
- }
14
- /** Codex through the Codex SDK, authenticated however the runner's Codex CLI is. */
15
- export declare const codex: (options: CodexOptions) => Harness;
package/dist/Codex.js DELETED
@@ -1,66 +0,0 @@
1
- import { Effect } from "effect";
2
- import { AgentFailed, failure, findExecutable } from "./Harness.js";
3
- const sandbox = {
4
- "read-only": "read-only",
5
- "workspace-write": "workspace-write",
6
- full: "danger-full-access",
7
- };
8
- const parse = (text) => {
9
- try {
10
- return JSON.parse(text);
11
- }
12
- catch {
13
- return text;
14
- }
15
- };
16
- /** Codex through the Codex SDK, authenticated however the runner's Codex CLI is. */
17
- export const codex = (options) => ({
18
- name: "codex",
19
- model: options.model,
20
- turn: (request) => Effect.gen(function* () {
21
- const sdk = yield* Effect.tryPromise({
22
- try: () => import("@openai/codex-sdk"),
23
- catch: failure("codex"),
24
- });
25
- const executable = findExecutable(options.executable, "CHEF_AGENT_CODEX_PATH", "codex");
26
- const client = yield* Effect.try({
27
- try: () => new sdk.Codex(executable === undefined ? {} : { codexPathOverride: executable }),
28
- catch: failure("codex"),
29
- });
30
- const threadOptions = {
31
- model: options.model,
32
- sandboxMode: sandbox[options.access ?? "read-only"],
33
- approvalPolicy: "never",
34
- skipGitRepoCheck: true,
35
- networkAccessEnabled: options.network ?? false,
36
- ...(options.effort === undefined ? {} : { modelReasoningEffort: options.effort }),
37
- ...(request.cwd === undefined ? {} : { workingDirectory: request.cwd }),
38
- };
39
- const thread = request.session === undefined
40
- ? client.startThread(threadOptions)
41
- : client.resumeThread(request.session, threadOptions);
42
- const prompt = request.instructions === undefined || request.session !== undefined
43
- ? request.prompt
44
- : `${request.instructions}\n\n${request.prompt}`;
45
- const turn = yield* Effect.tryPromise({
46
- try: (signal) => thread.run(prompt, {
47
- signal,
48
- ...(request.outputSchema === undefined ? {} : { outputSchema: request.outputSchema }),
49
- }),
50
- catch: failure("codex"),
51
- });
52
- const error = turn.items.find((item) => item.type === "error");
53
- if (turn.finalResponse === "" && error !== undefined)
54
- return yield* new AgentFailed({ harness: "codex", message: error.message });
55
- return {
56
- session: thread.id ?? undefined,
57
- text: turn.finalResponse,
58
- structured: request.outputSchema === undefined ? undefined : parse(turn.finalResponse),
59
- usage: {
60
- inputTokens: turn.usage?.input_tokens ?? 0,
61
- cachedInputTokens: turn.usage?.cached_input_tokens ?? 0,
62
- outputTokens: turn.usage?.output_tokens ?? 0,
63
- },
64
- };
65
- }),
66
- });
package/dist/Harness.d.ts DELETED
@@ -1,60 +0,0 @@
1
- import { Effect, Schema } from "effect";
2
- /** What the agent may do to the machine it runs on. */
3
- export type Access = "read-only" | "workspace-write" | "full";
4
- export declare const Usage: Schema.Struct<{
5
- readonly inputTokens: Schema.Finite;
6
- readonly cachedInputTokens: Schema.Finite;
7
- readonly outputTokens: Schema.Finite;
8
- /** Only Claude reports cost. */
9
- readonly costUsd: Schema.optionalKey<Schema.Finite>;
10
- }>;
11
- export type Usage = typeof Usage.Type;
12
- export declare const emptyUsage: Usage;
13
- export declare const addUsage: (a: Usage, b: Usage) => Usage;
14
- declare const AgentFailed_base: Schema.Class<AgentFailed, Schema.TaggedStruct<"AgentFailed", {
15
- readonly harness: Schema.String;
16
- readonly message: Schema.String;
17
- }>, import("effect/Cause").YieldableError & {
18
- readonly brand: unique symbol;
19
- }>;
20
- /** The agent could not finish the turn: it errored, was refused, or its process failed. */
21
- export declare class AgentFailed extends AgentFailed_base {
22
- }
23
- declare const AgentOutputInvalid_base: Schema.Class<AgentOutputInvalid, Schema.TaggedStruct<"AgentOutputInvalid", {
24
- readonly harness: Schema.String;
25
- readonly issue: Schema.String;
26
- readonly raw: Schema.String;
27
- }>, import("effect/Cause").YieldableError & {
28
- readonly brand: unique symbol;
29
- }>;
30
- /** The agent finished, but its output never matched the task's `output` schema. */
31
- export declare class AgentOutputInvalid extends AgentOutputInvalid_base {
32
- }
33
- export interface TurnRequest {
34
- readonly prompt: string;
35
- readonly cwd?: string | undefined;
36
- readonly instructions?: string | undefined;
37
- /** An object JSON Schema in strict form; the turn must answer with matching JSON. */
38
- readonly outputSchema?: Readonly<Record<string, unknown>> | undefined;
39
- /** Continue this session instead of starting a new one. */
40
- readonly session?: string | undefined;
41
- }
42
- export interface TurnResult {
43
- readonly session: string | undefined;
44
- readonly text: string;
45
- /** The parsed JSON answer when `outputSchema` was set. */
46
- readonly structured: unknown;
47
- readonly usage: Usage;
48
- }
49
- /** One coding agent behind one interface. Plain data until `turn` runs, so it can sit in task props. */
50
- export interface Harness {
51
- readonly name: string;
52
- readonly model: string;
53
- readonly turn: (request: TurnRequest) => Effect.Effect<TurnResult, AgentFailed>;
54
- }
55
- /** A harness from a turn function, for agents this package does not ship or for tests. */
56
- export declare const make: (harness: Harness) => Harness;
57
- export declare const failure: (harness: string) => (cause: unknown) => AgentFailed;
58
- /** The agent's CLI: an explicit path, then `envVar`, then `command` on the PATH. Bundled SDKs cannot find their own. */
59
- export declare const findExecutable: (explicit: string | undefined, envVar: string, command: string) => string | undefined;
60
- export {};
package/dist/Harness.js DELETED
@@ -1,54 +0,0 @@
1
- import { accessSync, constants } from "node:fs";
2
- import { delimiter, join } from "node:path";
3
- import { Schema } from "effect";
4
- export const Usage = Schema.Struct({
5
- inputTokens: Schema.Finite,
6
- cachedInputTokens: Schema.Finite,
7
- outputTokens: Schema.Finite,
8
- /** Only Claude reports cost. */
9
- costUsd: Schema.optionalKey(Schema.Finite),
10
- });
11
- export const emptyUsage = { inputTokens: 0, cachedInputTokens: 0, outputTokens: 0 };
12
- export const addUsage = (a, b) => {
13
- const cost = a.costUsd === undefined && b.costUsd === undefined
14
- ? undefined
15
- : (a.costUsd ?? 0) + (b.costUsd ?? 0);
16
- return {
17
- inputTokens: a.inputTokens + b.inputTokens,
18
- cachedInputTokens: a.cachedInputTokens + b.cachedInputTokens,
19
- outputTokens: a.outputTokens + b.outputTokens,
20
- ...(cost === undefined ? {} : { costUsd: cost }),
21
- };
22
- };
23
- /** The agent could not finish the turn: it errored, was refused, or its process failed. */
24
- export class AgentFailed extends Schema.TaggedError()("AgentFailed", {
25
- harness: Schema.String,
26
- message: Schema.String,
27
- }) {
28
- }
29
- /** The agent finished, but its output never matched the task's `output` schema. */
30
- export class AgentOutputInvalid extends Schema.TaggedError()("AgentOutputInvalid", { harness: Schema.String, issue: Schema.String, raw: Schema.String }) {
31
- }
32
- /** A harness from a turn function, for agents this package does not ship or for tests. */
33
- export const make = (harness) => harness;
34
- export const failure = (harness) => (cause) => new AgentFailed({
35
- harness,
36
- message: cause instanceof Error ? cause.message : String(cause),
37
- });
38
- /** The agent's CLI: an explicit path, then `envVar`, then `command` on the PATH. Bundled SDKs cannot find their own. */
39
- export const findExecutable = (explicit, envVar, command) => {
40
- const configured = explicit ?? process.env[envVar];
41
- if (configured !== undefined)
42
- return configured;
43
- for (const directory of (process.env.PATH ?? "").split(delimiter)) {
44
- const candidate = join(directory, command);
45
- try {
46
- accessSync(candidate, constants.X_OK);
47
- return candidate;
48
- }
49
- catch {
50
- continue;
51
- }
52
- }
53
- return undefined;
54
- };
@@ -1,13 +0,0 @@
1
- import { Effect, Schema } from "effect";
2
- type JsonObject = Record<string, unknown>;
3
- /**
4
- * An output contract both agents accept: an object JSON Schema in OpenAI's
5
- * strict form. Optional keys become required-but-nullable, and a non-object
6
- * output is wrapped in `{ value }`.
7
- */
8
- export interface OutputSchema {
9
- readonly jsonSchema: JsonObject;
10
- readonly decode: (raw: unknown) => Effect.Effect<unknown, Schema.SchemaError>;
11
- }
12
- export declare const make: (schema: Schema.Top) => OutputSchema;
13
- export {};
@@ -1,81 +0,0 @@
1
- /* oxlint-disable typescript/no-unsafe-type-assertion -- JSON Schema documents are walked as untyped JSON. */
2
- import { Schema } from "effect";
3
- const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
- const resolver = (definitions) => (node) => {
5
- const ref = node.$ref;
6
- if (typeof ref !== "string")
7
- return node;
8
- const target = definitions[ref.slice(ref.lastIndexOf("/") + 1)];
9
- return isObject(target) ? target : node;
10
- };
11
- const strictify = (node) => {
12
- if (Array.isArray(node))
13
- return node.map(strictify);
14
- if (!isObject(node))
15
- return node;
16
- const out = {};
17
- for (const [key, value] of Object.entries(node)) {
18
- out[key] =
19
- key === "properties" && isObject(value) ? strictProperties(node, value) : strictify(value);
20
- }
21
- if (out.type === "object") {
22
- out.additionalProperties = false;
23
- out.required = Object.keys(isObject(out.properties) ? out.properties : {});
24
- }
25
- return out;
26
- };
27
- const strictProperties = (node, properties) => {
28
- const required = new Set(Array.isArray(node.required) ? node.required : []);
29
- return Object.fromEntries(Object.entries(properties).map(([key, value]) => [
30
- key,
31
- required.has(key) ? strictify(value) : { anyOf: [strictify(value), { type: "null" }] },
32
- ]));
33
- };
34
- /** Drops the `null`s strict mode forces onto optional keys, so the original schema decodes. */
35
- const relax = (node, value, resolve) => {
36
- const schema = resolve(node);
37
- if (Array.isArray(value)) {
38
- const items = schema.items;
39
- return isObject(items) ? value.map((item) => relax(items, item, resolve)) : value;
40
- }
41
- if (!isObject(value))
42
- return value;
43
- const variants = schema.anyOf ?? schema.oneOf;
44
- if (Array.isArray(variants)) {
45
- const objectVariant = variants
46
- .map(resolve)
47
- .find((v) => v.type === "object");
48
- return objectVariant === undefined ? value : relax(objectVariant, value, resolve);
49
- }
50
- const properties = isObject(schema.properties) ? schema.properties : {};
51
- const required = new Set(Array.isArray(schema.required) ? schema.required : []);
52
- const out = {};
53
- for (const [key, field] of Object.entries(value)) {
54
- if (field === null && !required.has(key))
55
- continue;
56
- const fieldSchema = properties[key];
57
- out[key] = isObject(fieldSchema) ? relax(fieldSchema, field, resolve) : field;
58
- }
59
- return out;
60
- };
61
- export const make = (schema) => {
62
- const document = Schema.toJsonSchemaDocument(schema);
63
- const root = document.schema;
64
- const definitions = (document.definitions ?? {});
65
- const wrapped = resolver(definitions)(root).type !== "object";
66
- const objectRoot = wrapped
67
- ? { type: "object", properties: { value: root }, required: ["value"] }
68
- : root;
69
- const jsonSchema = strictify(objectRoot);
70
- if (Object.keys(definitions).length > 0)
71
- jsonSchema.$defs = strictify(definitions);
72
- const decodeOriginal = Schema.decodeUnknownEffect(schema);
73
- const resolve = resolver(definitions);
74
- return {
75
- jsonSchema,
76
- decode: (raw) => {
77
- const relaxed = relax(objectRoot, raw, resolve);
78
- return decodeOriginal(wrapped && isObject(relaxed) ? relaxed.value : relaxed);
79
- },
80
- };
81
- };
package/dist/Task.d.ts DELETED
@@ -1,68 +0,0 @@
1
- import { Effect, Schema, type Duration } from "effect";
2
- import type { TaskClass } from "@chef.run/core";
3
- import type { StageValue } from "@chef.run/core/TaskPublish";
4
- import { type AnyArtifact, type FileArtifact, type JsonArtifact } from "@chef.run/core/model/Artifact";
5
- import type { Retry } from "@chef.run/core/model/Spec";
6
- import type { TaskRuntime } from "@chef.run/core/model/TaskModule";
7
- import { AgentFailed, AgentOutputInvalid, Usage, type Harness } from "./Harness.ts";
8
- export interface Prompt {
9
- readonly text: string;
10
- /** The agent's working directory, e.g. a checkout the prompt builder made. */
11
- readonly cwd?: string;
12
- /** Appended to the agent's own system prompt. */
13
- readonly instructions?: string;
14
- }
15
- type PromptResult<E> = string | Prompt | Effect.Effect<string | Prompt, E>;
16
- /** Turns task input into a prompt: a plain function, or an init Effect that returns one. */
17
- export type Build<I, E, IE> = ((input: I) => PromptResult<E>) | Effect.Effect<(input: I) => PromptResult<E>, IE, TaskRuntime>;
18
- export interface AgentTaskProps<I extends Schema.Top, O extends Schema.Top, X extends AnyArtifact, E extends Schema.Top> {
19
- /** `import.meta.url` of the module whose default export is this class. */
20
- readonly main: string;
21
- readonly input: I;
22
- /** The answer's schema. Omitted, the answer is the agent's final text. */
23
- readonly output?: O;
24
- /** An artifact to store each answer in; the write commits with the attempt. */
25
- readonly save?: X;
26
- readonly agent: Harness;
27
- /** Failures the prompt builder may raise, besides the agent's own. */
28
- readonly error?: E;
29
- /** Follow-up turns asking the agent to fix output that does not decode. @default 2 */
30
- readonly repairs?: number;
31
- readonly timeout?: StageValue<Duration.Input>;
32
- readonly retry?: StageValue<Retry>;
33
- }
34
- type KeyProp<I, KT> = [I] extends [KT] ? {
35
- readonly key?: (input: I) => KT;
36
- } : {
37
- readonly key: (input: I) => KT;
38
- };
39
- /** `save` must hold the answer, and `key` is required unless the input already is the artifact key. */
40
- export type SaveProps<I, OT, X> = [X] extends [never] ? {
41
- readonly key?: never;
42
- } : X extends JsonArtifact<any, string, infer K, infer V> ? [OT] extends [V["Type"]] ? KeyProp<I, K["Type"]> : {
43
- readonly save: "the artifact's schema must accept the task's output";
44
- } : X extends FileArtifact<any, string, infer K, infer A> ? [A["Type"]] extends [never] ? KeyProp<I, K["Type"]> : {
45
- readonly save: "file artifacts with attributes are not supported";
46
- } : never;
47
- export type AgentSuccess<O extends Schema.Top, X extends AnyArtifact> = Schema.Struct<{
48
- readonly output: O;
49
- readonly usage: typeof Usage;
50
- } & ([X] extends [never] ? {} : {
51
- readonly artifact: X["Ref"];
52
- })>;
53
- export type AgentError<E extends Schema.Top> = Schema.Union<readonly [typeof AgentFailed, typeof AgentOutputInvalid, E]>;
54
- export type AgentTaskClass<Self, N extends string, I extends Schema.Top, O extends Schema.Top, X extends AnyArtifact, E extends Schema.Top> = TaskClass<Self, N, I, AgentSuccess<O, X>, AgentError<E>>;
55
- /**
56
- * A Chef task whose work is one coding-agent conversation. It is an ordinary
57
- * `Chef.Task`: workflows call, retry and catch it like any other.
58
- *
59
- * ```ts
60
- * export default class ReviewPr extends Agent.Task<ReviewPr>()(
61
- * "review-pr",
62
- * { main: import.meta.url, input: PrKey, output: Review, save: PrReview, agent: Agent.claude({ model: "claude-opus-5-5" }) },
63
- * (pr) => `Review ${pr.repo}#${pr.number}.`,
64
- * ) {}
65
- * ```
66
- */
67
- export declare const Task: <Self>() => <const N extends string, I extends Schema.Top, O extends Schema.Top = typeof Schema.String, X extends AnyArtifact = never, E extends Schema.Top = typeof Schema.Never, IE = never>(name: N, props: AgentTaskProps<I, O, X, E> & SaveProps<I["Type"], O["Type"], X>, build: Build<I["Type"], E["Type"], IE>) => AgentTaskClass<Self, N, I, O, X, E>;
68
- export {};
package/dist/Task.js DELETED
@@ -1,86 +0,0 @@
1
- /* oxlint-disable typescript/no-unsafe-type-assertion -- Success and error schemas are assembled at runtime and typed through AgentTaskClass. */
2
- import { Effect, Result, Schema } from "effect";
3
- import * as Chef from "@chef.run/core";
4
- import { Put, } from "@chef.run/core/model/Artifact";
5
- import { AgentFailed, AgentOutputInvalid, Usage, addUsage, emptyUsage, } from "./Harness.js";
6
- import * as OutputSchema from "./OutputSchema.js";
7
- const normalize = (prompt) => typeof prompt === "string" ? { text: prompt } : prompt;
8
- const lift = (result) => Effect.isEffect(result) ? Effect.map(result, normalize) : Effect.succeed(normalize(result));
9
- const converse = (harness, prompt, output, repairs) => Effect.gen(function* () {
10
- let request = {
11
- prompt: prompt.text,
12
- cwd: prompt.cwd,
13
- instructions: prompt.instructions,
14
- outputSchema: output?.jsonSchema,
15
- };
16
- let usage = emptyUsage;
17
- for (let attempt = 0;; attempt++) {
18
- const turn = yield* harness.turn(request);
19
- usage = addUsage(usage, turn.usage);
20
- yield* Effect.logDebug("agent turn finished").pipe(Effect.annotateLogs({ harness: harness.name, model: harness.model, attempt }));
21
- if (output === undefined)
22
- return { value: turn.text, text: turn.text, usage };
23
- const decoded = yield* Effect.result(output.decode(turn.structured));
24
- if (Result.isSuccess(decoded))
25
- return { value: decoded.success, text: turn.text, usage };
26
- const issue = decoded.failure.message;
27
- if (attempt >= repairs)
28
- return yield* new AgentOutputInvalid({
29
- harness: harness.name,
30
- issue,
31
- raw: turn.structured === undefined ? turn.text : JSON.stringify(turn.structured),
32
- });
33
- request = {
34
- prompt: `Your answer did not match the required output schema:\n${issue}\nAnswer again with corrected output.`,
35
- cwd: prompt.cwd,
36
- outputSchema: output.jsonSchema,
37
- session: turn.session,
38
- };
39
- }
40
- });
41
- /**
42
- * A Chef task whose work is one coding-agent conversation. It is an ordinary
43
- * `Chef.Task`: workflows call, retry and catch it like any other.
44
- *
45
- * ```ts
46
- * export default class ReviewPr extends Agent.Task<ReviewPr>()(
47
- * "review-pr",
48
- * { main: import.meta.url, input: PrKey, output: Review, save: PrReview, agent: Agent.claude({ model: "claude-opus-5-5" }) },
49
- * (pr) => `Review ${pr.repo}#${pr.number}.`,
50
- * ) {}
51
- * ```
52
- */
53
- export const Task = () => (name, props, build) => {
54
- const output = props.output === undefined ? undefined : OutputSchema.make(props.output);
55
- const artifact = props.save;
56
- const keyOf = props.key ?? ((input) => input);
57
- const success = Schema.Struct({
58
- output: props.output ?? Schema.String,
59
- usage: Usage,
60
- ...(artifact === undefined ? {} : { artifact: artifact.Ref }),
61
- });
62
- const error = Schema.Union([AgentFailed, AgentOutputInvalid, props.error ?? Schema.Never]);
63
- const init = Effect.gen(function* () {
64
- const put = artifact === undefined ? undefined : yield* Put(artifact);
65
- const prompt = Effect.isEffect(build) ? yield* build : build;
66
- return (input) => Effect.gen(function* () {
67
- const answer = yield* converse(props.agent, yield* lift(prompt(input)), output, props.repairs ?? 2);
68
- if (put === undefined || artifact === undefined)
69
- return { output: answer.value, usage: answer.usage };
70
- const key = keyOf(input);
71
- const tags = { agent: props.agent.name, model: props.agent.model };
72
- const ref = artifact.kind === "json"
73
- ? yield* put(key, answer.value, { tags })
74
- : yield* put(key, new TextEncoder().encode(output === undefined ? answer.text : JSON.stringify(answer.value)), { tags });
75
- return { output: answer.value, usage: answer.usage, artifact: ref };
76
- });
77
- });
78
- return Chef.Task()(name, {
79
- main: props.main,
80
- input: props.input,
81
- success,
82
- error,
83
- ...(props.timeout === undefined ? {} : { timeout: props.timeout }),
84
- ...(props.retry === undefined ? {} : { retry: props.retry }),
85
- }, init);
86
- };
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export { Task } from "./Task.ts";
2
- export type { AgentError, AgentSuccess, AgentTaskClass, AgentTaskProps, Build, Prompt, SaveProps, } from "./Task.ts";
3
- export { claude } from "./Claude.ts";
4
- export type { ClaudeOptions } from "./Claude.ts";
5
- export { codex } from "./Codex.ts";
6
- export type { CodexOptions } from "./Codex.ts";
7
- export { AgentFailed, AgentOutputInvalid, Usage, make as harness } from "./Harness.ts";
8
- export type { Access, Harness, TurnRequest, TurnResult } from "./Harness.ts";
package/dist/index.js DELETED
@@ -1,4 +0,0 @@
1
- export { Task } from "./Task.js";
2
- export { claude } from "./Claude.js";
3
- export { codex } from "./Codex.js";
4
- export { AgentFailed, AgentOutputInvalid, Usage, make as harness } from "./Harness.js";