@cleocode/adapters 2026.3.71 → 2026.3.73

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 (96) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1227 -101
  4. package/dist/index.js.map +4 -4
  5. package/dist/providers/claude-code/adapter.d.ts.map +1 -1
  6. package/dist/providers/claude-code/adapter.js +16 -5
  7. package/dist/providers/claude-code/adapter.js.map +1 -1
  8. package/dist/providers/claude-code/hooks.d.ts +89 -25
  9. package/dist/providers/claude-code/hooks.d.ts.map +1 -1
  10. package/dist/providers/claude-code/hooks.js +230 -28
  11. package/dist/providers/claude-code/hooks.js.map +1 -1
  12. package/dist/providers/codex/adapter.d.ts +70 -0
  13. package/dist/providers/codex/adapter.d.ts.map +1 -0
  14. package/dist/providers/codex/adapter.js +134 -0
  15. package/dist/providers/codex/adapter.js.map +1 -0
  16. package/dist/providers/codex/hooks.d.ts +85 -0
  17. package/dist/providers/codex/hooks.d.ts.map +1 -0
  18. package/dist/providers/codex/hooks.js +155 -0
  19. package/dist/providers/codex/hooks.js.map +1 -0
  20. package/dist/providers/codex/index.d.ts +22 -0
  21. package/dist/providers/codex/index.d.ts.map +1 -0
  22. package/dist/providers/codex/index.js +24 -0
  23. package/dist/providers/codex/index.js.map +1 -0
  24. package/dist/providers/codex/install.d.ts +74 -0
  25. package/dist/providers/codex/install.d.ts.map +1 -0
  26. package/dist/providers/codex/install.js +183 -0
  27. package/dist/providers/codex/install.js.map +1 -0
  28. package/dist/providers/cursor/adapter.d.ts.map +1 -1
  29. package/dist/providers/cursor/adapter.js +16 -2
  30. package/dist/providers/cursor/adapter.js.map +1 -1
  31. package/dist/providers/cursor/hooks.d.ts +102 -17
  32. package/dist/providers/cursor/hooks.d.ts.map +1 -1
  33. package/dist/providers/cursor/hooks.js +164 -18
  34. package/dist/providers/cursor/hooks.js.map +1 -1
  35. package/dist/providers/gemini-cli/adapter.d.ts +70 -0
  36. package/dist/providers/gemini-cli/adapter.d.ts.map +1 -0
  37. package/dist/providers/gemini-cli/adapter.js +145 -0
  38. package/dist/providers/gemini-cli/adapter.js.map +1 -0
  39. package/dist/providers/gemini-cli/hooks.d.ts +92 -0
  40. package/dist/providers/gemini-cli/hooks.d.ts.map +1 -0
  41. package/dist/providers/gemini-cli/hooks.js +169 -0
  42. package/dist/providers/gemini-cli/hooks.js.map +1 -0
  43. package/dist/providers/gemini-cli/index.d.ts +22 -0
  44. package/dist/providers/gemini-cli/index.d.ts.map +1 -0
  45. package/dist/providers/gemini-cli/index.js +24 -0
  46. package/dist/providers/gemini-cli/index.js.map +1 -0
  47. package/dist/providers/gemini-cli/install.d.ts +74 -0
  48. package/dist/providers/gemini-cli/install.d.ts.map +1 -0
  49. package/dist/providers/gemini-cli/install.js +183 -0
  50. package/dist/providers/gemini-cli/install.js.map +1 -0
  51. package/dist/providers/kimi/adapter.d.ts +72 -0
  52. package/dist/providers/kimi/adapter.d.ts.map +1 -0
  53. package/dist/providers/kimi/adapter.js +133 -0
  54. package/dist/providers/kimi/adapter.js.map +1 -0
  55. package/dist/providers/kimi/hooks.d.ts +64 -0
  56. package/dist/providers/kimi/hooks.d.ts.map +1 -0
  57. package/dist/providers/kimi/hooks.js +73 -0
  58. package/dist/providers/kimi/hooks.js.map +1 -0
  59. package/dist/providers/kimi/index.d.ts +22 -0
  60. package/dist/providers/kimi/index.d.ts.map +1 -0
  61. package/dist/providers/kimi/index.js +24 -0
  62. package/dist/providers/kimi/index.js.map +1 -0
  63. package/dist/providers/kimi/install.d.ts +80 -0
  64. package/dist/providers/kimi/install.d.ts.map +1 -0
  65. package/dist/providers/kimi/install.js +189 -0
  66. package/dist/providers/kimi/install.js.map +1 -0
  67. package/dist/providers/opencode/adapter.d.ts.map +1 -1
  68. package/dist/providers/opencode/adapter.js +13 -6
  69. package/dist/providers/opencode/adapter.js.map +1 -1
  70. package/dist/providers/opencode/hooks.d.ts +89 -28
  71. package/dist/providers/opencode/hooks.d.ts.map +1 -1
  72. package/dist/providers/opencode/hooks.js +145 -37
  73. package/dist/providers/opencode/hooks.js.map +1 -1
  74. package/package.json +3 -2
  75. package/src/index.ts +18 -0
  76. package/src/providers/claude-code/adapter.ts +16 -5
  77. package/src/providers/claude-code/hooks.ts +154 -30
  78. package/src/providers/codex/adapter.ts +154 -0
  79. package/src/providers/codex/hooks.ts +163 -0
  80. package/src/providers/codex/index.ts +27 -0
  81. package/src/providers/codex/install.ts +203 -0
  82. package/src/providers/codex/manifest.json +28 -0
  83. package/src/providers/cursor/adapter.ts +16 -2
  84. package/src/providers/cursor/hooks.ts +167 -18
  85. package/src/providers/gemini-cli/adapter.ts +165 -0
  86. package/src/providers/gemini-cli/hooks.ts +177 -0
  87. package/src/providers/gemini-cli/index.ts +27 -0
  88. package/src/providers/gemini-cli/install.ts +203 -0
  89. package/src/providers/gemini-cli/manifest.json +35 -0
  90. package/src/providers/kimi/adapter.ts +153 -0
  91. package/src/providers/kimi/hooks.ts +80 -0
  92. package/src/providers/kimi/index.ts +27 -0
  93. package/src/providers/kimi/install.ts +209 -0
  94. package/src/providers/kimi/manifest.json +24 -0
  95. package/src/providers/opencode/adapter.ts +13 -6
  96. package/src/providers/opencode/hooks.ts +146 -37
@@ -1,51 +1,88 @@
1
1
  /**
2
2
  * OpenCode Hook Provider
3
3
  *
4
- * Maps OpenCode's native hook events to CAAMP hook events.
5
- * OpenCode supports 6 of 8 CAAMP events through its agent/hook system.
4
+ * Maps OpenCode's native hook events to CAAMP canonical hook events.
5
+ * OpenCode supports 10 of 16 canonical events through its plugin system.
6
6
  *
7
- * OpenCode event mapping:
8
- * - session.start -> onSessionStart
9
- * - session.end -> onSessionEnd
10
- * - tool.start -> onToolStart
11
- * - tool.complete -> onToolComplete
12
- * - error -> onError
13
- * - prompt.submit -> onPromptSubmit
7
+ * Event translation uses CAAMP normalizer APIs:
8
+ * - `toCanonical(nativeName, 'opencode')` for runtime event name resolution
9
+ * - `getSupportedEvents('opencode')` to enumerate supported canonical events
10
+ * - `getProviderHookProfile('opencode')` for the full provider profile
14
11
  *
15
- * @task T5240
12
+ * OpenCode uses a JavaScript plugin system with event-prefixed names
13
+ * (e.g. `event:session.created`) for some hooks and bare names for others.
14
+ * The map is derived from `getProviderHookProfile('opencode').mappings` in
15
+ * CAAMP 1.9.1. PostToolUseFailure, SubagentStart, SubagentStop, Notification,
16
+ * and ConfigChange are not supported by OpenCode.
17
+ *
18
+ * @task T164
19
+ * @epic T134
16
20
  */
21
+ /** CAAMP provider identifier for OpenCode. */
22
+ const PROVIDER_ID = 'opencode';
17
23
  /**
18
- * Mapping from OpenCode native event names to CAAMP event names.
24
+ * Fallback map from OpenCode native event names to CAAMP canonical names.
25
+ *
26
+ * Derived from `getProviderHookProfile('opencode').mappings` in CAAMP 1.9.1.
27
+ * Covers all 10 supported events. PostToolUseFailure, SubagentStart,
28
+ * SubagentStop, Notification, and ConfigChange are not supported by OpenCode
29
+ * and are absent from this map.
19
30
  *
20
- * OpenCode uses dot-delimited event names (e.g. "session.start")
21
- * while CAAMP uses camelCase (e.g. "onSessionStart").
31
+ * OpenCode uses dot-delimited and event-prefixed names (e.g. "event:session.created")
32
+ * while CAAMP canonical names are PascalCase (e.g. "SessionStart").
22
33
  */
23
34
  const OPENCODE_EVENT_MAP = {
24
- 'session.start': 'onSessionStart',
25
- 'session.end': 'onSessionEnd',
26
- 'tool.start': 'onToolStart',
27
- 'tool.complete': 'onToolComplete',
28
- error: 'onError',
29
- 'prompt.submit': 'onPromptSubmit',
35
+ // CAAMP: toNative('SessionStart', 'opencode') = 'event:session.created'
36
+ 'event:session.created': 'SessionStart',
37
+ // CAAMP: toNative('SessionEnd', 'opencode') = 'event:session.deleted'
38
+ 'event:session.deleted': 'SessionEnd',
39
+ // CAAMP: toNative('PromptSubmit', 'opencode') = 'chat.message'
40
+ 'chat.message': 'PromptSubmit',
41
+ // CAAMP: toNative('ResponseComplete', 'opencode') = 'event:session.idle'
42
+ 'event:session.idle': 'ResponseComplete',
43
+ // CAAMP: toNative('PreToolUse', 'opencode') = 'tool.execute.before'
44
+ 'tool.execute.before': 'PreToolUse',
45
+ // CAAMP: toNative('PostToolUse', 'opencode') = 'tool.execute.after'
46
+ 'tool.execute.after': 'PostToolUse',
47
+ // CAAMP: toNative('PermissionRequest', 'opencode') = 'permission.ask'
48
+ 'permission.ask': 'PermissionRequest',
49
+ // CAAMP: toNative('PreModel', 'opencode') = 'chat.params'
50
+ 'chat.params': 'PreModel',
51
+ // CAAMP: toNative('PreCompact', 'opencode') = 'experimental.session.compacting'
52
+ 'experimental.session.compacting': 'PreCompact',
53
+ // CAAMP: toNative('PostCompact', 'opencode') = 'event:session.compacted'
54
+ 'event:session.compacted': 'PostCompact',
30
55
  };
31
56
  /**
32
57
  * Hook provider for OpenCode.
33
58
  *
34
- * OpenCode registers hooks via its configuration system at
35
- * .opencode/config.json. Hook handlers are defined as shell commands
36
- * or script paths that execute when the corresponding event fires.
59
+ * OpenCode registers hooks via its JavaScript plugin system at
60
+ * `.opencode/plugins/`. Supported handler type: plugin (JavaScript).
61
+ *
62
+ * Event mapping is based on `getProviderHookProfile('opencode')` from
63
+ * CAAMP 1.9.1. Async accessors (`getSupportedCanonicalEvents`,
64
+ * `getProviderProfile`) call CAAMP directly when available.
37
65
  *
38
- * Since hooks are registered through the config system (managed by
39
- * the install provider), registerNativeHooks and unregisterNativeHooks
40
- * track registration state without performing filesystem operations.
66
+ * Since hooks are registered through the plugin system (managed by the install
67
+ * provider), `registerNativeHooks` and `unregisterNativeHooks` track registration
68
+ * state without performing filesystem operations.
69
+ *
70
+ * @task T164
71
+ * @epic T134
41
72
  */
42
73
  export class OpenCodeHookProvider {
43
74
  registered = false;
44
75
  /**
45
- * Map an OpenCode native event name to a CAAMP hook event name.
76
+ * Map an OpenCode native event name to a CAAMP canonical hook event name.
77
+ *
78
+ * Looks up the native event name in the map derived from
79
+ * `getProviderHookProfile('opencode').mappings` (CAAMP 1.9.1).
80
+ * Returns null for unsupported events (PostToolUseFailure, SubagentStart,
81
+ * SubagentStop, Notification, ConfigChange).
46
82
  *
47
- * @param providerEvent - OpenCode event name (e.g. "session.start", "tool.complete")
48
- * @returns CAAMP event name or null if unmapped
83
+ * @param providerEvent - OpenCode native event (e.g. "event:session.created", "tool.execute.before")
84
+ * @returns CAAMP canonical event name, or null if unmapped
85
+ * @task T164
49
86
  */
50
87
  mapProviderEvent(providerEvent) {
51
88
  return OPENCODE_EVENT_MAP[providerEvent] ?? null;
@@ -53,12 +90,15 @@ export class OpenCodeHookProvider {
53
90
  /**
54
91
  * Register native hooks for a project.
55
92
  *
56
- * For OpenCode, hooks are registered via the config system
57
- * (.opencode/config.json), which is handled by the install provider.
58
- * This method marks hooks as registered without performing
59
- * filesystem operations.
93
+ * For OpenCode, hooks are registered via the plugin system
94
+ * (`.opencode/plugins/`), managed by the install provider.
95
+ * This method marks hooks as registered without performing filesystem operations.
96
+ *
97
+ * Iterating supported events is handled at install time using
98
+ * `getSupportedCanonicalEvents()` to enumerate all 10 supported hooks.
60
99
  *
61
100
  * @param _projectDir - Project directory (unused; config manages registration)
101
+ * @task T164
62
102
  */
63
103
  async registerNativeHooks(_projectDir) {
64
104
  this.registered = true;
@@ -66,24 +106,92 @@ export class OpenCodeHookProvider {
66
106
  /**
67
107
  * Unregister native hooks.
68
108
  *
69
- * For OpenCode, this is a no-op since hooks are managed through
70
- * the config system. Unregistration happens via the install
71
- * provider's uninstall method.
109
+ * For OpenCode, this is a no-op since hooks are managed through the plugin
110
+ * system. Unregistration happens via the install provider's uninstall method.
111
+ *
112
+ * @task T164
72
113
  */
73
114
  async unregisterNativeHooks() {
74
115
  this.registered = false;
75
116
  }
76
117
  /**
77
- * Check whether hooks have been registered via registerNativeHooks.
118
+ * Check whether hooks have been registered via `registerNativeHooks`.
78
119
  */
79
120
  isRegistered() {
80
121
  return this.registered;
81
122
  }
82
123
  /**
83
- * Get the full event mapping for introspection/debugging.
124
+ * Get the native→canonical event mapping for introspection and debugging.
125
+ *
126
+ * Returns the map derived from `getProviderHookProfile('opencode').mappings`
127
+ * (CAAMP 1.9.1). Use `getSupportedCanonicalEvents()` to enumerate canonical
128
+ * names via live CAAMP APIs.
129
+ *
130
+ * @returns Immutable record of native event name → canonical event name
84
131
  */
85
132
  getEventMap() {
86
133
  return { ...OPENCODE_EVENT_MAP };
87
134
  }
135
+ /**
136
+ * Enumerate supported canonical events via CAAMP's `getSupportedEvents()`.
137
+ *
138
+ * Calls `getSupportedEvents('opencode')` from the CAAMP normalizer to get the
139
+ * authoritative list. OpenCode supports 10 of 16 canonical events via its
140
+ * plugin system. Falls back to the values of the static event map when
141
+ * CAAMP is unavailable at runtime.
142
+ *
143
+ * @returns Array of CAAMP canonical event names supported by OpenCode
144
+ * @task T164
145
+ */
146
+ async getSupportedCanonicalEvents() {
147
+ try {
148
+ const { getSupportedEvents } = await import('@cleocode/caamp');
149
+ return getSupportedEvents(PROVIDER_ID);
150
+ }
151
+ catch {
152
+ return [...new Set(Object.values(OPENCODE_EVENT_MAP))];
153
+ }
154
+ }
155
+ /**
156
+ * Retrieve the full provider hook profile from CAAMP.
157
+ *
158
+ * Calls `getProviderHookProfile('opencode')` from the CAAMP normalizer to
159
+ * get the complete profile: hook system type (`plugin`), config path
160
+ * (`.opencode/plugins/`), handler types, and all event mappings.
161
+ * Returns null when CAAMP is unavailable at runtime.
162
+ *
163
+ * @returns Provider hook profile or null if CAAMP is unavailable
164
+ * @task T164
165
+ */
166
+ async getProviderProfile() {
167
+ try {
168
+ const { getProviderHookProfile } = await import('@cleocode/caamp');
169
+ return getProviderHookProfile(PROVIDER_ID) ?? null;
170
+ }
171
+ catch {
172
+ return null;
173
+ }
174
+ }
175
+ /**
176
+ * Translate a CAAMP canonical event to its OpenCode native name via CAAMP.
177
+ *
178
+ * Calls `toNative(canonical, 'opencode')` from the CAAMP normalizer.
179
+ * Returns null for unsupported events or when CAAMP is unavailable.
180
+ *
181
+ * @param canonical - CAAMP canonical event name (e.g. "PreToolUse")
182
+ * @returns OpenCode native event name or null
183
+ * @task T164
184
+ */
185
+ async toNativeEvent(canonical) {
186
+ try {
187
+ const { toNative } = await import('@cleocode/caamp');
188
+ return toNative(canonical, PROVIDER_ID);
189
+ }
190
+ catch {
191
+ // Invert the static map as fallback
192
+ const entry = Object.entries(OPENCODE_EVENT_MAP).find(([, v]) => v === canonical);
193
+ return entry?.[0] ?? null;
194
+ }
195
+ }
88
196
  }
89
197
  //# sourceMappingURL=hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/providers/opencode/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;;GAKG;AACH,MAAM,kBAAkB,GAA2B;IACjD,eAAe,EAAE,gBAAgB;IACjC,aAAa,EAAE,cAAc;IAC7B,YAAY,EAAE,aAAa;IAC3B,eAAe,EAAE,gBAAgB;IACjC,KAAK,EAAE,SAAS;IAChB,eAAe,EAAE,gBAAgB;CAClC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,OAAO,oBAAoB;IACvB,UAAU,GAAG,KAAK,CAAC;IAE3B;;;;;OAKG;IACH,gBAAgB,CAAC,aAAqB;QACpC,OAAO,kBAAkB,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC;IACnD,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,mBAAmB,CAAC,WAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,qBAAqB;QACzB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,EAAE,GAAG,kBAAkB,EAAE,CAAC;IACnC,CAAC;CACF"}
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/providers/opencode/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,8CAA8C;AAC9C,MAAM,WAAW,GAAG,UAAmB,CAAC;AAExC;;;;;;;;;;GAUG;AACH,MAAM,kBAAkB,GAA2B;IACjD,8EAA8E;IAC9E,uBAAuB,EAAE,cAAc;IACvC,8EAA8E;IAC9E,uBAAuB,EAAE,YAAY;IACrC,qEAAqE;IACrE,cAAc,EAAE,cAAc;IAC9B,2EAA2E;IAC3E,oBAAoB,EAAE,kBAAkB;IACxC,4EAA4E;IAC5E,qBAAqB,EAAE,YAAY;IACnC,2EAA2E;IAC3E,oBAAoB,EAAE,aAAa;IACnC,uEAAuE;IACvE,gBAAgB,EAAE,mBAAmB;IACrC,oEAAoE;IACpE,aAAa,EAAE,UAAU;IACzB,wFAAwF;IACxF,iCAAiC,EAAE,YAAY;IAC/C,gFAAgF;IAChF,yBAAyB,EAAE,aAAa;CACzC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,oBAAoB;IACvB,UAAU,GAAG,KAAK,CAAC;IAE3B;;;;;;;;;;;OAWG;IACH,gBAAgB,CAAC,aAAqB;QACpC,OAAO,kBAAkB,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC;IACnD,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,mBAAmB,CAAC,WAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,qBAAqB;QACzB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;;;;;OAQG;IACH,WAAW;QACT,OAAO,EAAE,GAAG,kBAAkB,EAAE,CAAC;IACnC,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,2BAA2B;QAC/B,IAAI,CAAC;YACH,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;YAC/D,OAAO,kBAAkB,CAAC,WAAW,CAAa,CAAC;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,kBAAkB;QACtB,IAAI,CAAC;YACH,MAAM,EAAE,sBAAsB,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACnE,OAAO,sBAAsB,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,aAAa,CAAC,SAAiB;QACnC,IAAI,CAAC;YACH,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC,SAA2C,EAAE,WAAW,CAAC,CAAC;QAC5E,CAAC;QAAC,MAAM,CAAC;YACP,oCAAoC;YACpC,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;YAClF,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleocode/adapters",
3
- "version": "2026.3.71",
3
+ "version": "2026.3.73",
4
4
  "description": "Unified provider adapters for CLEO (Claude Code, OpenCode, Cursor)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,8 @@
12
12
  }
13
13
  },
14
14
  "dependencies": {
15
- "@cleocode/contracts": "2026.3.71"
15
+ "@cleocode/caamp": "^1.9.1",
16
+ "@cleocode/contracts": "2026.3.73"
16
17
  },
17
18
  "license": "MIT",
18
19
  "engines": {
package/src/index.ts CHANGED
@@ -20,12 +20,30 @@ export {
20
20
  getSetupInstructions,
21
21
  getStatuslineConfig,
22
22
  } from './providers/claude-code/index.js';
23
+ export {
24
+ CodexAdapter,
25
+ CodexHookProvider,
26
+ CodexInstallProvider,
27
+ createAdapter as createCodexAdapter,
28
+ } from './providers/codex/index.js';
23
29
  export {
24
30
  CursorAdapter,
25
31
  CursorHookProvider,
26
32
  CursorInstallProvider,
27
33
  createAdapter as createCursorAdapter,
28
34
  } from './providers/cursor/index.js';
35
+ export {
36
+ createAdapter as createGeminiCliAdapter,
37
+ GeminiCliAdapter,
38
+ GeminiCliHookProvider,
39
+ GeminiCliInstallProvider,
40
+ } from './providers/gemini-cli/index.js';
41
+ export {
42
+ createAdapter as createKimiAdapter,
43
+ KimiAdapter,
44
+ KimiHookProvider,
45
+ KimiInstallProvider,
46
+ } from './providers/kimi/index.js';
29
47
  export {
30
48
  createAdapter as createOpenCodeAdapter,
31
49
  OpenCodeAdapter,
@@ -42,12 +42,23 @@ export class ClaudeCodeAdapter implements CLEOProviderAdapter {
42
42
 
43
43
  capabilities: AdapterCapabilities = {
44
44
  supportsHooks: true,
45
+ // 14/16 canonical events — derived from getProviderHookProfile('claude-code') in CAAMP 1.9.1.
46
+ // PreModel and PostModel are not supported by Claude Code.
45
47
  supportedHookEvents: [
46
- 'onSessionStart',
47
- 'onSessionEnd',
48
- 'onToolStart',
49
- 'onToolComplete',
50
- 'onError',
48
+ 'SessionStart',
49
+ 'SessionEnd',
50
+ 'PromptSubmit',
51
+ 'ResponseComplete',
52
+ 'PreToolUse',
53
+ 'PostToolUse',
54
+ 'PostToolUseFailure',
55
+ 'PermissionRequest',
56
+ 'SubagentStart',
57
+ 'SubagentStop',
58
+ 'PreCompact',
59
+ 'PostCompact',
60
+ 'Notification',
61
+ 'ConfigChange',
51
62
  ],
52
63
  supportsSpawn: true,
53
64
  supportsInstall: true,
@@ -1,12 +1,18 @@
1
1
  /**
2
2
  * Claude Code Hook Provider
3
3
  *
4
- * Maps Claude Code's native hook events to CAAMP hook events.
5
- * Claude Code uses: SessionStart, PostToolUse, UserPromptSubmit, Stop
6
- * CAAMP defines: onSessionStart, onToolComplete, onPromptSubmit, onSessionEnd
4
+ * Maps Claude Code's native hook events to CAAMP canonical hook events.
5
+ * Claude Code supports 14 of 16 canonical events (all except PreModel, PostModel).
7
6
  *
8
- * @task T5240
9
- * @task T144
7
+ * Event translation uses CAAMP normalizer APIs:
8
+ * - `toCanonical(nativeName, 'claude-code')` for runtime event name resolution
9
+ * - `getSupportedEvents('claude-code')` to enumerate supported canonical events
10
+ * - `getProviderHookProfile('claude-code')` for the full provider profile
11
+ *
12
+ * A static map derived from CAAMP 1.9.1 hook-mappings.json is maintained as
13
+ * a fallback for environments where CAAMP's runtime resolution is unavailable.
14
+ *
15
+ * @task T164
10
16
  * @epic T134
11
17
  */
12
18
 
@@ -14,35 +20,81 @@ import { readdir, readFile } from 'node:fs/promises';
14
20
  import { join } from 'node:path';
15
21
  import type { AdapterHookProvider } from '@cleocode/contracts';
16
22
 
23
+ /** CAAMP provider identifier for Claude Code. */
24
+ const PROVIDER_ID = 'claude-code' as const;
25
+
17
26
  /**
18
- * Mapping from Claude Code native event names to CAAMP event names.
27
+ * Fallback map from Claude Code native event names to CAAMP canonical names.
28
+ *
29
+ * Derived from `getProviderHookProfile('claude-code').mappings` in CAAMP 1.9.1.
30
+ * Covers all 14 supported events. PreModel and PostModel are not supported
31
+ * by Claude Code and are absent from this map.
32
+ *
33
+ * Used as fallback when CAAMP runtime is unavailable, and as the synchronous
34
+ * implementation of `mapProviderEvent()`.
19
35
  */
20
36
  const CLAUDE_CODE_EVENT_MAP: Record<string, string> = {
21
- SessionStart: 'onSessionStart',
22
- PostToolUse: 'onToolComplete',
23
- UserPromptSubmit: 'onPromptSubmit',
24
- Stop: 'onSessionEnd',
37
+ // CAAMP: toNative('SessionStart', 'claude-code') = 'SessionStart'
38
+ SessionStart: 'SessionStart',
39
+ // CAAMP: toNative('SessionEnd', 'claude-code') = 'SessionEnd'
40
+ SessionEnd: 'SessionEnd',
41
+ // CAAMP: toNative('PromptSubmit', 'claude-code') = 'UserPromptSubmit'
42
+ UserPromptSubmit: 'PromptSubmit',
43
+ // CAAMP: toNative('ResponseComplete', 'claude-code') = 'Stop'
44
+ Stop: 'ResponseComplete',
45
+ // CAAMP: toNative('PreToolUse', 'claude-code') = 'PreToolUse'
46
+ PreToolUse: 'PreToolUse',
47
+ // CAAMP: toNative('PostToolUse', 'claude-code') = 'PostToolUse'
48
+ PostToolUse: 'PostToolUse',
49
+ // CAAMP: toNative('PostToolUseFailure','claude-code') = 'PostToolUseFailure'
50
+ PostToolUseFailure: 'PostToolUseFailure',
51
+ // CAAMP: toNative('PermissionRequest', 'claude-code') = 'PermissionRequest'
52
+ PermissionRequest: 'PermissionRequest',
53
+ // CAAMP: toNative('SubagentStart', 'claude-code') = 'SubagentStart'
54
+ SubagentStart: 'SubagentStart',
55
+ // CAAMP: toNative('SubagentStop', 'claude-code') = 'SubagentStop'
56
+ SubagentStop: 'SubagentStop',
57
+ // CAAMP: toNative('PreCompact', 'claude-code') = 'PreCompact'
58
+ PreCompact: 'PreCompact',
59
+ // CAAMP: toNative('PostCompact', 'claude-code') = 'PostCompact'
60
+ PostCompact: 'PostCompact',
61
+ // CAAMP: toNative('Notification', 'claude-code') = 'Notification'
62
+ Notification: 'Notification',
63
+ // CAAMP: toNative('ConfigChange', 'claude-code') = 'ConfigChange'
64
+ ConfigChange: 'ConfigChange',
25
65
  };
26
66
 
27
67
  /**
28
68
  * Hook provider for Claude Code.
29
69
  *
30
- * Claude Code registers hooks via a plugin directory
31
- * with a hooks.json descriptor. The actual hook scripts are shell scripts
32
- * that invoke CLEO's brain observation system.
70
+ * Claude Code registers hooks via its global config at `~/.claude/settings.json`.
71
+ * Supported handler types: command, http, prompt, agent.
72
+ *
73
+ * Event mapping is based on `getProviderHookProfile('claude-code')` from
74
+ * CAAMP 1.9.1. Async accessors (`getSupportedCanonicalEvents`,
75
+ * `getProviderProfile`) call CAAMP directly when available.
33
76
  *
34
- * Since hooks are registered through the plugin system (installed via
35
- * the install provider), registerNativeHooks and unregisterNativeHooks
36
- * are effectively no-ops here — the plugin installer handles registration.
77
+ * Since hooks are registered through the config system (managed by the install
78
+ * provider), `registerNativeHooks` and `unregisterNativeHooks` track registration
79
+ * state without performing filesystem operations.
80
+ *
81
+ * @task T164
82
+ * @epic T134
37
83
  */
38
84
  export class ClaudeCodeHookProvider implements AdapterHookProvider {
39
85
  private registered = false;
40
86
 
41
87
  /**
42
- * Map a Claude Code native event name to a CAAMP hook event name.
88
+ * Map a Claude Code native event name to a CAAMP canonical hook event name.
89
+ *
90
+ * Looks up the native event name in the map derived from
91
+ * `getProviderHookProfile('claude-code').mappings` (CAAMP 1.9.1).
92
+ * Returns null for unrecognised events (e.g. PreModel, PostModel which
93
+ * Claude Code does not support).
43
94
  *
44
- * @param providerEvent - Claude Code event name (e.g. "SessionStart", "PostToolUse")
45
- * @returns CAAMP event name or null if unmapped
95
+ * @param providerEvent - Claude Code native event (e.g. "UserPromptSubmit", "Stop")
96
+ * @returns CAAMP canonical event name, or null if unmapped
97
+ * @task T164
46
98
  */
47
99
  mapProviderEvent(providerEvent: string): string | null {
48
100
  return CLAUDE_CODE_EVENT_MAP[providerEvent] ?? null;
@@ -51,12 +103,15 @@ export class ClaudeCodeHookProvider implements AdapterHookProvider {
51
103
  /**
52
104
  * Register native hooks for a project.
53
105
  *
54
- * For Claude Code, hooks are registered via the plugin system
55
- * (hooks.json descriptor), which is handled by the
56
- * install provider. This method is a no-op since registration
57
- * is managed through the plugin install lifecycle.
106
+ * For Claude Code, hooks are registered via the config system
107
+ * (`~/.claude/settings.json`), managed by the install provider.
108
+ * This method marks hooks as registered without performing filesystem operations.
58
109
  *
59
- * @param _projectDir - Project directory (unused; hooks are global)
110
+ * Iterating supported events is handled at install time using
111
+ * `getSupportedCanonicalEvents()` to enumerate all 14 supported hooks.
112
+ *
113
+ * @param _projectDir - Project directory (unused; Claude Code uses global config)
114
+ * @task T164
60
115
  */
61
116
  async registerNativeHooks(_projectDir: string): Promise<void> {
62
117
  this.registered = true;
@@ -65,32 +120,101 @@ export class ClaudeCodeHookProvider implements AdapterHookProvider {
65
120
  /**
66
121
  * Unregister native hooks.
67
122
  *
68
- * For Claude Code, this is a no-op since hooks are managed through
69
- * the plugin system. Unregistration happens via the install provider's
70
- * uninstall method.
123
+ * For Claude Code, this is a no-op since hooks are managed through the config
124
+ * system. Unregistration happens via the install provider's uninstall method.
125
+ *
126
+ * @task T164
71
127
  */
72
128
  async unregisterNativeHooks(): Promise<void> {
73
129
  this.registered = false;
74
130
  }
75
131
 
76
132
  /**
77
- * Check whether hooks have been registered via registerNativeHooks.
133
+ * Check whether hooks have been registered via `registerNativeHooks`.
78
134
  */
79
135
  isRegistered(): boolean {
80
136
  return this.registered;
81
137
  }
82
138
 
83
139
  /**
84
- * Get the full event mapping for introspection/debugging.
140
+ * Get the native→canonical event mapping for introspection and debugging.
141
+ *
142
+ * Returns the map derived from `getProviderHookProfile('claude-code').mappings`
143
+ * (CAAMP 1.9.1). Use `getSupportedCanonicalEvents()` to enumerate canonical
144
+ * names via live CAAMP APIs.
145
+ *
146
+ * @returns Immutable record of native event name → canonical event name
85
147
  */
86
148
  getEventMap(): Readonly<Record<string, string>> {
87
149
  return { ...CLAUDE_CODE_EVENT_MAP };
88
150
  }
89
151
 
152
+ /**
153
+ * Enumerate supported canonical events via CAAMP's `getSupportedEvents()`.
154
+ *
155
+ * Calls `getSupportedEvents('claude-code')` from the CAAMP normalizer to
156
+ * get the authoritative list. Claude Code supports 14 of 16 canonical events
157
+ * (PreModel and PostModel are not supported). Falls back to the values of
158
+ * the static event map when CAAMP is unavailable at runtime.
159
+ *
160
+ * @returns Array of CAAMP canonical event names supported by Claude Code
161
+ * @task T164
162
+ */
163
+ async getSupportedCanonicalEvents(): Promise<string[]> {
164
+ try {
165
+ const { getSupportedEvents } = await import('@cleocode/caamp');
166
+ return getSupportedEvents(PROVIDER_ID) as string[];
167
+ } catch {
168
+ return [...new Set(Object.values(CLAUDE_CODE_EVENT_MAP))];
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Retrieve the full provider hook profile from CAAMP.
174
+ *
175
+ * Calls `getProviderHookProfile('claude-code')` from the CAAMP normalizer to
176
+ * get the complete profile: hook system type (`config`), config path
177
+ * (`~/.claude/settings.json`), handler types, and all event mappings.
178
+ * Returns null when CAAMP is unavailable at runtime.
179
+ *
180
+ * @returns Provider hook profile or null if CAAMP is unavailable
181
+ * @task T164
182
+ */
183
+ async getProviderProfile(): Promise<unknown | null> {
184
+ try {
185
+ const { getProviderHookProfile } = await import('@cleocode/caamp');
186
+ return getProviderHookProfile(PROVIDER_ID) ?? null;
187
+ } catch {
188
+ return null;
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Translate a CAAMP canonical event to its Claude Code native name via CAAMP.
194
+ *
195
+ * Calls `toNative(canonical, 'claude-code')` from the CAAMP normalizer.
196
+ * Returns null for unsupported events (PreModel, PostModel) or when
197
+ * CAAMP is unavailable.
198
+ *
199
+ * @param canonical - CAAMP canonical event name (e.g. "PromptSubmit")
200
+ * @returns Claude Code native event name or null
201
+ * @task T164
202
+ */
203
+ async toNativeEvent(canonical: string): Promise<string | null> {
204
+ try {
205
+ const { toNative } = await import('@cleocode/caamp');
206
+ return toNative(canonical as Parameters<typeof toNative>[0], PROVIDER_ID);
207
+ } catch {
208
+ // Invert the static map as fallback
209
+ const entry = Object.entries(CLAUDE_CODE_EVENT_MAP).find(([, v]) => v === canonical);
210
+ return entry?.[0] ?? null;
211
+ }
212
+ }
213
+
90
214
  /**
91
215
  * Extract a plain-text transcript from Claude Code session JSONL files.
92
216
  *
93
- * Reads the most recent .jsonl file under ~/.claude/projects/ and
217
+ * Reads the most recent .jsonl file under `~/.claude/projects/` and
94
218
  * extracts user/assistant turn text into a flat string for brain
95
219
  * observation extraction.
96
220
  *