@renxqoo/renx-code 0.0.4 → 0.0.6
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 +82 -51
- package/bin/renx.cjs +16 -0
- package/package.json +2 -45
- package/src/agent/runtime/runtime.context-usage.test.ts +4 -5
- package/src/agent/runtime/runtime.error-handling.test.ts +4 -5
- package/src/agent/runtime/runtime.test.ts +7 -4
- package/src/agent/runtime/runtime.ts +3 -9
- package/src/agent/runtime/runtime.usage-forwarding.test.ts +4 -5
- package/src/agent/runtime/source-modules.test.ts +16 -35
- package/src/agent/runtime/source-modules.ts +17 -0
- package/vendor/agent-root/src/agent/ENTERPRISE_ACCEPTANCE_CHECKLIST.md +95 -0
- package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.html +1345 -0
- package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.md +1353 -0
- package/vendor/agent-root/src/agent/ERROR_CONTRACT.md +60 -0
- package/vendor/agent-root/src/agent/TEST_COVERAGE_ANALYSIS.md +278 -0
- package/vendor/agent-root/src/agent/__test__/error-contract.test.ts +72 -0
- package/vendor/agent-root/src/agent/__test__/types.test.ts +137 -0
- package/vendor/agent-root/src/agent/agent/__test__/abort-runtime.test.ts +83 -0
- package/vendor/agent-root/src/agent/agent/__test__/callback-safety.test.ts +34 -0
- package/vendor/agent-root/src/agent/agent/__test__/compaction.test.ts +323 -0
- package/vendor/agent-root/src/agent/agent/__test__/concurrency.test.ts +290 -0
- package/vendor/agent-root/src/agent/agent/__test__/error-normalizer.test.ts +377 -0
- package/vendor/agent-root/src/agent/agent/__test__/error.test.ts +212 -0
- package/vendor/agent-root/src/agent/agent/__test__/fault-injection.test.ts +295 -0
- package/vendor/agent-root/src/agent/agent/__test__/index.test.ts +3607 -0
- package/vendor/agent-root/src/agent/agent/__test__/logger.test.ts +35 -0
- package/vendor/agent-root/src/agent/agent/__test__/message-utils.test.ts +517 -0
- package/vendor/agent-root/src/agent/agent/__test__/telemetry.test.ts +97 -0
- package/vendor/agent-root/src/agent/agent/__test__/timeout-budget.test.ts +479 -0
- package/vendor/agent-root/src/agent/agent/__test__/tool-call-merge.test.ts +80 -0
- package/vendor/agent-root/src/agent/agent/__test__/tool-execution-ledger.test.ts +76 -0
- package/vendor/agent-root/src/agent/agent/__test__/write-buffer.test.ts +173 -0
- package/vendor/agent-root/src/agent/agent/__test__/write-file-session.test.ts +109 -0
- package/vendor/agent-root/src/agent/agent/abort-runtime.ts +71 -0
- package/vendor/agent-root/src/agent/agent/callback-safety.ts +33 -0
- package/vendor/agent-root/src/agent/agent/compaction.ts +291 -0
- package/vendor/agent-root/src/agent/agent/concurrency.ts +103 -0
- package/vendor/agent-root/src/agent/agent/error-normalizer.ts +190 -0
- package/vendor/agent-root/src/agent/agent/error.ts +198 -0
- package/vendor/agent-root/src/agent/agent/index.ts +1772 -0
- package/vendor/agent-root/src/agent/agent/logger.ts +65 -0
- package/vendor/agent-root/src/agent/agent/message-utils.ts +101 -0
- package/vendor/agent-root/src/agent/agent/stream-events.ts +61 -0
- package/vendor/agent-root/src/agent/agent/telemetry.ts +123 -0
- package/vendor/agent-root/src/agent/agent/timeout-budget.ts +227 -0
- package/vendor/agent-root/src/agent/agent/tool-call-merge.ts +111 -0
- package/vendor/agent-root/src/agent/agent/tool-execution-ledger.ts +164 -0
- package/vendor/agent-root/src/agent/agent/write-buffer.ts +188 -0
- package/vendor/agent-root/src/agent/agent/write-file-session.ts +238 -0
- package/vendor/agent-root/src/agent/app/__test__/agent-app-service.test.ts +1053 -0
- package/vendor/agent-root/src/agent/app/__test__/minimal-agent-application.test.ts +158 -0
- package/vendor/agent-root/src/agent/app/__test__/sqlite-agent-app-store.test.ts +437 -0
- package/vendor/agent-root/src/agent/app/agent-app-service.ts +748 -0
- package/vendor/agent-root/src/agent/app/contracts.ts +109 -0
- package/vendor/agent-root/src/agent/app/index.ts +5 -0
- package/vendor/agent-root/src/agent/app/minimal-agent-application.ts +151 -0
- package/vendor/agent-root/src/agent/app/ports.ts +72 -0
- package/vendor/agent-root/src/agent/app/sqlite-agent-app-store.ts +1182 -0
- package/vendor/agent-root/src/agent/app/sqlite-client.ts +177 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/00-README.md +36 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/01-scope-and-goals.md +33 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/02-architecture-overview.md +40 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/03-domain-model-and-contracts.md +91 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/04-ports-and-interfaces.md +116 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/05-run-orchestration-and-state-machine.md +52 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/06-cli-commands-and-ux.md +53 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/07-storage-design-local.md +52 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/08-error-and-observability.md +40 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/09-security-and-policy-boundary.md +19 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/10-test-plan-and-acceptance.md +28 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/11-implementation-phases.md +26 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/12-open-questions-and-risks.md +30 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/13-sqlite-schema-fields-and-rationale.md +567 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/14-project-flow-mermaid.md +583 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/15-openclaw-style-project-blueprint.md +972 -0
- package/vendor/agent-root/src/agent/error-contract.ts +154 -0
- package/vendor/agent-root/src/agent/prompts/system.ts +246 -0
- package/vendor/agent-root/src/agent/prompts/system1.ts +208 -0
- package/vendor/agent-root/src/agent/storage/__test__/file-history-store.test.ts +98 -0
- package/vendor/agent-root/src/agent/storage/file-history-store.ts +313 -0
- package/vendor/agent-root/src/agent/storage/file-storage-config.ts +94 -0
- package/vendor/agent-root/src/agent/storage/file-system.ts +31 -0
- package/vendor/agent-root/src/agent/storage/file-write-service.ts +21 -0
- package/vendor/agent-root/src/agent/tool/__test__/base-tool.test.ts +413 -0
- package/vendor/agent-root/src/agent/tool/__test__/bash-policy.test.ts +356 -0
- package/vendor/agent-root/src/agent/tool/__test__/bash.mocked-coverage.test.ts +375 -0
- package/vendor/agent-root/src/agent/tool/__test__/bash.test.ts +372 -0
- package/vendor/agent-root/src/agent/tool/__test__/error.test.ts +108 -0
- package/vendor/agent-root/src/agent/tool/__test__/file-edit-tool.test.ts +258 -0
- package/vendor/agent-root/src/agent/tool/__test__/file-history-tools.test.ts +121 -0
- package/vendor/agent-root/src/agent/tool/__test__/file-read-tool.test.ts +210 -0
- package/vendor/agent-root/src/agent/tool/__test__/glob.test.ts +139 -0
- package/vendor/agent-root/src/agent/tool/__test__/grep.mocked-coverage.test.ts +456 -0
- package/vendor/agent-root/src/agent/tool/__test__/grep.test.ts +192 -0
- package/vendor/agent-root/src/agent/tool/__test__/lsp.test.ts +300 -0
- package/vendor/agent-root/src/agent/tool/__test__/outside-workspace-confirmation.test.ts +214 -0
- package/vendor/agent-root/src/agent/tool/__test__/path-security.test.ts +336 -0
- package/vendor/agent-root/src/agent/tool/__test__/skill-loader.test.ts +494 -0
- package/vendor/agent-root/src/agent/tool/__test__/skill-parser.test.ts +543 -0
- package/vendor/agent-root/src/agent/tool/__test__/skill-tool.test.ts +172 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-concurrency-and-version.test.ts +116 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-create-get-list-update.test.ts +267 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-create.test.ts +519 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-errors.test.ts +225 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-output-blocking.test.ts +223 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-output.test.ts +184 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-parent-abort.test.ts +287 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-real-runner-adapter.test.ts +190 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-run-lifecycle.test.ts +352 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-store-runner-branches.test.ts +395 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-store.test.ts +391 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config-integration.test.ts +176 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config.test.ts +68 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-tools-core-edges.test.ts +630 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-tools-runtime-edges.test.ts +732 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-types.test.ts +494 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-utils-branches.test.ts +175 -0
- package/vendor/agent-root/src/agent/tool/__test__/tool-manager.test.ts +505 -0
- package/vendor/agent-root/src/agent/tool/__test__/types.test.ts +55 -0
- package/vendor/agent-root/src/agent/tool/__test__/web-fetch.test.ts +244 -0
- package/vendor/agent-root/src/agent/tool/__test__/web-search.test.ts +290 -0
- package/vendor/agent-root/src/agent/tool/__test__/write-file.test.ts +368 -0
- package/vendor/agent-root/src/agent/tool/base-tool.ts +345 -0
- package/vendor/agent-root/src/agent/tool/bash-policy.ts +636 -0
- package/vendor/agent-root/src/agent/tool/bash.ts +688 -0
- package/vendor/agent-root/src/agent/tool/error.ts +131 -0
- package/vendor/agent-root/src/agent/tool/file-edit-tool.ts +264 -0
- package/vendor/agent-root/src/agent/tool/file-history-list.ts +103 -0
- package/vendor/agent-root/src/agent/tool/file-history-restore.ts +149 -0
- package/vendor/agent-root/src/agent/tool/file-read-tool.ts +211 -0
- package/vendor/agent-root/src/agent/tool/glob.ts +171 -0
- package/vendor/agent-root/src/agent/tool/grep.ts +496 -0
- package/vendor/agent-root/src/agent/tool/lsp.ts +481 -0
- package/vendor/agent-root/src/agent/tool/path-security.ts +117 -0
- package/vendor/agent-root/src/agent/tool/search/common.ts +153 -0
- package/vendor/agent-root/src/agent/tool/skill/index.ts +13 -0
- package/vendor/agent-root/src/agent/tool/skill/loader.ts +229 -0
- package/vendor/agent-root/src/agent/tool/skill/parser.ts +124 -0
- package/vendor/agent-root/src/agent/tool/skill/types.ts +27 -0
- package/vendor/agent-root/src/agent/tool/skill-tool.ts +143 -0
- package/vendor/agent-root/src/agent/tool/task-create.ts +186 -0
- package/vendor/agent-root/src/agent/tool/task-errors.ts +42 -0
- package/vendor/agent-root/src/agent/tool/task-get.ts +116 -0
- package/vendor/agent-root/src/agent/tool/task-graph.ts +78 -0
- package/vendor/agent-root/src/agent/tool/task-list.ts +141 -0
- package/vendor/agent-root/src/agent/tool/task-mock-runner-adapter.ts +232 -0
- package/vendor/agent-root/src/agent/tool/task-output.ts +223 -0
- package/vendor/agent-root/src/agent/tool/task-parent-abort.ts +115 -0
- package/vendor/agent-root/src/agent/tool/task-real-runner-adapter.ts +336 -0
- package/vendor/agent-root/src/agent/tool/task-runner-adapter.ts +55 -0
- package/vendor/agent-root/src/agent/tool/task-stop.ts +187 -0
- package/vendor/agent-root/src/agent/tool/task-store.ts +217 -0
- package/vendor/agent-root/src/agent/tool/task-subagent-config.ts +149 -0
- package/vendor/agent-root/src/agent/tool/task-types.ts +264 -0
- package/vendor/agent-root/src/agent/tool/task-update.ts +315 -0
- package/vendor/agent-root/src/agent/tool/task.ts +209 -0
- package/vendor/agent-root/src/agent/tool/tool-manager.ts +362 -0
- package/vendor/agent-root/src/agent/tool/tool-prompts.ts +242 -0
- package/vendor/agent-root/src/agent/tool/types.ts +116 -0
- package/vendor/agent-root/src/agent/tool/web-fetch.ts +227 -0
- package/vendor/agent-root/src/agent/tool/web-search.ts +208 -0
- package/vendor/agent-root/src/agent/tool/write-file.ts +497 -0
- package/vendor/agent-root/src/agent/types.ts +232 -0
- package/vendor/agent-root/src/agent/utils/__tests__/index.test.ts +18 -0
- package/vendor/agent-root/src/agent/utils/__tests__/message-utils.test.ts +610 -0
- package/vendor/agent-root/src/agent/utils/__tests__/message.test.ts +223 -0
- package/vendor/agent-root/src/agent/utils/__tests__/token.test.ts +42 -0
- package/vendor/agent-root/src/agent/utils/index.ts +16 -0
- package/vendor/agent-root/src/agent/utils/message.ts +171 -0
- package/vendor/agent-root/src/agent/utils/token.ts +28 -0
- package/vendor/agent-root/src/config/__tests__/load-config-to-env.test.ts +129 -0
- package/vendor/agent-root/src/config/__tests__/loader.test.ts +247 -0
- package/vendor/agent-root/src/config/__tests__/runtime.test.ts +88 -0
- package/vendor/agent-root/src/config/index.ts +54 -0
- package/vendor/agent-root/src/config/loader.ts +431 -0
- package/vendor/agent-root/src/config/paths.ts +30 -0
- package/vendor/agent-root/src/config/runtime.ts +163 -0
- package/vendor/agent-root/src/config/types.ts +70 -0
- package/vendor/agent-root/src/logger/index.ts +57 -0
- package/vendor/agent-root/src/logger/logger.ts +819 -0
- package/vendor/agent-root/src/logger/types.ts +150 -0
- package/vendor/agent-root/src/providers/__tests__/errors.test.ts +441 -0
- package/vendor/agent-root/src/providers/__tests__/index.test.ts +16 -0
- package/vendor/agent-root/src/providers/__tests__/openai-compatible.options.test.ts +318 -0
- package/vendor/agent-root/src/providers/__tests__/openai-compatible.test.ts +600 -0
- package/vendor/agent-root/src/providers/__tests__/registry.test.ts +449 -0
- package/vendor/agent-root/src/providers/__tests__/responses-adapter.test.ts +298 -0
- package/vendor/agent-root/src/providers/adapters/__tests__/anthropic.test.ts +354 -0
- package/vendor/agent-root/src/providers/adapters/__tests__/kimi.test.ts +58 -0
- package/vendor/agent-root/src/providers/adapters/__tests__/standard.test.ts +261 -0
- package/vendor/agent-root/src/providers/adapters/anthropic.ts +572 -0
- package/vendor/agent-root/src/providers/adapters/base.ts +131 -0
- package/vendor/agent-root/src/providers/adapters/kimi.ts +48 -0
- package/vendor/agent-root/src/providers/adapters/responses.ts +732 -0
- package/vendor/agent-root/src/providers/adapters/standard.ts +120 -0
- package/vendor/agent-root/src/providers/http/__tests__/client.timeout.test.ts +313 -0
- package/vendor/agent-root/src/providers/http/client.ts +289 -0
- package/vendor/agent-root/src/providers/http/stream-parser.ts +109 -0
- package/vendor/agent-root/src/providers/index.ts +76 -0
- package/vendor/agent-root/src/providers/kimi-headers.ts +177 -0
- package/vendor/agent-root/src/providers/openai-compatible.ts +387 -0
- package/vendor/agent-root/src/providers/registry/model-config.ts +230 -0
- package/vendor/agent-root/src/providers/registry/provider-factory.ts +123 -0
- package/vendor/agent-root/src/providers/registry.ts +135 -0
- package/vendor/agent-root/src/providers/types/api.ts +284 -0
- package/vendor/agent-root/src/providers/types/config.ts +58 -0
- package/vendor/agent-root/src/providers/types/errors.ts +323 -0
- package/vendor/agent-root/src/providers/types/index.ts +72 -0
- package/vendor/agent-root/src/providers/types/provider.ts +45 -0
- package/vendor/agent-root/src/providers/types/registry.ts +88 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { Message } from '../../types';
|
|
3
|
+
import {
|
|
4
|
+
contentToText,
|
|
5
|
+
getAssistantToolCalls,
|
|
6
|
+
getToolCallId,
|
|
7
|
+
isSummaryMessage,
|
|
8
|
+
processToolCallPairs,
|
|
9
|
+
rebuildMessages,
|
|
10
|
+
splitMessages,
|
|
11
|
+
stringifyContentPart,
|
|
12
|
+
} from '../message';
|
|
13
|
+
|
|
14
|
+
function createMessage(partial: Partial<Message>): Message {
|
|
15
|
+
return {
|
|
16
|
+
messageId: partial.messageId || crypto.randomUUID(),
|
|
17
|
+
type: partial.type || 'assistant-text',
|
|
18
|
+
role: partial.role || 'assistant',
|
|
19
|
+
content: partial.content || '',
|
|
20
|
+
timestamp: partial.timestamp ?? Date.now(),
|
|
21
|
+
...partial,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('message utils', () => {
|
|
26
|
+
it('contentToText handles empty, string and multimodal content', () => {
|
|
27
|
+
expect(contentToText(undefined)).toBe('');
|
|
28
|
+
expect(contentToText('hello')).toBe('hello');
|
|
29
|
+
|
|
30
|
+
expect(
|
|
31
|
+
contentToText([
|
|
32
|
+
{ type: 'text', text: 'line1' },
|
|
33
|
+
{ type: 'image_url', image_url: { url: 'http://img' } },
|
|
34
|
+
{ type: 'file', file: { filename: 'a.txt' } },
|
|
35
|
+
{ type: 'input_audio', input_audio: { data: 'x', format: 'mp3' } },
|
|
36
|
+
{ type: 'input_video', input_video: { file_id: 'v1' } },
|
|
37
|
+
])
|
|
38
|
+
).toBe('line1\n[image] http://img\n[file] a.txt\n[audio]\n[video] v1');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('stringifyContentPart returns empty string for unknown part', () => {
|
|
42
|
+
expect(stringifyContentPart({ type: 'text', text: 'x' })).toBe('x');
|
|
43
|
+
expect(stringifyContentPart({ type: 'image_url', image_url: { url: 'u' } })).toBe('[image] u');
|
|
44
|
+
expect(stringifyContentPart({ type: 'file', file: { file_id: 'f1' } })).toBe('[file] f1');
|
|
45
|
+
expect(
|
|
46
|
+
stringifyContentPart({ type: 'input_audio', input_audio: { data: 'd', format: 'wav' } })
|
|
47
|
+
).toBe('[audio]');
|
|
48
|
+
expect(stringifyContentPart({ type: 'input_video', input_video: { url: 'v' } })).toBe(
|
|
49
|
+
'[video] v'
|
|
50
|
+
);
|
|
51
|
+
expect(stringifyContentPart({ type: 'unknown' } as never)).toBe('');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('assistant tool call and tool_call_id helpers return expected values', () => {
|
|
55
|
+
const assistantWithCalls = createMessage({
|
|
56
|
+
role: 'assistant',
|
|
57
|
+
type: 'tool-call',
|
|
58
|
+
tool_calls: [
|
|
59
|
+
{ id: 'call_1', type: 'function', index: 0, function: { name: 'x', arguments: '{}' } },
|
|
60
|
+
{ id: 'call_2', type: 'function', index: 1, function: { name: 'y', arguments: '{}' } },
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
const toolMessage = createMessage({
|
|
64
|
+
role: 'tool',
|
|
65
|
+
type: 'tool-result',
|
|
66
|
+
tool_call_id: 'call_1',
|
|
67
|
+
content: 'ok',
|
|
68
|
+
});
|
|
69
|
+
const userMessage = createMessage({ role: 'user', type: 'user', content: 'u' });
|
|
70
|
+
|
|
71
|
+
expect(getAssistantToolCalls(assistantWithCalls)).toEqual([{ id: 'call_1' }, { id: 'call_2' }]);
|
|
72
|
+
expect(getAssistantToolCalls(userMessage)).toEqual([]);
|
|
73
|
+
expect(getToolCallId(toolMessage)).toBe('call_1');
|
|
74
|
+
expect(getToolCallId(userMessage)).toBeUndefined();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('recognizes summary message prefixes', () => {
|
|
78
|
+
expect(
|
|
79
|
+
isSummaryMessage(
|
|
80
|
+
createMessage({
|
|
81
|
+
role: 'assistant',
|
|
82
|
+
type: 'summary',
|
|
83
|
+
content: '[Conversation Summary]\nabc',
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
).toBe(true);
|
|
87
|
+
expect(
|
|
88
|
+
isSummaryMessage(
|
|
89
|
+
createMessage({
|
|
90
|
+
role: 'assistant',
|
|
91
|
+
type: 'summary',
|
|
92
|
+
content: '[对话摘要]\nabc',
|
|
93
|
+
})
|
|
94
|
+
)
|
|
95
|
+
).toBe(true);
|
|
96
|
+
expect(
|
|
97
|
+
isSummaryMessage(
|
|
98
|
+
createMessage({ role: 'assistant', type: 'assistant-text', content: 'normal' })
|
|
99
|
+
)
|
|
100
|
+
).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('splitMessages preserves system and adjusts split point to last user', () => {
|
|
104
|
+
const messages: Message[] = [
|
|
105
|
+
createMessage({
|
|
106
|
+
messageId: 's',
|
|
107
|
+
type: 'system',
|
|
108
|
+
role: 'system',
|
|
109
|
+
content: 'sys',
|
|
110
|
+
timestamp: 1,
|
|
111
|
+
}),
|
|
112
|
+
createMessage({
|
|
113
|
+
messageId: 'a0',
|
|
114
|
+
type: 'assistant-text',
|
|
115
|
+
role: 'assistant',
|
|
116
|
+
content: 'a0',
|
|
117
|
+
timestamp: 2,
|
|
118
|
+
}),
|
|
119
|
+
createMessage({ messageId: 'u1', type: 'user', role: 'user', content: 'u1', timestamp: 3 }),
|
|
120
|
+
createMessage({
|
|
121
|
+
messageId: 'a2',
|
|
122
|
+
type: 'assistant-text',
|
|
123
|
+
role: 'assistant',
|
|
124
|
+
content: 'a2',
|
|
125
|
+
timestamp: 4,
|
|
126
|
+
}),
|
|
127
|
+
createMessage({
|
|
128
|
+
messageId: 'a3',
|
|
129
|
+
type: 'assistant-text',
|
|
130
|
+
role: 'assistant',
|
|
131
|
+
content: 'a3',
|
|
132
|
+
timestamp: 5,
|
|
133
|
+
}),
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
const result = splitMessages(messages, 1);
|
|
137
|
+
expect(result.systemMessage?.messageId).toBe('s');
|
|
138
|
+
expect(result.pending.map((m) => m.messageId)).toEqual(['a0']);
|
|
139
|
+
expect(result.active.map((m) => m.messageId)).toEqual(['u1', 'a2', 'a3']);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('processToolCallPairs keeps assistant/tool pairs together', () => {
|
|
143
|
+
const assistantPending = createMessage({
|
|
144
|
+
messageId: 'a_pending',
|
|
145
|
+
role: 'assistant',
|
|
146
|
+
type: 'tool-call',
|
|
147
|
+
tool_calls: [
|
|
148
|
+
{ id: 'c1', type: 'function', index: 0, function: { name: 'bash', arguments: '{}' } },
|
|
149
|
+
],
|
|
150
|
+
});
|
|
151
|
+
const pendingTool = createMessage({
|
|
152
|
+
messageId: 't_pending',
|
|
153
|
+
role: 'tool',
|
|
154
|
+
type: 'tool-result',
|
|
155
|
+
tool_call_id: 'c1',
|
|
156
|
+
content: 'pending',
|
|
157
|
+
});
|
|
158
|
+
const pendingUser = createMessage({
|
|
159
|
+
messageId: 'u_pending',
|
|
160
|
+
role: 'user',
|
|
161
|
+
type: 'user',
|
|
162
|
+
content: 'u',
|
|
163
|
+
});
|
|
164
|
+
const activeTool = createMessage({
|
|
165
|
+
messageId: 't_active',
|
|
166
|
+
role: 'tool',
|
|
167
|
+
type: 'tool-result',
|
|
168
|
+
tool_call_id: 'c1',
|
|
169
|
+
content: 'active',
|
|
170
|
+
});
|
|
171
|
+
const activeUser = createMessage({
|
|
172
|
+
messageId: 'u_active',
|
|
173
|
+
role: 'user',
|
|
174
|
+
type: 'user',
|
|
175
|
+
content: 'u2',
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const result = processToolCallPairs(
|
|
179
|
+
[assistantPending, pendingTool, pendingUser],
|
|
180
|
+
[activeTool, activeUser]
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
expect(result.pending.map((m) => m.messageId)).toEqual(['u_pending']);
|
|
184
|
+
expect(result.active.map((m) => m.messageId)).toEqual(['a_pending', 't_active', 'u_active']);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('processToolCallPairs returns original arrays when no active tools need pairing', () => {
|
|
188
|
+
const pending = [createMessage({ messageId: 'p1', role: 'user', type: 'user', content: 'p1' })];
|
|
189
|
+
const active = [
|
|
190
|
+
createMessage({ messageId: 'a1', role: 'assistant', type: 'assistant-text', content: 'a1' }),
|
|
191
|
+
];
|
|
192
|
+
const result = processToolCallPairs(pending, active);
|
|
193
|
+
expect(result.pending).toBe(pending);
|
|
194
|
+
expect(result.active).toBe(active);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('rebuildMessages combines system, summary and active messages in order', () => {
|
|
198
|
+
const system = createMessage({
|
|
199
|
+
messageId: 's',
|
|
200
|
+
role: 'system',
|
|
201
|
+
type: 'system',
|
|
202
|
+
content: 'sys',
|
|
203
|
+
});
|
|
204
|
+
const summary = createMessage({
|
|
205
|
+
messageId: 'sum',
|
|
206
|
+
role: 'assistant',
|
|
207
|
+
type: 'summary',
|
|
208
|
+
content: 'summary',
|
|
209
|
+
});
|
|
210
|
+
const active = [
|
|
211
|
+
createMessage({ messageId: 'u1', role: 'user', type: 'user', content: 'u1' }),
|
|
212
|
+
createMessage({ messageId: 'a1', role: 'assistant', type: 'assistant-text', content: 'a1' }),
|
|
213
|
+
];
|
|
214
|
+
|
|
215
|
+
expect(rebuildMessages(system, summary, active).map((m) => m.messageId)).toEqual([
|
|
216
|
+
's',
|
|
217
|
+
'sum',
|
|
218
|
+
'u1',
|
|
219
|
+
'a1',
|
|
220
|
+
]);
|
|
221
|
+
expect(rebuildMessages(undefined, null, active).map((m) => m.messageId)).toEqual(['u1', 'a1']);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* estimateTokens 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
6
|
+
import { estimateTokens } from '../token';
|
|
7
|
+
|
|
8
|
+
describe('estimateTokens', () => {
|
|
9
|
+
it('should return 0 for empty string', () => {
|
|
10
|
+
expect(estimateTokens('')).toBe(0);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should return 1 for whitespace-only short text', () => {
|
|
14
|
+
expect(estimateTokens(' ')).toBe(1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should estimate English text correctly', () => {
|
|
18
|
+
const text = 'Hello world this is a test';
|
|
19
|
+
expect(estimateTokens(text)).toBe(7);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should estimate Chinese text correctly', () => {
|
|
23
|
+
const text = '你好世界这是一个测试';
|
|
24
|
+
expect(estimateTokens(text)).toBe(15);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should estimate mixed text within reasonable range', () => {
|
|
28
|
+
const text = 'Hello 你好 World 世界';
|
|
29
|
+
const tokens = estimateTokens(text);
|
|
30
|
+
expect(tokens).toBeGreaterThanOrEqual(9);
|
|
31
|
+
expect(tokens).toBeLessThanOrEqual(10);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should handle special characters', () => {
|
|
35
|
+
const text = '!@#$%^&*()';
|
|
36
|
+
expect(estimateTokens(text)).toBe(3);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should round up fractional token counts', () => {
|
|
40
|
+
expect(estimateTokens('abcde')).toBe(2);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具函数导出
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
contentToText,
|
|
7
|
+
stringifyContentPart,
|
|
8
|
+
getAssistantToolCalls,
|
|
9
|
+
getToolCallId,
|
|
10
|
+
isSummaryMessage,
|
|
11
|
+
splitMessages,
|
|
12
|
+
processToolCallPairs,
|
|
13
|
+
rebuildMessages,
|
|
14
|
+
} from './message';
|
|
15
|
+
|
|
16
|
+
export { estimateTokens } from './token';
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message utility helpers for renx.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { InputContentPart, MessageContent } from '../../providers';
|
|
6
|
+
import type { Message } from '../types';
|
|
7
|
+
|
|
8
|
+
type ToolCallLike = { id?: string };
|
|
9
|
+
|
|
10
|
+
export function contentToText(content: MessageContent | undefined): string {
|
|
11
|
+
if (!content) return '';
|
|
12
|
+
if (typeof content === 'string') return content;
|
|
13
|
+
if (!Array.isArray(content)) return '';
|
|
14
|
+
|
|
15
|
+
return content
|
|
16
|
+
.map((part) => stringifyContentPart(part))
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.join('\n');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function stringifyContentPart(part: InputContentPart): string {
|
|
22
|
+
switch (part.type) {
|
|
23
|
+
case 'text':
|
|
24
|
+
return part.text || '';
|
|
25
|
+
case 'image_url':
|
|
26
|
+
return `[image] ${part.image_url?.url || ''}`.trim();
|
|
27
|
+
case 'file':
|
|
28
|
+
return `[file] ${part.file?.filename || part.file?.file_id || ''}`.trim();
|
|
29
|
+
case 'input_audio':
|
|
30
|
+
return '[audio]';
|
|
31
|
+
case 'input_video':
|
|
32
|
+
return `[video] ${part.input_video?.url || part.input_video?.file_id || ''}`.trim();
|
|
33
|
+
default:
|
|
34
|
+
return '';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getAssistantToolCalls(message: Message): ToolCallLike[] {
|
|
39
|
+
if (message.role !== 'assistant') return [];
|
|
40
|
+
const rawToolCalls = message.tool_calls;
|
|
41
|
+
if (!Array.isArray(rawToolCalls)) return [];
|
|
42
|
+
return rawToolCalls.map((call) => ({ id: call.id }));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getToolCallId(message: Message): string | undefined {
|
|
46
|
+
if (message.role !== 'tool') return undefined;
|
|
47
|
+
const toolCallId = message.tool_call_id;
|
|
48
|
+
return typeof toolCallId === 'string' ? toolCallId : undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isSummaryMessage(message: Message): boolean {
|
|
52
|
+
const text = contentToText(message.content);
|
|
53
|
+
return text.startsWith('[Conversation Summary]') || text.startsWith('[对话摘要]');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function splitMessages(
|
|
57
|
+
messages: Message[],
|
|
58
|
+
keepMessagesNum: number
|
|
59
|
+
): {
|
|
60
|
+
systemMessage: Message | undefined;
|
|
61
|
+
pending: Message[];
|
|
62
|
+
active: Message[];
|
|
63
|
+
} {
|
|
64
|
+
const systemMessage = messages.find((m) => m.role === 'system');
|
|
65
|
+
const nonSystemMessages = messages.filter((m) => m.role !== 'system');
|
|
66
|
+
|
|
67
|
+
let lastUserIndex = -1;
|
|
68
|
+
for (let i = nonSystemMessages.length - 1; i >= 0; i--) {
|
|
69
|
+
if (nonSystemMessages[i].role === 'user') {
|
|
70
|
+
lastUserIndex = i;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let splitPoint = nonSystemMessages.length - keepMessagesNum;
|
|
76
|
+
if (lastUserIndex !== -1 && lastUserIndex < splitPoint) {
|
|
77
|
+
splitPoint = lastUserIndex;
|
|
78
|
+
}
|
|
79
|
+
splitPoint = Math.max(0, splitPoint);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
systemMessage,
|
|
83
|
+
pending: nonSystemMessages.slice(0, splitPoint),
|
|
84
|
+
active: nonSystemMessages.slice(splitPoint),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function processToolCallPairs(
|
|
89
|
+
pending: Message[],
|
|
90
|
+
active: Message[]
|
|
91
|
+
): { pending: Message[]; active: Message[] } {
|
|
92
|
+
const toolCallToAssistant = new Map<string, Message>();
|
|
93
|
+
|
|
94
|
+
for (const msg of [...pending, ...active]) {
|
|
95
|
+
for (const call of getAssistantToolCalls(msg)) {
|
|
96
|
+
if (call.id) {
|
|
97
|
+
toolCallToAssistant.set(call.id, msg);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const toolsNeedingPair = active.filter((msg) => {
|
|
103
|
+
if (msg.role !== 'tool') return false;
|
|
104
|
+
const toolCallId = getToolCallId(msg);
|
|
105
|
+
return typeof toolCallId === 'string' && toolCallToAssistant.has(toolCallId);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (toolsNeedingPair.length === 0) {
|
|
109
|
+
return { pending, active };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const assistantsToMove = new Set<Message>();
|
|
113
|
+
const toolCallIdsToMove = new Set<string>();
|
|
114
|
+
|
|
115
|
+
for (const toolMsg of toolsNeedingPair) {
|
|
116
|
+
const toolCallId = getToolCallId(toolMsg);
|
|
117
|
+
if (!toolCallId) continue;
|
|
118
|
+
const assistantMsg = toolCallToAssistant.get(toolCallId);
|
|
119
|
+
if (assistantMsg) {
|
|
120
|
+
assistantsToMove.add(assistantMsg);
|
|
121
|
+
toolCallIdsToMove.add(toolCallId);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const newPending = pending.filter((msg) => {
|
|
126
|
+
if (assistantsToMove.has(msg)) return false;
|
|
127
|
+
if (msg.role === 'tool') {
|
|
128
|
+
const toolCallId = getToolCallId(msg);
|
|
129
|
+
if (toolCallId && toolCallIdsToMove.has(toolCallId)) return false;
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const newActive: Message[] = [];
|
|
135
|
+
const addedMessages = new Set<Message>();
|
|
136
|
+
|
|
137
|
+
for (const assistantMsg of assistantsToMove) {
|
|
138
|
+
newActive.push(assistantMsg);
|
|
139
|
+
addedMessages.add(assistantMsg);
|
|
140
|
+
|
|
141
|
+
for (const call of getAssistantToolCalls(assistantMsg)) {
|
|
142
|
+
if (call.id) {
|
|
143
|
+
const toolMsg = active.find((m) => m.role === 'tool' && getToolCallId(m) === call.id);
|
|
144
|
+
if (toolMsg && !addedMessages.has(toolMsg)) {
|
|
145
|
+
newActive.push(toolMsg);
|
|
146
|
+
addedMessages.add(toolMsg);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (const msg of active) {
|
|
153
|
+
if (!addedMessages.has(msg)) {
|
|
154
|
+
newActive.push(msg);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return { pending: newPending, active: newActive };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function rebuildMessages(
|
|
162
|
+
systemMessage: Message | undefined,
|
|
163
|
+
summaryMessage: Message | null,
|
|
164
|
+
active: Message[]
|
|
165
|
+
): Message[] {
|
|
166
|
+
const messages: Message[] = [];
|
|
167
|
+
if (systemMessage) messages.push(systemMessage);
|
|
168
|
+
if (summaryMessage) messages.push(summaryMessage);
|
|
169
|
+
messages.push(...active);
|
|
170
|
+
return messages;
|
|
171
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token 估算工具
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 估算文本 Token 数
|
|
7
|
+
*
|
|
8
|
+
* 算法说明:
|
|
9
|
+
* - 中文字符(Unicode \u4e00-\u9fa5):1 字符 ≈ 1.5 token
|
|
10
|
+
* - 其他字符(英文、数字、符号等):1 字符 ≈ 0.25 token
|
|
11
|
+
*/
|
|
12
|
+
export function estimateTokens(text: string): number {
|
|
13
|
+
if (!text) return 0;
|
|
14
|
+
|
|
15
|
+
let cnCount = 0;
|
|
16
|
+
let otherCount = 0;
|
|
17
|
+
|
|
18
|
+
for (const char of text) {
|
|
19
|
+
if (char >= '\u4e00' && char <= '\u9fa5') {
|
|
20
|
+
cnCount++;
|
|
21
|
+
} else {
|
|
22
|
+
otherCount++;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const totalTokens = cnCount * 1.5 + otherCount * 0.25;
|
|
27
|
+
return Math.ceil(totalTokens);
|
|
28
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as os from 'node:os';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { loadConfigToEnv } from '../loader';
|
|
6
|
+
|
|
7
|
+
describe('loadConfigToEnv', () => {
|
|
8
|
+
let tmpDir: string;
|
|
9
|
+
let globalDir: string;
|
|
10
|
+
const originalEnv = process.env;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'renx-env-test-'));
|
|
14
|
+
globalDir = path.join(tmpDir, '.renx-global');
|
|
15
|
+
process.env = { ...originalEnv };
|
|
16
|
+
|
|
17
|
+
delete process.env.AGENT_LOG_LEVEL;
|
|
18
|
+
delete process.env.AGENT_LOG_FORMAT;
|
|
19
|
+
delete process.env.AGENT_LOG_FILE_ENABLED;
|
|
20
|
+
delete process.env.AGENT_LOG_CONSOLE;
|
|
21
|
+
delete process.env.AGENT_FILE_HISTORY_ENABLED;
|
|
22
|
+
delete process.env.AGENT_FILE_HISTORY_MAX_PER_FILE;
|
|
23
|
+
delete process.env.AGENT_FILE_HISTORY_MAX_AGE_DAYS;
|
|
24
|
+
delete process.env.AGENT_FILE_HISTORY_MAX_TOTAL_MB;
|
|
25
|
+
delete process.env.AGENT_TOOL_CONFIRMATION_MODE;
|
|
26
|
+
delete process.env.AGENT_MODEL;
|
|
27
|
+
delete process.env.AGENT_MAX_STEPS;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
process.env = originalEnv;
|
|
32
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should load global config.json into env', () => {
|
|
36
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
37
|
+
fs.writeFileSync(
|
|
38
|
+
path.join(globalDir, 'config.json'),
|
|
39
|
+
JSON.stringify({
|
|
40
|
+
log: { level: 'DEBUG', format: 'json', file: true },
|
|
41
|
+
agent: { defaultModel: 'gpt-5.4' },
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const files = loadConfigToEnv({ projectRoot: tmpDir, globalDir });
|
|
46
|
+
|
|
47
|
+
expect(files).toHaveLength(1);
|
|
48
|
+
expect(process.env.AGENT_LOG_LEVEL).toBe('DEBUG');
|
|
49
|
+
expect(process.env.AGENT_LOG_FORMAT).toBe('json');
|
|
50
|
+
expect(process.env.AGENT_LOG_FILE_ENABLED).toBe('true');
|
|
51
|
+
expect(process.env.AGENT_MODEL).toBe('gpt-5.4');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should load project config.json over global', () => {
|
|
55
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
56
|
+
fs.writeFileSync(
|
|
57
|
+
path.join(globalDir, 'config.json'),
|
|
58
|
+
JSON.stringify({ log: { level: 'INFO' }, agent: { defaultModel: 'glm-5' } })
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const projectConfigDir = path.join(tmpDir, '.renx');
|
|
62
|
+
fs.mkdirSync(projectConfigDir, { recursive: true });
|
|
63
|
+
fs.writeFileSync(
|
|
64
|
+
path.join(projectConfigDir, 'config.json'),
|
|
65
|
+
JSON.stringify({ log: { level: 'ERROR' }, agent: { defaultModel: 'gpt-5.3' } })
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const files = loadConfigToEnv({ projectRoot: tmpDir, globalDir });
|
|
69
|
+
|
|
70
|
+
expect(files).toHaveLength(2);
|
|
71
|
+
expect(process.env.AGENT_LOG_LEVEL).toBe('ERROR');
|
|
72
|
+
expect(process.env.AGENT_MODEL).toBe('gpt-5.3');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should not override existing env vars', () => {
|
|
76
|
+
process.env.AGENT_LOG_LEVEL = 'WARN';
|
|
77
|
+
|
|
78
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
79
|
+
fs.writeFileSync(
|
|
80
|
+
path.join(globalDir, 'config.json'),
|
|
81
|
+
JSON.stringify({ log: { level: 'DEBUG' } })
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
loadConfigToEnv({ projectRoot: tmpDir, globalDir });
|
|
85
|
+
|
|
86
|
+
expect(process.env.AGENT_LOG_LEVEL).toBe('WARN');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should initialize global config.json when no config files exist', () => {
|
|
90
|
+
const files = loadConfigToEnv({ projectRoot: tmpDir, globalDir });
|
|
91
|
+
expect(files).toEqual([path.join(globalDir, 'config.json')]);
|
|
92
|
+
expect(fs.existsSync(path.join(globalDir, 'config.json'))).toBe(true);
|
|
93
|
+
expect(process.env.AGENT_MODEL).toBe('qwen3.5-plus');
|
|
94
|
+
expect(process.env.AGENT_TOOL_CONFIRMATION_MODE).toBe('manual');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should load storage config', () => {
|
|
98
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
99
|
+
fs.writeFileSync(
|
|
100
|
+
path.join(globalDir, 'config.json'),
|
|
101
|
+
JSON.stringify({
|
|
102
|
+
storage: {
|
|
103
|
+
fileHistory: { enabled: false, maxPerFile: 50 },
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
loadConfigToEnv({ projectRoot: tmpDir, globalDir });
|
|
109
|
+
|
|
110
|
+
expect(process.env.AGENT_FILE_HISTORY_ENABLED).toBe('false');
|
|
111
|
+
expect(process.env.AGENT_FILE_HISTORY_MAX_PER_FILE).toBe('50');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should load agent config', () => {
|
|
115
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
116
|
+
fs.writeFileSync(
|
|
117
|
+
path.join(globalDir, 'config.json'),
|
|
118
|
+
JSON.stringify({
|
|
119
|
+
agent: { confirmationMode: 'manual', defaultModel: 'qwen3.5-max', maxSteps: 100 },
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
loadConfigToEnv({ projectRoot: tmpDir, globalDir });
|
|
124
|
+
|
|
125
|
+
expect(process.env.AGENT_TOOL_CONFIRMATION_MODE).toBe('manual');
|
|
126
|
+
expect(process.env.AGENT_MODEL).toBe('qwen3.5-max');
|
|
127
|
+
expect(process.env.AGENT_MAX_STEPS).toBe('100');
|
|
128
|
+
});
|
|
129
|
+
});
|