@kenkaiiii/ggcoder 4.3.242 → 4.4.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/shared.d.ts.map +1 -1
- package/dist/cli/shared.js +27 -5
- package/dist/cli/shared.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/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/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/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/ui/App.d.ts.map +1 -1
- package/dist/ui/App.js +27 -5
- package/dist/ui/App.js.map +1 -1
- package/dist/utils/plan-steps.d.ts +18 -0
- package/dist/utils/plan-steps.d.ts.map +1 -1
- package/dist/utils/plan-steps.js +32 -0
- package/dist/utils/plan-steps.js.map +1 -1
- package/dist/utils/plan-steps.test.js +57 -1
- package/dist/utils/plan-steps.test.js.map +1 -1
- package/package.json +4 -3
- 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
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"}
|
|
@@ -1,106 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { getAppPaths } from "../config.js";
|
|
4
|
-
import { log } from "./logger.js";
|
|
5
|
-
// Anthropic's OAuth edge rejects requests whose claude-cli UA version lags too
|
|
6
|
-
// far behind the actual Claude Code release. Resolve dynamically from the npm
|
|
7
|
-
// registry so we never ship a stale-version time bomb.
|
|
8
|
-
const NPM_LATEST_URL = "https://registry.npmjs.org/@anthropic-ai/claude-code/latest";
|
|
9
|
-
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
10
|
-
const FETCH_TIMEOUT_MS = 3000;
|
|
11
|
-
// Last known good version at publish time. Used only when the npm fetch fails
|
|
12
|
-
// and no on-disk cache exists (e.g. first run on an offline machine). Keep
|
|
13
|
-
// reasonably current — bump on each ggcoder release.
|
|
14
|
-
const FALLBACK_VERSION = "2.1.88";
|
|
15
|
-
let memoryCache = null;
|
|
16
|
-
let inflight = null;
|
|
17
|
-
function cachePath() {
|
|
18
|
-
return path.join(getAppPaths().agentDir, "claude-code-version.json");
|
|
19
|
-
}
|
|
20
|
-
async function readDiskCache() {
|
|
21
|
-
try {
|
|
22
|
-
const raw = await fs.readFile(cachePath(), "utf-8");
|
|
23
|
-
const parsed = JSON.parse(raw);
|
|
24
|
-
if (typeof parsed.version === "string" && typeof parsed.fetchedAt === "number") {
|
|
25
|
-
return parsed;
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function writeDiskCache(data) {
|
|
34
|
-
try {
|
|
35
|
-
await fs.mkdir(getAppPaths().agentDir, { recursive: true, mode: 0o700 });
|
|
36
|
-
await fs.writeFile(cachePath(), JSON.stringify(data), { mode: 0o600 });
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
log("WARN", "claude-code-version", `Failed to write cache: ${err instanceof Error ? err.message : String(err)}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
async function fetchLatest() {
|
|
43
|
-
const controller = new AbortController();
|
|
44
|
-
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
45
|
-
try {
|
|
46
|
-
const response = await fetch(NPM_LATEST_URL, { signal: controller.signal });
|
|
47
|
-
if (!response.ok)
|
|
48
|
-
return null;
|
|
49
|
-
const data = (await response.json());
|
|
50
|
-
if (typeof data.version === "string" && /^\d/.test(data.version)) {
|
|
51
|
-
return data.version;
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
clearTimeout(timer);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Resolve the current Claude Code release version for spoofing the claude-cli
|
|
64
|
-
* User-Agent on OAuth and inference requests. Cached in-memory for the process
|
|
65
|
-
* lifetime and on disk for 24h. Falls back to a hardcoded constant if the npm
|
|
66
|
-
* registry is unreachable and no cache exists.
|
|
67
|
-
*/
|
|
68
|
-
export async function getClaudeCodeVersion() {
|
|
69
|
-
if (memoryCache && Date.now() < memoryCache.expiresAt) {
|
|
70
|
-
return memoryCache.version;
|
|
71
|
-
}
|
|
72
|
-
if (inflight)
|
|
73
|
-
return inflight;
|
|
74
|
-
inflight = (async () => {
|
|
75
|
-
const disk = await readDiskCache();
|
|
76
|
-
const diskFresh = disk && Date.now() - disk.fetchedAt < CACHE_TTL_MS;
|
|
77
|
-
if (disk && diskFresh) {
|
|
78
|
-
memoryCache = { version: disk.version, expiresAt: Date.now() + CACHE_TTL_MS };
|
|
79
|
-
return disk.version;
|
|
80
|
-
}
|
|
81
|
-
const fetched = await fetchLatest();
|
|
82
|
-
if (fetched) {
|
|
83
|
-
await writeDiskCache({ version: fetched, fetchedAt: Date.now() });
|
|
84
|
-
memoryCache = { version: fetched, expiresAt: Date.now() + CACHE_TTL_MS };
|
|
85
|
-
return fetched;
|
|
86
|
-
}
|
|
87
|
-
// npm unreachable — prefer stale disk cache over hardcoded fallback.
|
|
88
|
-
const resolved = disk?.version ?? FALLBACK_VERSION;
|
|
89
|
-
// Short TTL so we retry the npm fetch soon, but don't hammer it.
|
|
90
|
-
memoryCache = { version: resolved, expiresAt: Date.now() + 5 * 60 * 1000 };
|
|
91
|
-
log("WARN", "claude-code-version", `Failed to fetch latest Claude Code version; using ${resolved}`);
|
|
92
|
-
return resolved;
|
|
93
|
-
})();
|
|
94
|
-
try {
|
|
95
|
-
return await inflight;
|
|
96
|
-
}
|
|
97
|
-
finally {
|
|
98
|
-
inflight = null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/** Build the User-Agent string Anthropic's OAuth + inference edges expect. */
|
|
102
|
-
export async function getClaudeCliUserAgent() {
|
|
103
|
-
const version = await getClaudeCodeVersion();
|
|
104
|
-
return `claude-cli/${version} (external, cli)`;
|
|
105
|
-
}
|
|
1
|
+
// Moved to @kenkaiiii/gg-core.
|
|
2
|
+
export { getClaudeCodeVersion, getClaudeCliUserAgent } from "@kenkaiiii/gg-core";
|
|
106
3
|
//# sourceMappingURL=claude-code-version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code-version.js","sourceRoot":"","sources":["../../src/core/claude-code-version.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"claude-code-version.js","sourceRoot":"","sources":["../../src/core/claude-code-version.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/core/file-lock.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Simple file-based lock with PID tracking and stale detection.
|
|
3
|
-
* Uses atomic file creation (wx flag) to prevent races.
|
|
4
|
-
*/
|
|
5
|
-
export declare function withFileLock<T>(filePath: string, fn: () => Promise<T>): Promise<T>;
|
|
1
|
+
export { withFileLock } from "@kenkaiiii/gg-core";
|
|
6
2
|
//# sourceMappingURL=file-lock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-lock.d.ts","sourceRoot":"","sources":["../../src/core/file-lock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-lock.d.ts","sourceRoot":"","sources":["../../src/core/file-lock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/core/file-lock.js
CHANGED
|
@@ -1,76 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const STALE_TIMEOUT_MS = 10_000; // Lock is stale after 10s
|
|
4
|
-
const RETRY_INTERVAL_MS = 50; // Retry every 50ms
|
|
5
|
-
const MAX_WAIT_MS = 5_000; // Give up after 5s
|
|
6
|
-
/**
|
|
7
|
-
* Simple file-based lock with PID tracking and stale detection.
|
|
8
|
-
* Uses atomic file creation (wx flag) to prevent races.
|
|
9
|
-
*/
|
|
10
|
-
export async function withFileLock(filePath, fn) {
|
|
11
|
-
const lockPath = filePath + ".lock";
|
|
12
|
-
await acquireLock(lockPath);
|
|
13
|
-
try {
|
|
14
|
-
return await fn();
|
|
15
|
-
}
|
|
16
|
-
finally {
|
|
17
|
-
await releaseLock(lockPath);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async function acquireLock(lockPath) {
|
|
21
|
-
const startTime = Date.now();
|
|
22
|
-
while (true) {
|
|
23
|
-
try {
|
|
24
|
-
// O_EXCL: fail if file exists — atomic lock acquisition
|
|
25
|
-
const info = { pid: process.pid, timestamp: Date.now() };
|
|
26
|
-
await fs.writeFile(lockPath, JSON.stringify(info), { flag: "wx" });
|
|
27
|
-
return; // Lock acquired
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
if (err.code !== "EEXIST")
|
|
31
|
-
throw err;
|
|
32
|
-
// Lock file exists — check if it's stale
|
|
33
|
-
try {
|
|
34
|
-
const content = await fs.readFile(lockPath, "utf-8");
|
|
35
|
-
const info = JSON.parse(content);
|
|
36
|
-
// Check if the holding process is still alive
|
|
37
|
-
const isProcessAlive = isAlive(info.pid);
|
|
38
|
-
const isStale = Date.now() - info.timestamp > STALE_TIMEOUT_MS;
|
|
39
|
-
if (!isProcessAlive || isStale) {
|
|
40
|
-
// Stale lock — remove and retry
|
|
41
|
-
await fs.unlink(lockPath).catch(() => { });
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
// Corrupt lock file — remove and retry
|
|
47
|
-
await fs.unlink(lockPath).catch(() => { });
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
// Lock is held by a live process — wait and retry
|
|
51
|
-
if (Date.now() - startTime > MAX_WAIT_MS) {
|
|
52
|
-
// Timeout — force break the lock (better than deadlocking)
|
|
53
|
-
await fs.unlink(lockPath).catch(() => { });
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
await setTimeout(RETRY_INTERVAL_MS);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async function releaseLock(lockPath) {
|
|
61
|
-
await fs.unlink(lockPath).catch(() => { });
|
|
62
|
-
}
|
|
63
|
-
function isAlive(pid) {
|
|
64
|
-
try {
|
|
65
|
-
process.kill(pid, 0); // Signal 0 = check existence without killing
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
// EPERM = process exists but belongs to a different user — still alive
|
|
70
|
-
if (err.code === "EPERM")
|
|
71
|
-
return true;
|
|
72
|
-
// ESRCH = no such process — it's dead
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
1
|
+
// Moved to @kenkaiiii/gg-core.
|
|
2
|
+
export { withFileLock } from "@kenkaiiii/gg-core";
|
|
76
3
|
//# sourceMappingURL=file-lock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-lock.js","sourceRoot":"","sources":["../../src/core/file-lock.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"file-lock.js","sourceRoot":"","sources":["../../src/core/file-lock.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/core/logger.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { EventBus } from "./event-bus.js";
|
|
2
|
-
|
|
2
|
+
export { log, getSessionId, closeLogger } from "@kenkaiiii/gg-core";
|
|
3
3
|
/**
|
|
4
|
-
* Initialize the debug logger. Opens the log file in append
|
|
5
|
-
*
|
|
6
|
-
* session
|
|
7
|
-
* across sessions can be filtered by `grep "sid=<id>"`. No-op if already
|
|
8
|
-
* initialized.
|
|
4
|
+
* Initialize the debug logger for ggcoder. Opens the shared log file in append
|
|
5
|
+
* mode (via gg-core) and writes a one-time "ggcoder started …" line tagged with
|
|
6
|
+
* the session id. No-op if already initialized.
|
|
9
7
|
*/
|
|
10
8
|
export declare function initLogger(filePath: string, meta?: {
|
|
11
9
|
version?: string;
|
|
@@ -13,19 +11,8 @@ export declare function initLogger(filePath: string, meta?: {
|
|
|
13
11
|
model?: string;
|
|
14
12
|
thinking?: string;
|
|
15
13
|
}): void;
|
|
16
|
-
/** Session identifier included on every log line as `sid=<id>`. */
|
|
17
|
-
export declare function getSessionId(): string;
|
|
18
|
-
/**
|
|
19
|
-
* Write a timestamped log line. No-op if logger is not initialized.
|
|
20
|
-
*/
|
|
21
|
-
export declare function log(level: LogLevel, category: string, message: string, data?: Record<string, unknown>): void;
|
|
22
14
|
/**
|
|
23
15
|
* Subscribe to EventBus events and log them. Used by print/json modes.
|
|
24
16
|
*/
|
|
25
17
|
export declare function attachToEventBus(bus: EventBus): void;
|
|
26
|
-
/**
|
|
27
|
-
* Write a shutdown line, close the file descriptor, and clean up subscriptions.
|
|
28
|
-
*/
|
|
29
|
-
export declare function closeLogger(): void;
|
|
30
|
-
export {};
|
|
31
18
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIpE;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAChF,IAAI,CAUN;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAuFpD"}
|