Skip to content

Commit f7ef52e

Browse files
committed
docs: document apply patch helpers
1 parent 479df18 commit f7ef52e

7 files changed

Lines changed: 37 additions & 5 deletions

src/agents/api-key-rotation.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Tests provider API-key rotation behavior.
3+
* Covers rate-limit key rotation, same-key transient retries, aborts, and
4+
* thrown-object preservation.
5+
*/
16
import { describe, expect, it, vi } from "vitest";
27
import type { TransientProviderRetryParams } from "../provider-runtime/operation-retry.js";
38
import { executeWithApiKeyRotation } from "./api-key-rotation.js";

src/agents/api-key-rotation.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Provider API-key rotation wrapper.
3+
* Runs provider calls across configured keys on rate-limit failures and keeps
4+
* same-key transient retries separate from key rotation.
5+
*/
16
import { normalizeUniqueStringEntries } from "@openclaw/normalization-core/string-normalization";
27
import { sleepWithAbort } from "../infra/backoff.js";
38
import { formatErrorMessage } from "../infra/errors.js";
@@ -10,8 +15,6 @@ import {
1015
} from "../provider-runtime/operation-retry.js";
1116
import { collectProviderApiKeys, isApiKeyRateLimitError } from "./live-auth-keys.js";
1217

13-
// API-key rotation wrapper for provider calls. It tries configured keys in order
14-
// on rate-limit-like failures and can also retry transient errors on the same key.
1518
type ApiKeyRetryParams = {
1619
apiKey: string;
1720
error: unknown;

src/agents/apply-patch-paths.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Tests apply_patch destination path extraction.
3+
* Ensures pre-execution policy checks see add/update/delete/move paths in
4+
* host and sandbox forms without requiring full parser success.
5+
*/
16
import os from "node:os";
27
import path from "node:path";
38
import { describe, expect, it } from "vitest";

src/agents/apply-patch-paths.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Path extraction for the apply_patch envelope grammar.
3+
* Used by pre-execution policy hooks that only need destination paths, not the
4+
* full strict patch parser.
5+
*/
16
import path from "node:path";
27
import { resolveSandboxInputPath } from "./sandbox-paths.js";
38
import type { SandboxFsBridge } from "./sandbox/fs-bridge.js";

src/agents/apply-patch-update.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
/**
2+
* Update-hunk application for the apply_patch parser.
3+
* Locates expected old lines with tolerant matching, applies chunks in order,
4+
* and returns normalized file contents with a trailing newline.
5+
*/
16
import fs from "node:fs/promises";
27
import { formatErrorMessage } from "../infra/errors.js";
38

4-
// Update-hunk application for the apply_patch parser. It locates expected old
5-
// lines with tolerant matching, applies chunks in order, and returns normalized
6-
// file contents with a trailing newline.
79
type UpdateFileChunk = {
810
changeContext?: string;
911
oldLines: string[];

src/agents/apply-patch.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Tests apply_patch execution and path safety.
3+
* Covers host/sandbox file operations, workspace guards, symlink races, and
4+
* update hunk behavior.
5+
*/
16
import fs from "node:fs/promises";
27
import os from "node:os";
38
import path from "node:path";

src/agents/apply-patch.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Runtime apply_patch tool and parser.
3+
* Parses OpenAI-style patch envelopes and applies add/update/delete/move hunks
4+
* through guarded host or sandbox filesystem operations.
5+
*/
16
import syncFs from "node:fs";
27
import fs from "node:fs/promises";
38
import path from "node:path";
@@ -82,6 +87,7 @@ const applyPatchSchema = Type.Object({
8287
}),
8388
});
8489

90+
/** Create the agent tool wrapper for applying patch-envelope input. */
8591
export function createApplyPatchTool(
8692
options: { cwd?: string; sandbox?: SandboxApplyPatchConfig; workspaceOnly?: boolean } = {},
8793
): AgentTool<typeof applyPatchSchema, ApplyPatchToolDetails> {
@@ -122,6 +128,7 @@ export function createApplyPatchTool(
122128
};
123129
}
124130

131+
/** Parse and apply a patch envelope to the configured filesystem target. */
125132
export async function applyPatch(
126133
input: string,
127134
options: ApplyPatchOptions,

0 commit comments

Comments
 (0)