Skip to content

Commit 9c233dd

Browse files
committed
feat: update notification system to reflect session status changes
1 parent efb0364 commit 9c233dd

9 files changed

Lines changed: 59 additions & 53 deletions

File tree

‎docs/configuration.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Deep Code 使用 `settings.json` 设置文件进行持久化配置,支持两
4343
| `maxRequestFilesBytes` | number | 单次请求内图片原始字节总上限,默认 `134217728`(128 MiB) |
4444
| `debugLogEnabled` | boolean | 是否启用调试日志输出(默认 `false`) |
4545
| `telemetryEnabled` | boolean | 是否启用匿名使用数据上报(默认 `true`) |
46-
| `notify` | string | 任务完成通知脚本的完整路径(如 Slack 通知脚本) |
46+
| `notify` | string | 任务状态通知脚本的完整路径(如 Slack 通知脚本) |
4747
| `webSearchTool` | string | 自定义联网搜索脚本的完整路径 |
4848
| `deepseekSearchApiEnabled` | boolean | 是否使用 DeepSeek 官方网页搜索(默认 `false`) |
4949
| `mcpServers` | object | MCP 服务器配置(键为服务名,值为 McpServerConfig 对象) |
@@ -144,16 +144,16 @@ Deep Code 使用 `settings.json` 设置文件进行持久化配置,支持两
144144

145145
单个文件最大 64 MiB,上传超时不能超过 DeepSeek 规定的 10 分钟。远端文件 ID 会缓存在 `~/.deepcode/files-api-cache.json`;缓存不保存明文 API Key。遇到远端存储配额错误时,只会清理文件名以 `deepcode-` 开头的最旧文件,然后重试一次。
146146

147-
#### `notify` — 任务完成通知
147+
#### `notify` — 任务状态通知
148148

149-
设置一个 Shell 脚本的完整路径。当 AI 助手完成一轮任务后,会自动执行该脚本,可用于发送通知(如 Slack 消息)。
149+
设置一个 Shell 脚本的完整路径。当会话完成、失败、等待用户输入或等待权限确认时,会自动执行该脚本,可用于发送通知(如 Slack 消息)。恢复执行后再次暂停或结束时,会再次通知。
150150

151151
通知脚本执行时,会通过环境变量注入以下上下文信息:
152152

153153
| 环境变量 | 说明 |
154154
|----------|------|
155-
| `DURATION` | 会话耗时,单位秒(整数) |
156-
| `STATUS` | 会话状态:`"completed"` 或 `"failed"` |
155+
| `DURATION` | 本次执行从开始到暂停或结束的耗时,单位秒(整数);恢复执行后重新计时 |
156+
| `STATUS` | 实际会话状态:`completed`(完成)、`failed`(失败)、`waiting_for_user`(等待用户输入)或 `ask_permission`(等待权限确认) |
157157
| `FAIL_REASON` | 失败原因(仅失败时设置) |
158158
| `BODY` | 最后一条 AI 助手回复的文本内容 |
159159
| `TITLE` | 会话标题(对应 resume 列表中的标题) |

‎docs/configuration_en.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The following are all the top-level fields supported in `settings.json`, along w
4343
| `maxRequestFilesBytes` | number | Raw image byte limit per request, default `134217728` (128 MiB) |
4444
| `debugLogEnabled` | boolean | Enable debug log output (default `false`) |
4545
| `telemetryEnabled` | boolean | Enable anonymous usage reporting (default `true`) |
46-
| `notify` | string | Full path to a task-completion notification script (e.g., Slack notification script) |
46+
| `notify` | string | Full path to a task-status notification script (e.g., Slack notification script) |
4747
| `webSearchTool` | string | Full path to a custom web search script |
4848
| `deepseekSearchApiEnabled` | boolean | Use DeepSeek official web search (default `false`) |
4949
| `mcpServers` | object | MCP server configurations (keys are service names, values are McpServerConfig objects) |
@@ -144,16 +144,16 @@ When `BASE_URL` is `https://api.deepseek.com`, enabling `filesApiEnabled` upload
144144

145145
Each file is limited to 64 MiB, and the upload timeout cannot exceed DeepSeek's 10-minute limit. Remote IDs are cached in `~/.deepcode/files-api-cache.json` without storing the plaintext API key. On a remote storage-quota error, only the oldest files whose names start with `deepcode-` are removed before one retry.
146146

147-
#### `notify` — Task Completion Notification
147+
#### `notify` — Task Status Notifications
148148

149-
Set a full path to a shell script. When the AI assistant finishes a round of tasks, the script is executed automatically, which can be used to send notifications (e.g., a Slack message).
149+
Set a full path to a shell script. When a session completes, fails, waits for user input, or waits for permission approval, the script is executed automatically to send notifications (e.g., a Slack message). After the session resumes, another notification is sent when it pauses or ends again.
150150

151151
The following context is injected as environment variables when the notify script runs:
152152

153153
| Variable | Description |
154154
|----------|-------------|
155-
| `DURATION` | Session duration in seconds (integer) |
156-
| `STATUS` | Session status: `"completed"` or `"failed"` |
155+
| `DURATION` | Elapsed time from the start of the current execution until it pauses or ends, in whole seconds; resets when execution resumes |
156+
| `STATUS` | Actual session status: `completed`, `failed`, `waiting_for_user` (waiting for user input), or `ask_permission` (waiting for permission approval) |
157157
| `FAIL_REASON` | Failure reason (only set on failure) |
158158
| `BODY` | The text content of the last AI assistant reply |
159159
| `TITLE` | Session title (matches the resume list title) |

‎docs/notify.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Deep Code 任务完成通知
1+
# Deep Code 任务状态通知
22

3-
当 AI 助手完成一轮任务后,Deep Code 可以自动执行一个通知脚本,将任务结果发送到你指定的渠道(如 Slack、系统通知等)。
3+
当会话完成、失败、等待用户输入或等待权限确认时,Deep Code 可以自动执行一个通知脚本,将会话状态发送到你指定的渠道(如 Slack、系统通知等)。
44

55
## 工作原理
66

7-
在 `settings.json` 中配置 `notify` 字段,指向一个可执行脚本的完整路径。每次 AI 助手完成任务应答后,Deep Code 会执行该脚本,并通过环境变量注入上下文信息。
7+
在 `settings.json` 中配置 `notify` 字段,指向一个可执行脚本的完整路径。每次会话进入上述状态时,Deep Code 会执行该脚本,并通过环境变量注入上下文信息。恢复执行后再次暂停或结束时,会再次通知。
88

99
## 注入的环境变量
1010

1111
| 环境变量 | 说明 |
1212
|----------|------|
13-
| `DURATION` | 会话耗时,单位秒(整数) |
14-
| `STATUS` | 会话状态:`"completed"` 或 `"failed"` |
13+
| `DURATION` | 本次执行从开始到暂停或结束的耗时,单位秒(整数);恢复执行后重新计时 |
14+
| `STATUS` | 实际会话状态:`completed`(完成)、`failed`(失败)、`waiting_for_user`(等待用户输入)或 `ask_permission`(等待权限确认) |
1515
| `FAIL_REASON` | 失败原因(仅失败时设置) |
1616
| `BODY` | 最后一条 AI 助手回复的文本内容 |
1717
| `TITLE` | 会话标题(对应 resume 列表中的标题) |
@@ -68,7 +68,7 @@ BRANCH=$(git branch --show-current 2>/dev/null)
6868
curl -X POST "$SLACK_WEBHOOK_URL" \
6969
-H "Content-type: application/json" \
7070
--data "{
71-
\"text\": \"✅ Deep Code 任务已完成\n · cwd: $CURRENT_DIR\n · Branch: $BRANCH\n · Duration: $DURATION 秒\"
71+
\"text\": \"Deep Code 任务状态:${STATUS}\n · cwd: $CURRENT_DIR\n · Branch: $BRANCH\n · Duration: $DURATION 秒\"
7272
}"
7373
```
7474

@@ -161,7 +161,7 @@ echo \x1b]9;DeepCode: task %STATUS% (%DURATION%s)\x07
161161
```bash
162162
#!/bin/bash
163163
# macOS 系统通知
164-
osascript -e "display notification \"任务已${STATUS:-完成},耗时 ${DURATION}s\" with title \"DeepCode\""
164+
osascript -e "display notification \"任务状态:${STATUS:-completed},耗时 ${DURATION}s\" with title \"DeepCode\""
165165
```
166166

167167
```json
@@ -183,7 +183,7 @@ sudo apt install libnotify-bin # Debian/Ubuntu
183183
```bash
184184
#!/bin/bash
185185
# Linux notify-send 通知
186-
notify-send "DeepCode" "任务已${STATUS:-完成},耗时 ${DURATION}s"
186+
notify-send "DeepCode" "任务状态:${STATUS:-completed},耗时 ${DURATION}s"
187187
```
188188

189189
```json

‎docs/notify_en.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Deep Code Task Completion Notification
1+
# Deep Code Task Status Notifications
22

3-
When the AI assistant finishes a round of tasks, Deep Code can automatically execute a notification script to send task results to your chosen channel (Slack, system notifications, etc.).
3+
When a session completes, fails, waits for user input, or waits for permission approval, Deep Code can automatically execute a notification script to send the session status to your chosen channel (Slack, system notifications, etc.).
44

55
## How It Works
66

7-
Configure the `notify` field in `settings.json` with the full path to an executable script. Every time the AI assistant completes a task response, Deep Code executes that script and injects context as environment variables.
7+
Configure the `notify` field in `settings.json` with the full path to an executable script. Each time a session enters one of these states, Deep Code executes that script and injects context as environment variables. After the session resumes, another notification is sent when it pauses or ends again.
88

99
## Injected Environment Variables
1010

1111
| Variable | Description |
1212
|----------|-------------|
13-
| `DURATION` | Session duration in seconds (integer) |
14-
| `STATUS` | Session status: `"completed"` or `"failed"` |
13+
| `DURATION` | Elapsed time from the start of the current execution until it pauses or ends, in whole seconds; resets when execution resumes |
14+
| `STATUS` | Actual session status: `completed`, `failed`, `waiting_for_user` (waiting for user input), or `ask_permission` (waiting for permission approval) |
1515
| `FAIL_REASON` | Failure reason (only set on failure) |
1616
| `BODY` | The text content of the last AI assistant reply |
1717
| `TITLE` | Session title (matches the resume list title) |
@@ -68,7 +68,7 @@ BRANCH=$(git branch --show-current 2>/dev/null)
6868
curl -X POST "$SLACK_WEBHOOK_URL" \
6969
-H "Content-type: application/json" \
7070
--data "{
71-
\"text\": \"✅ Deep Code task completed\n · cwd: $CURRENT_DIR\n · Branch: $BRANCH\n · Duration: $DURATION s\"
71+
\"text\": \"Deep Code task status: ${STATUS}\n · cwd: $CURRENT_DIR\n · Branch: $BRANCH\n · Duration: $DURATION s\"
7272
}"
7373
```
7474

‎packages/core/src/session.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ ${agentInstructions}
17631763
),
17641764
false
17651765
);
1766-
this.maybeNotifyTaskCompletion(sessionId, notify, startedAt, env);
1766+
this.maybeNotifySessionStatus(sessionId, notify, startedAt, env);
17671767
return;
17681768
}
17691769

@@ -1775,7 +1775,7 @@ ${agentInstructions}
17751775
failReason: "interrupted",
17761776
updateTime: now,
17771777
}));
1778-
this.maybeNotifyTaskCompletion(sessionId, notify, startedAt, env);
1778+
this.maybeNotifySessionStatus(sessionId, notify, startedAt, env);
17791779
return;
17801780
}
17811781

@@ -1951,7 +1951,7 @@ ${agentInstructions}
19511951
if (this.sessionControllers.get(sessionId) === sessionController) {
19521952
this.sessionControllers.delete(sessionId);
19531953
}
1954-
this.maybeNotifyTaskCompletion(sessionId, notify, startedAt, env);
1954+
this.maybeNotifySessionStatus(sessionId, notify, startedAt, env);
19551955
}
19561956
}
19571957

@@ -3653,7 +3653,7 @@ ${agentInstructions}
36533653
}
36543654
}
36553655

3656-
private maybeNotifyTaskCompletion(
3656+
private maybeNotifySessionStatus(
36573657
sessionId: string,
36583658
notifyCommand: string | undefined,
36593659
startedAt: number,
@@ -3664,7 +3664,13 @@ ${agentInstructions}
36643664
}
36653665

36663666
const session = this.getSession(sessionId);
3667-
if (!session || (session.status !== "completed" && session.status !== "failed")) {
3667+
if (
3668+
!session ||
3669+
(session.status !== "completed" &&
3670+
session.status !== "failed" &&
3671+
session.status !== "waiting_for_user" &&
3672+
session.status !== "ask_permission")
3673+
) {
36683674
return;
36693675
}
36703676

‎packages/core/templates/skills/bundled/deepcode-self-refer/references/configuration.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Deep Code 使用 `settings.json` 设置文件进行持久化配置,支持两
4242
| `maxRequestFilesBytes` | number | 单次请求图片原始字节总上限,默认 `134217728`(128 MiB) |
4343
| `debugLogEnabled` | boolean | 是否启用调试日志输出(默认 `false`) |
4444
| `telemetryEnabled` | boolean | 是否启用匿名使用数据上报(默认 `true`) |
45-
| `notify` | string | 任务完成通知脚本的完整路径(如 Slack 通知脚本) |
45+
| `notify` | string | 任务状态通知脚本的完整路径(如 Slack 通知脚本) |
4646
| `webSearchTool` | string | 自定义联网搜索脚本的完整路径 |
4747
| `deepseekSearchApiEnabled` | boolean | 是否使用 DeepSeek 官方网页搜索(默认 `false`) |
4848
| `mcpServers` | object | MCP 服务器配置(键为服务名,值为 McpServerConfig 对象) |
@@ -131,16 +131,16 @@ Deep Code 使用 `settings.json` 设置文件进行持久化配置,支持两
131131

132132
单个文件最大 64 MiB,上传超时不能超过 10 分钟。远端文件 ID 缓存在 `~/.deepcode/files-api-cache.json`,其中不保存明文 API Key。配额不足时只清理文件名以 `deepcode-` 开头的最旧文件,然后重试一次。
133133

134-
#### `notify` — 任务完成通知
134+
#### `notify` — 任务状态通知
135135

136-
设置一个 Shell 脚本的完整路径。当 AI 助手完成一轮任务后,会自动执行该脚本,可用于发送通知(如 Slack 消息)。
136+
设置一个 Shell 脚本的完整路径。当会话完成、失败、等待用户输入或等待权限确认时,会自动执行该脚本,可用于发送通知(如 Slack 消息)。恢复执行后再次暂停或结束时,会再次通知。
137137

138138
通知脚本执行时,会通过环境变量注入以下上下文信息:
139139

140140
| 环境变量 | 说明 |
141141
| ------------- | ------------------------------------- |
142-
| `DURATION` | 会话耗时,单位秒(整数) |
143-
| `STATUS` | 会话状态:`"completed"` 或 `"failed"` |
142+
| `DURATION` | 本次执行从开始到暂停或结束的耗时,单位秒(整数);恢复执行后重新计时 |
143+
| `STATUS` | 实际会话状态:`completed`(完成)、`failed`(失败)、`waiting_for_user`(等待用户输入)或 `ask_permission`(等待权限确认) |
144144
| `FAIL_REASON` | 失败原因(仅失败时设置) |
145145
| `BODY` | 最后一条 AI 助手回复的文本内容 |
146146
| `TITLE` | 会话标题(对应 resume 列表中的标题) |

‎packages/core/templates/skills/bundled/deepcode-self-refer/references/configuration_en.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The following are all the top-level fields supported in `settings.json`, along w
4242
| `maxRequestFilesBytes` | number | Raw image byte limit per request, default `134217728` (128 MiB) |
4343
| `debugLogEnabled` | boolean | Enable debug log output (default `false`) |
4444
| `telemetryEnabled` | boolean | Enable anonymous usage reporting (default `true`) |
45-
| `notify` | string | Full path to a task-completion notification script (e.g., Slack notification script) |
45+
| `notify` | string | Full path to a task-status notification script (e.g., Slack notification script) |
4646
| `webSearchTool` | string | Full path to a custom web search script |
4747
| `deepseekSearchApiEnabled` | boolean | Use DeepSeek official web search (default `false`) |
4848
| `mcpServers` | object | MCP server configurations (keys are service names, values are McpServerConfig objects) |
@@ -129,16 +129,16 @@ When `BASE_URL` is `https://api.deepseek.com`, enabling `filesApiEnabled` upload
129129

130130
Each file is limited to 64 MiB, and the upload timeout cannot exceed 10 minutes. Remote IDs are cached in `~/.deepcode/files-api-cache.json` without storing the plaintext API key. During quota recovery, only the oldest files whose names start with `deepcode-` are removed before one retry.
131131

132-
#### `notify` — Task Completion Notification
132+
#### `notify` — Task Status Notifications
133133

134-
Set a full path to a shell script. When the AI assistant finishes a round of tasks, the script is executed automatically, which can be used to send notifications (e.g., a Slack message).
134+
Set a full path to a shell script. When a session completes, fails, waits for user input, or waits for permission approval, the script is executed automatically to send notifications (e.g., a Slack message). After the session resumes, another notification is sent when it pauses or ends again.
135135

136136
The following context is injected as environment variables when the notify script runs:
137137

138138
| Variable | Description |
139139
| ------------- | ----------------------------------------------- |
140-
| `DURATION` | Session duration in seconds (integer) |
141-
| `STATUS` | Session status: `"completed"` or `"failed"` |
140+
| `DURATION` | Elapsed time from the start of the current execution until it pauses or ends, in whole seconds; resets when execution resumes |
141+
| `STATUS` | Actual session status: `completed`, `failed`, `waiting_for_user` (waiting for user input), or `ask_permission` (waiting for permission approval) |
142142
| `FAIL_REASON` | Failure reason (only set on failure) |
143143
| `BODY` | The text content of the last AI assistant reply |
144144
| `TITLE` | Session title (matches the resume list title) |

0 commit comments

Comments
 (0)