geloforge 0.7.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.
@@ -20,6 +20,11 @@ import { assertSafeWithinRoot, atomicWriteFile } from "./path-safety.mjs";
20
20
 
21
21
  const ACTIVE_LOCKS = new Set();
22
22
  const SLEEP_VIEW = new Int32Array(new SharedArrayBuffer(4));
23
+ const TRANSIENT_LOCK_FS_CODES = new Set(["EPERM", "EACCES", "EBUSY"]);
24
+
25
+ function isTransientLockFsError(err) {
26
+ return Boolean(err && TRANSIENT_LOCK_FS_CODES.has(err.code));
27
+ }
23
28
 
24
29
  function sleepSyncMs(ms) {
25
30
  if (!Number.isFinite(ms) || ms <= 0) return;
@@ -84,16 +89,24 @@ function isExpectedSameLock(currentMeta, expectedMeta) {
84
89
  }
85
90
 
86
91
  function releaseLockSafe(lockAbs, token) {
87
- try {
88
- if (!fs.existsSync(lockAbs)) return;
89
- const st = fs.lstatSync(lockAbs);
90
- if (st.isSymbolicLink() || !st.isFile()) return;
91
- const parsed = JSON.parse(fs.readFileSync(lockAbs, "utf8"));
92
- if (parsed && parsed.token === token) {
93
- fs.unlinkSync(lockAbs);
92
+ for (let attempt = 0; attempt < 5; attempt += 1) {
93
+ try {
94
+ if (!fs.existsSync(lockAbs)) return;
95
+ const st = fs.lstatSync(lockAbs);
96
+ if (st.isSymbolicLink() || !st.isFile()) return;
97
+ const parsed = JSON.parse(fs.readFileSync(lockAbs, "utf8"));
98
+ if (parsed && parsed.token === token) {
99
+ fs.unlinkSync(lockAbs);
100
+ }
101
+ return;
102
+ } catch (err) {
103
+ if (isTransientLockFsError(err) && attempt < 4) {
104
+ sleepSyncMs(10);
105
+ continue;
106
+ }
107
+ // Do not unlink lock owned by another process or already removed
108
+ return;
94
109
  }
95
- } catch {
96
- // Do not unlink lock owned by another process or already removed
97
110
  }
98
111
  }
99
112
 
@@ -114,7 +127,7 @@ function acquireReclaimGuard(reclaimAbs, staleLockMs) {
114
127
  }
115
128
  return guardToken;
116
129
  } catch (err) {
117
- if (!err || (err.code !== "EEXIST" && err.code !== "EPERM")) {
130
+ if (!err || (err.code !== "EEXIST" && !isTransientLockFsError(err))) {
118
131
  throw err;
119
132
  }
120
133
  // Check if an abandoned reclaim guard was left by a dead process
@@ -148,7 +161,7 @@ function tryReclaimStaleLock(lockAbs, expectedMeta, staleLockMs) {
148
161
  try {
149
162
  currentMeta = parseLockMeta(lockAbs);
150
163
  } catch (err) {
151
- if (err && err.code === "ENOENT") {
164
+ if (err && (err.code === "ENOENT" || isTransientLockFsError(err))) {
152
165
  return false;
153
166
  }
154
167
  throw err;
@@ -163,7 +176,7 @@ function tryReclaimStaleLock(lockAbs, expectedMeta, staleLockMs) {
163
176
  try {
164
177
  fs.renameSync(lockAbs, staleTmp);
165
178
  } catch (err) {
166
- if (err && (err.code === "ENOENT" || err.code === "EPERM" || err.code === "EACCES" || err.code === "EBUSY")) {
179
+ if (err && (err.code === "ENOENT" || isTransientLockFsError(err))) {
167
180
  return false;
168
181
  }
169
182
  throw err;
@@ -224,6 +237,20 @@ export function recoverPendingTransactionJournal(projectDir) {
224
237
  return { recovered: true, restoredFiles };
225
238
  }
226
239
 
240
+ function resolveSafeLockPath(resolvedDir, relPath, timeoutMs, delayMs, startMs) {
241
+ while (true) {
242
+ try {
243
+ return assertSafeWithinRoot(resolvedDir, relPath);
244
+ } catch (err) {
245
+ const elapsed = Date.now() - startMs;
246
+ if (!isTransientLockFsError(err) || elapsed >= timeoutMs) {
247
+ throw err;
248
+ }
249
+ sleepSyncMs(Math.min(delayMs, timeoutMs - elapsed));
250
+ }
251
+ }
252
+ }
253
+
227
254
  /**
228
255
  * Executes `fn` while holding an exclusive atomic lockfile at `<projectDir>/.geloforge/.state.lock`.
229
256
  */
@@ -266,9 +293,9 @@ export function withProjectLock(
266
293
  fs.mkdirSync(gfDirAbs, { recursive: true });
267
294
  }
268
295
 
269
- const lockAbs = assertSafeWithinRoot(resolvedDir, ".geloforge/.state.lock");
270
- const token = crypto.randomBytes(12).toString("hex");
271
296
  const startMs = Date.now();
297
+ const lockAbs = resolveSafeLockPath(resolvedDir, ".geloforge/.state.lock", timeout, delay, startMs);
298
+ const token = crypto.randomBytes(12).toString("hex");
272
299
 
273
300
  let acquired = false;
274
301
  while (!acquired) {
@@ -288,23 +315,28 @@ export function withProjectLock(
288
315
  }
289
316
  acquired = true;
290
317
  } catch (err) {
291
- if (!err || (err.code !== "EEXIST" && err.code !== "EPERM")) {
318
+ if (!err || (err.code !== "EEXIST" && !isTransientLockFsError(err))) {
292
319
  throw err;
293
320
  }
294
321
 
295
322
  // Inspect existing lock (if present) for staleness or symlink violation
296
323
  let metaInfo = null;
324
+ let transientInspectError = false;
297
325
  try {
298
326
  metaInfo = parseLockMeta(lockAbs);
299
327
  } catch (inspectErr) {
300
328
  if (inspectErr && inspectErr.code === "ENOENT") {
301
329
  continue;
302
330
  }
303
- throw inspectErr;
331
+ if (isTransientLockFsError(inspectErr)) {
332
+ transientInspectError = true;
333
+ } else {
334
+ throw inspectErr;
335
+ }
304
336
  }
305
337
 
306
338
  const nowMs = Date.now();
307
- if (isLockStale(metaInfo, staleMs, nowMs)) {
339
+ if (!transientInspectError && isLockStale(metaInfo, staleMs, nowMs)) {
308
340
  if (tryReclaimStaleLock(lockAbs, metaInfo, staleMs)) {
309
341
  continue;
310
342
  }
@@ -16,6 +16,7 @@ import {
16
16
  walkNonSymlinkFiles,
17
17
  } from "./path-safety.mjs";
18
18
  import { listTaskLeases, listTasks, scopesOverlap } from "./task-manager.mjs";
19
+ import { suggestProjectSkills } from "./skills-advisor.mjs";
19
20
 
20
21
  function inspectGitState(projectDir) {
21
22
  const gs = getGitStatusScoped(projectDir);
@@ -626,6 +627,47 @@ function buildRecommendations({
626
627
  });
627
628
  }
628
629
 
630
+ try {
631
+ if (state && ((state.active_tasks || []).length > 0 || state.last_verified_evidence)) {
632
+ const advisor = suggestProjectSkills({
633
+ projectDir,
634
+ harnessDir,
635
+ taskId: (state.active_tasks || [])[0] || null,
636
+ limit: 3,
637
+ scaffoldDraft: false,
638
+ });
639
+ if (advisor.recommendedSkills.length > 0) {
640
+ const top = advisor.recommendedSkills[0];
641
+ recs.push({
642
+ rank: 56,
643
+ priority: "low",
644
+ category: "skills",
645
+ title: `Load matching skill "${top.name}" for current project/task context`,
646
+ reason: top.reasons.join("; ") || "Relevant active skill matched current project signals.",
647
+ options: [`Compile focused context with ${top.name}`],
648
+ command: `geloforge context ${advisor.taskId ? `--task ${advisor.taskId} ` : ""}--skills --skill ${top.name}`,
649
+ requiresHumanApproval: false,
650
+ });
651
+ } else {
652
+ const evGap = advisor.skillGaps.find((g) => g.kind === "evidence_backed_workflow" && !g.existingQuarantinedDraft);
653
+ if (evGap) {
654
+ recs.push({
655
+ rank: 54,
656
+ priority: "low",
657
+ category: "skills",
658
+ title: `Scaffold quarantined skill draft "${evGap.suggestedName}" from verified evidence`,
659
+ reason: evGap.reason,
660
+ options: ["Stage quarantined draft in proposals/skills/ for human review"],
661
+ command: `geloforge skills suggest --scaffold-draft`,
662
+ requiresHumanApproval: false,
663
+ });
664
+ }
665
+ }
666
+ }
667
+ } catch {
668
+ // Non-fatal advisory check
669
+ }
670
+
629
671
  recs.sort((a, b) => {
630
672
  if (b.rank !== a.rank) return b.rank - a.rank;
631
673
  return String(a.title).localeCompare(String(b.title));