geloforge 0.6.0 → 0.9.0
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/README.md +84 -87
- package/VERSION +1 -1
- package/adapters/n8n/staging-audit-error-workflow.json +132 -0
- package/core/audit-learning.mjs +68 -0
- package/core/audit-provider.mjs +157 -0
- package/core/autonomous-audit.mjs +214 -0
- package/core/checkpoint.mjs +20 -10
- package/core/coding-loop.mjs +500 -0
- package/core/compatibility.json +1 -1
- package/core/context-cache.mjs +114 -0
- package/core/context-compiler.mjs +77 -10
- package/core/doctor.mjs +319 -0
- package/core/evidence-capture.mjs +24 -3
- package/core/hooks-init.mjs +245 -0
- package/core/mcp-init.mjs +13 -9
- package/core/mcp-lock.mjs +488 -0
- package/core/mcp-server.mjs +70 -8
- package/core/operation-approval.mjs +102 -0
- package/core/project-lock.mjs +49 -17
- package/core/project-status.mjs +68 -0
- package/core/promotion.mjs +90 -0
- package/core/runtime-files.mjs +40 -0
- package/core/skills-advisor.mjs +944 -0
- package/core/staging-audit.mjs +454 -0
- package/core/staging-evidence.mjs +127 -0
- package/core/task-manager.mjs +3 -1
- package/core/text-utils.mjs +63 -5
- package/core/worktrees.mjs +64 -0
- package/package.json +6 -2
- package/policies/approval-boundaries.md +4 -4
- package/policies/token-efficiency.md +9 -9
- package/schemas/approval-record.schema.json +9 -0
- package/scripts/geloforge.mjs +648 -14
- package/templates/project-starter/AGENTS.md +4 -3
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight, opt-in local hook installer (`geloforge hooks init`) for Git pre-commit,
|
|
3
|
+
* Claude Code, and Gemini CLI. Zero external dependencies, zero background daemons,
|
|
4
|
+
* safe non-destructive merging, and strict symlink/path confinement.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { parseConfig } from "./mcp-init.mjs";
|
|
11
|
+
import { assertSafeWithinRoot } from "./path-safety.mjs";
|
|
12
|
+
import { loadProjectManifestAndState } from "./project-locator.mjs";
|
|
13
|
+
import { runMultiFileTransaction, withProjectLock } from "./project-lock.mjs";
|
|
14
|
+
import { assertSafeAncestorChain } from "./skills-history.mjs";
|
|
15
|
+
|
|
16
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
17
|
+
const __dirname = path.dirname(__filename);
|
|
18
|
+
const DEFAULT_HARNESS_DIR = path.resolve(__dirname, "..");
|
|
19
|
+
|
|
20
|
+
export const HOOK_TARGETS = ["git", "claude", "gemini"];
|
|
21
|
+
const GIT_START = "# >>> geloforge:hooks-init:start";
|
|
22
|
+
const GIT_END = "# <<< geloforge:hooks-init:end";
|
|
23
|
+
const AGENT_DOCTOR_COMMAND = "npx geloforge doctor --skip-mcp-check";
|
|
24
|
+
|
|
25
|
+
function normalizeTargets(rawTargets) {
|
|
26
|
+
if (!rawTargets || rawTargets.length === 0) {
|
|
27
|
+
return [...HOOK_TARGETS];
|
|
28
|
+
}
|
|
29
|
+
const items = Array.isArray(rawTargets) ? rawTargets : [rawTargets];
|
|
30
|
+
const parsed = items
|
|
31
|
+
.flatMap((entry) => String(entry).split(","))
|
|
32
|
+
.map((s) => s.trim().toLowerCase())
|
|
33
|
+
.filter(Boolean);
|
|
34
|
+
if (parsed.length === 0) {
|
|
35
|
+
return [...HOOK_TARGETS];
|
|
36
|
+
}
|
|
37
|
+
const unique = [...new Set(parsed)];
|
|
38
|
+
for (const target of unique) {
|
|
39
|
+
if (!HOOK_TARGETS.includes(target)) {
|
|
40
|
+
throw new Error(`Unknown hook target "${target}". Expected: ${HOOK_TARGETS.join(", ")}.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return unique;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function readExistingHookFile(projectDir, relPath) {
|
|
47
|
+
const filePath = assertSafeWithinRoot(projectDir, relPath);
|
|
48
|
+
assertSafeAncestorChain(filePath, projectDir, relPath);
|
|
49
|
+
const stat = fs.lstatSync(filePath, { throwIfNoEntry: false });
|
|
50
|
+
if (stat && (stat.isSymbolicLink() || !stat.isFile())) {
|
|
51
|
+
throw new Error(`Refusing symbolic link or non-regular file at ${relPath}.`);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
filePath,
|
|
55
|
+
relPath,
|
|
56
|
+
original: stat ? fs.readFileSync(filePath, "utf8") : null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function buildGitPreCommitBlock(eol) {
|
|
61
|
+
return [
|
|
62
|
+
GIT_START,
|
|
63
|
+
"if command -v geloforge >/dev/null 2>&1; then",
|
|
64
|
+
' GELOFORGE_BIN="geloforge"',
|
|
65
|
+
'elif [ -x "./node_modules/.bin/geloforge" ]; then',
|
|
66
|
+
' GELOFORGE_BIN="./node_modules/.bin/geloforge"',
|
|
67
|
+
"elif command -v npx >/dev/null 2>&1 && npx --no-install geloforge --version >/dev/null 2>&1; then",
|
|
68
|
+
' GELOFORGE_BIN="npx --no-install geloforge"',
|
|
69
|
+
"else",
|
|
70
|
+
' GELOFORGE_BIN=""',
|
|
71
|
+
"fi",
|
|
72
|
+
'if [ -n "$GELOFORGE_BIN" ]; then',
|
|
73
|
+
" $GELOFORGE_BIN validate || exit 1",
|
|
74
|
+
' if [ -f ".geloforge/mcp-lock.json" ]; then',
|
|
75
|
+
" $GELOFORGE_BIN mcp lock --check || exit 1",
|
|
76
|
+
" fi",
|
|
77
|
+
"else",
|
|
78
|
+
' echo "[geloforge] pre-commit skipped: geloforge binary not found in PATH or node_modules." >&2',
|
|
79
|
+
"fi",
|
|
80
|
+
GIT_END,
|
|
81
|
+
].join(eol);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function planGitHookEdit(projectDir) {
|
|
85
|
+
const gitAbs = assertSafeWithinRoot(projectDir, ".git");
|
|
86
|
+
const gitStat = fs.lstatSync(gitAbs, { throwIfNoEntry: false });
|
|
87
|
+
if (!gitStat || gitStat.isSymbolicLink() || !gitStat.isDirectory()) {
|
|
88
|
+
return {
|
|
89
|
+
target: "git",
|
|
90
|
+
path: ".git/hooks/pre-commit",
|
|
91
|
+
action: "skipped",
|
|
92
|
+
reason: "Not a real Git repository directory",
|
|
93
|
+
write: null,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const hooksDirAbs = assertSafeWithinRoot(projectDir, ".git/hooks");
|
|
98
|
+
const hooksStat = fs.lstatSync(hooksDirAbs, { throwIfNoEntry: false });
|
|
99
|
+
if (hooksStat && (hooksStat.isSymbolicLink() || !hooksStat.isDirectory())) {
|
|
100
|
+
throw new Error("Refusing symbolic link or non-directory .git/hooks path.");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const file = readExistingHookFile(projectDir, ".git/hooks/pre-commit");
|
|
104
|
+
const original = file.original;
|
|
105
|
+
const eol = original && original.includes("\r\n") ? "\r\n" : "\n";
|
|
106
|
+
const block = buildGitPreCommitBlock(eol);
|
|
107
|
+
|
|
108
|
+
let nextContent;
|
|
109
|
+
if (original === null) {
|
|
110
|
+
nextContent = `#!/usr/bin/env sh${eol}${eol}${block}${eol}`;
|
|
111
|
+
} else {
|
|
112
|
+
const startIdx = original.indexOf(GIT_START);
|
|
113
|
+
const endIdx = original.indexOf(GIT_END);
|
|
114
|
+
if (startIdx === -1 && endIdx === -1) {
|
|
115
|
+
const trimmed = original.replace(/[\r\n]+$/, "");
|
|
116
|
+
nextContent = trimmed.length > 0 ? `${trimmed}${eol}${eol}${block}${eol}` : `#!/usr/bin/env sh${eol}${eol}${block}${eol}`;
|
|
117
|
+
} else if (
|
|
118
|
+
startIdx === -1 ||
|
|
119
|
+
endIdx < startIdx ||
|
|
120
|
+
original.lastIndexOf(GIT_START) !== startIdx ||
|
|
121
|
+
original.lastIndexOf(GIT_END) !== endIdx
|
|
122
|
+
) {
|
|
123
|
+
throw new Error("Invalid GeloForge hook markers in .git/hooks/pre-commit.");
|
|
124
|
+
} else {
|
|
125
|
+
nextContent = original.slice(0, startIdx) + block + original.slice(endIdx + GIT_END.length);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const action = original === nextContent ? "unchanged" : original === null ? "create" : "update";
|
|
130
|
+
return {
|
|
131
|
+
target: "git",
|
|
132
|
+
path: file.relPath,
|
|
133
|
+
action,
|
|
134
|
+
write:
|
|
135
|
+
action === "unchanged"
|
|
136
|
+
? null
|
|
137
|
+
: { label: "git-hook", filePath: file.filePath, content: nextContent, mode: 0o755 },
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function hasGeloForgeHookEntry(list) {
|
|
142
|
+
return list.some((entry) => {
|
|
143
|
+
if (!entry || typeof entry !== "object") return false;
|
|
144
|
+
if (typeof entry.command === "string" && /\bgeloforge\b/i.test(entry.command)) return true;
|
|
145
|
+
if (Array.isArray(entry.hooks)) {
|
|
146
|
+
return entry.hooks.some((h) => h && typeof h.command === "string" && /\bgeloforge\b/i.test(h.command));
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function planAgentHookEdit(projectDir, target, relPath, eventKey) {
|
|
153
|
+
const file = readExistingHookFile(projectDir, relPath);
|
|
154
|
+
const original = file.original;
|
|
155
|
+
let data = {};
|
|
156
|
+
if (original !== null && original.trim().length > 0) {
|
|
157
|
+
data = parseConfig(original, relPath).data;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let hooksObj = {};
|
|
161
|
+
if (Object.hasOwn(data, "hooks")) {
|
|
162
|
+
if (!data.hooks || Array.isArray(data.hooks) || typeof data.hooks !== "object") {
|
|
163
|
+
throw new Error(`Expected "hooks" to be a JSON object in ${relPath}.`);
|
|
164
|
+
}
|
|
165
|
+
hooksObj = { ...data.hooks };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let eventList = [];
|
|
169
|
+
if (Object.hasOwn(hooksObj, eventKey)) {
|
|
170
|
+
if (!Array.isArray(hooksObj[eventKey])) {
|
|
171
|
+
throw new Error(`Expected "hooks.${eventKey}" to be an array in ${relPath}.`);
|
|
172
|
+
}
|
|
173
|
+
eventList = [...hooksObj[eventKey]];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (hasGeloForgeHookEntry(eventList)) {
|
|
177
|
+
return { target, path: relPath, action: "unchanged", write: null };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
eventList.push({
|
|
181
|
+
hooks: [{ type: "command", command: AGENT_DOCTOR_COMMAND }],
|
|
182
|
+
});
|
|
183
|
+
hooksObj[eventKey] = eventList;
|
|
184
|
+
const nextData = { ...data, hooks: hooksObj };
|
|
185
|
+
const eol = original && original.includes("\r\n") ? "\r\n" : "\n";
|
|
186
|
+
const nextContent = `${JSON.stringify(nextData, null, 2).replace(/\n/g, eol)}${eol}`;
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
target,
|
|
190
|
+
path: relPath,
|
|
191
|
+
action: original === null ? "create" : "update",
|
|
192
|
+
write: { label: `${target}-hook`, filePath: file.filePath, content: nextContent },
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Installs or updates opt-in GeloForge verification/advisory hooks for Git, Claude Code, and Gemini CLI.
|
|
198
|
+
*/
|
|
199
|
+
export function initProjectHooks({
|
|
200
|
+
projectDir: rawProjectDir,
|
|
201
|
+
harnessDir: rawHarnessDir = DEFAULT_HARNESS_DIR,
|
|
202
|
+
targets = HOOK_TARGETS,
|
|
203
|
+
dryRun = false,
|
|
204
|
+
} = {}) {
|
|
205
|
+
const resolvedTargets = normalizeTargets(targets);
|
|
206
|
+
const harnessDir = path.resolve(rawHarnessDir || DEFAULT_HARNESS_DIR);
|
|
207
|
+
const loaded = loadProjectManifestAndState(rawProjectDir, harnessDir);
|
|
208
|
+
const { projectDir } = loaded;
|
|
209
|
+
|
|
210
|
+
const run = () => {
|
|
211
|
+
const plans = [];
|
|
212
|
+
|
|
213
|
+
for (const target of resolvedTargets) {
|
|
214
|
+
if (target === "git") {
|
|
215
|
+
plans.push(planGitHookEdit(projectDir));
|
|
216
|
+
} else if (target === "claude") {
|
|
217
|
+
plans.push(planAgentHookEdit(projectDir, "claude", ".claude/settings.json", "Stop"));
|
|
218
|
+
} else if (target === "gemini") {
|
|
219
|
+
plans.push(planAgentHookEdit(projectDir, "gemini", ".gemini/settings.json", "AfterAgent"));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!dryRun) {
|
|
224
|
+
const writes = plans.map((p) => p.write).filter(Boolean);
|
|
225
|
+
if (writes.length > 0) {
|
|
226
|
+
// Agent settings may sit alongside MCP config; keep pre-image backups in memory rather than writing .tx-journal.json
|
|
227
|
+
runMultiFileTransaction(writes);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
projectDir,
|
|
233
|
+
dryRun: Boolean(dryRun),
|
|
234
|
+
targets: resolvedTargets,
|
|
235
|
+
files: plans.map(({ target, path: fileRel, action, reason }) => ({
|
|
236
|
+
target,
|
|
237
|
+
path: fileRel,
|
|
238
|
+
action,
|
|
239
|
+
...(reason ? { reason } : {}),
|
|
240
|
+
})),
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
return dryRun ? run() : withProjectLock(projectDir, run);
|
|
245
|
+
}
|
package/core/mcp-init.mjs
CHANGED
|
@@ -5,7 +5,8 @@ import { assertSafeWithinRoot, isForbiddenSecretPath } from "./path-safety.mjs";
|
|
|
5
5
|
import { loadProjectManifestAndState } from "./project-locator.mjs";
|
|
6
6
|
import { runMultiFileTransaction, withProjectLock } from "./project-lock.mjs";
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const DEFAULT_CLIENTS = ["cursor", "vscode", "claude", "gemini"];
|
|
9
|
+
export const MCP_CLIENTS = {
|
|
9
10
|
cursor: {
|
|
10
11
|
config: ".cursor/mcp.json", key: "mcpServers",
|
|
11
12
|
rules: ".cursor/rules/geloforge.mdc", frontmatter: "---\nalwaysApply: true\n---\n\n",
|
|
@@ -17,8 +18,10 @@ const CLIENTS = {
|
|
|
17
18
|
claude: {
|
|
18
19
|
config: ".mcp.json", key: "mcpServers", type: "stdio", rules: ".claude/rules/geloforge.md",
|
|
19
20
|
},
|
|
20
|
-
gemini: { config: ".gemini/settings.json", key: "mcpServers", rules: "GEMINI.md" },
|
|
21
|
+
gemini: { config: ".gemini/settings.json", key: "mcpServers", rules: "GEMINI.md", appendRules: true },
|
|
22
|
+
antigravity: { config: ".agents/mcp_config.json", key: "mcpServers", rules: "AGENTS.md", appendRules: true },
|
|
21
23
|
};
|
|
24
|
+
const CLIENTS = MCP_CLIENTS;
|
|
22
25
|
|
|
23
26
|
const START = "<!-- geloforge:mcp-init:start -->";
|
|
24
27
|
const END = "<!-- geloforge:mcp-init:end -->";
|
|
@@ -31,7 +34,7 @@ function readConfigFile(projectDir, relativePath) {
|
|
|
31
34
|
return { filePath, relativePath, original: stat ? fs.readFileSync(filePath, "utf8") : null, mode: stat ? stat.mode & 0o777 : undefined };
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
function parseConfig(source, filename) {
|
|
37
|
+
export function parseConfig(source, filename) {
|
|
35
38
|
// Keep source offsets so we can edit server fields without rewriting comments and other settings.
|
|
36
39
|
const lexemes = [...source.matchAll(/"(?:[^"\\]|\\[\s\S])*"|\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|[^\s]/g)];
|
|
37
40
|
const tokens = lexemes.filter(([token]) => !token.startsWith("//") && !token.startsWith("/*"));
|
|
@@ -150,7 +153,7 @@ function updateServer(file, client, server) {
|
|
|
150
153
|
return { data, content };
|
|
151
154
|
}
|
|
152
155
|
|
|
153
|
-
function updateRules(file, { frontmatter = "",
|
|
156
|
+
function updateRules(file, { frontmatter = "", appendRules = false, readOnly }) {
|
|
154
157
|
const original = file.original ?? "";
|
|
155
158
|
const eol = original.includes("\r\n") ? "\r\n" : "\n";
|
|
156
159
|
const block = [
|
|
@@ -158,7 +161,8 @@ function updateRules(file, { frontmatter = "", gemini = false, readOnly }) {
|
|
|
158
161
|
"## GeloForge workflow",
|
|
159
162
|
"",
|
|
160
163
|
"- At the start of project work, call `geloforge_recommend` and review pending approvals.",
|
|
161
|
-
"- Before making changes, call `geloforge_context` with the task ID or a short query
|
|
164
|
+
"- Before auditing, debugging, or making changes, call `geloforge_context` with the task ID or a short query and `skills: true`.",
|
|
165
|
+
"- Follow relevant skills returned with the context. If none match, continue with the project rules. Record any skills used in the handoff.",
|
|
162
166
|
...(readOnly ? [
|
|
163
167
|
"- Use `geloforge_task` and `geloforge_checkpoint` to read task and checkpoint history.",
|
|
164
168
|
] : [
|
|
@@ -170,7 +174,7 @@ function updateRules(file, { frontmatter = "", gemini = false, readOnly }) {
|
|
|
170
174
|
const start = original.indexOf(START);
|
|
171
175
|
const end = original.indexOf(END);
|
|
172
176
|
if (start === -1 && end === -1) {
|
|
173
|
-
if (original && !
|
|
177
|
+
if (original && !appendRules) throw new Error(`Existing rule ${file.relativePath} has no GeloForge section.`);
|
|
174
178
|
return original ? `${original}${eol}${eol}${block}${eol}` : `${frontmatter}${block}${eol}`;
|
|
175
179
|
}
|
|
176
180
|
if (start === -1 || end < start || original.lastIndexOf(START) !== start || original.lastIndexOf(END) !== end) {
|
|
@@ -204,9 +208,9 @@ function launchCommand({ projectDir, harnessDir, readOnly }) {
|
|
|
204
208
|
}
|
|
205
209
|
|
|
206
210
|
export function initMcpClients({ projectDir, harnessDir, clients, dryRun = false, readOnly = false }) {
|
|
207
|
-
const names = clients?.length ? [...new Set(clients)] :
|
|
211
|
+
const names = clients?.length ? [...new Set(clients)] : DEFAULT_CLIENTS;
|
|
208
212
|
for (const name of names) {
|
|
209
|
-
if (!Object.hasOwn(CLIENTS, name)) throw new Error(`Unknown MCP client "${name}". Use cursor, vscode, claude, or
|
|
213
|
+
if (!Object.hasOwn(CLIENTS, name)) throw new Error(`Unknown MCP client "${name}". Use cursor, vscode, claude, gemini, or antigravity.`);
|
|
210
214
|
}
|
|
211
215
|
const run = () => {
|
|
212
216
|
loadProjectManifestAndState(projectDir, harnessDir);
|
|
@@ -226,7 +230,7 @@ export function initMcpClients({ projectDir, harnessDir, clients, dryRun = false
|
|
|
226
230
|
const rules = readConfigFile(projectDir, rulesPath);
|
|
227
231
|
return [
|
|
228
232
|
{ ...config, content },
|
|
229
|
-
{ ...rules, content: updateRules(rules, { frontmatter: client.frontmatter,
|
|
233
|
+
{ ...rules, content: updateRules(rules, { frontmatter: client.frontmatter, appendRules: client.appendRules, readOnly }) },
|
|
230
234
|
];
|
|
231
235
|
});
|
|
232
236
|
const destinations = edits.map(({ filePath }) => process.platform === "win32" ? filePath.toLowerCase() : filePath);
|