feat(controller): observe the bounded Linux execution substrate
This commit is contained in:
parent
098a29e417
commit
3fb33ad841
6 changed files with 341 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env node
|
||||
import http from "node:http";
|
||||
import { ControllerEngine, bootEvent } from "./controller-engine.mjs";
|
||||
import { ExecutionObserver } from "./execution-observer.mjs";
|
||||
import { DeepSeekJsonClient } from "./model-client.mjs";
|
||||
import { MachineNavigation } from "./machine-navigation.mjs";
|
||||
|
||||
|
|
@ -10,6 +11,16 @@ const STATE_ROOT =
|
|||
process.env.BS_TCS_CONTROLLER_STATE_ROOT ||
|
||||
"/var/lib/guanghu/personas/bingshuo-tcs";
|
||||
const MODEL = process.env.DEEPSEEK_MODEL || "deepseek-chat";
|
||||
const EXECUTION_BRIDGE_BIN =
|
||||
process.env.GUANGHU_EXECUTION_BRIDGE_BIN ||
|
||||
"/opt/guanghu/execution-bridge/current/guanghu-execution-bridge";
|
||||
const EXECUTION_BRIDGE_POLICY =
|
||||
process.env.GUANGHU_EXECUTION_BRIDGE_POLICY ||
|
||||
"/opt/guanghu/execution-bridge/current/policy.json";
|
||||
const EXECUTION_OBSERVE_INTERVAL_MS = Math.max(
|
||||
10_000,
|
||||
Number(process.env.GUANGHU_EXECUTION_OBSERVE_INTERVAL_MS || 30_000),
|
||||
);
|
||||
const MAX_BODY_BYTES = 16 * 1024;
|
||||
|
||||
const runtime = {
|
||||
|
|
@ -19,6 +30,16 @@ const runtime = {
|
|||
last_event_id: null,
|
||||
last_error: null,
|
||||
receipt: null,
|
||||
execution_substrate: {
|
||||
schema: "guanghu.cognitive-execution-observation/v1",
|
||||
target_node_id: "JD-FD-PRIMARY",
|
||||
mode: "READ_ONLY_STATUS",
|
||||
bridge_bound: 0,
|
||||
target_state_verified: 0,
|
||||
restart_allowed: false,
|
||||
arbitrary_shell: false,
|
||||
state: "NOT_YET_OBSERVED",
|
||||
},
|
||||
};
|
||||
|
||||
const engine = new ControllerEngine({
|
||||
|
|
@ -27,6 +48,29 @@ const engine = new ControllerEngine({
|
|||
modelName: MODEL,
|
||||
});
|
||||
const navigation = new MachineNavigation();
|
||||
const executionObserver = new ExecutionObserver({
|
||||
binaryPath: EXECUTION_BRIDGE_BIN,
|
||||
policyPath: EXECUTION_BRIDGE_POLICY,
|
||||
stateRoot: STATE_ROOT,
|
||||
});
|
||||
|
||||
async function refreshExecutionSubstrate() {
|
||||
try {
|
||||
runtime.execution_substrate = await executionObserver.observe();
|
||||
} catch (error) {
|
||||
runtime.execution_substrate = {
|
||||
schema: "guanghu.cognitive-execution-observation/v1",
|
||||
target_node_id: "JD-FD-PRIMARY",
|
||||
mode: "READ_ONLY_STATUS",
|
||||
bridge_bound: 0,
|
||||
target_state_verified: 0,
|
||||
restart_allowed: false,
|
||||
arbitrary_shell: false,
|
||||
state: "FAIL_0",
|
||||
error: String(error.message || error).slice(0, 240),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function send(response, status, body) {
|
||||
const payload = JSON.stringify(body);
|
||||
|
|
@ -63,6 +107,7 @@ function health() {
|
|||
persona_brain_runtime_exists: existence.persona_brain_runtime_exists || 0,
|
||||
living_ai_system_controller_running:
|
||||
existence.living_ai_system_controller_running || 0,
|
||||
execution_substrate: runtime.execution_substrate,
|
||||
...navigationHealth,
|
||||
};
|
||||
}
|
||||
|
|
@ -202,6 +247,12 @@ server.listen(PORT, HOST, () => {
|
|||
port: PORT,
|
||||
})}\n`,
|
||||
);
|
||||
void refreshExecutionSubstrate();
|
||||
const executionObservationTimer = setInterval(
|
||||
() => void refreshExecutionSubstrate(),
|
||||
EXECUTION_OBSERVE_INTERVAL_MS,
|
||||
);
|
||||
executionObservationTimer.unref();
|
||||
if (runtime.phase === "PAUSED_FOR_HUMAN") return;
|
||||
eventQueue = handleEvent(bootEvent()).catch((error) => {
|
||||
runtime.phase = "FAILED_CLOSED";
|
||||
|
|
|
|||
Loading…
Reference in a new issue