@omnitype-code/adapter-sdk 2.0.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.
Files changed (46) hide show
  1. package/README.md +163 -0
  2. package/dist/adapters/filesystem-only.d.ts +30 -0
  3. package/dist/adapters/filesystem-only.d.ts.map +1 -0
  4. package/dist/adapters/filesystem-only.js +115 -0
  5. package/dist/adapters/filesystem-only.js.map +1 -0
  6. package/dist/adapters/hook-poller.d.ts +40 -0
  7. package/dist/adapters/hook-poller.d.ts.map +1 -0
  8. package/dist/adapters/hook-poller.js +125 -0
  9. package/dist/adapters/hook-poller.js.map +1 -0
  10. package/dist/adapters/index.d.ts +34 -0
  11. package/dist/adapters/index.d.ts.map +1 -0
  12. package/dist/adapters/index.js +61 -0
  13. package/dist/adapters/index.js.map +1 -0
  14. package/dist/adapters/stdin-json-hook-tool.d.ts +87 -0
  15. package/dist/adapters/stdin-json-hook-tool.d.ts.map +1 -0
  16. package/dist/adapters/stdin-json-hook-tool.js +491 -0
  17. package/dist/adapters/stdin-json-hook-tool.js.map +1 -0
  18. package/dist/adapters/transcript-scavenger.d.ts +40 -0
  19. package/dist/adapters/transcript-scavenger.d.ts.map +1 -0
  20. package/dist/adapters/transcript-scavenger.js +569 -0
  21. package/dist/adapters/transcript-scavenger.js.map +1 -0
  22. package/dist/classifier.d.ts +132 -0
  23. package/dist/classifier.d.ts.map +1 -0
  24. package/dist/classifier.js +95 -0
  25. package/dist/classifier.js.map +1 -0
  26. package/dist/index.d.ts +8 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +8 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/loader.d.ts +51 -0
  31. package/dist/loader.d.ts.map +1 -0
  32. package/dist/loader.js +352 -0
  33. package/dist/loader.js.map +1 -0
  34. package/dist/manifest.d.ts +131 -0
  35. package/dist/manifest.d.ts.map +1 -0
  36. package/dist/manifest.js +12 -0
  37. package/dist/manifest.js.map +1 -0
  38. package/dist/normalize.d.ts +51 -0
  39. package/dist/normalize.d.ts.map +1 -0
  40. package/dist/normalize.js +122 -0
  41. package/dist/normalize.js.map +1 -0
  42. package/dist/tier.d.ts +12 -0
  43. package/dist/tier.d.ts.map +1 -0
  44. package/dist/tier.js +62 -0
  45. package/dist/tier.js.map +1 -0
  46. package/package.json +36 -0
@@ -0,0 +1,87 @@
1
+ /**
2
+ * stdin-json-hook-tool — co-process adapter template.
3
+ *
4
+ * This replaces ALL the hand-written hook installers in v1 (Claude Code,
5
+ * Cursor, Codex, Gemini, Windsurf, Droid, Firebender, Copilot, Cline).
6
+ * Each tool becomes a ~30-line JSON manifest + this shared runtime.
7
+ *
8
+ * The adapter:
9
+ * 1. Installs a preToolUse hook into the target tool's config.
10
+ * 2. The hook writes a JSON payload to a named pipe / UDS when a tool call fires.
11
+ * 3. This adapter reads that pipe and emits canonical events to the daemon.
12
+ *
13
+ * Hook payload (tool writes to pipe):
14
+ * { tool_name, tool_input: { path?, content?, ... }, session_id?, model?, ts }
15
+ *
16
+ * For tools that support preToolUse hooks natively (Claude Code, Cursor, etc.)
17
+ * the hook is a small node one-liner. Tools without hook APIs fall back to
18
+ * the transcript-scavenger-adapter.
19
+ */
20
+ import { type HookPayload } from '../normalize.js';
21
+ export declare const ADAPTER_VERSION = "omnitype-v2-hook-2";
22
+ export interface HookConfig {
23
+ tool: string;
24
+ pipeDir: string;
25
+ model?: string;
26
+ }
27
+ export declare function buildHookOneliner(cfg: HookConfig): string;
28
+ export type HookCapability = 'native-hook' | 'vscode-command' | 'transcript-only' | 'process-only';
29
+ /**
30
+ * installFormat controls how the hook entry is written into the config file.
31
+ *
32
+ * 'claude-code' — { matcher, hooks: [{ type, command }] } pushed into a hooks array
33
+ * 'cursor' — { command } pushed into afterFileEdit array
34
+ * 'antigravity' — named top-level key in hooks.json with PreToolUse event array
35
+ * (Antigravity / Gemini: `~/.gemini/config/hooks.json`; PreToolUse
36
+ * stdout must include `{ "decision": "allow" }` — see `buildHookOneliner`)
37
+ */
38
+ export type HookInstallFormat = 'claude-code' | 'cursor' | 'antigravity';
39
+ export interface ToolHookSpec {
40
+ toolId: string;
41
+ displayName: string;
42
+ capability: HookCapability;
43
+ /** Only set when capability === 'native-hook' */
44
+ configPath?: string | ((home: string) => string);
45
+ /**
46
+ * For claude-code/cursor: dot-path to the hooks array in the config JSON.
47
+ * For antigravity: the top-level named key in hooks.json (e.g. 'omnitype').
48
+ */
49
+ hookSection?: string;
50
+ /** Only set when capability === 'native-hook'. tool_name patterns that trigger writes. */
51
+ eventTypes?: string[];
52
+ /** Defaults to 'claude-code' if not set. */
53
+ installFormat?: HookInstallFormat;
54
+ modelField: string;
55
+ sessionField: string;
56
+ detect: () => boolean;
57
+ }
58
+ /**
59
+ * Hook integration matrix. Only entries with `capability: 'native-hook'` write
60
+ * into a tool's config file. Anything else is captured via:
61
+ * - the VSCode extension's discriminator (capability === 'vscode-command')
62
+ * - the transcript scavenger (capability === 'transcript-only')
63
+ * - the filesystem watcher + ToolDetector (capability === 'process-only')
64
+ *
65
+ * We **deliberately do not** install hooks into config keys that the target
66
+ * tool does not actually read. (Earlier versions wrote bogus keys into
67
+ * ~/.cursor/mcp.json, ~/.openai/codex/config.json, and .vscode/settings.json;
68
+ * those tools ignored the keys silently, producing a false green-checkmark in
69
+ * `omnitype status`. Those entries have been demoted to their real capability.)
70
+ */
71
+ export declare const TOOL_SPECS: ToolHookSpec[];
72
+ export declare function specByCapability(cap: HookCapability): ToolHookSpec[];
73
+ export interface InstallResult {
74
+ toolId: string;
75
+ installed: boolean;
76
+ alreadyCurrent: boolean;
77
+ skipped: boolean;
78
+ reason?: string;
79
+ }
80
+ export declare function installHooks(workspace: string): InstallResult[];
81
+ export interface HookEvent {
82
+ tool: string;
83
+ payload: HookPayload;
84
+ ts: number;
85
+ }
86
+ export declare function drainHookEvents(pipeDir: string): HookEvent[];
87
+ //# sourceMappingURL=stdin-json-hook-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3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IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CA8C/D;AA4ND,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,CAmB5D"}
@@ -0,0 +1,491 @@
1
+ /**
2
+ * stdin-json-hook-tool — co-process adapter template.
3
+ *
4
+ * This replaces ALL the hand-written hook installers in v1 (Claude Code,
5
+ * Cursor, Codex, Gemini, Windsurf, Droid, Firebender, Copilot, Cline).
6
+ * Each tool becomes a ~30-line JSON manifest + this shared runtime.
7
+ *
8
+ * The adapter:
9
+ * 1. Installs a preToolUse hook into the target tool's config.
10
+ * 2. The hook writes a JSON payload to a named pipe / UDS when a tool call fires.
11
+ * 3. This adapter reads that pipe and emits canonical events to the daemon.
12
+ *
13
+ * Hook payload (tool writes to pipe):
14
+ * { tool_name, tool_input: { path?, content?, ... }, session_id?, model?, ts }
15
+ *
16
+ * For tools that support preToolUse hooks natively (Claude Code, Cursor, etc.)
17
+ * the hook is a small node one-liner. Tools without hook APIs fall back to
18
+ * the transcript-scavenger-adapter.
19
+ */
20
+ import { mkdirSync, writeFileSync, readFileSync, existsSync, renameSync } from 'node:fs';
21
+ import { join, dirname } from 'node:path';
22
+ import { homedir } from 'node:os';
23
+ export const ADAPTER_VERSION = 'omnitype-v2-hook-2';
24
+ /** Cursor rejects legacy `userPromptSubmit` (invalid hook type). */
25
+ const CURSOR_DEPRECATED_PROMPT_KEY = 'userPromptSubmit';
26
+ /** Valid replacement per Cursor hooks schema. */
27
+ const CURSOR_PROMPT_HOOK_EVENT = 'beforeSubmitPrompt';
28
+ /**
29
+ * Mutates root `hooks.json` object in place. Returns true if the file should be rewritten.
30
+ */
31
+ function migrateCursorDeprecatedHookKeys(config) {
32
+ const hooksVal = config['hooks'];
33
+ if (!hooksVal || typeof hooksVal !== 'object' || Array.isArray(hooksVal))
34
+ return false;
35
+ const hooks = hooksVal;
36
+ if (!(CURSOR_DEPRECATED_PROMPT_KEY in hooks))
37
+ return false;
38
+ const legacy = hooks[CURSOR_DEPRECATED_PROMPT_KEY];
39
+ if (Array.isArray(legacy) && legacy.length > 0) {
40
+ if (!Array.isArray(hooks[CURSOR_PROMPT_HOOK_EVENT]))
41
+ hooks[CURSOR_PROMPT_HOOK_EVENT] = [];
42
+ hooks[CURSOR_PROMPT_HOOK_EVENT].push(...legacy);
43
+ }
44
+ delete hooks[CURSOR_DEPRECATED_PROMPT_KEY];
45
+ return true;
46
+ }
47
+ export function buildHookOneliner(cfg) {
48
+ // Antigravity provides workspacePaths in the hook stdin payload.
49
+ // Use it instead of the hardcoded install-time workspace so the hook works
50
+ // correctly across all workspaces from a single global ~/.gemini/config/hooks.json.
51
+ if (cfg.tool === 'antigravity' || cfg.tool === 'gemini') {
52
+ return (`node -e "/*${ADAPTER_VERSION}*/` +
53
+ `let b='';process.stdin.on('data',c=>b+=c);` +
54
+ `process.stdin.on('end',()=>{` +
55
+ `try{` +
56
+ `const j=JSON.parse(b);` +
57
+ `const _fs=require('fs'),_p=require('path');` +
58
+ `const _w=(j.workspacePaths&&j.workspacePaths[0])||process.cwd();` +
59
+ `const _d=_p.join(_w,'.omnitype','hooks');` +
60
+ `_fs.mkdirSync(_d,{recursive:true});` +
61
+ `const _f=_p.join(_d,'event-'+Date.now()+'-'+Math.random().toString(36).slice(2)+'.json');` +
62
+ `_fs.writeFileSync(_f,JSON.stringify({tool:'${cfg.tool}',payload:j,ts:Date.now()}));` +
63
+ `}catch(_){}` +
64
+ // Antigravity / Gemini hooks.json PreToolUse contract (Google docs): stdout MUST be JSON
65
+ // with `decision` — otherwise the agent may block or ignore the hook.
66
+ `finally{process.stdout.write(JSON.stringify({decision:'allow'}));}})"`);
67
+ }
68
+ // Other tools (Claude Code, Cursor): pipeDir is workspace-specific, set at install time.
69
+ return (`node -e "/*${ADAPTER_VERSION}*/` +
70
+ `let b='';process.stdin.on('data',c=>b+=c);` +
71
+ `process.stdin.on('end',()=>{` +
72
+ `try{` +
73
+ `const j=JSON.parse(b);` +
74
+ `const _fs=require('fs'),_p=require('path'),_os=require('os');` +
75
+ `const _d='${cfg.pipeDir.replace(/'/g, "\\'")}';` +
76
+ `_fs.mkdirSync(_d,{recursive:true});` +
77
+ `const _f=_p.join(_d,'event-'+Date.now()+'-'+Math.random().toString(36).slice(2)+'.json');` +
78
+ `_fs.writeFileSync(_f,JSON.stringify({tool:'${cfg.tool}',payload:j,ts:Date.now()}));` +
79
+ `}catch(_){}})"`);
80
+ }
81
+ /**
82
+ * Hook integration matrix. Only entries with `capability: 'native-hook'` write
83
+ * into a tool's config file. Anything else is captured via:
84
+ * - the VSCode extension's discriminator (capability === 'vscode-command')
85
+ * - the transcript scavenger (capability === 'transcript-only')
86
+ * - the filesystem watcher + ToolDetector (capability === 'process-only')
87
+ *
88
+ * We **deliberately do not** install hooks into config keys that the target
89
+ * tool does not actually read. (Earlier versions wrote bogus keys into
90
+ * ~/.cursor/mcp.json, ~/.openai/codex/config.json, and .vscode/settings.json;
91
+ * those tools ignored the keys silently, producing a false green-checkmark in
92
+ * `omnitype status`. Those entries have been demoted to their real capability.)
93
+ */
94
+ export const TOOL_SPECS = [
95
+ // ── Real native hooks ────────────────────────────────────────────────────
96
+ {
97
+ toolId: 'claude-code',
98
+ displayName: 'Claude Code',
99
+ capability: 'native-hook',
100
+ configPath: (h) => join(h, '.claude', 'settings.json'),
101
+ hookSection: 'hooks.PreToolUse',
102
+ // Bash and NotebookEdit added: Bash is how Claude writes via `sed`/heredocs,
103
+ // NotebookEdit covers ipynb edits. Both fire PreToolUse so we get session_id.
104
+ eventTypes: ['Write', 'Edit', 'MultiEdit', 'NotebookEdit', 'Bash'],
105
+ modelField: 'model',
106
+ sessionField: 'session_id',
107
+ detect: () => existsSync(join(homedir(), '.claude')),
108
+ },
109
+ {
110
+ toolId: 'cursor',
111
+ displayName: 'Cursor',
112
+ capability: 'native-hook',
113
+ // Real Cursor hooks file. As of Cursor 1.x this is ~/.cursor/hooks.json.
114
+ // MCP hooks (preMCPExecution etc.) live in ~/.cursor/mcp.json and do NOT
115
+ // fire for Cursor's internal agent edits — so we only register hooks the
116
+ // tool will actually invoke.
117
+ configPath: (h) => join(h, '.cursor', 'hooks.json'),
118
+ hookSection: 'hooks.afterFileEdit',
119
+ eventTypes: ['afterFileEdit'],
120
+ modelField: 'model',
121
+ sessionField: 'composerId',
122
+ detect: () => existsSync('/Applications/Cursor.app') ||
123
+ existsSync(join(homedir(), '.cursor')),
124
+ },
125
+ {
126
+ toolId: 'gemini',
127
+ displayName: 'Gemini CLI',
128
+ capability: 'native-hook',
129
+ // Confirmed path: hooks live in ~/.gemini/config/hooks.json, NOT settings.json
130
+ configPath: (h) => join(h, '.gemini', 'config', 'hooks.json'),
131
+ hookSection: 'omnitype',
132
+ installFormat: 'antigravity',
133
+ eventTypes: ['write_to_file', 'replace_file_content', 'multi_replace_file_content'],
134
+ modelField: 'model',
135
+ sessionField: 'conversationId',
136
+ detect: () => existsSync(join(homedir(), '.gemini')),
137
+ },
138
+ // ── Captured via VSCode-command interception (no native hook required) ───
139
+ {
140
+ toolId: 'copilot',
141
+ displayName: 'GitHub Copilot',
142
+ // Copilot has no hooks API. We intercept the inline-completion accept
143
+ // command (`editor.action.inlineSuggest.commit`, `github.copilot.accept`)
144
+ // from the VSCode extension to mark AI-origin edits.
145
+ capability: 'vscode-command',
146
+ modelField: 'model',
147
+ sessionField: 'session_id',
148
+ detect: () => existsSync(join(homedir(), '.vscode')) ||
149
+ existsSync(join(homedir(), 'Library', 'Application Support', 'Code')),
150
+ },
151
+ // ── Captured via transcript scavenger ────────────────────────────────────
152
+ {
153
+ toolId: 'codex',
154
+ displayName: 'OpenAI Codex CLI',
155
+ // Codex CLI config is ~/.codex/config.toml (TOML, not JSON) and has no
156
+ // hooks API. Attribution comes from the session JSONL under ~/.codex/sessions/
157
+ // which contains apply_patch tool_calls with exact diffs.
158
+ capability: 'transcript-only',
159
+ modelField: 'model',
160
+ sessionField: 'session_id',
161
+ detect: () => existsSync(join(homedir(), '.codex')),
162
+ },
163
+ {
164
+ toolId: 'windsurf',
165
+ displayName: 'Windsurf',
166
+ // Windsurf's mcp_config.json hooks fire for MCP tools, not for Cascade
167
+ // agent edits. Captured via transcript + VSCode discriminator.
168
+ capability: 'transcript-only',
169
+ modelField: 'model',
170
+ sessionField: 'session_id',
171
+ detect: () => existsSync('/Applications/Windsurf.app') ||
172
+ existsSync(join(homedir(), '.codeium', 'windsurf')),
173
+ },
174
+ {
175
+ toolId: 'cline',
176
+ displayName: 'Cline',
177
+ capability: 'transcript-only',
178
+ modelField: 'model',
179
+ sessionField: 'session_id',
180
+ detect: () => existsSync(join(homedir(), '.cline')),
181
+ },
182
+ {
183
+ toolId: 'aider',
184
+ displayName: 'Aider',
185
+ capability: 'transcript-only',
186
+ modelField: 'model',
187
+ sessionField: 'session_id',
188
+ detect: () => {
189
+ try {
190
+ const cp = require('child_process');
191
+ cp.execFileSync('which', ['aider'], { stdio: 'pipe' });
192
+ return true;
193
+ }
194
+ catch {
195
+ return existsSync(join(homedir(), '.aider.conf.yml'));
196
+ }
197
+ },
198
+ },
199
+ // ── Antigravity 2.0 — IDE / CLI / SDK / Chat Agent ───────────────────────
200
+ // Surfaces read `~/.gemini/config/hooks.json` (Antigravity docs). If the open
201
+ // workspace already has `.agents/hooks.json`, `installHooks` merges the same
202
+ // `omnitype` block there too (avoid defining both if you do not want double PreToolUse).
203
+ // Hook stdin: toolCall + conversationId + transcriptPath (see Google Antigravity hooks docs).
204
+ // Model is often absent on PreToolUse — extension still uses state.vscdb + transcript scavenger.
205
+ {
206
+ toolId: 'antigravity',
207
+ displayName: 'Antigravity (IDE / CLI / SDK / Agent)',
208
+ capability: 'native-hook',
209
+ configPath: (h) => join(h, '.gemini', 'config', 'hooks.json'),
210
+ hookSection: 'omnitype',
211
+ installFormat: 'antigravity',
212
+ eventTypes: ['write_to_file', 'replace_file_content', 'multi_replace_file_content'],
213
+ modelField: 'model',
214
+ sessionField: 'conversationId',
215
+ detect: () => existsSync('/Applications/Antigravity.app') ||
216
+ existsSync('/Applications/Google Antigravity.app') ||
217
+ existsSync('/Applications/Antigravity IDE.app') ||
218
+ existsSync('/Applications/Google Antigravity IDE.app') ||
219
+ existsSync(join(homedir(), '.antigravity-ide')) ||
220
+ existsSync(join(homedir(), '.antigravity')),
221
+ },
222
+ ];
223
+ export function specByCapability(cap) {
224
+ return TOOL_SPECS.filter((s) => s.capability === cap);
225
+ }
226
+ export function installHooks(workspace) {
227
+ const pipeDir = join(workspace, '.omnitype', 'hooks');
228
+ mkdirSync(pipeDir, { recursive: true });
229
+ const results = [];
230
+ for (const spec of TOOL_SPECS) {
231
+ if (!spec.detect()) {
232
+ results.push({
233
+ toolId: spec.toolId,
234
+ installed: false,
235
+ alreadyCurrent: false,
236
+ skipped: true,
237
+ reason: 'not installed',
238
+ });
239
+ continue;
240
+ }
241
+ // Non-native-hook tools are captured by the VSCode extension, transcript
242
+ // scavenger, or filesystem watcher. There's nothing to write into a config
243
+ // file — report honestly so `omnitype status` doesn't claim a false hook.
244
+ if (spec.capability !== 'native-hook') {
245
+ results.push({
246
+ toolId: spec.toolId,
247
+ installed: false,
248
+ alreadyCurrent: false,
249
+ skipped: true,
250
+ reason: `captured via ${spec.capability} (no hook config needed)`,
251
+ });
252
+ continue;
253
+ }
254
+ try {
255
+ const result = installToolHook(spec, pipeDir, workspace);
256
+ results.push(result);
257
+ }
258
+ catch (err) {
259
+ results.push({
260
+ toolId: spec.toolId,
261
+ installed: false,
262
+ alreadyCurrent: false,
263
+ skipped: false,
264
+ reason: String(err),
265
+ });
266
+ }
267
+ }
268
+ return results;
269
+ }
270
+ /**
271
+ * Installs into `~/.gemini/config/hooks.json` per **Antigravity / Gemini hooks.json** (named
272
+ * blocks with `PreToolUse` / `PostToolUse` / `PreInvocation` / …). PreToolUse must print JSON
273
+ * with `"decision":"allow"` to stdout — see `buildHookOneliner` (`finally` block).
274
+ *
275
+ * { "omnitype": { "PreToolUse": [{ "matcher": "...", "hooks": [{ "type": "command", "command": "..." }] }] } }
276
+ *
277
+ * spec.hookSection is the top-level named key (e.g. "omnitype"). Merges preserve user hooks.
278
+ * Idempotent: current OmniType row detected by ADAPTER_VERSION in the command string.
279
+ *
280
+ * When `<workspace>/.agents/` exists, the same `omnitype` merge is written to
281
+ * `<workspace>/.agents/hooks.json` (created if missing) in addition to `~/.gemini/config/hooks.json`.
282
+ * If both define the same PreToolUse handlers, the hook may run twice — use one location when possible.
283
+ */
284
+ function isOmnitypeAntigravityPreHandler(handler) {
285
+ if (!handler || typeof handler !== 'object')
286
+ return false;
287
+ const hooks = handler['hooks'];
288
+ if (!Array.isArray(hooks))
289
+ return false;
290
+ return hooks.some((h) => {
291
+ const cmd = h['command'];
292
+ return typeof cmd === 'string' && (cmd.includes(ADAPTER_VERSION) || cmd.includes('omnitype-v2-hook'));
293
+ });
294
+ }
295
+ function mergeAntigravityOmnitypeBlock(configPath, spec, pipeDir) {
296
+ const namedKey = spec.hookSection;
297
+ const matcher = (spec.eventTypes ?? []).join('|') || '*';
298
+ const hookCmd = buildHookOneliner({ tool: spec.toolId, pipeDir });
299
+ let config = {};
300
+ if (existsSync(configPath)) {
301
+ try {
302
+ config = JSON.parse(readFileSync(configPath, 'utf-8'));
303
+ }
304
+ catch { /* start fresh */ }
305
+ }
306
+ const existing = config[namedKey];
307
+ const newPreEntry = { matcher, hooks: [{ type: 'command', command: hookCmd }] };
308
+ const MERGE_KEYS = ['PostToolUse', 'PreInvocation', 'PostInvocation', 'Stop'];
309
+ const nextBlock = {};
310
+ if (existing && typeof existing === 'object' && !Array.isArray(existing)) {
311
+ const ex = existing;
312
+ for (const k of MERGE_KEYS) {
313
+ if (ex[k] !== undefined)
314
+ nextBlock[k] = ex[k];
315
+ }
316
+ const pre = Array.isArray(ex.PreToolUse) ? [...ex.PreToolUse] : [];
317
+ nextBlock.PreToolUse = [...pre.filter((h) => !isOmnitypeAntigravityPreHandler(h)), newPreEntry];
318
+ }
319
+ else {
320
+ nextBlock.PreToolUse = [newPreEntry];
321
+ }
322
+ const nextConfig = { ...config, [namedKey]: nextBlock };
323
+ const out = `${JSON.stringify(nextConfig, null, 2)}\n`;
324
+ let prev = '';
325
+ if (existsSync(configPath)) {
326
+ try {
327
+ prev = readFileSync(configPath, 'utf-8');
328
+ }
329
+ catch {
330
+ prev = '';
331
+ }
332
+ }
333
+ const changed = prev !== out;
334
+ if (changed) {
335
+ mkdirSync(dirname(configPath), { recursive: true });
336
+ writeFileSync(configPath + '.tmp', out, 'utf-8');
337
+ renameSync(configPath + '.tmp', configPath);
338
+ }
339
+ return { changed };
340
+ }
341
+ function installAntigravityHook(spec, pipeDir, workspace) {
342
+ const configPath = typeof spec.configPath === 'function'
343
+ ? spec.configPath(homedir())
344
+ : spec.configPath;
345
+ const primary = mergeAntigravityOmnitypeBlock(configPath, spec, pipeDir);
346
+ const agentsDir = join(workspace, '.agents');
347
+ const agentsPath = join(agentsDir, 'hooks.json');
348
+ let anyChanged = primary.changed;
349
+ if (existsSync(agentsDir)) {
350
+ try {
351
+ const w = mergeAntigravityOmnitypeBlock(agentsPath, spec, pipeDir);
352
+ anyChanged ||= w.changed;
353
+ }
354
+ catch {
355
+ /* optional workspace-local hooks — best-effort */
356
+ }
357
+ }
358
+ return {
359
+ toolId: spec.toolId,
360
+ installed: true,
361
+ alreadyCurrent: !anyChanged,
362
+ skipped: false,
363
+ };
364
+ }
365
+ function installToolHook(spec, pipeDir, workspace) {
366
+ if (!spec.configPath || !spec.hookSection) {
367
+ return {
368
+ toolId: spec.toolId,
369
+ installed: false,
370
+ alreadyCurrent: false,
371
+ skipped: true,
372
+ reason: 'no configPath / hookSection for this capability',
373
+ };
374
+ }
375
+ if (spec.installFormat === 'antigravity') {
376
+ return installAntigravityHook(spec, pipeDir, workspace);
377
+ }
378
+ const configPath = typeof spec.configPath === 'function'
379
+ ? spec.configPath(homedir())
380
+ : spec.configPath;
381
+ let config = {};
382
+ if (existsSync(configPath)) {
383
+ try {
384
+ config = JSON.parse(readFileSync(configPath, 'utf-8'));
385
+ }
386
+ catch { /* start fresh */ }
387
+ }
388
+ const cursorLegacyMigrated = spec.toolId === 'cursor' && migrateCursorDeprecatedHookKeys(config);
389
+ const hookCmd = buildHookOneliner({ tool: spec.toolId, pipeDir });
390
+ // Navigate to the hook section
391
+ const sectionPath = spec.hookSection.split('.');
392
+ let cur = config;
393
+ for (let i = 0; i < sectionPath.length - 1; i++) {
394
+ const key = sectionPath[i];
395
+ if (!cur[key] || typeof cur[key] !== 'object')
396
+ cur[key] = {};
397
+ cur = cur[key];
398
+ }
399
+ const hookKey = sectionPath[sectionPath.length - 1];
400
+ // Check for existing hook
401
+ const existing = cur[hookKey];
402
+ const existingArr = Array.isArray(existing) ? existing : [];
403
+ const isOurs = (entry) => {
404
+ const cmd = extractCmd(entry);
405
+ return cmd?.includes('.omnitype') ?? false;
406
+ };
407
+ const isCurrent = (entry) => {
408
+ const cmd = extractCmd(entry);
409
+ return cmd?.includes(ADAPTER_VERSION) ?? false;
410
+ };
411
+ if (existingArr.some(isCurrent)) {
412
+ if (cursorLegacyMigrated) {
413
+ mkdirSync(dirname(configPath), { recursive: true });
414
+ writeFileSync(configPath + '.tmp', JSON.stringify(config, null, 2), 'utf-8');
415
+ renameSync(configPath + '.tmp', configPath);
416
+ return { toolId: spec.toolId, installed: true, alreadyCurrent: false, skipped: false };
417
+ }
418
+ return { toolId: spec.toolId, installed: true, alreadyCurrent: true, skipped: false };
419
+ }
420
+ // Remove stale omnitype hooks, keep others
421
+ const cleaned = existingArr.filter((e) => !isOurs(e));
422
+ // Add new hook entry
423
+ const hookEntry = buildHookEntry(spec, hookCmd, spec.eventTypes ?? []);
424
+ cleaned.push(hookEntry);
425
+ cur[hookKey] = cleaned;
426
+ mkdirSync(dirname(configPath), { recursive: true });
427
+ writeFileSync(configPath + '.tmp', JSON.stringify(config, null, 2), 'utf-8');
428
+ renameSync(configPath + '.tmp', configPath);
429
+ return {
430
+ toolId: spec.toolId,
431
+ installed: true,
432
+ alreadyCurrent: false,
433
+ skipped: false,
434
+ };
435
+ }
436
+ function buildHookEntry(spec, cmd, eventTypes) {
437
+ // Claude Code format: { matcher, hooks: [{ type, command }] }
438
+ if (spec.toolId === 'claude-code') {
439
+ return {
440
+ matcher: eventTypes.join('|'),
441
+ hooks: [{ type: 'command', command: cmd }],
442
+ };
443
+ }
444
+ // Cursor afterFileEdit format: { command }
445
+ if (spec.toolId === 'cursor') {
446
+ return { command: cmd };
447
+ }
448
+ // Generic format
449
+ return { command: cmd, events: eventTypes };
450
+ }
451
+ function extractCmd(entry) {
452
+ if (typeof entry !== 'object' || entry === null)
453
+ return undefined;
454
+ const e = entry;
455
+ if (typeof e['command'] === 'string')
456
+ return e['command'];
457
+ // Claude Code nested format
458
+ const hooks = e['hooks'];
459
+ if (Array.isArray(hooks) && hooks.length > 0) {
460
+ const h = hooks[0];
461
+ return typeof h['command'] === 'string' ? h['command'] : undefined;
462
+ }
463
+ return undefined;
464
+ }
465
+ // ─── Hook event reader ────────────────────────────────────────────────────────
466
+ // Polls the pipeDir for JSON files written by hooks and consumes them.
467
+ import { readdirSync, unlinkSync } from 'node:fs';
468
+ export function drainHookEvents(pipeDir) {
469
+ if (!existsSync(pipeDir))
470
+ return [];
471
+ const events = [];
472
+ let files;
473
+ try {
474
+ files = readdirSync(pipeDir).filter((f) => f.endsWith('.json'));
475
+ }
476
+ catch {
477
+ return [];
478
+ }
479
+ files.sort(); // process in order
480
+ for (const file of files) {
481
+ const p = join(pipeDir, file);
482
+ try {
483
+ const raw = JSON.parse(readFileSync(p, 'utf-8'));
484
+ events.push(raw);
485
+ unlinkSync(p);
486
+ }
487
+ catch { /* skip corrupt files */ }
488
+ }
489
+ return events;
490
+ }
491
+ //# sourceMappingURL=stdin-json-hook-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdin-json-hook-tool.js","sourceRoot":"","sources":["../../src/adapters/stdin-json-hook-tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAYlC,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAEpD,oEAAoE;AACpE,MAAM,4BAA4B,GAAG,kBAAkB,CAAC;AACxD,iDAAiD;AACjD,MAAM,wBAAwB,GAAG,oBAAoB,CAAC;AAEtD;;GAEG;AACH,SAAS,+BAA+B,CAAC,MAA+B;IACtE,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IACvF,MAAM,KAAK,GAAG,QAAmC,CAAC;IAClD,IAAI,CAAC,CAAC,4BAA4B,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3D,MAAM,MAAM,GAAG,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACnD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;YAAE,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AAM,CAAC,CAAC,wBAAwB,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * transcript-scavenger-adapter
3
+ *
4
+ * Tails on-disk transcripts from AI tools to recover SessionStarted,
5
+ * ModelClaim, and PromptCapture events for tools that:
6
+ * - don't support preToolUse hooks, or
7
+ * - had hooks fire but lost events due to timing/TTL issues.
8
+ *
9
+ * Events from this adapter are tagged `retrospective: true` and always T2
10
+ * (we can identify the session and model but not the exact splice).
11
+ *
12
+ * Supported transcript formats:
13
+ * - Claude Code: ~/.claude/projects/<slug>/<session>.jsonl
14
+ * - Cline: ~/.cline/tasks/TASK_ID/api_conversation_history.json
15
+ * + VSCode ext: ~/.vscode/extensions/saoudrizwan.claude-dev-X/tasks/X/api_conversation_history.json
16
+ * - Aider: .aider.chat.history.md (workspace-relative conversation history)
17
+ * - Windsurf: ~/.windsurf/memories/conversations/*.jsonl
18
+ * + workspace: .windsurf/history/*.json
19
+ * - OpenCode: ~/.opencode/sessions/*.jsonl
20
+ */
21
+ import type { EmitFn } from '../loader.js';
22
+ export declare const ADAPTER_ID = "org.omnitype.adapters.transcript-scavenger";
23
+ export declare const TRANSCRIPT_TIER: "T2";
24
+ export declare class TranscriptScavengerAdapter {
25
+ private emit;
26
+ private workspace;
27
+ private user;
28
+ private host;
29
+ private seenSessions;
30
+ private seenPromptHashes;
31
+ private filePositions;
32
+ private watchers;
33
+ constructor(emit: EmitFn, workspace: string, user: string, host: string);
34
+ start(): void;
35
+ private scanAll;
36
+ private parseTranscript;
37
+ private processTranscript;
38
+ stop(): void;
39
+ }
40
+ //# sourceMappingURL=transcript-scavenger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript-scavenger.d.ts","sourceRoot":"","sources":["../../src/adapters/transcript-scavenger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAYH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,eAAO,MAAM,UAAU,+CAA+C,CAAC;AACvE,eAAO,MAAM,eAAe,EAAG,IAAa,CAAC;AAqd7C,qBAAa,0BAA0B;IACrC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,QAAQ,CAAkC;gBAEtC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAOvE,KAAK,IAAI,IAAI;IA0Bb,OAAO,CAAC,OAAO;IAgBf,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,iBAAiB;IA6EzB,IAAI,IAAI,IAAI;CAIb"}