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