@agent_forge/forge 1.84.3 → 1.84.5
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 +6 -6
- package/run.js +90 -13
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent_forge/forge",
|
|
3
|
-
"version": "1.84.
|
|
3
|
+
"version": "1.84.5",
|
|
4
4
|
"description": "AI 开发质量门禁引擎 — 结构化门禁管道,在 AI 生成的代码进入仓库前进行质量锻造",
|
|
5
5
|
"bin": {
|
|
6
6
|
"forge": "run.js"
|
|
7
7
|
},
|
|
8
8
|
"optionalDependencies": {
|
|
9
|
-
"@agent_forge/forge-darwin-arm64": "1.84.
|
|
10
|
-
"@agent_forge/forge-darwin-x64": "1.84.
|
|
11
|
-
"@agent_forge/forge-linux-arm64": "1.84.
|
|
12
|
-
"@agent_forge/forge-linux-x64": "1.84.
|
|
13
|
-
"@agent_forge/forge-win32-x64": "1.84.
|
|
9
|
+
"@agent_forge/forge-darwin-arm64": "1.84.5",
|
|
10
|
+
"@agent_forge/forge-darwin-x64": "1.84.5",
|
|
11
|
+
"@agent_forge/forge-linux-arm64": "1.84.5",
|
|
12
|
+
"@agent_forge/forge-linux-x64": "1.84.5",
|
|
13
|
+
"@agent_forge/forge-win32-x64": "1.84.5"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"run.js",
|
package/run.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { spawn } = require("child_process");
|
|
4
|
+
const crypto = require("crypto");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
const path = require("path");
|
|
4
8
|
|
|
5
9
|
// 通过 optionalDependencies 平台子包定位当前平台的二进制。
|
|
6
10
|
// npm install 时按 os/cpu 只装匹配当前平台的一个子包(@agent_forge/forge-<platform>-<arch>),
|
|
@@ -9,6 +13,69 @@ const { spawn } = require("child_process");
|
|
|
9
13
|
const exe = process.platform === "win32" ? "forge.exe" : "forge";
|
|
10
14
|
const platformPkg = `@agent_forge/forge-${process.platform}-${process.arch}`;
|
|
11
15
|
|
|
16
|
+
// 基础设施失败的可见性(docs/plans/hook-silent-failure-visibility-2026-10.md):
|
|
17
|
+
// 本包装器自己能看见的四类失败(平台不支持 / 子包缺失 / spawn 失败 / 被信号杀死)
|
|
18
|
+
// 都 fail-open,但此前对宿主是「静默 approve」——没人知道 hook 零拦截。现在:
|
|
19
|
+
// - hook 调用(argv[2] === "hook"):同一宿主进程(ppid)同一原因第一次 stderr 输出
|
|
20
|
+
// 带修复办法的提示并 exit 1(宿主把 stderr 展示给用户,且 1 从不阻断),之后同因
|
|
21
|
+
// 静默 exit 0。包装器不能消费 stdin(子进程要读),所以会话键取 ppid 而非 session id;
|
|
22
|
+
// `sh -c` 不 exec 末条命令的宿主上 ppid 逐次变化,去重退化为逐次提示,不比现状差。
|
|
23
|
+
// - 非 hook 调用(交互使用):stderr 总是输出提示,退出码保持 0(既有契约)。
|
|
24
|
+
// - stdout 契约不变:仍打印 {"decision":"approve"}。
|
|
25
|
+
// 去重状态与 Go 侧同目录($TMPDIR/forge-hook-infra-<uid>/ppid-<pid>/),键带 wrapper: 前缀
|
|
26
|
+
// 避免与 Go 侧撞车。FORGE_HOOK_INFRA_DEDUP=0 恢复逐次 exit 1(与 Go 侧同一逃生口)。
|
|
27
|
+
// 包装器侧的逃生口无法落 checklog——这些失败发生时 forge 二进制本身缺席或没起来。
|
|
28
|
+
//
|
|
29
|
+
// node 缺失(`env: node: No such file or directory`)发生在本脚本运行之前,这里无能
|
|
30
|
+
// 为力,由 `forge doctor` 的 hook runtime 检查承担。
|
|
31
|
+
const isHook = process.argv[2] === "hook";
|
|
32
|
+
|
|
33
|
+
function claimNotice(cause) {
|
|
34
|
+
try {
|
|
35
|
+
// 与 Go 侧同根(带 uid、0700);根是符号链接时按状态不可用处理(宁可多提示)。
|
|
36
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
37
|
+
const root = path.join(os.tmpdir(), `forge-hook-infra-${uid}`);
|
|
38
|
+
try {
|
|
39
|
+
if (!fs.lstatSync(root).isDirectory()) return true;
|
|
40
|
+
} catch (_) {
|
|
41
|
+
// 根尚不存在:下面创建。
|
|
42
|
+
}
|
|
43
|
+
const dir = path.join(root, `ppid-${process.ppid}`);
|
|
44
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
45
|
+
const key = crypto.createHash("sha256").update(`wrapper:${cause}`).digest("hex").slice(0, 16);
|
|
46
|
+
const marker = path.join(dir, key);
|
|
47
|
+
try {
|
|
48
|
+
fs.closeSync(fs.openSync(marker, "wx", 0o600));
|
|
49
|
+
return true;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (!(e && e.code === "EEXIST")) throw e;
|
|
52
|
+
// PID 复用 / 久驻会话:超过 12 小时的旧标记视为陈旧,重新认领。
|
|
53
|
+
if (Date.now() - fs.statSync(marker).mtimeMs > 12 * 3600 * 1000) {
|
|
54
|
+
fs.rmSync(marker, { force: true });
|
|
55
|
+
fs.closeSync(fs.openSync(marker, "wx", 0o600));
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// 状态记不下来时宁可多提示,不吞(与 Go 侧 ClaimInfraNotice 同取向)。
|
|
62
|
+
return !(e && e.code === "EEXIST");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function failOpen(cause, message, fix) {
|
|
67
|
+
const dedupOn = (process.env.FORGE_HOOK_INFRA_DEDUP || "").trim() !== "0";
|
|
68
|
+
const first = !isHook || !dedupOn || claimNotice(cause);
|
|
69
|
+
console.log('{"decision":"approve"}');
|
|
70
|
+
if (first) {
|
|
71
|
+
console.error(
|
|
72
|
+
`[forge] hook 基础设施故障(${cause},已放行、不阻断${dedupOn ? ";本会话同因不再提示" : ""}): ${message}\n` +
|
|
73
|
+
`修复: ${fix}\n(FORGE_HOOK_INFRA_DEDUP=0 恢复逐次报错)`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
process.exit(isHook && first ? 1 : 0);
|
|
77
|
+
}
|
|
78
|
+
|
|
12
79
|
// 支持的平台白名单(goreleaser 构建矩阵:linux/darwin × amd64/arm64 + windows/amd64)。
|
|
13
80
|
// 不在此列的平台(如 windows-arm64)无对应子包,require.resolve 必失败——明确 stderr 提示,
|
|
14
81
|
// 不混入"子包未装"的静默 approve,避免用户误以为 Forge 正常工作却零拦截。
|
|
@@ -17,18 +84,24 @@ const SUPPORTED = new Set([
|
|
|
17
84
|
]);
|
|
18
85
|
const platKey = `${process.platform}-${process.arch}`;
|
|
19
86
|
if (!SUPPORTED.has(platKey)) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
87
|
+
failOpen(
|
|
88
|
+
"unsupported-platform",
|
|
89
|
+
`unsupported platform: ${platKey} (no prebuilt binary); hooks will not fire`,
|
|
90
|
+
"该平台没有预编译二进制(支持 darwin/linux 的 arm64/x64 与 win32-x64);改用受支持平台,或从源码构建 forge 放进 PATH。"
|
|
91
|
+
);
|
|
23
92
|
}
|
|
24
93
|
|
|
25
94
|
let binaryPath;
|
|
26
95
|
try {
|
|
27
96
|
binaryPath = require.resolve(`${platformPkg}/bin/${exe}`);
|
|
28
97
|
} catch (_) {
|
|
29
|
-
// 支持的平台但子包未装(npm 12 + --omit=optional /
|
|
30
|
-
|
|
31
|
-
|
|
98
|
+
// 支持的平台但子包未装(npm 12 + --omit=optional / 安装中断)——fail-open 避免阻塞 hooks,
|
|
99
|
+
// 但不再静默:首次提示 + 修复办法。
|
|
100
|
+
failOpen(
|
|
101
|
+
"subpackage-missing",
|
|
102
|
+
`platform package ${platformPkg} is not installed; hooks will not fire`,
|
|
103
|
+
"重装并保留 optionalDependencies:npm i -g @agent_forge/forge --include=optional(不要带 --omit=optional)。"
|
|
104
|
+
);
|
|
32
105
|
}
|
|
33
106
|
|
|
34
107
|
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
@@ -39,18 +112,22 @@ const child = spawn(binaryPath, process.argv.slice(2), {
|
|
|
39
112
|
// spawn 失败走 error 事件而非 exit——无监听器会带栈迹非零崩溃,违反本包装器的
|
|
40
113
|
// fail-open 契约(宿主表现为 hook 异常而非 approve)。
|
|
41
114
|
child.on("error", (e) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
115
|
+
failOpen(
|
|
116
|
+
"spawn-failed",
|
|
117
|
+
`spawn failed: ${e.message}; hooks will not fire`,
|
|
118
|
+
`检查 ${binaryPath} 是否存在且可执行(chmod +x);仍失败则重装:npm i -g @agent_forge/forge --include=optional。`
|
|
119
|
+
);
|
|
45
120
|
});
|
|
46
121
|
|
|
47
122
|
// exit 的 code 为 null 表示被信号杀死(OOM/SIGKILL)——不能折叠成成功语义;
|
|
48
|
-
// 按包装器 fail-open 契约显式 approve
|
|
123
|
+
// 按包装器 fail-open 契约显式 approve 并给出可见提示。
|
|
49
124
|
child.on("exit", (code, signal) => {
|
|
50
125
|
if (code === null) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
126
|
+
failOpen(
|
|
127
|
+
"signal-killed",
|
|
128
|
+
`forge exited on signal ${signal}; hooks will not fire`,
|
|
129
|
+
"forge 被信号终止(常见于内存不足或被安全软件杀掉);重试,持续复现请带上本行报错反馈。"
|
|
130
|
+
);
|
|
54
131
|
}
|
|
55
132
|
process.exit(code || 0);
|
|
56
133
|
});
|