@hasna/codewith-sdk 0.1.26

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 OpenAI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,17 @@
1
+ # Modifications
2
+
3
+ Codewith is a modified derivative of OpenAI Codex.
4
+
5
+ Original work: OpenAI Codex, copyright 2025 OpenAI, licensed under the Apache
6
+ License, Version 2.0.
7
+
8
+ Derivative work: Codewith, copyright 2026 Hasna.
9
+
10
+ Unless a file or directory is explicitly documented as copied verbatim from an
11
+ upstream or third-party source, files in this distribution may include Hasna
12
+ modifications from the OpenAI Codex codebase. Prominent categories of
13
+ modification include Codewith product branding, package names and release
14
+ metadata, distribution packaging, local state paths, authentication profiles,
15
+ provider configuration, and Codewith-specific documentation.
16
+
17
+ Detailed source changes are tracked in this repository's git history.
package/NOTICE ADDED
@@ -0,0 +1,12 @@
1
+ Codewith
2
+ Copyright 2026 Hasna
3
+
4
+ Codewith is a modified derivative of OpenAI Codex.
5
+ Portions copyright 2025 OpenAI.
6
+ See MODIFICATIONS.md for a summary of Codewith modifications.
7
+
8
+ Codewith is not affiliated with, sponsored by, or endorsed by OpenAI.
9
+
10
+ This project includes code derived from [Ratatui](https://github.com/ratatui/ratatui), licensed under the MIT license.
11
+ Copyright (c) 2016-2022 Florian Dehau
12
+ Copyright (c) 2023-2025 The Ratatui Developers
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # Codewith SDK
2
+
3
+ Embed the Codewith agent in your workflows and apps.
4
+
5
+ The TypeScript SDK wraps the `codewith` CLI from `@hasna/codewith`. It spawns the CLI and exchanges JSONL events over stdin/stdout.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @hasna/codewith-sdk
11
+ ```
12
+
13
+ Requires Node.js 18+.
14
+
15
+ ## Quickstart
16
+
17
+ ```typescript
18
+ import { Codewith } from "@hasna/codewith-sdk";
19
+
20
+ const codewith = new Codewith();
21
+ const thread = codewith.startThread();
22
+ const turn = await thread.run("Diagnose the test failure and propose a fix");
23
+
24
+ console.log(turn.finalResponse);
25
+ console.log(turn.items);
26
+ ```
27
+
28
+ Call `run()` repeatedly on the same `Thread` instance to continue that conversation.
29
+
30
+ ```typescript
31
+ const nextTurn = await thread.run("Implement the fix");
32
+ ```
33
+
34
+ ### Streaming responses
35
+
36
+ `run()` buffers events until the turn finishes. To react to intermediate progress—tool calls, streaming responses, and file change notifications—use `runStreamed()` instead, which returns an async generator of structured events.
37
+
38
+ ```typescript
39
+ const { events } = await thread.runStreamed("Diagnose the test failure and propose a fix");
40
+
41
+ for await (const event of events) {
42
+ switch (event.type) {
43
+ case "item.completed":
44
+ console.log("item", event.item);
45
+ break;
46
+ case "turn.completed":
47
+ console.log("usage", event.usage);
48
+ break;
49
+ }
50
+ }
51
+ ```
52
+
53
+ ### Structured output
54
+
55
+ The Codewith agent can produce a JSON response that conforms to a specified schema. The schema can be provided for each turn as a plain JSON object.
56
+
57
+ ```typescript
58
+ const schema = {
59
+ type: "object",
60
+ properties: {
61
+ summary: { type: "string" },
62
+ status: { type: "string", enum: ["ok", "action_required"] },
63
+ },
64
+ required: ["summary", "status"],
65
+ additionalProperties: false,
66
+ } as const;
67
+
68
+ const turn = await thread.run("Summarize repository status", { outputSchema: schema });
69
+ console.log(turn.finalResponse);
70
+ ```
71
+
72
+ You can also create a JSON schema from a [Zod schema](https://github.com/colinhacks/zod) using the [`zod-to-json-schema`](https://www.npmjs.com/package/zod-to-json-schema) package and setting the `target` to `"openAi"`.
73
+
74
+ ```typescript
75
+ const schema = z.object({
76
+ summary: z.string(),
77
+ status: z.enum(["ok", "action_required"]),
78
+ });
79
+
80
+ const turn = await thread.run("Summarize repository status", {
81
+ outputSchema: zodToJsonSchema(schema, { target: "openAi" }),
82
+ });
83
+ console.log(turn.finalResponse);
84
+ ```
85
+
86
+ ### Attaching images
87
+
88
+ Provide structured input entries when you need to include images alongside text. Text entries are concatenated into the final prompt while image entries are passed to the Codewith CLI via `--image`.
89
+
90
+ ```typescript
91
+ const turn = await thread.run([
92
+ { type: "text", text: "Describe these screenshots" },
93
+ { type: "local_image", path: "./ui.png" },
94
+ { type: "local_image", path: "./diagram.jpg" },
95
+ ]);
96
+ ```
97
+
98
+ ### Resuming an existing thread
99
+
100
+ Threads are persisted in `~/.codewith/sessions`. If you lose the in-memory `Thread` object, reconstruct it with `resumeThread()` and keep going.
101
+
102
+ ```typescript
103
+ const savedThreadId = process.env.CODEX_THREAD_ID!;
104
+ const thread = codewith.resumeThread(savedThreadId);
105
+ await thread.run("Implement the fix");
106
+ ```
107
+
108
+ ### Working directory controls
109
+
110
+ Codewith runs in the current working directory by default. To avoid unrecoverable errors, Codewith requires the working directory to be a Git repository. You can skip the Git repository check by passing the `skipGitRepoCheck` option when creating a thread.
111
+
112
+ ```typescript
113
+ const thread = codewith.startThread({
114
+ workingDirectory: "/path/to/project",
115
+ skipGitRepoCheck: true,
116
+ });
117
+ ```
118
+
119
+ ### Controlling the Codewith CLI environment
120
+
121
+ By default, the Codewith CLI inherits the Node.js process environment. Provide the optional `env` parameter when instantiating the
122
+ `Codewith` client to fully control which variables the Codewith CLI receives—useful for sandboxed hosts like Electron apps.
123
+
124
+ ```typescript
125
+ const codewith = new Codewith({
126
+ env: {
127
+ PATH: "/usr/local/bin",
128
+ },
129
+ });
130
+ ```
131
+
132
+ The SDK still injects its required variables (such as `CODEX_API_KEY`) on top of the environment you provide. If you set
133
+ `baseUrl`, the SDK passes it as a `--config openai_base_url=...` override.
134
+
135
+ ### Passing `--config` overrides
136
+
137
+ Use the `config` option to provide additional Codewith CLI configuration overrides. The SDK accepts a JSON object, flattens it
138
+ into dotted paths, and serializes values as TOML literals before passing them as repeated `--config key=value` flags.
139
+
140
+ ```typescript
141
+ const codewith = new Codewith({
142
+ config: {
143
+ show_raw_agent_reasoning: true,
144
+ sandbox_workspace_write: { network_access: true },
145
+ },
146
+ });
147
+ ```
148
+
149
+ Thread options still take precedence for overlapping settings because they are emitted after these global overrides.
@@ -0,0 +1,18 @@
1
+ # Third-Party Notices
2
+
3
+ Codewith release artifacts may include third-party runtime tools. Their license
4
+ texts are distributed in the `licenses/` directory of packaged artifacts.
5
+
6
+ ## Bundled Runtime Tools
7
+
8
+ - `ripgrep` / `rg`: copyright 2015 Andrew Gallant and contributors. Licensed
9
+ under either the MIT License or the Unlicense.
10
+ - `zsh`: copyright 1992-2017 Paul Falstad, Richard Coleman, Zoltan Hidvegi,
11
+ Andrew Main, Peter Stephenson, Sven Wischnowsky, and others. Licensed under
12
+ the zsh license, with file-specific terms taking precedence in upstream zsh
13
+ distributions.
14
+ - `bubblewrap` / `bwrap`: distributed under the GNU Library General Public
15
+ License, version 2, as included in `licenses/bubblewrap-LGPL-2.0.txt`.
16
+
17
+ This notice file is informational and does not replace the license texts
18
+ distributed with the package.
@@ -0,0 +1,276 @@
1
+ import { ContentBlock } from '@modelcontextprotocol/sdk/types.js';
2
+
3
+ /** The status of a command execution. */
4
+ type CommandExecutionStatus = "in_progress" | "completed" | "failed";
5
+ /** A command executed by the agent. */
6
+ type CommandExecutionItem = {
7
+ id: string;
8
+ type: "command_execution";
9
+ /** The command line executed by the agent. */
10
+ command: string;
11
+ /** Aggregated stdout and stderr captured while the command was running. */
12
+ aggregated_output: string;
13
+ /** Set when the command exits; omitted while still running. */
14
+ exit_code?: number;
15
+ /** Current status of the command execution. */
16
+ status: CommandExecutionStatus;
17
+ };
18
+ /** Indicates the type of the file change. */
19
+ type PatchChangeKind = "add" | "delete" | "update";
20
+ /** A set of file changes by the agent. */
21
+ type FileUpdateChange = {
22
+ path: string;
23
+ kind: PatchChangeKind;
24
+ };
25
+ /** The status of a file change. */
26
+ type PatchApplyStatus = "completed" | "failed";
27
+ /** A set of file changes by the agent. Emitted once the patch succeeds or fails. */
28
+ type FileChangeItem = {
29
+ id: string;
30
+ type: "file_change";
31
+ /** Individual file changes that comprise the patch. */
32
+ changes: FileUpdateChange[];
33
+ /** Whether the patch ultimately succeeded or failed. */
34
+ status: PatchApplyStatus;
35
+ };
36
+ /** The status of an MCP tool call. */
37
+ type McpToolCallStatus = "in_progress" | "completed" | "failed";
38
+ /**
39
+ * Represents a call to an MCP tool. The item starts when the invocation is dispatched
40
+ * and completes when the MCP server reports success or failure.
41
+ */
42
+ type McpToolCallItem = {
43
+ id: string;
44
+ type: "mcp_tool_call";
45
+ /** Name of the MCP server handling the request. */
46
+ server: string;
47
+ /** The tool invoked on the MCP server. */
48
+ tool: string;
49
+ /** Arguments forwarded to the tool invocation. */
50
+ arguments: unknown;
51
+ /** Result payload returned by the MCP server for successful calls. */
52
+ result?: {
53
+ content: ContentBlock[];
54
+ _meta?: unknown;
55
+ structured_content: unknown;
56
+ };
57
+ /** Error message reported for failed calls. */
58
+ error?: {
59
+ message: string;
60
+ };
61
+ /** Current status of the tool invocation. */
62
+ status: McpToolCallStatus;
63
+ };
64
+ /** Response from the agent. Either natural-language text or JSON when structured output is requested. */
65
+ type AgentMessageItem = {
66
+ id: string;
67
+ type: "agent_message";
68
+ /** Either natural-language text or JSON when structured output is requested. */
69
+ text: string;
70
+ };
71
+ /** Agent's reasoning summary. */
72
+ type ReasoningItem = {
73
+ id: string;
74
+ type: "reasoning";
75
+ text: string;
76
+ };
77
+ /** Captures a web search request. Completes when results are returned to the agent. */
78
+ type WebSearchItem = {
79
+ id: string;
80
+ type: "web_search";
81
+ query: string;
82
+ };
83
+ /** Describes a non-fatal error surfaced as an item. */
84
+ type ErrorItem = {
85
+ id: string;
86
+ type: "error";
87
+ message: string;
88
+ };
89
+ /** An item in the agent's to-do list. */
90
+ type TodoItem = {
91
+ text: string;
92
+ completed: boolean;
93
+ };
94
+ /**
95
+ * Tracks the agent's running to-do list. Starts when the plan is issued, updates as steps change,
96
+ * and completes when the turn ends.
97
+ */
98
+ type TodoListItem = {
99
+ id: string;
100
+ type: "todo_list";
101
+ items: TodoItem[];
102
+ };
103
+ /** Canonical union of thread items and their type-specific payloads. */
104
+ type ThreadItem = AgentMessageItem | ReasoningItem | CommandExecutionItem | FileChangeItem | McpToolCallItem | WebSearchItem | TodoListItem | ErrorItem;
105
+
106
+ /** Emitted when a new thread is started as the first event. */
107
+ type ThreadStartedEvent = {
108
+ type: "thread.started";
109
+ /** The identifier of the new thread. Can be used to resume the thread later. */
110
+ thread_id: string;
111
+ };
112
+ /**
113
+ * Emitted when a turn is started by sending a new prompt to the model.
114
+ * A turn encompasses all events that happen while the agent is processing the prompt.
115
+ */
116
+ type TurnStartedEvent = {
117
+ type: "turn.started";
118
+ };
119
+ /** Describes the usage of tokens during a turn. */
120
+ type Usage = {
121
+ /** The number of input tokens used during the turn. */
122
+ input_tokens: number;
123
+ /** The number of cached input tokens used during the turn. */
124
+ cached_input_tokens: number;
125
+ /** The number of output tokens used during the turn. */
126
+ output_tokens: number;
127
+ /** The number of reasoning output tokens used during the turn. */
128
+ reasoning_output_tokens: number;
129
+ };
130
+ /** Emitted when a turn is completed. Typically right after the assistant's response. */
131
+ type TurnCompletedEvent = {
132
+ type: "turn.completed";
133
+ usage: Usage;
134
+ };
135
+ /** Indicates that a turn failed with an error. */
136
+ type TurnFailedEvent = {
137
+ type: "turn.failed";
138
+ error: ThreadError;
139
+ };
140
+ /** Emitted when a new item is added to the thread. Typically the item is initially "in progress". */
141
+ type ItemStartedEvent = {
142
+ type: "item.started";
143
+ item: ThreadItem;
144
+ };
145
+ /** Emitted when an item is updated. */
146
+ type ItemUpdatedEvent = {
147
+ type: "item.updated";
148
+ item: ThreadItem;
149
+ };
150
+ /** Signals that an item has reached a terminal state—either success or failure. */
151
+ type ItemCompletedEvent = {
152
+ type: "item.completed";
153
+ item: ThreadItem;
154
+ };
155
+ /** Fatal error emitted by the stream. */
156
+ type ThreadError = {
157
+ message: string;
158
+ };
159
+ /** Represents an unrecoverable error emitted directly by the event stream. */
160
+ type ThreadErrorEvent = {
161
+ type: "error";
162
+ message: string;
163
+ };
164
+ /** Top-level JSONL events emitted by codex exec. */
165
+ type ThreadEvent = ThreadStartedEvent | TurnStartedEvent | TurnCompletedEvent | TurnFailedEvent | ItemStartedEvent | ItemUpdatedEvent | ItemCompletedEvent | ThreadErrorEvent;
166
+
167
+ type TurnOptions = {
168
+ /** JSON schema describing the expected agent output. */
169
+ outputSchema?: unknown;
170
+ /** AbortSignal to cancel the turn. */
171
+ signal?: AbortSignal;
172
+ };
173
+
174
+ /** Completed turn. */
175
+ type Turn = {
176
+ items: ThreadItem[];
177
+ finalResponse: string;
178
+ usage: Usage | null;
179
+ };
180
+ /** Alias for `Turn` to describe the result of `run()`. */
181
+ type RunResult = Turn;
182
+ /** The result of the `runStreamed` method. */
183
+ type StreamedTurn = {
184
+ events: AsyncGenerator<ThreadEvent>;
185
+ };
186
+ /** Alias for `StreamedTurn` to describe the result of `runStreamed()`. */
187
+ type RunStreamedResult = StreamedTurn;
188
+ /** An input to send to the agent. */
189
+ type UserInput = {
190
+ type: "text";
191
+ text: string;
192
+ } | {
193
+ type: "local_image";
194
+ path: string;
195
+ };
196
+ type Input = string | UserInput[];
197
+ /** Represent a thread of conversation with the agent. One thread can have multiple consecutive turns. */
198
+ declare class Thread {
199
+ private _exec;
200
+ private _options;
201
+ private _id;
202
+ private _threadOptions;
203
+ /** Returns the ID of the thread. Populated after the first turn starts. */
204
+ get id(): string | null;
205
+ /** Provides the input to the agent and streams events as they are produced during the turn. */
206
+ runStreamed(input: Input, turnOptions?: TurnOptions): Promise<StreamedTurn>;
207
+ private runStreamedInternal;
208
+ /** Provides the input to the agent and returns the completed turn. */
209
+ run(input: Input, turnOptions?: TurnOptions): Promise<Turn>;
210
+ }
211
+
212
+ type CodexConfigValue = string | number | boolean | CodexConfigValue[] | CodexConfigObject;
213
+ type CodexConfigObject = {
214
+ [key: string]: CodexConfigValue;
215
+ };
216
+ type CodexOptions = {
217
+ codexPathOverride?: string;
218
+ baseUrl?: string;
219
+ apiKey?: string;
220
+ /**
221
+ * Additional `--config key=value` overrides to pass to the Codewith CLI.
222
+ *
223
+ * Provide a JSON object and the SDK will flatten it into dotted paths and
224
+ * serialize values as TOML literals so they are compatible with the CLI's
225
+ * `--config` parsing.
226
+ */
227
+ config?: CodexConfigObject;
228
+ /**
229
+ * Environment variables passed to the Codewith CLI process. When provided, the SDK
230
+ * will not inherit variables from `process.env`.
231
+ */
232
+ env?: Record<string, string>;
233
+ };
234
+
235
+ type ApprovalMode = "never" | "on-request" | "on-failure" | "untrusted";
236
+ type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
237
+ type ModelReasoningEffort = "minimal" | "low" | "medium" | "high" | "xhigh";
238
+ type WebSearchMode = "disabled" | "cached" | "live";
239
+ type ThreadOptions = {
240
+ model?: string;
241
+ sandboxMode?: SandboxMode;
242
+ workingDirectory?: string;
243
+ skipGitRepoCheck?: boolean;
244
+ modelReasoningEffort?: ModelReasoningEffort;
245
+ networkAccessEnabled?: boolean;
246
+ webSearchMode?: WebSearchMode;
247
+ webSearchEnabled?: boolean;
248
+ approvalPolicy?: ApprovalMode;
249
+ additionalDirectories?: string[];
250
+ };
251
+
252
+ /**
253
+ * Codewith is the main class for interacting with the Codewith agent.
254
+ *
255
+ * Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.
256
+ */
257
+ declare class Codewith {
258
+ private exec;
259
+ private options;
260
+ constructor(options?: CodexOptions);
261
+ /**
262
+ * Starts a new conversation with an agent.
263
+ * @returns A new thread instance.
264
+ */
265
+ startThread(options?: ThreadOptions): Thread;
266
+ /**
267
+ * Resumes a conversation with an agent based on the thread id.
268
+ * Threads are persisted in ~/.codewith/sessions by default.
269
+ *
270
+ * @param id The id of the thread to resume.
271
+ * @returns A new thread instance.
272
+ */
273
+ resumeThread(id: string, options?: ThreadOptions): Thread;
274
+ }
275
+
276
+ export { type AgentMessageItem, type ApprovalMode, Codewith, type CodexOptions, type CommandExecutionItem, type ErrorItem, type FileChangeItem, type Input, type ItemCompletedEvent, type ItemStartedEvent, type ItemUpdatedEvent, type McpToolCallItem, type ModelReasoningEffort, type ReasoningItem, type RunResult, type RunStreamedResult, type SandboxMode, Thread, type ThreadError, type ThreadErrorEvent, type ThreadEvent, type ThreadItem, type ThreadOptions, type ThreadStartedEvent, type TodoListItem, type TurnCompletedEvent, type TurnFailedEvent, type TurnOptions, type TurnStartedEvent, type Usage, type UserInput, type WebSearchItem, type WebSearchMode };