mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
feat: add runtime debug snapshots and injection planning
This commit is contained in:
94
runtime-debug.js
Normal file
94
runtime-debug.js
Normal file
@@ -0,0 +1,94 @@
|
||||
function safeClone(value, fallback = null) {
|
||||
if (value == null) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof structuredClone === "function") {
|
||||
return structuredClone(value);
|
||||
}
|
||||
} catch {
|
||||
// ignore and fall through
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(JSON.stringify(value));
|
||||
} catch {
|
||||
return fallback ?? value;
|
||||
}
|
||||
}
|
||||
|
||||
function nowIso() {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
const runtimeDebugState = {
|
||||
hostCapabilities: null,
|
||||
taskPromptBuilds: {},
|
||||
taskLlmRequests: {},
|
||||
injections: {},
|
||||
updatedAt: "",
|
||||
};
|
||||
|
||||
function touchRuntimeDebugState() {
|
||||
runtimeDebugState.updatedAt = nowIso();
|
||||
}
|
||||
|
||||
export function resetRuntimeDebugSnapshot() {
|
||||
runtimeDebugState.hostCapabilities = null;
|
||||
runtimeDebugState.taskPromptBuilds = {};
|
||||
runtimeDebugState.taskLlmRequests = {};
|
||||
runtimeDebugState.injections = {};
|
||||
runtimeDebugState.updatedAt = nowIso();
|
||||
}
|
||||
|
||||
export function recordHostCapabilitySnapshot(snapshot = null) {
|
||||
runtimeDebugState.hostCapabilities = safeClone(snapshot, null);
|
||||
touchRuntimeDebugState();
|
||||
}
|
||||
|
||||
export function recordTaskPromptBuild(taskType, snapshot = {}) {
|
||||
const normalizedTaskType = String(taskType || "").trim() || "unknown";
|
||||
runtimeDebugState.taskPromptBuilds[normalizedTaskType] = {
|
||||
updatedAt: nowIso(),
|
||||
...safeClone(snapshot, {}),
|
||||
};
|
||||
touchRuntimeDebugState();
|
||||
}
|
||||
|
||||
export function recordTaskLlmRequest(taskType, snapshot = {}) {
|
||||
const normalizedTaskType = String(taskType || "").trim() || "unknown";
|
||||
runtimeDebugState.taskLlmRequests[normalizedTaskType] = {
|
||||
updatedAt: nowIso(),
|
||||
...safeClone(snapshot, {}),
|
||||
};
|
||||
touchRuntimeDebugState();
|
||||
}
|
||||
|
||||
export function recordInjectionSnapshot(kind, snapshot = {}) {
|
||||
const normalizedKind = String(kind || "").trim() || "default";
|
||||
runtimeDebugState.injections[normalizedKind] = {
|
||||
updatedAt: nowIso(),
|
||||
...safeClone(snapshot, {}),
|
||||
};
|
||||
touchRuntimeDebugState();
|
||||
}
|
||||
|
||||
export function getRuntimeDebugSnapshot() {
|
||||
return safeClone(
|
||||
{
|
||||
hostCapabilities: runtimeDebugState.hostCapabilities,
|
||||
taskPromptBuilds: runtimeDebugState.taskPromptBuilds,
|
||||
taskLlmRequests: runtimeDebugState.taskLlmRequests,
|
||||
injections: runtimeDebugState.injections,
|
||||
updatedAt: runtimeDebugState.updatedAt,
|
||||
},
|
||||
{
|
||||
hostCapabilities: null,
|
||||
taskPromptBuilds: {},
|
||||
taskLlmRequests: {},
|
||||
injections: {},
|
||||
updatedAt: "",
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user