@omnitype-code/cli 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/dist/core/ApiClient.js +15 -0
- package/dist/core/ModelDetector.js +116 -111
- package/dist/core/ToolDetector.js +249 -0
- package/dist/core/ToolHookInstallers.js +703 -0
- package/dist/core/TranscriptScanner.js +380 -0
- package/dist/daemon.js +17 -0
- package/dist/index.js +124 -27
- package/package.json +3 -2
- package/scripts/postinstall.js +94 -0
- package/src/core/ApiClient.ts +15 -0
- package/src/core/ModelDetector.ts +118 -126
- package/src/core/ToolDetector.ts +227 -0
- package/src/core/ToolHookInstallers.ts +580 -0
- package/src/core/TranscriptScanner.ts +320 -0
- package/src/daemon.ts +16 -1
- package/src/index.ts +134 -31
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transcript-based model detection — TypeScript port of git-ai's model_extraction.rs.
|
|
3
|
+
*
|
|
4
|
+
* Strategy: for each AI tool, find the most recently modified session file,
|
|
5
|
+
* read its tail (50 KB), scan lines in reverse for a model field, fall back
|
|
6
|
+
* to the head for tools that emit model_change events at session start.
|
|
7
|
+
*
|
|
8
|
+
* Results are cached for 60 s so directory scanning doesn't run on every edit.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as os from 'os';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
|
|
15
|
+
export interface TranscriptResult {
|
|
16
|
+
model: string;
|
|
17
|
+
tool: string;
|
|
18
|
+
/** mtime of the session file — callers can use this to judge freshness. */
|
|
19
|
+
mtime: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const TAIL_BYTES = 51_200; // 50 KB — mirrors git-ai
|
|
23
|
+
const HEAD_LINES = 20;
|
|
24
|
+
const CACHE_TTL = 60_000; // re-scan directories at most once per minute
|
|
25
|
+
const HOME = os.homedir();
|
|
26
|
+
|
|
27
|
+
// ── Model extraction from a single JSONL line ─────────────────────────────────
|
|
28
|
+
|
|
29
|
+
function modelFromLine(line: string): string | undefined {
|
|
30
|
+
const t = line.trim();
|
|
31
|
+
if (!t) return undefined;
|
|
32
|
+
let j: any;
|
|
33
|
+
try { j = JSON.parse(t); } catch { return undefined; }
|
|
34
|
+
|
|
35
|
+
// Copilot CLI / Windsurf: session.model_change event
|
|
36
|
+
if (j?.type === 'session.model_change') {
|
|
37
|
+
const m = j?.data?.newModel;
|
|
38
|
+
if (typeof m === 'string' && m) return m;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Standard JSONL: message.model, top-level model, or modelID
|
|
42
|
+
const candidate = j?.message?.model ?? j?.model ?? j?.modelID ?? j?.data?.model;
|
|
43
|
+
if (typeof candidate === 'string' && candidate && candidate !== '<synthetic>')
|
|
44
|
+
return candidate;
|
|
45
|
+
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ── JSONL extraction: tail scan + head fallback ───────────────────────────────
|
|
50
|
+
|
|
51
|
+
function extractJsonl(filePath: string): string | undefined {
|
|
52
|
+
let fd: number | undefined;
|
|
53
|
+
try {
|
|
54
|
+
fd = fs.openSync(filePath, 'r');
|
|
55
|
+
const size = fs.fstatSync(fd).size;
|
|
56
|
+
if (!size) { fs.closeSync(fd); return undefined; }
|
|
57
|
+
|
|
58
|
+
const readSize = Math.min(TAIL_BYTES, size);
|
|
59
|
+
const seekPos = size - readSize;
|
|
60
|
+
const buf = Buffer.alloc(readSize);
|
|
61
|
+
fs.readSync(fd, buf, 0, readSize, seekPos);
|
|
62
|
+
fs.closeSync(fd);
|
|
63
|
+
fd = undefined;
|
|
64
|
+
|
|
65
|
+
// Reverse-scan the tail
|
|
66
|
+
const lines = buf.toString('utf8').split('\n');
|
|
67
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
68
|
+
const m = modelFromLine(lines[i]);
|
|
69
|
+
if (m) return m;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Head fallback: model_change events are emitted at session start
|
|
73
|
+
if (seekPos > 0) {
|
|
74
|
+
const head = fs.readFileSync(filePath, 'utf8').split('\n');
|
|
75
|
+
for (let i = 0; i < Math.min(HEAD_LINES, head.length); i++) {
|
|
76
|
+
const m = modelFromLine(head[i]);
|
|
77
|
+
if (m) return m;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch { /* unreadable */ }
|
|
81
|
+
finally { if (fd !== undefined) try { fs.closeSync(fd); } catch {} }
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ── Amp: thread JSON — model lives in messages[].usage.model ─────────────────
|
|
86
|
+
|
|
87
|
+
function extractAmp(filePath: string): string | undefined {
|
|
88
|
+
try {
|
|
89
|
+
const messages: any[] = JSON.parse(fs.readFileSync(filePath, 'utf8'))?.messages ?? [];
|
|
90
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
91
|
+
const m = messages[i]?.usage?.model;
|
|
92
|
+
if (typeof m === 'string' && m) return m;
|
|
93
|
+
}
|
|
94
|
+
} catch {}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ── Tool specs: where each tool stores transcripts ────────────────────────────
|
|
99
|
+
|
|
100
|
+
interface ToolSpec {
|
|
101
|
+
tool: string;
|
|
102
|
+
dirs: (cwd?: string) => string[];
|
|
103
|
+
ext: string;
|
|
104
|
+
extract: (p: string) => string | undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Claude Code encodes a project path as the absolute path with '/' replaced by '-'.
|
|
109
|
+
* e.g. /Users/foo/myproject → -Users-foo-myproject
|
|
110
|
+
*/
|
|
111
|
+
function claudeProjectDir(cwd: string, base: string): string {
|
|
112
|
+
return path.join(base, 'projects', cwd.replace(/\//g, '-'));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Returns the VS Code workspaceStorage root, then filters subdirs to those
|
|
117
|
+
* whose workspace.json `folder` URI matches the given cwd.
|
|
118
|
+
* Falls back to returning all copilot transcript dirs if cwd is unknown.
|
|
119
|
+
*/
|
|
120
|
+
function copilotDirs(cwd?: string): string[] {
|
|
121
|
+
const roots: string[] = [];
|
|
122
|
+
switch (process.platform) {
|
|
123
|
+
case 'darwin': roots.push(path.join(HOME, 'Library', 'Application Support', 'Code', 'User', 'workspaceStorage')); break;
|
|
124
|
+
case 'win32': if (process.env.APPDATA) roots.push(path.join(process.env.APPDATA, 'Code', 'User', 'workspaceStorage')); break;
|
|
125
|
+
default: roots.push(path.join(HOME, '.config', 'Code', 'User', 'workspaceStorage')); break;
|
|
126
|
+
}
|
|
127
|
+
// Also check Insiders
|
|
128
|
+
if (process.platform === 'darwin')
|
|
129
|
+
roots.push(path.join(HOME, 'Library', 'Application Support', 'Code - Insiders', 'User', 'workspaceStorage'));
|
|
130
|
+
|
|
131
|
+
const result: string[] = [];
|
|
132
|
+
for (const root of roots) {
|
|
133
|
+
if (!fs.existsSync(root)) continue;
|
|
134
|
+
let entries: fs.Dirent[];
|
|
135
|
+
try { entries = fs.readdirSync(root, { withFileTypes: true }); } catch { continue; }
|
|
136
|
+
for (const e of entries) {
|
|
137
|
+
if (!e.isDirectory()) continue;
|
|
138
|
+
const transcriptsDir = path.join(root, e.name, 'GitHub.copilot-chat', 'transcripts');
|
|
139
|
+
if (!fs.existsSync(transcriptsDir)) continue;
|
|
140
|
+
if (cwd) {
|
|
141
|
+
// Read workspace.json to check if this workspace matches the cwd
|
|
142
|
+
try {
|
|
143
|
+
const wj = JSON.parse(fs.readFileSync(path.join(root, e.name, 'workspace.json'), 'utf8'));
|
|
144
|
+
const folder = (wj?.folder ?? '').replace(/^file:\/\//, '').replace(/%20/g, ' ');
|
|
145
|
+
if (folder !== cwd && !folder.startsWith(cwd + '/')) continue;
|
|
146
|
+
} catch { continue; }
|
|
147
|
+
}
|
|
148
|
+
result.push(transcriptsDir);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Extract model from a Copilot JSONL event stream line. */
|
|
155
|
+
function extractCopilotJsonl(filePath: string): string | undefined {
|
|
156
|
+
let fd: number | undefined;
|
|
157
|
+
try {
|
|
158
|
+
fd = fs.openSync(filePath, 'r');
|
|
159
|
+
const size = fs.fstatSync(fd).size;
|
|
160
|
+
if (!size) { fs.closeSync(fd); return undefined; }
|
|
161
|
+
const readSize = Math.min(TAIL_BYTES, size);
|
|
162
|
+
const buf = Buffer.alloc(readSize);
|
|
163
|
+
fs.readSync(fd, buf, 0, readSize, size - readSize);
|
|
164
|
+
fs.closeSync(fd); fd = undefined;
|
|
165
|
+
const lines = buf.toString('utf8').split('\n');
|
|
166
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
167
|
+
const t = lines[i].trim();
|
|
168
|
+
if (!t) continue;
|
|
169
|
+
try {
|
|
170
|
+
const j = JSON.parse(t);
|
|
171
|
+
// assistant.message carries modelId in data
|
|
172
|
+
const m = j?.data?.modelId ?? j?.data?.model ?? j?.model ?? j?.message?.model;
|
|
173
|
+
if (typeof m === 'string' && m) return m;
|
|
174
|
+
} catch {}
|
|
175
|
+
}
|
|
176
|
+
} catch {}
|
|
177
|
+
finally { if (fd !== undefined) try { fs.closeSync(fd); } catch {} }
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const SPECS: ToolSpec[] = [
|
|
182
|
+
{
|
|
183
|
+
tool: 'claude-code',
|
|
184
|
+
dirs: (cwd?: string) => {
|
|
185
|
+
const base = process.env.CLAUDE_CONFIG_DIR ?? path.join(HOME, '.claude');
|
|
186
|
+
const alt = path.join(HOME, '.config', 'claude');
|
|
187
|
+
if (cwd) {
|
|
188
|
+
// Scope to the current workspace so other projects don't bleed in.
|
|
189
|
+
return [claudeProjectDir(cwd, base), claudeProjectDir(cwd, alt)];
|
|
190
|
+
}
|
|
191
|
+
return [path.join(base, 'projects'), path.join(alt, 'projects')];
|
|
192
|
+
},
|
|
193
|
+
ext: '.jsonl',
|
|
194
|
+
extract: extractJsonl,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
tool: 'codex',
|
|
198
|
+
dirs: () => [path.join(HOME, '.codex')],
|
|
199
|
+
ext: '.jsonl',
|
|
200
|
+
extract: extractJsonl,
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
tool: 'gemini-cli',
|
|
204
|
+
dirs: () => [path.join(HOME, '.gemini', 'tmp')],
|
|
205
|
+
ext: '.jsonl',
|
|
206
|
+
extract: extractJsonl,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
tool: 'amp',
|
|
210
|
+
dirs: () => {
|
|
211
|
+
const xdg = process.env.XDG_DATA_HOME;
|
|
212
|
+
const local = process.env.LOCALAPPDATA;
|
|
213
|
+
if (process.platform === 'win32') return local ? [path.join(local, 'amp', 'threads')] : [];
|
|
214
|
+
return [path.join(xdg ?? path.join(HOME, '.local', 'share'), 'amp', 'threads')];
|
|
215
|
+
},
|
|
216
|
+
ext: '.json',
|
|
217
|
+
extract: extractAmp,
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
tool: 'copilot',
|
|
221
|
+
dirs: (cwd?: string) => copilotDirs(cwd),
|
|
222
|
+
ext: '.jsonl',
|
|
223
|
+
extract: extractCopilotJsonl,
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
tool: 'windsurf',
|
|
227
|
+
dirs: () => [path.join(HOME, '.codeium', 'windsurf', 'conversations')],
|
|
228
|
+
ext: '.jsonl',
|
|
229
|
+
extract: extractJsonl,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
tool: 'continue',
|
|
233
|
+
dirs: () => [path.join(HOME, '.continue', 'sessions')],
|
|
234
|
+
ext: '.json',
|
|
235
|
+
extract: (filePath: string) => {
|
|
236
|
+
try {
|
|
237
|
+
const msgs: any[] = JSON.parse(fs.readFileSync(filePath, 'utf8'))?.history ?? [];
|
|
238
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
239
|
+
const m = msgs[i]?.message?.model ?? msgs[i]?.model;
|
|
240
|
+
if (typeof m === 'string' && m) return m;
|
|
241
|
+
}
|
|
242
|
+
} catch {}
|
|
243
|
+
return undefined;
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
// Copilot CLI: ~/.copilot/session-state/*/events.jsonl
|
|
248
|
+
tool: 'copilot-cli',
|
|
249
|
+
dirs: () => [path.join(HOME, '.copilot', 'session-state')],
|
|
250
|
+
ext: '.jsonl',
|
|
251
|
+
extract: extractJsonl,
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
tool: 'droid',
|
|
255
|
+
dirs: () => [path.join(HOME, '.factory', 'sessions')],
|
|
256
|
+
ext: '.jsonl',
|
|
257
|
+
extract: extractJsonl,
|
|
258
|
+
},
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
// ── Directory scanner: finds the newest file with the given extension ─────────
|
|
262
|
+
|
|
263
|
+
function newestFile(dirs: string[], ext: string): { path: string; mtime: number } | undefined {
|
|
264
|
+
let best: { path: string; mtime: number } | undefined;
|
|
265
|
+
|
|
266
|
+
function scan(dir: string, depth = 0): void {
|
|
267
|
+
if (depth > 6) return;
|
|
268
|
+
let entries: fs.Dirent[];
|
|
269
|
+
try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
|
270
|
+
for (const e of entries) {
|
|
271
|
+
const full = path.join(dir, e.name);
|
|
272
|
+
if (e.isDirectory()) scan(full, depth + 1);
|
|
273
|
+
else if (e.isFile() && e.name.endsWith(ext)) {
|
|
274
|
+
try {
|
|
275
|
+
const mtime = fs.statSync(full).mtimeMs;
|
|
276
|
+
if (!best || mtime > best.mtime) best = { path: full, mtime };
|
|
277
|
+
} catch {}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
for (const dir of dirs) scan(dir);
|
|
283
|
+
return best;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ── Public API ────────────────────────────────────────────────────────────────
|
|
287
|
+
|
|
288
|
+
let _cache: TranscriptResult | undefined;
|
|
289
|
+
let _cacheAt = 0;
|
|
290
|
+
let _cacheCwd: string | undefined;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Returns the model from the most recently modified AI session transcript.
|
|
294
|
+
* When `cwd` is provided, claude-code scanning is scoped to that workspace
|
|
295
|
+
* so activity from other projects doesn't bleed into the result.
|
|
296
|
+
* Result is cached for 60 s (cache is busted when cwd changes).
|
|
297
|
+
*/
|
|
298
|
+
export function scanTranscripts(cwd?: string): TranscriptResult | undefined {
|
|
299
|
+
if (_cache && _cacheCwd === cwd && Date.now() - _cacheAt < CACHE_TTL) return _cache;
|
|
300
|
+
|
|
301
|
+
let best: TranscriptResult | undefined;
|
|
302
|
+
|
|
303
|
+
for (const spec of SPECS) {
|
|
304
|
+
const file = newestFile(spec.dirs(cwd), spec.ext);
|
|
305
|
+
if (!file) continue;
|
|
306
|
+
if (best && file.mtime <= best.mtime) continue;
|
|
307
|
+
|
|
308
|
+
const model = spec.extract(file.path);
|
|
309
|
+
if (!model) continue;
|
|
310
|
+
|
|
311
|
+
best = { model, tool: spec.tool, mtime: file.mtime };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
_cache = best;
|
|
315
|
+
_cacheAt = Date.now();
|
|
316
|
+
_cacheCwd = cwd;
|
|
317
|
+
return best;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function invalidateTranscriptCache(): void { _cache = undefined; _cacheAt = 0; }
|
package/src/daemon.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { FileProvenance } from './core/FileProvenance';
|
|
|
9
9
|
import type { StoredProvenance, LineHashBaseline } from './core/FileProvenance';
|
|
10
10
|
import { extensionIsActiveFor, writeDaemonHeartbeat } from './core/Heartbeat';
|
|
11
11
|
import { UI, COLORS } from './core/UI';
|
|
12
|
+
import { installAllToolHooks } from './core/ToolHookInstallers';
|
|
12
13
|
|
|
13
14
|
const PUSH_INTERVAL_MS = 60_000;
|
|
14
15
|
const IDLE_PUSH_MS = 10_000;
|
|
@@ -59,7 +60,21 @@ export function startDaemon(opts: { watchPath: string; projectName: string; bran
|
|
|
59
60
|
process.exit(1);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
// Auto-install preToolUse hooks into all supported tools.
|
|
64
|
+
installAllToolHooks();
|
|
65
|
+
|
|
66
|
+
const watchPath = path.resolve(opts.watchPath);
|
|
67
|
+
|
|
68
|
+
// Initialize per-project .omnitype/ dir and ensure it is in .gitignore.
|
|
69
|
+
const omniDir = path.join(watchPath, '.omnitype');
|
|
70
|
+
try { fs.mkdirSync(omniDir, { recursive: true }); } catch {}
|
|
71
|
+
try {
|
|
72
|
+
const gitignore = path.join(watchPath, '.gitignore');
|
|
73
|
+
const current = fs.existsSync(gitignore) ? fs.readFileSync(gitignore, 'utf8') : '';
|
|
74
|
+
if (!current.split('\n').some(l => l.trim() === '.omnitype' || l.trim() === '.omnitype/')) {
|
|
75
|
+
fs.appendFileSync(gitignore, (current.length && !current.endsWith('\n') ? '\n' : '') + '.omnitype/\n');
|
|
76
|
+
}
|
|
77
|
+
} catch {}
|
|
63
78
|
const projectName = opts.projectName;
|
|
64
79
|
const branch = opts.branch ?? gitBranch(watchPath);
|
|
65
80
|
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,8 @@ import { startDaemon } from './daemon';
|
|
|
13
13
|
import { runBlame } from './blame';
|
|
14
14
|
import { fetchNotes, pushNotes } from './core/GitNotes';
|
|
15
15
|
import { UI, COLORS } from './core/UI';
|
|
16
|
+
import { installAllToolHooks, checkHookStatus, type HookStatus } from './core/ToolHookInstallers';
|
|
17
|
+
import { detectInstalledTools } from './core/ToolDetector';
|
|
16
18
|
|
|
17
19
|
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
18
20
|
const program = new Command();
|
|
@@ -80,45 +82,146 @@ program
|
|
|
80
82
|
.description('Show current auth and model detection status')
|
|
81
83
|
.action(() => {
|
|
82
84
|
const api = new ApiClient();
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
const cwd = process.cwd();
|
|
86
|
+
const detection = new ModelDetector().detect(undefined, cwd);
|
|
87
|
+
|
|
88
|
+
const lines: string[] = [];
|
|
89
|
+
const col1 = 10;
|
|
90
|
+
const lbl = (k: string) => chalk.bold(chalk.hex(COLORS.primary)(k.padEnd(col1)));
|
|
91
|
+
|
|
92
|
+
// Account
|
|
88
93
|
if (api.isSignedIn) {
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
lines.push(`${lbl('Account')} ${chalk.cyan(api.username)}`);
|
|
95
|
+
lines.push(`${lbl('Server')} ${UI.dim(api.apiUrl)}`);
|
|
91
96
|
} else {
|
|
92
|
-
|
|
97
|
+
lines.push(`${lbl('Account')} ${chalk.red('not signed in')} ${UI.dim('→ omnitype login')}`);
|
|
93
98
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
|
|
100
|
+
lines.push('');
|
|
101
|
+
|
|
102
|
+
// AI context
|
|
103
|
+
const toolColor = (t: string) =>
|
|
104
|
+
t.includes('claude') ? '#D97757' : t.includes('gpt') || t.includes('openai') ? '#10A37F'
|
|
105
|
+
: t.includes('gemini') ? '#4285F4' : t.includes('copilot') ? '#6E40C9' : COLORS.ai;
|
|
106
|
+
|
|
107
|
+
const modelStr = detection.model === 'unknown'
|
|
108
|
+
? chalk.gray('none detected')
|
|
109
|
+
: chalk.bold(chalk.hex(toolColor(detection.model))(detection.model));
|
|
110
|
+
|
|
111
|
+
const toolStr = detection.tool === 'unknown'
|
|
112
|
+
? chalk.gray('—')
|
|
113
|
+
: chalk.hex(toolColor(detection.tool))(detection.tool);
|
|
114
|
+
|
|
115
|
+
const confBadge: Record<string, string> = {
|
|
116
|
+
deterministic: chalk.bgGreen.black(' HOOK '),
|
|
117
|
+
high: chalk.bgCyan.black(' HIGH '),
|
|
118
|
+
medium: chalk.bgYellow.black(' MED '),
|
|
119
|
+
low: chalk.bgRed.black(' LOW '),
|
|
108
120
|
};
|
|
109
|
-
content += ` ${chalk.bold('Conf:')} ${confColors[detection.confidence] || detection.confidence}\n`;
|
|
110
121
|
|
|
111
|
-
|
|
122
|
+
lines.push(`${lbl('Model')} ${modelStr}`);
|
|
123
|
+
lines.push(`${lbl('Tool')} ${toolStr}`);
|
|
124
|
+
lines.push(`${lbl('Confidence')} ${confBadge[detection.confidence] ?? detection.confidence}`);
|
|
125
|
+
|
|
126
|
+
// Repo
|
|
112
127
|
try {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
const cp = require('child_process');
|
|
129
|
+
const branch = cp.execSync('git rev-parse --abbrev-ref HEAD', { cwd, encoding: 'utf8', stdio: ['pipe','pipe','pipe'] }).trim();
|
|
130
|
+
const remote = (() => { try { return cp.execSync('git remote get-url origin', { cwd, encoding: 'utf8', stdio: ['pipe','pipe','pipe'] }).trim().replace(/^https?:\/\/[^/]+\//, '').replace(/\.git$/, ''); } catch { return ''; } })();
|
|
131
|
+
lines.push('');
|
|
132
|
+
lines.push(`${lbl('Project')} ${chalk.white(path.basename(cwd))}`);
|
|
133
|
+
lines.push(`${lbl('Branch')} ${chalk.magenta(branch)}`);
|
|
134
|
+
if (remote) lines.push(`${lbl('Remote')} ${UI.dim(remote)}`);
|
|
119
135
|
} catch {}
|
|
120
136
|
|
|
121
|
-
console.log(UI.box(
|
|
137
|
+
console.log(UI.box(lines.join('\n'), `${UI.logo()} Status`));
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// ── omnitype doctor ─────────────────────────────────────────────────────────
|
|
141
|
+
program
|
|
142
|
+
.command('doctor')
|
|
143
|
+
.description('Check hook status for all detected AI tools')
|
|
144
|
+
.option('--fix', 'Auto-install or upgrade any missing/stale hooks')
|
|
145
|
+
.action((opts) => {
|
|
146
|
+
const api = new ApiClient();
|
|
147
|
+
const installed = detectInstalledTools();
|
|
148
|
+
const hookStatuses = checkHookStatus();
|
|
149
|
+
const hookMap = new Map(hookStatuses.map(s => [s.tool, s.status]));
|
|
150
|
+
|
|
151
|
+
const col = 20;
|
|
152
|
+
const lbl = (k: string) => chalk.bold(k.padEnd(col));
|
|
153
|
+
|
|
154
|
+
const hookBadge: Record<HookStatus, string> = {
|
|
155
|
+
'installed': chalk.bgGreen.black(' HOOKED '),
|
|
156
|
+
'stale': chalk.bgYellow.black(' STALE '),
|
|
157
|
+
'not-installed': chalk.bgRed.black(' NOT HOOKED'),
|
|
158
|
+
'tool-absent': '',
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const lines: string[] = [];
|
|
162
|
+
let needsFix = false;
|
|
163
|
+
|
|
164
|
+
const hookedTools = installed.filter(t => t.hookSupport === 'hooked');
|
|
165
|
+
const configOnlyTools = installed.filter(t => t.hookSupport === 'config-only');
|
|
166
|
+
const unhooked = installed.filter(t => t.hookSupport === 'no-hook');
|
|
167
|
+
|
|
168
|
+
// ── Tools with sentinel hook support ──
|
|
169
|
+
if (hookedTools.length > 0) {
|
|
170
|
+
lines.push(chalk.bold(chalk.hex(COLORS.primary)('Sentinel hooks:')));
|
|
171
|
+
for (const tool of hookedTools) {
|
|
172
|
+
const status = hookMap.get(tool.id) ?? 'not-installed';
|
|
173
|
+
lines.push(` ${lbl(tool.name)} ${hookBadge[status]}`);
|
|
174
|
+
if (status === 'stale' || status === 'not-installed') needsFix = true;
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
lines.push(chalk.gray('No hookable AI tools detected on this machine.'));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ── Config-only tools (model readable, no hook API) ──
|
|
181
|
+
if (configOnlyTools.length > 0) {
|
|
182
|
+
lines.push('');
|
|
183
|
+
lines.push(chalk.bold(chalk.hex(COLORS.secondary)('Config-readable (no hook API):')));
|
|
184
|
+
for (const tool of configOnlyTools) {
|
|
185
|
+
lines.push(` ${lbl(tool.name)} ${chalk.hex(COLORS.secondary)(' DETECTED ')} ${UI.dim('model readable from config')}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ── Detected tools we don't support yet ──
|
|
190
|
+
if (unhooked.length > 0) {
|
|
191
|
+
lines.push('');
|
|
192
|
+
lines.push(chalk.bold(chalk.hex(COLORS.warning)('Detected (not yet supported):')));
|
|
193
|
+
for (const tool of unhooked) {
|
|
194
|
+
lines.push(` ${lbl(tool.name)} ${chalk.gray('— support coming soon')}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ── Nothing detected at all ──
|
|
199
|
+
if (installed.length === 0) {
|
|
200
|
+
lines.push(chalk.gray('No AI coding tools detected on this machine.'));
|
|
201
|
+
lines.push(UI.dim('Install Claude Code, Cursor, Windsurf, or another tool and re-run.'));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ── Fix prompt ──
|
|
205
|
+
if (needsFix) {
|
|
206
|
+
lines.push('');
|
|
207
|
+
if (opts.fix) {
|
|
208
|
+
installAllToolHooks();
|
|
209
|
+
lines.push(chalk.hex(COLORS.success)('✔ Hooks installed/upgraded. Run doctor again to verify.'));
|
|
210
|
+
} else {
|
|
211
|
+
lines.push(chalk.yellow('→ Run with --fix to install or upgrade missing/stale hooks.'));
|
|
212
|
+
lines.push(UI.dim(' Hooks give deterministic (100% accurate) model attribution.'));
|
|
213
|
+
}
|
|
214
|
+
} else if (hookedTools.length > 0) {
|
|
215
|
+
lines.push('');
|
|
216
|
+
lines.push(chalk.hex(COLORS.success)('✔ All hooks up to date.'));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
console.log(UI.box(lines.join('\n'), `${UI.logo()} Doctor`));
|
|
220
|
+
|
|
221
|
+
// Market analysis telemetry — fire and forget
|
|
222
|
+
if (installed.length > 0) {
|
|
223
|
+
api.reportToolEnvironment(installed.map(t => ({ id: t.id, name: t.name, hookSupport: t.hookSupport })));
|
|
224
|
+
}
|
|
122
225
|
});
|
|
123
226
|
|
|
124
227
|
// ── omnitype daemon ─────────────────────────────────────────────────────────
|