@shelken/pi-co-authored-by 0.2.12 → 0.2.14
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 +1 -1
- package/src/commit.ts +8 -2
- package/src/config.ts +33 -0
- package/src/index.ts +9 -1
package/package.json
CHANGED
package/src/commit.ts
CHANGED
|
@@ -30,9 +30,15 @@ export function wrapBashWithCommitHook(
|
|
|
30
30
|
hooksDir: string,
|
|
31
31
|
modelName: string,
|
|
32
32
|
piVersion: string,
|
|
33
|
+
options?: {
|
|
34
|
+
generatorName?: string;
|
|
35
|
+
coAuthorEmail?: string;
|
|
36
|
+
},
|
|
33
37
|
): string {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
38
|
+
const generatorName = options?.generatorName || "pi";
|
|
39
|
+
const email = options?.coAuthorEmail || "noreply@pi.dev";
|
|
40
|
+
const coAuthor = `${CO_AUTHOR_NAME}: ${modelName} <${email}>`;
|
|
41
|
+
const generatedBy = `${GENERATED_BY_NAME}: ${generatorName} ${piVersion}`;
|
|
36
42
|
const runPath = join(hooksDir, "run");
|
|
37
43
|
|
|
38
44
|
return [
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_CO_AUTHOR_EMAIL = "noreply@pi.dev";
|
|
5
|
+
|
|
6
|
+
export function resolveGeneratorName(configDirName?: string | null): "omp" | "pi" {
|
|
7
|
+
return configDirName === ".omp" ? "omp" : "pi";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 从宿主 agent 目录读取配置邮箱。
|
|
12
|
+
* agentDir 由宿主 API(getAgentDir())注入,绝不自行拼接硬编码宿主路径。
|
|
13
|
+
* 任何缺失或解析失败均平滑回退默认邮箱,不抛错。
|
|
14
|
+
*/
|
|
15
|
+
export function resolveCoAuthorEmail(
|
|
16
|
+
configDirName: string | null | undefined,
|
|
17
|
+
agentDir: string,
|
|
18
|
+
): string {
|
|
19
|
+
const envEmail = process.env.PI_CO_AUTHORED_BY_EMAIL || process.env.CO_AUTHORED_BY_EMAIL;
|
|
20
|
+
if (envEmail?.trim()) return envEmail.trim();
|
|
21
|
+
|
|
22
|
+
const filename =
|
|
23
|
+
configDirName === ".omp" ? "config.yml" : configDirName === ".pi" ? "settings.json" : null;
|
|
24
|
+
if (!filename) return DEFAULT_CO_AUTHOR_EMAIL;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const text = readFileSync(join(agentDir, filename), "utf8");
|
|
28
|
+
const match = text.match(/coAuthor[\s\S]*?email["':\s]+([^\s"',}]+)/);
|
|
29
|
+
return match?.[1]?.trim() || DEFAULT_CO_AUTHOR_EMAIL;
|
|
30
|
+
} catch {
|
|
31
|
+
return DEFAULT_CO_AUTHOR_EMAIL;
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { isToolCallEventType, VERSION } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { CONFIG_DIR_NAME, getAgentDir, isToolCallEventType, VERSION } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import {
|
|
4
4
|
createCommitHookDirectory,
|
|
5
5
|
removeCommitHookDirectory,
|
|
6
6
|
wrapBashWithCommitHook,
|
|
7
7
|
} from "./commit.ts";
|
|
8
|
+
import { resolveCoAuthorEmail, resolveGeneratorName } from "./config.ts";
|
|
8
9
|
import { isGitCommitCommand } from "./git-commit.ts";
|
|
9
10
|
|
|
10
11
|
export default function (pi: ExtensionAPI) {
|
|
@@ -32,11 +33,18 @@ export default function (pi: ExtensionAPI) {
|
|
|
32
33
|
const model = ctx.model;
|
|
33
34
|
const modelName = model ? (model.name || `${model.provider}/${model.id}`) : "unknown";
|
|
34
35
|
|
|
36
|
+
const generatorName = resolveGeneratorName(CONFIG_DIR_NAME);
|
|
37
|
+
const coAuthorEmail = resolveCoAuthorEmail(CONFIG_DIR_NAME, getAgentDir());
|
|
38
|
+
|
|
35
39
|
event.input.command = wrapBashWithCommitHook(
|
|
36
40
|
event.input.command,
|
|
37
41
|
ensureHooksDir(),
|
|
38
42
|
modelName,
|
|
39
43
|
VERSION,
|
|
44
|
+
{
|
|
45
|
+
generatorName,
|
|
46
|
+
coAuthorEmail,
|
|
47
|
+
},
|
|
40
48
|
);
|
|
41
49
|
});
|
|
42
50
|
}
|