@kenkaiiii/ggcoder 4.3.243 → 4.5.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/cli/auth.d.ts.map +1 -1
- package/dist/cli/auth.js +17 -2
- package/dist/cli/auth.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +3 -14
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -17
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +14 -10
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +1 -40
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -200
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/auto-update.d.ts +4 -26
- package/dist/core/auto-update.d.ts.map +1 -1
- package/dist/core/auto-update.js +12 -237
- package/dist/core/auto-update.js.map +1 -1
- package/dist/core/claude-code-version.d.ts +1 -9
- package/dist/core/claude-code-version.d.ts.map +1 -1
- package/dist/core/claude-code-version.js +2 -105
- package/dist/core/claude-code-version.js.map +1 -1
- package/dist/core/compaction/compactor.d.ts.map +1 -1
- package/dist/core/compaction/compactor.js +4 -0
- package/dist/core/compaction/compactor.js.map +1 -1
- package/dist/core/file-lock.d.ts +1 -5
- package/dist/core/file-lock.d.ts.map +1 -1
- package/dist/core/file-lock.js +2 -75
- package/dist/core/file-lock.js.map +1 -1
- package/dist/core/logger.d.ts +4 -17
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +21 -110
- package/dist/core/logger.js.map +1 -1
- package/dist/core/model-registry.d.ts +1 -54
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +4 -296
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/oauth/anthropic.d.ts +1 -3
- package/dist/core/oauth/anthropic.d.ts.map +1 -1
- package/dist/core/oauth/anthropic.js +2 -96
- package/dist/core/oauth/anthropic.js.map +1 -1
- package/dist/core/oauth/gemini.d.ts +1 -3
- package/dist/core/oauth/gemini.d.ts.map +1 -1
- package/dist/core/oauth/gemini.js +2 -379
- package/dist/core/oauth/gemini.js.map +1 -1
- package/dist/core/oauth/kimi.d.ts +2 -0
- package/dist/core/oauth/kimi.d.ts.map +1 -0
- package/dist/core/oauth/kimi.js +3 -0
- package/dist/core/oauth/kimi.js.map +1 -0
- package/dist/core/oauth/openai.d.ts +1 -3
- package/dist/core/oauth/openai.d.ts.map +1 -1
- package/dist/core/oauth/openai.js +2 -187
- package/dist/core/oauth/openai.js.map +1 -1
- package/dist/core/oauth/pkce.d.ts +1 -4
- package/dist/core/oauth/pkce.d.ts.map +1 -1
- package/dist/core/oauth/pkce.js +2 -16
- package/dist/core/oauth/pkce.js.map +1 -1
- package/dist/core/oauth/types.d.ts +1 -13
- package/dist/core/oauth/types.d.ts.map +1 -1
- package/dist/core/telegram.d.ts +1 -112
- package/dist/core/telegram.d.ts.map +1 -1
- package/dist/core/telegram.js +2 -251
- package/dist/core/telegram.js.map +1 -1
- package/dist/core/thinking-level.d.ts +1 -4
- package/dist/core/thinking-level.d.ts.map +1 -1
- package/dist/core/thinking-level.js +3 -58
- package/dist/core/thinking-level.js.map +1 -1
- package/dist/core/voice-transcriber.d.ts +1 -32
- package/dist/core/voice-transcriber.d.ts.map +1 -1
- package/dist/core/voice-transcriber.js +3 -112
- package/dist/core/voice-transcriber.js.map +1 -1
- package/dist/interactive.d.ts.map +1 -1
- package/dist/interactive.js +5 -1
- package/dist/interactive.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +7 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/read.d.ts +6 -1
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +70 -4
- package/dist/tools/read.js.map +1 -1
- package/dist/ui/hooks/useAgentLoop.d.ts.map +1 -1
- package/dist/ui/hooks/useAgentLoop.js +7 -0
- package/dist/ui/hooks/useAgentLoop.js.map +1 -1
- package/dist/ui/login.js +1 -1
- package/dist/ui/login.js.map +1 -1
- package/dist/ui/prompt-routing.d.ts.map +1 -1
- package/dist/ui/prompt-routing.js +42 -18
- package/dist/ui/prompt-routing.js.map +1 -1
- package/dist/ui/slash-command-images.test.js +30 -8
- package/dist/ui/slash-command-images.test.js.map +1 -1
- package/dist/utils/image.d.ts +25 -2
- package/dist/utils/image.d.ts.map +1 -1
- package/dist/utils/image.js +116 -23
- package/dist/utils/image.js.map +1 -1
- package/package.json +5 -4
- package/dist/core/model-registry.test.d.ts +0 -2
- package/dist/core/model-registry.test.d.ts.map +0 -1
- package/dist/core/model-registry.test.js +0 -95
- package/dist/core/model-registry.test.js.map +0 -1
- package/dist/core/oauth/gemini.test.d.ts +0 -2
- package/dist/core/oauth/gemini.test.d.ts.map +0 -1
- package/dist/core/oauth/gemini.test.js +0 -154
- package/dist/core/oauth/gemini.test.js.map +0 -1
- package/dist/core/thinking-level.test.d.ts +0 -2
- package/dist/core/thinking-level.test.d.ts.map +0 -1
- package/dist/core/thinking-level.test.js +0 -38
- package/dist/core/thinking-level.test.js.map +0 -1
- package/dist/core/voice-transcriber.test.d.ts +0 -2
- package/dist/core/voice-transcriber.test.d.ts.map +0 -1
- package/dist/core/voice-transcriber.test.js +0 -88
- package/dist/core/voice-transcriber.test.js.map +0 -1
|
@@ -1,41 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare class AuthStorage {
|
|
3
|
-
private data;
|
|
4
|
-
private filePath;
|
|
5
|
-
private loaded;
|
|
6
|
-
/** Per-provider lock to serialize concurrent refresh calls. */
|
|
7
|
-
private refreshLocks;
|
|
8
|
-
constructor(filePath?: string);
|
|
9
|
-
/** Path to the on-disk auth file. Useful for status output. */
|
|
10
|
-
get path(): string;
|
|
11
|
-
/** List provider keys with stored credentials. */
|
|
12
|
-
listProviders(): Promise<string[]>;
|
|
13
|
-
/** True if credentials exist for `provider`. */
|
|
14
|
-
hasCredentials(provider: string): Promise<boolean>;
|
|
15
|
-
load(): Promise<void>;
|
|
16
|
-
private ensureLoaded;
|
|
17
|
-
getCredentials(provider: string): Promise<OAuthCredentials | undefined>;
|
|
18
|
-
setCredentials(provider: string, creds: OAuthCredentials): Promise<void>;
|
|
19
|
-
clearCredentials(provider: string): Promise<void>;
|
|
20
|
-
clearAll(): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Returns valid credentials, auto-refreshing if expired.
|
|
23
|
-
* If `forceRefresh` is true, refreshes even if the token hasn't expired
|
|
24
|
-
* (useful when the provider rejects a token with 401 before its stored expiry).
|
|
25
|
-
* Throws if not logged in.
|
|
26
|
-
*/
|
|
27
|
-
resolveCredentials(provider: string, opts?: {
|
|
28
|
-
forceRefresh?: boolean;
|
|
29
|
-
}): Promise<OAuthCredentials>;
|
|
30
|
-
/**
|
|
31
|
-
* Returns a valid access token, auto-refreshing if expired.
|
|
32
|
-
* Throws if not logged in.
|
|
33
|
-
*/
|
|
34
|
-
resolveToken(provider: string): Promise<string>;
|
|
35
|
-
private save;
|
|
36
|
-
}
|
|
37
|
-
export declare class NotLoggedInError extends Error {
|
|
38
|
-
provider: string;
|
|
39
|
-
constructor(provider: string);
|
|
40
|
-
}
|
|
1
|
+
export { AuthStorage, NotLoggedInError } from "@kenkaiiii/gg-core";
|
|
41
2
|
//# sourceMappingURL=auth-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-storage.d.ts","sourceRoot":"","sources":["../../src/core/auth-storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth-storage.d.ts","sourceRoot":"","sources":["../../src/core/auth-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,201 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { refreshAnthropicToken } from "./oauth/anthropic.js";
|
|
5
|
-
import { refreshOpenAIToken } from "./oauth/openai.js";
|
|
6
|
-
import { refreshGeminiToken } from "./oauth/gemini.js";
|
|
7
|
-
import { withFileLock } from "./file-lock.js";
|
|
8
|
-
import { log } from "./logger.js";
|
|
9
|
-
export class AuthStorage {
|
|
10
|
-
data = {};
|
|
11
|
-
filePath;
|
|
12
|
-
loaded = false;
|
|
13
|
-
/** Per-provider lock to serialize concurrent refresh calls. */
|
|
14
|
-
refreshLocks = new Map();
|
|
15
|
-
constructor(filePath) {
|
|
16
|
-
this.filePath = filePath ?? getAppPaths().authFile;
|
|
17
|
-
}
|
|
18
|
-
/** Path to the on-disk auth file. Useful for status output. */
|
|
19
|
-
get path() {
|
|
20
|
-
return this.filePath;
|
|
21
|
-
}
|
|
22
|
-
/** List provider keys with stored credentials. */
|
|
23
|
-
async listProviders() {
|
|
24
|
-
await this.ensureLoaded();
|
|
25
|
-
return Object.keys(this.data);
|
|
26
|
-
}
|
|
27
|
-
/** True if credentials exist for `provider`. */
|
|
28
|
-
async hasCredentials(provider) {
|
|
29
|
-
await this.ensureLoaded();
|
|
30
|
-
return Boolean(this.data[provider]);
|
|
31
|
-
}
|
|
32
|
-
async load() {
|
|
33
|
-
await withFileLock(this.filePath, async () => {
|
|
34
|
-
try {
|
|
35
|
-
const content = await fs.readFile(this.filePath, "utf-8");
|
|
36
|
-
this.data = JSON.parse(content);
|
|
37
|
-
log("INFO", "auth", `Loaded credentials from ${this.filePath}`, {
|
|
38
|
-
providers: Object.keys(this.data).join(",") || "(none)",
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
this.data = {};
|
|
43
|
-
const code = err.code;
|
|
44
|
-
if (code === "ENOENT") {
|
|
45
|
-
log("INFO", "auth", `No auth file found at ${this.filePath} (first run)`);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
log("ERROR", "auth", `Failed to load auth file: ${err instanceof Error ? err.message : String(err)}`, { path: this.filePath, code: code ?? "unknown" });
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
this.loaded = true;
|
|
53
|
-
}
|
|
54
|
-
async ensureLoaded() {
|
|
55
|
-
if (!this.loaded)
|
|
56
|
-
await this.load();
|
|
57
|
-
}
|
|
58
|
-
async getCredentials(provider) {
|
|
59
|
-
await this.ensureLoaded();
|
|
60
|
-
return this.data[provider];
|
|
61
|
-
}
|
|
62
|
-
async setCredentials(provider, creds) {
|
|
63
|
-
await this.ensureLoaded();
|
|
64
|
-
this.data[provider] = creds;
|
|
65
|
-
await this.save();
|
|
66
|
-
}
|
|
67
|
-
async clearCredentials(provider) {
|
|
68
|
-
await this.ensureLoaded();
|
|
69
|
-
delete this.data[provider];
|
|
70
|
-
await this.save();
|
|
71
|
-
}
|
|
72
|
-
async clearAll() {
|
|
73
|
-
this.data = {};
|
|
74
|
-
await this.save();
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Returns valid credentials, auto-refreshing if expired.
|
|
78
|
-
* If `forceRefresh` is true, refreshes even if the token hasn't expired
|
|
79
|
-
* (useful when the provider rejects a token with 401 before its stored expiry).
|
|
80
|
-
* Throws if not logged in.
|
|
81
|
-
*/
|
|
82
|
-
async resolveCredentials(provider, opts) {
|
|
83
|
-
await this.ensureLoaded();
|
|
84
|
-
const creds = this.data[provider];
|
|
85
|
-
if (!creds) {
|
|
86
|
-
throw new NotLoggedInError(provider);
|
|
87
|
-
}
|
|
88
|
-
// GLM and Moonshot use static API keys — no refresh needed
|
|
89
|
-
if (provider === "glm" ||
|
|
90
|
-
provider === "moonshot" ||
|
|
91
|
-
provider === "xiaomi" ||
|
|
92
|
-
provider === "minimax" ||
|
|
93
|
-
provider === "deepseek" ||
|
|
94
|
-
provider === "openrouter") {
|
|
95
|
-
return creds;
|
|
96
|
-
}
|
|
97
|
-
// Return if not expired and not force-refreshing
|
|
98
|
-
if (!opts?.forceRefresh && Date.now() < creds.expiresAt) {
|
|
99
|
-
return creds;
|
|
100
|
-
}
|
|
101
|
-
// Serialize concurrent refresh calls per provider to avoid races
|
|
102
|
-
const existing = this.refreshLocks.get(provider);
|
|
103
|
-
if (existing)
|
|
104
|
-
return existing;
|
|
105
|
-
const refreshPromise = withFileLock(this.filePath, async () => {
|
|
106
|
-
// Re-read from disk in case another process refreshed while we waited for the lock
|
|
107
|
-
try {
|
|
108
|
-
const content = await fs.readFile(this.filePath, "utf-8");
|
|
109
|
-
const freshData = JSON.parse(content);
|
|
110
|
-
const freshCreds = freshData[provider];
|
|
111
|
-
if (freshCreds && !opts?.forceRefresh && Date.now() < freshCreds.expiresAt) {
|
|
112
|
-
// Another process already refreshed — use their token
|
|
113
|
-
this.data[provider] = freshCreds;
|
|
114
|
-
return freshCreds;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
// Fall through to refresh
|
|
119
|
-
}
|
|
120
|
-
const refreshFn = provider === "anthropic"
|
|
121
|
-
? refreshAnthropicToken
|
|
122
|
-
: provider === "gemini"
|
|
123
|
-
? refreshGeminiToken
|
|
124
|
-
: refreshOpenAIToken;
|
|
125
|
-
let refreshed;
|
|
126
|
-
try {
|
|
127
|
-
refreshed = await refreshFn(creds.refreshToken);
|
|
128
|
-
}
|
|
129
|
-
catch (err) {
|
|
130
|
-
// Refresh token revoked / expired / invalid → the stored creds are
|
|
131
|
-
// unusable. Wipe them so the next launch surfaces a clean
|
|
132
|
-
// NotLoggedInError instead of hitting the same dead refresh path
|
|
133
|
-
// every time. The user must re-login.
|
|
134
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
135
|
-
const isAuthFailure = /\((401|400)\)/.test(msg) ||
|
|
136
|
-
/invalid_grant|invalid_token|invalid.*refresh/i.test(msg) ||
|
|
137
|
-
/unauthorized/i.test(msg);
|
|
138
|
-
if (isAuthFailure) {
|
|
139
|
-
delete this.data[provider];
|
|
140
|
-
await atomicWriteFile(this.filePath, JSON.stringify(this.data, null, 2));
|
|
141
|
-
throw new NotLoggedInError(provider);
|
|
142
|
-
}
|
|
143
|
-
throw err;
|
|
144
|
-
}
|
|
145
|
-
if (!refreshed.accountId && creds.accountId) {
|
|
146
|
-
refreshed.accountId = creds.accountId;
|
|
147
|
-
}
|
|
148
|
-
if (!refreshed.projectId && creds.projectId) {
|
|
149
|
-
refreshed.projectId = creds.projectId;
|
|
150
|
-
}
|
|
151
|
-
this.data[provider] = refreshed;
|
|
152
|
-
// Write atomically (we already hold the file lock)
|
|
153
|
-
await atomicWriteFile(this.filePath, JSON.stringify(this.data, null, 2));
|
|
154
|
-
return refreshed;
|
|
155
|
-
});
|
|
156
|
-
this.refreshLocks.set(provider, refreshPromise);
|
|
157
|
-
try {
|
|
158
|
-
return await refreshPromise;
|
|
159
|
-
}
|
|
160
|
-
finally {
|
|
161
|
-
this.refreshLocks.delete(provider);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Returns a valid access token, auto-refreshing if expired.
|
|
166
|
-
* Throws if not logged in.
|
|
167
|
-
*/
|
|
168
|
-
async resolveToken(provider) {
|
|
169
|
-
const creds = await this.resolveCredentials(provider);
|
|
170
|
-
return creds.accessToken;
|
|
171
|
-
}
|
|
172
|
-
async save() {
|
|
173
|
-
await withFileLock(this.filePath, async () => {
|
|
174
|
-
await atomicWriteFile(this.filePath, JSON.stringify(this.data, null, 2));
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Atomic file write using temp file + rename pattern.
|
|
180
|
-
* Prevents partial/corrupt data if the process crashes mid-write.
|
|
181
|
-
*/
|
|
182
|
-
async function atomicWriteFile(filePath, content) {
|
|
183
|
-
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.${crypto.randomUUID().slice(0, 8)}.tmp`;
|
|
184
|
-
try {
|
|
185
|
-
await fs.writeFile(tmpPath, content, { encoding: "utf-8", mode: 0o600 });
|
|
186
|
-
await fs.rename(tmpPath, filePath);
|
|
187
|
-
}
|
|
188
|
-
catch (err) {
|
|
189
|
-
await fs.unlink(tmpPath).catch(() => { });
|
|
190
|
-
throw err;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
export class NotLoggedInError extends Error {
|
|
194
|
-
provider;
|
|
195
|
-
constructor(provider) {
|
|
196
|
-
super(`Not logged in to ${provider}. Run "ggcoder login" to authenticate.`);
|
|
197
|
-
this.name = "NotLoggedInError";
|
|
198
|
-
this.provider = provider;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
1
|
+
// Moved to @kenkaiiii/gg-core. Shim keeps relative imports + the
|
|
2
|
+
// `@kenkaiiii/ggcoder/auth` subpath export resolving unchanged.
|
|
3
|
+
export { AuthStorage, NotLoggedInError } from "@kenkaiiii/gg-core";
|
|
201
4
|
//# sourceMappingURL=auth-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-storage.js","sourceRoot":"","sources":["../../src/core/auth-storage.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"auth-storage.js","sourceRoot":"","sources":["../../src/core/auth-storage.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,gEAAgE;AAChE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Phase 1 (instant): If a previous background check found a newer version,
|
|
5
|
-
* kick off a background update now. Non-blocking.
|
|
6
|
-
*
|
|
7
|
-
* Phase 2 (async): Fire off a background version check for the *next* startup.
|
|
8
|
-
*
|
|
9
|
-
* Returns a message to display, or null.
|
|
10
|
-
*/
|
|
11
|
-
export declare function checkAndAutoUpdate(currentVersion: string): string | null;
|
|
12
|
-
/**
|
|
13
|
-
* Read the current state file and report whether a newer version has been
|
|
14
|
-
* downloaded / is pending install. Used by the TUI to show a persistent
|
|
15
|
-
* "update ready" indicator in the status row.
|
|
16
|
-
*/
|
|
17
|
-
export declare function getPendingUpdate(currentVersion: string): {
|
|
1
|
+
export declare const checkAndAutoUpdate: (currentVersion: string) => string | null;
|
|
2
|
+
export declare const getPendingUpdate: (currentVersion: string) => {
|
|
18
3
|
latestVersion: string;
|
|
19
4
|
} | null;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* Checks every hour. If an update is found, calls `onUpdate` with a message.
|
|
23
|
-
*/
|
|
24
|
-
export declare function startPeriodicUpdateCheck(currentVersion: string, onUpdate: (message: string) => void): void;
|
|
25
|
-
/**
|
|
26
|
-
* Stop periodic update checks.
|
|
27
|
-
*/
|
|
28
|
-
export declare function stopPeriodicUpdateCheck(): void;
|
|
5
|
+
export declare const startPeriodicUpdateCheck: (currentVersion: string, onUpdate: (message: string) => void) => void;
|
|
6
|
+
export declare const stopPeriodicUpdateCheck: () => void;
|
|
29
7
|
//# sourceMappingURL=auto-update.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-update.d.ts","sourceRoot":"","sources":["../../src/core/auto-update.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-update.d.ts","sourceRoot":"","sources":["../../src/core/auto-update.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,kBAAkB,2CAA6B,CAAC;AAC7D,eAAO,MAAM,gBAAgB;;QAA2B,CAAC;AACzD,eAAO,MAAM,wBAAwB,uEAAmC,CAAC;AACzE,eAAO,MAAM,uBAAuB,YAAkC,CAAC"}
|
package/dist/core/auto-update.js
CHANGED
|
@@ -1,240 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// The update engine now lives in @kenkaiiii/gg-core. This module pins it to
|
|
2
|
+
// ggcoder's npm package + state file, keeping the "ggcoder"-branded surface and
|
|
3
|
+
// the same exported function names so consumers/tests are unchanged.
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import os from "node:os";
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
PackageManager["UNKNOWN"] = "unknown";
|
|
15
|
-
})(PackageManager || (PackageManager = {}));
|
|
16
|
-
function getStateFilePath() {
|
|
17
|
-
return path.join(os.homedir(), ".gg", "update-state.json");
|
|
18
|
-
}
|
|
19
|
-
function readState() {
|
|
20
|
-
try {
|
|
21
|
-
const raw = fs.readFileSync(getStateFilePath(), "utf-8");
|
|
22
|
-
return JSON.parse(raw);
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function writeState(state) {
|
|
29
|
-
try {
|
|
30
|
-
const dir = path.dirname(getStateFilePath());
|
|
31
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
32
|
-
fs.writeFileSync(getStateFilePath(), JSON.stringify(state));
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// Non-fatal
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function compareVersions(a, b) {
|
|
39
|
-
const pa = a.split(".").map(Number);
|
|
40
|
-
const pb = b.split(".").map(Number);
|
|
41
|
-
for (let i = 0; i < 3; i++) {
|
|
42
|
-
const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
43
|
-
if (diff !== 0)
|
|
44
|
-
return diff;
|
|
45
|
-
}
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
|
48
|
-
function detectInstallInfo() {
|
|
49
|
-
const scriptPath = (process.argv[1] ?? "").replace(/\\/g, "/");
|
|
50
|
-
// npx — skip (ephemeral)
|
|
51
|
-
if (scriptPath.includes("/_npx/")) {
|
|
52
|
-
return { packageManager: PackageManager.UNKNOWN, updateCommand: null };
|
|
53
|
-
}
|
|
54
|
-
// pnpm global
|
|
55
|
-
if (scriptPath.includes("/.pnpm") || scriptPath.includes("/pnpm/global")) {
|
|
56
|
-
return {
|
|
57
|
-
packageManager: PackageManager.PNPM,
|
|
58
|
-
updateCommand: `pnpm add -g ${PACKAGE_NAME}@latest`,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
// yarn global
|
|
62
|
-
if (scriptPath.includes("/.yarn/") || scriptPath.includes("/yarn/global")) {
|
|
63
|
-
return {
|
|
64
|
-
packageManager: PackageManager.YARN,
|
|
65
|
-
updateCommand: `yarn global add ${PACKAGE_NAME}@latest`,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
// npm global (default)
|
|
69
|
-
return {
|
|
70
|
-
packageManager: PackageManager.NPM,
|
|
71
|
-
updateCommand: `npm install -g ${PACKAGE_NAME}@latest`,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Fetch latest version from npm registry asynchronously.
|
|
76
|
-
*/
|
|
77
|
-
async function fetchLatestVersion() {
|
|
78
|
-
try {
|
|
79
|
-
const controller = new AbortController();
|
|
80
|
-
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
81
|
-
const response = await fetch(REGISTRY_URL, { signal: controller.signal });
|
|
82
|
-
clearTimeout(timeout);
|
|
83
|
-
const data = (await response.json());
|
|
84
|
-
const version = data.version?.trim();
|
|
85
|
-
return version && /^\d+\.\d+\.\d+/.test(version) ? version : null;
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Perform the update in a detached background process so it doesn't block
|
|
93
|
-
* or interfere with the current CLI session. The update takes effect on
|
|
94
|
-
* the next launch.
|
|
95
|
-
*/
|
|
96
|
-
function performUpdateInBackground(command) {
|
|
97
|
-
try {
|
|
98
|
-
const parts = command.split(" ");
|
|
99
|
-
const child = spawn(parts[0], parts.slice(1), {
|
|
100
|
-
detached: true,
|
|
101
|
-
stdio: "ignore",
|
|
102
|
-
env: { ...process.env, npm_config_loglevel: "silent" },
|
|
103
|
-
});
|
|
104
|
-
child.unref();
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
// Non-fatal — will retry next startup
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Check for updates at CLI startup. Two-phase approach:
|
|
112
|
-
*
|
|
113
|
-
* Phase 1 (instant): If a previous background check found a newer version,
|
|
114
|
-
* kick off a background update now. Non-blocking.
|
|
115
|
-
*
|
|
116
|
-
* Phase 2 (async): Fire off a background version check for the *next* startup.
|
|
117
|
-
*
|
|
118
|
-
* Returns a message to display, or null.
|
|
119
|
-
*/
|
|
120
|
-
export function checkAndAutoUpdate(currentVersion) {
|
|
121
|
-
try {
|
|
122
|
-
const state = readState();
|
|
123
|
-
let message = null;
|
|
124
|
-
// Phase 1: Apply pending update from previous check
|
|
125
|
-
if (state?.updatePending && state.latestVersion) {
|
|
126
|
-
if (compareVersions(state.latestVersion, currentVersion) > 0) {
|
|
127
|
-
const info = detectInstallInfo();
|
|
128
|
-
if (info.updateCommand) {
|
|
129
|
-
// Run update in background — takes effect next launch
|
|
130
|
-
performUpdateInBackground(info.updateCommand);
|
|
131
|
-
message = `Ken just shipped ${state.latestVersion}! Installing in the background — takes effect next launch.`;
|
|
132
|
-
writeState({
|
|
133
|
-
...state,
|
|
134
|
-
lastCheckedAt: Date.now(),
|
|
135
|
-
updatePending: false,
|
|
136
|
-
lastUpdateAttempt: Date.now(),
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
// Already on latest (user may have updated manually)
|
|
142
|
-
writeState({ ...state, updatePending: false });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
// Phase 2: Schedule background check for next startup
|
|
146
|
-
const shouldCheck = !state || Date.now() - state.lastCheckedAt > CHECK_INTERVAL_MS;
|
|
147
|
-
if (shouldCheck) {
|
|
148
|
-
scheduleBackgroundCheck(currentVersion);
|
|
149
|
-
}
|
|
150
|
-
return message;
|
|
151
|
-
}
|
|
152
|
-
catch {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Read the current state file and report whether a newer version has been
|
|
158
|
-
* downloaded / is pending install. Used by the TUI to show a persistent
|
|
159
|
-
* "update ready" indicator in the status row.
|
|
160
|
-
*/
|
|
161
|
-
export function getPendingUpdate(currentVersion) {
|
|
162
|
-
try {
|
|
163
|
-
const state = readState();
|
|
164
|
-
if (!state?.latestVersion)
|
|
165
|
-
return null;
|
|
166
|
-
if (compareVersions(state.latestVersion, currentVersion) <= 0)
|
|
167
|
-
return null;
|
|
168
|
-
return { latestVersion: state.latestVersion };
|
|
169
|
-
}
|
|
170
|
-
catch {
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Fire-and-forget async version check. Updates the state file so the
|
|
176
|
-
* next startup knows whether an update is available.
|
|
177
|
-
*/
|
|
178
|
-
function scheduleBackgroundCheck(currentVersion) {
|
|
179
|
-
fetchLatestVersion()
|
|
180
|
-
.then((latestVersion) => {
|
|
181
|
-
const newState = {
|
|
182
|
-
lastCheckedAt: Date.now(),
|
|
183
|
-
latestVersion: latestVersion ?? undefined,
|
|
184
|
-
updatePending: false,
|
|
185
|
-
};
|
|
186
|
-
if (latestVersion && compareVersions(latestVersion, currentVersion) > 0) {
|
|
187
|
-
newState.updatePending = true;
|
|
188
|
-
}
|
|
189
|
-
writeState(newState);
|
|
190
|
-
})
|
|
191
|
-
.catch(() => {
|
|
192
|
-
// Non-fatal — will retry next time
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
// ── In-session periodic check ──────────────────────────────────────────
|
|
196
|
-
let periodicTimer = null;
|
|
197
|
-
/**
|
|
198
|
-
* Start periodic update checks during a long-running session.
|
|
199
|
-
* Checks every hour. If an update is found, calls `onUpdate` with a message.
|
|
200
|
-
*/
|
|
201
|
-
export function startPeriodicUpdateCheck(currentVersion, onUpdate) {
|
|
202
|
-
if (periodicTimer)
|
|
203
|
-
return; // Already running
|
|
204
|
-
periodicTimer = setInterval(() => {
|
|
205
|
-
fetchLatestVersion()
|
|
206
|
-
.then((latestVersion) => {
|
|
207
|
-
if (!latestVersion)
|
|
208
|
-
return;
|
|
209
|
-
if (compareVersions(latestVersion, currentVersion) <= 0)
|
|
210
|
-
return;
|
|
211
|
-
const info = detectInstallInfo();
|
|
212
|
-
if (!info.updateCommand)
|
|
213
|
-
return;
|
|
214
|
-
// Mark pending for next startup
|
|
215
|
-
writeState({
|
|
216
|
-
lastCheckedAt: Date.now(),
|
|
217
|
-
latestVersion,
|
|
218
|
-
updatePending: true,
|
|
219
|
-
});
|
|
220
|
-
onUpdate(`Ken just pushed a fresh update — ${currentVersion} → ${latestVersion}! I'll grab it on next launch (or run ${info.updateCommand} if you can't wait).`);
|
|
221
|
-
// Stop checking once we've notified
|
|
222
|
-
stopPeriodicUpdateCheck();
|
|
223
|
-
})
|
|
224
|
-
.catch(() => {
|
|
225
|
-
// Non-fatal
|
|
226
|
-
});
|
|
227
|
-
}, CHECK_INTERVAL_MS);
|
|
228
|
-
// Don't keep the process alive just for update checks
|
|
229
|
-
periodicTimer.unref();
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Stop periodic update checks.
|
|
233
|
-
*/
|
|
234
|
-
export function stopPeriodicUpdateCheck() {
|
|
235
|
-
if (periodicTimer) {
|
|
236
|
-
clearInterval(periodicTimer);
|
|
237
|
-
periodicTimer = null;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
6
|
+
import { createAutoUpdater } from "@kenkaiiii/gg-core";
|
|
7
|
+
const updater = createAutoUpdater({
|
|
8
|
+
packageName: "@kenkaiiii/ggcoder",
|
|
9
|
+
stateFilePath: () => path.join(os.homedir(), ".gg", "update-state.json"),
|
|
10
|
+
});
|
|
11
|
+
export const checkAndAutoUpdate = updater.checkAndAutoUpdate;
|
|
12
|
+
export const getPendingUpdate = updater.getPendingUpdate;
|
|
13
|
+
export const startPeriodicUpdateCheck = updater.startPeriodicUpdateCheck;
|
|
14
|
+
export const stopPeriodicUpdateCheck = updater.stopPeriodicUpdateCheck;
|
|
240
15
|
//# sourceMappingURL=auto-update.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-update.js","sourceRoot":"","sources":["../../src/core/auto-update.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"auto-update.js","sourceRoot":"","sources":["../../src/core/auto-update.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,gFAAgF;AAChF,qEAAqE;AACrE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,OAAO,GAAG,iBAAiB,CAAC;IAChC,WAAW,EAAE,oBAAoB;IACjC,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,mBAAmB,CAAC;CACzE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;AACzD,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC;AACzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC"}
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Resolve the current Claude Code release version for spoofing the claude-cli
|
|
3
|
-
* User-Agent on OAuth and inference requests. Cached in-memory for the process
|
|
4
|
-
* lifetime and on disk for 24h. Falls back to a hardcoded constant if the npm
|
|
5
|
-
* registry is unreachable and no cache exists.
|
|
6
|
-
*/
|
|
7
|
-
export declare function getClaudeCodeVersion(): Promise<string>;
|
|
8
|
-
/** Build the User-Agent string Anthropic's OAuth + inference edges expect. */
|
|
9
|
-
export declare function getClaudeCliUserAgent(): Promise<string>;
|
|
1
|
+
export { getClaudeCodeVersion, getClaudeCliUserAgent } from "@kenkaiiii/gg-core";
|
|
10
2
|
//# sourceMappingURL=claude-code-version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code-version.d.ts","sourceRoot":"","sources":["../../src/core/claude-code-version.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"claude-code-version.d.ts","sourceRoot":"","sources":["../../src/core/claude-code-version.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
|