geloforge 0.0.0-stage → 0.7.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/LICENSE +21 -0
- package/README.md +72 -2
- package/THIRD_PARTY_NOTICES.md +33 -0
- package/VERSION +1 -0
- package/adapters/n8n/staging-audit-error-workflow.json +132 -0
- package/core/adopt-project.mjs +458 -0
- package/core/audit-learning.mjs +68 -0
- package/core/audit-provider.mjs +88 -0
- package/core/autonomous-audit.mjs +214 -0
- package/core/checkpoint.mjs +448 -0
- package/core/codebase-map.mjs +886 -0
- package/core/compatibility.json +16 -0
- package/core/compatibility.mjs +123 -0
- package/core/context-cache.mjs +113 -0
- package/core/context-compiler.mjs +1315 -0
- package/core/evidence-capture.mjs +347 -0
- package/core/git-utils.mjs +167 -0
- package/core/handoff.mjs +815 -0
- package/core/json-schema-lite.mjs +119 -0
- package/core/mcp-init.mjs +251 -0
- package/core/mcp-server.mjs +915 -0
- package/core/operation-approval.mjs +102 -0
- package/core/path-safety.mjs +508 -0
- package/core/project-locator.mjs +231 -0
- package/core/project-lock.mjs +438 -0
- package/core/project-status.mjs +635 -0
- package/core/project-validator.mjs +544 -0
- package/core/promotion.mjs +90 -0
- package/core/runtime-files.mjs +40 -0
- package/core/skills-history.mjs +572 -0
- package/core/skills-lifecycle.mjs +2225 -0
- package/core/skills-lint.mjs +365 -0
- package/core/skills.mjs +1449 -0
- package/core/staging-audit.mjs +454 -0
- package/core/staging-evidence.mjs +127 -0
- package/core/task-manager.mjs +1044 -0
- package/core/template-utils.mjs +190 -0
- package/core/text-utils.mjs +48 -0
- package/core/verify-task.mjs +48 -0
- package/core/worktrees.mjs +64 -0
- package/core/yaml-subset.mjs +572 -0
- package/package.json +50 -4
- package/policies/approval-boundaries.md +42 -0
- package/policies/memory-policy.md +53 -0
- package/policies/token-efficiency.md +30 -0
- package/schemas/README.md +43 -0
- package/schemas/adr.schema.json +64 -0
- package/schemas/agent-handoff.schema.json +139 -0
- package/schemas/approval-record.schema.json +110 -0
- package/schemas/conflict-record.schema.json +60 -0
- package/schemas/context-pack-manifest.schema.json +194 -0
- package/schemas/evidence-manifest.schema.json +83 -0
- package/schemas/incident-record.schema.json +53 -0
- package/schemas/project-manifest.schema.json +90 -0
- package/schemas/project-state.schema.json +64 -0
- package/schemas/recovery-checkpoint.schema.json +49 -0
- package/schemas/research-record.schema.json +76 -0
- package/schemas/task-contract.schema.json +95 -0
- package/scripts/bootstrap-project.mjs +357 -0
- package/scripts/geloforge.mjs +2512 -0
- package/templates/profiles/README.md +19 -0
- package/templates/profiles/ai-system/brain/profile.md +21 -0
- package/templates/profiles/ai-system/gitignore.append +5 -0
- package/templates/profiles/ai-system/profile.json +6 -0
- package/templates/profiles/automation/brain/profile.md +19 -0
- package/templates/profiles/automation/gitignore.append +5 -0
- package/templates/profiles/automation/profile.json +6 -0
- package/templates/profiles/desktop/brain/profile.md +21 -0
- package/templates/profiles/desktop/gitignore.append +7 -0
- package/templates/profiles/desktop/profile.json +6 -0
- package/templates/profiles/mobile/brain/profile.md +20 -0
- package/templates/profiles/mobile/gitignore.append +8 -0
- package/templates/profiles/mobile/profile.json +6 -0
- package/templates/profiles/web/brain/profile.md +21 -0
- package/templates/profiles/web/gitignore.append +6 -0
- package/templates/profiles/web/profile.json +6 -0
- package/templates/project-starter/AGENTS.md +27 -0
- package/templates/project-starter/GEMINI.md +16 -0
- package/templates/project-starter/README.md +26 -0
- package/templates/project-starter/brain/INDEX.md +40 -0
- package/templates/project-starter/brain/architecture/overview.md +30 -0
- package/templates/project-starter/brain/decisions/.gitkeep +0 -0
- package/templates/project-starter/brain/manifest.yaml +36 -0
- package/templates/project-starter/brain/requirements/constraints.md +29 -0
- package/templates/project-starter/brain/requirements/prd.md +37 -0
- package/templates/project-starter/brain/state/current.yaml +19 -0
- package/templates/project-starter/gitignore.template +25 -0
- package/templates/project-starter/src/.gitkeep +0 -0
- package/templates/project-starter/tasks/.gitkeep +0 -0
- package/templates/project-starter/tests/.gitkeep +0 -0
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inspects a GeloForge project's validation health, Second Brain operational state, and Git status.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { findBlockedAudit, readAutonomousMode } from "./autonomous-audit.mjs";
|
|
8
|
+
import { parseYaml, extractFrontmatter } from "./yaml-subset.mjs";
|
|
9
|
+
import { validateProject } from "./project-validator.mjs";
|
|
10
|
+
import { getGitStatusScoped } from "./git-utils.mjs";
|
|
11
|
+
import { resolveProjectPaths } from "./project-locator.mjs";
|
|
12
|
+
import {
|
|
13
|
+
assertSafeWithinRoot,
|
|
14
|
+
hasSecretContent,
|
|
15
|
+
isForbiddenSecretPath,
|
|
16
|
+
walkNonSymlinkFiles,
|
|
17
|
+
} from "./path-safety.mjs";
|
|
18
|
+
import { listTaskLeases, listTasks, scopesOverlap } from "./task-manager.mjs";
|
|
19
|
+
|
|
20
|
+
function inspectGitState(projectDir) {
|
|
21
|
+
const gs = getGitStatusScoped(projectDir);
|
|
22
|
+
if (!gs.available) {
|
|
23
|
+
return { available: false, branch: null, head: null, dirtyCount: 0, clean: null };
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
available: true,
|
|
27
|
+
branch: gs.branch,
|
|
28
|
+
head: gs.unborn ? "unborn" : gs.head,
|
|
29
|
+
dirtyCount: gs.dirtyCount,
|
|
30
|
+
clean: !gs.dirty,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getProjectStatus(rawProjectDir, options = {}) {
|
|
35
|
+
if (typeof rawProjectDir !== "string" || rawProjectDir.trim().length === 0) {
|
|
36
|
+
throw new Error("Missing required project path (--project <path>).");
|
|
37
|
+
}
|
|
38
|
+
const projectDir = path.resolve(rawProjectDir);
|
|
39
|
+
if (!fs.existsSync(projectDir)) {
|
|
40
|
+
throw new Error(`Project directory does not exist: ${projectDir}`);
|
|
41
|
+
}
|
|
42
|
+
const rootStat = fs.lstatSync(projectDir);
|
|
43
|
+
if (rootStat.isSymbolicLink() || !rootStat.isDirectory()) {
|
|
44
|
+
throw new Error(`Project root must be a real non-symlink directory: ${projectDir}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const validation = validateProject(projectDir, options);
|
|
48
|
+
|
|
49
|
+
let manifest = null;
|
|
50
|
+
const manifestPath = path.join(projectDir, "brain", "manifest.yaml");
|
|
51
|
+
if (fs.existsSync(manifestPath)) {
|
|
52
|
+
try {
|
|
53
|
+
manifest = parseYaml(fs.readFileSync(manifestPath, "utf8"), "brain/manifest.yaml");
|
|
54
|
+
} catch {
|
|
55
|
+
manifest = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const projectPaths = resolveProjectPaths(manifest);
|
|
60
|
+
let state = null;
|
|
61
|
+
const statePath = path.join(projectDir, projectPaths.state);
|
|
62
|
+
if (fs.existsSync(statePath)) {
|
|
63
|
+
try {
|
|
64
|
+
state = parseYaml(fs.readFileSync(statePath, "utf8"), projectPaths.state);
|
|
65
|
+
} catch {
|
|
66
|
+
state = null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const vcs = inspectGitState(projectDir);
|
|
71
|
+
const advisoryWarnings = [...validation.warnings];
|
|
72
|
+
let autonomousMode = "off";
|
|
73
|
+
let blockedAudit = null;
|
|
74
|
+
try {
|
|
75
|
+
autonomousMode = readAutonomousMode(projectDir);
|
|
76
|
+
blockedAudit = findBlockedAudit(projectDir, state?.blocked_tasks ?? []);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
advisoryWarnings.push(`Could not inspect autonomous audit state: ${err.message}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const pendingApprovalsInbox = manifest
|
|
82
|
+
? scanPendingApprovalsInbox({ projectDir, projectPaths, state, warnings: advisoryWarnings })
|
|
83
|
+
: [];
|
|
84
|
+
|
|
85
|
+
let activeLeases = [];
|
|
86
|
+
let expiredLeasesCount = 0;
|
|
87
|
+
let leaseOverlaps = [];
|
|
88
|
+
try {
|
|
89
|
+
const leaseState = listTaskLeases({ projectDir });
|
|
90
|
+
activeLeases = leaseState.activeLeases || [];
|
|
91
|
+
expiredLeasesCount = (leaseState.expiredLeases || []).length;
|
|
92
|
+
leaseOverlaps = detectLeaseOverlaps(activeLeases);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
advisoryWarnings.push(`Could not inspect active task leases: ${err.message}`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let tasks = [];
|
|
98
|
+
if (manifest) {
|
|
99
|
+
try {
|
|
100
|
+
tasks = listTasks({ projectDir }).tasks || [];
|
|
101
|
+
} catch (err) {
|
|
102
|
+
advisoryWarnings.push(`Could not inspect project tasks: ${err.message}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const recommendations = buildRecommendations({
|
|
107
|
+
validation,
|
|
108
|
+
manifest,
|
|
109
|
+
state,
|
|
110
|
+
vcs,
|
|
111
|
+
tasks,
|
|
112
|
+
pendingApprovalsInbox,
|
|
113
|
+
activeLeases,
|
|
114
|
+
leaseOverlaps,
|
|
115
|
+
blockedAudit,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const nextSteps = [];
|
|
119
|
+
if (!validation.valid) {
|
|
120
|
+
nextSteps.push('Run "geloforge validate" and fix Second Brain schema or reference errors.');
|
|
121
|
+
} else if (state) {
|
|
122
|
+
if ((state.open_conflicts || []).length > 0) {
|
|
123
|
+
nextSteps.push(
|
|
124
|
+
`Resolve ${state.open_conflicts.length} open conflict(s) (${state.open_conflicts.join(", ")}) before approving decisions.`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if ((state.blocked_tasks || []).length > 0) {
|
|
128
|
+
nextSteps.push(`Unblock task(s): ${(state.blocked_tasks || []).join(", ")}.`);
|
|
129
|
+
}
|
|
130
|
+
if ((state.active_tasks || []).length === 0) {
|
|
131
|
+
nextSteps.push('Create and activate a task: geloforge task new --title "<goal>" --activate');
|
|
132
|
+
} else if (!state.last_verified_evidence) {
|
|
133
|
+
nextSteps.push(
|
|
134
|
+
`Capture command-backed evidence: geloforge evidence capture --task ${state.active_tasks[0]} -- <test-command>`
|
|
135
|
+
);
|
|
136
|
+
} else {
|
|
137
|
+
nextSteps.push(
|
|
138
|
+
`Compile task context: geloforge context --task ${state.active_tasks[0]} --map --profile quick`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (leaseOverlaps.length > 0) {
|
|
144
|
+
nextSteps.push(`Resolve ${leaseOverlaps.length} overlapping multi-IDE lease(s): geloforge task leases`);
|
|
145
|
+
}
|
|
146
|
+
if (pendingApprovalsInbox.length > 0) {
|
|
147
|
+
nextSteps.push(
|
|
148
|
+
`Review ${pendingApprovalsInbox.length} pending human approval item(s): geloforge recommend`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
projectDir,
|
|
154
|
+
autonomousMode,
|
|
155
|
+
valid: validation.valid,
|
|
156
|
+
compatibilityStatus: validation.compatibilityStatus,
|
|
157
|
+
project: manifest
|
|
158
|
+
? {
|
|
159
|
+
id: manifest.project_id || null,
|
|
160
|
+
name: manifest.name || null,
|
|
161
|
+
slug: manifest.slug || null,
|
|
162
|
+
status: manifest.status || null,
|
|
163
|
+
profile: manifest.profile ?? null,
|
|
164
|
+
profileVersion: manifest.profile_version ?? null,
|
|
165
|
+
schemaVersion: manifest.schema_version || null,
|
|
166
|
+
}
|
|
167
|
+
: null,
|
|
168
|
+
operationalState: state
|
|
169
|
+
? {
|
|
170
|
+
currentPhase: state.current_phase || null,
|
|
171
|
+
stateRevision: state.state_revision ?? null,
|
|
172
|
+
status: state.status || null,
|
|
173
|
+
activeTasks: state.active_tasks || [],
|
|
174
|
+
blockedTasks: state.blocked_tasks || [],
|
|
175
|
+
pendingApprovals: state.pending_approvals || [],
|
|
176
|
+
openConflicts: state.open_conflicts || [],
|
|
177
|
+
lastVerifiedEvidence: state.last_verified_evidence ?? null,
|
|
178
|
+
lastCompletedTask: state.last_completed_task ?? null,
|
|
179
|
+
lastCheckpoint: state.last_checkpoint ?? null,
|
|
180
|
+
}
|
|
181
|
+
: null,
|
|
182
|
+
vcs,
|
|
183
|
+
activeLeases,
|
|
184
|
+
expiredLeasesCount,
|
|
185
|
+
leaseOverlaps,
|
|
186
|
+
pendingApprovalsInbox,
|
|
187
|
+
recommendations,
|
|
188
|
+
nextSteps,
|
|
189
|
+
counts: {
|
|
190
|
+
records: validation.recordCount,
|
|
191
|
+
markdownFiles: validation.checkedMarkdownFiles,
|
|
192
|
+
errors: validation.errors.length,
|
|
193
|
+
warnings: advisoryWarnings.length,
|
|
194
|
+
pendingApprovalsInbox: pendingApprovalsInbox.length,
|
|
195
|
+
activeLeases: activeLeases.length,
|
|
196
|
+
},
|
|
197
|
+
errors: validation.errors,
|
|
198
|
+
warnings: advisoryWarnings,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Returns structured Co-Pilot recommendations and pending human approvals for a project.
|
|
204
|
+
*/
|
|
205
|
+
export function getProjectRecommendations(projectDir) {
|
|
206
|
+
const status = getProjectStatus(projectDir);
|
|
207
|
+
return {
|
|
208
|
+
projectDir: status.projectDir,
|
|
209
|
+
autonomousMode: status.autonomousMode,
|
|
210
|
+
valid: status.valid,
|
|
211
|
+
project: status.project,
|
|
212
|
+
operationalState: status.operationalState,
|
|
213
|
+
vcs: status.vcs,
|
|
214
|
+
activeLeases: status.activeLeases,
|
|
215
|
+
leaseOverlaps: status.leaseOverlaps,
|
|
216
|
+
pendingApprovalsInbox: status.pendingApprovalsInbox,
|
|
217
|
+
recommendations: status.recommendations,
|
|
218
|
+
nextSteps: status.nextSteps,
|
|
219
|
+
warnings: status.warnings,
|
|
220
|
+
errors: status.errors,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const MAX_INBOX_FILE_BYTES = 512 * 1024;
|
|
225
|
+
const PRIORITY_ORDER = { critical: 4, high: 3, medium: 2, low: 1 };
|
|
226
|
+
|
|
227
|
+
function readSafeProjectRecordText(projectDir, relPath, warnings) {
|
|
228
|
+
const norm = relPath.replace(/\\/g, "/");
|
|
229
|
+
if (isForbiddenSecretPath(norm)) {
|
|
230
|
+
warnings.push(`Skipped forbidden secret path in status scan: ${norm}`);
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
let resolved;
|
|
234
|
+
try {
|
|
235
|
+
resolved = assertSafeWithinRoot(projectDir, norm);
|
|
236
|
+
} catch (err) {
|
|
237
|
+
warnings.push(`Blocked unsafe path "${norm}": ${err.message}`);
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
if (!fs.existsSync(resolved)) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
const stat = fs.lstatSync(resolved);
|
|
244
|
+
if (stat.isSymbolicLink() || !stat.isFile() || stat.size > MAX_INBOX_FILE_BYTES) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
const text = fs.readFileSync(resolved, "utf8");
|
|
248
|
+
if (hasSecretContent(text)) {
|
|
249
|
+
warnings.push(`Blocked record containing credential-like content: ${norm}`);
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
return text;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function scanPendingApprovalsInbox({ projectDir, projectPaths, state, warnings }) {
|
|
256
|
+
const items = [];
|
|
257
|
+
const seenKeys = new Set();
|
|
258
|
+
|
|
259
|
+
const proposalsRelDir = String(projectPaths.proposals_dir || "proposals").replace(/\\/g, "/");
|
|
260
|
+
const decisionsRelDir = String(projectPaths.decisions_dir || "brain/decisions").replace(/\\/g, "/");
|
|
261
|
+
|
|
262
|
+
// 1. Skill proposals under <proposals_dir>/skills/.proposals/*.yaml
|
|
263
|
+
const skillPropsDir = path.join(projectDir, proposalsRelDir, "skills", ".proposals");
|
|
264
|
+
for (const absFile of walkNonSymlinkFiles(projectDir, skillPropsDir, (p) => /\.ya?ml$/i.test(p), warnings)) {
|
|
265
|
+
const rel = path.relative(projectDir, absFile).replace(/\\/g, "/");
|
|
266
|
+
const raw = readSafeProjectRecordText(projectDir, rel, warnings);
|
|
267
|
+
if (!raw) continue;
|
|
268
|
+
try {
|
|
269
|
+
const data = parseYaml(raw, rel);
|
|
270
|
+
const statusVal = String(data?.status || "draft").toLowerCase();
|
|
271
|
+
if (!data || data.is_example === true) continue;
|
|
272
|
+
if (!["draft", "pending", "proposed", "pending_approval"].includes(statusVal)) continue;
|
|
273
|
+
const skillName = String(data.skill_name || path.basename(rel, path.extname(rel)));
|
|
274
|
+
const kind = data.kind === "skill_update" ? "skill_update" : "skill_draft";
|
|
275
|
+
const key = `${kind}:${skillName}`;
|
|
276
|
+
if (seenKeys.has(key)) continue;
|
|
277
|
+
seenKeys.add(key);
|
|
278
|
+
items.push({
|
|
279
|
+
kind,
|
|
280
|
+
id: skillName,
|
|
281
|
+
title: `${kind === "skill_update" ? "Skill update" : "Skill draft"}: ${skillName}`,
|
|
282
|
+
status: statusVal,
|
|
283
|
+
path: rel,
|
|
284
|
+
requestedBy: data.created_by || null,
|
|
285
|
+
createdAt: data.created_at || null,
|
|
286
|
+
summary: data.reason || null,
|
|
287
|
+
approveHint: `Review ${proposalsRelDir}/skills/${skillName}/SKILL.md, sign APPR via "geloforge skills sign", then run "geloforge skills promote --skill ${skillName} --approval APPR-NNNN".`,
|
|
288
|
+
});
|
|
289
|
+
} catch (err) {
|
|
290
|
+
warnings.push(`Could not parse skill proposal ${rel}: ${err.message}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// 2. APPR-*.yaml records under <proposals_dir>
|
|
295
|
+
const apprSeenIds = new Set();
|
|
296
|
+
const proposalsAbs = path.join(projectDir, proposalsRelDir);
|
|
297
|
+
for (const absFile of walkNonSymlinkFiles(
|
|
298
|
+
projectDir,
|
|
299
|
+
proposalsAbs,
|
|
300
|
+
(p) => /^APPR-\d{4}.*\.ya?ml$/i.test(path.basename(p)),
|
|
301
|
+
warnings
|
|
302
|
+
)) {
|
|
303
|
+
const rel = path.relative(projectDir, absFile).replace(/\\/g, "/");
|
|
304
|
+
const raw = readSafeProjectRecordText(projectDir, rel, warnings);
|
|
305
|
+
if (!raw) continue;
|
|
306
|
+
try {
|
|
307
|
+
const data = parseYaml(raw, rel);
|
|
308
|
+
if (!data || data.is_example === true || typeof data.id !== "string") continue;
|
|
309
|
+
const statusVal = String(data.status || "").toLowerCase();
|
|
310
|
+
const listedPending = Array.isArray(state?.pending_approvals) && state.pending_approvals.includes(data.id);
|
|
311
|
+
if (!listedPending && !["pending", "proposed", "requested", "draft"].includes(statusVal)) continue;
|
|
312
|
+
apprSeenIds.add(data.id);
|
|
313
|
+
const key = `approval_record:${data.id}`;
|
|
314
|
+
if (seenKeys.has(key)) continue;
|
|
315
|
+
seenKeys.add(key);
|
|
316
|
+
items.push({
|
|
317
|
+
kind: "approval_record",
|
|
318
|
+
id: data.id,
|
|
319
|
+
title: data.title || data.summary || data.boundary_category || data.action_category || data.id,
|
|
320
|
+
status: statusVal || "pending",
|
|
321
|
+
path: rel,
|
|
322
|
+
requestedBy: data.requested_by || null,
|
|
323
|
+
createdAt: data.requested_at || data.created_at || null,
|
|
324
|
+
summary: data.rationale || (data.boundary_category ? `category=${data.boundary_category}` : null),
|
|
325
|
+
approveHint: `Inspect ${rel}; owner must review and mark approved (or promote skill if skill-related).`,
|
|
326
|
+
});
|
|
327
|
+
} catch (err) {
|
|
328
|
+
warnings.push(`Could not parse approval record ${rel}: ${err.message}`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// 3. Pending ADR-*.md proposals under <decisions_dir> and <proposals_dir>
|
|
333
|
+
for (const dirRel of Array.from(new Set([decisionsRelDir, proposalsRelDir]))) {
|
|
334
|
+
const absDir = path.join(projectDir, dirRel);
|
|
335
|
+
for (const absFile of walkNonSymlinkFiles(
|
|
336
|
+
projectDir,
|
|
337
|
+
absDir,
|
|
338
|
+
(p) => /^ADR-\d{4}.*\.md$/i.test(path.basename(p)),
|
|
339
|
+
warnings
|
|
340
|
+
)) {
|
|
341
|
+
const rel = path.relative(projectDir, absFile).replace(/\\/g, "/");
|
|
342
|
+
const raw = readSafeProjectRecordText(projectDir, rel, warnings);
|
|
343
|
+
if (!raw) continue;
|
|
344
|
+
try {
|
|
345
|
+
const fm = extractFrontmatter(raw, rel);
|
|
346
|
+
if (!fm || fm.is_example === true) continue;
|
|
347
|
+
const statusVal = String(fm.status || "").toLowerCase();
|
|
348
|
+
if (!["proposed", "draft", "pending", "under_review"].includes(statusVal)) continue;
|
|
349
|
+
const adrId = String(fm.id || path.basename(rel, ".md"));
|
|
350
|
+
const key = `adr_proposal:${adrId}:${rel}`;
|
|
351
|
+
if (seenKeys.has(key)) continue;
|
|
352
|
+
seenKeys.add(key);
|
|
353
|
+
items.push({
|
|
354
|
+
kind: "adr_proposal",
|
|
355
|
+
id: adrId,
|
|
356
|
+
title: fm.title || adrId,
|
|
357
|
+
status: statusVal,
|
|
358
|
+
path: rel,
|
|
359
|
+
requestedBy: fm.owner || fm.proposed_by || fm.author || null,
|
|
360
|
+
createdAt: fm.updated_at || fm.created_at || fm.date || null,
|
|
361
|
+
summary: Array.isArray(fm.tags) && fm.tags.length > 0 ? `tags=${fm.tags.join(",")}` : fm.decision_summary || null,
|
|
362
|
+
approveHint: `Review architectural trade-offs in ${rel} and record human decision before updating ADR status.`,
|
|
363
|
+
});
|
|
364
|
+
} catch (err) {
|
|
365
|
+
warnings.push(`Could not parse ADR frontmatter ${rel}: ${err.message}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// 4. State pending_approvals entries not already represented above
|
|
371
|
+
for (const apprId of state?.pending_approvals || []) {
|
|
372
|
+
if (apprSeenIds.has(apprId)) continue;
|
|
373
|
+
const key = `state_approval:${apprId}`;
|
|
374
|
+
if (seenKeys.has(key)) continue;
|
|
375
|
+
seenKeys.add(key);
|
|
376
|
+
items.push({
|
|
377
|
+
kind: "state_approval",
|
|
378
|
+
id: apprId,
|
|
379
|
+
title: `Pending state approval: ${apprId}`,
|
|
380
|
+
status: "pending",
|
|
381
|
+
path: null,
|
|
382
|
+
requestedBy: null,
|
|
383
|
+
createdAt: null,
|
|
384
|
+
summary: "Listed in state.pending_approvals",
|
|
385
|
+
approveHint: `Review ${apprId} and resolve state.pending_approvals.`,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
items.sort((a, b) => {
|
|
390
|
+
const kCmp = String(a.kind).localeCompare(String(b.kind));
|
|
391
|
+
if (kCmp !== 0) return kCmp;
|
|
392
|
+
const idCmp = String(a.id).localeCompare(String(b.id));
|
|
393
|
+
if (idCmp !== 0) return idCmp;
|
|
394
|
+
return String(a.path || "").localeCompare(String(b.path || ""));
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
return items;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function detectLeaseOverlaps(activeLeases) {
|
|
401
|
+
const overlaps = [];
|
|
402
|
+
for (let i = 0; i < activeLeases.length; i += 1) {
|
|
403
|
+
for (let j = i + 1; j < activeLeases.length; j += 1) {
|
|
404
|
+
const a = activeLeases[i];
|
|
405
|
+
const b = activeLeases[j];
|
|
406
|
+
const sameTask = a.task_id === b.task_id;
|
|
407
|
+
const scopeHit = (a.claimed_scope || []).some((s1) =>
|
|
408
|
+
(b.claimed_scope || []).some((s2) => scopesOverlap(s1, s2))
|
|
409
|
+
);
|
|
410
|
+
if (sameTask || scopeHit) {
|
|
411
|
+
overlaps.push({
|
|
412
|
+
leaseA: { task_id: a.task_id, role: a.role, tool: a.tool, session_id: a.session_id },
|
|
413
|
+
leaseB: { task_id: b.task_id, role: b.role, tool: b.tool, session_id: b.session_id },
|
|
414
|
+
sameTask,
|
|
415
|
+
scopeOverlap: scopeHit,
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return overlaps;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function buildRecommendations({
|
|
424
|
+
validation,
|
|
425
|
+
state,
|
|
426
|
+
vcs,
|
|
427
|
+
tasks,
|
|
428
|
+
pendingApprovalsInbox,
|
|
429
|
+
activeLeases,
|
|
430
|
+
leaseOverlaps,
|
|
431
|
+
blockedAudit,
|
|
432
|
+
}) {
|
|
433
|
+
const recs = [];
|
|
434
|
+
|
|
435
|
+
if (!validation.valid) {
|
|
436
|
+
recs.push({
|
|
437
|
+
rank: 100,
|
|
438
|
+
priority: "critical",
|
|
439
|
+
category: "validation",
|
|
440
|
+
title: `Fix ${validation.errors.length} Second Brain validation error(s)`,
|
|
441
|
+
reason: "Schema, ID reference, or safety validation failed; AI agents should not trust invalid state.",
|
|
442
|
+
options: ["Inspect errors with validate --json and repair referenced records"],
|
|
443
|
+
command: "geloforge validate",
|
|
444
|
+
requiresHumanApproval: false,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (leaseOverlaps.length > 0) {
|
|
449
|
+
recs.push({
|
|
450
|
+
rank: 95,
|
|
451
|
+
priority: "high",
|
|
452
|
+
category: "coordination",
|
|
453
|
+
title: `Resolve ${leaseOverlaps.length} overlapping multi-IDE task/file-scope lease(s)`,
|
|
454
|
+
reason: "Two concurrent IDE sessions claimed the same task or overlapping file paths.",
|
|
455
|
+
options: [
|
|
456
|
+
"Release stale/duplicate lease via geloforge task release",
|
|
457
|
+
"Narrow file scopes into disjoint modules or separate Git worktrees",
|
|
458
|
+
],
|
|
459
|
+
command: "geloforge task leases",
|
|
460
|
+
requiresHumanApproval: true,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (state && (state.open_conflicts || []).length > 0) {
|
|
465
|
+
recs.push({
|
|
466
|
+
rank: 90,
|
|
467
|
+
priority: "high",
|
|
468
|
+
category: "conflict",
|
|
469
|
+
title: `Resolve ${state.open_conflicts.length} open conflict(s): ${state.open_conflicts.join(", ")}`,
|
|
470
|
+
reason: "Unresolved CONF-* contradictions block authoritative decisions and require human arbitration.",
|
|
471
|
+
options: [
|
|
472
|
+
"Accept newer verified evidence and supersede older decision via ADR",
|
|
473
|
+
"Reject conflicting proposal and document rationale in CONF record",
|
|
474
|
+
],
|
|
475
|
+
command: `geloforge recommend`,
|
|
476
|
+
requiresHumanApproval: true,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (pendingApprovalsInbox.length > 0) {
|
|
481
|
+
const first = pendingApprovalsInbox[0];
|
|
482
|
+
recs.push({
|
|
483
|
+
rank: 85,
|
|
484
|
+
priority: "high",
|
|
485
|
+
category: "approval_inbox",
|
|
486
|
+
title: `Review ${pendingApprovalsInbox.length} pending human approval item(s)`,
|
|
487
|
+
reason: `Human authorization pending for: ${pendingApprovalsInbox.map((i) => `${i.kind}:${i.id}`).slice(0, 4).join(", ")}.`,
|
|
488
|
+
options: [
|
|
489
|
+
"Inspect diff/evidence and sign/approve with human authorization",
|
|
490
|
+
"Reject or request narrower scope before promotion",
|
|
491
|
+
],
|
|
492
|
+
command: first.approveHint,
|
|
493
|
+
requiresHumanApproval: true,
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (state && (state.blocked_tasks || []).length > 0) {
|
|
498
|
+
recs.push({
|
|
499
|
+
rank: 80,
|
|
500
|
+
priority: "high",
|
|
501
|
+
category: "blocked_task",
|
|
502
|
+
title: `Unblock ${state.blocked_tasks.length} blocked task(s): ${state.blocked_tasks.join(", ")}`,
|
|
503
|
+
reason: "Work cannot advance on blocked tasks without human decision or dependency completion.",
|
|
504
|
+
options: [
|
|
505
|
+
"Resolve blocker and move task back to ready/active via geloforge task update",
|
|
506
|
+
"Pause/cancel obsolete task via geloforge task update --status cancelled",
|
|
507
|
+
],
|
|
508
|
+
command: `geloforge task show --task ${state.blocked_tasks[0]}`,
|
|
509
|
+
requiresHumanApproval: true,
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (blockedAudit) {
|
|
514
|
+
recs.push({
|
|
515
|
+
rank: 81,
|
|
516
|
+
priority: "high",
|
|
517
|
+
category: "autonomous_audit",
|
|
518
|
+
title: `Review the blocked staging audit in ${blockedAudit.id}`,
|
|
519
|
+
reason: blockedAudit.resume_instructions,
|
|
520
|
+
options: ["Inspect the checkpoint and verify the missing or mismatched evidence"],
|
|
521
|
+
command: `geloforge checkpoint show --id ${blockedAudit.id}`,
|
|
522
|
+
requiresHumanApproval: false,
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if (state) {
|
|
527
|
+
const activeIds = state.active_tasks || [];
|
|
528
|
+
if (activeIds.length === 0) {
|
|
529
|
+
const candidate = tasks
|
|
530
|
+
.filter((t) => !t.is_example && (t.status === "ready" || t.status === "inbox" || t.status === "in_review"))
|
|
531
|
+
.sort((a, b) => (PRIORITY_ORDER[b.priority] || 0) - (PRIORITY_ORDER[a.priority] || 0))[0];
|
|
532
|
+
|
|
533
|
+
if (candidate) {
|
|
534
|
+
recs.push({
|
|
535
|
+
rank: 72,
|
|
536
|
+
priority: "medium",
|
|
537
|
+
category: "task_activation",
|
|
538
|
+
title: `Activate next ${candidate.priority}-priority task: ${candidate.id} (${candidate.title})`,
|
|
539
|
+
reason: "No task is currently active in project state, while queued non-example task contracts exist.",
|
|
540
|
+
options: [
|
|
541
|
+
`Activate ${candidate.id} and compile focused context`,
|
|
542
|
+
"Create a new scoped task if priorities changed",
|
|
543
|
+
],
|
|
544
|
+
command: `geloforge task update --task ${candidate.id} --status active --activate`,
|
|
545
|
+
requiresHumanApproval: false,
|
|
546
|
+
});
|
|
547
|
+
} else {
|
|
548
|
+
recs.push({
|
|
549
|
+
rank: 70,
|
|
550
|
+
priority: "medium",
|
|
551
|
+
category: "task_creation",
|
|
552
|
+
title: "Create and activate a scoped task contract",
|
|
553
|
+
reason: "No active or queued tasks exist; defining a task enables tight token budgets and evidence tracking.",
|
|
554
|
+
options: ["Define task objective + acceptance criteria before editing"],
|
|
555
|
+
command: 'geloforge task new --title "<goal>" --activate',
|
|
556
|
+
requiresHumanApproval: false,
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
} else {
|
|
560
|
+
const primaryTaskId = activeIds[0];
|
|
561
|
+
const primaryTask = tasks.find((t) => t.id === primaryTaskId);
|
|
562
|
+
|
|
563
|
+
if (vcs.available && vcs.dirtyCount > 0 && !state.last_checkpoint) {
|
|
564
|
+
recs.push({
|
|
565
|
+
rank: 76,
|
|
566
|
+
priority: "medium",
|
|
567
|
+
category: "checkpoint",
|
|
568
|
+
title: `Create a recovery checkpoint before context grows (${vcs.dirtyCount} uncommitted change(s))`,
|
|
569
|
+
reason: "Mid-session checkpoints preserve verified state and resume instructions so fresh sessions avoid context rot.",
|
|
570
|
+
options: ["Save CHKPT-NNNN now and continue or start a fresh context window"],
|
|
571
|
+
command: `geloforge checkpoint create --summary "Progress on ${primaryTaskId}"`,
|
|
572
|
+
requiresHumanApproval: false,
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (!state.last_verified_evidence || (primaryTask && primaryTask.evidenceCount === 0)) {
|
|
577
|
+
recs.push({
|
|
578
|
+
rank: 74,
|
|
579
|
+
priority: "medium",
|
|
580
|
+
category: "verification",
|
|
581
|
+
title: `Capture command-backed verification evidence for ${primaryTaskId}`,
|
|
582
|
+
reason: "Verified EVID-* records separate real passing checks from unverified agent claims.",
|
|
583
|
+
options: ["Run project test suite via evidence capture (shell: false)"],
|
|
584
|
+
command: `geloforge evidence capture --task ${primaryTaskId} -- <test-command>`,
|
|
585
|
+
requiresHumanApproval: false,
|
|
586
|
+
});
|
|
587
|
+
} else {
|
|
588
|
+
recs.push({
|
|
589
|
+
rank: 68,
|
|
590
|
+
priority: "medium",
|
|
591
|
+
category: "task_closure",
|
|
592
|
+
title: `Review ${primaryTaskId} completion readiness or extract reusable skill`,
|
|
593
|
+
reason: `${primaryTaskId} has ${primaryTask?.evidenceCount || 1} linked evidence record(s).`,
|
|
594
|
+
options: [
|
|
595
|
+
`Mark task completed: geloforge task done --task ${primaryTaskId}`,
|
|
596
|
+
`Draft quarantined skill from verified work: geloforge skills draft --task ${primaryTaskId}`,
|
|
597
|
+
],
|
|
598
|
+
command: `geloforge task done --task ${primaryTaskId}`,
|
|
599
|
+
requiresHumanApproval: true,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
recs.push({
|
|
604
|
+
rank: 60,
|
|
605
|
+
priority: "low",
|
|
606
|
+
category: "context_efficiency",
|
|
607
|
+
title: `Compile diff-focused quick context for ${primaryTaskId}`,
|
|
608
|
+
reason: "Keeps token consumption bounded (~4000 tokens) and highlights peer IDE leases.",
|
|
609
|
+
options: ["Compile quick diff packet (completed tasks pruned automatically)"],
|
|
610
|
+
command: `geloforge context --task ${primaryTaskId} --from-diff --map --profile quick`,
|
|
611
|
+
requiresHumanApproval: false,
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (activeLeases.length === 0 && state && (state.active_tasks || []).length > 0 && vcs.available && vcs.dirtyCount > 0) {
|
|
617
|
+
recs.push({
|
|
618
|
+
rank: 50,
|
|
619
|
+
priority: "low",
|
|
620
|
+
category: "multi_ide_coordination",
|
|
621
|
+
title: `Claim a cooperative task lease for ${state.active_tasks[0]} when using multiple IDEs`,
|
|
622
|
+
reason: "Active workspace edits exist with no active lease; leases warn peer IDE agents before scope collisions.",
|
|
623
|
+
options: ["Register your IDE tool, role, and owned paths with TTL"],
|
|
624
|
+
command: `geloforge task claim --task ${state.active_tasks[0]} --tool <ide> --role developer --scopes "<paths>"`,
|
|
625
|
+
requiresHumanApproval: false,
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
recs.sort((a, b) => {
|
|
630
|
+
if (b.rank !== a.rank) return b.rank - a.rank;
|
|
631
|
+
return String(a.title).localeCompare(String(b.title));
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
return recs;
|
|
635
|
+
}
|