Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

graduation(G3): STUB engine-graduation.ts + graduation-custody.ts (drop in favour of G2a at integration)

garrytanb0ea27ea33eb
diff --git a/src/core/persistence/engine-graduation.ts b/src/core/persistence/engine-graduation.ts
new file mode 100644
index 0000000000..fe224a961a
--- /dev/null
+++ b/src/core/persistence/engine-graduation.ts
@@ -0,0 +1,19 @@
+/**
+ * STUB (G3 CLI lane). The G2a lane owns this module; the integrator replaces
+ * this file with G2a's implementation. Signatures follow GRADUATION_LANES.md
+ * and the CLI <-> orchestrator types in engine-graduation.types.ts.
+ */
+import type {
+ GraduationCommandOptions, GraduationPlan, GraduationReceipt, GraduationRollbackResult, GraduationStatusDoc,
+} from './engine-graduation.types.ts';
+
+function notMerged(name: string): never {
+ throw new Error(`${name}: the engine graduation orchestrator (G2a) is not merged into this build.`);
+}
+
+export async function planGraduation(_opts: GraduationCommandOptions): Promise<GraduationPlan> { return notMerged('planGraduation'); }
+export async function runGraduation(_opts: GraduationCommandOptions): Promise<GraduationReceipt> { return notMerged('runGraduation'); }
+export async function graduationStatus(): Promise<GraduationStatusDoc> { return notMerged('graduationStatus'); }
+export async function resumeGraduation(_opts: GraduationCommandOptions): Promise<GraduationReceipt> { return notMerged('resumeGraduation'); }
+export async function rollbackGraduation(_opts: GraduationCommandOptions): Promise<GraduationRollbackResult> { return notMerged('rollbackGraduation'); }
+export async function reconcileGraduation(): Promise<void> { return notMerged('reconcileGraduation'); }
diff --git a/src/core/persistence/graduation-custody.ts b/src/core/persistence/graduation-custody.ts
new file mode 100644
index 0000000000..3d76b07f65
--- /dev/null
+++ b/src/core/persistence/graduation-custody.ts
@@ -0,0 +1,43 @@
+/**
+ * STUB (G3 CLI lane). The G2a lane owns this module; the integrator replaces
+ * this file with G2a's implementation. Only `inspectGraduationPath` is
+ * stubbed (file reads per the plan's marker and tombstone formats) so the
+ * CLI, serve and doctor consumers can be exercised before G2a merges.
+ */
+import { readFileSync, statSync } from 'node:fs';
+import type { GraduationPathState, IntentMarker, Tombstone } from './engine-graduation.types.ts';
+
+export function intentMarkerPath(dataDir: string): string {
+ return `${dataDir}.gbrain-graduation.json`;
+}
+
+function readJson<T>(path: string): T | null {
+ try { return JSON.parse(readFileSync(path, 'utf8')) as T; } catch { return null; }
+}
+
+function pidAlive(pid: number): boolean {
+ try { process.kill(pid, 0); return true; } catch (e) { return (e as NodeJS.ErrnoException).code === 'EPERM'; }
+}
+
+export function readIntentMarker(dataDir: string): IntentMarker | null {
+ return readJson<IntentMarker>(intentMarkerPath(dataDir));
+}
+
+export function readTombstone(dataDir: string): Tombstone | null {
+ try {
+ if (!statSync(dataDir).isFile()) return null;
+ } catch {
+ return null;
+ }
+ const t = readJson<Tombstone>(dataDir);
+ return t?.kind === 'gbrain-engine-graduated' ? t : null;
+}
+
+export function inspectGraduationPath(dataDir: string): GraduationPathState {
+ const marker = readIntentMarker(dataDir);
+ const tombstone = readTombstone(dataDir);
+ if (tombstone) return { dataDir, state: 'graduated', marker, tombstone };
+ if (!marker) return { dataDir, state: 'none', marker, tombstone };
+ if (marker.state === 'graduated' || marker.state === 'rolled_back' || marker.state === 'abandoned') return { dataDir, state: 'none', marker, tombstone };
+ return { dataDir, state: pidAlive(marker.pid) ? 'in_progress' : 'interrupted', marker, tombstone };
+}