@simonfestl/husky-cli 1.21.0 ā 1.22.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/dist/commands/auth.js +8 -2
- package/dist/commands/worktree.js +12 -6
- package/dist/lib/api-client.js +7 -0
- package/package.json +1 -1
package/dist/commands/auth.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { getConfig, setSessionConfig, clearSessionConfig, getSessionConfig, fetchAndCacheRole } from "./config.js";
|
|
3
3
|
import { getPermissions, clearPermissionsCache, getCacheStatus, hasPermission, canAccessKnowledgeBase } from "../lib/permissions-cache.js";
|
|
4
|
+
import { apiRequest as hybridApiRequest } from "../lib/api-client.js";
|
|
4
5
|
const API_KEY_ROLES = [
|
|
5
6
|
"admin", "supervisor", "worker", "reviewer", "support",
|
|
6
7
|
"purchasing", "ops", "e2e_agent", "pr_agent"
|
|
@@ -164,7 +165,7 @@ authCommand
|
|
|
164
165
|
.option("--json", "Output as JSON")
|
|
165
166
|
.action(async (options) => {
|
|
166
167
|
try {
|
|
167
|
-
const data = await
|
|
168
|
+
const data = await hybridApiRequest("/api/auth/whoami");
|
|
168
169
|
if (options.json) {
|
|
169
170
|
console.log(JSON.stringify(data, null, 2));
|
|
170
171
|
return;
|
|
@@ -172,7 +173,12 @@ authCommand
|
|
|
172
173
|
console.log("\nš Authentication Info");
|
|
173
174
|
console.log("ā".repeat(40));
|
|
174
175
|
console.log(`Role: ${data.role}`);
|
|
175
|
-
|
|
176
|
+
if (data.keyId) {
|
|
177
|
+
console.log(`Key ID: ${data.keyId}`);
|
|
178
|
+
}
|
|
179
|
+
if (data.agent) {
|
|
180
|
+
console.log(`Agent: ${data.agent}`);
|
|
181
|
+
}
|
|
176
182
|
console.log(`Source: ${data.source}`);
|
|
177
183
|
if (data.scopes && data.scopes.length > 0) {
|
|
178
184
|
console.log(`Scopes: ${data.scopes.join(", ")}`);
|
|
@@ -12,6 +12,15 @@ export const worktreeCommand = new Command("worktree")
|
|
|
12
12
|
function getProjectDir(options) {
|
|
13
13
|
return options.project ? path.resolve(options.project) : process.cwd();
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if current session has worker role.
|
|
17
|
+
* Workers have restricted permissions (cannot push/create PRs directly).
|
|
18
|
+
*/
|
|
19
|
+
function isWorkerRole() {
|
|
20
|
+
const config = getConfig();
|
|
21
|
+
const role = config.sessionRole || config.role || "";
|
|
22
|
+
return role === "worker";
|
|
23
|
+
}
|
|
15
24
|
/**
|
|
16
25
|
* Get a WorktreeManager instance.
|
|
17
26
|
*/
|
|
@@ -733,9 +742,7 @@ worktreeCommand
|
|
|
733
742
|
.action(async (sessionName, options) => {
|
|
734
743
|
try {
|
|
735
744
|
// Worker role cannot push - must submit for review
|
|
736
|
-
|
|
737
|
-
const role = config.sessionRole || config.role || "";
|
|
738
|
-
if (role === "worker") {
|
|
745
|
+
if (isWorkerRole()) {
|
|
739
746
|
console.error("Error: Workers cannot push directly.");
|
|
740
747
|
console.error("Submit for review instead: husky task update <id> --status review");
|
|
741
748
|
console.error("The Reviewer agent will push and create the PR.");
|
|
@@ -772,15 +779,14 @@ worktreeCommand
|
|
|
772
779
|
.option("--task-id <id>", "Task ID to update with PR URL")
|
|
773
780
|
.option("--json", "Output as JSON")
|
|
774
781
|
.action(async (sessionName, options) => {
|
|
775
|
-
const config = getConfig();
|
|
776
782
|
// Worker role cannot create PRs - must submit for review
|
|
777
|
-
|
|
778
|
-
if (role === "worker") {
|
|
783
|
+
if (isWorkerRole()) {
|
|
779
784
|
console.error("Error: Workers cannot create PRs directly.");
|
|
780
785
|
console.error("Submit for review instead: husky task update <id> --status review");
|
|
781
786
|
console.error("The Reviewer agent will create the PR after code review.");
|
|
782
787
|
process.exit(1);
|
|
783
788
|
}
|
|
789
|
+
const config = getConfig();
|
|
784
790
|
try {
|
|
785
791
|
const manager = getManager(options);
|
|
786
792
|
const info = manager.getWorktree(sessionName);
|
package/dist/lib/api-client.js
CHANGED
|
@@ -61,16 +61,21 @@ async function doFetch(url, method, authHeader, body) {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
async function getAuthHeader(session, apiKey) {
|
|
64
|
+
// DEBUG: console.log('DEBUG session:', session?.token ? 'exists' : 'missing', session?.expiresAt);
|
|
64
65
|
if (session?.token && session.expiresAt) {
|
|
66
|
+
// DEBUG: console.log('DEBUG: Checking expiration...');
|
|
65
67
|
if (isSessionExpired(session.expiresAt)) {
|
|
68
|
+
// DEBUG: console.log('DEBUG: Session expired, refreshing...');
|
|
66
69
|
if (session.agent) {
|
|
67
70
|
const newSession = await refreshSession(session.agent);
|
|
68
71
|
if (newSession) {
|
|
72
|
+
// DEBUG: console.log('DEBUG: Refresh successful, using Bearer token');
|
|
69
73
|
return { "Authorization": `Bearer ${newSession.token}` };
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
clearSessionConfig();
|
|
73
77
|
if (apiKey) {
|
|
78
|
+
// DEBUG: console.log('DEBUG: Refresh failed, falling back to API key');
|
|
74
79
|
return { "x-api-key": apiKey };
|
|
75
80
|
}
|
|
76
81
|
throw new Error("Session expired and no API key available for refresh");
|
|
@@ -78,9 +83,11 @@ async function getAuthHeader(session, apiKey) {
|
|
|
78
83
|
if (isSessionExpiringSoon(session.expiresAt) && session.agent) {
|
|
79
84
|
refreshSession(session.agent).catch(() => { });
|
|
80
85
|
}
|
|
86
|
+
// DEBUG: console.log('DEBUG: Using existing Bearer token');
|
|
81
87
|
return { "Authorization": `Bearer ${session.token}` };
|
|
82
88
|
}
|
|
83
89
|
if (apiKey) {
|
|
90
|
+
// DEBUG: console.log('DEBUG: No session, using API key');
|
|
84
91
|
return { "x-api-key": apiKey };
|
|
85
92
|
}
|
|
86
93
|
throw new Error("No authentication configured. Run: husky auth login --agent <name> or husky config set api-key <key>");
|