@kenkaiiii/ggcoder 4.3.243 → 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/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/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 +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"}
|
package/dist/core/logger.js
CHANGED
|
@@ -1,59 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const MAX_BYTES = 10 * 1024 * 1024; // 10 MB
|
|
8
|
-
let fd = null;
|
|
9
|
-
let sessionId = "";
|
|
10
|
-
let unsubscribers = [];
|
|
11
|
-
function rotateIfNeeded(filePath) {
|
|
12
|
-
try {
|
|
13
|
-
const st = fs.statSync(filePath);
|
|
14
|
-
if (st.size < MAX_BYTES)
|
|
15
|
-
return;
|
|
16
|
-
const rotated = `${filePath}.1`;
|
|
17
|
-
// Replace prior rotation (fs.renameSync overwrites on POSIX; on Windows
|
|
18
|
-
// it fails if dest exists, so unlink first defensively).
|
|
19
|
-
try {
|
|
20
|
-
fs.unlinkSync(rotated);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
// No prior rotation
|
|
24
|
-
}
|
|
25
|
-
fs.renameSync(filePath, rotated);
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
// Log file doesn't exist yet or stat failed — nothing to rotate
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
// The file-writer logger core (open/log/rotate/close) now lives in
|
|
2
|
+
// @kenkaiiii/gg-core. This module keeps ggcoder's "ggcoder"-branded startup
|
|
3
|
+
// line and the EventBus bridge (`attachToEventBus`), which needs the gg-agent
|
|
4
|
+
// `EventBus` type and therefore must stay out of the UI-free core.
|
|
5
|
+
import { openLog, log, registerLogCleanup } from "@kenkaiiii/gg-core";
|
|
6
|
+
export { log, getSessionId, closeLogger } from "@kenkaiiii/gg-core";
|
|
31
7
|
/**
|
|
32
|
-
* Initialize the debug logger. Opens the log file in append
|
|
33
|
-
*
|
|
34
|
-
* session
|
|
35
|
-
* across sessions can be filtered by `grep "sid=<id>"`. No-op if already
|
|
36
|
-
* initialized.
|
|
8
|
+
* Initialize the debug logger for ggcoder. Opens the shared log file in append
|
|
9
|
+
* mode (via gg-core) and writes a one-time "ggcoder started …" line tagged with
|
|
10
|
+
* the session id. No-op if already initialized.
|
|
37
11
|
*/
|
|
38
12
|
export function initLogger(filePath, meta) {
|
|
39
|
-
if (
|
|
40
|
-
return;
|
|
41
|
-
rotateIfNeeded(filePath);
|
|
42
|
-
try {
|
|
43
|
-
fd = fs.openSync(filePath, "a");
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
// Can't open log file — silently disable logging
|
|
13
|
+
if (!openLog(filePath, "ggcoder"))
|
|
47
14
|
return;
|
|
48
|
-
}
|
|
49
|
-
sessionId = randomBytes(4).toString("hex");
|
|
50
|
-
// Visible separator between sessions when back-reading the log.
|
|
51
|
-
try {
|
|
52
|
-
fs.writeSync(fd, "\n");
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
// Write failed — proceed without the separator
|
|
56
|
-
}
|
|
57
15
|
const parts = ["ggcoder"];
|
|
58
16
|
if (meta?.version)
|
|
59
17
|
parts[0] += ` v${meta.version}`;
|
|
@@ -67,41 +25,14 @@ export function initLogger(filePath, meta) {
|
|
|
67
25
|
parts.push(`pid=${process.pid}`);
|
|
68
26
|
log("INFO", "startup", parts.join(" "));
|
|
69
27
|
}
|
|
70
|
-
/** Session identifier included on every log line as `sid=<id>`. */
|
|
71
|
-
export function getSessionId() {
|
|
72
|
-
return sessionId;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Write a timestamped log line. No-op if logger is not initialized.
|
|
76
|
-
*/
|
|
77
|
-
export function log(level, category, message, data) {
|
|
78
|
-
if (fd === null)
|
|
79
|
-
return;
|
|
80
|
-
const ts = new Date().toISOString();
|
|
81
|
-
let line = `[${ts}] [sid=${sessionId}] [${level}] [${category}] ${message}`;
|
|
82
|
-
if (data) {
|
|
83
|
-
const pairs = Object.entries(data)
|
|
84
|
-
.map(([k, v]) => `${k}=${typeof v === "string" ? v : JSON.stringify(v)}`)
|
|
85
|
-
.join(" ");
|
|
86
|
-
line += ` ${pairs}`;
|
|
87
|
-
}
|
|
88
|
-
line += "\n";
|
|
89
|
-
try {
|
|
90
|
-
fs.writeSync(fd, line);
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
// Write failed — don't crash
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
28
|
/**
|
|
97
29
|
* Subscribe to EventBus events and log them. Used by print/json modes.
|
|
98
30
|
*/
|
|
99
31
|
export function attachToEventBus(bus) {
|
|
100
|
-
|
|
101
|
-
unsubs.push(bus.on("tool_call_start", ({ toolCallId, name }) => {
|
|
32
|
+
registerLogCleanup(bus.on("tool_call_start", ({ toolCallId, name }) => {
|
|
102
33
|
log("INFO", "tool", `Tool call started: ${name}`, { id: toolCallId });
|
|
103
34
|
}));
|
|
104
|
-
|
|
35
|
+
registerLogCleanup(bus.on("tool_call_end", ({ toolCallId, result: _result, isError, durationMs }) => {
|
|
105
36
|
const level = isError ? "ERROR" : "INFO";
|
|
106
37
|
log(level, "tool", `Tool call ended`, {
|
|
107
38
|
id: toolCallId,
|
|
@@ -109,7 +40,7 @@ export function attachToEventBus(bus) {
|
|
|
109
40
|
isError: String(isError),
|
|
110
41
|
});
|
|
111
42
|
}));
|
|
112
|
-
|
|
43
|
+
registerLogCleanup(bus.on("turn_end", ({ turn, stopReason, usage }) => {
|
|
113
44
|
log("INFO", "turn", `Turn ${turn} ended`, {
|
|
114
45
|
stopReason,
|
|
115
46
|
inputTokens: String(usage.inputTokens),
|
|
@@ -118,7 +49,7 @@ export function attachToEventBus(bus) {
|
|
|
118
49
|
...(usage.cacheWrite != null && { cacheWrite: String(usage.cacheWrite) }),
|
|
119
50
|
});
|
|
120
51
|
}));
|
|
121
|
-
|
|
52
|
+
registerLogCleanup(bus.on("agent_done", ({ totalTurns, totalUsage }) => {
|
|
122
53
|
log("INFO", "agent", `Agent done`, {
|
|
123
54
|
totalTurns: String(totalTurns),
|
|
124
55
|
inputTokens: String(totalUsage.inputTokens),
|
|
@@ -127,50 +58,30 @@ export function attachToEventBus(bus) {
|
|
|
127
58
|
...(totalUsage.cacheWrite != null && { cacheWrite: String(totalUsage.cacheWrite) }),
|
|
128
59
|
});
|
|
129
60
|
}));
|
|
130
|
-
|
|
61
|
+
registerLogCleanup(bus.on("error", ({ error }) => {
|
|
131
62
|
log("ERROR", "error", error.message);
|
|
132
63
|
}));
|
|
133
|
-
|
|
64
|
+
registerLogCleanup(bus.on("session_start", ({ sessionId }) => {
|
|
134
65
|
log("INFO", "session", `Session started`, { sessionId });
|
|
135
66
|
}));
|
|
136
|
-
|
|
67
|
+
registerLogCleanup(bus.on("model_change", ({ provider, model }) => {
|
|
137
68
|
log("INFO", "model", `Model changed`, { provider, model });
|
|
138
69
|
}));
|
|
139
|
-
|
|
70
|
+
registerLogCleanup(bus.on("compaction_start", ({ messageCount }) => {
|
|
140
71
|
log("INFO", "compaction", `Compaction started`, { messageCount: String(messageCount) });
|
|
141
72
|
}));
|
|
142
|
-
|
|
73
|
+
registerLogCleanup(bus.on("compaction_end", ({ originalCount, newCount }) => {
|
|
143
74
|
log("INFO", "compaction", `Compaction ended`, {
|
|
144
75
|
originalCount: String(originalCount),
|
|
145
76
|
newCount: String(newCount),
|
|
146
77
|
});
|
|
147
78
|
}));
|
|
148
|
-
|
|
79
|
+
registerLogCleanup(bus.on("user_input", ({ content }) => {
|
|
149
80
|
const truncated = content.length > 100 ? content.slice(0, 100) + "..." : content;
|
|
150
81
|
log("INFO", "input", `User input: ${truncated}`);
|
|
151
82
|
}));
|
|
152
|
-
|
|
83
|
+
registerLogCleanup(bus.on("slash_command", ({ name, args }) => {
|
|
153
84
|
log("INFO", "command", `Slash command: /${name}${args ? ` ${args}` : ""}`);
|
|
154
85
|
}));
|
|
155
|
-
unsubscribers.push(...unsubs);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Write a shutdown line, close the file descriptor, and clean up subscriptions.
|
|
159
|
-
*/
|
|
160
|
-
export function closeLogger() {
|
|
161
|
-
if (fd === null)
|
|
162
|
-
return;
|
|
163
|
-
log("INFO", "shutdown", "ggcoder shutting down");
|
|
164
|
-
try {
|
|
165
|
-
fs.closeSync(fd);
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
// Ignore close errors
|
|
169
|
-
}
|
|
170
|
-
fd = null;
|
|
171
|
-
for (const unsub of unsubscribers) {
|
|
172
|
-
unsub();
|
|
173
|
-
}
|
|
174
|
-
unsubscribers = [];
|
|
175
86
|
}
|
|
176
87
|
//# sourceMappingURL=logger.js.map
|
package/dist/core/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,4EAA4E;AAC5E,8EAA8E;AAC9E,mEAAmE;AACnE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGtE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIpE;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,QAAgB,EAChB,IAAiF;IAEjF,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC;QAAE,OAAO;IAC1C,MAAM,KAAK,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1B,IAAI,IAAI,EAAE,OAAO;QAAE,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;IACnD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtB,IAAI,IAAI,EAAE,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5D,IAAI,IAAI,EAAE,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACnD,IAAI,IAAI,EAAE,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5D,KAAK,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjC,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED;;GAE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AC;IAC7E,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,55 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export interface ModelInfo {
|
|
3
|
-
id: string;
|
|
4
|
-
name: string;
|
|
5
|
-
provider: Provider;
|
|
6
|
-
contextWindow: number;
|
|
7
|
-
/**
|
|
8
|
-
* ChatGPT Codex transport uses product-specific windows that can differ from
|
|
9
|
-
* the public API model window. OpenAI OAuth requests include an accountId and
|
|
10
|
-
* route through `/codex/responses`; API-key requests do not.
|
|
11
|
-
*/
|
|
12
|
-
codexContextWindow?: number;
|
|
13
|
-
maxOutputTokens: number;
|
|
14
|
-
supportsThinking: boolean;
|
|
15
|
-
supportsImages: boolean;
|
|
16
|
-
supportsVideo: boolean;
|
|
17
|
-
costTier: "low" | "medium" | "high";
|
|
18
|
-
/**
|
|
19
|
-
* The top reasoning tier this model genuinely uses. Used when thinking is
|
|
20
|
-
* enabled to pick the strongest setting per model:
|
|
21
|
-
* - OpenAI GPT-5.5-era: `xhigh`
|
|
22
|
-
* - OpenAI Pro/Codex/old: clamped to what the model accepts
|
|
23
|
-
* - Claude Opus 4.8 / 4.7 / 4.6 and Sonnet 4.6: `max`
|
|
24
|
-
* - Claude Haiku 4.5: `high` (no adaptive `max` tier)
|
|
25
|
-
* - GLM / Moonshot / Xiaomi / MiniMax / Qwen: `high` — binary-thinking
|
|
26
|
-
* providers ignore the level on the wire, so the value is cosmetic
|
|
27
|
-
* - DeepSeek V4: `xhigh` (DeepSeek maps `xhigh` → its internal `max`)
|
|
28
|
-
*/
|
|
29
|
-
maxThinkingLevel: ThinkingLevel;
|
|
30
|
-
}
|
|
31
|
-
export declare const MODELS: ModelInfo[];
|
|
32
|
-
export declare function getModel(id: string): ModelInfo | undefined;
|
|
33
|
-
export declare function getModelsForProvider(provider: Provider): ModelInfo[];
|
|
34
|
-
export declare function getDefaultModel(provider: Provider): ModelInfo;
|
|
35
|
-
export interface ContextWindowOptions {
|
|
36
|
-
provider?: Provider;
|
|
37
|
-
accountId?: string;
|
|
38
|
-
}
|
|
39
|
-
export declare function usesOpenAICodexTransport(options?: ContextWindowOptions): boolean;
|
|
40
|
-
export declare function getContextWindow(modelId: string, options?: ContextWindowOptions): number;
|
|
41
|
-
/**
|
|
42
|
-
* The strongest thinking level the given model genuinely uses. Falls back to
|
|
43
|
-
* `"high"` for unknown models since every provider we ship accepts it.
|
|
44
|
-
*/
|
|
45
|
-
export declare function getMaxThinkingLevel(modelId: string): ThinkingLevel;
|
|
46
|
-
/**
|
|
47
|
-
* Get the model to use for compaction summarization.
|
|
48
|
-
* - Anthropic: always Sonnet 4.6
|
|
49
|
-
* - OpenAI: cheapest (Codex Mini)
|
|
50
|
-
* - Gemini: use the current model
|
|
51
|
-
* - GLM: GLM-4.7 Flash (cheap alternative)
|
|
52
|
-
* - Moonshot: use the current model (no cheap alternative)
|
|
53
|
-
*/
|
|
54
|
-
export declare function getSummaryModel(provider: Provider, currentModelId: string): ModelInfo;
|
|
1
|
+
export * from "@kenkaiiii/gg-core/models";
|
|
55
2
|
//# sourceMappingURL=model-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-registry.d.ts","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"model-registry.d.ts","sourceRoot":"","sources":["../../src/core/model-registry.ts"],"names":[],"mappings":"AAGA,cAAc,2BAA2B,CAAC"}
|