@thegitai/cli 1.0.0 → 1.0.1

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.
@@ -743,6 +743,8 @@ async function runTurnStream({ openStream, config, session, input, request, reco
743
743
  }
744
744
  }
745
745
  export async function sendServerUserMessage({ config, session, input, jobFollowUp = false, imageAttachments = [], fetchImpl = globalThis.fetch, signal, onTurnStart, onInterjectionDelivered, recoverySleep, }) {
746
+ if (!jobFollowUp)
747
+ session.sessionLastPromptAt = new Date().toISOString();
746
748
  const autoAttach = autoAttachImages(input, session.rootDir, imageAttachments);
747
749
  const requestImageAttachments = autoAttach.attachments.length > 0
748
750
  ? [...imageAttachments, ...autoAttach.attachments]
@@ -15,6 +15,7 @@ function sanitizeModelInfo(raw) {
15
15
  return null;
16
16
  }
17
17
  const locked = isModelLock(value.locked) ? value.locked : undefined;
18
+ const comparison = sanitizeComparison(value.comparison);
18
19
  return {
19
20
  id,
20
21
  label,
@@ -22,11 +23,34 @@ function sanitizeModelInfo(raw) {
22
23
  description,
23
24
  ...(locked ? { locked } : {}),
24
25
  ...(value.auto === true ? { auto: true } : {}),
26
+ ...(comparison ? { comparison } : {}),
25
27
  };
26
28
  }
27
29
  function isModelLock(value) {
28
30
  return value === 'plan' || value === 'auto-only';
29
31
  }
32
+ function sanitizeComparison(raw) {
33
+ if (!raw || typeof raw !== 'object')
34
+ return undefined;
35
+ const value = raw;
36
+ if ((value.intelligenceScore !== null &&
37
+ (typeof value.intelligenceScore !== 'number' || !Number.isFinite(value.intelligenceScore) ||
38
+ value.intelligenceScore < 0 || value.intelligenceScore > 100)) ||
39
+ typeof value.responseTimeMs !== 'number' || !Number.isFinite(value.responseTimeMs) ||
40
+ value.responseTimeMs <= 0 || typeof value.benchmarkLabel !== 'string' ||
41
+ typeof value.benchmarkUrl !== 'string' || !/^https?:\/\//.test(value.benchmarkUrl) ||
42
+ (value.evaluationNote !== null && typeof value.evaluationNote !== 'string') ||
43
+ typeof value.updatedAt !== 'string' || !Number.isFinite(Date.parse(value.updatedAt)))
44
+ return undefined;
45
+ return {
46
+ intelligenceScore: value.intelligenceScore,
47
+ benchmarkLabel: value.benchmarkLabel,
48
+ benchmarkUrl: value.benchmarkUrl,
49
+ evaluationNote: value.evaluationNote,
50
+ responseTimeMs: value.responseTimeMs,
51
+ updatedAt: value.updatedAt,
52
+ };
53
+ }
30
54
  function isCostRating(value) {
31
55
  return Number.isInteger(value) && value >= 1 && value <= 3;
32
56
  }
@@ -103,7 +127,10 @@ export async function fetchServerModels({ config, fetchImpl = globalThis.fetch,
103
127
  if (models.length === 0) {
104
128
  throw new Error('Server returned an invalid model list.');
105
129
  }
106
- return { models };
130
+ return { models: models.map((model) => {
131
+ const comparison = sanitizeComparison(data?.comparisons?.[model.id]);
132
+ return comparison ? { ...model, comparison } : model;
133
+ }) };
107
134
  }, ladder);
108
135
  }
109
136
  export function selectServerModel({ requestedModelId, cached, serverModels, }) {
@@ -3,6 +3,7 @@ import { spawn } from 'child_process';
3
3
  import { buildCommandEnv, commandUsesSudo, resolveCommandShell, sanitizeCommandText, terminateChild, } from './executor.js';
4
4
  import { isTuiMode } from './runtime-mode.js';
5
5
  import { redactConnectionStringCredentials } from './secret-preview.js';
6
+ import { scopedSessionId } from './session-context.js';
6
7
  const MAX_RUNNING_JOBS = 8;
7
8
  const MAX_FINISHED_JOBS = 20;
8
9
  const MAX_JOB_BUFFER_CHARS = 200 * 1024;
@@ -18,11 +19,14 @@ let pendingModelNotifications = [];
18
19
  export function setBackgroundJobUpdateHook(hook) {
19
20
  updateHook = hook;
20
21
  }
22
+ function fallbackSessionId() {
23
+ return scopedSessionId() ?? activeSessionId;
24
+ }
21
25
  function normalizeSessionId(sessionId) {
22
- return String(sessionId ?? activeSessionId ?? 'default').trim() || 'default';
26
+ return String(sessionId ?? fallbackSessionId() ?? 'default').trim() || 'default';
23
27
  }
24
28
  function sessionFilter(sessionId) {
25
- const value = String(sessionId ?? activeSessionId ?? '').trim();
29
+ const value = String(sessionId ?? fallbackSessionId() ?? '').trim();
26
30
  return value || null;
27
31
  }
28
32
  function belongsToSession(record, sessionId) {
@@ -3,33 +3,54 @@ import path from 'node:path';
3
3
  import { createHash } from 'node:crypto';
4
4
  import { getClientStateDir } from '../client-state.js';
5
5
  import { MAX_IMAGE_SIZE_BYTES, imageExtensionForMime, isSupportedImageMimeType, sniffImageMimeType, } from './image-limits.js';
6
+ import { scopedSessionId } from '../session-context.js';
6
7
  const IMAGE_FILE_MODE = 0o600;
7
8
  const IMAGE_DIR_MODE = 0o700;
8
9
  export const SESSION_IMAGE_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
9
10
  let activeSessionId = null;
10
11
  export function setImageStoreSession(sessionId) {
11
- activeSessionId = String(sessionId ?? '').trim() || null;
12
- contentIndex.clear();
12
+ const next = String(sessionId ?? '').trim() || null;
13
+ if (activeSessionId !== next && activeSessionId)
14
+ contentIndexes.delete(activeSessionId);
15
+ activeSessionId = next;
16
+ }
17
+ function currentSession() {
18
+ return scopedSessionId() ?? activeSessionId;
19
+ }
20
+ const contentIndexes = new Map();
21
+ function contentIndexFor(sessionId) {
22
+ let index = contentIndexes.get(sessionId);
23
+ if (!index) {
24
+ index = new Map();
25
+ contentIndexes.set(sessionId, index);
26
+ }
27
+ return index;
13
28
  }
14
- const contentIndex = new Map();
15
29
  function imageContentKey(base64Data) {
16
30
  return createHash('sha256').update(base64Data).digest('hex');
17
31
  }
18
32
  function rememberStoredImage(base64Data, cachePath) {
19
- contentIndex.set(imageContentKey(base64Data), cachePath);
33
+ const sessionId = currentSession();
34
+ if (!sessionId)
35
+ return;
36
+ contentIndexFor(sessionId).set(imageContentKey(base64Data), cachePath);
20
37
  }
21
38
  export function findStoredImageByContent(base64Data) {
22
- const cachePath = contentIndex.get(imageContentKey(base64Data));
39
+ const sessionId = currentSession();
40
+ if (!sessionId)
41
+ return undefined;
42
+ const index = contentIndexFor(sessionId);
43
+ const cachePath = index.get(imageContentKey(base64Data));
23
44
  if (!cachePath)
24
45
  return undefined;
25
46
  if (!existsSync(cachePath)) {
26
- contentIndex.delete(imageContentKey(base64Data));
47
+ index.delete(imageContentKey(base64Data));
27
48
  return undefined;
28
49
  }
29
50
  return cachePath;
30
51
  }
31
52
  export function getImageStoreSession() {
32
- return activeSessionId;
53
+ return currentSession();
33
54
  }
34
55
  function safeSessionDirName(sessionId) {
35
56
  const normalized = String(sessionId ?? '').trim();
@@ -71,11 +92,12 @@ export function storeSessionImageBytes({ sessionId, base64Data, mimeType, env =
71
92
  return { cachePath, mimeType, base64Data, index };
72
93
  }
73
94
  export function tryCacheAttachmentBytes({ base64Data, mimeType, env = process.env, }) {
74
- if (!activeSessionId)
95
+ const sessionId = currentSession();
96
+ if (!sessionId)
75
97
  return undefined;
76
98
  try {
77
99
  const stored = storeSessionImageBytes({
78
- sessionId: activeSessionId,
100
+ sessionId,
79
101
  base64Data,
80
102
  mimeType,
81
103
  env,
@@ -87,16 +109,18 @@ export function tryCacheAttachmentBytes({ base64Data, mimeType, env = process.en
87
109
  }
88
110
  }
89
111
  export function isSessionStorePath(candidate, env = process.env) {
90
- if (!activeSessionId)
112
+ const sessionId = currentSession();
113
+ if (!sessionId)
91
114
  return false;
92
- const dir = getSessionImageDir(activeSessionId, env);
115
+ const dir = getSessionImageDir(sessionId, env);
93
116
  const resolved = path.resolve(candidate);
94
117
  return (resolved.startsWith(dir + path.sep) && path.dirname(resolved) === dir);
95
118
  }
96
119
  export function readSessionImageByIndex(index, env = process.env) {
97
- if (!activeSessionId || !Number.isInteger(index) || index < 1)
120
+ const sessionId = currentSession();
121
+ if (!sessionId || !Number.isInteger(index) || index < 1)
98
122
  return null;
99
- const dir = getSessionImageDir(activeSessionId, env);
123
+ const dir = getSessionImageDir(sessionId, env);
100
124
  if (!existsSync(dir))
101
125
  return null;
102
126
  try {
@@ -112,9 +136,10 @@ export function readSessionImageByIndex(index, env = process.env) {
112
136
  return null;
113
137
  }
114
138
  export function describeSessionImageStore(env = process.env) {
115
- if (!activeSessionId)
139
+ const sessionId = currentSession();
140
+ if (!sessionId)
116
141
  return null;
117
- const dir = getSessionImageDir(activeSessionId, env);
142
+ const dir = getSessionImageDir(sessionId, env);
118
143
  if (!existsSync(dir))
119
144
  return null;
120
145
  const indices = [];
@@ -1,18 +1,22 @@
1
1
  import { chmodSync, lstatSync, mkdtempSync } from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
+ import { scopedSessionId } from './session-context.js';
4
5
  const scratchDirs = new Map();
5
6
  let activeSessionId = 'default';
6
7
  export function setScratchSession(sessionId) {
7
8
  activeSessionId = String(sessionId ?? '').trim() || 'default';
8
9
  }
10
+ function currentKey() {
11
+ return scopedSessionId() ?? activeSessionId;
12
+ }
9
13
  function allocateSessionScratchDir() {
10
14
  const dir = mkdtempSync(path.join(os.tmpdir(), 'thegitai-'));
11
- scratchDirs.set(activeSessionId, dir);
15
+ scratchDirs.set(currentKey(), dir);
12
16
  return dir;
13
17
  }
14
18
  export function sessionScratchDir() {
15
- return scratchDirs.get(activeSessionId) ?? allocateSessionScratchDir();
19
+ return scratchDirs.get(currentKey()) ?? allocateSessionScratchDir();
16
20
  }
17
21
  function isOwnedDirectory(dir) {
18
22
  try {
@@ -0,0 +1,11 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ const storage = new AsyncLocalStorage();
3
+ export function runWithSession(sessionId, fn) {
4
+ const id = String(sessionId ?? '').trim();
5
+ if (!id)
6
+ return fn();
7
+ return storage.run(id, fn);
8
+ }
9
+ export function scopedSessionId() {
10
+ return storage.getStore() ?? null;
11
+ }
@@ -143,6 +143,7 @@ function normalizeSnapshot(raw, rootDir) {
143
143
  updatedAt: normalizeIsoDate(raw.updatedAt),
144
144
  modelId,
145
145
  branch: normalizeBranch(raw.branch),
146
+ lastPromptAt: raw.lastPromptAt ? normalizeIsoDate(raw.lastPromptAt) : null,
146
147
  history: cloneJson(normalizeHistory(raw.history)),
147
148
  clientState: sanitizeClientState(raw.clientState),
148
149
  serverState: sanitizeOpaqueState(raw.serverState),
@@ -249,6 +250,7 @@ export function snapshotFromSession(session) {
249
250
  updatedAt: now,
250
251
  modelId: session.modelId,
251
252
  branch: readGitBranch(session.rootDir),
253
+ lastPromptAt: session.sessionLastPromptAt ?? null,
252
254
  history: cloneJson(session.history),
253
255
  clientState: {
254
256
  editCounter: session.clientState.editCounter,
@@ -273,6 +275,8 @@ export function applySessionSnapshot(session, snapshot, options = {}) {
273
275
  session.sessionName = snapshot.name;
274
276
  session.sessionCreatedAt = snapshot.createdAt;
275
277
  session.sessionUpdatedAt = snapshot.updatedAt;
278
+ session.sessionLastPromptAt =
279
+ snapshot.lastPromptAt ?? session.sessionLastPromptAt ?? null;
276
280
  session.modelId = Number(options.modelOverride ?? snapshot.modelId);
277
281
  session.history = cloneJson(snapshot.history);
278
282
  session.serverState = sanitizeOpaqueState(snapshot.serverState);
@@ -342,6 +346,7 @@ function metadataFromSnapshot(snapshot) {
342
346
  lastUserMessage: extractFirstUserPrompt(snapshot.history),
343
347
  summaryPreview: '',
344
348
  branch: snapshot.branch ?? null,
349
+ lastPromptAt: snapshot.lastPromptAt ?? null,
345
350
  };
346
351
  }
347
352
  export function listSessionMetadata(rootDir, env = process.env) {
@@ -56,6 +56,7 @@ export function createSession({ rootDir, autoYes = false, agentMode, modelId, ma
56
56
  sessionName,
57
57
  sessionCreatedAt: createdAt,
58
58
  sessionUpdatedAt: createdAt,
59
+ sessionLastPromptAt: null,
59
60
  modelId: Number(modelId),
60
61
  turnState: {
61
62
  id: null,
@@ -80,6 +81,7 @@ export function startNewConversation(session) {
80
81
  session.sessionName = null;
81
82
  session.sessionCreatedAt = createdAt;
82
83
  session.sessionUpdatedAt = createdAt;
84
+ session.sessionLastPromptAt = null;
83
85
  }
84
86
  export function clearConversation(session) {
85
87
  session.history = [];
@@ -1,7 +1,12 @@
1
+ import { scopedSessionId } from './session-context.js';
1
2
  export const MAX_TODO_ITEMS = 20;
2
3
  export const MAX_TODO_TEXT_CHARS = 160;
3
- let items = [];
4
+ const lists = new Map();
4
5
  let activeSessionId = null;
6
+ const NO_SESSION = '';
7
+ function currentKey() {
8
+ return scopedSessionId() ?? activeSessionId ?? NO_SESSION;
9
+ }
5
10
  const STATUS_ALIASES = {
6
11
  pending: 'pending',
7
12
  todo: 'pending',
@@ -39,22 +44,24 @@ export function extractTodosArg(args) {
39
44
  export function setTodoSession(sessionId) {
40
45
  const next = String(sessionId ?? '').trim() || null;
41
46
  if (activeSessionId !== next) {
42
- items = [];
47
+ lists.delete(activeSessionId ?? NO_SESSION);
43
48
  }
44
49
  activeSessionId = next;
45
50
  }
46
- export function listTodos() {
47
- return items.map((item) => ({ ...item }));
51
+ export function listTodos(sessionId) {
52
+ const key = sessionId === undefined ? currentKey() : (sessionId ?? NO_SESSION);
53
+ return (lists.get(key) ?? []).map((item) => ({ ...item }));
48
54
  }
49
- export function getTodoSnapshot() {
55
+ export function getTodoSnapshot(sessionId) {
56
+ const items = listTodos(sessionId);
50
57
  return {
51
- items: listTodos(),
58
+ items,
52
59
  completedCount: items.filter((item) => item.status === 'completed').length,
53
60
  totalCount: items.length,
54
61
  };
55
62
  }
56
- export function clearTodos() {
57
- items = [];
63
+ export function clearTodos(sessionId) {
64
+ lists.delete(sessionId === undefined ? currentKey() : (sessionId ?? NO_SESSION));
58
65
  }
59
66
  export function replaceTodos(raw) {
60
67
  if (!Array.isArray(raw)) {
@@ -101,6 +108,6 @@ export function replaceTodos(raw) {
101
108
  }
102
109
  next.push({ text: boundedText, status: finalStatus });
103
110
  }
104
- items = next;
111
+ lists.set(currentKey(), next);
105
112
  return { ok: true, snapshot: getTodoSnapshot(), normalizations };
106
113
  }
@@ -216,6 +216,7 @@ function recordAssistantEdit(session, call, result, before) {
216
216
  }
217
217
  export async function executeLocalToolCall(session, call, diagnosticsPlan) {
218
218
  session.turnAbortSignal?.throwIfAborted();
219
+ session.onToolStart?.(call);
219
220
  session.onStatus(formatToolCallForStatus(call, session.mcp?.label(call.name)));
220
221
  try {
221
222
  const agentModeBlocked = buildAgentModeToolBlockedResult(session.agentMode, call);
@@ -67,7 +67,7 @@ function executeNodeScript(rootDir, script, timeout) {
67
67
  let settled = false;
68
68
  let timeoutTimer = null;
69
69
  let killTimer = null;
70
- const child = spawn(process.execPath, ['--input-type=module'], {
70
+ const child = spawn(process.versions.electron ? 'node' : process.execPath, ['--input-type=module'], {
71
71
  cwd: rootDir,
72
72
  detached: process.platform !== 'win32',
73
73
  env: {
@@ -541,6 +541,8 @@ async function runJavaScriptCheck(rootDir, filePath) {
541
541
  return runTypeScriptCheck(rootDir);
542
542
  }
543
543
  if (filePath) {
544
+ if (!(await commandExists('node')))
545
+ return runJavaScriptStaticCheck(rootDir, filePath);
544
546
  const result = await runCheck('node', ['--check', filePath], rootDir);
545
547
  const staticDiagnostics = runJavaScriptStaticCheck(rootDir, filePath);
546
548
  if (result.exitCode !== 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thegitai/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "TheGitAI is an agentic AI coding tool for your terminal. It reads and searches your repository, writes and edits files, runs your tests, and verifies the change before handing it back.",
5
5
  "keywords": [
6
6
  "agentic-ai",
@@ -45,11 +45,11 @@
45
45
  "@lydell/node-pty-linux-x64": "1.1.0",
46
46
  "@lydell/node-pty-win32-arm64": "1.1.0",
47
47
  "@lydell/node-pty-win32-x64": "1.1.0",
48
- "@thegitai/tui-darwin-arm64": "1.0.0",
49
- "@thegitai/tui-darwin-x64": "1.0.0",
50
- "@thegitai/tui-linux-arm64": "1.0.0",
51
- "@thegitai/tui-linux-x64": "1.0.0",
52
- "@thegitai/tui-win32-x64": "1.0.0",
48
+ "@thegitai/tui-darwin-arm64": "1.0.1",
49
+ "@thegitai/tui-darwin-x64": "1.0.1",
50
+ "@thegitai/tui-linux-arm64": "1.0.1",
51
+ "@thegitai/tui-linux-x64": "1.0.1",
52
+ "@thegitai/tui-win32-x64": "1.0.1",
53
53
  "@vscode/ripgrep": "1.18.0"
54
54
  },
55
55
  "repository": {