@lex-inc/thoughtful 0.0.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.
package/ENVIRONMENT.md ADDED
@@ -0,0 +1,83 @@
1
+ # Environment Configuration
2
+
3
+ The CLI now supports automatic environment detection and manual environment control via flags.
4
+
5
+ ## Automatic Environment Detection
6
+
7
+ The CLI automatically detects whether it's running in development or production:
8
+
9
+ ### Development Mode (uses `http://localhost:3000`)
10
+ - When running from source via `bun run dev`
11
+ - When `NODE_ENV=development` is set
12
+
13
+ ### Production Mode (uses `https://www.thoughtful.app`)
14
+ - When installed globally via `bun add -g @lex-inc/thoughtful`
15
+ - When running the built CLI from `dist/index.js`
16
+
17
+ ## Manual Environment Control
18
+
19
+ You can override the automatic detection with command-line flags:
20
+
21
+ ```bash
22
+ # Force development API (localhost:3000)
23
+ thoughtful pages list --dev
24
+
25
+ # Force production API (www.thoughtful.app)
26
+ bun run dev pages list --prod
27
+ ```
28
+
29
+ ## Configuration Precedence
30
+
31
+ API URL is determined in this order (highest to lowest priority):
32
+
33
+ 1. **CLI flags**: `--dev` or `--prod`
34
+ 2. **Environment variable**: `THOUGHTFUL_API_URL`
35
+ 3. **Config file**: `~/.config/thoughtful/config.json`
36
+ 4. **Smart default**:
37
+ - `http://localhost:3000` when running from source
38
+ - `https://www.thoughtful.app` when running built/installed CLI
39
+
40
+ ## Important Implementation Details
41
+
42
+ ### Config File Preservation
43
+
44
+ The CLI prevents environment/flag-based overrides from being persisted to the config file. This means:
45
+
46
+ - Using `--dev` or `--prod` flags won't change your config file
47
+ - Using `THOUGHTFUL_API_URL` won't change your config file
48
+ - Token refreshes preserve your config file's API URL
49
+
50
+ Only explicit user actions (like `thoughtful config set-url`) would change the stored API URL.
51
+
52
+ ### Examples
53
+
54
+ ```bash
55
+ # Development workflow
56
+ bun run dev pages list # Uses config file URL
57
+ bun run dev pages list --dev # Forces localhost
58
+ THOUGHTFUL_API_URL=http://localhost:3000 bun run dev pages list # Uses env var
59
+
60
+ # Production workflow
61
+ thoughtful pages list # Uses production
62
+ thoughtful pages list --dev # Forces localhost for testing
63
+
64
+ # Override examples
65
+ NODE_ENV=development thoughtful pages list # Uses localhost
66
+ THOUGHTFUL_API_URL=https://staging.example.com thoughtful pages list # Uses staging
67
+ ```
68
+
69
+ ## Testing
70
+
71
+ To verify the configuration is working:
72
+
73
+ ```bash
74
+ # Check current config
75
+ cat ~/.config/thoughtful/config.json | jq -r '.apiUrl'
76
+
77
+ # Test with different environments
78
+ bun run dev whoami --prod # Should connect to production
79
+ bun run dev whoami --dev # Should try localhost (will fail if server not running)
80
+
81
+ # Verify config file unchanged
82
+ cat ~/.config/thoughtful/config.json | jq -r '.apiUrl'
83
+ ```
package/README.md ADDED
@@ -0,0 +1,294 @@
1
+ # @lex-inc/thoughtful
2
+
3
+ Command-line interface for interacting with your Thoughtful workspace.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add -g @lex-inc/thoughtful
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Authentication
14
+
15
+ ```bash
16
+ # Log in to Thoughtful (interactive - will prompt for email and verification code)
17
+ thoughtful login
18
+
19
+ # Log in non-interactively with email and code
20
+ thoughtful login --email user@example.com --code 123456
21
+
22
+ # Log in in non-interactive mode (requires --email and --code flags)
23
+ thoughtful login --no-input --email user@example.com --code 123456
24
+
25
+ # Show current user, organization, and workspace
26
+ thoughtful whoami
27
+
28
+ # Log out
29
+ thoughtful logout
30
+ ```
31
+
32
+ ### Organizations
33
+
34
+ ```bash
35
+ # List organizations you belong to
36
+ thoughtful orgs list
37
+
38
+ # Switch to a different organization
39
+ thoughtful orgs switch <org-id>
40
+ ```
41
+
42
+ ### Workspaces
43
+
44
+ ```bash
45
+ # List workspaces in current organization
46
+ thoughtful workspaces list
47
+
48
+ # Switch to a different workspace
49
+ thoughtful workspaces switch <workspace-id>
50
+
51
+ # Create a new workspace
52
+ thoughtful workspaces create "My New Workspace"
53
+ ```
54
+
55
+ ### Pages
56
+
57
+ ```bash
58
+ # List all pages (tree view)
59
+ thoughtful pages list
60
+
61
+ # List all pages (flat)
62
+ thoughtful pages list --flat
63
+
64
+ # Get page details
65
+ thoughtful pages get <slug>
66
+
67
+ # Create a new page
68
+ thoughtful pages create "Page Title"
69
+ thoughtful pages create "Page Title" --parent parent-slug
70
+ thoughtful pages create "Page Title" --owner user@example.com
71
+ thoughtful pages create "Page Title" --status on_track
72
+
73
+ # Create a page with title from stdin
74
+ echo "Page Title" | thoughtful pages create -
75
+ thoughtful pages create - < title.txt
76
+
77
+ # Update a page
78
+ thoughtful pages update <slug> --title "New Title"
79
+ thoughtful pages update <slug> --status completed
80
+ thoughtful pages update <slug> --owner user@example.com
81
+
82
+ # Delete a page
83
+ thoughtful pages delete <slug>
84
+ thoughtful pages delete <slug> --yes # Skip confirmation
85
+
86
+ # Search pages
87
+ thoughtful pages search "query"
88
+ ```
89
+
90
+ ### Chat Threads
91
+
92
+ ```bash
93
+ # List recent chat threads
94
+ thoughtful threads list
95
+
96
+ # Start a new thread
97
+ thoughtful threads new
98
+ thoughtful threads new "Initial message"
99
+
100
+ # Show messages in a thread
101
+ thoughtful threads show <thread-id>
102
+
103
+ # Send a message to a thread
104
+ thoughtful threads send <thread-id> "Your message"
105
+
106
+ # Send a message without quotes (variadic args)
107
+ thoughtful threads send <thread-id> Your message here
108
+
109
+ # Send a message from stdin
110
+ echo "Your message" | thoughtful threads send <thread-id> -
111
+ thoughtful threads send <thread-id> - < message.txt
112
+ ```
113
+
114
+ ### Shell Completion
115
+
116
+ The CLI supports tab completion for bash, zsh, and fish shells:
117
+
118
+ #### Bash
119
+
120
+ Add to your `~/.bashrc`:
121
+
122
+ ```bash
123
+ eval "$(thoughtful completion bash)"
124
+ ```
125
+
126
+ #### Zsh
127
+
128
+ Add to your `~/.zshrc`:
129
+
130
+ ```bash
131
+ eval "$(thoughtful completion zsh)"
132
+ ```
133
+
134
+ #### Fish
135
+
136
+ Save the completion script to your Fish completions directory:
137
+
138
+ ```bash
139
+ thoughtful completion fish > ~/.config/fish/completions/thoughtful.fish
140
+ ```
141
+
142
+ After adding the completion script, restart your shell or source the config file:
143
+
144
+ ```bash
145
+ # Bash
146
+ source ~/.bashrc
147
+
148
+ # Zsh
149
+ source ~/.zshrc
150
+
151
+ # Fish - restart the shell or run
152
+ source ~/.config/fish/config.fish
153
+ ```
154
+
155
+ ### Global Flags
156
+
157
+ The following flags can be used with any command:
158
+
159
+ - **`--json`**: Output results in JSON format (machine-readable)
160
+ - **`--no-color`**: Disable colored output
161
+ - **`--no-input`**: Disable interactive prompts (requires all inputs via flags)
162
+ - **`-q, --quiet`**: Suppress non-essential output
163
+ - **`-v, --verbose`**: Show verbose output
164
+ - **`--dev`**: Use development API (http://localhost:3000)
165
+ - **`--prod`**: Use production API (https://www.thoughtful.app)
166
+
167
+ ```bash
168
+ # JSON output for machine-readable results
169
+ thoughtful whoami --json
170
+ thoughtful pages list --json
171
+
172
+ # Non-interactive mode (useful in scripts and CI/CD)
173
+ thoughtful login --no-input --email user@example.com --code 123456
174
+ thoughtful pages delete old-page --no-input --yes
175
+
176
+ # Force production API when running from source
177
+ bun run dev pages list --prod
178
+
179
+ # Use local development API
180
+ thoughtful pages list --dev
181
+
182
+ # Combine flags
183
+ thoughtful pages list --json --no-color | jq '.pages'
184
+ ```
185
+
186
+ ## Configuration
187
+
188
+ ### Config File Location
189
+
190
+ The CLI follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) for storing configuration:
191
+
192
+ - **XDG-compliant**: `$XDG_CONFIG_HOME/thoughtful/config.json` (if `XDG_CONFIG_HOME` is set)
193
+ - **Default**: `~/.config/thoughtful/config.json` (if `XDG_CONFIG_HOME` is not set)
194
+ - **Legacy**: `~/.thoughtful/config.json` (automatically migrated to XDG location on first run)
195
+
196
+ The config file stores authentication credentials and workspace preferences:
197
+
198
+ ```json
199
+ {
200
+ "apiUrl": "https://www.thoughtful.app",
201
+ "accessToken": "...",
202
+ "refreshToken": "...",
203
+ "tokenExpiresAt": "...",
204
+ "activeOrgId": "...",
205
+ "activeWorkspaceId": "...",
206
+ "user": {
207
+ "id": "...",
208
+ "email": "...",
209
+ "displayName": "..."
210
+ }
211
+ }
212
+ ```
213
+
214
+ Tokens are automatically refreshed before expiry.
215
+
216
+ ### Environment Variables
217
+
218
+ The CLI supports the following environment variables:
219
+
220
+ - **`THOUGHTFUL_API_URL`**: Override the API URL
221
+ ```bash
222
+ export THOUGHTFUL_API_URL=http://localhost:3000
223
+ thoughtful whoami
224
+ ```
225
+
226
+ - **`NODE_ENV`**: Set to `development` to automatically use localhost API
227
+ ```bash
228
+ NODE_ENV=development thoughtful pages list # Uses http://localhost:3000
229
+ ```
230
+
231
+ - **`THOUGHTFUL_NO_COLOR`**: Disable colored output (set to `1` or `true`)
232
+ ```bash
233
+ THOUGHTFUL_NO_COLOR=1 thoughtful pages list
234
+ ```
235
+
236
+ Also respects the standard `NO_COLOR` environment variable ([no-color.org](https://no-color.org/)).
237
+
238
+ - **`THOUGHTFUL_DEBUG`**: Enable debug logging (set to `1` or `true`)
239
+ ```bash
240
+ THOUGHTFUL_DEBUG=1 thoughtful login
241
+ ```
242
+
243
+ ### Environment Detection
244
+
245
+ The CLI automatically detects whether you're in development or production:
246
+
247
+ - **Development mode** (uses `http://localhost:3000`):
248
+ - When running from source: `bun run dev <command>`
249
+ - When `NODE_ENV=development` is set
250
+
251
+ - **Production mode** (uses `https://www.thoughtful.app`):
252
+ - When installed globally: `thoughtful <command>`
253
+ - When built and run from dist: `./dist/index.js <command>`
254
+
255
+ You can override the environment detection with CLI flags:
256
+
257
+ ```bash
258
+ # Force production API when running from source
259
+ bun run dev pages list --prod
260
+
261
+ # Force development API when using installed CLI
262
+ thoughtful pages list --dev
263
+ ```
264
+
265
+ ### Configuration Precedence
266
+
267
+ Settings are resolved in the following order (highest to lowest priority):
268
+
269
+ 1. Command-line flags (e.g., `--dev`, `--prod`, `--json`)
270
+ 2. Environment variables (e.g., `THOUGHTFUL_API_URL`, `NODE_ENV`)
271
+ 3. Config file (`~/.config/thoughtful/config.json`)
272
+ 4. Smart defaults based on environment:
273
+ - Development: `http://localhost:3000`
274
+ - Production: `https://www.thoughtful.app`
275
+
276
+ ## Development
277
+
278
+ ```bash
279
+ # Install dependencies
280
+ bun install
281
+
282
+ # Run in development mode
283
+ bun run dev <command>
284
+
285
+ # Build for production
286
+ bun run build
287
+
288
+ # Type check
289
+ bun run typecheck
290
+ ```
291
+
292
+ ## License
293
+
294
+ MIT