dgxay-code-cli 0.0.0-stage → 1.0.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.
Files changed (45) hide show
  1. package/LICENSE +674 -0
  2. package/README-zh.md +200 -0
  3. package/README.md +182 -2
  4. package/bin/dgxay.js +42 -0
  5. package/package.json +47 -4
  6. package/src/cli/ansi.js +509 -0
  7. package/src/cli/approval.js +186 -0
  8. package/src/cli/args.js +162 -0
  9. package/src/cli/command-table.js +52 -0
  10. package/src/cli/editor.js +574 -0
  11. package/src/cli/index.js +228 -0
  12. package/src/cli/print.js +148 -0
  13. package/src/cli/render.js +324 -0
  14. package/src/cli/repl-state.js +85 -0
  15. package/src/cli/repl.js +1167 -0
  16. package/src/cli/slash.js +74 -0
  17. package/src/cli/ui.js +52 -0
  18. package/src/commands/_shared.js +20 -0
  19. package/src/commands/chat.js +212 -0
  20. package/src/commands/config.js +363 -0
  21. package/src/commands/context.js +43 -0
  22. package/src/commands/doctor.js +192 -0
  23. package/src/commands/export.js +102 -0
  24. package/src/commands/mcp.js +257 -0
  25. package/src/commands/model.js +223 -0
  26. package/src/commands/oauth.js +246 -0
  27. package/src/commands/permission.js +108 -0
  28. package/src/commands/provider.js +332 -0
  29. package/src/commands/run.js +172 -0
  30. package/src/commands/skill.js +94 -0
  31. package/src/commands/workspace.js +100 -0
  32. package/src/core/agent.js +419 -0
  33. package/src/core/llm.js +709 -0
  34. package/src/core/mcp.js +271 -0
  35. package/src/core/oauth.js +737 -0
  36. package/src/core/prompt.js +269 -0
  37. package/src/core/sessions.js +208 -0
  38. package/src/core/tools.js +391 -0
  39. package/src/services/config.js +182 -0
  40. package/src/services/input.js +91 -0
  41. package/src/services/session-bus.js +104 -0
  42. package/src/services/settings.js +340 -0
  43. package/src/services/skills.js +125 -0
  44. package/src/services/terminal.js +124 -0
  45. package/src/services/version.js +25 -0
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * REPL 的运行时状态。
5
+ * 配置以「每次操作重新读取」为主,但 UI 模式 / 权限 / 工作空间 / 模型在会话内可临时覆盖,
6
+ * 用 overrides 表示;用 cfg.patchConfig() 持久化修改后再刷新覆盖值。
7
+ */
8
+
9
+ const path = require('path');
10
+ const os = require('os');
11
+
12
+ function createState() {
13
+ return {
14
+ cwd: process.cwd(),
15
+ overrides: {},
16
+ runtime: {
17
+ mode: 'chat',
18
+ permission: 'normal',
19
+ providerId: '',
20
+ modelId: '',
21
+ skill: ''
22
+ },
23
+ chat: null,
24
+ streaming: false,
25
+ abortRequested: false,
26
+ terminalBusy: false,
27
+ requestController: null,
28
+ lastResponse: null,
29
+ pendingInsert: ''
30
+ };
31
+ }
32
+
33
+ function recentWorkspaces(config) {
34
+ const list = config?.work?.recentWorkspaces || [];
35
+ return list.filter((item) => typeof item === 'string' && item.trim());
36
+ }
37
+
38
+ function activeProvider(config) {
39
+ const providers = config?.providers || [];
40
+ return providers.find((p) => p.id === config?.activeProviderId) || providers[0] || null;
41
+ }
42
+
43
+ function activeModel(config) {
44
+ const provider = activeProvider(config);
45
+ if (!provider) return null;
46
+ const models = provider.models || [];
47
+ const model = models.find((m) => m.id === config?.activeModelId) || models[0];
48
+ if (!model) return null;
49
+ return {
50
+ id: model.id,
51
+ name: model.name || model.id,
52
+ providerId: provider.id,
53
+ providerName: provider.name,
54
+ protocol: provider.protocol || 'openai',
55
+ contextWindow: Number(model.contextWindow) || 0,
56
+ reviewModelId: provider.reviewModelId || ''
57
+ };
58
+ }
59
+
60
+ function workspaceOf(state, config) {
61
+ return state.cwd || config?.work?.workspace || os.homedir();
62
+ }
63
+
64
+ function workspaceLabel(workspace) {
65
+ if (!workspace) return '未选择';
66
+ const parts = String(workspace)
67
+ .split(/[\\/]/)
68
+ .filter(Boolean);
69
+ return parts[parts.length - 1] || workspace;
70
+ }
71
+
72
+ function relativePath(base, target) {
73
+ const rel = path.relative(base, target);
74
+ return rel === '' ? '.' : rel;
75
+ }
76
+
77
+ module.exports = {
78
+ createState,
79
+ recentWorkspaces,
80
+ activeProvider,
81
+ activeModel,
82
+ workspaceOf,
83
+ workspaceLabel,
84
+ relativePath
85
+ };