@papert-code/sdk-typescript 0.1.0

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,372 @@
1
+ # @papert-code/sdk-typescript
2
+
3
+ A minimum experimental TypeScript SDK for programmatic access to Papert Code.
4
+
5
+ Feel free to submit a feature request/issue/PR.
6
+
7
+ ## What’s inside
8
+
9
+ - Streaming `query` API (multi-turn, tool-aware) for embedding the agent.
10
+ - Programmatic CLI wrapper (`createPapertAgent`) to drive the full CLI/core end-to-end.
11
+ - Permission controls (plan/default/auto-edit/yolo), custom tool approvals, and MCP server support.
12
+ - Ready-made examples under `packages/sdk-typescript/examples` (TS + JS/ESM).
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @papert-code/sdk-typescript
18
+ ```
19
+
20
+ ## Requirements
21
+
22
+ - Node.js >= 18.0.0
23
+ - For most users, no separate CLI install is required because the SDK bundles the Papert Code CLI.
24
+
25
+ > **Note for nvm users**: If you use nvm to manage Node.js versions, the SDK may not be able to auto-detect the Papert Code executable. You should explicitly set the `pathToPapertExecutable` option to the full path of the `papert` binary.
26
+
27
+ ## Bundled CLI (how the SDK runs Papert)
28
+
29
+ The SDK ships with a bundled Papert Code CLI under `dist/cli/cli.js`. By default,
30
+ the SDK auto-detects and uses this bundled CLI. You can still override it with:
31
+
32
+ - `pathToPapertExecutable` in `query()`
33
+ - `cliBinaryPath` in `createPapertAgent()`
34
+ - or the `PAPERT_CODE_CLI_PATH` environment variable
35
+
36
+ ## Quick Start (streaming)
37
+
38
+ ```typescript
39
+ import { query } from '@papert-code/sdk-typescript';
40
+
41
+ // Single-turn query
42
+ const result = query({
43
+ prompt: 'What files are in the current directory?',
44
+ options: {
45
+ cwd: '/path/to/project',
46
+ },
47
+ });
48
+
49
+ // Iterate over messages
50
+ for await (const message of result) {
51
+ if (message.type === 'assistant') {
52
+ console.log('Assistant:', message.message.content);
53
+ } else if (message.type === 'result') {
54
+ console.log('Result:', message.result);
55
+ }
56
+ }
57
+ ```
58
+
59
+ ## Quick Start (reusable sessions)
60
+
61
+ ```typescript
62
+ import { createClient } from '@papert-code/sdk-typescript';
63
+
64
+ const client = createClient({
65
+ cwd: '/path/to/project',
66
+ permissionMode: 'auto-edit',
67
+ });
68
+
69
+ const session = client.createSession({ sessionId: 'demo-session' });
70
+ await session.send('Create TODO.md with 3 items');
71
+ await session.send('Now summarize TODO.md');
72
+ await client.close();
73
+ ```
74
+
75
+ ## Quick Start (full CLI agent)
76
+
77
+ Drive the CLI/core as a subprocess while setting model/base URL/API key programmatically.
78
+
79
+ ```typescript
80
+ import { createPapertAgent } from '@papert-code/sdk-typescript';
81
+
82
+ const agent = await createPapertAgent({
83
+ cliArgs: {
84
+ model: 'gpt-4o-mini', // or your provider model id
85
+ approvalMode: 'auto-edit', // plan | default | auto-edit | yolo
86
+ apiKey: process.env.OPENAI_API_KEY,
87
+ baseUrl: 'https://api.openai.com/v1', // optional for compatible APIs
88
+ // cliBinaryPath: '/abs/path/to/cli/dist/index.js', // optional override
89
+ },
90
+ });
91
+
92
+ const { stdout, stderr, exitCode } = await agent.runPrompt(
93
+ 'Summarize outstanding TODOs',
94
+ { extraArgs: ['--output-format', 'json'] }, // per-call flags
95
+ );
96
+ ```
97
+
98
+ ## High-level Client API
99
+
100
+ The SDK now includes a reusable session client:
101
+
102
+ - `createClient(options?)`
103
+ - `client.createSession({ sessionId?, options? })`
104
+ - `client.getSession(sessionId)`
105
+ - `client.close()`
106
+ - `session.stream(prompt, options?)`
107
+ - `session.send(prompt, options?)`
108
+ - `session.close()`
109
+ - `session.getSessionId()`
110
+
111
+ ### Run the baked examples (no ts-node needed)
112
+
113
+ ```bash
114
+ npm run build && npm run bundle:cli # ensure dist/cli is bundled into the SDK
115
+ export OPENAI_API_KEY="your_key"
116
+ node packages/sdk-typescript/examples/basic-run.mjs
117
+ node packages/sdk-typescript/examples/custom-endpoint.mjs
118
+ node packages/sdk-typescript/examples/abort-run.mjs
119
+ node packages/sdk-typescript/examples/bad-key.mjs
120
+ node packages/sdk-typescript/examples/client-session.mjs
121
+ node packages/sdk-typescript/examples/runtime-subagents.mjs
122
+ ```
123
+
124
+ ## API Reference
125
+
126
+ ### `query(config)`
127
+
128
+ Creates a new query session with the Papert Code.
129
+
130
+ #### Parameters
131
+
132
+ - `prompt`: `string | AsyncIterable<SDKUserMessage>` - The prompt to send. Use a string for single-turn queries or an async iterable for multi-turn conversations.
133
+ - `options`: `QueryOptions` - Configuration options for the query session.
134
+
135
+ #### QueryOptions
136
+
137
+ | Option | Type | Default | Description |
138
+ | ------------------------ | ---------------------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
139
+ | `cwd` | `string` | `process.cwd()` | The working directory for the query session. Determines the context in which file operations and commands are executed. |
140
+ | `model` | `string` | - | The AI model to use (e.g., `'papert-max'`, `'papert-plus'`, `'papert-turbo'`). Takes precedence over `OPENAI_MODEL` and `PAPERT_MODEL` environment variables. |
141
+ | `pathToPapertExecutable` | `string` | Auto-detected | Path to the Papert Code executable. Supports multiple formats: `'papert'` (native binary from PATH), `'/path/to/papert'` (explicit path), `'/path/to/cli.js'` (Node.js bundle), `'node:/path/to/cli.js'` (force Node.js runtime), `'bun:/path/to/cli.js'` (force Bun runtime). If not provided, auto-detects from: bundled CLI inside the SDK, `PAPERT_CODE_CLI_PATH` env var, `~/.volta/bin/papert`, `~/.npm-global/bin/papert`, `/usr/local/bin/papert`, `~/.local/bin/papert`, `~/node_modules/.bin/papert`, `~/.yarn/bin/papert`. |
142
+ | `permissionMode` | `'default' \| 'plan' \| 'auto-edit' \| 'yolo'` | `'default'` | Permission mode controlling tool execution approval. See [Permission Modes](#permission-modes) for details. |
143
+ | `canUseTool` | `CanUseTool` | - | Custom permission handler for tool execution approval. Invoked when a tool requires confirmation. Must respond within 30 seconds or the request will be auto-denied. See [Custom Permission Handler](#custom-permission-handler). |
144
+ | `env` | `Record<string, string>` | - | Environment variables to pass to the Papert Code process. Merged with the current process environment. |
145
+ | `skillsPath` | `string \| string[]` | - | Additional skills directories to load. The CLI scans these paths for skills in addition to the default user and workspace skill locations. |
146
+ | `mcpServers` | `Record<string, ExternalMcpServerConfig>` | - | External MCP (Model Context Protocol) servers to connect. Each server is identified by a unique name and configured with `command`, `args`, and `env`. |
147
+ | `abortController` | `AbortController` | - | Controller to cancel the query session. Call `abortController.abort()` to terminate the session and cleanup resources. |
148
+ | `debug` | `boolean` | `false` | Enable debug mode for verbose logging from the CLI process. |
149
+ | `maxSessionTurns` | `number` | `-1` (unlimited) | Maximum number of conversation turns before the session automatically terminates. A turn consists of a user message and an assistant response. |
150
+ | `coreTools` | `string[]` | - | Equivalent to `tool.core` in settings.json. If specified, only these tools will be available to the AI. Example: `['read_file', 'write_file', 'run_terminal_cmd']`. |
151
+ | `excludeTools` | `string[]` | - | Equivalent to `tool.exclude` in settings.json. Excluded tools return a permission error immediately. Takes highest priority over all other permission settings. Supports pattern matching: tool name (`'write_file'`), tool class (`'ShellTool'`), or shell command prefix (`'ShellTool(rm )'`). |
152
+ | `allowedTools` | `string[]` | - | Equivalent to `tool.allowed` in settings.json. Matching tools bypass `canUseTool` callback and execute automatically. Only applies when tool requires confirmation. Supports same pattern matching as `excludeTools`. |
153
+ | `authType` | `'openai' \| 'papert-oauth'` | `'openai'` | Authentication type for the AI service. Using `'papert-oauth'` in SDK is not recommended as credentials are stored in `~/.papert` and may need periodic refresh. |
154
+ | `agents` | `SubagentConfig[]` | - | Configuration for subagents that can be invoked during the session. Subagents are specialized AI agents for specific tasks or domains. |
155
+ | `includePartialMessages` | `boolean` | `false` | When `true`, the SDK emits incomplete messages as they are being generated, allowing real-time streaming of the AI's response. |
156
+
157
+ ### Timeouts
158
+
159
+ The SDK enforces the following timeouts:
160
+
161
+ | Timeout | Duration | Description |
162
+ | ------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
163
+ | Permission Callback | 30 seconds | Maximum time for `canUseTool` callback to respond. If exceeded, the tool request is auto-denied. |
164
+ | Control Request | 30 seconds | Maximum time for control operations like `initialize()`, `setModel()`, `setPermissionMode()`, and `interrupt()` to complete. |
165
+
166
+ ### Message Types
167
+
168
+ The SDK provides type guards to identify different message types:
169
+
170
+ ```typescript
171
+ import {
172
+ isSDKUserMessage,
173
+ isSDKAssistantMessage,
174
+ isSDKSystemMessage,
175
+ isSDKResultMessage,
176
+ isSDKPartialAssistantMessage,
177
+ } from '@papert-code/sdk-typescript';
178
+
179
+ for await (const message of result) {
180
+ if (isSDKAssistantMessage(message)) {
181
+ // Handle assistant message
182
+ } else if (isSDKResultMessage(message)) {
183
+ // Handle result message
184
+ }
185
+ }
186
+ ```
187
+
188
+ ### Query Instance Methods
189
+
190
+ The `Query` instance returned by `query()` provides several methods:
191
+
192
+ ```typescript
193
+ const q = query({ prompt: 'Hello', options: {} });
194
+
195
+ // Get session ID
196
+ const sessionId = q.getSessionId();
197
+
198
+ // Check if closed
199
+ const closed = q.isClosed();
200
+
201
+ // Interrupt the current operation
202
+ await q.interrupt();
203
+
204
+ // Change permission mode mid-session
205
+ await q.setPermissionMode('yolo');
206
+
207
+ // Change model mid-session
208
+ await q.setModel('papert-max');
209
+
210
+ // Close the session
211
+ await q.close();
212
+ ```
213
+
214
+ ## Permission Modes
215
+
216
+ The SDK supports different permission modes for controlling tool execution:
217
+
218
+ - **`default`**: Write tools are denied unless approved via `canUseTool` callback or in `allowedTools`. Read-only tools execute without confirmation.
219
+ - **`plan`**: Blocks all write tools, instructing AI to present a plan first.
220
+ - **`auto-edit`**: Auto-approve edit tools (edit, write_file) while other tools require confirmation.
221
+ - **`yolo`**: All tools execute automatically without confirmation.
222
+
223
+ ### Permission Priority Chain
224
+
225
+ 1. `excludeTools` - Blocks tools completely
226
+ 2. `permissionMode: 'plan'` - Blocks non-read-only tools
227
+ 3. `permissionMode: 'yolo'` - Auto-approves all tools
228
+ 4. `allowedTools` - Auto-approves matching tools
229
+ 5. `canUseTool` callback - Custom approval logic
230
+ 6. Default behavior - Auto-deny in SDK mode
231
+
232
+ ## Examples
233
+
234
+ ### Multi-turn Conversation
235
+
236
+ ```typescript
237
+ import { query, type SDKUserMessage } from '@papert-code/sdk-typescript';
238
+
239
+ async function* generateMessages(): AsyncIterable<SDKUserMessage> {
240
+ yield {
241
+ type: 'user',
242
+ session_id: 'my-session',
243
+ message: { role: 'user', content: 'Create a hello.txt file' },
244
+ parent_tool_use_id: null,
245
+ };
246
+
247
+ // Wait for some condition or user input
248
+ yield {
249
+ type: 'user',
250
+ session_id: 'my-session',
251
+ message: { role: 'user', content: 'Now read the file back' },
252
+ parent_tool_use_id: null,
253
+ };
254
+ }
255
+
256
+ const result = query({
257
+ prompt: generateMessages(),
258
+ options: {
259
+ permissionMode: 'auto-edit',
260
+ },
261
+ });
262
+
263
+ for await (const message of result) {
264
+ console.log(message);
265
+ }
266
+ ```
267
+
268
+ ### Custom Permission Handler
269
+
270
+ ```typescript
271
+ import { query, type CanUseTool } from '@papert-code/sdk-typescript';
272
+
273
+ const canUseTool: CanUseTool = async (toolName, input, { signal }) => {
274
+ // Allow all read operations
275
+ if (toolName.startsWith('read_')) {
276
+ return { behavior: 'allow', updatedInput: input };
277
+ }
278
+
279
+ // Prompt user for write operations (in a real app)
280
+ const userApproved = await promptUser(`Allow ${toolName}?`);
281
+
282
+ if (userApproved) {
283
+ return { behavior: 'allow', updatedInput: input };
284
+ }
285
+
286
+ return { behavior: 'deny', message: 'User denied the operation' };
287
+ };
288
+
289
+ const result = query({
290
+ prompt: 'Create a new file',
291
+ options: {
292
+ canUseTool,
293
+ },
294
+ });
295
+ ```
296
+
297
+ ### With MCP Servers
298
+
299
+ ```typescript
300
+ import { query } from '@papert-code/sdk-typescript';
301
+
302
+ const result = query({
303
+ prompt: 'Use the custom tool from my MCP server',
304
+ options: {
305
+ mcpServers: {
306
+ 'my-server': {
307
+ command: 'node',
308
+ args: ['path/to/mcp-server.js'],
309
+ env: { PORT: '3000' },
310
+ },
311
+ },
312
+ },
313
+ });
314
+ ```
315
+
316
+ ### Abort a Query
317
+
318
+ ```typescript
319
+ import { query, isAbortError } from '@papert-code/sdk-typescript';
320
+
321
+ const abortController = new AbortController();
322
+
323
+ const result = query({
324
+ prompt: 'Long running task...',
325
+ options: {
326
+ abortController,
327
+ },
328
+ });
329
+
330
+ // Abort after 5 seconds
331
+ setTimeout(() => abortController.abort(), 5000);
332
+
333
+ try {
334
+ for await (const message of result) {
335
+ console.log(message);
336
+ }
337
+ } catch (error) {
338
+ if (isAbortError(error)) {
339
+ console.log('Query was aborted');
340
+ } else {
341
+ throw error;
342
+ }
343
+ }
344
+ ```
345
+
346
+ ## Error Handling
347
+
348
+ The SDK provides an `AbortError` class for handling aborted queries:
349
+
350
+ ```typescript
351
+ import { AbortError, isAbortError } from '@papert-code/sdk-typescript';
352
+
353
+ try {
354
+ // ... query operations
355
+ } catch (error) {
356
+ if (isAbortError(error)) {
357
+ // Handle abort
358
+ } else {
359
+ // Handle other errors
360
+ }
361
+ }
362
+ ```
363
+
364
+ ## License
365
+
366
+ Apache-2.0 - see [LICENSE](./LICENSE) for details.
367
+
368
+ ## Multi-agent and Skills Guide
369
+
370
+ For complete `.papert` setup with subagents and skills:
371
+
372
+ - `docs/cli/sdk-typescript-multi-agent-skills.md`
package/dist/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ * Copyright 2026 Papert-code
191
+ Copyright 2025 Papert
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
@@ -0,0 +1,47 @@
1
+ type ApprovalMode = 'default' | 'yolo' | 'auto-edit';
2
+ export interface PapertAgentOptions {
3
+ /**
4
+ * Path to the papert-code CLI entrypoint. Defaults to the package entry
5
+ * resolved from Node (equivalent to `require.resolve('@papert-code/papert-code')`).
6
+ */
7
+ cliBinaryPath?: string;
8
+ /**
9
+ * CLI arguments to seed the agent with (mirrors CLI flags).
10
+ */
11
+ cliArgs?: {
12
+ model?: string;
13
+ approvalMode?: ApprovalMode;
14
+ baseUrl?: string;
15
+ apiKey?: string;
16
+ cwd?: string;
17
+ extraArgs?: string[];
18
+ };
19
+ }
20
+ export interface RunPromptOptions {
21
+ /**
22
+ * Additional CLI flags to append just for this prompt.
23
+ */
24
+ extraArgs?: string[];
25
+ /**
26
+ * AbortSignal to terminate the underlying process.
27
+ */
28
+ signal?: AbortSignal;
29
+ }
30
+ export interface PapertAgent {
31
+ runPrompt: (prompt: string, options?: RunPromptOptions) => Promise<{
32
+ stdout: string;
33
+ stderr: string;
34
+ exitCode: number | null;
35
+ }>;
36
+ }
37
+ /**
38
+ * Lightweight programmatic wrapper around the papert-code CLI.
39
+ *
40
+ * Example:
41
+ * const agent = await createPapertAgent({
42
+ * cliArgs: { model: 'gemini-3-pro', approvalMode: 'auto_edit' },
43
+ * });
44
+ * const result = await agent.runPrompt('Summarize outstanding TODOs');
45
+ */
46
+ export declare function createPapertAgent(options?: PapertAgentOptions): Promise<PapertAgent>;
47
+ export {};