@kkcode-app/agent 1.1.1 → 1.1.3

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/plugin.ts +53 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kkcode-app/agent",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Connect OpenCode to KKCode and send actionable iPhone notifications.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/plugin.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * [INPUT]: 依赖 OpenCode 2 Promise plugin context 的 location/session/event API 与 notification-core
3
- * [OUTPUT]: 默认导出 `{ id, setup }` OpenCode 2 插件,按 execution/permission/Form 事件上报推送
3
+ * [OUTPUT]: 默认导出 `{ id, setup }` OpenCode 2 插件,按 execution/permission/Form 事件上报推送;对 NOTIFIABLE_EVENT_TYPES 内的丢弃路径写调试日志,保证推送静默失败可排查
4
4
  * [POS]: OpenCode 2 插件实现模块,与 plugin-v1.ts 一起由包入口 entry.ts 组合导出;自身不是 exports 解析目标
5
5
  * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
6
  */
@@ -33,6 +33,24 @@ type V2Context = {
33
33
 
34
34
  type SessionInfo = { title?: string; parentID?: string };
35
35
 
36
+ /**
37
+ * 本插件打算推送的事件类型。handle() 只对这些类型写丢弃日志——流式期间
38
+ * session.step.* / message.updated 等高频事件数量极大,全量记录会刷爆调试日志。
39
+ * handle() 末尾还有一处 UNHANDLED 兜底,用于捕捉本表与分支实现之间的漂移。
40
+ */
41
+ const NOTIFIABLE_EVENT_TYPES: readonly string[] = [
42
+ "session.execution.succeeded",
43
+ "session.execution.failed",
44
+ "permission.v2.asked",
45
+ "permission.asked",
46
+ "form.created",
47
+ "question.v2.asked",
48
+ ];
49
+
50
+ function isNotifiable(type: string): boolean {
51
+ return NOTIFIABLE_EVENT_TYPES.includes(type);
52
+ }
53
+
36
54
  function record(value: unknown): Record<string, unknown> {
37
55
  return value && typeof value === "object" && !Array.isArray(value)
38
56
  ? (value as Record<string, unknown>)
@@ -158,10 +176,22 @@ async function setup(ctx: V2Context): Promise<() => void> {
158
176
  };
159
177
 
160
178
  const handle = async (event: V2Event) => {
161
- if (!eventBelongsToLocation(event, ctx.location)) return;
179
+ if (!eventBelongsToLocation(event, ctx.location)) {
180
+ if (isNotifiable(event.type)) {
181
+ await debugLog(
182
+ `v2 ${event.type} DROPPED | location mismatch | event=${event.location?.directory ?? "none"} plugin=${ctx.location.directory ?? "none"}`,
183
+ );
184
+ }
185
+ return;
186
+ }
162
187
  const data = event.data ?? {};
163
188
  const sessionID = sessionIDOf(event);
164
- if (!sessionID) return;
189
+ if (!sessionID) {
190
+ if (isNotifiable(event.type)) {
191
+ await debugLog(`v2 ${event.type} DROPPED | no sessionID | id=${event.id ?? "none"}`);
192
+ }
193
+ return;
194
+ }
165
195
 
166
196
  if (event.type === "session.execution.succeeded") {
167
197
  const info = await getSessionInfo(sessionID);
@@ -186,7 +216,10 @@ async function setup(ctx: V2Context): Promise<() => void> {
186
216
  if (event.type === "permission.v2.asked" || event.type === "permission.asked") {
187
217
  const requestID = requestIDOf(event) ?? event.id;
188
218
  const key = `permission:${sessionID}:${requestID ?? ""}`;
189
- if (!rememberRequest(seenRequests, key)) return;
219
+ if (!rememberRequest(seenRequests, key)) {
220
+ await debugLog(`v2 ${event.type} DEDUPED | ${sessionID} | key=${key}`);
221
+ return;
222
+ }
190
223
  await report(event, {
191
224
  sessionID,
192
225
  type: "permission.asked",
@@ -196,15 +229,24 @@ async function setup(ctx: V2Context): Promise<() => void> {
196
229
  }
197
230
  if (event.type === "form.created") {
198
231
  const summary = questionSummary(data);
199
- if (!summary) return;
232
+ if (!summary) {
233
+ await debugLog(`v2 form.created SKIPPED | not a question form | ${sessionID}`);
234
+ return;
235
+ }
200
236
  const key = `question:${sessionID}:${requestIDOf(event) ?? event.id ?? ""}`;
201
- if (!rememberRequest(seenRequests, key)) return;
237
+ if (!rememberRequest(seenRequests, key)) {
238
+ await debugLog(`v2 form.created DEDUPED | ${sessionID} | key=${key}`);
239
+ return;
240
+ }
202
241
  await report(event, { sessionID, type: "question.asked", summary });
203
242
  return;
204
243
  }
205
244
  if (event.type === "question.v2.asked") {
206
245
  const key = `question:${sessionID}:${requestIDOf(event) ?? event.id ?? ""}`;
207
- if (!rememberRequest(seenRequests, key)) return;
246
+ if (!rememberRequest(seenRequests, key)) {
247
+ await debugLog(`v2 ${event.type} DEDUPED | ${sessionID} | key=${key}`);
248
+ return;
249
+ }
208
250
  const questions = Array.isArray(data.questions) ? data.questions.map(record) : [];
209
251
  const first = questions[0] ?? {};
210
252
  await report(event, {
@@ -213,6 +255,10 @@ async function setup(ctx: V2Context): Promise<() => void> {
213
255
  summary:
214
256
  compactText(first.question ?? first.header, 400) || "KKCode is waiting for your answer",
215
257
  });
258
+ return;
259
+ }
260
+ if (isNotifiable(event.type)) {
261
+ await debugLog(`v2 ${event.type} UNHANDLED | ${sessionID} | NOTIFIABLE_EVENT_TYPES drift`);
216
262
  }
217
263
  };
218
264