leetcode-local-cli 0.11.0__tar.gz → 0.12.0__tar.gz

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 (60) hide show
  1. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/PKG-INFO +53 -12
  2. leetcode_local_cli-0.12.0/README.md +195 -0
  3. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/pyproject.toml +1 -1
  4. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/commands/__init__.py +2 -0
  5. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/commands/account.py +20 -1
  6. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/commands/problems.py +17 -2
  7. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/commands/rendering.py +10 -2
  8. leetcode_local_cli-0.12.0/src/leetcode_local_cli/commands/settings.py +50 -0
  9. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/commands/testing.py +29 -4
  10. leetcode_local_cli-0.12.0/src/leetcode_local_cli/execution/nodes.py +266 -0
  11. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/execution/protocol.py +8 -1
  12. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/execution/runner.py +61 -11
  13. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/execution/worker.py +28 -2
  14. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/integrations/devtools.py +2 -1
  15. leetcode_local_cli-0.12.0/src/leetcode_local_cli/integrations/editor.py +47 -0
  16. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/integrations/leetcode.py +43 -3
  17. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/integrations/problem_parser.py +30 -5
  18. leetcode_local_cli-0.12.0/src/leetcode_local_cli/models/editor.py +20 -0
  19. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/models/execution.py +11 -0
  20. leetcode_local_cli-0.12.0/src/leetcode_local_cli/models/nodes.py +16 -0
  21. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/models/result.py +2 -0
  22. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/storage/config.py +80 -19
  23. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/storage/solution.py +65 -19
  24. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/common.py +4 -0
  25. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/diagnostics.py +1 -1
  26. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/doctor_checks.py +17 -0
  27. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/local_test.py +21 -4
  28. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/login.py +41 -9
  29. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/problems.py +7 -2
  30. leetcode_local_cli-0.12.0/src/leetcode_local_cli/use_cases/settings.py +54 -0
  31. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/setup.py +17 -5
  32. leetcode_local_cli-0.11.0/README.md +0 -154
  33. leetcode_local_cli-0.11.0/src/leetcode_local_cli/integrations/editor.py +0 -23
  34. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/LICENSE +0 -0
  35. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/__init__.py +0 -0
  36. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/__main__.py +0 -0
  37. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/cli.py +0 -0
  38. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/commands/common.py +0 -0
  39. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/commands/setup.py +0 -0
  40. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/commands/submission.py +0 -0
  41. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/execution/__init__.py +0 -0
  42. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/integrations/__init__.py +0 -0
  43. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/integrations/browser.py +0 -0
  44. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/models/__init__.py +0 -0
  45. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/models/account.py +0 -0
  46. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/models/diagnostics.py +0 -0
  47. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/models/problem.py +0 -0
  48. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/models/session.py +0 -0
  49. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/models/solution.py +0 -0
  50. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/models/submission.py +0 -0
  51. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/storage/__init__.py +0 -0
  52. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/storage/paths.py +0 -0
  53. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/storage/safe_files.py +0 -0
  54. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/storage/session.py +0 -0
  55. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/storage/solution_source.py +0 -0
  56. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/__init__.py +0 -0
  57. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/account.py +0 -0
  58. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/errors.py +0 -0
  59. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/use_cases/submission.py +0 -0
  60. {leetcode_local_cli-0.11.0 → leetcode_local_cli-0.12.0}/src/leetcode_local_cli/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: leetcode-local-cli
3
- Version: 0.11.0
3
+ Version: 0.12.0
4
4
  Summary: Local coding workflow CLI for LeetCode CN.
5
5
  Keywords: cli,leetcode,leetcode-cn,uv
6
6
  Author: Aetherialter
@@ -26,7 +26,7 @@ Description-Content-Type: text/markdown
26
26
 
27
27
  面向 LeetCode 中文站的轻量本地刷题 CLI:配置一个工作区,通过 Chrome、Edge 或手动 Cookie 登录,在线获取题目,在 `solution.py` 中解题并进行本地调用、诊断和远程提交。
28
28
 
29
- 本文对应版本:`v0.11.0`。发布记录见 [GitHub Releases](https://github.com/Aetherialter/leetcode-local-cli/releases)。
29
+ 本文对应版本:`v0.12.0`。发布记录见 [GitHub Releases](https://github.com/Aetherialter/leetcode-local-cli/releases)。
30
30
 
31
31
  开发本地源码使用 `uv sync --locked --all-groups`,随后用 `uv run lc ...`;未激活虚拟环境或安装全局工具时,裸 `lc` 不一定可用。
32
32
 
@@ -37,13 +37,13 @@ Description-Content-Type: text/markdown
37
37
  Linux / macOS:
38
38
 
39
39
  ```bash
40
- curl -LsSf https://raw.githubusercontent.com/Aetherialter/leetcode-local-cli/v0.11.0/scripts/install.sh | sh
40
+ curl -LsSf https://raw.githubusercontent.com/Aetherialter/leetcode-local-cli/v0.12.0/scripts/install.sh | sh
41
41
  ```
42
42
 
43
43
  Windows PowerShell:
44
44
 
45
45
  ```powershell
46
- powershell -ExecutionPolicy ByPass -Command "irm https://raw.githubusercontent.com/Aetherialter/leetcode-local-cli/v0.11.0/scripts/install.ps1 | iex"
46
+ powershell -ExecutionPolicy ByPass -Command "irm https://raw.githubusercontent.com/Aetherialter/leetcode-local-cli/v0.12.0/scripts/install.ps1 | iex"
47
47
  ```
48
48
 
49
49
  也可以直接安装并初始化:
@@ -76,6 +76,7 @@ lc status
76
76
  lc profile
77
77
  lc show
78
78
  lc get 1
79
+ lc config editor zed
79
80
  lc init
80
81
  lc doctor
81
82
  lc solve 1
@@ -98,17 +99,19 @@ lc check <Submission ID>
98
99
  | `lc login --browser chrome\|edge` | 只使用指定浏览器,失败后进入手动登录 |
99
100
  | `lc status` / `lc profile` | 检查登录态或展示账号信息 |
100
101
  | `lc show` / `lc get <题号>` | 查看题目列表或详情 |
101
- | `lc solve <题号>` | 生成并打开 `solution.py` |
102
+ | `lc config editor [程序] [--arg=参数]` | 查看或设置用户编辑器;`--arg` 可重复,`--clear` 移除设置 |
103
+ | `lc solve <题号> [--editor 程序]` | 生成 `solution.py`,使用已配置或临时指定的编辑器 |
102
104
  | `lc solve <题号> --no-open` | 只保存解法,不请求打开编辑器 |
103
105
  | `lc test [--timeout 秒数]` | 交互调用 `Solution` 的首个公开方法 |
104
106
  | `lc test --stdin` | JSON Lines 模式,适合 AI 或 CI |
107
+ | `lc test --verbose` | 显示完整异常调用栈;也可配合 `--stdin` |
105
108
  | `lc doctor [--run-solution]` | 检查工作区、Session 和网络;可选择执行解法 |
106
109
  | `lc submit [--wait-timeout 秒数]` | 提交 marker 区域并限时等待判题;仅 Accepted 返回 0 |
107
110
  | `lc check <Submission ID>` | 查询一次已有提交的当前状态,不会重新提交代码 |
108
111
 
109
- `login`、`status`、`profile`、`show`、`get`、`check` 和不带 `--run-solution` 的 `doctor` 不要求先初始化工作区。账号和题目命令需要有效 Session;`doctor` 在 Session 缺失时仍会诊断并返回失败。`solve`、`test`、`submit` 和 `doctor --run-solution` 需要已配置的工作区。
112
+ `config editor`、`login`、`status`、`profile`、`show`、`get`、`check` 和不带 `--run-solution` 的 `doctor` 不要求先初始化工作区。`status`、`profile`、`show`、`get`、`solve`、`submit` 和 `check` 都需要本地存在格式完整的 `session.json`;其中题目命令(`show`、`get`、`solve`)不预先验证远端登录态,公开题目查询成功不能证明当前登录仍有效。如需确认远端登录状态及当前 Cookie 实际对应的账号,请使用 `lc status`、`lc profile` 或 `lc doctor`(浏览器当前登录账号、`session.json` 记录的用户名,以及 Cookie 实际对应的远端账号可能不一致)。`doctor` 在 Session 缺失时仍会诊断并返回失败。`solve`、`test`、`submit` 和 `doctor --run-solution` 需要已配置的工作区。
110
113
 
111
- 解法保存成功但系统无法打开文件时,`solve` 显示保存路径和警告,仍返回 0;写入失败则返回 1,并且不打开文件。
114
+ 解法保存成功但未配置编辑器或启动失败时,`solve` 显示保存路径和警告,仍返回 0;写入失败则返回 1,并且不打开文件。
112
115
 
113
116
  用户配置或 marker 损坏时,普通 `init` 不覆盖它们。明确修复目标后执行:
114
117
 
@@ -118,6 +121,27 @@ uv run lc init D:/Projects/leetcode-local-cli --repair --yes
118
121
 
119
122
  修复前会在损坏文件旁创建 `原文件名.<随机标识>.bak`,保留原始字节。后续失败会尝试回滚本次文件变化,已创建的备份保留供恢复;版本、站点或语言不受支持,以及链接或权限问题,不会被 `--repair` 强行覆盖。
120
123
 
124
+ ## 编辑器配置
125
+
126
+ 编辑器属于当前用户的个人设置,存入用户配置目录的 `config.toml`,不存入工作区 marker 或 Session。尚未初始化时也可设置;之后初始化或切换默认工作区会保留它。
127
+
128
+ 用户配置格式现为 v2,工作区 marker 仍为 v1,Session 格式不变。已有 v1 用户配置(含内测编辑器设置)可继续读取,读取不改写文件;显式设置/清除编辑器或执行 `init` 时才保存为 v2。也可用 `lc config editor zed` 保存并升级。升级后旧版 `lc` 会拒绝该配置,不能用旧版 `init --repair` 降级。
129
+
130
+ ```shell
131
+ lc config editor zed
132
+ lc config editor code --arg=--reuse-window
133
+ lc config editor
134
+ lc solve 1 --editor zed
135
+ lc solve 1 --no-open
136
+ lc config editor --clear
137
+ ```
138
+
139
+ `zed`、`code` 和别名 `vscode` 从 PATH 查找,也可指定可执行文件绝对路径。可重复的 `--arg` 按参数数组原样传递,路径最后追加;不支持 Shell 命令串或文件占位符。配置不自动安装编辑器。
140
+
141
+ 优先级为:`--no-open` 禁止打开(并跳过 `--editor` 校验);否则 `--editor` 覆盖用户配置,且不继承旧编辑器的参数(非法 `--editor` 参数按用法错误返回退出码 2);没有临时参数时使用用户设置。不增加工作区或环境变量覆盖层。
142
+
143
+ 未配置时只保存并提示,不使用系统 `.py` 文件关联,避免关联到 Python/uv 后意外执行代码。显式配置失败也不静默回退。Windows 的 VS Code 标准 `code.cmd` 入口会解析为安装目录的 `Code.exe`,其他 `.cmd`/`.bat` 编辑器入口拒绝执行。启动后短时间内非零退出会警告;GUI 持续运行视为请求已发出,不强行终止,也不保证窗口一定可见。
144
+
121
145
  ## 浏览器登录
122
146
 
123
147
  首次使用浏览器自动登录前:
@@ -127,9 +151,9 @@ uv run lc init D:/Projects/leetcode-local-cli --repair --yes
127
151
  3. CLI 优先尝试日常 Chrome,再尝试日常 Edge;如果设置页面没有自动显示,请手动打开上述地址。
128
152
  4. 出现 **Allow remote debugging?** 连接确认框时选择 **Allow**,并保持 LeetCode 页面已登录。
129
153
  5. CLI 只获取 `leetcode.cn` 的 `LEETCODE_SESSION` 和 `csrftoken`,在线验证后保存。
130
- 6. 自动登录失败时,回退到隐藏输入的手动 Cookie。
154
+ 6. 自动登录失败时,在交互式终端中回退到隐藏输入的手动 Cookie;若处于管道、后台脚本等非交互式终端,则立即提示并返回退出码 1,不阻塞等待输入、不从管道读取明文 Cookie,也不破坏已有 `session.json`。
131
155
 
132
- CLI 不读取或解密浏览器 Cookie 数据库,不创建专用 profile,也不关闭日常浏览器。授权等待上限为 180 秒。
156
+ CLI 不读取或解密浏览器 Cookie 数据库,不创建专用 profile,也不关闭日常浏览器。单次浏览器尝试共享 180 秒单调时钟预算(涵盖连接、授权等待、重试与 Cookie 轮询,不含连接关闭超时与随后的在线账号校验)。
133
157
 
134
158
  ## 本地调用
135
159
 
@@ -139,7 +163,20 @@ CLI 不读取或解密浏览器 Cookie 数据库,不创建专用 profile,也
139
163
  参数 > nums = [3, 2, 4], target = 6
140
164
  ```
141
165
 
142
- 连续两次回车退出。每组默认限时 1 秒;无输入、参数错误、异常或超时返回退出码 1。退出码 0 只表示调用正常完成,不代表算法正确。链表和二叉树暂不自动转换。
166
+ 连续两次回车退出。每组默认限时 1 秒;无输入、参数错误、异常或超时返回退出码 1。退出码 0 只表示调用正常完成,不代表算法正确。
167
+
168
+ 支持按入口类型注解转换节点:`ListNode`、`TreeNode`、`Optional[...]`、`... | None`,以及相应的字符串注解。普通 `list` 保持列表含义,不根据参数名猜类型;节点参数缺少注解时请补齐。嵌套节点集合及混合节点类型注解会明确拒绝。
169
+
170
+ 启用 `from __future__ import annotations` 不改变这些规则,`list["ListNode"]` 同样拒绝。`Literal["ListNode"]` 中的字符串是取值,`Annotated[int, "ListNode"]` 中的字符串是元数据,均不触发节点转换;`Annotated[ListNode, ...]` 等节点包装暂不支持。
171
+
172
+ ```text
173
+ l1 = [2,4,3], l2 = [5,6,4]
174
+ root = [1,null,2,3]
175
+ ```
176
+
177
+ 链表用整数数组;树用力扣式层序数组,`null` 与 `None` 都表示空位(字符串 `"null"` 不受影响)。空数组或 `null`/`None` 表示空节点;树中无法连接到根的非空值会被拒绝。返回节点转换回同类数组,树尾多余空位移除;有节点返回注解时空节点输出 `[]`。普通方法返回 `None` 时,展示调用后的参数,节点参数也转回数组。
178
+
179
+ 生成模板提供位于提交区域外的本地节点定义,不将这些辅助定义发送给 LeetCode。第一版只支持整数节点的无环单链表和普通二叉树,不支持环、共享节点身份、随机指针、N 叉树、嵌套节点集合及设计题多方法调用。单个节点数组输入最多 100,000 项,输出最多 100,000 个节点;超过限制明确失败,不截断为成功。
143
180
 
144
181
  非交互示例:
145
182
 
@@ -149,9 +186,13 @@ printf 'nums = [3, 2, 4], target = 6\n' | lc test --stdin
149
186
 
150
187
  `--stdin` 的运行时启动失败(包括未初始化工作区)也输出 JSON Lines,包含 `kind: startup_error`、稳定的 `code` 和中文 `error`,退出码为 1。非法 CLI 参数仍使用标准用法错误,退出码为 2。
151
188
 
152
- `lc submit` 取得 submission ID 后默认等待判题 30 秒。判题查询只在总预算内有限重试;初始提交 POST 不自动重试,避免重复提交。等待超时或查询失败时会保留 submission ID,并返回退出码 1。
189
+ 异常默认显示类型、原因和可定位的 `solution.py` 行号,并保留 stdout/stderr;`--verbose` 增加完整调用栈,不采集局部变量。JSON 模式通过 `error_line` 和可选 `traceback` 字段表达,不混入 Rich 文本。调用栈仍可能包含源码片段、路径及异常内容,共享前请自行检查。
190
+
191
+ 某组超时后,下一组会重启 worker;若重新加载失败,该组报告失败并保留行号及可选调用栈,后续输入仍可继续尝试。
192
+
193
+ `lc submit` 取得 submission ID 后默认等待判题 30 秒。判题查询只在总预算内有限重试;初始提交 POST 不自动重试,避免重复提交。遇到明确认证失效(HTTP 401 或已确认 GraphQL 鉴权错误码)会提示执行 `lc login`;遇到权限拒绝(HTTP 403 或对应权限错误码)会提示检查账号权限或登录状态。等待超时或查询失败时会保留 submission ID,并返回退出码 1。
153
194
 
154
- 等待超时后可执行 `lc check <Submission ID>` 重新查询。该命令只请求一次:已经判题则展示结果,仍在判题则提示稍后重试;只有结果为 Accepted 时返回退出码 0。
195
+ 等待超时后可执行 `lc check <Submission ID>` 重新查询。该命令只请求一次:已经判题则展示结果;若服务端返回未完成中间态(对仍在处理、跨账号不可见或不存在的提交,接口可能返回相同状态),CLI 会提示暂未取得可确认的判题结果,请确认提交 ID 和当前账号,并返回退出码 1(若提交确仍在处理可稍后重查);只有结果为 Accepted 时返回退出码 0。
155
196
 
156
197
  ## 安全与限制
157
198
 
@@ -0,0 +1,195 @@
1
+ # leetcode-local-cli
2
+
3
+ 面向 LeetCode 中文站的轻量本地刷题 CLI:配置一个工作区,通过 Chrome、Edge 或手动 Cookie 登录,在线获取题目,在 `solution.py` 中解题并进行本地调用、诊断和远程提交。
4
+
5
+ 本文对应版本:`v0.12.0`。发布记录见 [GitHub Releases](https://github.com/Aetherialter/leetcode-local-cli/releases)。
6
+
7
+ 开发本地源码使用 `uv sync --locked --all-groups`,随后用 `uv run lc ...`;未激活虚拟环境或安装全局工具时,裸 `lc` 不一定可用。
8
+
9
+ ## 安装
10
+
11
+ 需要 Python 3.12+、[uv](https://docs.astral.sh/uv/) 和 Chrome 或 Microsoft Edge。
12
+
13
+ Linux / macOS:
14
+
15
+ ```bash
16
+ curl -LsSf https://raw.githubusercontent.com/Aetherialter/leetcode-local-cli/v0.12.0/scripts/install.sh | sh
17
+ ```
18
+
19
+ Windows PowerShell:
20
+
21
+ ```powershell
22
+ powershell -ExecutionPolicy ByPass -Command "irm https://raw.githubusercontent.com/Aetherialter/leetcode-local-cli/v0.12.0/scripts/install.ps1 | iex"
23
+ ```
24
+
25
+ 也可以直接安装并初始化:
26
+
27
+ ```shell
28
+ uv tool install leetcode-local-cli
29
+ lc init
30
+ ```
31
+
32
+ 自动化验收可以显式指定完整工作区路径:
33
+
34
+ ```shell
35
+ lc init D:/Projects/leetcode-local-cli --yes
36
+ ```
37
+
38
+ 升级或卸载:
39
+
40
+ ```shell
41
+ uv tool upgrade leetcode-local-cli
42
+ uv tool uninstall leetcode-local-cli
43
+ ```
44
+
45
+ 从 `0.10.x` 或更早版本升级后,请重新执行 `lc login`,并用 `lc init <原工作区完整路径> --yes` 注册工作区;已有普通 `solution.py` 会保留。旧工作区 Session 和根目录 `.leetcode-local-cli.toml` 不自动读取或迁移。旧凭据应由用户自行安全清理,不要提交或同步。
46
+
47
+ ## 快速开始
48
+
49
+ ```shell
50
+ lc login
51
+ lc status
52
+ lc profile
53
+ lc show
54
+ lc get 1
55
+ lc config editor zed
56
+ lc init
57
+ lc doctor
58
+ lc solve 1
59
+ lc test
60
+ lc submit
61
+ lc check <Submission ID>
62
+ ```
63
+
64
+ `lc solve` 会覆盖默认工作区中的普通 `solution.py`,切题前请自行保存解法。符号链接、目录、junction 和其他 reparse point 会被拒绝。
65
+
66
+ 生成模板用 `raise NotImplementedError("请实现题目方法")` 标记待实现方法;开始解题后将它替换为实际返回逻辑。
67
+
68
+ ## 命令
69
+
70
+ | 命令 | 作用 |
71
+ | --- | --- |
72
+ | `lc init [path]` | 配置或复用默认工作区;显式路径是完整工作区路径 |
73
+ | `lc init <path> --repair` | 先备份,再恢复损坏的用户配置和目标工作区 marker;保留解法 |
74
+ | `lc login` | 依次尝试 Chrome、Edge 和手动 Cookie |
75
+ | `lc login --browser chrome\|edge` | 只使用指定浏览器,失败后进入手动登录 |
76
+ | `lc status` / `lc profile` | 检查登录态或展示账号信息 |
77
+ | `lc show` / `lc get <题号>` | 查看题目列表或详情 |
78
+ | `lc config editor [程序] [--arg=参数]` | 查看或设置用户编辑器;`--arg` 可重复,`--clear` 移除设置 |
79
+ | `lc solve <题号> [--editor 程序]` | 生成 `solution.py`,使用已配置或临时指定的编辑器 |
80
+ | `lc solve <题号> --no-open` | 只保存解法,不请求打开编辑器 |
81
+ | `lc test [--timeout 秒数]` | 交互调用 `Solution` 的首个公开方法 |
82
+ | `lc test --stdin` | JSON Lines 模式,适合 AI 或 CI |
83
+ | `lc test --verbose` | 显示完整异常调用栈;也可配合 `--stdin` |
84
+ | `lc doctor [--run-solution]` | 检查工作区、Session 和网络;可选择执行解法 |
85
+ | `lc submit [--wait-timeout 秒数]` | 提交 marker 区域并限时等待判题;仅 Accepted 返回 0 |
86
+ | `lc check <Submission ID>` | 查询一次已有提交的当前状态,不会重新提交代码 |
87
+
88
+ `config editor`、`login`、`status`、`profile`、`show`、`get`、`check` 和不带 `--run-solution` 的 `doctor` 不要求先初始化工作区。`status`、`profile`、`show`、`get`、`solve`、`submit` 和 `check` 都需要本地存在格式完整的 `session.json`;其中题目命令(`show`、`get`、`solve`)不预先验证远端登录态,公开题目查询成功不能证明当前登录仍有效。如需确认远端登录状态及当前 Cookie 实际对应的账号,请使用 `lc status`、`lc profile` 或 `lc doctor`(浏览器当前登录账号、`session.json` 记录的用户名,以及 Cookie 实际对应的远端账号可能不一致)。`doctor` 在 Session 缺失时仍会诊断并返回失败。`solve`、`test`、`submit` 和 `doctor --run-solution` 需要已配置的工作区。
89
+
90
+ 解法保存成功但未配置编辑器或启动失败时,`solve` 显示保存路径和警告,仍返回 0;写入失败则返回 1,并且不打开文件。
91
+
92
+ 用户配置或 marker 损坏时,普通 `init` 不覆盖它们。明确修复目标后执行:
93
+
94
+ ```powershell
95
+ uv run lc init D:/Projects/leetcode-local-cli --repair --yes
96
+ ```
97
+
98
+ 修复前会在损坏文件旁创建 `原文件名.<随机标识>.bak`,保留原始字节。后续失败会尝试回滚本次文件变化,已创建的备份保留供恢复;版本、站点或语言不受支持,以及链接或权限问题,不会被 `--repair` 强行覆盖。
99
+
100
+ ## 编辑器配置
101
+
102
+ 编辑器属于当前用户的个人设置,存入用户配置目录的 `config.toml`,不存入工作区 marker 或 Session。尚未初始化时也可设置;之后初始化或切换默认工作区会保留它。
103
+
104
+ 用户配置格式现为 v2,工作区 marker 仍为 v1,Session 格式不变。已有 v1 用户配置(含内测编辑器设置)可继续读取,读取不改写文件;显式设置/清除编辑器或执行 `init` 时才保存为 v2。也可用 `lc config editor zed` 保存并升级。升级后旧版 `lc` 会拒绝该配置,不能用旧版 `init --repair` 降级。
105
+
106
+ ```shell
107
+ lc config editor zed
108
+ lc config editor code --arg=--reuse-window
109
+ lc config editor
110
+ lc solve 1 --editor zed
111
+ lc solve 1 --no-open
112
+ lc config editor --clear
113
+ ```
114
+
115
+ `zed`、`code` 和别名 `vscode` 从 PATH 查找,也可指定可执行文件绝对路径。可重复的 `--arg` 按参数数组原样传递,路径最后追加;不支持 Shell 命令串或文件占位符。配置不自动安装编辑器。
116
+
117
+ 优先级为:`--no-open` 禁止打开(并跳过 `--editor` 校验);否则 `--editor` 覆盖用户配置,且不继承旧编辑器的参数(非法 `--editor` 参数按用法错误返回退出码 2);没有临时参数时使用用户设置。不增加工作区或环境变量覆盖层。
118
+
119
+ 未配置时只保存并提示,不使用系统 `.py` 文件关联,避免关联到 Python/uv 后意外执行代码。显式配置失败也不静默回退。Windows 的 VS Code 标准 `code.cmd` 入口会解析为安装目录的 `Code.exe`,其他 `.cmd`/`.bat` 编辑器入口拒绝执行。启动后短时间内非零退出会警告;GUI 持续运行视为请求已发出,不强行终止,也不保证窗口一定可见。
120
+
121
+ ## 浏览器登录
122
+
123
+ 首次使用浏览器自动登录前:
124
+
125
+ 1. Chrome 打开 `chrome://inspect/#remote-debugging`;Edge 打开 `edge://inspect/#remote-debugging`。
126
+ 2. 勾选 **Allow remote debugging for this browser instance**,再执行 `lc login`。
127
+ 3. CLI 优先尝试日常 Chrome,再尝试日常 Edge;如果设置页面没有自动显示,请手动打开上述地址。
128
+ 4. 出现 **Allow remote debugging?** 连接确认框时选择 **Allow**,并保持 LeetCode 页面已登录。
129
+ 5. CLI 只获取 `leetcode.cn` 的 `LEETCODE_SESSION` 和 `csrftoken`,在线验证后保存。
130
+ 6. 自动登录失败时,在交互式终端中回退到隐藏输入的手动 Cookie;若处于管道、后台脚本等非交互式终端,则立即提示并返回退出码 1,不阻塞等待输入、不从管道读取明文 Cookie,也不破坏已有 `session.json`。
131
+
132
+ CLI 不读取或解密浏览器 Cookie 数据库,不创建专用 profile,也不关闭日常浏览器。单次浏览器尝试共享 180 秒单调时钟预算(涵盖连接、授权等待、重试与 Cookie 轮询,不含连接关闭超时与随后的在线账号校验)。
133
+
134
+ ## 本地调用
135
+
136
+ `lc test` 自动选择 `Solution` 中第一个不以 `_` 开头的实例方法。输入安全 Python 字面量参数:
137
+
138
+ ```text
139
+ 参数 > nums = [3, 2, 4], target = 6
140
+ ```
141
+
142
+ 连续两次回车退出。每组默认限时 1 秒;无输入、参数错误、异常或超时返回退出码 1。退出码 0 只表示调用正常完成,不代表算法正确。
143
+
144
+ 支持按入口类型注解转换节点:`ListNode`、`TreeNode`、`Optional[...]`、`... | None`,以及相应的字符串注解。普通 `list` 保持列表含义,不根据参数名猜类型;节点参数缺少注解时请补齐。嵌套节点集合及混合节点类型注解会明确拒绝。
145
+
146
+ 启用 `from __future__ import annotations` 不改变这些规则,`list["ListNode"]` 同样拒绝。`Literal["ListNode"]` 中的字符串是取值,`Annotated[int, "ListNode"]` 中的字符串是元数据,均不触发节点转换;`Annotated[ListNode, ...]` 等节点包装暂不支持。
147
+
148
+ ```text
149
+ l1 = [2,4,3], l2 = [5,6,4]
150
+ root = [1,null,2,3]
151
+ ```
152
+
153
+ 链表用整数数组;树用力扣式层序数组,`null` 与 `None` 都表示空位(字符串 `"null"` 不受影响)。空数组或 `null`/`None` 表示空节点;树中无法连接到根的非空值会被拒绝。返回节点转换回同类数组,树尾多余空位移除;有节点返回注解时空节点输出 `[]`。普通方法返回 `None` 时,展示调用后的参数,节点参数也转回数组。
154
+
155
+ 生成模板提供位于提交区域外的本地节点定义,不将这些辅助定义发送给 LeetCode。第一版只支持整数节点的无环单链表和普通二叉树,不支持环、共享节点身份、随机指针、N 叉树、嵌套节点集合及设计题多方法调用。单个节点数组输入最多 100,000 项,输出最多 100,000 个节点;超过限制明确失败,不截断为成功。
156
+
157
+ 非交互示例:
158
+
159
+ ```shell
160
+ printf 'nums = [3, 2, 4], target = 6\n' | lc test --stdin
161
+ ```
162
+
163
+ `--stdin` 的运行时启动失败(包括未初始化工作区)也输出 JSON Lines,包含 `kind: startup_error`、稳定的 `code` 和中文 `error`,退出码为 1。非法 CLI 参数仍使用标准用法错误,退出码为 2。
164
+
165
+ 异常默认显示类型、原因和可定位的 `solution.py` 行号,并保留 stdout/stderr;`--verbose` 增加完整调用栈,不采集局部变量。JSON 模式通过 `error_line` 和可选 `traceback` 字段表达,不混入 Rich 文本。调用栈仍可能包含源码片段、路径及异常内容,共享前请自行检查。
166
+
167
+ 某组超时后,下一组会重启 worker;若重新加载失败,该组报告失败并保留行号及可选调用栈,后续输入仍可继续尝试。
168
+
169
+ `lc submit` 取得 submission ID 后默认等待判题 30 秒。判题查询只在总预算内有限重试;初始提交 POST 不自动重试,避免重复提交。遇到明确认证失效(HTTP 401 或已确认 GraphQL 鉴权错误码)会提示执行 `lc login`;遇到权限拒绝(HTTP 403 或对应权限错误码)会提示检查账号权限或登录状态。等待超时或查询失败时会保留 submission ID,并返回退出码 1。
170
+
171
+ 等待超时后可执行 `lc check <Submission ID>` 重新查询。该命令只请求一次:已经判题则展示结果;若服务端返回未完成中间态(对仍在处理、跨账号不可见或不存在的提交,接口可能返回相同状态),CLI 会提示暂未取得可确认的判题结果,请确认提交 ID 和当前账号,并返回退出码 1(若提交确仍在处理可稍后重查);只有结果为 Accepted 时返回退出码 0。
172
+
173
+ ## 安全与限制
174
+
175
+ - 当前只支持 LeetCode 中文站和 Python3 提交。
176
+ - HTTP 凭据仅发往 `https://leetcode.cn` 的默认 HTTPS 端口,拒绝全部重定向;不自动切换到其他域名、子域名或 HTTP 地址。
177
+ - Session 包含真实 Cookie,保存在当前系统用户的本地状态目录:Windows 为 `%LOCALAPPDATA%\leetcode-local-cli\session.json`,macOS 为 `~/Library/Application Support/leetcode-local-cli/session.json`,Linux 为 `${XDG_STATE_HOME:-~/.local/state}/leetcode-local-cli/session.json`。不得提交、上传、同步或共享。
178
+ - 工作区 marker 保存在 `.leetcode_local_cli/workspace.toml`,属于本机工作区元数据;建议忽略,不提交。CLI 不自动修改用户仓库的 `.gitignore`。
179
+ - 本项目源码仓库忽略根目录 `solution.py`;开发者可将工作区与源码放在一起,个人解法不属于工具源码。普通用户仍可自选独立工作区。
180
+ - `solution.py` 只接受 UTF-8 或 UTF-8 BOM。
181
+ - `lc test` 与 `lc doctor --run-solution` 会执行本地代码,只能用于可信工作区。
182
+ - 判题等待超时不代表提交失败,应使用终端显示的 submission ID 到 LeetCode 查看最终结果。
183
+
184
+ ## 维护者文档
185
+
186
+ - [当前状态](docs/PROJECT_STATUS.md)
187
+ - [架构](docs/ARCHITECTURE.md)
188
+ - [产品边界](docs/PRODUCT_BOUNDARIES.md)
189
+ - [安全边界](docs/SECURITY_REVIEW.md)
190
+ - [技术决策](docs/TECH_DECISIONS.md)
191
+ - [发布流程](docs/RELEASING.md)
192
+
193
+ ## License
194
+
195
+ [MIT License](LICENSE)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "leetcode-local-cli"
3
- version = "0.11.0"
3
+ version = "0.12.0"
4
4
  description = "Local coding workflow CLI for LeetCode CN."
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -2,6 +2,7 @@ from typer import Typer
2
2
 
3
3
  from leetcode_local_cli.commands.account import login, profile, status
4
4
  from leetcode_local_cli.commands.problems import get_problem, show, solve
5
+ from leetcode_local_cli.commands.settings import config_app
5
6
  from leetcode_local_cli.commands.setup import init_workspace
6
7
  from leetcode_local_cli.commands.submission import check, submit
7
8
  from leetcode_local_cli.commands.testing import doctor, test
@@ -10,6 +11,7 @@ from leetcode_local_cli.commands.testing import doctor, test
10
11
  def register_commands(app: Typer) -> None:
11
12
  """Register every public CLI command without coupling handlers to the app."""
12
13
  app.command("init")(init_workspace)
14
+ app.add_typer(config_app, name="config")
13
15
  app.command()(login)
14
16
  app.command()(status)
15
17
  app.command()(profile)
@@ -1,3 +1,4 @@
1
+ import sys
1
2
  from getpass import getpass
2
3
  from pathlib import Path
3
4
  from typing import Annotated
@@ -63,7 +64,21 @@ def login(
63
64
  _login_manually(paths.session_file)
64
65
 
65
66
 
67
+ def _is_interactive_stdin() -> bool:
68
+ if sys.stdin is None:
69
+ return False
70
+ try:
71
+ return sys.stdin.isatty()
72
+ except ValueError:
73
+ return False
74
+
75
+
66
76
  def _login_manually(session_file: Path) -> None:
77
+ if not _is_interactive_stdin():
78
+ warning(
79
+ "当前为非交互式终端,无法安全读取手动 Cookie;请在交互式终端中执行 lc login"
80
+ )
81
+ raise Exit(1)
67
82
  warning("无法自动获取 LeetCode 登录状态,请手动粘贴 Cookie")
68
83
  manual_cookies = get_cookies_from_input()
69
84
  if not manual_cookies:
@@ -102,4 +117,8 @@ def profile() -> None:
102
117
 
103
118
 
104
119
  def get_cookies_from_input() -> dict[str, str] | None:
105
- return parse_cookie_header(getpass("请粘贴 Cookie(输入内容不会回显):\n"))
120
+ try:
121
+ raw_cookie = getpass("请粘贴 Cookie(输入内容不会回显):\n")
122
+ except EOFError:
123
+ return None
124
+ return parse_cookie_header(raw_cookie)
@@ -1,3 +1,5 @@
1
+ from typer import BadParameter
2
+
1
3
  from leetcode_local_cli.commands import common
2
4
  from leetcode_local_cli.commands.rendering import (
3
5
  loading,
@@ -6,12 +8,14 @@ from leetcode_local_cli.commands.rendering import (
6
8
  success,
7
9
  warning,
8
10
  )
11
+ from leetcode_local_cli.models.editor import EditorConfig
9
12
  from leetcode_local_cli.use_cases.errors import UseCaseError
10
13
  from leetcode_local_cli.use_cases.problems import (
11
14
  get_problem_detail_by_question_id,
12
15
  get_problem_summaries,
13
16
  write_problem_solution,
14
17
  )
18
+ from leetcode_local_cli.use_cases.settings import get_editor
15
19
 
16
20
 
17
21
  def get_problem(question_id: str) -> None:
@@ -39,9 +43,17 @@ def show(limit: int = 50, skip: int = 0) -> None:
39
43
  render_problem_list(problem_summaries)
40
44
 
41
45
 
42
- def solve(question_id: str, no_open: bool = False) -> None:
46
+ def solve(question_id: str, no_open: bool = False, editor: str | None = None) -> None:
47
+ selected_editor: EditorConfig | None = None
48
+ if not no_open and editor is not None:
49
+ try:
50
+ selected_editor = EditorConfig(editor)
51
+ except ValueError as exc:
52
+ raise BadParameter(str(exc), param_hint="--editor") from exc
43
53
  try:
44
54
  paths = common.require_app_paths()
55
+ if not no_open and selected_editor is None:
56
+ selected_editor = get_editor(paths.user)
45
57
  problem_detail = get_problem_detail_by_question_id(
46
58
  paths.user,
47
59
  question_id,
@@ -52,7 +64,10 @@ def solve(question_id: str, no_open: bool = False) -> None:
52
64
  render_problem_detail(problem_detail)
53
65
  try:
54
66
  result = write_problem_solution(
55
- paths.workspace, problem_detail, open_editor=not no_open
67
+ paths.workspace,
68
+ problem_detail,
69
+ open_editor=not no_open,
70
+ editor=selected_editor,
56
71
  )
57
72
  success(f"解法已保存:{result.path}")
58
73
  if result.open_warning:
@@ -136,9 +136,15 @@ def render_local_execution_error(
136
136
  error_detail: str,
137
137
  stdout: str = "",
138
138
  stderr: str = "",
139
+ error_line: int | None = None,
140
+ traceback: str = "",
139
141
  ) -> None:
140
142
  error(f"第 {case_index} 组执行失败")
141
143
  console.print(_external_text(f"原因:{error_detail}", style="red"))
144
+ if error_line is not None:
145
+ console.print(_external_text(f"位置:solution.py:{error_line}", style="red"))
146
+ if traceback:
147
+ console.print(_external_text(traceback, style="red"))
142
148
  if stdout:
143
149
  console.print(_external_text("标准输出:", style="red"))
144
150
  console.print(
@@ -316,9 +322,11 @@ def render_doctor_report(report: DoctorReport) -> None:
316
322
 
317
323
  def render_submission_result(result: SubmissionOutcome) -> None:
318
324
  if isinstance(result, SubmissionPending):
319
- warning("提交仍在判题中")
325
+ warning(
326
+ "暂未取得可确认的判题结果。提交可能仍在处理,或对当前账号不可见,请确认提交 ID 和账号。"
327
+ )
320
328
  info(f"Submission ID:{result.submission_id}")
321
- info(f"可稍后重新执行:lc check {result.submission_id}")
329
+ info(f"若提交仍在处理,可稍后重新执行:lc check {result.submission_id}")
322
330
  return
323
331
  if isinstance(result, SubmissionTimedOut):
324
332
  error(f"判题等待超过 {result.waited_seconds:g} 秒")
@@ -0,0 +1,50 @@
1
+ import json
2
+ from typing import Annotated
3
+
4
+ from typer import Argument, BadParameter, Option, Typer
5
+
6
+ from leetcode_local_cli.commands import common
7
+ from leetcode_local_cli.commands.rendering import info, success
8
+ from leetcode_local_cli.models.editor import EditorConfig
9
+ from leetcode_local_cli.use_cases.errors import UseCaseError
10
+ from leetcode_local_cli.use_cases.settings import configure_editor, get_editor
11
+
12
+ config_app = Typer(help="管理当前用户的设置", no_args_is_help=True)
13
+
14
+
15
+ @config_app.command("editor")
16
+ def editor_settings(
17
+ command: Annotated[
18
+ str | None, Argument(help="zed、code、vscode 或编辑器可执行文件绝对路径")
19
+ ] = None,
20
+ args: Annotated[
21
+ list[str] | None,
22
+ Option("--arg", help="程序参数,可重复;以 - 开头时使用 --arg=值"),
23
+ ] = None,
24
+ clear: Annotated[bool, Option("--clear", help="移除用户编辑器设置")] = False,
25
+ ) -> None:
26
+ if clear and (command is not None or args):
27
+ raise BadParameter("--clear 不能与编辑器命令或参数同时使用")
28
+ if args and command is None:
29
+ raise BadParameter("--arg 必须同时指定编辑器命令")
30
+ try:
31
+ paths = common.get_user_paths()
32
+ if clear:
33
+ configure_editor(paths, None)
34
+ success("已移除编辑器设置")
35
+ elif command is not None:
36
+ try:
37
+ editor = EditorConfig(command, tuple(args or ()))
38
+ except ValueError as exc:
39
+ raise BadParameter(str(exc)) from exc
40
+ configure_editor(paths, editor)
41
+ success(f"已设置编辑器:{editor.command}")
42
+ else:
43
+ editor = get_editor(paths)
44
+ info(
45
+ json.dumps([editor.command, *editor.args], ensure_ascii=False)
46
+ if editor
47
+ else "未配置编辑器,可执行 lc config editor zed"
48
+ )
49
+ except UseCaseError as exc:
50
+ common.exit_for_use_case_error(exc)
@@ -27,7 +27,10 @@ from leetcode_local_cli.models.execution import (
27
27
  )
28
28
  from leetcode_local_cli.use_cases.diagnostics import get_doctor_report
29
29
  from leetcode_local_cli.use_cases.errors import UseCaseError
30
- from leetcode_local_cli.use_cases.local_test import start_local_test
30
+ from leetcode_local_cli.use_cases.local_test import (
31
+ LocalTestStartupError,
32
+ start_local_test,
33
+ )
31
34
 
32
35
 
33
36
  def test(
@@ -42,6 +45,9 @@ def test(
42
45
  bool,
43
46
  Option("--stdin", help="从标准输入逐行读取参数,不显示 Rich 交互界面"),
44
47
  ] = False,
48
+ verbose: Annotated[
49
+ bool, Option("--verbose", help="显示完整异常调用栈,不采集局部变量")
50
+ ] = False,
45
51
  ) -> None:
46
52
  if not math.isfinite(timeout) or timeout <= 0:
47
53
  raise BadParameter("必须是大于 0 的有限秒数", param_hint="--timeout")
@@ -50,12 +56,27 @@ def test(
50
56
  worker = start_local_test(
51
57
  common.require_workspace_paths().solution_file,
52
58
  timeout=timeout,
59
+ verbose=verbose,
53
60
  )
54
61
  except UseCaseError as exc:
55
62
  if stdin:
56
- _write_stdin_test_event(
57
- {"kind": "startup_error", "code": exc.code.value, "error": exc.message}
58
- )
63
+ event: dict[str, object] = {
64
+ "kind": "startup_error",
65
+ "code": exc.code.value,
66
+ "error": exc.message,
67
+ }
68
+ if isinstance(exc, LocalTestStartupError):
69
+ event["error_line"] = exc.error_line
70
+ if verbose and exc.traceback:
71
+ event["traceback"] = exc.traceback
72
+ _write_stdin_test_event(event)
73
+ raise Exit(1) from exc
74
+ if isinstance(exc, LocalTestStartupError):
75
+ error(exc.message)
76
+ if exc.error_line is not None:
77
+ error(f"位置:solution.py:{exc.error_line}")
78
+ if verbose and exc.traceback:
79
+ error(exc.traceback)
59
80
  raise Exit(1) from exc
60
81
  common.exit_for_use_case_error(exc)
61
82
 
@@ -132,6 +153,8 @@ def _run_interactive_local_test(
132
153
  error_detail=error_detail or "本地代码执行失败",
133
154
  stdout=result.stdout,
134
155
  stderr=result.stderr,
156
+ error_line=result.error_line,
157
+ traceback=result.traceback,
135
158
  )
136
159
 
137
160
  if total == 0:
@@ -186,6 +209,8 @@ def _run_stdin_local_test(worker: LocalExecutionWorker) -> bool:
186
209
  "error": error_detail or "本地代码执行失败",
187
210
  "stdout": result.stdout,
188
211
  "stderr": result.stderr,
212
+ "error_line": result.error_line,
213
+ **({"traceback": result.traceback} if result.traceback else {}),
189
214
  }
190
215
  )
191
216
  if total == 0: