codex-lens 0.1.29 → 0.1.30

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/build.js CHANGED
@@ -20,6 +20,7 @@ async function buildAll() {
20
20
  'src/aggregator.js',
21
21
  'src/watcher.js',
22
22
  'src/pty-manager.js',
23
+ 'src/git-manager.js',
23
24
  'src/lib/sse-parser.js',
24
25
  'src/lib/diff-builder.js',
25
26
  'src/lib/log-manager.js',
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "child_process";
3
+ import { existsSync } from "fs";
4
+ import { join } from "path";
5
+ import { createLogger } from "./lib/logger.js";
6
+ const logger = createLogger("GitManager");
7
+ class GitManager {
8
+ constructor(projectRoot, wsEmitter) {
9
+ this.projectRoot = projectRoot;
10
+ this.wsEmitter = wsEmitter;
11
+ this.gitDir = join(projectRoot, ".git");
12
+ this.currentStatus = null;
13
+ this.currentBranch = null;
14
+ this._statusTimeout = null;
15
+ }
16
+ isGitRepo() {
17
+ return existsSync(this.gitDir);
18
+ }
19
+ runGitCommand(args) {
20
+ return new Promise((resolve, reject) => {
21
+ const proc = spawn("git", args, {
22
+ cwd: this.projectRoot,
23
+ shell: true,
24
+ windowsHide: true
25
+ });
26
+ let stdout = "";
27
+ let stderr = "";
28
+ proc.stdout?.on("data", (data) => {
29
+ stdout += data.toString();
30
+ });
31
+ proc.stderr?.on("data", (data) => {
32
+ stderr += data.toString();
33
+ });
34
+ proc.on("close", (code) => {
35
+ resolve({ code, stdout, stderr });
36
+ });
37
+ proc.on("error", (err) => {
38
+ reject(err);
39
+ });
40
+ });
41
+ }
42
+ parsePorcelainStatus(output) {
43
+ const lines = output.trim().split("\n");
44
+ const result = {
45
+ staged: [],
46
+ unstaged: [],
47
+ untracked: [],
48
+ conflicted: []
49
+ };
50
+ for (const line of lines) {
51
+ if (!line || line.length < 3) continue;
52
+ const indexStatus = line[0];
53
+ const workTreeStatus = line[1];
54
+ const path = line.slice(3).trim();
55
+ const fileInfo = { path, indexStatus, workTreeStatus };
56
+ if (indexStatus !== " " && indexStatus !== "?") {
57
+ result.staged.push(fileInfo);
58
+ }
59
+ if (workTreeStatus === "M" || workTreeStatus === "D") {
60
+ result.unstaged.push(fileInfo);
61
+ }
62
+ if (indexStatus === "?" && workTreeStatus === "?") {
63
+ result.untracked.push(fileInfo);
64
+ }
65
+ if (indexStatus === "U" || workTreeStatus === "U") {
66
+ result.conflicted.push(fileInfo);
67
+ }
68
+ }
69
+ return result;
70
+ }
71
+ async getStatus() {
72
+ if (!this.isGitRepo()) return null;
73
+ try {
74
+ const { stdout } = await this.runGitCommand(["status", "--porcelain"]);
75
+ this.currentStatus = this.parsePorcelainStatus(stdout);
76
+ return this.currentStatus;
77
+ } catch (error) {
78
+ logger.error(`Failed to get git status: ${error.message}`);
79
+ return null;
80
+ }
81
+ }
82
+ async getCurrentBranch() {
83
+ if (!this.isGitRepo()) return null;
84
+ try {
85
+ const { stdout } = await this.runGitCommand(["branch", "--show-current"]);
86
+ this.currentBranch = stdout.trim();
87
+ return this.currentBranch;
88
+ } catch (error) {
89
+ logger.error(`Failed to get branch: ${error.message}`);
90
+ return null;
91
+ }
92
+ }
93
+ async stageFile(filePath) {
94
+ await this.runGitCommand(["add", filePath]);
95
+ return this.getStatus();
96
+ }
97
+ async unstageFile(filePath) {
98
+ await this.runGitCommand(["reset", "HEAD", "--", filePath]);
99
+ return this.getStatus();
100
+ }
101
+ async stageAll() {
102
+ await this.runGitCommand(["add", "-A"]);
103
+ return this.getStatus();
104
+ }
105
+ async unstageAll() {
106
+ await this.runGitCommand(["reset", "HEAD"]);
107
+ return this.getStatus();
108
+ }
109
+ async commit(message) {
110
+ await this.runGitCommand(["commit", "-m", message]);
111
+ return this.getStatus();
112
+ }
113
+ async broadcastUpdate() {
114
+ const branch = await this.getCurrentBranch();
115
+ const status = await this.getStatus();
116
+ this.wsEmitter({
117
+ type: "git_status",
118
+ data: {
119
+ isRepo: true,
120
+ branch,
121
+ status,
122
+ stagedCount: status?.staged?.length || 0,
123
+ unstagedCount: (status?.unstaged?.length || 0) + (status?.untracked?.length || 0),
124
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
125
+ }
126
+ });
127
+ }
128
+ scheduleStatusUpdate() {
129
+ if (this._statusTimeout) {
130
+ clearTimeout(this._statusTimeout);
131
+ }
132
+ this._statusTimeout = setTimeout(() => {
133
+ this.broadcastUpdate();
134
+ }, 500);
135
+ }
136
+ }
137
+ function createGitManager(projectRoot, wsEmitter) {
138
+ return new GitManager(projectRoot, wsEmitter);
139
+ }
140
+ export {
141
+ createGitManager
142
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-lens",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "A visualization tool for Codex that monitors API requests and file system changes",
5
5
  "license": "MIT",
6
6
  "type": "module",