@gheima/cli 0.9.0 → 0.9.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/CHANGELOG.md +12 -0
- package/dist/cli.js +3 -1
- package/dist/device-login.js +20 -5
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @gheima/cli
|
|
2
2
|
|
|
3
|
+
## 0.9.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ff3385e: A sign-in that can no longer succeed now reports a stable error code under `--json`: `login_expired` (expired or already used) or `login_denied`, instead of the generic `error`, so a script or an agent knows to start a new one with `gheima login --no-wait`.
|
|
8
|
+
|
|
9
|
+
## 0.9.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 2c58022: `gheima login --resume` still pending (exit 7) now says to tell the person and run it again once they have approved, instead of "run it again to keep waiting", which led agents to poll until the code expired.
|
|
14
|
+
|
|
3
15
|
## 0.9.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/cli.js
CHANGED
|
@@ -19,7 +19,7 @@ import { findLink, toDotenv, writeLink } from './link.js';
|
|
|
19
19
|
import { listSourceFiles, packSource } from './pack.js';
|
|
20
20
|
import { defaultServiceName, gitRemote, gitSubdir } from './git-remote.js';
|
|
21
21
|
import { AGENTS_FILE, agentsSection, upsertAgentsMd } from './agents-md.js';
|
|
22
|
-
import { clearPendingLogin, defaultClientName, loadPendingLogin, LoginStillPending, openBrowser, pollForApproval, savePendingLogin, startDeviceLogin, } from './device-login.js';
|
|
22
|
+
import { clearPendingLogin, defaultClientName, loadPendingLogin, LoginEnded, LoginStillPending, openBrowser, pollForApproval, savePendingLogin, startDeviceLogin, } from './device-login.js';
|
|
23
23
|
const program = new Command();
|
|
24
24
|
program
|
|
25
25
|
.name('gheima')
|
|
@@ -85,6 +85,8 @@ function localErrorCode(err) {
|
|
|
85
85
|
return 'unauthenticated';
|
|
86
86
|
if (err instanceof LoginStillPending)
|
|
87
87
|
return 'login_pending';
|
|
88
|
+
if (err instanceof LoginEnded)
|
|
89
|
+
return err.code;
|
|
88
90
|
return 'error';
|
|
89
91
|
}
|
|
90
92
|
/**
|
package/dist/device-login.js
CHANGED
|
@@ -83,8 +83,23 @@ export async function startDeviceLogin(baseUrl, clientName) {
|
|
|
83
83
|
export class LoginStillPending extends Error {
|
|
84
84
|
name = 'LoginStillPending';
|
|
85
85
|
constructor() {
|
|
86
|
-
super(
|
|
87
|
-
|
|
86
|
+
super(
|
|
87
|
+
// An agent reads this at the exact moment it decides whether to poll again: it says to hand
|
|
88
|
+
// back to the person, as the agent recipe does, not to loop until the code expires.
|
|
89
|
+
'Still waiting for the person to approve the sign-in in the browser. Tell them, and run ' +
|
|
90
|
+
'`gheima login --resume` once they say they have approved.');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A sign-in that can no longer succeed: it expired, was already used, or was denied. Carries a
|
|
95
|
+
* stable `code` so a script or an agent knows to start a new one with `login --no-wait`.
|
|
96
|
+
*/
|
|
97
|
+
export class LoginEnded extends Error {
|
|
98
|
+
code;
|
|
99
|
+
name = 'LoginEnded';
|
|
100
|
+
constructor(message, code) {
|
|
101
|
+
super(message);
|
|
102
|
+
this.code = code;
|
|
88
103
|
}
|
|
89
104
|
}
|
|
90
105
|
const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -103,7 +118,7 @@ export async function pollForApproval(baseUrl, start, opts = {}) {
|
|
|
103
118
|
let intervalMs = Math.max(1, start.interval) * 1000;
|
|
104
119
|
for (;;) {
|
|
105
120
|
if (now() >= deadline) {
|
|
106
|
-
throw new
|
|
121
|
+
throw new LoginEnded(`This sign-in expired before it was approved. ${restart}`, 'login_expired');
|
|
107
122
|
}
|
|
108
123
|
if (opts.giveUpAt !== undefined && now() >= opts.giveUpAt)
|
|
109
124
|
throw new LoginStillPending();
|
|
@@ -124,9 +139,9 @@ export async function pollForApproval(baseUrl, start, opts = {}) {
|
|
|
124
139
|
opts.onSlowDown?.(Math.round(intervalMs / 1000));
|
|
125
140
|
break;
|
|
126
141
|
case 'access_denied':
|
|
127
|
-
throw new
|
|
142
|
+
throw new LoginEnded(`The sign-in was denied in the dashboard. ${restart}`, 'login_denied');
|
|
128
143
|
case 'expired_token':
|
|
129
|
-
throw new
|
|
144
|
+
throw new LoginEnded(`This sign-in expired or was already used. ${restart}`, 'login_expired');
|
|
130
145
|
default:
|
|
131
146
|
throw new Error(body.error?.message ?? `Sign-in failed (HTTP ${res.status}). ${restart}`);
|
|
132
147
|
}
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// GENERATED by scripts/write-version.mjs from package.json. Do not edit.
|
|
2
|
-
export const VERSION = '0.9.
|
|
2
|
+
export const VERSION = '0.9.2';
|