@jeremyy_prt/cc-config 1.1.2 → 1.1.4
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/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import type { StatuslineConfig } from "../statusline.config";
|
|
4
4
|
import { defaultConfig } from "../statusline.config";
|
|
@@ -18,6 +18,21 @@ import { saveSession } from "./lib/spend";
|
|
|
18
18
|
import type { HookInput } from "./lib/types";
|
|
19
19
|
import { getUsageLimits } from "./lib/usage-limits";
|
|
20
20
|
|
|
21
|
+
// Fonction pour lire stdin de manière compatible Node.js et Bun
|
|
22
|
+
async function getStdin(): Promise<string> {
|
|
23
|
+
// Si Bun est disponible, utiliser Bun.stdin
|
|
24
|
+
if (typeof Bun !== "undefined") {
|
|
25
|
+
return await Bun.stdin.text();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Sinon, utiliser process.stdin (Node.js)
|
|
29
|
+
const chunks: Buffer[] = [];
|
|
30
|
+
for await (const chunk of process.stdin) {
|
|
31
|
+
chunks.push(chunk as Buffer);
|
|
32
|
+
}
|
|
33
|
+
return Buffer.concat(chunks).toString("utf-8");
|
|
34
|
+
}
|
|
35
|
+
|
|
21
36
|
function buildFirstLine(
|
|
22
37
|
branch: string,
|
|
23
38
|
dirPath: string,
|
|
@@ -122,7 +137,8 @@ function buildThirdLine(
|
|
|
122
137
|
|
|
123
138
|
async function main() {
|
|
124
139
|
try {
|
|
125
|
-
const
|
|
140
|
+
const stdinData = await getStdin();
|
|
141
|
+
const input: HookInput = JSON.parse(stdinData);
|
|
126
142
|
|
|
127
143
|
await saveSession(input);
|
|
128
144
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
2
|
|
|
3
3
|
export interface GitStatus {
|
|
4
4
|
branch: string;
|
|
@@ -15,9 +15,24 @@ export interface GitStatus {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function exec(command: string): { stdout: string; exitCode: number } {
|
|
19
|
+
try {
|
|
20
|
+
const stdout = execSync(command, {
|
|
21
|
+
encoding: "utf-8",
|
|
22
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
23
|
+
});
|
|
24
|
+
return { stdout, exitCode: 0 };
|
|
25
|
+
} catch (error: any) {
|
|
26
|
+
return {
|
|
27
|
+
stdout: error.stdout?.toString() || "",
|
|
28
|
+
exitCode: error.status || 1,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
18
33
|
export async function getGitStatus(): Promise<GitStatus> {
|
|
19
34
|
try {
|
|
20
|
-
const isGitRepo =
|
|
35
|
+
const isGitRepo = exec("git rev-parse --git-dir");
|
|
21
36
|
if (isGitRepo.exitCode !== 0) {
|
|
22
37
|
return {
|
|
23
38
|
branch: "no-git",
|
|
@@ -27,21 +42,17 @@ export async function getGitStatus(): Promise<GitStatus> {
|
|
|
27
42
|
};
|
|
28
43
|
}
|
|
29
44
|
|
|
30
|
-
const branchResult =
|
|
31
|
-
const branch = branchResult.trim() || "detached";
|
|
45
|
+
const branchResult = exec("git branch --show-current");
|
|
46
|
+
const branch = branchResult.stdout.trim() || "detached";
|
|
32
47
|
|
|
33
|
-
const diffCheck =
|
|
34
|
-
const cachedCheck =
|
|
35
|
-
.quiet()
|
|
36
|
-
.nothrow();
|
|
48
|
+
const diffCheck = exec("git diff-index --quiet HEAD --");
|
|
49
|
+
const cachedCheck = exec("git diff-index --quiet --cached HEAD --");
|
|
37
50
|
|
|
38
51
|
if (diffCheck.exitCode !== 0 || cachedCheck.exitCode !== 0) {
|
|
39
|
-
const unstagedDiff =
|
|
40
|
-
const stagedDiff =
|
|
41
|
-
const stagedFilesResult =
|
|
42
|
-
|
|
43
|
-
.text();
|
|
44
|
-
const unstagedFilesResult = await $`git diff --name-only`.quiet().text();
|
|
52
|
+
const unstagedDiff = exec("git diff --numstat").stdout;
|
|
53
|
+
const stagedDiff = exec("git diff --cached --numstat").stdout;
|
|
54
|
+
const stagedFilesResult = exec("git diff --cached --name-only").stdout;
|
|
55
|
+
const unstagedFilesResult = exec("git diff --name-only").stdout;
|
|
45
56
|
|
|
46
57
|
const parseStats = (diff: string) => {
|
|
47
58
|
let added = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
5
|
|
|
6
6
|
export interface UsageLimits {
|
|
7
7
|
five_hour: {
|
|
@@ -22,7 +22,8 @@ interface CachedUsageLimits {
|
|
|
22
22
|
const CACHE_DURATION_MS = 60 * 1000; // 1 minute
|
|
23
23
|
|
|
24
24
|
function getCacheFilePath(): string {
|
|
25
|
-
|
|
25
|
+
// Utiliser __dirname pour Node.js au lieu de import.meta.dir (Bun)
|
|
26
|
+
const projectRoot = join(__dirname, "..", "..");
|
|
26
27
|
return join(projectRoot, "data", "usage-limits-cache.json");
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -38,10 +39,16 @@ interface Credentials {
|
|
|
38
39
|
|
|
39
40
|
export async function getCredentials(): Promise<string | null> {
|
|
40
41
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
// Cette commande ne fonctionne que sur macOS
|
|
43
|
+
// Sur Windows, retourner null (la statusline affichera sans les limites)
|
|
44
|
+
if (process.platform !== "darwin") {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const result = execSync(
|
|
49
|
+
'security find-generic-password -s "Claude Code-credentials" -w',
|
|
50
|
+
{ encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] },
|
|
51
|
+
);
|
|
45
52
|
const creds: Credentials = JSON.parse(result.trim());
|
|
46
53
|
return creds.claudeAiOauth.accessToken;
|
|
47
54
|
} catch {
|