@alint-js/agent-codex-cli 0.0.22

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 ADDED
@@ -0,0 +1,40 @@
1
+ # `@alint-js/agent-codex-cli`
2
+
3
+ > [!IMPORTANT]
4
+ > This package is a WIP. APIs may be subject to major changes.
5
+
6
+ A Codex CLI-backed `AgentAdapter` for alint. It delegates execution to the official
7
+ `@openai/codex-sdk`, which wraps the local `codex` CLI and owns the JSONL event
8
+ protocol.
9
+
10
+ ## What it does
11
+
12
+ `createCodexCliAdapter()` returns an `AgentAdapter` that starts a Codex thread,
13
+ sends the rule prompt, and maps the SDK run result back to alint's `{ answer,
14
+ usage }` shape. Codex uses its own local configuration, AGENTS instructions,
15
+ sandboxing, MCP servers, and tool runtime.
16
+
17
+ ## How to use
18
+
19
+ ```ts
20
+ import { createCodexCliAdapter } from '@alint-js/agent-codex-cli'
21
+
22
+ const adapter = createCodexCliAdapter({
23
+ sandbox: 'read-only',
24
+ })
25
+ ```
26
+
27
+ Pass `{ useRequestModel: true }` only when alint's resolved model should override
28
+ the local Codex model configuration.
29
+
30
+ ## When to use
31
+
32
+ - You want alint rules to delegate a check to the local Codex CLI environment.
33
+ - You want Codex to decide which of its own tools to use.
34
+
35
+ ## When not to use
36
+
37
+ - Your rule needs alint `AgentTool` callbacks. This adapter rejects them because
38
+ Codex CLI does not execute in-process JavaScript tool callbacks.
39
+ - You need direct OpenAI-compatible chat completion calls. Use a structured-output
40
+ rule or another agent adapter instead.
@@ -0,0 +1,27 @@
1
+ import { CodexOptions, RunResult, SandboxMode, ThreadOptions, TurnOptions } from "@openai/codex-sdk";
2
+ import { AgentAdapter, AgentRequest } from "@alint-js/core/agent";
3
+
4
+ //#region src/index.d.ts
5
+ interface CodexCliAdapterOptions {
6
+ additionalDirectories: string[];
7
+ approvalPolicy: ThreadOptions['approvalPolicy'];
8
+ codexPath: string;
9
+ config: NonNullable<CodexOptions['config']>;
10
+ cwd: string;
11
+ env: Record<string, string>;
12
+ outputSchema: NonNullable<TurnOptions['outputSchema']>;
13
+ run: (request: CodexCliRunRequest) => Promise<RunResult>;
14
+ sandbox: SandboxMode;
15
+ skipGitRepoCheck: boolean;
16
+ useRequestModel: boolean;
17
+ }
18
+ interface CodexCliRunRequest {
19
+ codexOptions: CodexOptions;
20
+ input: string;
21
+ threadOptions: ThreadOptions;
22
+ turnOptions: TurnOptions;
23
+ }
24
+ declare function createCodexCliAdapter(options?: Partial<CodexCliAdapterOptions>): AgentAdapter;
25
+ declare function createRunRequest(request: AgentRequest, options: Partial<CodexCliAdapterOptions>): CodexCliRunRequest;
26
+ //#endregion
27
+ export { CodexCliAdapterOptions, CodexCliRunRequest, createCodexCliAdapter, createRunRequest };
package/dist/index.mjs ADDED
@@ -0,0 +1,53 @@
1
+ import process from "node:process";
2
+ import { Codex } from "@openai/codex-sdk";
3
+ //#region src/index.ts
4
+ function createCodexCliAdapter(options = {}) {
5
+ const run = options.run ?? runCodexSdk;
6
+ return async (request) => {
7
+ if (request.tools.length > 0) throw new TypeError("Codex CLI adapter does not support alint AgentTool callbacks. Codex uses its own local tool runtime.");
8
+ const result = await run(createRunRequest(request, options));
9
+ return {
10
+ answer: result.finalResponse,
11
+ usage: mapUsage(result.usage)
12
+ };
13
+ };
14
+ }
15
+ function createRunRequest(request, options) {
16
+ const cwd = options.cwd ?? process.cwd();
17
+ return {
18
+ codexOptions: {
19
+ ...options.codexPath ? { codexPathOverride: options.codexPath } : {},
20
+ ...options.config ? { config: options.config } : {},
21
+ ...options.env ? { env: options.env } : {}
22
+ },
23
+ input: formatPrompt(request),
24
+ threadOptions: {
25
+ ...options.additionalDirectories ? { additionalDirectories: options.additionalDirectories } : {},
26
+ ...options.approvalPolicy ? { approvalPolicy: options.approvalPolicy } : {},
27
+ ...options.sandbox ? { sandboxMode: options.sandbox } : {},
28
+ ...options.skipGitRepoCheck !== void 0 ? { skipGitRepoCheck: options.skipGitRepoCheck } : {},
29
+ ...options.useRequestModel ? { model: request.model.id } : {},
30
+ workingDirectory: cwd
31
+ },
32
+ turnOptions: {
33
+ ...options.outputSchema ? { outputSchema: options.outputSchema } : {},
34
+ ...request.signal ? { signal: request.signal } : {}
35
+ }
36
+ };
37
+ }
38
+ function formatPrompt(request) {
39
+ return [request.instructions, request.prompt].filter(Boolean).join("\n\n");
40
+ }
41
+ function mapUsage(usage) {
42
+ if (!usage) return;
43
+ return {
44
+ inputTokens: usage.input_tokens,
45
+ outputTokens: usage.output_tokens,
46
+ totalTokens: usage.input_tokens + usage.output_tokens
47
+ };
48
+ }
49
+ async function runCodexSdk(request) {
50
+ return await new Codex(request.codexOptions).startThread(request.threadOptions).run(request.input, request.turnOptions);
51
+ }
52
+ //#endregion
53
+ export { createCodexCliAdapter, createRunRequest };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@alint-js/agent-codex-cli",
3
+ "type": "module",
4
+ "version": "0.0.22",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.mts",
8
+ "default": "./dist/index.mjs"
9
+ },
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "peerDependencies": {
16
+ "@alint-js/core": "0.0.22"
17
+ },
18
+ "dependencies": {
19
+ "@openai/codex-sdk": "^0.144.3"
20
+ },
21
+ "devDependencies": {
22
+ "@alint-js/core": "0.0.22"
23
+ },
24
+ "scripts": {
25
+ "build": "tsdown",
26
+ "typecheck": "tsc -p tsconfig.json --noEmit",
27
+ "test": "vitest run --config vitest.config.ts"
28
+ }
29
+ }