[GH-ISSUE #18] sessionStart 钩子向 stdout 打印非 JSON 时报 JSON 解析错误 #15

Closed
opened 2026-03-03 15:47:12 +03:00 by kerem · 10 comments
Owner

Originally created by @beilo on GitHub (Jan 31, 2026).
Original GitHub issue: https://github.com/mindfold-ai/Trellis/issues/18

环境

  • Cursor:2.5.0-pre.31.patch.0
  • 钩子:sessionStart,命令例如 python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.py"

现象
执行 session start 时出现:

JSON Parse Error: SyntaxError: Unexpected token '<', "<session-c"... is not valid JSON

钩子收到的 input(stdin)
脚本收到的 JSON 示例:

{
  "conversation_id": "4c84288d-6932-46bd-9e19-44e8dab7f055",
  "generation_id": "",
  "model": "default",
  "session_id": "4c84288d-6932-46bd-9e19-44e8dab7f055",
  "is_background_agent": false,
  "composer_mode": "agent",
  "hook_event_name": "sessionStart",
  "cursor_version": "2.5.0-pre.31.patch.0",
  "workspace_roots": ["/Users/am/temp/xxxx"],
  "user_email": "xxx@xxx.cn",
  "transcript_path": null
}

原因
钩子脚本向 stdout 打印了普通文本(如 <session-context>...)。Cursor 会把 stdout 整体当 JSON 解析,遇到 < 就报错。

建议

  1. 文档:在 Hooks 文档的 sessionStart 小节明确写:stdout 必须是单行 JSON 对象(如 {"continue": true, "additional_context": "..."}),避免让人误以为可以直接输出任意上下文文本。
  2. 报错:当 stdout 不是合法 JSON 时,给出更明确的提示(例如“sessionStart 钩子必须向 stdout 输出 JSON 对象”)并可在文档中注明 sessionStart 的 output schema。

补充内容:
tl init 的时候只勾选了 claude code。因为 cursor 是支持了
https://cursor.com/cn/docs/context/subagents
https://cursor.com/cn/docs/agent/hooks

按理说是能跟claude code一样的。

Originally created by @beilo on GitHub (Jan 31, 2026). Original GitHub issue: https://github.com/mindfold-ai/Trellis/issues/18 **环境** - Cursor:`2.5.0-pre.31.patch.0` - 钩子:`sessionStart`,命令例如 `python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.py"` **现象** 执行 session start 时出现: ```text JSON Parse Error: SyntaxError: Unexpected token '<', "<session-c"... is not valid JSON ``` **钩子收到的 input(stdin)** 脚本收到的 JSON 示例: ```json { "conversation_id": "4c84288d-6932-46bd-9e19-44e8dab7f055", "generation_id": "", "model": "default", "session_id": "4c84288d-6932-46bd-9e19-44e8dab7f055", "is_background_agent": false, "composer_mode": "agent", "hook_event_name": "sessionStart", "cursor_version": "2.5.0-pre.31.patch.0", "workspace_roots": ["/Users/am/temp/xxxx"], "user_email": "xxx@xxx.cn", "transcript_path": null } ``` **原因** 钩子脚本向 stdout 打印了普通文本(如 `<session-context>...`)。Cursor 会把 stdout 整体当 JSON 解析,遇到 `<` 就报错。 **建议** 1. **文档**:在 Hooks 文档的 sessionStart 小节明确写:**stdout 必须是单行 JSON 对象**(如 `{"continue": true, "additional_context": "..."}`),避免让人误以为可以直接输出任意上下文文本。 2. **报错**:当 stdout 不是合法 JSON 时,给出更明确的提示(例如“sessionStart 钩子必须向 stdout 输出 JSON 对象”)并可在文档中注明 sessionStart 的 output schema。 补充内容: tl init 的时候只勾选了 claude code。因为 cursor 是支持了 https://cursor.com/cn/docs/context/subagents https://cursor.com/cn/docs/agent/hooks 按理说是能跟claude code一样的。
kerem closed this issue 2026-03-03 15:47:12 +03:00
Author
Owner

@taosu0216 commented on GitHub (Jan 31, 2026):

编码问题正在hotfix

<!-- gh-comment-id:3827842623 --> @taosu0216 commented on GitHub (Jan 31, 2026): 编码问题正在hotfix
Author
Owner

@taosu0216 commented on GitHub (Jan 31, 2026):

cursor 的 hook 后续我们也会支持一下,感谢建议

<!-- gh-comment-id:3827869162 --> @taosu0216 commented on GitHub (Jan 31, 2026): cursor 的 hook 后续我们也会支持一下,感谢建议
Author
Owner

@taosu0216 commented on GitHub (Feb 1, 2026):

已经在beta最新版本修复

<!-- gh-comment-id:3830334760 --> @taosu0216 commented on GitHub (Feb 1, 2026): 已经在beta最新版本修复
Author
Owner

@beilo commented on GitHub (Feb 1, 2026):

合并到 master 了嘛

<!-- gh-comment-id:3830677478 --> @beilo commented on GitHub (Feb 1, 2026): 合并到 master 了嘛
Author
Owner

@taosu0216 commented on GitHub (Feb 1, 2026):

合并到 master 了嘛

没有, beta 还没测试完,全部测试完成之后才会合进main, 但可以使用 npm install -g @mindfoldhq/trellis@beta 下载最新beta的版本

<!-- gh-comment-id:3830687212 --> @taosu0216 commented on GitHub (Feb 1, 2026): > 合并到 master 了嘛 没有, beta 还没测试完,全部测试完成之后才会合进main, 但可以使用 npm install -g @mindfoldhq/trellis@beta 下载最新beta的版本
Author
Owner

@beilo commented on GitHub (Feb 1, 2026):

好嘞 感谢大佬 我是源码部署的。我等合并吧~

<!-- gh-comment-id:3830799818 --> @beilo commented on GitHub (Feb 1, 2026): 好嘞 感谢大佬 我是源码部署的。我等合并吧~
Author
Owner

@taosu0216 commented on GitHub (Feb 1, 2026):

好嘞 感谢大佬 我是源码部署的。我等合并吧~

https://github.com/mindfold-ai/Trellis/tree/feat/opencode 直接从这个分支再重新部署一遍也ok的, beta 版本的改动目前都是在这个分支推进的

<!-- gh-comment-id:3830887279 --> @taosu0216 commented on GitHub (Feb 1, 2026): > 好嘞 感谢大佬 我是源码部署的。我等合并吧~ https://github.com/mindfold-ai/Trellis/tree/feat/opencode 直接从这个分支再重新部署一遍也ok的, beta 版本的改动目前都是在这个分支推进的
Author
Owner

@beilo commented on GitHub (Feb 2, 2026):

--- Resolving conflicts ---

? .trellis/.gitignore has changes. (Use arrow keys)
[1] Overwrite - Replace with new version
❯ [2] Skip - Keep your current version
[3] Create copy - Save new version as .new
[a] Apply Overwrite to all
[s] Apply Skip to all
[n] Apply Create copy to all

请问这里的最佳实践是Apply Skip to all 吗?因为我之前写了一些文档了。刚刚Apply Overwrite to all把我的文档全覆盖了

<!-- gh-comment-id:3833139163 --> @beilo commented on GitHub (Feb 2, 2026): --- Resolving conflicts --- ? .trellis/.gitignore has changes. (Use arrow keys) [1] Overwrite - Replace with new version ❯ [2] Skip - Keep your current version [3] Create copy - Save new version as .new [a] Apply Overwrite to all [s] Apply Skip to all [n] Apply Create copy to all 请问这里的最佳实践是Apply Skip to all 吗?因为我之前写了一些文档了。刚刚Apply Overwrite to all把我的文档全覆盖了
Author
Owner

@taosu0216 commented on GitHub (Feb 2, 2026):

--- Resolving conflicts ---

? .trellis/.gitignore has changes. (Use arrow keys) [1] Overwrite - Replace with new version ❯ [2] Skip - Keep your current version [3] Create copy - Save new version as .new [a] Apply Overwrite to all [s] Apply Skip to all [n] Apply Create copy to all

请问这里的最佳实践是Apply Skip to all 吗?因为我之前写了一些文档了。刚刚Apply Overwrite to all把我的文档全覆盖了

如果自己已经做过一些魔改的话, 一般其实都是直接 skip 的, 因为改动通常都是一些更通用化, 泛化的改动 另外每次改动都会在 .trellis/ 目录下面自动生成一份你当前本地的backup 备份的, 另外每次也会自动生成一个task 记录相关changelog, 可以让ai看那个task 帮你看看是否有必要进行相关修改

Image
<!-- gh-comment-id:3833180423 --> @taosu0216 commented on GitHub (Feb 2, 2026): > --- Resolving conflicts --- > > ? .trellis/.gitignore has changes. (Use arrow keys) [1] Overwrite - Replace with new version ❯ [2] Skip - Keep your current version [3] Create copy - Save new version as .new [a] Apply Overwrite to all [s] Apply Skip to all [n] Apply Create copy to all > > 请问这里的最佳实践是Apply Skip to all 吗?因为我之前写了一些文档了。刚刚Apply Overwrite to all把我的文档全覆盖了 如果自己已经做过一些魔改的话, 一般其实都是直接 skip 的, 因为改动通常都是一些更通用化, 泛化的改动 另外每次改动都会在 .trellis/ 目录下面自动生成一份你当前本地的backup 备份的, 另外每次也会自动生成一个task 记录相关changelog, 可以让ai看那个task 帮你看看是否有必要进行相关修改 <img width="572" height="366" alt="Image" src="https://github.com/user-attachments/assets/a1bdc69e-c223-4eeb-b1df-ccd6978aa870" />
Author
Owner

@beilo commented on GitHub (Feb 2, 2026):

好呢谢谢~。

<!-- gh-comment-id:3833219367 --> @beilo commented on GitHub (Feb 2, 2026): 好呢谢谢~。
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Trellis#15
No description provided.