@simonfestl/husky-cli 1.10.0 → 1.13.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 CHANGED
@@ -143,6 +143,76 @@ husky e2e list --task <id> # List artifacts
143
143
  husky e2e clean --older-than 7 # Clean old artifacts
144
144
  ```
145
145
 
146
+ ### PR Management (PR Agent)
147
+
148
+ ```bash
149
+ husky pr list # List open PRs
150
+ husky pr get <pr-number> # Get PR details
151
+ husky pr review <pr-number> # Start review
152
+ husky pr approve <pr-number> # Approve PR
153
+ husky pr request-changes <pr-number> --comment "..."
154
+ husky pr merge <pr-number> # Merge PR
155
+ husky pr close <pr-number> # Close PR
156
+ ```
157
+
158
+ ### Infrastructure (DevOps)
159
+
160
+ ```bash
161
+ husky infra status # Overall infra status
162
+ husky infra vms # List all VMs
163
+ husky infra services # Cloud Run services
164
+ husky infra logs <service> # Service logs
165
+ husky infra metrics # Resource metrics
166
+ ```
167
+
168
+ ### YouTube Summarization
169
+
170
+ ```bash
171
+ husky youtube <url> # Summarize video with Gemini AI
172
+ husky youtube <url> --remember # Also store in Second Brain
173
+ husky youtube <url> --json # JSON output
174
+ ```
175
+
176
+ ### Image Generation
177
+
178
+ ```bash
179
+ husky image "a futuristic city" # Generate image with Imagen 3
180
+ husky image "..." --output ./image.png # Save to file
181
+ husky image "..." --aspect 16:9 # Aspect ratio
182
+ ```
183
+
184
+ ### Mermaid Diagrams
185
+
186
+ ```bash
187
+ husky mermaid validate <file> # Validate Mermaid syntax
188
+ husky mermaid validate --stdin # Validate from stdin
189
+ ```
190
+
191
+ ### Service Accounts
192
+
193
+ ```bash
194
+ husky sa list # List service accounts
195
+ husky sa create <name> --role worker # Create service account
196
+ husky sa get <id> # Get details
197
+ husky sa delete <id> # Delete service account
198
+ ```
199
+
200
+ ### Agent Messaging
201
+
202
+ ```bash
203
+ husky agent-msg send <to> "message" # Send to another agent
204
+ husky agent-msg inbox # Check inbox
205
+ husky agent-msg read <id> # Read message
206
+ ```
207
+
208
+ ### Preview Deployments
209
+
210
+ ```bash
211
+ husky preview list # List PR previews
212
+ husky preview get <pr-number> # Get preview URL
213
+ husky preview logs <pr-number> # Preview logs
214
+ ```
215
+
146
216
  ### Business Strategy
147
217
 
148
218
  ```bash
@@ -249,6 +319,41 @@ husky config list
249
319
  husky config test
250
320
  ```
251
321
 
322
+ ### Authentication (Session Tokens)
323
+
324
+ Session tokens provide short-lived JWT authentication for agents. They are created using `HUSKY_API_KEY` and auto-refresh when expired.
325
+
326
+ ```bash
327
+ # Login (creates 1-hour session token)
328
+ husky auth login --agent supervisor
329
+ husky auth login --agent husky-worker-1
330
+
331
+ # Check session status
332
+ husky auth session
333
+ husky auth session --json
334
+
335
+ # Refresh token manually
336
+ husky auth refresh
337
+ husky auth refresh --agent supervisor
338
+
339
+ # Logout (clear session)
340
+ husky auth logout
341
+ ```
342
+
343
+ **VM Startup Pattern:**
344
+ ```bash
345
+ #!/bin/bash
346
+ VM_NAME=$(hostname)
347
+ husky auth login --agent "$VM_NAME"
348
+ # All subsequent commands use Bearer token
349
+ ```
350
+
351
+ **How it works:**
352
+ 1. `HUSKY_API_KEY` is used once to create a session token
353
+ 2. All subsequent API calls use `Authorization: Bearer <token>`
354
+ 3. Token auto-refreshes when expired or within 5 minutes of expiry
355
+ 4. Falls back to `x-api-key` if refresh fails
356
+
252
357
  ### Help & Documentation
253
358
 
254
359
  ```bash
@@ -328,6 +433,27 @@ husky --version
328
433
 
329
434
  ## Changelog
330
435
 
436
+ ### v1.12.0 (2026-01-12) - Session Token Authentication
437
+
438
+ **New Features:**
439
+ - `husky auth login --agent <name>` - Create session token from HUSKY_API_KEY
440
+ - `husky auth logout` - Clear session token
441
+ - `husky auth session` - Show session status (agent, role, expiry)
442
+ - `husky auth refresh` - Manually refresh token
443
+
444
+ **Improvements:**
445
+ - All API calls now use Bearer token authentication (auto-refresh)
446
+ - Token auto-refreshes when expired or within 5 minutes of expiry
447
+ - Falls back to x-api-key for backwards compatibility
448
+ - JWT_SECRET now required in production (fail-fast)
449
+
450
+ **Documentation:**
451
+ - Added missing command sections: pr, infra, youtube, image, mermaid, sa, agent-msg, preview
452
+ - Updated architecture docs with session token flow
453
+
454
+ **Code Quality:**
455
+ - Removed `as any` type suppression in sop.ts
456
+
331
457
  ### v1.7.0 (2026-01-11) - E2E Agent Production Ready
332
458
 
333
459
  **New Features:**
@@ -1,5 +1,5 @@
1
1
  import { Command } from "commander";
2
- import { getConfig } from "./config.js";
2
+ import { getConfig, setSessionConfig, clearSessionConfig, getSessionConfig } from "./config.js";
3
3
  import { getPermissions, clearPermissionsCache, getCacheStatus, hasPermission, canAccessKnowledgeBase } from "../lib/permissions-cache.js";
4
4
  const API_KEY_ROLES = [
5
5
  "admin", "supervisor", "worker", "reviewer", "support",
@@ -260,3 +260,178 @@ authCommand
260
260
  process.exit(1);
261
261
  }
262
262
  });
263
+ authCommand
264
+ .command("login")
265
+ .description("Create a session token for this agent")
266
+ .requiredOption("--agent <name>", "Agent name (must be registered in Firestore)")
267
+ .option("--json", "Output as JSON")
268
+ .action(async (options) => {
269
+ try {
270
+ const config = getConfig();
271
+ if (!config.apiUrl || !config.apiKey) {
272
+ console.error("API not configured. Run: husky config set api-url <url> && husky config set api-key <key>");
273
+ process.exit(1);
274
+ }
275
+ const url = new URL("/api/auth/session", config.apiUrl);
276
+ const res = await fetch(url.toString(), {
277
+ method: "POST",
278
+ headers: {
279
+ "x-api-key": config.apiKey,
280
+ "Content-Type": "application/json",
281
+ },
282
+ body: JSON.stringify({ agent: options.agent }),
283
+ });
284
+ if (!res.ok) {
285
+ const error = await res.json().catch(() => ({ error: res.statusText }));
286
+ if (res.status === 404) {
287
+ console.error(`Agent '${options.agent}' not found. Register the agent first.`);
288
+ }
289
+ else {
290
+ console.error(`Login failed: ${error.message || error.error || `HTTP ${res.status}`}`);
291
+ }
292
+ process.exit(1);
293
+ }
294
+ const session = await res.json();
295
+ setSessionConfig(session);
296
+ if (options.json) {
297
+ console.log(JSON.stringify({
298
+ success: true,
299
+ agent: session.agent,
300
+ role: session.role,
301
+ expiresAt: session.expiresAt,
302
+ }, null, 2));
303
+ return;
304
+ }
305
+ const expiresAt = new Date(session.expiresAt);
306
+ console.log("\n✅ Session created");
307
+ console.log("─".repeat(40));
308
+ console.log(`Agent: ${session.agent}`);
309
+ console.log(`Role: ${session.role}`);
310
+ console.log(`Expires: ${expiresAt.toLocaleString()}`);
311
+ console.log("");
312
+ console.log("All API calls will now use this session token.");
313
+ }
314
+ catch (error) {
315
+ console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`);
316
+ process.exit(1);
317
+ }
318
+ });
319
+ authCommand
320
+ .command("logout")
321
+ .description("Clear the current session token")
322
+ .option("--json", "Output as JSON")
323
+ .action(async (options) => {
324
+ const session = getSessionConfig();
325
+ if (!session) {
326
+ if (options.json) {
327
+ console.log(JSON.stringify({ success: false, message: "No active session" }));
328
+ }
329
+ else {
330
+ console.log("No active session to clear.");
331
+ }
332
+ return;
333
+ }
334
+ clearSessionConfig();
335
+ if (options.json) {
336
+ console.log(JSON.stringify({ success: true, agent: session.agent }));
337
+ return;
338
+ }
339
+ console.log(`✅ Session cleared for agent '${session.agent}'`);
340
+ });
341
+ authCommand
342
+ .command("session")
343
+ .description("Show current session status")
344
+ .option("--json", "Output as JSON")
345
+ .action(async (options) => {
346
+ const session = getSessionConfig();
347
+ if (!session || !session.token) {
348
+ if (options.json) {
349
+ console.log(JSON.stringify({ active: false }));
350
+ }
351
+ else {
352
+ console.log("No active session. Run: husky auth login --agent <name>");
353
+ }
354
+ return;
355
+ }
356
+ const expiresAt = session.expiresAt ? new Date(session.expiresAt) : null;
357
+ const now = new Date();
358
+ const isExpired = expiresAt ? expiresAt < now : true;
359
+ const expiresInMs = expiresAt ? expiresAt.getTime() - now.getTime() : 0;
360
+ const expiresInMinutes = Math.max(0, Math.floor(expiresInMs / 60000));
361
+ if (options.json) {
362
+ console.log(JSON.stringify({
363
+ active: !isExpired,
364
+ agent: session.agent,
365
+ role: session.role,
366
+ expiresAt: session.expiresAt,
367
+ expired: isExpired,
368
+ expiresInMinutes,
369
+ }, null, 2));
370
+ return;
371
+ }
372
+ console.log("\n🔐 Session Status");
373
+ console.log("─".repeat(40));
374
+ console.log(`Agent: ${session.agent || "(unknown)"}`);
375
+ console.log(`Role: ${session.role || "(unknown)"}`);
376
+ if (isExpired) {
377
+ console.log(`Status: 🔴 EXPIRED`);
378
+ console.log(`Expired: ${expiresAt?.toLocaleString() || "(unknown)"}`);
379
+ console.log("");
380
+ console.log("Run: husky auth refresh --agent <name>");
381
+ }
382
+ else {
383
+ console.log(`Status: 🟢 ACTIVE`);
384
+ console.log(`Expires: ${expiresAt?.toLocaleString()} (${expiresInMinutes} minutes)`);
385
+ }
386
+ });
387
+ authCommand
388
+ .command("refresh")
389
+ .description("Refresh the session token")
390
+ .option("--agent <name>", "Agent name (uses current session agent if not specified)")
391
+ .option("--json", "Output as JSON")
392
+ .action(async (options) => {
393
+ try {
394
+ const config = getConfig();
395
+ if (!config.apiUrl || !config.apiKey) {
396
+ console.error("API not configured. Run: husky config set api-url <url> && husky config set api-key <key>");
397
+ process.exit(1);
398
+ }
399
+ const currentSession = getSessionConfig();
400
+ const agentName = options.agent || currentSession?.agent;
401
+ if (!agentName) {
402
+ console.error("No agent specified and no active session. Use: husky auth refresh --agent <name>");
403
+ process.exit(1);
404
+ }
405
+ const url = new URL("/api/auth/session", config.apiUrl);
406
+ const res = await fetch(url.toString(), {
407
+ method: "POST",
408
+ headers: {
409
+ "x-api-key": config.apiKey,
410
+ "Content-Type": "application/json",
411
+ },
412
+ body: JSON.stringify({ agent: agentName }),
413
+ });
414
+ if (!res.ok) {
415
+ const error = await res.json().catch(() => ({ error: res.statusText }));
416
+ console.error(`Refresh failed: ${error.message || error.error || `HTTP ${res.status}`}`);
417
+ process.exit(1);
418
+ }
419
+ const session = await res.json();
420
+ setSessionConfig(session);
421
+ if (options.json) {
422
+ console.log(JSON.stringify({
423
+ success: true,
424
+ agent: session.agent,
425
+ role: session.role,
426
+ expiresAt: session.expiresAt,
427
+ }, null, 2));
428
+ return;
429
+ }
430
+ const expiresAt = new Date(session.expiresAt);
431
+ console.log(`✅ Session refreshed for '${session.agent}' (expires: ${expiresAt.toLocaleString()})`);
432
+ }
433
+ catch (error) {
434
+ console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`);
435
+ process.exit(1);
436
+ }
437
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Husky Biz Emove Command
3
+ *
4
+ * Manages emovedistribution.com (B2B e-mobility parts supplier) via web scraping
5
+ * WooCommerce platform integration (Spanish locale)
6
+ * - Parts search and catalog browsing
7
+ * - Order history and details
8
+ * - Invoice download
9
+ */
10
+ import { Command } from "commander";
11
+ export declare const emoveCommand: Command;
12
+ export default emoveCommand;
@@ -0,0 +1,249 @@
1
+ /**
2
+ * Husky Biz Emove Command
3
+ *
4
+ * Manages emovedistribution.com (B2B e-mobility parts supplier) via web scraping
5
+ * WooCommerce platform integration (Spanish locale)
6
+ * - Parts search and catalog browsing
7
+ * - Order history and details
8
+ * - Invoice download
9
+ */
10
+ import { Command } from "commander";
11
+ import { EmovePlaywrightClient } from "../../lib/biz/emove-playwright.js";
12
+ import { getConfig, saveConfig } from "../config.js";
13
+ import * as path from "path";
14
+ import { homedir } from "os";
15
+ export const emoveCommand = new Command("emove")
16
+ .description("Manage emovedistribution.com (e-mobility parts supplier - WooCommerce/ES)");
17
+ // ============================================================================
18
+ // husky biz emove login
19
+ // ============================================================================
20
+ emoveCommand
21
+ .command("login")
22
+ .description("Setup Emove credentials")
23
+ .requiredOption("-u, --username <username>", "Login username or email")
24
+ .requiredOption("-p, --password <password>", "Login password")
25
+ .option("--base-url <url>", "Base URL", "https://emovedistribution.com")
26
+ .action(async (options) => {
27
+ try {
28
+ // Save to config
29
+ const config = getConfig();
30
+ config.emoveUsername = options.username;
31
+ config.emovePassword = options.password;
32
+ if (options.baseUrl) {
33
+ config.emoveBaseUrl = options.baseUrl;
34
+ }
35
+ saveConfig(config);
36
+ console.log("Testing authentication...");
37
+ // Test login
38
+ const client = EmovePlaywrightClient.fromConfig();
39
+ try {
40
+ const result = await client.login();
41
+ if (result.success) {
42
+ console.log("✓ Successfully authenticated with emovedistribution.com");
43
+ console.log("\nYou can now use:");
44
+ console.log(" husky biz emove orders list");
45
+ console.log(" husky biz emove orders get <id>");
46
+ console.log(" husky biz emove invoice <order-id>");
47
+ console.log(" husky biz emove products <query>");
48
+ }
49
+ else {
50
+ console.error("✗ Login failed:", result.error);
51
+ process.exit(1);
52
+ }
53
+ }
54
+ finally {
55
+ await client.close();
56
+ }
57
+ }
58
+ catch (error) {
59
+ console.error("✗ Login failed:", error.message);
60
+ process.exit(1);
61
+ }
62
+ });
63
+ // ============================================================================
64
+ // husky biz emove orders
65
+ // ============================================================================
66
+ const ordersSubcommand = new Command("orders")
67
+ .description("View supplier orders");
68
+ ordersSubcommand
69
+ .command("list")
70
+ .description("List all orders from Emove")
71
+ .option("--json", "Output as JSON")
72
+ .action(async (options) => {
73
+ const client = EmovePlaywrightClient.fromConfig();
74
+ try {
75
+ const orders = await client.listOrders();
76
+ if (options.json) {
77
+ console.log(JSON.stringify(orders, null, 2));
78
+ return;
79
+ }
80
+ if (orders.length === 0) {
81
+ console.log("\n No orders found.\n");
82
+ return;
83
+ }
84
+ console.log(`\n 📦 Emove Orders (${orders.length} found)\n`);
85
+ // Header
86
+ console.log(` ${"Order #".padEnd(15)} │ ` +
87
+ `${"Date".padEnd(20)} │ ` +
88
+ `${"Status".padEnd(15)} │ ` +
89
+ `${"Total".padEnd(12)}`);
90
+ console.log(" " + "─".repeat(75));
91
+ // Orders
92
+ for (const order of orders) {
93
+ console.log(` ${order.orderNumber.padEnd(15)} │ ` +
94
+ `${order.date.padEnd(20)} │ ` +
95
+ `${order.status.padEnd(15)} │ ` +
96
+ `${order.total || 'N/A'}`);
97
+ }
98
+ console.log("");
99
+ }
100
+ catch (error) {
101
+ console.error("Error:", error.message);
102
+ process.exit(1);
103
+ }
104
+ finally {
105
+ await client.close();
106
+ }
107
+ });
108
+ ordersSubcommand
109
+ .command("get <id>")
110
+ .description("Get order details")
111
+ .option("--json", "Output as JSON")
112
+ .action(async (id, options) => {
113
+ const client = EmovePlaywrightClient.fromConfig();
114
+ try {
115
+ const order = await client.getOrder(id);
116
+ if (options.json) {
117
+ console.log(JSON.stringify(order, null, 2));
118
+ return;
119
+ }
120
+ console.log(`\n Order ${order.orderNumber}`);
121
+ console.log(" " + "─".repeat(60));
122
+ console.log(` Status: ${order.status}`);
123
+ console.log(` Date: ${order.date}`);
124
+ console.log(` Total: ${order.total || 'N/A'}`);
125
+ if (order.trackingNumber) {
126
+ console.log(` Tracking: ${order.trackingNumber}`);
127
+ }
128
+ if (order.paymentMethod) {
129
+ console.log(` Payment: ${order.paymentMethod}`);
130
+ }
131
+ if (order.customer && order.customer.name) {
132
+ console.log(`\n Shipping To:`);
133
+ console.log(` ${order.customer.name}`);
134
+ if (order.customer.company) {
135
+ console.log(` ${order.customer.company}`);
136
+ }
137
+ if (order.customer.address) {
138
+ console.log(` ${order.customer.address}`);
139
+ }
140
+ if (order.customer.postcode && order.customer.city) {
141
+ console.log(` ${order.customer.postcode} ${order.customer.city}`);
142
+ }
143
+ if (order.customer.email) {
144
+ console.log(` ${order.customer.email}`);
145
+ }
146
+ }
147
+ if (order.items.length > 0) {
148
+ console.log(`\n Items:`);
149
+ for (const item of order.items) {
150
+ const sku = item.sku ? `[${item.sku}]`.padEnd(18) : "".padEnd(18);
151
+ const name = item.name.slice(0, 35).padEnd(35);
152
+ console.log(` ${item.quantity}x ${sku} ${name} (${item.total})`);
153
+ }
154
+ }
155
+ if (order.subtotal || order.shipping || order.tax) {
156
+ console.log(`\n Totals:`);
157
+ if (order.subtotal)
158
+ console.log(` Subtotal: ${order.subtotal}`);
159
+ if (order.shipping)
160
+ console.log(` Shipping: ${order.shipping}`);
161
+ if (order.tax)
162
+ console.log(` Tax: ${order.tax}`);
163
+ if (order.total)
164
+ console.log(` Total: ${order.total}`);
165
+ }
166
+ if (order.invoiceUrl) {
167
+ console.log(`\n 📄 Invoice available`);
168
+ console.log(` Download with: husky biz emove invoice ${order.id}`);
169
+ }
170
+ console.log("");
171
+ }
172
+ catch (error) {
173
+ console.error("Error:", error.message);
174
+ process.exit(1);
175
+ }
176
+ finally {
177
+ await client.close();
178
+ }
179
+ });
180
+ emoveCommand.addCommand(ordersSubcommand);
181
+ // ============================================================================
182
+ // husky biz emove invoice
183
+ // ============================================================================
184
+ emoveCommand
185
+ .command("invoice <order-id>")
186
+ .description("Download invoice PDF for order")
187
+ .option("-o, --output <path>", "Save path (default: ~/Downloads/emove-invoice-{id}.pdf)")
188
+ .action(async (orderId, options) => {
189
+ const client = EmovePlaywrightClient.fromConfig();
190
+ try {
191
+ const savePath = options.output ||
192
+ path.join(homedir(), 'Downloads', `emove-invoice-${orderId}.pdf`);
193
+ console.log(`Downloading invoice for order #${orderId}...`);
194
+ const success = await client.downloadInvoice(orderId, savePath);
195
+ if (success) {
196
+ console.log(`✓ Invoice saved to: ${savePath}`);
197
+ }
198
+ else {
199
+ console.error("✗ Invoice not available for this order");
200
+ process.exit(1);
201
+ }
202
+ }
203
+ catch (error) {
204
+ console.error("Error:", error.message);
205
+ process.exit(1);
206
+ }
207
+ finally {
208
+ await client.close();
209
+ }
210
+ });
211
+ // ============================================================================
212
+ // husky biz emove products
213
+ // ============================================================================
214
+ emoveCommand
215
+ .command("products <query>")
216
+ .description("Search for parts in catalog")
217
+ .option("--json", "Output as JSON")
218
+ .action(async (query, options) => {
219
+ const client = EmovePlaywrightClient.fromConfig();
220
+ try {
221
+ const products = await client.searchProducts(query);
222
+ if (options.json) {
223
+ console.log(JSON.stringify(products, null, 2));
224
+ return;
225
+ }
226
+ if (products.length === 0) {
227
+ console.log(`\n No products found for: "${query}"\n`);
228
+ return;
229
+ }
230
+ console.log(`\n 🔍 Search results for: "${query}" (${products.length} found)\n`);
231
+ for (const product of products) {
232
+ const sku = product.sku ? `[${product.sku}]` : '';
233
+ const price = product.price || 'Price hidden (login required)';
234
+ const stock = product.stockStatus || '';
235
+ console.log(` ${product.name}`);
236
+ console.log(` ${sku} ${price}${stock ? ' - ' + stock : ''}`);
237
+ console.log(` ${product.url}`);
238
+ console.log("");
239
+ }
240
+ }
241
+ catch (error) {
242
+ console.error("Error:", error.message);
243
+ process.exit(1);
244
+ }
245
+ finally {
246
+ await client.close();
247
+ }
248
+ });
249
+ export default emoveCommand;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Husky Biz Skuterzone Command
3
+ *
4
+ * Manages skuterzonepro.com (B2B e-mobility parts supplier) via web scraping
5
+ * WooCommerce platform integration
6
+ * - Parts search and catalog browsing
7
+ * - Order history and details
8
+ * - Invoice download
9
+ */
10
+ import { Command } from "commander";
11
+ export declare const skuterzoneCommand: Command;
12
+ export default skuterzoneCommand;