@haaaiawd/second-nature 0.1.51 → 0.2.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/openclaw.plugin.json +29 -29
- package/package.json +55 -55
- package/runtime/cli/commands/index.js +326 -325
- package/runtime/cli/ops/heartbeat-surface.d.ts +84 -84
- package/runtime/cli/ops/heartbeat-surface.js +100 -100
- package/runtime/cli/ops/ops-router.js +1555 -1482
- package/runtime/cli/ops/workspace-heartbeat-runner.d.ts +85 -85
- package/runtime/cli/ops/workspace-heartbeat-runner.js +242 -242
- package/runtime/connectors/base/contract.d.ts +111 -111
- package/runtime/connectors/base/failure-taxonomy.d.ts +13 -13
- package/runtime/connectors/base/failure-taxonomy.js +186 -186
- package/runtime/connectors/base/map-life-evidence.js +137 -137
- package/runtime/connectors/base/policy-layer.js +202 -202
- package/runtime/connectors/evidence-normalizer.d.ts +45 -0
- package/runtime/connectors/evidence-normalizer.js +115 -0
- package/runtime/connectors/manifest/manifest-schema.d.ts +152 -152
- package/runtime/connectors/manifest/manifest-schema.js +54 -54
- package/runtime/connectors/services/connector-executor-adapter.d.ts +20 -20
- package/runtime/connectors/services/connector-executor-adapter.js +645 -645
- package/runtime/core/second-nature/action/action-closure-recorder.d.ts +70 -0
- package/runtime/core/second-nature/action/action-closure-recorder.js +184 -0
- package/runtime/core/second-nature/action/action-proposal-builder.d.ts +70 -0
- package/runtime/core/second-nature/action/action-proposal-builder.js +217 -0
- package/runtime/core/second-nature/action/autonomy-policy-evaluator.d.ts +43 -0
- package/runtime/core/second-nature/action/autonomy-policy-evaluator.js +213 -0
- package/runtime/core/second-nature/action/policy-bound-dispatch.d.ts +69 -0
- package/runtime/core/second-nature/action/policy-bound-dispatch.js +112 -0
- package/runtime/core/second-nature/body/tool-affordance/affordance-side-effect.d.ts +49 -0
- package/runtime/core/second-nature/body/tool-affordance/affordance-side-effect.js +100 -0
- package/runtime/core/second-nature/control-plane/accepted-projection-loader.d.ts +45 -0
- package/runtime/core/second-nature/control-plane/accepted-projection-loader.js +85 -0
- package/runtime/core/second-nature/control-plane/heartbeat-orchestrator.d.ts +38 -0
- package/runtime/core/second-nature/control-plane/heartbeat-orchestrator.js +165 -0
- package/runtime/core/second-nature/guidance/guidance-proposal-consumer.d.ts +51 -0
- package/runtime/core/second-nature/guidance/guidance-proposal-consumer.js +113 -0
- package/runtime/core/second-nature/heartbeat/goal-lifecycle-policy.d.ts +24 -24
- package/runtime/core/second-nature/heartbeat/goal-lifecycle-policy.js +61 -61
- package/runtime/core/second-nature/heartbeat/heartbeat-loop.d.ts +97 -97
- package/runtime/core/second-nature/heartbeat/heartbeat-loop.js +397 -397
- package/runtime/core/second-nature/orchestrator/platform-capability-router.js +149 -149
- package/runtime/core/second-nature/perception/judgment-engine.d.ts +53 -0
- package/runtime/core/second-nature/perception/judgment-engine.js +239 -0
- package/runtime/core/second-nature/perception/perception-builder.d.ts +62 -0
- package/runtime/core/second-nature/perception/perception-builder.js +208 -0
- package/runtime/core/second-nature/perception/sensitivity-classifier.d.ts +37 -0
- package/runtime/core/second-nature/perception/sensitivity-classifier.js +87 -0
- package/runtime/core/second-nature/quiet-dream/dream-consolidation-runner.d.ts +44 -0
- package/runtime/core/second-nature/quiet-dream/dream-consolidation-runner.js +180 -0
- package/runtime/core/second-nature/quiet-dream/dream-scheduler.d.ts +36 -0
- package/runtime/core/second-nature/quiet-dream/dream-scheduler.js +105 -0
- package/runtime/core/second-nature/quiet-dream/memory-projection-lifecycle.d.ts +36 -0
- package/runtime/core/second-nature/quiet-dream/memory-projection-lifecycle.js +151 -0
- package/runtime/core/second-nature/quiet-dream/quiet-daily-review-builder.d.ts +46 -0
- package/runtime/core/second-nature/quiet-dream/quiet-daily-review-builder.js +123 -0
- package/runtime/observability/causal-loop-health.d.ts +44 -0
- package/runtime/observability/causal-loop-health.js +118 -0
- package/runtime/observability/diagnostic-redaction.d.ts +43 -0
- package/runtime/observability/diagnostic-redaction.js +114 -0
- package/runtime/observability/loop-stage-event-sink.d.ts +43 -0
- package/runtime/observability/loop-stage-event-sink.js +148 -0
- package/runtime/observability/loop-status.d.ts +46 -0
- package/runtime/observability/loop-status.js +85 -0
- package/runtime/shared/types/index.js +3 -0
- package/runtime/shared/types/v8-contracts.d.ts +86 -0
- package/runtime/shared/types/v8-contracts.js +84 -0
- package/runtime/storage/db/schema/index.d.ts +1 -0
- package/runtime/storage/db/schema/index.js +1 -0
- package/runtime/storage/db/schema/v8-entities.d.ts +1973 -0
- package/runtime/storage/db/schema/v8-entities.js +160 -0
- package/runtime/storage/v8-state-stores.d.ts +147 -0
- package/runtime/storage/v8-state-stores.js +491 -0
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stable HeartbeatSurfaceResult for second_nature_ops / CLI (T1.1.3, cli-system / ADR-005).
|
|
3
|
-
*
|
|
4
|
-
* S1 scope: carrier / probe / runtime-unavailable / fake control-plane passthrough only.
|
|
5
|
-
* Workspace full runtime: delegates to `runHeartbeatCycle` when read models are wired (US-001 / CH-09-02).
|
|
6
|
-
*/
|
|
7
|
-
import type { SurfaceMode } from "../runtime/runtime-artifact-boundary.js";
|
|
8
|
-
import type { HeartbeatSignal } from "../../core/second-nature/heartbeat/signal.js";
|
|
9
|
-
import type { CliReadModels } from "../read-models/index.js";
|
|
10
|
-
import type { RuntimeDecisionRecorder } from "../../observability/services/runtime-decision-recorder.js";
|
|
11
|
-
import type { StateDatabase } from "../../storage/db/index.js";
|
|
12
|
-
import type { ConnectorExecutor } from "../../core/second-nature/orchestrator/effect-dispatcher.js";
|
|
13
|
-
import type { CapabilityContractRegistry } from "../../connectors/base/manifest.js";
|
|
14
|
-
import type { AffordanceMap } from "../../shared/types/v7-entities.js";
|
|
15
|
-
import type { ExperienceWriter } from "../../core/second-nature/body/tool-experience/experience-writer.js";
|
|
16
|
-
import type { QuietDreamSchedulePort } from "../../core/second-nature/quiet/run-source-backed-quiet.js";
|
|
17
|
-
import type { HeartbeatDigestAssemblerDeps } from "../../observability/services/heartbeat-digest-assembler.js";
|
|
18
|
-
import type { GoalLifecyclePolicy } from "../../core/second-nature/heartbeat/goal-lifecycle-policy.js";
|
|
19
|
-
import type { IdleCuriosityPolicy } from "../../core/second-nature/heartbeat/idle-curiosity-policy.js";
|
|
20
|
-
import type { CircuitBreakerManager } from "../../core/second-nature/body/circuit-breaker/circuit-breaker-manager.js";
|
|
21
|
-
export type HeartbeatSurfaceStatus = "heartbeat_ok" | "intent_selected" | "denied" | "deferred" | "runtime_carrier_only" | "delivery_unavailable";
|
|
22
|
-
export interface HeartbeatSurfaceResult {
|
|
23
|
-
ok: boolean;
|
|
24
|
-
status: HeartbeatSurfaceStatus;
|
|
25
|
-
surfaceMode: SurfaceMode;
|
|
26
|
-
decisionId?: string;
|
|
27
|
-
deliveryAttemptId?: string;
|
|
28
|
-
capabilityReportRef?: string;
|
|
29
|
-
fallbackRef?: string;
|
|
30
|
-
reasons: string[];
|
|
31
|
-
/** When false, callers must not treat the round as lived-experience loop completion */
|
|
32
|
-
livedExperienceLoopClaimed: boolean;
|
|
33
|
-
/** True when structured fields mirror a fake adapter for schema parity only */
|
|
34
|
-
schemaParityOnly?: boolean;
|
|
35
|
-
}
|
|
36
|
-
export interface HeartbeatCheckInput {
|
|
37
|
-
probeOnly?: boolean;
|
|
38
|
-
runtimeAvailable: boolean;
|
|
39
|
-
fakeControlPlanePassthrough?: Record<string, unknown>;
|
|
40
|
-
/** When set, full-runtime heartbeat_check runs the control-plane decision loop (US-001). */
|
|
41
|
-
readModels?: CliReadModels;
|
|
42
|
-
/** When set, full-runtime cycles are persisted so `loadStatus` exits unknown (T1.2.3). */
|
|
43
|
-
runtimeRecorder?: RuntimeDecisionRecorder;
|
|
44
|
-
/**
|
|
45
|
-
* T2.2.2: when set together with `workspaceRoot`, life evidence from the state DB is loaded
|
|
46
|
-
* and merged into SnapshotInputs so planner/guard paths see real source-ref truth.
|
|
47
|
-
*/
|
|
48
|
-
state?: StateDatabase;
|
|
49
|
-
workspaceRoot?: string;
|
|
50
|
-
timestamp?: string;
|
|
51
|
-
sessionContext?: string;
|
|
52
|
-
scopeHint?: HeartbeatSignal["scopeHint"];
|
|
53
|
-
/**
|
|
54
|
-
* When present, guard-allowed connector_action intents are dispatched through the
|
|
55
|
-
* connector-system instead of returning connector_dispatch_unwired.
|
|
56
|
-
*/
|
|
57
|
-
connectorExecutor?: ConnectorExecutor;
|
|
58
|
-
/** Capability registry used by planner to avoid platform/capability protocol mismatches. */
|
|
59
|
-
connectorRegistry?: CapabilityContractRegistry;
|
|
60
|
-
/** v7 T-V7C.C.2: affordance map for breaker-aware guard evaluation. */
|
|
61
|
-
affordanceMap?: AffordanceMap;
|
|
62
|
-
/** v7 T-V7C.C.2: experience writer for heartbeat connector attempts. */
|
|
63
|
-
experienceWriter?: ExperienceWriter;
|
|
64
|
-
/**
|
|
65
|
-
* v7 T-V7C.C.6: when present, a successful Quiet write auto-triggers Dream scheduling.
|
|
66
|
-
* Fixes the production-data gap where dream_output_index does not grow after Quiet.
|
|
67
|
-
*/
|
|
68
|
-
dreamSchedulePort?: QuietDreamSchedulePort;
|
|
69
|
-
/**
|
|
70
|
-
* v7 T-V7C.C.6: when present, generates a HeartbeatDigest after each cycle.
|
|
71
|
-
* Fixes the production-data gap where heartbeat_digest does not grow.
|
|
72
|
-
*/
|
|
73
|
-
digestOpts?: {
|
|
74
|
-
assemblerDeps: HeartbeatDigestAssemblerDeps;
|
|
75
|
-
digestWindowHour?: number;
|
|
76
|
-
};
|
|
77
|
-
/** v7 T-CP.C.3: goal lifecycle policy for evaluating goal transitions. */
|
|
78
|
-
goalLifecyclePolicy?: GoalLifecyclePolicy;
|
|
79
|
-
/** v7 T-CP.C.3: idle curiosity policy for read-only sensing when no active goals. */
|
|
80
|
-
idleCuriosityPolicy?: IdleCuriosityPolicy;
|
|
81
|
-
/** v7 T-BTS.C.5: circuit breaker manager for connector execution health. */
|
|
82
|
-
circuitBreakerManager?: CircuitBreakerManager;
|
|
83
|
-
}
|
|
84
|
-
export declare function heartbeatCheck(input: HeartbeatCheckInput): Promise<HeartbeatSurfaceResult>;
|
|
1
|
+
/**
|
|
2
|
+
* Stable HeartbeatSurfaceResult for second_nature_ops / CLI (T1.1.3, cli-system / ADR-005).
|
|
3
|
+
*
|
|
4
|
+
* S1 scope: carrier / probe / runtime-unavailable / fake control-plane passthrough only.
|
|
5
|
+
* Workspace full runtime: delegates to `runHeartbeatCycle` when read models are wired (US-001 / CH-09-02).
|
|
6
|
+
*/
|
|
7
|
+
import type { SurfaceMode } from "../runtime/runtime-artifact-boundary.js";
|
|
8
|
+
import type { HeartbeatSignal } from "../../core/second-nature/heartbeat/signal.js";
|
|
9
|
+
import type { CliReadModels } from "../read-models/index.js";
|
|
10
|
+
import type { RuntimeDecisionRecorder } from "../../observability/services/runtime-decision-recorder.js";
|
|
11
|
+
import type { StateDatabase } from "../../storage/db/index.js";
|
|
12
|
+
import type { ConnectorExecutor } from "../../core/second-nature/orchestrator/effect-dispatcher.js";
|
|
13
|
+
import type { CapabilityContractRegistry } from "../../connectors/base/manifest.js";
|
|
14
|
+
import type { AffordanceMap } from "../../shared/types/v7-entities.js";
|
|
15
|
+
import type { ExperienceWriter } from "../../core/second-nature/body/tool-experience/experience-writer.js";
|
|
16
|
+
import type { QuietDreamSchedulePort } from "../../core/second-nature/quiet/run-source-backed-quiet.js";
|
|
17
|
+
import type { HeartbeatDigestAssemblerDeps } from "../../observability/services/heartbeat-digest-assembler.js";
|
|
18
|
+
import type { GoalLifecyclePolicy } from "../../core/second-nature/heartbeat/goal-lifecycle-policy.js";
|
|
19
|
+
import type { IdleCuriosityPolicy } from "../../core/second-nature/heartbeat/idle-curiosity-policy.js";
|
|
20
|
+
import type { CircuitBreakerManager } from "../../core/second-nature/body/circuit-breaker/circuit-breaker-manager.js";
|
|
21
|
+
export type HeartbeatSurfaceStatus = "heartbeat_ok" | "intent_selected" | "denied" | "deferred" | "runtime_carrier_only" | "delivery_unavailable";
|
|
22
|
+
export interface HeartbeatSurfaceResult {
|
|
23
|
+
ok: boolean;
|
|
24
|
+
status: HeartbeatSurfaceStatus;
|
|
25
|
+
surfaceMode: SurfaceMode;
|
|
26
|
+
decisionId?: string;
|
|
27
|
+
deliveryAttemptId?: string;
|
|
28
|
+
capabilityReportRef?: string;
|
|
29
|
+
fallbackRef?: string;
|
|
30
|
+
reasons: string[];
|
|
31
|
+
/** When false, callers must not treat the round as lived-experience loop completion */
|
|
32
|
+
livedExperienceLoopClaimed: boolean;
|
|
33
|
+
/** True when structured fields mirror a fake adapter for schema parity only */
|
|
34
|
+
schemaParityOnly?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface HeartbeatCheckInput {
|
|
37
|
+
probeOnly?: boolean;
|
|
38
|
+
runtimeAvailable: boolean;
|
|
39
|
+
fakeControlPlanePassthrough?: Record<string, unknown>;
|
|
40
|
+
/** When set, full-runtime heartbeat_check runs the control-plane decision loop (US-001). */
|
|
41
|
+
readModels?: CliReadModels;
|
|
42
|
+
/** When set, full-runtime cycles are persisted so `loadStatus` exits unknown (T1.2.3). */
|
|
43
|
+
runtimeRecorder?: RuntimeDecisionRecorder;
|
|
44
|
+
/**
|
|
45
|
+
* T2.2.2: when set together with `workspaceRoot`, life evidence from the state DB is loaded
|
|
46
|
+
* and merged into SnapshotInputs so planner/guard paths see real source-ref truth.
|
|
47
|
+
*/
|
|
48
|
+
state?: StateDatabase;
|
|
49
|
+
workspaceRoot?: string;
|
|
50
|
+
timestamp?: string;
|
|
51
|
+
sessionContext?: string;
|
|
52
|
+
scopeHint?: HeartbeatSignal["scopeHint"];
|
|
53
|
+
/**
|
|
54
|
+
* When present, guard-allowed connector_action intents are dispatched through the
|
|
55
|
+
* connector-system instead of returning connector_dispatch_unwired.
|
|
56
|
+
*/
|
|
57
|
+
connectorExecutor?: ConnectorExecutor;
|
|
58
|
+
/** Capability registry used by planner to avoid platform/capability protocol mismatches. */
|
|
59
|
+
connectorRegistry?: CapabilityContractRegistry;
|
|
60
|
+
/** v7 T-V7C.C.2: affordance map for breaker-aware guard evaluation. */
|
|
61
|
+
affordanceMap?: AffordanceMap;
|
|
62
|
+
/** v7 T-V7C.C.2: experience writer for heartbeat connector attempts. */
|
|
63
|
+
experienceWriter?: ExperienceWriter;
|
|
64
|
+
/**
|
|
65
|
+
* v7 T-V7C.C.6: when present, a successful Quiet write auto-triggers Dream scheduling.
|
|
66
|
+
* Fixes the production-data gap where dream_output_index does not grow after Quiet.
|
|
67
|
+
*/
|
|
68
|
+
dreamSchedulePort?: QuietDreamSchedulePort;
|
|
69
|
+
/**
|
|
70
|
+
* v7 T-V7C.C.6: when present, generates a HeartbeatDigest after each cycle.
|
|
71
|
+
* Fixes the production-data gap where heartbeat_digest does not grow.
|
|
72
|
+
*/
|
|
73
|
+
digestOpts?: {
|
|
74
|
+
assemblerDeps: HeartbeatDigestAssemblerDeps;
|
|
75
|
+
digestWindowHour?: number;
|
|
76
|
+
};
|
|
77
|
+
/** v7 T-CP.C.3: goal lifecycle policy for evaluating goal transitions. */
|
|
78
|
+
goalLifecyclePolicy?: GoalLifecyclePolicy;
|
|
79
|
+
/** v7 T-CP.C.3: idle curiosity policy for read-only sensing when no active goals. */
|
|
80
|
+
idleCuriosityPolicy?: IdleCuriosityPolicy;
|
|
81
|
+
/** v7 T-BTS.C.5: circuit breaker manager for connector execution health. */
|
|
82
|
+
circuitBreakerManager?: CircuitBreakerManager;
|
|
83
|
+
}
|
|
84
|
+
export declare function heartbeatCheck(input: HeartbeatCheckInput): Promise<HeartbeatSurfaceResult>;
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import { createWorkspaceHeartbeatRunner } from "./workspace-heartbeat-runner.js";
|
|
2
|
-
function mapCycleToSurface(cycle, surfaceMode) {
|
|
3
|
-
const status = cycle.status === "runtime_carrier_only"
|
|
4
|
-
? "runtime_carrier_only"
|
|
5
|
-
: cycle.status;
|
|
6
|
-
return {
|
|
7
|
-
ok: true,
|
|
8
|
-
status,
|
|
9
|
-
surfaceMode,
|
|
10
|
-
decisionId: cycle.decisionId,
|
|
11
|
-
deliveryAttemptId: cycle.deliveryAttemptId,
|
|
12
|
-
fallbackRef: cycle.fallbackRef,
|
|
13
|
-
reasons: cycle.reasons,
|
|
14
|
-
livedExperienceLoopClaimed: false,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export async function heartbeatCheck(input) {
|
|
18
|
-
if (!input.runtimeAvailable) {
|
|
19
|
-
return {
|
|
20
|
-
ok: true,
|
|
21
|
-
status: "runtime_carrier_only",
|
|
22
|
-
surfaceMode: "host_safe_carrier",
|
|
23
|
-
reasons: ["runtime_unavailable_packaged_carrier"],
|
|
24
|
-
livedExperienceLoopClaimed: false,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
if (input.probeOnly) {
|
|
28
|
-
return {
|
|
29
|
-
ok: true,
|
|
30
|
-
status: "heartbeat_ok",
|
|
31
|
-
surfaceMode: "capability_probe",
|
|
32
|
-
reasons: ["probe_only"],
|
|
33
|
-
livedExperienceLoopClaimed: false,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (input.fakeControlPlanePassthrough) {
|
|
37
|
-
const decisionId = typeof input.fakeControlPlanePassthrough.decisionId === "string"
|
|
38
|
-
? input.fakeControlPlanePassthrough.decisionId
|
|
39
|
-
: undefined;
|
|
40
|
-
return {
|
|
41
|
-
ok: true,
|
|
42
|
-
status: "intent_selected",
|
|
43
|
-
surfaceMode: "host_safe_carrier",
|
|
44
|
-
reasons: ["fake_control_plane_passthrough"],
|
|
45
|
-
decisionId,
|
|
46
|
-
livedExperienceLoopClaimed: false,
|
|
47
|
-
schemaParityOnly: true,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (!input.readModels) {
|
|
51
|
-
return {
|
|
52
|
-
ok: true,
|
|
53
|
-
status: "runtime_carrier_only",
|
|
54
|
-
surfaceMode: "host_safe_carrier",
|
|
55
|
-
reasons: ["heartbeat_read_models_unavailable"],
|
|
56
|
-
livedExperienceLoopClaimed: false,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const timestamp = typeof input.timestamp === "string" && input.timestamp.trim().length > 0
|
|
60
|
-
? input.timestamp.trim()
|
|
61
|
-
: new Date().toISOString();
|
|
62
|
-
const signal = {
|
|
63
|
-
trigger: "heartbeat_bridge",
|
|
64
|
-
scopeHint: input.scopeHint,
|
|
65
|
-
payload: {
|
|
66
|
-
timestamp,
|
|
67
|
-
sessionContext: typeof input.sessionContext === "string"
|
|
68
|
-
? input.sessionContext
|
|
69
|
-
: undefined,
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
const run = createWorkspaceHeartbeatRunner(input.readModels, {
|
|
73
|
-
runtimeRecorder: input.runtimeRecorder,
|
|
74
|
-
state: input.state,
|
|
75
|
-
workspaceRoot: input.workspaceRoot ?? process.cwd(),
|
|
76
|
-
connectorExecutor: input.connectorExecutor,
|
|
77
|
-
connectorRegistry: input.connectorRegistry,
|
|
78
|
-
affordanceMap: input.affordanceMap,
|
|
79
|
-
experienceWriter: input.experienceWriter,
|
|
80
|
-
dreamSchedulePort: input.dreamSchedulePort,
|
|
81
|
-
digestOpts: input.digestOpts,
|
|
82
|
-
goalLifecyclePolicy: input.goalLifecyclePolicy,
|
|
83
|
-
idleCuriosityPolicy: input.idleCuriosityPolicy,
|
|
84
|
-
circuitBreakerManager: input.circuitBreakerManager,
|
|
85
|
-
});
|
|
86
|
-
try {
|
|
87
|
-
const cycle = await run(signal);
|
|
88
|
-
return mapCycleToSurface(cycle, "workspace_full_runtime");
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
92
|
-
return {
|
|
93
|
-
ok: false,
|
|
94
|
-
status: "denied",
|
|
95
|
-
surfaceMode: "workspace_full_runtime",
|
|
96
|
-
reasons: [`heartbeat_cycle_exception:${msg.slice(0, 120)}`],
|
|
97
|
-
livedExperienceLoopClaimed: false,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
1
|
+
import { createWorkspaceHeartbeatRunner } from "./workspace-heartbeat-runner.js";
|
|
2
|
+
function mapCycleToSurface(cycle, surfaceMode) {
|
|
3
|
+
const status = cycle.status === "runtime_carrier_only"
|
|
4
|
+
? "runtime_carrier_only"
|
|
5
|
+
: cycle.status;
|
|
6
|
+
return {
|
|
7
|
+
ok: true,
|
|
8
|
+
status,
|
|
9
|
+
surfaceMode,
|
|
10
|
+
decisionId: cycle.decisionId,
|
|
11
|
+
deliveryAttemptId: cycle.deliveryAttemptId,
|
|
12
|
+
fallbackRef: cycle.fallbackRef,
|
|
13
|
+
reasons: cycle.reasons,
|
|
14
|
+
livedExperienceLoopClaimed: false,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export async function heartbeatCheck(input) {
|
|
18
|
+
if (!input.runtimeAvailable) {
|
|
19
|
+
return {
|
|
20
|
+
ok: true,
|
|
21
|
+
status: "runtime_carrier_only",
|
|
22
|
+
surfaceMode: "host_safe_carrier",
|
|
23
|
+
reasons: ["runtime_unavailable_packaged_carrier"],
|
|
24
|
+
livedExperienceLoopClaimed: false,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (input.probeOnly) {
|
|
28
|
+
return {
|
|
29
|
+
ok: true,
|
|
30
|
+
status: "heartbeat_ok",
|
|
31
|
+
surfaceMode: "capability_probe",
|
|
32
|
+
reasons: ["probe_only"],
|
|
33
|
+
livedExperienceLoopClaimed: false,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (input.fakeControlPlanePassthrough) {
|
|
37
|
+
const decisionId = typeof input.fakeControlPlanePassthrough.decisionId === "string"
|
|
38
|
+
? input.fakeControlPlanePassthrough.decisionId
|
|
39
|
+
: undefined;
|
|
40
|
+
return {
|
|
41
|
+
ok: true,
|
|
42
|
+
status: "intent_selected",
|
|
43
|
+
surfaceMode: "host_safe_carrier",
|
|
44
|
+
reasons: ["fake_control_plane_passthrough"],
|
|
45
|
+
decisionId,
|
|
46
|
+
livedExperienceLoopClaimed: false,
|
|
47
|
+
schemaParityOnly: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (!input.readModels) {
|
|
51
|
+
return {
|
|
52
|
+
ok: true,
|
|
53
|
+
status: "runtime_carrier_only",
|
|
54
|
+
surfaceMode: "host_safe_carrier",
|
|
55
|
+
reasons: ["heartbeat_read_models_unavailable"],
|
|
56
|
+
livedExperienceLoopClaimed: false,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const timestamp = typeof input.timestamp === "string" && input.timestamp.trim().length > 0
|
|
60
|
+
? input.timestamp.trim()
|
|
61
|
+
: new Date().toISOString();
|
|
62
|
+
const signal = {
|
|
63
|
+
trigger: "heartbeat_bridge",
|
|
64
|
+
scopeHint: input.scopeHint,
|
|
65
|
+
payload: {
|
|
66
|
+
timestamp,
|
|
67
|
+
sessionContext: typeof input.sessionContext === "string"
|
|
68
|
+
? input.sessionContext
|
|
69
|
+
: undefined,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const run = createWorkspaceHeartbeatRunner(input.readModels, {
|
|
73
|
+
runtimeRecorder: input.runtimeRecorder,
|
|
74
|
+
state: input.state,
|
|
75
|
+
workspaceRoot: input.workspaceRoot ?? process.cwd(),
|
|
76
|
+
connectorExecutor: input.connectorExecutor,
|
|
77
|
+
connectorRegistry: input.connectorRegistry,
|
|
78
|
+
affordanceMap: input.affordanceMap,
|
|
79
|
+
experienceWriter: input.experienceWriter,
|
|
80
|
+
dreamSchedulePort: input.dreamSchedulePort,
|
|
81
|
+
digestOpts: input.digestOpts,
|
|
82
|
+
goalLifecyclePolicy: input.goalLifecyclePolicy,
|
|
83
|
+
idleCuriosityPolicy: input.idleCuriosityPolicy,
|
|
84
|
+
circuitBreakerManager: input.circuitBreakerManager,
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
const cycle = await run(signal);
|
|
88
|
+
return mapCycleToSurface(cycle, "workspace_full_runtime");
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
status: "denied",
|
|
95
|
+
surfaceMode: "workspace_full_runtime",
|
|
96
|
+
reasons: [`heartbeat_cycle_exception:${msg.slice(0, 120)}`],
|
|
97
|
+
livedExperienceLoopClaimed: false,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|