Add link to cookbook (#2)
This commit is contained in:
committed by
GitHub
parent
ae7b518c53
commit
1c26c272c8
@@ -1,4 +1,5 @@
|
|||||||
/* eslint‑disable no-bitwise */
|
/* eslint‑disable no-bitwise */
|
||||||
|
|
||||||
export type Direction =
|
export type Direction =
|
||||||
| "left"
|
| "left"
|
||||||
| "right"
|
| "right"
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ type AgentLoopParams = {
|
|||||||
onItem: (item: ResponseItem) => void;
|
onItem: (item: ResponseItem) => void;
|
||||||
onLoading: (loading: boolean) => void;
|
onLoading: (loading: boolean) => void;
|
||||||
|
|
||||||
/**
|
/** Called when the command is not auto-approved to request explicit user review. */
|
||||||
* Used to reach out to the user only if the command is not auto-approved.
|
|
||||||
*/
|
|
||||||
getCommandConfirmation: (
|
getCommandConfirmation: (
|
||||||
command: Array<string>,
|
command: Array<string>,
|
||||||
applyPatch: ApplyPatchCommand | undefined,
|
applyPatch: ApplyPatchCommand | undefined,
|
||||||
@@ -53,12 +51,12 @@ export class AgentLoop {
|
|||||||
private instructions?: string;
|
private instructions?: string;
|
||||||
private approvalPolicy: ApprovalPolicy;
|
private approvalPolicy: ApprovalPolicy;
|
||||||
private config: AppConfig;
|
private config: AppConfig;
|
||||||
// Using `InstanceType<typeof OpenAI>` sidesteps typing issues with the
|
|
||||||
// OpenAI package under the TS 5+ `moduleResolution=bundler` setup.
|
// Using `InstanceType<typeof OpenAI>` sidesteps typing issues with the OpenAI package under
|
||||||
// OpenAI client instance. We keep the concrete type to avoid sprinkling
|
// the TS 5+ `moduleResolution=bundler` setup. OpenAI client instance. We keep the concrete
|
||||||
// `any` across the implementation while still allowing paths where the
|
// type to avoid sprinkling `any` across the implementation while still allowing paths where
|
||||||
// OpenAI SDK types may not perfectly match. The `typeof OpenAI` pattern
|
// the OpenAI SDK types may not perfectly match. The `typeof OpenAI` pattern captures the
|
||||||
// captures the instance shape without resorting to `any`.
|
// instance shape without resorting to `any`.
|
||||||
private oai: OpenAI;
|
private oai: OpenAI;
|
||||||
|
|
||||||
private onItem: (item: ResponseItem) => void;
|
private onItem: (item: ResponseItem) => void;
|
||||||
@@ -688,7 +686,7 @@ export class AgentLoop {
|
|||||||
// process and surface each item (no‑op until we can depend on streaming events)
|
// process and surface each item (no‑op until we can depend on streaming events)
|
||||||
if (event.type === "response.output_item.done") {
|
if (event.type === "response.output_item.done") {
|
||||||
const item = event.item;
|
const item = event.item;
|
||||||
// ① if it's a reasoning item, annotate it
|
// 1) if it's a reasoning item, annotate it
|
||||||
type ReasoningItem = { type?: string; duration_ms?: number };
|
type ReasoningItem = { type?: string; duration_ms?: number };
|
||||||
const maybeReasoning = item as ReasoningItem;
|
const maybeReasoning = item as ReasoningItem;
|
||||||
if (maybeReasoning.type === "reasoning") {
|
if (maybeReasoning.type === "reasoning") {
|
||||||
@@ -776,7 +774,7 @@ export class AgentLoop {
|
|||||||
// thinking times so UIs and tests can surface/verify them.
|
// thinking times so UIs and tests can surface/verify them.
|
||||||
// const thinkingEnd = Date.now();
|
// const thinkingEnd = Date.now();
|
||||||
|
|
||||||
// ① Per‑turn measurement – exact time spent between request and
|
// 1) Per‑turn measurement – exact time spent between request and
|
||||||
// response for *this* command.
|
// response for *this* command.
|
||||||
// this.onItem({
|
// this.onItem({
|
||||||
// id: `thinking-${thinkingEnd}`,
|
// id: `thinking-${thinkingEnd}`,
|
||||||
@@ -792,7 +790,7 @@ export class AgentLoop {
|
|||||||
// ],
|
// ],
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// ② Session‑wide cumulative counter so users can track overall wait
|
// 2) Session‑wide cumulative counter so users can track overall wait
|
||||||
// time across multiple turns.
|
// time across multiple turns.
|
||||||
// this.cumulativeThinkingMs += thinkingEnd - thinkingStart;
|
// this.cumulativeThinkingMs += thinkingEnd - thinkingStart;
|
||||||
// this.onItem({
|
// this.onItem({
|
||||||
@@ -975,6 +973,7 @@ export class AgentLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const prefix = `You are operating as and within the Codex CLI, a terminal-based agentic coding assistant built by OpenAI. It wraps OpenAI models to enable natural language interaction with a local codebase. You are expected to be precise, safe, and helpful.
|
const prefix = `You are operating as and within the Codex CLI, a terminal-based agentic coding assistant built by OpenAI. It wraps OpenAI models to enable natural language interaction with a local codebase. You are expected to be precise, safe, and helpful.
|
||||||
|
|
||||||
You can:
|
You can:
|
||||||
- Receive user prompts, project context, and files.
|
- Receive user prompts, project context, and files.
|
||||||
- Stream responses and emit function calls (e.g., shell commands, code edits).
|
- Stream responses and emit function calls (e.g., shell commands, code edits).
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Based on reference implementation from
|
||||||
|
// https://cookbook.openai.com/examples/gpt4-1_prompting_guide#reference-implementation-apply_patchpy
|
||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user