@kkcode-app/agent 1.1.0 → 1.1.2

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.
package/README.md CHANGED
@@ -115,10 +115,11 @@ OpenCode 1 or 2, and incrementally registers the matching plugin entry in the
115
115
  global `opencode.json(c)`. Existing JSONC comments and unrelated plugins are
116
116
  preserved. Restart OpenCode after first-time registration.
117
117
 
118
- The npm package contains two native plugin entrypoints: OpenCode 1 resolves
119
- `./server`, while OpenCode 2 loads the default `{ id, setup }` entrypoint. Both
120
- map runtime events to the same five KKCode notification types, so the phone and
121
- Go notification service do not need version-specific configuration.
118
+ The npm package exposes one shared entrypoint (`""`, `./plugin` and `./server`
119
+ all resolve to the same file). Its default export carries both shapes:
120
+ OpenCode 1 loads `server()`, OpenCode 2 loads `setup`. Both map runtime events
121
+ to the same five KKCode notification types, so the phone and Go notification
122
+ service do not need version-specific configuration.
122
123
 
123
124
  ## How it works
124
125
 
package/dist/entry.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * [INPUT]: 依赖 plugin.ts 的 OpenCode 2 `{ id, setup }` 实现与 plugin-v1.ts 的 OpenCode 1 函数入口
3
+ * [OUTPUT]: 默认导出同时满足 OpenCode 1 `{ id, server() }` 与 OpenCode 2 `{ id, setup }` 的合并入口对象
4
+ * [POS]: @kkcode-app/agent 的唯一包入口;exports "." / "./plugin" / "./server" 全部指向此文件,
5
+ * 因为 OpenCode 2 的包解析器优先解析 "./server" 子路径(Bun.resolveSync),
6
+ * 两代加载器必须拿到同一个默认导出,不能分别指向两个文件
7
+ * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
8
+ */
9
+ import v1 from "./plugin-v1.js";
10
+ import v2 from "./plugin.js";
11
+ export default { id: v2.id, setup: v2.setup, server: v1 };
12
+ //# sourceMappingURL=entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChC,OAAO,EAAE,MAAM,aAAa,CAAC;AAE7B,eAAe,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC"}
package/dist/plugin-v1.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * [INPUT]: 依赖 OpenCode 1 PluginInput/client 与 notification-core 共享上报内核
3
3
  * [OUTPUT]: 默认导出 OpenCode 1 函数插件,处理 idle/error/permission/question 事件
4
- * [POS]: @kkcode-app/agent 的 ./server 与 ./plugin 兼容入口;不承载 OpenCode 2 setup API
4
+ * [POS]: OpenCode 1 插件实现模块,由包入口 entry.ts 以 { id, server } 组合导出;自身不是 exports 解析目标
5
5
  * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
6
  */
7
7
  import { compactText, debugLog, errorSummary, reportNotification, } from "./notification-core.js";
package/dist/plugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * [INPUT]: 依赖 OpenCode 2 Promise plugin context 的 location/session/event API 与 notification-core
3
3
  * [OUTPUT]: 默认导出 `{ id, setup }` OpenCode 2 插件,按 execution/permission/Form 事件上报推送
4
- * [POS]: @kkcode-app/agent 默认插件入口;OpenCode 1 由独立 ./server export 加载 plugin-v1.ts
4
+ * [POS]: OpenCode 2 插件实现模块,与 plugin-v1.ts 一起由包入口 entry.ts 组合导出;自身不是 exports 解析目标
5
5
  * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
6
  */
7
7
  import { basename, normalize } from "node:path";
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "@kkcode-app/agent",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Connect OpenCode to KKCode and send actionable iPhone notifications.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "exports": {
8
- ".": "./src/plugin.ts",
9
- "./plugin": "./src/plugin-v1.ts",
10
- "./server": "./src/plugin-v1.ts"
8
+ ".": "./src/entry.ts",
9
+ "./plugin": "./src/entry.ts",
10
+ "./server": "./src/entry.ts"
11
11
  },
12
12
  "bin": {
13
13
  "kkcode": "dist/index.js"
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
+ "src/entry.ts",
17
18
  "src/plugin.ts",
18
19
  "src/plugin-v1.ts",
19
20
  "src/notification-core.ts",
package/src/entry.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * [INPUT]: 依赖 plugin.ts 的 OpenCode 2 `{ id, setup }` 实现与 plugin-v1.ts 的 OpenCode 1 函数入口
3
+ * [OUTPUT]: 默认导出同时满足 OpenCode 1 `{ id, server() }` 与 OpenCode 2 `{ id, setup }` 的合并入口对象
4
+ * [POS]: @kkcode-app/agent 的唯一包入口;exports "." / "./plugin" / "./server" 全部指向此文件,
5
+ * 因为 OpenCode 2 的包解析器优先解析 "./server" 子路径(Bun.resolveSync),
6
+ * 两代加载器必须拿到同一个默认导出,不能分别指向两个文件
7
+ * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
8
+ */
9
+
10
+ import v1 from "./plugin-v1.js";
11
+ import v2 from "./plugin.js";
12
+
13
+ export default { id: v2.id, setup: v2.setup, server: v1 };
package/src/plugin-v1.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * [INPUT]: 依赖 OpenCode 1 PluginInput/client 与 notification-core 共享上报内核
3
3
  * [OUTPUT]: 默认导出 OpenCode 1 函数插件,处理 idle/error/permission/question 事件
4
- * [POS]: @kkcode-app/agent 的 ./server 与 ./plugin 兼容入口;不承载 OpenCode 2 setup API
4
+ * [POS]: OpenCode 1 插件实现模块,由包入口 entry.ts 以 { id, server } 组合导出;自身不是 exports 解析目标
5
5
  * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
6
  */
7
7
 
package/src/plugin.ts CHANGED
@@ -1,7 +1,7 @@
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 事件上报推送
4
- * [POS]: @kkcode-app/agent 默认插件入口;OpenCode 1 由独立 ./server export 加载 plugin-v1.ts
3
+ * [OUTPUT]: 默认导出 `{ id, setup }` OpenCode 2 插件,按 execution/permission/Form 事件上报推送;对 NOTIFIABLE_EVENT_TYPES 内的丢弃路径写调试日志,保证推送静默失败可排查
4
+ * [POS]: OpenCode 2 插件实现模块,与 plugin-v1.ts 一起由包入口 entry.ts 组合导出;自身不是 exports 解析目标
5
5
  * [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
6
6
  */
7
7
 
@@ -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