Skip to content

feat(notify): pass STATUS, FAIL_REASON, BODY, TITLE as env vars to notify hook#90

Merged
qorzj merged 5 commits into
lessweb:mainfrom
Lellansin:feature/notify-env-context
May 19, 2026
Merged

feat(notify): pass STATUS, FAIL_REASON, BODY, TITLE as env vars to notify hook#90
qorzj merged 5 commits into
lessweb:mainfrom
Lellansin:feature/notify-env-context

Conversation

@Lellansin
Copy link
Copy Markdown
Contributor

@Lellansin Lellansin commented May 19, 2026

变更内容

  • src/common/notify.ts:新增 NotifyContext 类型(status/failReason/body/title);buildNotifyEnv 条件注入 STATUSFAIL_REASONBODYTITLE 环境变量;launchNotifyScript 新增可选的 context 参数;buildNotifyEnv 不再将 process.env 全量透传给 notify 脚本,仅暴露显式配置的变量
  • src/session.tsmaybeNotifyTaskCompletion 从会话中提取最后一条 assistant 消息作为 BODY,并传入 session.statussession.failReasonsession.summary 作为 context
  • src/tests/settings-and-notify.test.ts:新增 5 个测试用例,覆盖无 context、全量 context、部分 context、空字符串拒绝、特殊字符保留
  • src/tests/session.test.ts:新增 2 个集成测试用例(成功/失败场景),验证 notify hook 接收到的 STATUSFAIL_REASONBODYTITLEDURATION 上下文
  • docs/configuration.md / docs/configuration_en.md:新增 notify 环境变量表格;新增飞书 Webhook 通知示例

注入的环境变量

变量 说明
DURATION 会话耗时(秒)
STATUS "completed""failed"
FAIL_REASON 失败原因(仅失败时)
BODY 最后一条 AI 回复文本
TITLE 会话标题(对应 resume 列表标题)

背景

当前 notify hook 仅注入 DURATION 和用户自定义的 settings.env 变量,通知脚本无法判断任务成功/失败,也无法获取会话标题或 AI 回复内容。同时原有实现将 process.env 全量透传给 notify 子进程,存在 API Key 等敏感信息泄露风险。本次改动补齐了这些关键上下文,并收紧了环境变量暴露。

验证

  • npm run check(typecheck + lint + format)✅
  • npm test(248 tests, 0 fail)✅

@Lellansin Lellansin marked this pull request as draft May 19, 2026 03:06
@Lellansin
Copy link
Copy Markdown
Contributor Author

飞书测试效果:
image

Lellansin added 3 commits May 19, 2026 15:01
- Add NotifyContext type with status, failReason, body fields
- buildNotifyEnv injects STATUS, FAIL_REASON, BODY when provided
- maybeNotifyTaskCompletion extracts last assistant message as BODY
- launchNotifyScript accepts optional context parameter
- Add unit tests for new context env var injection
- Update docs with env variable table and iTerm2/macOS notify examples
… examples; add edge-case tests

- Expand OSC 9 example to cover both iTerm2 and Windows Terminal
- Add .bat example for Windows Terminal users
- Add Linux notify-send example
- Add Windows msg popup notification example
- Add tests for empty-string rejection and special character preservation
…ook example

- Remove iTerm2/Windows Terminal OSC 9, macOS osascript, Linux notify-send, and Windows msg examples (OSC 9 is not compatible with current spawn+stdio:ignore architecture)
- Add Feishu (Lark) webhook notification example in both Chinese and English docs
- Keep the env variable table (DURATION, STATUS, FAIL_REASON, BODY, TITLE) unchanged
@Lellansin Lellansin force-pushed the feature/notify-env-context branch from 30a7394 to 479606f Compare May 19, 2026 07:05
@Lellansin Lellansin marked this pull request as ready for review May 19, 2026 07:05
qorzj added 2 commits May 19, 2026 15:50
- Add docs/notify.md and docs/notify_en.md with Slack, Feishu, terminal,
  macOS, Linux, Windows msg, and custom notification examples
- Simplify notify section in configuration.md / configuration_en.md to
  field description + env table + reference to notify docs
- Replace external binfer.net link with docs/notify.md in README FAQ
  across README.md, README-zh_CN.md, README-en.md
@qorzj qorzj merged commit 3a6ec19 into lessweb:main May 19, 2026
9 checks passed
@qorzj
Copy link
Copy Markdown
Collaborator

qorzj commented May 19, 2026

我做了一些文档的修改,把通知的内容都提取到notify.md中,configuration.md聚焦在配置上。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants