@simonfestl/husky-cli 1.25.3 → 1.26.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.
@@ -4,6 +4,7 @@ import { randomUUID } from "crypto";
4
4
  import { readFileSync } from "fs";
5
5
  import { join, dirname } from "path";
6
6
  import { fileURLToPath } from "url";
7
+ import { getApiClient } from "./api-client.js";
7
8
  // Get or generate persistent worker identity (stored in ~/.husky/config.json)
8
9
  export function getWorkerIdentity() {
9
10
  const config = getConfig();
@@ -43,55 +44,54 @@ export function generateSessionId() {
43
44
  return `sess-${randomUUID().slice(0, 8)}`;
44
45
  }
45
46
  // Register or update worker with API, return workerId
46
- export async function ensureWorkerRegistered(apiUrl, apiKey) {
47
+ // Note: apiUrl and apiKey parameters kept for backwards compatibility but not used
48
+ export async function ensureWorkerRegistered(_apiUrl, _apiKey) {
47
49
  const identity = getWorkerIdentity();
48
- // Try to get existing worker
49
- const getRes = await fetch(`${apiUrl}/api/workers/${identity.workerId}`, {
50
- headers: { "x-api-key": apiKey },
51
- });
52
- if (getRes.ok) {
50
+ const api = getApiClient();
51
+ try {
52
+ // Try to get existing worker
53
+ await api.get(`/api/workers/${identity.workerId}`);
53
54
  // Worker exists, just return the ID
54
55
  return identity.workerId;
55
56
  }
56
- if (getRes.status === 404) {
57
- // Register new worker
58
- const registerRes = await fetch(`${apiUrl}/api/workers`, {
59
- method: "POST",
60
- headers: { "x-api-key": apiKey, "Content-Type": "application/json" },
61
- body: JSON.stringify({
62
- name: identity.workerName,
63
- type: "claude-code",
64
- hostname: identity.hostname,
65
- username: identity.username,
66
- platform: identity.platform,
67
- agentVersion: identity.agentVersion,
68
- }),
69
- });
70
- if (!registerRes.ok) {
71
- console.error(`Warning: Failed to register worker: ${registerRes.status}`);
57
+ catch (error) {
58
+ const errorMsg = error instanceof Error ? error.message : "";
59
+ if (!errorMsg.includes("404")) {
60
+ // Unexpected error, return local ID
72
61
  return identity.workerId;
73
62
  }
74
- const worker = await registerRes.json();
63
+ }
64
+ // Worker not found (404), register new worker
65
+ try {
66
+ const worker = await api.post("/api/workers", {
67
+ name: identity.workerName,
68
+ type: "claude-code",
69
+ hostname: identity.hostname,
70
+ username: identity.username,
71
+ platform: identity.platform,
72
+ agentVersion: identity.agentVersion,
73
+ });
75
74
  // Update local config with server-assigned ID if different
76
75
  if (worker.id !== identity.workerId) {
77
76
  setConfig("workerId", worker.id);
78
77
  return worker.id;
79
78
  }
80
79
  }
80
+ catch {
81
+ console.error("Warning: Failed to register worker");
82
+ }
81
83
  return identity.workerId;
82
84
  }
83
85
  // Register a new session with API
84
- export async function registerSession(apiUrl, apiKey, workerId, sessionId) {
86
+ // Note: apiUrl and apiKey parameters kept for backwards compatibility but not used
87
+ export async function registerSession(_apiUrl, _apiKey, workerId, sessionId) {
85
88
  try {
86
- await fetch(`${apiUrl}/api/workers/sessions`, {
87
- method: "POST",
88
- headers: { "x-api-key": apiKey, "Content-Type": "application/json" },
89
- body: JSON.stringify({
90
- id: sessionId,
91
- workerId,
92
- pid: process.pid,
93
- workingDirectory: process.cwd(),
94
- }),
89
+ const api = getApiClient();
90
+ await api.post("/api/workers/sessions", {
91
+ id: sessionId,
92
+ workerId,
93
+ pid: process.pid,
94
+ workingDirectory: process.cwd(),
95
95
  });
96
96
  }
97
97
  catch {
@@ -99,13 +99,11 @@ export async function registerSession(apiUrl, apiKey, workerId, sessionId) {
99
99
  }
100
100
  }
101
101
  // Send session heartbeat
102
- export async function sessionHeartbeat(apiUrl, apiKey, sessionId, currentTaskId) {
102
+ // Note: apiUrl and apiKey parameters kept for backwards compatibility but not used
103
+ export async function sessionHeartbeat(_apiUrl, _apiKey, sessionId, currentTaskId) {
103
104
  try {
104
- await fetch(`${apiUrl}/api/workers/sessions/${sessionId}/heartbeat`, {
105
- method: "POST",
106
- headers: { "x-api-key": apiKey, "Content-Type": "application/json" },
107
- body: JSON.stringify({ currentTaskId }),
108
- });
105
+ const api = getApiClient();
106
+ await api.post(`/api/workers/sessions/${sessionId}/heartbeat`, { currentTaskId });
109
107
  }
110
108
  catch {
111
109
  // Silently fail
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonfestl/husky-cli",
3
- "version": "1.25.3",
3
+ "version": "1.26.0",
4
4
  "description": "CLI for Huskyv0 Task Orchestration with Claude Agent SDK",
5
5
  "type": "module",
6
6
  "bin": {
@@ -25,6 +25,8 @@
25
25
  "@google/generative-ai": "^0.24.1",
26
26
  "@inquirer/prompts": "^8.1.0",
27
27
  "@types/uuid": "^10.0.0",
28
+ "chalk": "^5.6.2",
29
+ "cli-table3": "^0.6.5",
28
30
  "commander": "^12.1.0",
29
31
  "firebase-admin": "^13.6.0",
30
32
  "playwright": "^1.57.0",