codex-lens 0.1.29 → 0.1.31

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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 AdonisZeng
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AdonisZeng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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',
@@ -156,6 +156,21 @@ class Aggregator {
156
156
  const fileTree = scanDirectory(this.projectRoot);
157
157
  logger.info(`Sending file_tree with ${fileTree.length} top-level items`);
158
158
  ws.send(JSON.stringify({ type: "file_tree", data: fileTree }));
159
+ if (this.gitManager?.isGitRepo()) {
160
+ const branch = this.gitManager.getCurrentBranch();
161
+ const status = this.gitManager.currentStatus;
162
+ ws.send(JSON.stringify({
163
+ type: "git_status",
164
+ data: {
165
+ isRepo: true,
166
+ branch,
167
+ status,
168
+ stagedCount: status?.staged?.length || 0,
169
+ unstagedCount: (status?.unstaged?.length || 0) + (status?.untracked?.length || 0),
170
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
171
+ }
172
+ }));
173
+ }
159
174
  ws.on("close", () => {
160
175
  logger.info("API client disconnected");
161
176
  this.clients.delete(ws);
@@ -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.31",
4
4
  "description": "A visualization tool for Codex that monitors API requests and file system changes",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/aggregator.js CHANGED
@@ -186,6 +186,23 @@ class Aggregator {
186
186
  logger.info(`Sending file_tree with ${fileTree.length} top-level items`);
187
187
  ws.send(JSON.stringify({ type: 'file_tree', data: fileTree }));
188
188
 
189
+ // Send initial git status if available
190
+ if (this.gitManager?.isGitRepo()) {
191
+ const branch = this.gitManager.getCurrentBranch();
192
+ const status = this.gitManager.currentStatus;
193
+ ws.send(JSON.stringify({
194
+ type: 'git_status',
195
+ data: {
196
+ isRepo: true,
197
+ branch,
198
+ status,
199
+ stagedCount: status?.staged?.length || 0,
200
+ unstagedCount: (status?.unstaged?.length || 0) + (status?.untracked?.length || 0),
201
+ timestamp: new Date().toISOString()
202
+ }
203
+ }));
204
+ }
205
+
189
206
  ws.on('close', () => {
190
207
  logger.info('API client disconnected');
191
208
  this.clients.delete(ws);