@zhongqian97-code/ecode 0.0.7 → 0.0.8

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.
Files changed (2) hide show
  1. package/dist/index.js +61 -18
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10,6 +10,33 @@ import { render } from "ink";
10
10
  import { existsSync, readFileSync } from "fs";
11
11
  import { homedir } from "os";
12
12
  import { join } from "path";
13
+ var MODEL_CONTEXT_LIMITS = {
14
+ "gpt-4o": 128e3,
15
+ "gpt-4o-mini": 128e3,
16
+ "gpt-4-turbo": 128e3,
17
+ "gpt-4": 8192,
18
+ "gpt-3.5-turbo": 16385,
19
+ "o1": 2e5,
20
+ "o1-mini": 128e3,
21
+ "o1-preview": 128e3,
22
+ "o3": 2e5,
23
+ "o3-mini": 2e5,
24
+ "claude-3-5-sonnet-20241022": 2e5,
25
+ "claude-3-5-haiku-20241022": 2e5,
26
+ "claude-3-opus-20240229": 2e5,
27
+ "claude-3-sonnet-20240229": 2e5,
28
+ "claude-3-haiku-20240307": 2e5,
29
+ "claude-sonnet-4-6": 2e5,
30
+ "claude-opus-4-7": 2e5,
31
+ "claude-haiku-4-5-20251001": 2e5,
32
+ "deepseek-chat": 65536,
33
+ "deepseek-reasoner": 65536
34
+ };
35
+ var DEFAULT_CONTEXT_LIMIT = 128e3;
36
+ function getContextLimit(model, override) {
37
+ if (override !== void 0) return override;
38
+ return MODEL_CONTEXT_LIMITS[model] ?? DEFAULT_CONTEXT_LIMIT;
39
+ }
13
40
  var DEFAULTS = {
14
41
  baseUrl: "https://api.openai.com/v1",
15
42
  apiKey: "",
@@ -50,7 +77,9 @@ function loadConfig() {
50
77
  // dangerousPatterns: 文件配置覆盖默认值,不支持环境变量(命令数组不适合通过环境变量传递)
51
78
  dangerousPatterns: fileConfig.dangerousPatterns ?? DEFAULTS.dangerousPatterns,
52
79
  // logDir: ECODE_LOG_DIR > 文件配置 > undefined
53
- logDir: process.env.ECODE_LOG_DIR ?? fileConfig.logDir ?? DEFAULTS.logDir
80
+ logDir: process.env.ECODE_LOG_DIR ?? fileConfig.logDir ?? DEFAULTS.logDir,
81
+ // contextLimit: 仅支持配置文件,不支持环境变量(数值类型直接在文件中配置更清晰)
82
+ contextLimit: fileConfig.contextLimit
54
83
  };
55
84
  }
56
85
 
@@ -439,6 +468,33 @@ function ToolMessage({
439
468
  truncated
440
469
  ] }) });
441
470
  }
471
+ function estimateLines(msg, expandTools) {
472
+ if (msg.role === "user") {
473
+ return Math.max(1, msg.content.split("\n").length);
474
+ }
475
+ if (msg.role === "assistant") {
476
+ const contentLines = msg.content ? msg.content.split("\n").length : 0;
477
+ const assistantMsg = msg;
478
+ let reasoningLines = 0;
479
+ if (assistantMsg.reasoning_content && assistantMsg.reasoning_content.length > 0) {
480
+ if (expandTools) {
481
+ reasoningLines = 1 + assistantMsg.reasoning_content.split("\n").length;
482
+ } else {
483
+ reasoningLines = 1;
484
+ }
485
+ }
486
+ let toolLines = 0;
487
+ if (assistantMsg.tool_calls && assistantMsg.tool_calls.length > 0) {
488
+ toolLines = expandTools ? assistantMsg.tool_calls.length : 1;
489
+ }
490
+ return Math.max(1, contentLines + reasoningLines + toolLines);
491
+ }
492
+ if (msg.role === "tool") {
493
+ if (!expandTools) return 1;
494
+ return Math.min(TOOL_RESULT_MAX_LINES, msg.content.split("\n").length) + 1;
495
+ }
496
+ return 1;
497
+ }
442
498
  function ConversationHistory({
443
499
  messages,
444
500
  maxHeight = 20,
@@ -447,24 +503,10 @@ function ConversationHistory({
447
503
  const visible = messages.filter(
448
504
  (m) => m.role !== "system"
449
505
  );
450
- function estimateLines(msg) {
451
- if (msg.role === "user") {
452
- return Math.max(1, msg.content.split("\n").length);
453
- }
454
- if (msg.role === "assistant") {
455
- const contentLines = msg.content ? msg.content.split("\n").length : 0;
456
- const toolLines = msg.tool_calls?.length ?? 0;
457
- return Math.max(1, contentLines + toolLines);
458
- }
459
- if (msg.role === "tool") {
460
- return Math.min(TOOL_RESULT_MAX_LINES, msg.content.split("\n").length) + 1;
461
- }
462
- return 1;
463
- }
464
506
  let totalLines = 0;
465
507
  let startIdx = visible.length;
466
508
  for (let i = visible.length - 1; i >= 0; i--) {
467
- const lines = estimateLines(visible[i]);
509
+ const lines = estimateLines(visible[i], expandTools);
468
510
  if (totalLines + lines > maxHeight) break;
469
511
  totalLines += lines;
470
512
  startIdx = i;
@@ -586,10 +628,11 @@ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
586
628
  function App({ config: config2, version: version2, autoMode: autoMode2 = false }) {
587
629
  const [messages, setMessages] = useState3([]);
588
630
  const [status, setStatus] = useState3("idle");
631
+ const contextLimit = getContextLimit(config2.model, config2.contextLimit);
589
632
  const [tokenUsage, setTokenUsage] = useState3({
590
633
  used: 0,
591
634
  estimated: true,
592
- limit: 128e3
635
+ limit: contextLimit
593
636
  });
594
637
  const [toolName, setToolName] = useState3(void 0);
595
638
  const [confirmPrompt, setConfirmPrompt] = useState3(void 0);
@@ -666,7 +709,7 @@ function App({ config: config2, version: version2, autoMode: autoMode2 = false }
666
709
  setTokenUsage({
667
710
  used: chunk.usage.totalTokens,
668
711
  estimated: false,
669
- limit: 128e3
712
+ limit: getContextLimit(config2.model, config2.contextLimit)
670
713
  });
671
714
  }
672
715
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhongqian97-code/ecode",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "A minimal Claude Code clone with REPL interface and bash tool calling",
5
5
  "type": "module",
6
6
  "author": "zhongqian97-code",