@eddacraft/kindling-adapter-claude-code 0.1.0
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/LICENSE +190 -0
- package/README.md +198 -0
- package/dist/claude-code/events.d.ts +134 -0
- package/dist/claude-code/events.d.ts.map +1 -0
- package/dist/claude-code/events.js +94 -0
- package/dist/claude-code/events.js.map +1 -0
- package/dist/claude-code/filter.d.ts +60 -0
- package/dist/claude-code/filter.d.ts.map +1 -0
- package/dist/claude-code/filter.js +150 -0
- package/dist/claude-code/filter.js.map +1 -0
- package/dist/claude-code/hooks.d.ts +105 -0
- package/dist/claude-code/hooks.d.ts.map +1 -0
- package/dist/claude-code/hooks.js +113 -0
- package/dist/claude-code/hooks.js.map +1 -0
- package/dist/claude-code/index.d.ts +12 -0
- package/dist/claude-code/index.d.ts.map +1 -0
- package/dist/claude-code/index.js +18 -0
- package/dist/claude-code/index.js.map +1 -0
- package/dist/claude-code/mapping.d.ts +27 -0
- package/dist/claude-code/mapping.d.ts.map +1 -0
- package/dist/claude-code/mapping.js +234 -0
- package/dist/claude-code/mapping.js.map +1 -0
- package/dist/claude-code/provenance.d.ts +27 -0
- package/dist/claude-code/provenance.d.ts.map +1 -0
- package/dist/claude-code/provenance.js +134 -0
- package/dist/claude-code/provenance.js.map +1 -0
- package/dist/claude-code/session.d.ts +98 -0
- package/dist/claude-code/session.d.ts.map +1 -0
- package/dist/claude-code/session.js +191 -0
- package/dist/claude-code/session.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright
|
|
52
|
+
owner or by an individual or Legal Entity authorized to submit on behalf
|
|
53
|
+
of the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 EddaCraft
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# @eddacraft/kindling-adapter-claude-code
|
|
2
|
+
|
|
3
|
+
Claude Code adapter for Kindling - capture tool calls and session context via hooks for memory continuity.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This adapter integrates Kindling with [Claude Code](https://claude.ai/code) via its hooks system. It automatically captures:
|
|
8
|
+
|
|
9
|
+
- **Tool calls** (Read, Write, Edit, Bash, Glob, Grep, etc.)
|
|
10
|
+
- **User messages**
|
|
11
|
+
- **Subagent completions**
|
|
12
|
+
- **Session lifecycle** (start/stop)
|
|
13
|
+
|
|
14
|
+
All captured events become searchable observations in Kindling, enabling context retrieval across sessions.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @eddacraft/kindling-adapter-claude-code @eddacraft/kindling-core @eddacraft/kindling-store-sqlite
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createHookHandlers } from '@eddacraft/kindling-adapter-claude-code';
|
|
26
|
+
import { openDatabase, SqliteKindlingStore } from '@eddacraft/kindling-store-sqlite';
|
|
27
|
+
|
|
28
|
+
// Initialize store
|
|
29
|
+
const db = openDatabase({ dbPath: '~/.kindling/kindling.db' });
|
|
30
|
+
const store = new SqliteKindlingStore(db);
|
|
31
|
+
|
|
32
|
+
// Create hook handlers
|
|
33
|
+
const handlers = createHookHandlers(store);
|
|
34
|
+
|
|
35
|
+
// Register with Claude Code hooks (see Hook Configuration below)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Hook Configuration
|
|
39
|
+
|
|
40
|
+
The adapter provides handlers for Claude Code hooks. Register them in your `.claude/settings.json`:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"hooks": {
|
|
45
|
+
"SessionStart": [
|
|
46
|
+
{
|
|
47
|
+
"type": "command",
|
|
48
|
+
"command": "kindling-hook session-start"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"PostToolUse": [
|
|
52
|
+
{
|
|
53
|
+
"type": "command",
|
|
54
|
+
"command": "kindling-hook post-tool-use"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"Stop": [
|
|
58
|
+
{
|
|
59
|
+
"type": "command",
|
|
60
|
+
"command": "kindling-hook stop"
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## API Reference
|
|
68
|
+
|
|
69
|
+
### `createHookHandlers(store, config?)`
|
|
70
|
+
|
|
71
|
+
Creates hook handlers connected to a Kindling store.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const handlers = createHookHandlers(store, {
|
|
75
|
+
// Capture tool results (default: true)
|
|
76
|
+
captureResults: true,
|
|
77
|
+
|
|
78
|
+
// Capture user messages (default: true)
|
|
79
|
+
captureUserMessages: true,
|
|
80
|
+
|
|
81
|
+
// Capture subagent outputs (default: true)
|
|
82
|
+
captureSubagents: true,
|
|
83
|
+
|
|
84
|
+
// Default intent for new sessions
|
|
85
|
+
defaultIntent: 'Claude Code session',
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Hook Handlers
|
|
90
|
+
|
|
91
|
+
| Handler | Hook | Description |
|
|
92
|
+
| -------------------- | ---------------- | ----------------------------------- |
|
|
93
|
+
| `onSessionStart` | SessionStart | Opens a session capsule |
|
|
94
|
+
| `onPostToolUse` | PostToolUse | Captures tool calls as observations |
|
|
95
|
+
| `onStop` | Stop | Closes the session capsule |
|
|
96
|
+
| `onUserPromptSubmit` | UserPromptSubmit | Captures user messages |
|
|
97
|
+
| `onSubagentStop` | SubagentStop | Captures subagent completions |
|
|
98
|
+
|
|
99
|
+
### Utility Methods
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
// Check if a session is active
|
|
103
|
+
handlers.isSessionActive('session-123');
|
|
104
|
+
|
|
105
|
+
// Get session statistics
|
|
106
|
+
handlers.getSessionStats('session-123');
|
|
107
|
+
// Returns: { eventCount: 42, duration: 3600000 }
|
|
108
|
+
|
|
109
|
+
// Access the underlying session manager
|
|
110
|
+
const manager = handlers.getSessionManager();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Event Mapping
|
|
114
|
+
|
|
115
|
+
| Claude Code Event | Observation Kind | Description |
|
|
116
|
+
| ------------------------ | ---------------- | -------------------- |
|
|
117
|
+
| PostToolUse (Write/Edit) | `file_diff` | File modifications |
|
|
118
|
+
| PostToolUse (Bash) | `command` | Shell commands |
|
|
119
|
+
| PostToolUse (other) | `tool_call` | Tool invocations |
|
|
120
|
+
| UserPromptSubmit | `message` | User messages |
|
|
121
|
+
| SubagentStop | `node_end` | Subagent completions |
|
|
122
|
+
|
|
123
|
+
## Content Filtering
|
|
124
|
+
|
|
125
|
+
The adapter includes safety features to prevent accidental capture of sensitive data:
|
|
126
|
+
|
|
127
|
+
- **Secret detection**: API keys, tokens, and passwords are automatically masked
|
|
128
|
+
- **Content truncation**: Large outputs are truncated (default: 50KB)
|
|
129
|
+
- **Path exclusions**: Files in `.git/`, `node_modules/`, `.env`, etc. are flagged
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import {
|
|
133
|
+
filterContent,
|
|
134
|
+
maskSecrets,
|
|
135
|
+
isExcludedPath,
|
|
136
|
+
} from '@eddacraft/kindling-adapter-claude-code';
|
|
137
|
+
|
|
138
|
+
// Filter content with secret masking
|
|
139
|
+
const safe = filterContent('api_key=secret123');
|
|
140
|
+
// Result: 'api_key=[REDACTED]'
|
|
141
|
+
|
|
142
|
+
// Check if path should be excluded
|
|
143
|
+
isExcludedPath('/project/.env'); // true
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Direct Usage
|
|
147
|
+
|
|
148
|
+
You can also use the lower-level APIs directly:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { SessionManager, mapEvent } from '@eddacraft/kindling-adapter-claude-code';
|
|
152
|
+
|
|
153
|
+
// Create session manager
|
|
154
|
+
const manager = new SessionManager(store);
|
|
155
|
+
|
|
156
|
+
// Start session
|
|
157
|
+
const ctx = manager.onSessionStart({
|
|
158
|
+
sessionId: 'session-1',
|
|
159
|
+
cwd: '/home/user/project',
|
|
160
|
+
intent: 'Debug authentication',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Process events
|
|
164
|
+
const event = {
|
|
165
|
+
type: 'post_tool_use',
|
|
166
|
+
timestamp: Date.now(),
|
|
167
|
+
sessionId: 'session-1',
|
|
168
|
+
cwd: '/home/user/project',
|
|
169
|
+
toolName: 'Read',
|
|
170
|
+
toolInput: { file_path: '/src/auth.ts' },
|
|
171
|
+
toolResult: '// auth code...',
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const result = manager.onEvent(event);
|
|
175
|
+
|
|
176
|
+
// End session
|
|
177
|
+
manager.onStop('session-1', {
|
|
178
|
+
summaryContent: 'Fixed token validation bug',
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Use Case: Session Continuity
|
|
183
|
+
|
|
184
|
+
The primary use case is maintaining context across Claude Code sessions:
|
|
185
|
+
|
|
186
|
+
1. **Session 1**: Work on authentication bug
|
|
187
|
+
- Adapter captures: file reads, edits, test runs, errors
|
|
188
|
+
- Session closes with summary
|
|
189
|
+
|
|
190
|
+
2. **Session 2**: "What did I work on yesterday?"
|
|
191
|
+
- Query Kindling: `service.retrieve({ query: 'authentication' })`
|
|
192
|
+
- Get back: relevant observations with provenance
|
|
193
|
+
|
|
194
|
+
This enables Claude Code to "remember" what happened in previous sessions.
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
Apache-2.0
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code hook event type definitions
|
|
3
|
+
*
|
|
4
|
+
* These represent events emitted by Claude Code hooks during sessions.
|
|
5
|
+
* Based on Claude Code hooks documentation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base context provided to all hooks
|
|
9
|
+
*/
|
|
10
|
+
export interface HookContext {
|
|
11
|
+
/** Current working directory */
|
|
12
|
+
cwd: string;
|
|
13
|
+
/** Session ID */
|
|
14
|
+
sessionId: string;
|
|
15
|
+
/** Transcript path (readonly) */
|
|
16
|
+
transcriptPath?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Tool use input/output for PreToolUse and PostToolUse hooks
|
|
20
|
+
*/
|
|
21
|
+
export interface ToolUseContext extends HookContext {
|
|
22
|
+
/** Tool name (Read, Write, Edit, Bash, Glob, Grep, etc.) */
|
|
23
|
+
toolName: string;
|
|
24
|
+
/** Tool input parameters */
|
|
25
|
+
toolInput: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* PostToolUse hook context with result
|
|
29
|
+
*/
|
|
30
|
+
export interface PostToolUseContext extends ToolUseContext {
|
|
31
|
+
/** Tool result (success case) */
|
|
32
|
+
toolResult?: unknown;
|
|
33
|
+
/** Tool error (failure case) */
|
|
34
|
+
toolError?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* SessionStart hook context
|
|
38
|
+
*/
|
|
39
|
+
export interface SessionStartContext extends HookContext {
|
|
40
|
+
/** Optional project name derived from cwd */
|
|
41
|
+
projectName?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Stop hook context
|
|
45
|
+
*/
|
|
46
|
+
export interface StopContext extends HookContext {
|
|
47
|
+
/** Stop reason */
|
|
48
|
+
reason?: 'user' | 'complete' | 'error' | 'interrupt';
|
|
49
|
+
/** Final transcript summary if available */
|
|
50
|
+
summary?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* SubagentStop hook context
|
|
54
|
+
*/
|
|
55
|
+
export interface SubagentStopContext extends HookContext {
|
|
56
|
+
/** Subagent type */
|
|
57
|
+
agentType: string;
|
|
58
|
+
/** Subagent task description */
|
|
59
|
+
task?: string;
|
|
60
|
+
/** Subagent output */
|
|
61
|
+
output?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* UserPromptSubmit hook context
|
|
65
|
+
*/
|
|
66
|
+
export interface UserPromptSubmitContext extends HookContext {
|
|
67
|
+
/** User's message content */
|
|
68
|
+
content: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* PreCompact hook context
|
|
72
|
+
*/
|
|
73
|
+
export interface PreCompactContext extends HookContext {
|
|
74
|
+
/** Token count before compaction */
|
|
75
|
+
tokenCount?: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Claude Code hook event - unified type for all hook events
|
|
79
|
+
*/
|
|
80
|
+
export interface ClaudeCodeEvent {
|
|
81
|
+
/** Hook type */
|
|
82
|
+
type: 'session_start' | 'pre_tool_use' | 'post_tool_use' | 'stop' | 'subagent_stop' | 'user_prompt' | 'pre_compact';
|
|
83
|
+
/** Event timestamp */
|
|
84
|
+
timestamp: number;
|
|
85
|
+
/** Session ID */
|
|
86
|
+
sessionId: string;
|
|
87
|
+
/** Working directory (used as repoId) */
|
|
88
|
+
cwd: string;
|
|
89
|
+
/** Tool name (for tool use events) */
|
|
90
|
+
toolName?: string;
|
|
91
|
+
/** Tool input parameters */
|
|
92
|
+
toolInput?: Record<string, unknown>;
|
|
93
|
+
/** Tool result */
|
|
94
|
+
toolResult?: unknown;
|
|
95
|
+
/** Tool error */
|
|
96
|
+
toolError?: string;
|
|
97
|
+
/** User message content */
|
|
98
|
+
userContent?: string;
|
|
99
|
+
/** Subagent type */
|
|
100
|
+
agentType?: string;
|
|
101
|
+
/** Subagent output */
|
|
102
|
+
agentOutput?: string;
|
|
103
|
+
/** Stop reason */
|
|
104
|
+
stopReason?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Create event from SessionStart hook
|
|
108
|
+
*/
|
|
109
|
+
export declare function createSessionStartEvent(ctx: SessionStartContext): ClaudeCodeEvent;
|
|
110
|
+
/**
|
|
111
|
+
* Create event from PostToolUse hook
|
|
112
|
+
*/
|
|
113
|
+
export declare function createPostToolUseEvent(ctx: PostToolUseContext): ClaudeCodeEvent;
|
|
114
|
+
/**
|
|
115
|
+
* Create event from Stop hook
|
|
116
|
+
*/
|
|
117
|
+
export declare function createStopEvent(ctx: StopContext): ClaudeCodeEvent;
|
|
118
|
+
/**
|
|
119
|
+
* Create event from SubagentStop hook
|
|
120
|
+
*/
|
|
121
|
+
export declare function createSubagentStopEvent(ctx: SubagentStopContext): ClaudeCodeEvent;
|
|
122
|
+
/**
|
|
123
|
+
* Create event from UserPromptSubmit hook
|
|
124
|
+
*/
|
|
125
|
+
export declare function createUserPromptEvent(ctx: UserPromptSubmitContext): ClaudeCodeEvent;
|
|
126
|
+
/**
|
|
127
|
+
* Create event from PreCompact hook
|
|
128
|
+
*/
|
|
129
|
+
export declare function createPreCompactEvent(ctx: PreCompactContext): ClaudeCodeEvent;
|
|
130
|
+
/**
|
|
131
|
+
* Type guard for Claude Code events
|
|
132
|
+
*/
|
|
133
|
+
export declare function isClaudeCodeEvent(event: unknown): event is ClaudeCodeEvent;
|
|
134
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/claude-code/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,iCAAiC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gCAA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iB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,mBAAmB,GAAG,eAAe,CAOjF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,kBAAkB,GAAG,eAAe,CAW/E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,WAAW,GAAG,eAAe,CAQjE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,mBAAmB,GAAG,eAAe,CASjF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,uBAAuB,GAAG,eAAe,CAQnF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,iBAAiB,GAAG,eAAe,CAO7E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAY1E"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code hook event type definitions
|
|
3
|
+
*
|
|
4
|
+
* These represent events emitted by Claude Code hooks during sessions.
|
|
5
|
+
* Based on Claude Code hooks documentation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create event from SessionStart hook
|
|
9
|
+
*/
|
|
10
|
+
export function createSessionStartEvent(ctx) {
|
|
11
|
+
return {
|
|
12
|
+
type: 'session_start',
|
|
13
|
+
timestamp: Date.now(),
|
|
14
|
+
sessionId: ctx.sessionId,
|
|
15
|
+
cwd: ctx.cwd,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create event from PostToolUse hook
|
|
20
|
+
*/
|
|
21
|
+
export function createPostToolUseEvent(ctx) {
|
|
22
|
+
return {
|
|
23
|
+
type: 'post_tool_use',
|
|
24
|
+
timestamp: Date.now(),
|
|
25
|
+
sessionId: ctx.sessionId,
|
|
26
|
+
cwd: ctx.cwd,
|
|
27
|
+
toolName: ctx.toolName,
|
|
28
|
+
toolInput: ctx.toolInput,
|
|
29
|
+
toolResult: ctx.toolResult,
|
|
30
|
+
toolError: ctx.toolError,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create event from Stop hook
|
|
35
|
+
*/
|
|
36
|
+
export function createStopEvent(ctx) {
|
|
37
|
+
return {
|
|
38
|
+
type: 'stop',
|
|
39
|
+
timestamp: Date.now(),
|
|
40
|
+
sessionId: ctx.sessionId,
|
|
41
|
+
cwd: ctx.cwd,
|
|
42
|
+
stopReason: ctx.reason,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create event from SubagentStop hook
|
|
47
|
+
*/
|
|
48
|
+
export function createSubagentStopEvent(ctx) {
|
|
49
|
+
return {
|
|
50
|
+
type: 'subagent_stop',
|
|
51
|
+
timestamp: Date.now(),
|
|
52
|
+
sessionId: ctx.sessionId,
|
|
53
|
+
cwd: ctx.cwd,
|
|
54
|
+
agentType: ctx.agentType,
|
|
55
|
+
agentOutput: ctx.output,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create event from UserPromptSubmit hook
|
|
60
|
+
*/
|
|
61
|
+
export function createUserPromptEvent(ctx) {
|
|
62
|
+
return {
|
|
63
|
+
type: 'user_prompt',
|
|
64
|
+
timestamp: Date.now(),
|
|
65
|
+
sessionId: ctx.sessionId,
|
|
66
|
+
cwd: ctx.cwd,
|
|
67
|
+
userContent: ctx.content,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create event from PreCompact hook
|
|
72
|
+
*/
|
|
73
|
+
export function createPreCompactEvent(ctx) {
|
|
74
|
+
return {
|
|
75
|
+
type: 'pre_compact',
|
|
76
|
+
timestamp: Date.now(),
|
|
77
|
+
sessionId: ctx.sessionId,
|
|
78
|
+
cwd: ctx.cwd,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Type guard for Claude Code events
|
|
83
|
+
*/
|
|
84
|
+
export function isClaudeCodeEvent(event) {
|
|
85
|
+
if (typeof event !== 'object' || event === null) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const e = event;
|
|
89
|
+
return (typeof e.type === 'string' &&
|
|
90
|
+
typeof e.timestamp === 'number' &&
|
|
91
|
+
typeof e.sessionId === 'string' &&
|
|
92
|
+
typeof e.cwd === 'string');
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/claude-code/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqHH;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAwB;IAC9D,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,GAAG,EAAE,GAAG,CAAC,GAAG;KACb,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAuB;IAC5D,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,UAAU,EAAE,GAAG,CAAC,UAAU;QAC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,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,OAAO,CACL,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ;QAC1B,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ;QAC/B,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ;QAC/B,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ,CAC1B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content filtering and safety utilities for Claude Code adapter
|
|
3
|
+
*
|
|
4
|
+
* Provides filters to prevent accidental secret capture and reduce noise:
|
|
5
|
+
* - Content truncation for large outputs
|
|
6
|
+
* - Pattern-based secret detection
|
|
7
|
+
* - File path filtering
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Maximum content length before truncation (characters)
|
|
11
|
+
*/
|
|
12
|
+
export declare const MAX_CONTENT_LENGTH = 50000;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum result length for tool results
|
|
15
|
+
*/
|
|
16
|
+
export declare const MAX_RESULT_LENGTH = 10000;
|
|
17
|
+
/**
|
|
18
|
+
* Options for content filtering
|
|
19
|
+
*/
|
|
20
|
+
export interface FilterOptions {
|
|
21
|
+
/** Maximum content length before truncation */
|
|
22
|
+
maxLength?: number;
|
|
23
|
+
/** Whether to detect and mask secrets */
|
|
24
|
+
maskSecrets?: boolean;
|
|
25
|
+
/** Whether to append truncation notice */
|
|
26
|
+
showTruncationNotice?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Truncate content if it exceeds max length
|
|
30
|
+
*/
|
|
31
|
+
export declare function truncateContent(content: string, options?: FilterOptions): string;
|
|
32
|
+
/**
|
|
33
|
+
* Detect if content contains potential secrets
|
|
34
|
+
*/
|
|
35
|
+
export declare function containsSecrets(content: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Mask potential secrets in content
|
|
38
|
+
*/
|
|
39
|
+
export declare function maskSecrets(content: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Filter content with all safety rules
|
|
42
|
+
*/
|
|
43
|
+
export declare function filterContent(content: string, options?: FilterOptions): string;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a file path should be excluded from capture
|
|
46
|
+
*/
|
|
47
|
+
export declare function isExcludedPath(path: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a tool's result should be captured
|
|
50
|
+
*/
|
|
51
|
+
export declare function shouldCaptureToolResult(toolName: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Filter tool result for storage
|
|
54
|
+
*/
|
|
55
|
+
export declare function filterToolResult(toolName: string, result: unknown, maxLength?: number): string | null;
|
|
56
|
+
/**
|
|
57
|
+
* Create a redaction reason string
|
|
58
|
+
*/
|
|
59
|
+
export declare function createRedactionReason(reason: string): string;
|
|
60
|
+
//# sourceMappingURL=filter.d.ts.map
|