chatccc 0.2.252 → 0.2.254
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/README.md +10 -1
- package/bin/cccagent.mjs +12 -3
- package/bin/chatccc.mjs +15 -6
- package/config.sample.json +2 -1
- package/deepccc-agent/README.md +40 -35
- package/deepccc-agent/os-prompts/darwin.md +8 -8
- package/deepccc-agent/os-prompts/linux.md +8 -8
- package/deepccc-agent/os-prompts/win32.md +11 -11
- package/deepccc-agent/package.json +65 -65
- package/dist/deepccc-agent/src/cli.js +634 -0
- package/dist/deepccc-agent/src/config.js +81 -0
- package/dist/deepccc-agent/src/context.js +348 -0
- package/dist/deepccc-agent/src/file-log.js +34 -0
- package/dist/deepccc-agent/src/file-tools.js +1208 -0
- package/dist/deepccc-agent/src/index.js +601 -0
- package/dist/deepccc-agent/src/permissions.js +170 -0
- package/dist/deepccc-agent/src/privacy.js +124 -0
- package/dist/deepccc-agent/src/proc-tree-kill.js +60 -0
- package/dist/deepccc-agent/src/progress/cards-helpers.js +70 -0
- package/dist/deepccc-agent/src/progress/reducer.js +102 -0
- package/dist/deepccc-agent/src/progress/terminal-renderer.js +264 -0
- package/dist/deepccc-agent/src/progress/view.js +30 -0
- package/dist/deepccc-agent/src/raw-stream-log.js +106 -0
- package/dist/deepccc-agent/src/session-search.js +276 -0
- package/dist/deepccc-agent/src/session-select.js +23 -0
- package/dist/deepccc-agent/src/sigint.js +26 -0
- package/dist/deepccc-agent/src/skills.js +178 -0
- package/dist/deepccc-agent/src/web-tools.js +246 -0
- package/dist/src/adapters/adapter-interface.js +19 -0
- package/dist/src/adapters/ccc-adapter.js +112 -0
- package/dist/src/adapters/claude-adapter.js +497 -0
- package/dist/src/adapters/claude-session-meta-store.js +92 -0
- package/dist/src/adapters/codex-adapter.js +279 -0
- package/dist/src/adapters/codex-session-meta-store.js +94 -0
- package/dist/src/adapters/cursor-adapter.js +491 -0
- package/dist/src/adapters/cursor-session-meta-store.js +116 -0
- package/dist/src/adapters/jsonl-stream.js +104 -0
- package/{src/adapters/proc-tree-kill.ts → dist/src/adapters/proc-tree-kill.js} +94 -97
- package/dist/src/adapters/raw-stream-log.js +106 -0
- package/dist/src/adapters/resource-monitor.js +113 -0
- package/dist/src/agent-activity.js +133 -0
- package/dist/src/agent-delegate-task-rpc.js +129 -0
- package/dist/src/agent-delegate-task.js +48 -0
- package/dist/src/agent-file-rpc.js +152 -0
- package/dist/src/agent-image-rpc.js +148 -0
- package/dist/src/agent-platform-routing.js +13 -0
- package/dist/src/agent-reload-config-rpc.js +23 -0
- package/dist/src/agent-rpc-body.js +87 -0
- package/dist/src/agent-stop-stuck.js +110 -0
- package/dist/src/agent-team/application/board-service.js +142 -0
- package/dist/src/agent-team/application/main-agent-service.js +151 -0
- package/dist/src/agent-team/domain/board.js +69 -0
- package/dist/src/agent-team/http/board-routes.js +213 -0
- package/dist/src/agent-team/infrastructure/filesystem-browser.js +112 -0
- package/dist/src/agent-team/infrastructure/main-agent-session-runtime.js +30 -0
- package/dist/src/agent-team/main-agent-bootstrap.js +15 -0
- package/dist/src/agent-team/repositories/board-repository.js +10 -0
- package/dist/src/agent-team/repositories/feishu-p2p-contact-store.js +64 -0
- package/dist/src/agent-team/repositories/json-board-repository.js +209 -0
- package/dist/src/agent-team/repositories/main-agent-binding-repository.js +84 -0
- package/dist/src/agent-team/sync/board-sync-adapter.js +1 -0
- package/dist/src/agent-team/web/agent-team-page.js +219 -0
- package/dist/src/agent-tool.js +10 -0
- package/dist/src/card-action-routing.js +7 -0
- package/dist/src/card-plain-text.js +101 -0
- package/dist/src/cardkit.js +158 -0
- package/dist/src/cards.js +573 -0
- package/dist/src/chatgpt-subscription-rpc.js +18 -0
- package/dist/src/chatgpt-subscription.js +199 -0
- package/dist/src/chrome-devtools-guard.js +238 -0
- package/dist/src/claude-sdk-installer.js +249 -0
- package/dist/src/codex-reset-actions.js +143 -0
- package/dist/src/config-utils.js +149 -0
- package/dist/src/config.js +808 -0
- package/dist/src/cursor-usage.js +77 -0
- package/dist/src/exit-banner.js +28 -0
- package/dist/src/feishu-api.js +1404 -0
- package/dist/src/feishu-message-ingress.js +137 -0
- package/dist/src/feishu-platform.js +97 -0
- package/dist/src/format-message.js +252 -0
- package/dist/src/git-command.js +155 -0
- package/dist/src/im-skills.js +121 -0
- package/dist/src/index.js +835 -0
- package/dist/src/litellm-proxy.js +300 -0
- package/dist/src/orchestrator.js +2096 -0
- package/dist/src/package-root.js +26 -0
- package/dist/src/platform-adapter.js +7 -0
- package/dist/src/platform-startup.js +6 -0
- package/dist/src/privacy.js +100 -0
- package/dist/src/progress/reducer.js +102 -0
- package/dist/src/progress/terminal-renderer.js +264 -0
- package/dist/src/progress/view.js +30 -0
- package/dist/src/response-stall.js +14 -0
- package/dist/src/runtime-entry.js +13 -0
- package/dist/src/runtime-reload.js +19 -0
- package/dist/src/session-chat-binding.js +183 -0
- package/dist/src/session-name.js +7 -0
- package/dist/src/session.js +2147 -0
- package/dist/src/shared-prefix.js +16 -0
- package/dist/src/shared.js +493 -0
- package/dist/src/sim-agent.js +105 -0
- package/dist/src/sim-platform.js +142 -0
- package/dist/src/sim-store.js +231 -0
- package/dist/src/simplify.js +99 -0
- package/dist/src/startup-lifecycle.js +209 -0
- package/dist/src/stream-state.js +141 -0
- package/dist/src/terminal-error.js +100 -0
- package/dist/src/trace.js +50 -0
- package/dist/src/turn-cards.js +92 -0
- package/dist/src/update-command-guard.js +114 -0
- package/{src/web-ui.ts → dist/src/web-ui.js} +753 -839
- package/dist/src/wechat-platform.js +545 -0
- package/package.json +76 -74
- package/deepccc-agent/LICENSE +0 -201
- package/deepccc-agent/bin/deepccc.mjs +0 -26
- package/deepccc-agent/docs/cache-hit-rate-1.jpg +0 -0
- package/deepccc-agent/docs/cache-hit-rate-2.jpg +0 -0
- package/deepccc-agent/package-lock.json +0 -2027
- package/deepccc-agent/src/__tests__/chat-session.test.ts +0 -877
- package/deepccc-agent/src/__tests__/cli-json.test.ts +0 -49
- package/deepccc-agent/src/__tests__/config.test.ts +0 -34
- package/deepccc-agent/src/__tests__/context.test.ts +0 -341
- package/deepccc-agent/src/__tests__/file-tools.test.ts +0 -240
- package/deepccc-agent/src/__tests__/permissions.test.ts +0 -199
- package/deepccc-agent/src/__tests__/privacy.test.ts +0 -318
- package/deepccc-agent/src/__tests__/progress-reducer.test.ts +0 -121
- package/deepccc-agent/src/__tests__/session-search.test.ts +0 -262
- package/deepccc-agent/src/__tests__/session-select.test.ts +0 -116
- package/deepccc-agent/src/__tests__/sigint.test.ts +0 -56
- package/deepccc-agent/src/__tests__/skills.test.ts +0 -284
- package/deepccc-agent/src/__tests__/terminal-renderer.test.ts +0 -247
- package/deepccc-agent/src/__tests__/web-tools.test.ts +0 -220
- package/deepccc-agent/src/cli.ts +0 -682
- package/deepccc-agent/src/config.ts +0 -101
- package/deepccc-agent/src/context.ts +0 -465
- package/deepccc-agent/src/file-log.ts +0 -38
- package/deepccc-agent/src/file-tools.ts +0 -1493
- package/deepccc-agent/src/index.ts +0 -710
- package/deepccc-agent/src/permissions.ts +0 -226
- package/deepccc-agent/src/privacy.ts +0 -141
- package/deepccc-agent/src/proc-tree-kill.ts +0 -61
- package/deepccc-agent/src/progress/cards-helpers.ts +0 -76
- package/deepccc-agent/src/progress/reducer.ts +0 -113
- package/deepccc-agent/src/progress/terminal-renderer.ts +0 -294
- package/deepccc-agent/src/progress/view.ts +0 -77
- package/deepccc-agent/src/raw-stream-log.ts +0 -124
- package/deepccc-agent/src/session-search.ts +0 -370
- package/deepccc-agent/src/session-select.ts +0 -48
- package/deepccc-agent/src/sigint.ts +0 -50
- package/deepccc-agent/src/skills.ts +0 -205
- package/deepccc-agent/src/web-tools.ts +0 -313
- package/deepccc-agent/tsconfig.build.json +0 -13
- package/deepccc-agent/tsconfig.json +0 -13
- package/deepccc-agent/vitest.config.ts +0 -7
- package/src/__tests__/adapter-interface.test.ts +0 -152
- package/src/__tests__/agent-activity.test.ts +0 -86
- package/src/__tests__/agent-delegate-task-rpc.test.ts +0 -165
- package/src/__tests__/agent-image-rpc.test.ts +0 -34
- package/src/__tests__/agent-platform-routing.test.ts +0 -26
- package/src/__tests__/agent-reload-config-rpc.test.ts +0 -99
- package/src/__tests__/agent-rpc-body.test.ts +0 -42
- package/src/__tests__/builtin-chat-session.test.ts +0 -532
- package/src/__tests__/builtin-cli-json.test.ts +0 -39
- package/src/__tests__/builtin-config.test.ts +0 -26
- package/src/__tests__/builtin-context.test.ts +0 -319
- package/src/__tests__/builtin-file-tools.test.ts +0 -240
- package/src/__tests__/builtin-permissions.test.ts +0 -219
- package/src/__tests__/builtin-session-search.test.ts +0 -262
- package/src/__tests__/builtin-session-select.test.ts +0 -116
- package/src/__tests__/builtin-sigint.test.ts +0 -56
- package/src/__tests__/builtin-skills.test.ts +0 -284
- package/src/__tests__/builtin-web-tools.test.ts +0 -220
- package/src/__tests__/card-action-routing.test.ts +0 -18
- package/src/__tests__/card-plain-text.test.ts +0 -45
- package/src/__tests__/cardkit.test.ts +0 -60
- package/src/__tests__/cards.test.ts +0 -607
- package/src/__tests__/ccc-adapter.test.ts +0 -194
- package/src/__tests__/chatgpt-subscription-rpc.test.ts +0 -89
- package/src/__tests__/chatgpt-subscription.test.ts +0 -135
- package/src/__tests__/chrome-devtools-guard.test.ts +0 -165
- package/src/__tests__/claude-adapter.test.ts +0 -614
- package/src/__tests__/claude-raw-stream-log.test.ts +0 -96
- package/src/__tests__/claude-sdk-installer.test.ts +0 -285
- package/src/__tests__/codex-adapter.test.ts +0 -331
- package/src/__tests__/codex-raw-stream-log.test.ts +0 -170
- package/src/__tests__/codex-reset-actions.test.ts +0 -146
- package/src/__tests__/config-reload.test.ts +0 -284
- package/src/__tests__/config-sample.test.ts +0 -97
- package/src/__tests__/config-utils.test.ts +0 -40
- package/src/__tests__/config.test.ts +0 -395
- package/src/__tests__/crash-logging.test.ts +0 -360
- package/src/__tests__/cursor-adapter.test.ts +0 -890
- package/src/__tests__/cursor-session-meta-store.test.ts +0 -212
- package/src/__tests__/feishu-api.test.ts +0 -60
- package/src/__tests__/feishu-avatar.test.ts +0 -504
- package/src/__tests__/feishu-message-ingress.test.ts +0 -138
- package/src/__tests__/feishu-platform.test.ts +0 -75
- package/src/__tests__/fixtures/codex_simple_text.jsonl +0 -4
- package/src/__tests__/fixtures/codex_with_tool.jsonl +0 -6
- package/src/__tests__/fixtures/cursor_partial_only.jsonl +0 -5
- package/src/__tests__/fixtures/cursor_partial_with_final.jsonl +0 -13
- package/src/__tests__/fixtures/cursor_with_tool_call.jsonl +0 -12
- package/src/__tests__/format-message.test.ts +0 -316
- package/src/__tests__/git-command.test.ts +0 -288
- package/src/__tests__/im-skills.test.ts +0 -125
- package/src/__tests__/jsonl-stream.test.ts +0 -79
- package/src/__tests__/orchestrator.test.ts +0 -1268
- package/src/__tests__/package-files.test.ts +0 -24
- package/src/__tests__/platform-startup.test.ts +0 -19
- package/src/__tests__/privacy.test.ts +0 -198
- package/src/__tests__/proc-tree-kill.test.ts +0 -108
- package/src/__tests__/progress-reducer.test.ts +0 -121
- package/src/__tests__/raw-stream-log.test.ts +0 -106
- package/src/__tests__/response-stall.test.ts +0 -49
- package/src/__tests__/restart.test.ts +0 -232
- package/src/__tests__/session-ccc-config.test.ts +0 -66
- package/src/__tests__/session.test.ts +0 -3004
- package/src/__tests__/shared-prefix.test.ts +0 -36
- package/src/__tests__/sim-agent.test.ts +0 -174
- package/src/__tests__/sim-platform.test.ts +0 -93
- package/src/__tests__/sim-store.test.ts +0 -214
- package/src/__tests__/simplify.test.ts +0 -283
- package/src/__tests__/startup-lifecycle.test.ts +0 -231
- package/src/__tests__/stop-session.test.ts +0 -162
- package/src/__tests__/stream-state.test.ts +0 -164
- package/src/__tests__/terminal-error.test.ts +0 -54
- package/src/__tests__/terminal-renderer.test.ts +0 -247
- package/src/__tests__/update-command-guard.test.ts +0 -144
- package/src/__tests__/web-ui.test.ts +0 -438
- package/src/__tests__/wechat-platform.test.ts +0 -111
- package/src/adapters/adapter-interface.ts +0 -217
- package/src/adapters/ccc-adapter.ts +0 -150
- package/src/adapters/claude-adapter.ts +0 -673
- package/src/adapters/claude-session-meta-store.ts +0 -120
- package/src/adapters/codex-adapter.ts +0 -426
- package/src/adapters/codex-session-meta-store.ts +0 -131
- package/src/adapters/cursor-adapter.ts +0 -681
- package/src/adapters/cursor-session-meta-store.ts +0 -154
- package/src/adapters/jsonl-stream.ts +0 -157
- package/src/adapters/raw-stream-log.ts +0 -124
- package/src/adapters/resource-monitor.ts +0 -141
- package/src/agent-activity.ts +0 -175
- package/src/agent-delegate-task-rpc.ts +0 -153
- package/src/agent-delegate-task.ts +0 -91
- package/src/agent-file-rpc.ts +0 -172
- package/src/agent-image-rpc.ts +0 -168
- package/src/agent-platform-routing.ts +0 -28
- package/src/agent-reload-config-rpc.ts +0 -34
- package/src/agent-rpc-body.ts +0 -92
- package/src/agent-stop-stuck.ts +0 -129
- package/src/card-action-routing.ts +0 -14
- package/src/card-plain-text.ts +0 -108
- package/src/cardkit.ts +0 -179
- package/src/cards.ts +0 -684
- package/src/chatgpt-subscription-rpc.ts +0 -27
- package/src/chatgpt-subscription.ts +0 -299
- package/src/chrome-devtools-guard.ts +0 -318
- package/src/claude-sdk-installer.ts +0 -324
- package/src/codex-reset-actions.ts +0 -184
- package/src/config-utils.ts +0 -211
- package/src/config.ts +0 -1063
- package/src/cursor-usage.ts +0 -128
- package/src/exit-banner.ts +0 -33
- package/src/feishu-api.ts +0 -1616
- package/src/feishu-message-ingress.ts +0 -195
- package/src/feishu-platform.ts +0 -159
- package/src/format-message.ts +0 -293
- package/src/git-command.ts +0 -202
- package/src/im-skills.ts +0 -149
- package/src/index.ts +0 -1089
- package/src/litellm-proxy.ts +0 -374
- package/src/orchestrator.ts +0 -2543
- package/src/platform-adapter.ts +0 -70
- package/src/platform-startup.ts +0 -16
- package/src/privacy.ts +0 -118
- package/src/progress/reducer.ts +0 -113
- package/src/progress/terminal-renderer.ts +0 -294
- package/src/progress/view.ts +0 -77
- package/src/response-stall.ts +0 -28
- package/src/runtime-reload.ts +0 -34
- package/src/session-chat-binding.ts +0 -292
- package/src/session-name.ts +0 -8
- package/src/session.ts +0 -2659
- package/src/shared-prefix.ts +0 -29
- package/src/shared.ts +0 -552
- package/src/sim-agent.ts +0 -167
- package/src/sim-platform.ts +0 -177
- package/src/sim-store.ts +0 -317
- package/src/simplify.ts +0 -120
- package/src/startup-lifecycle.ts +0 -250
- package/src/stream-state.ts +0 -177
- package/src/terminal-error.ts +0 -129
- package/src/trace.ts +0 -51
- package/src/turn-cards.ts +0 -118
- package/src/update-command-guard.ts +0 -165
- package/src/wechat-platform.ts +0 -680
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, parse } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/** Locate the installed ChatCCC package root from either src/ or dist/src/. */
|
|
5
|
+
export function findChatCccPackageRoot(startDir = dirname(fileURLToPath(import.meta.url))) {
|
|
6
|
+
let current = startDir;
|
|
7
|
+
const filesystemRoot = parse(current).root;
|
|
8
|
+
while (true) {
|
|
9
|
+
const packagePath = join(current, "package.json");
|
|
10
|
+
if (existsSync(packagePath)) {
|
|
11
|
+
try {
|
|
12
|
+
const pkg = JSON.parse(readFileSync(packagePath, "utf8"));
|
|
13
|
+
if (pkg.name === "chatccc")
|
|
14
|
+
return current;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// Keep walking: a malformed unrelated package.json is not our root.
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (current === filesystemRoot)
|
|
21
|
+
break;
|
|
22
|
+
current = dirname(current);
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`Unable to locate ChatCCC package root from ${startDir}`);
|
|
25
|
+
}
|
|
26
|
+
export const CHATCCC_PACKAGE_ROOT = findChatCccPackageRoot();
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { USER_DATA_DIR } from "./config.js";
|
|
4
|
+
let config = null;
|
|
5
|
+
let loadedStamp;
|
|
6
|
+
function privacyFilePath() {
|
|
7
|
+
return join(USER_DATA_DIR, "privacy.json");
|
|
8
|
+
}
|
|
9
|
+
function privacyFileStamp() {
|
|
10
|
+
const filePath = privacyFilePath();
|
|
11
|
+
if (!existsSync(filePath))
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
const s = statSync(filePath);
|
|
15
|
+
return `${s.mtimeMs}:${s.size}`;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function sanitizeRules(raw) {
|
|
22
|
+
const result = {};
|
|
23
|
+
for (const [from, to] of Object.entries(raw)) {
|
|
24
|
+
if (!from) {
|
|
25
|
+
console.error("[PRIVACY] privacy.json rule key cannot be empty, skipped");
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (typeof to !== "string") {
|
|
29
|
+
console.error(`[PRIVACY] privacy.json value must be a string, skipped "${from}"`);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
result[from] = to;
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
function normalizeConfig(parsed) {
|
|
37
|
+
const hasNewSchema = Object.prototype.hasOwnProperty.call(parsed, "enabled") ||
|
|
38
|
+
Object.prototype.hasOwnProperty.call(parsed, "rules");
|
|
39
|
+
if (!hasNewSchema) {
|
|
40
|
+
return { enabled: true, rules: sanitizeRules(parsed) };
|
|
41
|
+
}
|
|
42
|
+
const enabledRaw = parsed.enabled;
|
|
43
|
+
const enabled = enabledRaw === undefined ? true : enabledRaw !== false;
|
|
44
|
+
if (enabledRaw !== undefined && typeof enabledRaw !== "boolean") {
|
|
45
|
+
console.error("[PRIVACY] privacy.json enabled must be a boolean, using true");
|
|
46
|
+
}
|
|
47
|
+
const rulesRaw = parsed.rules;
|
|
48
|
+
if (rulesRaw === undefined)
|
|
49
|
+
return { enabled, rules: {} };
|
|
50
|
+
if (typeof rulesRaw !== "object" || rulesRaw === null || Array.isArray(rulesRaw)) {
|
|
51
|
+
console.error("[PRIVACY] privacy.json rules must be an object");
|
|
52
|
+
return { enabled, rules: {} };
|
|
53
|
+
}
|
|
54
|
+
return { enabled, rules: sanitizeRules(rulesRaw) };
|
|
55
|
+
}
|
|
56
|
+
function loadConfig() {
|
|
57
|
+
const filePath = privacyFilePath();
|
|
58
|
+
if (!existsSync(filePath)) {
|
|
59
|
+
return { enabled: true, rules: {} };
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const raw = readFileSync(filePath, "utf-8").replace(/^\uFEFF/, "");
|
|
63
|
+
const parsed = JSON.parse(raw);
|
|
64
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
65
|
+
console.error("[PRIVACY] privacy.json must be an object");
|
|
66
|
+
return { enabled: true, rules: {} };
|
|
67
|
+
}
|
|
68
|
+
return normalizeConfig(parsed);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.error(`[PRIVACY] failed to read privacy.json: ${err.message}`);
|
|
72
|
+
return { enabled: true, rules: {} };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function getPrivacyConfig() {
|
|
76
|
+
const stamp = privacyFileStamp();
|
|
77
|
+
if (!config || stamp !== loadedStamp) {
|
|
78
|
+
config = loadConfig();
|
|
79
|
+
loadedStamp = stamp;
|
|
80
|
+
}
|
|
81
|
+
return config;
|
|
82
|
+
}
|
|
83
|
+
export function getPrivacyRules() {
|
|
84
|
+
return getPrivacyConfig().rules;
|
|
85
|
+
}
|
|
86
|
+
export function reloadPrivacyRules() {
|
|
87
|
+
config = null;
|
|
88
|
+
loadedStamp = undefined;
|
|
89
|
+
}
|
|
90
|
+
export function applyPrivacy(text) {
|
|
91
|
+
const { enabled, rules } = getPrivacyConfig();
|
|
92
|
+
if (!enabled || Object.keys(rules).length === 0 || !text)
|
|
93
|
+
return text;
|
|
94
|
+
let result = text;
|
|
95
|
+
for (const [from, to] of Object.entries(rules)) {
|
|
96
|
+
// Use split+join instead of regex replacement so rule keys stay literal.
|
|
97
|
+
result = result.split(from).join(to);
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* progress/reducer.ts — ChatEvent 事件流 → ProgressView 的增量合并
|
|
3
|
+
*
|
|
4
|
+
* 这是飞书与终端共享的唯一一份"事件 → 过程视图"公共逻辑:
|
|
5
|
+
* 终端 REPL 直接消费 ChatSession.chat() 的事件流,逐条 reduce;
|
|
6
|
+
* 飞书侧 display loop 若未来接入事件流,同样使用本 reducer,保证两端
|
|
7
|
+
* 看到的过程状态(正文累积、工具调用、终态判定)完全一致。
|
|
8
|
+
*/
|
|
9
|
+
import { withProgressView, } from "./view.js";
|
|
10
|
+
/** 工具调用 input 单行摘要(终端折叠行展示用) */
|
|
11
|
+
export function summarizeToolInput(input, maxChars = 120) {
|
|
12
|
+
let raw;
|
|
13
|
+
if (typeof input === "string") {
|
|
14
|
+
raw = input;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
try {
|
|
18
|
+
raw = JSON.stringify(input);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
raw = String(input);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const oneLine = raw.replace(/\s+/g, " ").trim();
|
|
25
|
+
return oneLine.length > maxChars ? oneLine.slice(0, maxChars) + "…" : oneLine;
|
|
26
|
+
}
|
|
27
|
+
/** 工具结果单行摘要(成功/失败各取首行) */
|
|
28
|
+
export function summarizeToolResult(content, maxChars = 120) {
|
|
29
|
+
let raw;
|
|
30
|
+
if (typeof content === "string") {
|
|
31
|
+
raw = content;
|
|
32
|
+
}
|
|
33
|
+
else if (content instanceof Error) {
|
|
34
|
+
raw = content.message;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
try {
|
|
38
|
+
raw = JSON.stringify(content);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
raw = String(content);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const firstLine = raw.split("\n")[0] ?? "";
|
|
45
|
+
return firstLine.length > maxChars ? firstLine.slice(0, maxChars) + "…" : firstLine;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 把一条 ChatEvent 合并进 ProgressView,返回新视图(不可变更新)。
|
|
49
|
+
* 未识别的/不影响展示的事件(如 compact)返回原视图。
|
|
50
|
+
*/
|
|
51
|
+
export function reduceProgress(prev, event) {
|
|
52
|
+
switch (event.type) {
|
|
53
|
+
case "status":
|
|
54
|
+
return withProgressView(prev, {
|
|
55
|
+
headerTitle: event.phase === "compacting" ? "压缩上下文中..." : "生成回复中...",
|
|
56
|
+
});
|
|
57
|
+
case "text":
|
|
58
|
+
// accumulated 是全文累积,直接全量替换,天然幂等
|
|
59
|
+
return withProgressView(prev, { text: event.accumulated });
|
|
60
|
+
case "tool_use": {
|
|
61
|
+
const tool = {
|
|
62
|
+
id: event.id ?? `tool-${prev.tools.length + 1}`,
|
|
63
|
+
name: event.name,
|
|
64
|
+
status: "running",
|
|
65
|
+
detail: summarizeToolInput(event.input),
|
|
66
|
+
};
|
|
67
|
+
return withProgressView(prev, { tools: [...prev.tools, tool] });
|
|
68
|
+
}
|
|
69
|
+
case "tool_result": {
|
|
70
|
+
const nextStatus = event.is_error ? "error" : "ok";
|
|
71
|
+
const summary = summarizeToolResult(event.content);
|
|
72
|
+
let matched = false;
|
|
73
|
+
const tools = prev.tools.map((t) => {
|
|
74
|
+
if (matched || t.id !== event.tool_use_id)
|
|
75
|
+
return t;
|
|
76
|
+
matched = true;
|
|
77
|
+
return { ...t, status: nextStatus, summary };
|
|
78
|
+
});
|
|
79
|
+
if (!matched) {
|
|
80
|
+
// id 缺失或失配:兜底更新最后一个 running 工具,避免状态悬挂
|
|
81
|
+
const lastRunning = [...prev.tools].reverse().findIndex((t) => t.status === "running");
|
|
82
|
+
if (lastRunning >= 0) {
|
|
83
|
+
const idx = prev.tools.length - 1 - lastRunning;
|
|
84
|
+
const updated = prev.tools.map((t, i) => i === idx ? { ...t, status: nextStatus, summary } : t);
|
|
85
|
+
return withProgressView(prev, { tools: updated });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return withProgressView(prev, { tools });
|
|
89
|
+
}
|
|
90
|
+
case "done":
|
|
91
|
+
return withProgressView(prev, {
|
|
92
|
+
status: "done",
|
|
93
|
+
showStop: false,
|
|
94
|
+
text: event.text,
|
|
95
|
+
});
|
|
96
|
+
case "error":
|
|
97
|
+
return withProgressView(prev, { status: "error", showStop: false });
|
|
98
|
+
case "compact":
|
|
99
|
+
// 旧上下文压缩不影响当前过程展示
|
|
100
|
+
return prev;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* progress/terminal-renderer.ts — 终端"过程区块"渲染器
|
|
3
|
+
*
|
|
4
|
+
* 把 ProgressView 渲染为终端里的一块固定区域(对应飞书过程卡片):
|
|
5
|
+
* - 状态行:生成中 / 完成 / 已停止 / 异常结束
|
|
6
|
+
* - 工具行:每个工具调用一行(emoji + 名称 + ✓/✗ + 摘要),不再滚屏刷 JSON
|
|
7
|
+
* - 正文行:模型流式输出,原地更新不滚动
|
|
8
|
+
*
|
|
9
|
+
* 实现要点:
|
|
10
|
+
* - 隐藏光标(\x1b[?25l)→ 每帧整块重绘(\x1b[{n}A 上移 + \x1b[2K 清行 + \x1b[J 清下方)
|
|
11
|
+
* - 帧节流合并重绘,避免高频文本增量导致闪烁
|
|
12
|
+
* - 每行按显示宽度截断(CJK/emoji 算 2 列),保证永不折行:一旦折行,
|
|
13
|
+
* 实际占用的屏幕行数会超过 blockLines 计数,下次重绘上移行数不足,
|
|
14
|
+
* 会清掉区块上方的历史内容(用户输入的问题被"吃掉")。
|
|
15
|
+
* - end() 时把终态区块定型留在屏幕上(与飞书完成卡片留在消息流语义一致),恢复光标
|
|
16
|
+
*/
|
|
17
|
+
import { getToolEmoji, truncateContent } from "../cards.js";
|
|
18
|
+
import { progressView } from "./view.js";
|
|
19
|
+
const RESET = "\x1b[0m";
|
|
20
|
+
const DIM = "\x1b[2m";
|
|
21
|
+
const BOLD = "\x1b[1m";
|
|
22
|
+
const GREEN = "\x1b[32m";
|
|
23
|
+
const YELLOW = "\x1b[33m";
|
|
24
|
+
const RED = "\x1b[31m";
|
|
25
|
+
const HIDE_CURSOR = "\x1b[?25l";
|
|
26
|
+
const SHOW_CURSOR = "\x1b[?25h";
|
|
27
|
+
/** 生成中标题后的心跳点号动画帧(1 → 2 → 3 → 2 循环,避免跳变感) */
|
|
28
|
+
const ANIM_FRAMES = ["·", "··", "···", "··"];
|
|
29
|
+
const ANSI_TOKEN = /\x1b\[[0-9;]*m/;
|
|
30
|
+
/** 单个字符在终端里的显示列宽:CJK/emoji 占 2 列,控制符/ZWJ/变体选择符占 0 列 */
|
|
31
|
+
export function charWidth(ch) {
|
|
32
|
+
const code = ch.codePointAt(0);
|
|
33
|
+
if (code < 32 || (code >= 0x7f && code <= 0xa0))
|
|
34
|
+
return 0; // 控制字符
|
|
35
|
+
if (code === 0x200d || code === 0xfe0e || code === 0xfe0f)
|
|
36
|
+
return 0; // ZWJ / VS15 / VS16
|
|
37
|
+
if ((code >= 0x1100 && code <= 0x115f) || // 谚文 Jamo
|
|
38
|
+
(code >= 0x2e80 && code <= 0x303f) || // CJK 部首 / 标点
|
|
39
|
+
(code >= 0x3040 && code <= 0xa4cf) || // 假名 / 汉字 / 谚文 / 彝文
|
|
40
|
+
(code >= 0xac00 && code <= 0xd7a3) || // 谚文音节
|
|
41
|
+
(code >= 0xf900 && code <= 0xfaff) || // CJK 兼容汉字
|
|
42
|
+
(code >= 0xfe30 && code <= 0xfe6f) || // CJK 兼容形式
|
|
43
|
+
(code >= 0xff00 && code <= 0xff60) || // 全角形式
|
|
44
|
+
(code >= 0xffe0 && code <= 0xffe6) || // 全角符号
|
|
45
|
+
(code >= 0x2600 && code <= 0x27bf) || // 杂项符号 + Dingbats(emoji 呈现 2 列)
|
|
46
|
+
(code >= 0x1f000 && code <= 0x1faff) // emoji 补充区
|
|
47
|
+
) {
|
|
48
|
+
return 2;
|
|
49
|
+
}
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 按终端显示宽度截断一行(CJK/emoji 计 2 列),ANSI 序列零宽且永不截断。
|
|
54
|
+
* 截断位置若处于未闭合的颜色状态,自动补 \x1b[0m,避免颜色泄漏到后续输出。
|
|
55
|
+
*/
|
|
56
|
+
export function clipToWidth(s, maxCols) {
|
|
57
|
+
if (maxCols <= 0)
|
|
58
|
+
return "";
|
|
59
|
+
let out = "";
|
|
60
|
+
let visible = 0;
|
|
61
|
+
let colorOpen = false;
|
|
62
|
+
let i = 0;
|
|
63
|
+
while (i < s.length) {
|
|
64
|
+
if (s.charCodeAt(i) === 0x1b) {
|
|
65
|
+
const m = ANSI_TOKEN.exec(s.slice(i));
|
|
66
|
+
if (m && m.index === 0) {
|
|
67
|
+
out += m[0];
|
|
68
|
+
colorOpen = m[0] !== "\x1b[0m";
|
|
69
|
+
i += m[0].length;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const cp = s.codePointAt(i);
|
|
74
|
+
const ch = String.fromCodePoint(cp);
|
|
75
|
+
const w = charWidth(ch);
|
|
76
|
+
if (visible + w > maxCols)
|
|
77
|
+
break;
|
|
78
|
+
out += ch;
|
|
79
|
+
visible += w;
|
|
80
|
+
i += ch.length;
|
|
81
|
+
}
|
|
82
|
+
if (colorOpen)
|
|
83
|
+
out += "\x1b[0m";
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
function buildStatusLine(view) {
|
|
87
|
+
switch (view.status) {
|
|
88
|
+
case "done":
|
|
89
|
+
return `${BOLD}${GREEN}✅ 完成${RESET}`;
|
|
90
|
+
case "stopped":
|
|
91
|
+
return `${YELLOW}⏹ 已停止${RESET}`;
|
|
92
|
+
case "error":
|
|
93
|
+
return `${RED}❌ 异常结束${RESET}`;
|
|
94
|
+
case "generating": {
|
|
95
|
+
const hint = view.showStop ? `${DIM} · Ctrl+C 停止${RESET}` : "";
|
|
96
|
+
return `⏳ ${view.headerTitle}${hint}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function buildToolLine(tool) {
|
|
101
|
+
const emoji = getToolEmoji(tool.name);
|
|
102
|
+
const mark = tool.status === "running"
|
|
103
|
+
? "…"
|
|
104
|
+
: tool.status === "ok"
|
|
105
|
+
? `${GREEN}✓${RESET}`
|
|
106
|
+
: `${RED}✗${RESET}`;
|
|
107
|
+
const info = tool.status === "running" ? (tool.detail ?? "") : (tool.summary ?? "");
|
|
108
|
+
// 摘要/详情用正常色:最终区块里不出现浅色文字(可读性优先)
|
|
109
|
+
return ` ${emoji} ${tool.name} ${mark} ${info}`;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 把 ProgressView 展开为区块的完整行列表(不含 ANSI 定位序列,只含内容与颜色)。
|
|
113
|
+
* 单独导出便于单元测试;每行按终端宽度截断,避免长行折行导致行数计数失准。
|
|
114
|
+
*/
|
|
115
|
+
export function buildBlockLines(view, width, maxBodyLines = 30, maxBodyChars = 12000) {
|
|
116
|
+
const clip = (s) => clipToWidth(s, width);
|
|
117
|
+
const lines = [];
|
|
118
|
+
lines.push(clip(buildStatusLine(view)));
|
|
119
|
+
for (const tool of view.tools) {
|
|
120
|
+
lines.push(clip(buildToolLine(tool)));
|
|
121
|
+
}
|
|
122
|
+
const body = truncateContent(view.text, maxBodyLines, maxBodyChars);
|
|
123
|
+
if (body.trim()) {
|
|
124
|
+
for (const line of body.split("\n")) {
|
|
125
|
+
lines.push(clip(line));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
lines.push(`${DIM}等待 Agent 输出...${RESET}`);
|
|
130
|
+
}
|
|
131
|
+
return lines;
|
|
132
|
+
}
|
|
133
|
+
export class TerminalProgressRenderer {
|
|
134
|
+
out;
|
|
135
|
+
frameMs;
|
|
136
|
+
animMs;
|
|
137
|
+
maxBodyLines;
|
|
138
|
+
maxBodyChars;
|
|
139
|
+
view;
|
|
140
|
+
blockLines = 0;
|
|
141
|
+
dirty = false;
|
|
142
|
+
timer = null;
|
|
143
|
+
ended = false;
|
|
144
|
+
animFrame = 0;
|
|
145
|
+
animTimer = null;
|
|
146
|
+
constructor(opts = {}) {
|
|
147
|
+
this.out = opts.out ?? process.stdout;
|
|
148
|
+
this.frameMs = opts.frameMs ?? 66;
|
|
149
|
+
this.animMs = opts.animMs ?? 300;
|
|
150
|
+
this.maxBodyLines = opts.maxBodyLines ?? 30;
|
|
151
|
+
this.maxBodyChars = opts.maxBodyChars ?? 12000;
|
|
152
|
+
this.view = progressView();
|
|
153
|
+
}
|
|
154
|
+
/** 开始一轮区块:隐藏光标并渲染首帧,随后启动生成中心跳动画 */
|
|
155
|
+
begin(view) {
|
|
156
|
+
this.view = view;
|
|
157
|
+
this.out.write(HIDE_CURSOR);
|
|
158
|
+
this.renderNow(view);
|
|
159
|
+
this.startAnimation();
|
|
160
|
+
}
|
|
161
|
+
/** 标记视图已更新,按帧节流合并重绘(高频增量不闪烁) */
|
|
162
|
+
render(view) {
|
|
163
|
+
this.view = view;
|
|
164
|
+
if (this.ended)
|
|
165
|
+
return;
|
|
166
|
+
this.dirty = true;
|
|
167
|
+
if (this.timer)
|
|
168
|
+
return;
|
|
169
|
+
this.timer = setTimeout(() => {
|
|
170
|
+
this.timer = null;
|
|
171
|
+
if (this.dirty && !this.ended) {
|
|
172
|
+
this.dirty = false;
|
|
173
|
+
this.renderNow(this.view);
|
|
174
|
+
}
|
|
175
|
+
}, this.frameMs);
|
|
176
|
+
}
|
|
177
|
+
/** 强制立即重绘(工具结果、终态等低频率但需及时反馈的事件) */
|
|
178
|
+
flush() {
|
|
179
|
+
if (this.timer) {
|
|
180
|
+
clearTimeout(this.timer);
|
|
181
|
+
this.timer = null;
|
|
182
|
+
}
|
|
183
|
+
if (this.ended)
|
|
184
|
+
return;
|
|
185
|
+
this.dirty = false;
|
|
186
|
+
this.renderNow(this.view);
|
|
187
|
+
}
|
|
188
|
+
/** 结束一轮:定型终态区块(留在屏幕上),恢复光标,停止动画 */
|
|
189
|
+
end(view) {
|
|
190
|
+
if (this.timer) {
|
|
191
|
+
clearTimeout(this.timer);
|
|
192
|
+
this.timer = null;
|
|
193
|
+
}
|
|
194
|
+
this.stopAnimation();
|
|
195
|
+
this.ended = true;
|
|
196
|
+
this.renderNow(view);
|
|
197
|
+
this.out.write(SHOW_CURSOR);
|
|
198
|
+
}
|
|
199
|
+
/** 兜底清理:清除未决定时器并恢复光标 */
|
|
200
|
+
dispose() {
|
|
201
|
+
if (this.timer) {
|
|
202
|
+
clearTimeout(this.timer);
|
|
203
|
+
this.timer = null;
|
|
204
|
+
}
|
|
205
|
+
this.stopAnimation();
|
|
206
|
+
if (!this.ended) {
|
|
207
|
+
this.out.write(SHOW_CURSOR);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
startAnimation() {
|
|
211
|
+
if (this.animMs <= 0 || this.animTimer)
|
|
212
|
+
return;
|
|
213
|
+
this.animTimer = setInterval(() => {
|
|
214
|
+
this.animFrame++;
|
|
215
|
+
// 终态(done/stopped/error)由 end() 停止;此处兜底跳过,避免结束后还在重绘
|
|
216
|
+
if (this.ended || this.view.status !== "generating")
|
|
217
|
+
return;
|
|
218
|
+
// 无新事件也持续重绘,点号动画让静止期(思考/工具运行中)也有动态感
|
|
219
|
+
this.renderNow(this.view);
|
|
220
|
+
}, this.animMs);
|
|
221
|
+
this.animTimer.unref?.();
|
|
222
|
+
}
|
|
223
|
+
stopAnimation() {
|
|
224
|
+
if (this.animTimer) {
|
|
225
|
+
clearInterval(this.animTimer);
|
|
226
|
+
this.animTimer = null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
renderNow(view) {
|
|
230
|
+
const width = this.out.columns && this.out.columns > 0 ? this.out.columns : 80;
|
|
231
|
+
const lines = buildBlockLines(this.applyAnimation(view), width, this.maxBodyLines, this.maxBodyChars);
|
|
232
|
+
const newLines = lines.length;
|
|
233
|
+
if (this.blockLines > 0) {
|
|
234
|
+
// 关键:光标此刻停在区块【最后一行】行尾,回到区块第一行只需上移
|
|
235
|
+
// blockLines - 1 行。上移 blockLines 行会每帧多上移 1 行,把区块上方
|
|
236
|
+
// 的历史内容逐行"吃掉"(用户看到的"一行一行往上吃")。
|
|
237
|
+
this.out.write(`\x1b[${this.blockLines - 1}A`);
|
|
238
|
+
this.out.write("\r");
|
|
239
|
+
}
|
|
240
|
+
for (let i = 0; i < lines.length; i++) {
|
|
241
|
+
this.out.write(`\r\x1b[2K${lines[i]}`);
|
|
242
|
+
if (i < lines.length - 1) {
|
|
243
|
+
this.out.write("\n");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (newLines < this.blockLines) {
|
|
247
|
+
// 新区块比旧区块短:清掉下方多出的行
|
|
248
|
+
this.out.write("\n");
|
|
249
|
+
for (let i = 0; i < this.blockLines - newLines; i++) {
|
|
250
|
+
this.out.write("\x1b[2K\n");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
this.out.write("\x1b[J");
|
|
254
|
+
this.blockLines = newLines;
|
|
255
|
+
}
|
|
256
|
+
/** 生成中阶段在标题后叠加心跳点号动画;终态原样返回(buildBlockLines 保持纯函数可测) */
|
|
257
|
+
applyAnimation(view) {
|
|
258
|
+
if (view.status !== "generating")
|
|
259
|
+
return view;
|
|
260
|
+
const base = view.headerTitle.replace(/\.\.\.\s*$/, "").trim();
|
|
261
|
+
const dots = ANIM_FRAMES[this.animFrame % ANIM_FRAMES.length];
|
|
262
|
+
return { ...view, headerTitle: `${base} ${dots}` };
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* progress/view.ts — 平台无关的"过程进度"视图模型
|
|
3
|
+
*
|
|
4
|
+
* 这是飞书过程卡片与终端过程区块共享的唯一数据模型:
|
|
5
|
+
* - 飞书:buildProgressCard(view) 把 ProgressView 渲染为卡片 JSON
|
|
6
|
+
* - 终端:TerminalProgressRenderer 把 ProgressView 渲染为 ANSI 区块
|
|
7
|
+
* - 事件流:reduceProgress(prev, event) 把 ChatEvent 增量合并进 ProgressView
|
|
8
|
+
*
|
|
9
|
+
* 语义与飞书卡片对齐:
|
|
10
|
+
* - headerTitle 是"生成中"阶段展示的标题(如"正在启动 Agent · 0秒")
|
|
11
|
+
* - status 决定终态外观(完成 / 已停止 / 异常结束)
|
|
12
|
+
* - text 是正文累积(对应卡片 main_content / 终端区块正文)
|
|
13
|
+
* - tools 是本轮工具调用列表(飞书卡片暂不展示,终端折叠为单行)
|
|
14
|
+
*/
|
|
15
|
+
/** 创建 ProgressView,未提供的字段使用与飞书 buildProgressCard 一致的默认值 */
|
|
16
|
+
export function progressView(init = {}) {
|
|
17
|
+
return {
|
|
18
|
+
status: init.status ?? "generating",
|
|
19
|
+
headerTitle: init.headerTitle ?? "生成中...",
|
|
20
|
+
headerTemplate: init.headerTemplate ?? "blue",
|
|
21
|
+
text: init.text ?? "",
|
|
22
|
+
tools: init.tools ?? [],
|
|
23
|
+
showStop: init.showStop ?? true,
|
|
24
|
+
updatedAt: Date.now(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** 只读浅拷贝并覆盖部分字段,返回新视图(reducer 的不可变更新用) */
|
|
28
|
+
export function withProgressView(prev, patch) {
|
|
29
|
+
return { ...prev, ...patch, updatedAt: Date.now() };
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracks how long the displayed output character count has remained unchanged.
|
|
3
|
+
* Leaving a monitored phase clears the window; returning starts a fresh one.
|
|
4
|
+
*/
|
|
5
|
+
export function observeResponseProgress(previous, isMonitoredPhase, totalChars, now = Date.now()) {
|
|
6
|
+
if (!isMonitoredPhase)
|
|
7
|
+
return undefined;
|
|
8
|
+
if (previous?.totalChars === totalChars)
|
|
9
|
+
return previous;
|
|
10
|
+
return { totalChars, unchangedSince: now };
|
|
11
|
+
}
|
|
12
|
+
export function hasResponseStalled(observation, now, timeoutMs) {
|
|
13
|
+
return observation !== undefined && now - observation.unchangedSince >= timeoutMs;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
/** Use compiled JavaScript in installed packages, with a tsx fallback for source checkouts. */
|
|
4
|
+
export function resolveChatCccRuntimeSpawnSpec(projectRoot) {
|
|
5
|
+
const compiledEntry = join(projectRoot, "dist", "src", "index.js");
|
|
6
|
+
if (existsSync(compiledEntry)) {
|
|
7
|
+
return { command: process.execPath, args: [compiledEntry] };
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
command: process.execPath,
|
|
11
|
+
args: [join(projectRoot, "node_modules", "tsx", "dist", "cli.mjs"), "src/index.ts"],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { APP_ID, CONFIG_FILE, maskAppId, reloadConfigFromDisk, resolveDefaultAgentTool, } from "./config.js";
|
|
2
|
+
import { appendStartupTrace } from "./shared.js";
|
|
3
|
+
import { clearAdapterCache } from "./session.js";
|
|
4
|
+
import { startChromeDevtoolsGuard } from "./chrome-devtools-guard.js";
|
|
5
|
+
export function reloadRuntimeConfig(source) {
|
|
6
|
+
reloadConfigFromDisk();
|
|
7
|
+
clearAdapterCache();
|
|
8
|
+
startChromeDevtoolsGuard();
|
|
9
|
+
const result = {
|
|
10
|
+
configPath: CONFIG_FILE,
|
|
11
|
+
defaultAgent: resolveDefaultAgentTool(),
|
|
12
|
+
reloadedAt: new Date().toISOString(),
|
|
13
|
+
};
|
|
14
|
+
appendStartupTrace(`${source}: config reloaded`, {
|
|
15
|
+
appIdMask: maskAppId(APP_ID),
|
|
16
|
+
defaultAgent: result.defaultAgent,
|
|
17
|
+
});
|
|
18
|
+
return result;
|
|
19
|
+
}
|