@papert-code/papert-code 0.2.5 → 0.3.1

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.
Files changed (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +122 -227
  3. package/dist/cli.js +332863 -325652
  4. package/package.json +7 -7
package/LICENSE CHANGED
@@ -188,7 +188,7 @@
188
188
  identification within third-party archives.
189
189
 
190
190
  Copyright 2025 Google LLC
191
- Copyright 2025 Papert
191
+ Copyright 2025 Qwen
192
192
 
193
193
  Licensed under the Apache License, Version 2.0 (the "License");
194
194
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -1,302 +1,197 @@
1
1
  # Papert Code
2
2
 
3
- Papert Code is a powerful command-line AI workflow tool adapted from [**Gemini CLI**](https://github.com/google-gemini/gemini-cli) ([details](./README.gemini.md)), It enhances your development workflow with advanced code understanding, automated tasks, and intelligent assistance.
3
+ Papert Code is a terminal-native AI coding companion that automates everyday developer workflows. It reads, edits, and generates code across large repositories, automates shell tasks with safety rails, and exposes the same capabilities through a TypeScript SDK and a VS Code companion extension.
4
4
 
5
- ## Key Features
5
+ - Terminal-first agent with `papert`, built for high-signal, multi-turn coding sessions.
6
+ - Codebase-aware tools: reads and edits files, runs ripgrep queries, executes shell commands, and respects `.gitignore` + `.papertignore`.
7
+ - Safety and control: structured plans, explicit approval modes (`plan`, `default`, `auto-edit`, `yolo`), and sandbox support (Seatbelt/macOS, Docker, Podman).
8
+ - Extensible platform: user commands, subagents, Model Context Protocol (MCP) servers, and a TypeScript SDK for embedding Papert Code into your own apps.
9
+ - Works with any OpenAI-compatible API; pick your own model, base URL, and keys.
6
10
 
7
- - **Code Understanding & Editing** - Query and edit large codebases beyond traditional context window limits
8
- - **Workflow Automation** - Automate operational tasks like handling pull requests and complex rebases
9
- - **Enhanced Parser** - Adapted parser specifically optimized for Papert-Coder models
10
- - **Vision Model Support** - Automatically detect images in your input and seamlessly switch to vision-capable models for multimodal analysis
11
+ ## Repository layout
11
12
 
12
- ## Programmatic API (Alpha)
13
-
14
- Embed the full Papert Code CLI toolchain directly inside another Node.js or
15
- TypeScript processno subprocess management required. Install the CLI as a
16
- dependency and import the new API entry point:
17
-
18
- ```bash
19
- npm install
20
- ```
21
-
22
- ```ts
23
- import { createPapertAgent } from '@papert-code/papert-code/api';
24
-
25
- const agent = await createPapertAgent({
26
- cliArgs: {
27
- model: 'gemini-3-pro',
28
- approvalMode: 'auto_edit',
29
- },
30
- });
31
-
32
- await agent.runPrompt('Summarize outstanding TODOs');
33
- ```
34
-
35
- The agent shares settings, MCP configuration, and auth flows with the CLI (for
36
- example `~/.papert/settings.json`, `OPENAI_API_KEY`, or Papert OAuth tokens). Use
37
- `createProgrammaticCliArgs` to mimic CLI flags in code, and see
38
- [`docs/cli/programmatic-agent.md`](./docs/cli/programmatic-agent.md) plus the
39
- [`examples/programmatic-agent`](./examples/programmatic-agent) sample for a
40
- complete walkthrough.
41
-
42
- ## Release (npm)
43
-
44
- - Bump versions across workspace (root, core, cli, vscode companion as needed) to the target (e.g. 0.2.5).
45
- - Install deps and run checks: `pnpm install && pnpm lint && pnpm test --filter core && pnpm build`.
46
- - Publish core and CLI from repo root: `pnpm publish --filter @papert-code/papert-code-core --access public` then `pnpm publish --filter @papert-code/papert-code --access public`.
47
- - Verify: `npm view @papert-code/papert-code version` (and core) shows the new version; optionally smoke-test `pnpm dlx @papert-code/papert-code@<version> --help`.
13
+ - `packages/cli` the Papert Code CLI (interactive TUI, tools, settings, sandbox integration).
14
+ - `packages/core` — core tool implementations, MCP plumbing, and shared services.
15
+ - `packages/sdk-typescript` programmatic access to Papert Code (streaming queries + full CLI runner).
16
+ - `packages/test-utils` helpers for integration/terminal tests.
17
+ - `packages/vscode-ide-companion` VS Code extension that mirrors the CLI features inside the editor.
18
+ - `docs/` — user and contributor documentation.
48
19
 
49
20
  ## Installation
50
21
 
51
22
  ### Prerequisites
52
23
 
53
- Ensure you have [Node.js version 20](https://nodejs.org/en/download) or higher installed.
24
+ - Node.js **>= 20**
25
+
26
+ ### Install from npm
54
27
 
55
28
  ```bash
56
- curl -qL https://www.npmjs.com/install.sh | sh
29
+ npm install -g @papert-code/papert-code
30
+ papert --version
57
31
  ```
58
32
 
59
33
  ### Install from source
60
34
 
61
35
  ```bash
62
- git clone https://github.com/PapertLM/papert-code.git
36
+ git clone https://github.com/azharlabs/papert-code.git
63
37
  cd papert-code
64
38
  npm install
65
39
  npm install -g .
66
40
  ```
67
41
 
68
- ## Quick Start
42
+ ## Configure a model provider
69
43
 
70
- ```bash
71
- # Start Papert Code
72
- papert
44
+ Papert Code speaks the OpenAI-compatible API. Set your provider values via environment variables or `.env`/`.papert/.env` files:
73
45
 
74
- # Example commands
75
- > Explain this codebase structure
76
- > Help me refactor this function
77
- > Generate unit tests for this module
46
+ ```bash
47
+ export OPENAI_API_KEY="your_api_key"
48
+ export OPENAI_BASE_URL="https://api.your-provider.com/v1" # optional if using api.openai.com
49
+ export OPENAI_MODEL="your-model-id" # e.g. gpt-4o-mini
78
50
  ```
79
51
 
80
- ### Session Management
52
+ You can also pass flags per session:
81
53
 
82
- Control your token usage with configurable session limits to optimize costs and performance.
54
+ ```bash
55
+ papert --model gpt-4o-mini --base-url https://api.openai.com/v1
56
+ ```
83
57
 
84
- #### Configure Session Token Limit
58
+ ## Quick start
85
59
 
86
- Create or edit `.papert/settings.json` in your home directory:
60
+ ```bash
61
+ papert
87
62
 
88
- ```json
89
- {
90
- "sessionTokenLimit": 32000
91
- }
63
+ # Example prompts
64
+ > Give me a map of the main services in this repo.
65
+ > Refactor the auth middleware for clearer error handling.
66
+ > Generate integration tests for the payment flow.
92
67
  ```
93
68
 
94
- #### Session Commands
69
+ ### Everyday commands
95
70
 
96
- - **`/compress`** - Compress conversation history to continue within token limits
97
- - **`/clear`** - Clear all conversation history and start fresh
98
- - **`/stats`** - Check current token usage and limits
71
+ - `/help` list commands
72
+ - `/clear` wipe the conversation
73
+ - `/compress` shrink history to stay within context limits
74
+ - `/stats` — show token and tool usage
75
+ - `/exit` — quit the session
99
76
 
100
- > 📝 **Note**: Session token limit applies to a single conversation, not cumulative API calls.
77
+ Keyboard shortcuts: `Ctrl+C` cancels the current turn, `Ctrl+D` exits on an empty line, arrow keys navigate history.
101
78
 
102
- ### Vision Model Configuration
79
+ ## Core capabilities
103
80
 
104
- Papert Code includes intelligent vision model auto-switching that detects images in your input and can automatically switch to vision-capable models for multimodal analysis. **This feature is enabled by default** - when you include images in your queries, you'll see a dialog asking how you'd like to handle the vision model switch.
81
+ - **Repository awareness**: traverses large codebases, respects `.gitignore` and `.papertignore`, and uses ripgrep for fast search.
82
+ - **Structured editing**: reads and writes files with minimal diffs; keeps edits scoped and reversible.
83
+ - **Shell automation**: runs commands with approval; supports long-running tasks and streaming output.
84
+ - **Planning and approvals**: choose how cautious the agent should be:
85
+ - `plan`: always propose a plan before acting
86
+ - `default`: ask for confirmation on impactful operations
87
+ - `auto-edit`: auto-approve safe edits, prompt for risky ones
88
+ - `yolo`: auto-approve everything (use sparingly)
89
+ - **Sandboxing**: optional seatbelt (macOS) or container sandboxes (Docker/Podman) to isolate filesystem and network access.
90
+ - **Extensibility**:
91
+ - `.papert/commands/` for custom slash-commands
92
+ - `.papert/agents/` for specialized subagents
93
+ - MCP servers for external toolchains and data sources
105
94
 
106
- #### Skip the Switch Dialog (Optional)
95
+ ## Project settings and ignore files
107
96
 
108
- If you don't want to see the interactive dialog each time, configure the default behavior in your `.papert/settings.json`:
97
+ Papert Code looks for `.papert/settings.json` in your project or `~/.papert/settings.json` for user defaults. Example:
109
98
 
110
99
  ```json
111
100
  {
112
- "experimental": {
113
- "vlmSwitchMode": "once"
101
+ "model": "gpt-4o-mini",
102
+ "approvalMode": "default",
103
+ "tool": {
104
+ "core": ["read_file", "write_file", "run_terminal_cmd"],
105
+ "exclude": ["ShellTool(rm )"]
106
+ },
107
+ "sandbox": {
108
+ "enabled": false
114
109
  }
115
110
  }
116
111
  ```
117
112
 
118
- **Available modes:**
119
-
120
- - **`"once"`** - Switch to vision model for this query only, then revert
121
- - **`"session"`** - Switch to vision model for the entire session
122
- - **`"persist"`** - Continue with current model (no switching)
123
- - **Not set** - Show interactive dialog each time (default)
113
+ Use `.papertignore` to exclude directories or files from context collection (same semantics as `.gitignore`). Environment variables can live in `.papert/.env` (project-scoped) or `~/.papert/.env` (user-scoped).
124
114
 
125
- #### Command Line Override
115
+ ## TypeScript SDK
126
116
 
127
- You can also set the behavior via command line:
117
+ Install the SDK:
128
118
 
129
119
  ```bash
130
- # Switch once per query
131
- papert --vlm-switch-mode once
132
-
133
- # Switch for entire session
134
- papert --vlm-switch-mode session
135
-
136
- # Never switch automatically
137
- papert --vlm-switch-mode persist
120
+ npm install @papert-code/sdk-typescript
138
121
  ```
139
122
 
140
- #### Disable Vision Models (Optional)
123
+ ### Streaming queries
141
124
 
142
- To completely disable vision model support, add to your `.papert/settings.json`:
125
+ ```typescript
126
+ import { query } from '@papert-code/sdk-typescript';
143
127
 
144
- ```json
145
- {
146
- "experimental": {
147
- "visionModelPreview": false
128
+ for await (const message of query({
129
+ prompt: 'List the services in this repo and summarize their responsibilities.',
130
+ options: { cwd: '/path/to/project', model: 'gpt-4o-mini' },
131
+ })) {
132
+ if (message.type === 'assistant') {
133
+ console.log(message.message.content);
134
+ }
135
+ if (message.type === 'result') {
136
+ console.log('Finished');
148
137
  }
149
138
  }
150
139
  ```
151
140
 
152
- > 💡 **Tip**: In YOLO mode (`--yolo`), vision switching happens automatically without prompts when images are detected.
153
-
154
- ```bash
155
- # Just run this command and follow the browser authentication
156
- papert
157
- ```
158
-
159
- **What happens:**
160
-
161
- 1. **Instant Setup**: CLI opens your browser automatically
162
- 2. **One-Click Login**: Authenticate with your papert.ai account
163
- 3. **Automatic Management**: Credentials cached locally for future use
164
- 4. **No Configuration**: Zero setup required - just start coding!
165
-
166
- #### OpenAI-Compatible API
167
-
168
- Use API keys for OpenAI or other compatible providers:
169
-
170
- **Configuration Methods:**
171
-
172
- 1. **Environment Variables**
173
-
174
- ```bash
175
- export OPENAI_API_KEY="your_api_key_here"
176
- export OPENAI_BASE_URL="your_api_endpoint"
177
- export OPENAI_MODEL="your_model_choice"
178
- ```
179
-
180
- 2. **Project `.env` File**
181
- Create a `.env` file in your project root:
182
- ```env
183
- OPENAI_API_KEY=your_api_key_here
184
- OPENAI_BASE_URL=your_api_endpoint
185
- OPENAI_MODEL=your_model_choice
186
- ```
187
-
188
- ## Usage Examples
189
-
190
- ### 🔍 Explore Codebases
191
-
192
- ```bash
193
- cd your-project/
194
- papert
195
-
196
- # Architecture analysis
197
- > Describe the main pieces of this system's architecture
198
- > What are the key dependencies and how do they interact?
199
- > Find all API endpoints and their authentication methods
200
- ```
201
-
202
- ### 💻 Code Development
141
+ ### Drive the full CLI
203
142
 
204
- ```bash
205
- # Refactoring
206
- > Refactor this function to improve readability and performance
207
- > Convert this class to use dependency injection
208
- > Split this large module into smaller, focused components
209
-
210
- # Code generation
211
- > Create a REST API endpoint for user management
212
- > Generate unit tests for the authentication module
213
- > Add error handling to all database operations
214
- ```
215
-
216
- ### 🔄 Automate Workflows
217
-
218
- ```bash
219
- # Git automation
220
- > Analyze git commits from the last 7 days, grouped by feature
221
- > Create a changelog from recent commits
222
- > Find all TODO comments and create GitHub issues
223
-
224
- # File operations
225
- > Convert all images in this directory to PNG format
226
- > Rename all test files to follow the *.test.ts pattern
227
- > Find and remove all console.log statements
228
- ```
229
-
230
- ### 🐛 Debugging & Analysis
231
-
232
- ```bash
233
- # Performance analysis
234
- > Identify performance bottlenecks in this React component
235
- > Find all N+1 query problems in the codebase
143
+ ```typescript
144
+ import { createPapertAgent } from '@papert-code/sdk-typescript';
236
145
 
237
- # Security audit
238
- > Check for potential SQL injection vulnerabilities
239
- > Find all hardcoded credentials or API keys
240
- ```
241
-
242
- ## Popular Tasks
146
+ const agent = await createPapertAgent({
147
+ cliArgs: {
148
+ model: 'gpt-4o-mini',
149
+ approvalMode: 'auto-edit', // plan | default | auto-edit | yolo
150
+ apiKey: process.env.OPENAI_API_KEY,
151
+ baseUrl: 'https://api.openai.com/v1'
152
+ },
153
+ });
243
154
 
244
- ### 📚 Understand New Codebases
155
+ const { stdout, exitCode } = await agent.runPrompt(
156
+ 'Summarize outstanding TODOs by directory',
157
+ { extraArgs: ['--output-format', 'json'] },
158
+ );
245
159
 
246
- ```text
247
- > What are the core business logic components?
248
- > What security mechanisms are in place?
249
- > How does the data flow through the system?
250
- > What are the main design patterns used?
251
- > Generate a dependency graph for this module
160
+ console.log(stdout, exitCode);
252
161
  ```
253
162
 
254
- ### 🔨 Code Refactoring & Optimization
163
+ SDK features:
255
164
 
256
- ```text
257
- > What parts of this module can be optimized?
258
- > Help me refactor this class to follow SOLID principles
259
- > Add proper error handling and logging
260
- > Convert callbacks to async/await pattern
261
- > Implement caching for expensive operations
262
- ```
165
+ - Multi-turn streaming API with tool awareness.
166
+ - Permission hooks (`canUseTool`), custom tool allow/deny lists, and MCP server wiring.
167
+ - Abort support via `AbortController`, per-call environment overrides, and subagent configuration.
168
+ - Works with the installed `papert` binary or a specified CLI path.
263
169
 
264
- ### 📝 Documentation & Testing
170
+ Examples live under `packages/sdk-typescript/examples` (ESM, no ts-node required).
265
171
 
266
- ```text
267
- > Generate comprehensive JSDoc comments for all public APIs
268
- > Write unit tests with edge cases for this component
269
- > Create API documentation in OpenAPI format
270
- > Add inline comments explaining complex algorithms
271
- > Generate a README for this module
272
- ```
172
+ ## VS Code companion
273
173
 
274
- ### 🚀 Development Acceleration
174
+ `packages/vscode-ide-companion` mirrors the CLI experience inside VS Code: native diffing, context awareness, and the same approval modes. Build it with `npm run build:vscode` or install from the marketplace once published.
275
175
 
276
- ```text
277
- > Set up a new Express server with authentication
278
- > Create a React component with TypeScript and tests
279
- > Implement a rate limiter middleware
280
- > Add database migrations for new schema
281
- > Configure CI/CD pipeline for this project
282
- ```
176
+ ## Development
283
177
 
284
- ## Commands & Shortcuts
178
+ Common scripts:
285
179
 
286
- ### Session Commands
180
+ - `npm run build` — build the CLI bundle
181
+ - `npm test` — run workspace tests in parallel
182
+ - `npm run lint` / `npm run lint:ci` — lint source and tests
183
+ - `npm run typecheck` — TypeScript checks
184
+ - `npm run build:all` — CLI + sandbox + VS Code companion
185
+ - `npm run clean` — remove build artifacts and generated files
287
186
 
288
- - `/help` - Display available commands
289
- - `/clear` - Clear conversation history
290
- - `/compress` - Compress history to save tokens
291
- - `/stats` - Show current session information
292
- - `/exit` or `/quit` - Exit Papert Code
187
+ See `CONTRIBUTING.md` for full contributor guidance and sandbox notes.
293
188
 
294
- ### Keyboard Shortcuts
189
+ ## Troubleshooting
295
190
 
296
- - `Ctrl+C` - Cancel current operation
297
- - `Ctrl+D` - Exit (on empty line)
298
- - `Up/Down` - Navigate command history
191
+ - Check `docs/support/troubleshooting.md` for common fixes.
192
+ - Verify your provider configuration (`OPENAI_API_KEY`, `OPENAI_BASE_URL`, `OPENAI_MODEL`).
193
+ - Use `/stats` to see context usage and `/compress` to shrink history if you hit limits.
299
194
 
300
- ## Acknowledgments
195
+ ## License
301
196
 
302
- This project is based on [Google Gemini CLI](https://github.com/google-gemini/gemini-cli). We acknowledge and appreciate the excellent work of the Gemini CLI team.
197
+ Apache 2.0, see `LICENSE`.