@hmawla/co-assistant 1.0.0 → 1.0.2

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 CHANGED
@@ -6,9 +6,9 @@ Chat with state-of-the-art AI models (GPT-5, Claude Sonnet 4, o3, and more) dire
6
6
 
7
7
  ---
8
8
 
9
- ## Setup
9
+ ## Quick Start
10
10
 
11
- ### Prerequisites
11
+ ### 1. Prerequisites
12
12
 
13
13
  | Requirement | How to get it |
14
14
  |------------|---------------|
@@ -17,70 +17,139 @@ Chat with state-of-the-art AI models (GPT-5, Claude Sonnet 4, o3, and more) dire
17
17
  | **Telegram User ID** | Message [@userinfobot](https://t.me/userinfobot) → copy the numeric ID |
18
18
  | **GitHub Token** | [github.com/settings/tokens](https://github.com/settings/tokens) — create a token with Copilot access |
19
19
 
20
- ### Install & Configure
20
+ ### 2. Install
21
+
22
+ Install globally from npm:
21
23
 
22
24
  ```bash
23
- git clone https://github.com/your-username/co-assistant.git
24
- cd co-assistant
25
- npm install
25
+ npm install -g @hmawla/co-assistant
26
+ ```
27
+
28
+ ### 3. Create a project directory
29
+
30
+ Co-Assistant needs a working directory to store your configuration, plugins, and data:
31
+
32
+ ```bash
33
+ mkdir my-assistant && cd my-assistant
26
34
  ```
27
35
 
36
+ ### 4. Set up
37
+
28
38
  Run the interactive setup wizard — it walks you through every credential and preference:
29
39
 
30
40
  ```bash
31
- npx tsx src/cli/index.ts setup
41
+ co-assistant setup
32
42
  ```
33
43
 
34
- The wizard creates your `.env` file and `config.json`. You can re-run it at any time to update settings.
44
+ The wizard creates your `.env` file and `config.json`. Re-run it anytime to update settings.
35
45
 
36
- ### Personalise
46
+ ### 5. Start
37
47
 
38
- Two markdown files control how the AI behaves and who it knows you are:
48
+ ```bash
49
+ co-assistant start
50
+ ```
39
51
 
40
- | File | Purpose | Committed? |
41
- |------|---------|------------|
42
- | `personality.md` | Defines the assistant's tone, style, and behaviour | ✅ Yes |
43
- | `user.md` | Your personal profile (name, role, timezone, preferences) | ❌ Gitignored |
52
+ Open Telegram, find your bot, and send a message. That's it.
44
53
 
45
- **Set up your user profile** (copy the template and fill in your details):
54
+ **Verbose mode** (shows messages and debug logs in the terminal):
46
55
 
47
56
  ```bash
48
- cp user.md.example user.md
57
+ co-assistant start -v
49
58
  ```
50
59
 
51
- Both files are read fresh on each message — edit them anytime without restarting.
60
+ ---
61
+
62
+ ## Installation Methods
52
63
 
53
- ### Start
64
+ ### Global install from npm (recommended)
65
+
66
+ Works on **Linux**, **macOS**, and **Windows**:
54
67
 
55
68
  ```bash
56
- npx tsx src/cli/index.ts start
69
+ npm install -g @hmawla/co-assistant
57
70
  ```
58
71
 
59
- Open Telegram, find your bot, and send a message. That's it.
72
+ After install, the `co-assistant` command is available everywhere. Create a directory for your instance and run `co-assistant setup` inside it.
73
+
74
+ > **Windows note:** If `co-assistant` is not found after install, ensure your npm global bin
75
+ > directory is in your `PATH`. Run `npm config get prefix` and add the resulting path + `/bin`
76
+ > (or `\bin` on Windows) to your system PATH.
60
77
 
61
- **Verbose mode** (shows incoming/outgoing messages and debug logs in the terminal):
78
+ ### Run without installing (npx)
79
+
80
+ Try it out without a global install:
62
81
 
63
82
  ```bash
83
+ npx @hmawla/co-assistant setup
84
+ npx @hmawla/co-assistant start
85
+ ```
86
+
87
+ ### Install from source
88
+
89
+ For development or customisation:
90
+
91
+ ```bash
92
+ git clone https://github.com/hmawla/co-assistant.git
93
+ cd co-assistant
94
+ npm install
95
+ ```
96
+
97
+ Run commands via tsx during development:
98
+
99
+ ```bash
100
+ npx tsx src/cli/index.ts setup
64
101
  npx tsx src/cli/index.ts start -v
65
102
  ```
66
103
 
104
+ Or build first, then run the compiled output:
105
+
106
+ ```bash
107
+ npm run build
108
+ node dist/cli/index.js start
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Personalise
114
+
115
+ Two markdown files control how the AI behaves and who it knows you are:
116
+
117
+ | File | Purpose | Included in package? |
118
+ |------|---------|---------------------|
119
+ | `personality.md` | Defines the assistant's tone, style, and behaviour | ✅ Yes — edit to customise |
120
+ | `user.md` | Your personal profile (name, role, timezone, preferences) | Template only (`user.md.example`) |
121
+
122
+ **Set up your user profile:**
123
+
124
+ ```bash
125
+ cp user.md.example user.md
126
+ # Edit user.md with your details
127
+ ```
128
+
129
+ Both files are read fresh on each message — edit them anytime without restarting. If the files don't exist in your working directory, the assistant works fine without them.
130
+
67
131
  ---
68
132
 
69
133
  ## Production Deployment
70
134
 
71
135
  For running Co-Assistant permanently on a server (VPS, Raspberry Pi, etc.).
72
136
 
73
- ### 1. Build
137
+ ### Linux — systemd (recommended)
74
138
 
75
139
  ```bash
76
- npm run build
77
- ```
140
+ # Install globally on the server
141
+ npm install -g @hmawla/co-assistant
78
142
 
79
- This compiles TypeScript to `dist/` via tsup.
143
+ # Create a dedicated directory
144
+ sudo mkdir -p /opt/co-assistant
145
+ sudo chown $USER:$USER /opt/co-assistant
146
+ cd /opt/co-assistant
80
147
 
81
- ### 2. Run with systemd (recommended for Linux)
148
+ # Set up credentials
149
+ co-assistant setup
150
+ ```
82
151
 
83
- Create a service file:
152
+ Create a systemd service:
84
153
 
85
154
  ```bash
86
155
  sudo nano /etc/systemd/system/co-assistant.service
@@ -95,8 +164,8 @@ Wants=network-online.target
95
164
  [Service]
96
165
  Type=simple
97
166
  User=your-username
98
- WorkingDirectory=/path/to/co-assistant
99
- ExecStart=/usr/bin/node dist/index.js start
167
+ WorkingDirectory=/opt/co-assistant
168
+ ExecStart=/usr/bin/co-assistant start
100
169
  Restart=always
101
170
  RestartSec=10
102
171
  Environment=NODE_ENV=production
@@ -105,7 +174,7 @@ Environment=NODE_ENV=production
105
174
  WantedBy=multi-user.target
106
175
  ```
107
176
 
108
- Enable and start:
177
+ > **Tip:** Run `which co-assistant` to find the exact path for `ExecStart` if it differs.
109
178
 
110
179
  ```bash
111
180
  sudo systemctl daemon-reload
@@ -121,30 +190,102 @@ sudo journalctl -u co-assistant -f # Live logs
121
190
  sudo systemctl restart co-assistant # Restart after config changes
122
191
  ```
123
192
 
124
- ### 3. Alternative: PM2
193
+ ### macOS launchd
125
194
 
126
195
  ```bash
127
- npm install -g pm2
128
- pm2 start dist/index.js --name co-assistant -- start
196
+ npm install -g @hmawla/co-assistant
197
+ mkdir -p ~/co-assistant && cd ~/co-assistant
198
+ co-assistant setup
199
+ ```
200
+
201
+ Create a launch agent:
202
+
203
+ ```bash
204
+ nano ~/Library/LaunchAgents/com.co-assistant.plist
205
+ ```
206
+
207
+ ```xml
208
+ <?xml version="1.0" encoding="UTF-8"?>
209
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
210
+ "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
211
+ <plist version="1.0">
212
+ <dict>
213
+ <key>Label</key>
214
+ <string>com.co-assistant</string>
215
+ <key>ProgramArguments</key>
216
+ <array>
217
+ <string>/usr/local/bin/co-assistant</string>
218
+ <string>start</string>
219
+ </array>
220
+ <key>WorkingDirectory</key>
221
+ <string>/Users/your-username/co-assistant</string>
222
+ <key>RunAtLoad</key>
223
+ <true/>
224
+ <key>KeepAlive</key>
225
+ <true/>
226
+ <key>StandardOutPath</key>
227
+ <string>/Users/your-username/co-assistant/co-assistant.log</string>
228
+ <key>StandardErrorPath</key>
229
+ <string>/Users/your-username/co-assistant/co-assistant.log</string>
230
+ </dict>
231
+ </plist>
232
+ ```
233
+
234
+ > **Tip:** Run `which co-assistant` and replace `/usr/local/bin/co-assistant` with the actual path.
235
+
236
+ ```bash
237
+ launchctl load ~/Library/LaunchAgents/com.co-assistant.plist
238
+ ```
239
+
240
+ ### Windows — Task Scheduler or PM2
241
+
242
+ **Option A: PM2 (cross-platform, recommended for Windows)**
243
+
244
+ ```powershell
245
+ npm install -g @hmawla/co-assistant pm2
246
+ mkdir C:\co-assistant
247
+ cd C:\co-assistant
248
+ co-assistant setup
249
+ pm2 start co-assistant -- start
250
+ pm2 save
251
+ pm2-startup install # auto-start on boot
252
+ ```
253
+
254
+ **Option B: Task Scheduler**
255
+
256
+ 1. Open Task Scheduler → Create Basic Task
257
+ 2. Set trigger to "When the computer starts"
258
+ 3. Action: Start a program
259
+ - Program: `co-assistant` (or full path from `where co-assistant`)
260
+ - Arguments: `start`
261
+ - Start in: `C:\co-assistant`
262
+ 4. Check "Run whether user is logged on or not"
263
+
264
+ ### Any OS — PM2
265
+
266
+ PM2 works the same way on Linux, macOS, and Windows:
267
+
268
+ ```bash
269
+ npm install -g @hmawla/co-assistant pm2
270
+ mkdir my-assistant && cd my-assistant
271
+ co-assistant setup
272
+ pm2 start co-assistant -- start
129
273
  pm2 save
130
274
  pm2 startup # generates command to auto-start on boot
131
275
  ```
132
276
 
133
- ### 4. Alternative: Docker
277
+ ### Docker
134
278
 
135
279
  ```dockerfile
136
280
  FROM node:20-slim
137
281
  WORKDIR /app
138
- COPY package*.json ./
139
- RUN npm ci --production
140
- COPY dist/ dist/
282
+ RUN npm install -g @hmawla/co-assistant
283
+ COPY .env config.json personality.md ./
141
284
  COPY plugins/ plugins/
142
285
  COPY heartbeats/ heartbeats/
143
- COPY personality.md ./
144
- COPY config.json .env ./
145
286
  # Optional — only if you created a user.md:
146
287
  # COPY user.md ./
147
- CMD ["node", "dist/index.js", "start"]
288
+ CMD ["co-assistant", "start"]
148
289
  ```
149
290
 
150
291
  ```bash
@@ -170,39 +311,24 @@ All configured via `.env` (the setup wizard handles this):
170
311
 
171
312
  ---
172
313
 
173
- ## CLI Commands
174
-
175
- **How to run commands:**
176
-
177
- ```bash
178
- # During development (runs TypeScript directly):
179
- npx tsx src/cli/index.ts setup
180
- npx tsx src/cli/index.ts start -v
181
-
182
- # After building (npm run build):
183
- node dist/cli/index.js setup
184
- node dist/cli/index.js start
185
-
186
- # After global install (npm install -g .):
187
- co-assistant setup
188
- co-assistant start
189
- ```
314
+ ## CLI Reference
190
315
 
191
316
  | Command | Description |
192
317
  |---------|-------------|
193
- | `setup` | Interactive setup wizard |
194
- | `start` | Start the bot (`-v` for verbose) |
195
- | `model` | Show current model |
196
- | `model <name>` | Switch AI model |
197
- | `plugin list` | List discovered plugins |
198
- | `plugin enable <name>` | Enable a plugin |
199
- | `plugin disable <name>` | Disable a plugin |
200
- | `plugin configure <name>` | Set up plugin credentials |
201
- | `heartbeat list` | List heartbeat events |
202
- | `heartbeat add` | Create a new heartbeat event |
203
- | `heartbeat remove <name>` | Delete a heartbeat event |
204
- | `heartbeat run [name]` | Test heartbeat(s) on demand |
205
- | `status` | Show bot and system status |
318
+ | `co-assistant setup` | Interactive setup wizard |
319
+ | `co-assistant start` | Start the bot |
320
+ | `co-assistant start -v` | Start with verbose logging |
321
+ | `co-assistant model` | Show current AI model |
322
+ | `co-assistant model <name>` | Switch AI model |
323
+ | `co-assistant plugin list` | List discovered plugins |
324
+ | `co-assistant plugin enable <name>` | Enable a plugin |
325
+ | `co-assistant plugin disable <name>` | Disable a plugin |
326
+ | `co-assistant plugin configure <name>` | Set up plugin credentials |
327
+ | `co-assistant heartbeat list` | List heartbeat events |
328
+ | `co-assistant heartbeat add` | Create a new heartbeat event |
329
+ | `co-assistant heartbeat remove <name>` | Delete a heartbeat event |
330
+ | `co-assistant heartbeat run [name]` | Test heartbeat(s) on demand |
331
+ | `co-assistant status` | Show bot and system status |
206
332
 
207
333
  ---
208
334
 
@@ -224,12 +350,12 @@ Models are grouped by rate consumption (requests per prompt):
224
350
 
225
351
  | Tier | Models | Rate |
226
352
  |------|--------|------|
227
- | **Premium** | `gpt-5`, `o3`, `claude-opus-4` | 3x |
228
- | **Standard** | `gpt-4.1`, `gpt-4o`, `o4-mini`, `claude-sonnet-4` | 1x |
229
- | **Low** | `gpt-4o-mini`, `gpt-4.1-mini`, `gpt-5-mini`, `o3-mini`, `claude-haiku-4.5` | 0.33x |
230
- | **Free** | `gpt-4.1-nano` | 0x |
353
+ | **Premium** | `gpt-5`, `o3`, `claude-opus-4` | |
354
+ | **Standard** | `gpt-4.1`, `gpt-4o`, `o4-mini`, `claude-sonnet-4` | |
355
+ | **Low** | `gpt-4o-mini`, `gpt-4.1-mini`, `gpt-5-mini`, `o3-mini`, `claude-haiku-4.5` | 0.33× |
356
+ | **Free** | `gpt-4.1-nano` | |
231
357
 
232
- Switch via CLI (`co-assistant model claude-sonnet-4`) or in the setup wizard.
358
+ Switch anytime: `co-assistant model claude-sonnet-4`
233
359
 
234
360
  ---
235
361
 
@@ -237,16 +363,16 @@ Switch via CLI (`co-assistant model claude-sonnet-4`) or in the setup wizard.
237
363
 
238
364
  ### `personality.md` — How the AI behaves
239
365
 
240
- Defines the assistant's identity, tone, formatting rules, and boundaries. This file is committed to the repo so your team shares the same base personality. Edit it to change the assistant's style.
366
+ Defines the assistant's identity, tone, formatting rules, and boundaries. Shipped with a sensible default. Edit it to change the assistant's style — changes apply on the next message.
241
367
 
242
368
  ### `user.md` — Who you are
243
369
 
244
- Contains your personal details so the AI can address you correctly and understand your context. This file is gitignored — each user creates their own from the template.
370
+ Your personal details (name, title, timezone, role, preferences) so the AI can address you correctly and understand your context. Copy `user.md.example` to get started.
245
371
 
246
- Both files are injected as system-level context on every message. The AI sees:
247
- 1. Personality instructions (how to behave)
248
- 2. User profile (who it's talking to)
249
- 3. Your actual message
372
+ Both files are injected as system-level context on every message:
373
+ 1. **Personality** how the assistant should behave
374
+ 2. **User profile** who it's talking to
375
+ 3. **Your message** — the actual prompt
250
376
 
251
377
  ---
252
378
 
@@ -262,15 +388,15 @@ Both files are injected as system-level context on every message. The AI sees:
262
388
  ### Enable a Plugin
263
389
 
264
390
  ```bash
265
- npx tsx src/cli/index.ts plugin enable gmail
266
- npx tsx src/cli/index.ts plugin configure gmail
391
+ co-assistant plugin enable gmail
392
+ co-assistant plugin configure gmail
267
393
  ```
268
394
 
269
395
  The configure command walks you through setting up OAuth credentials. For Google plugins, it includes an automated local OAuth flow to obtain refresh tokens.
270
396
 
271
397
  ### Create Your Own Plugin
272
398
 
273
- Create a directory under `plugins/` with:
399
+ Create a directory under `plugins/` in your working directory:
274
400
 
275
401
  ```
276
402
  plugins/my-plugin/
@@ -342,15 +468,8 @@ Tool names are automatically prefixed with the plugin ID (e.g., `my-plugin_do_so
342
468
 
343
469
  Heartbeats are scheduled AI prompts that run every N minutes. Use them for periodic checks like "do I have unread emails that need a reply?"
344
470
 
345
- ### Setup
346
-
347
471
  1. Set the interval in `.env`: `HEARTBEAT_INTERVAL_MINUTES=5`
348
- 2. Add a heartbeat event:
349
-
350
- ```bash
351
- npx tsx src/cli/index.ts heartbeat add
352
- ```
353
-
472
+ 2. Add a heartbeat event: `co-assistant heartbeat add`
354
473
  3. Or trigger manually via Telegram: `/heartbeat`
355
474
 
356
475
  Heartbeat prompts are stored as `.heartbeat.md` files in the `heartbeats/` directory. They support deduplication via `{{DEDUP_STATE}}` placeholders and `<!-- PROCESSED: id1, id2 -->` markers.
@@ -360,25 +479,21 @@ Heartbeat prompts are stored as `.heartbeat.md` files in the `heartbeats/` direc
360
479
  ## Architecture
361
480
 
362
481
  ```
363
- co-assistant/
364
- ├── src/
365
- ├── ai/ # Copilot SDK client, session pool, model registry
366
- ├── bot/ # Telegraf bot, handlers, middleware (auth, logging)
367
- ├── cli/ # Commander.js CLI (setup, start, plugin, model, heartbeat)
368
- ├── core/ # App orchestrator, config, logger, heartbeat, GC
369
- │ ├── plugins/ # Plugin registry, manager, sandbox, credentials
370
- ├── storage/ # SQLite database, migrations, repositories
371
- │ └── utils/ # Google OAuth helper
372
- ├── plugins/ # Installed plugins (gmail, google-calendar)
373
- ├── heartbeats/ # Heartbeat prompt files (.heartbeat.md)
374
- ├── data/ # SQLite database (auto-created)
375
- ├── personality.md # AI personality & behaviour instructions
376
- ├── user.md # Your personal profile (gitignored)
377
- ├── user.md.example # User profile template
378
- ├── config.json # Plugin & runtime configuration (gitignored)
379
- └── config.json.example
482
+ your-project/ # Your working directory
483
+ ├── .env # Credentials (auto-created by setup)
484
+ ├── config.json # Plugin & runtime config (auto-created)
485
+ ├── personality.md # AI personality instructions
486
+ ├── user.md # Your personal profile
487
+ ├── plugins/ # Your plugins (gmail, google-calendar, custom)
488
+ │ ├── gmail/
489
+ └── google-calendar/
490
+ ├── heartbeats/ # Heartbeat prompt files
491
+ ├── data/ # SQLite database (auto-created)
492
+ └── node_modules/ # If installed locally
380
493
  ```
381
494
 
495
+ When installed globally, the package provides the `co-assistant` binary. All runtime files (config, data, plugins, heartbeats) live in whichever directory you run the command from.
496
+
382
497
  **Key internals:**
383
498
 
384
499
  - **Session pool** — Multiple parallel AI sessions so messages don't queue behind each other
@@ -391,6 +506,26 @@ co-assistant/
391
506
 
392
507
  ---
393
508
 
509
+ ## Updating
510
+
511
+ ```bash
512
+ npm update -g @hmawla/co-assistant
513
+ ```
514
+
515
+ Your `.env`, `config.json`, `user.md`, plugins, and heartbeats are unaffected — they live in your working directory, not in the package.
516
+
517
+ ---
518
+
519
+ ## Uninstall
520
+
521
+ ```bash
522
+ npm uninstall -g @hmawla/co-assistant
523
+ ```
524
+
525
+ Your working directory and data are preserved. Delete it manually if no longer needed.
526
+
527
+ ---
528
+
394
529
  ## License
395
530
 
396
531
  MIT
package/dist/cli/index.js CHANGED
@@ -27,11 +27,19 @@ function resolveLogLevel() {
27
27
  const valid = ["fatal", "error", "warn", "info", "debug", "trace", "silent"];
28
28
  return envLevel && valid.includes(envLevel) ? envLevel : "info";
29
29
  }
30
+ function isPinoPrettyAvailable() {
31
+ try {
32
+ import.meta.resolve("pino-pretty");
33
+ return true;
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
30
38
  function buildLoggerOptions() {
31
39
  const level = resolveLogLevel();
32
40
  const isProduction = process.env.NODE_ENV === "production";
33
41
  const opts = { level };
34
- if (!isProduction) {
42
+ if (!isProduction && isPinoPrettyAvailable()) {
35
43
  opts.transport = {
36
44
  target: "pino-pretty",
37
45
  options: {