@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.
Files changed (71) hide show
  1. package/openclaw.plugin.json +29 -29
  2. package/package.json +55 -55
  3. package/runtime/cli/commands/index.js +326 -325
  4. package/runtime/cli/ops/heartbeat-surface.d.ts +84 -84
  5. package/runtime/cli/ops/heartbeat-surface.js +100 -100
  6. package/runtime/cli/ops/ops-router.js +1555 -1482
  7. package/runtime/cli/ops/workspace-heartbeat-runner.d.ts +85 -85
  8. package/runtime/cli/ops/workspace-heartbeat-runner.js +242 -242
  9. package/runtime/connectors/base/contract.d.ts +111 -111
  10. package/runtime/connectors/base/failure-taxonomy.d.ts +13 -13
  11. package/runtime/connectors/base/failure-taxonomy.js +186 -186
  12. package/runtime/connectors/base/map-life-evidence.js +137 -137
  13. package/runtime/connectors/base/policy-layer.js +202 -202
  14. package/runtime/connectors/evidence-normalizer.d.ts +45 -0
  15. package/runtime/connectors/evidence-normalizer.js +115 -0
  16. package/runtime/connectors/manifest/manifest-schema.d.ts +152 -152
  17. package/runtime/connectors/manifest/manifest-schema.js +54 -54
  18. package/runtime/connectors/services/connector-executor-adapter.d.ts +20 -20
  19. package/runtime/connectors/services/connector-executor-adapter.js +645 -645
  20. package/runtime/core/second-nature/action/action-closure-recorder.d.ts +70 -0
  21. package/runtime/core/second-nature/action/action-closure-recorder.js +184 -0
  22. package/runtime/core/second-nature/action/action-proposal-builder.d.ts +70 -0
  23. package/runtime/core/second-nature/action/action-proposal-builder.js +217 -0
  24. package/runtime/core/second-nature/action/autonomy-policy-evaluator.d.ts +43 -0
  25. package/runtime/core/second-nature/action/autonomy-policy-evaluator.js +213 -0
  26. package/runtime/core/second-nature/action/policy-bound-dispatch.d.ts +69 -0
  27. package/runtime/core/second-nature/action/policy-bound-dispatch.js +112 -0
  28. package/runtime/core/second-nature/body/tool-affordance/affordance-side-effect.d.ts +49 -0
  29. package/runtime/core/second-nature/body/tool-affordance/affordance-side-effect.js +100 -0
  30. package/runtime/core/second-nature/control-plane/accepted-projection-loader.d.ts +45 -0
  31. package/runtime/core/second-nature/control-plane/accepted-projection-loader.js +85 -0
  32. package/runtime/core/second-nature/control-plane/heartbeat-orchestrator.d.ts +38 -0
  33. package/runtime/core/second-nature/control-plane/heartbeat-orchestrator.js +165 -0
  34. package/runtime/core/second-nature/guidance/guidance-proposal-consumer.d.ts +51 -0
  35. package/runtime/core/second-nature/guidance/guidance-proposal-consumer.js +113 -0
  36. package/runtime/core/second-nature/heartbeat/goal-lifecycle-policy.d.ts +24 -24
  37. package/runtime/core/second-nature/heartbeat/goal-lifecycle-policy.js +61 -61
  38. package/runtime/core/second-nature/heartbeat/heartbeat-loop.d.ts +97 -97
  39. package/runtime/core/second-nature/heartbeat/heartbeat-loop.js +397 -397
  40. package/runtime/core/second-nature/orchestrator/platform-capability-router.js +149 -149
  41. package/runtime/core/second-nature/perception/judgment-engine.d.ts +53 -0
  42. package/runtime/core/second-nature/perception/judgment-engine.js +239 -0
  43. package/runtime/core/second-nature/perception/perception-builder.d.ts +62 -0
  44. package/runtime/core/second-nature/perception/perception-builder.js +208 -0
  45. package/runtime/core/second-nature/perception/sensitivity-classifier.d.ts +37 -0
  46. package/runtime/core/second-nature/perception/sensitivity-classifier.js +87 -0
  47. package/runtime/core/second-nature/quiet-dream/dream-consolidation-runner.d.ts +44 -0
  48. package/runtime/core/second-nature/quiet-dream/dream-consolidation-runner.js +180 -0
  49. package/runtime/core/second-nature/quiet-dream/dream-scheduler.d.ts +36 -0
  50. package/runtime/core/second-nature/quiet-dream/dream-scheduler.js +105 -0
  51. package/runtime/core/second-nature/quiet-dream/memory-projection-lifecycle.d.ts +36 -0
  52. package/runtime/core/second-nature/quiet-dream/memory-projection-lifecycle.js +151 -0
  53. package/runtime/core/second-nature/quiet-dream/quiet-daily-review-builder.d.ts +46 -0
  54. package/runtime/core/second-nature/quiet-dream/quiet-daily-review-builder.js +123 -0
  55. package/runtime/observability/causal-loop-health.d.ts +44 -0
  56. package/runtime/observability/causal-loop-health.js +118 -0
  57. package/runtime/observability/diagnostic-redaction.d.ts +43 -0
  58. package/runtime/observability/diagnostic-redaction.js +114 -0
  59. package/runtime/observability/loop-stage-event-sink.d.ts +43 -0
  60. package/runtime/observability/loop-stage-event-sink.js +148 -0
  61. package/runtime/observability/loop-status.d.ts +46 -0
  62. package/runtime/observability/loop-status.js +85 -0
  63. package/runtime/shared/types/index.js +3 -0
  64. package/runtime/shared/types/v8-contracts.d.ts +86 -0
  65. package/runtime/shared/types/v8-contracts.js +84 -0
  66. package/runtime/storage/db/schema/index.d.ts +1 -0
  67. package/runtime/storage/db/schema/index.js +1 -0
  68. package/runtime/storage/db/schema/v8-entities.d.ts +1973 -0
  69. package/runtime/storage/db/schema/v8-entities.js +160 -0
  70. package/runtime/storage/v8-state-stores.d.ts +147 -0
  71. package/runtime/storage/v8-state-stores.js +491 -0
@@ -1,97 +1,97 @@
1
- /**
2
- * Heartbeat Decision Loop
3
- *
4
- * Main entry point for the heartbeat runtime. Accepts a HeartbeatSignal,
5
- * builds runtime snapshot, plans candidate intents, evaluates hard guards,
6
- * and returns a HeartbeatCycleResult.
7
- *
8
- * Per design doc §4.3: heartbeat round follows the sequence:
9
- * signal → snapshot → plan → guard → result (HEARTBEAT_OK or intent_selected)
10
- *
11
- * Per ADR-005: heartbeat is the free-rhythm main entry; this loop
12
- * implements the default conservative path where HEARTBEAT_OK is
13
- * the first-class result when no action is warranted.
14
- */
15
- import type { HeartbeatSignal, HeartbeatCycleResult, HeartbeatCycleStatus, RuntimeScope, RuntimeTrigger } from "./signal.js";
16
- import type { CandidateIntent, ContinuitySnapshot, IntentKind } from "../types.js";
17
- import { type SnapshotInputs } from "./snapshot-builder.js";
18
- import { type HeartbeatRuntimeSnapshot } from "./runtime-snapshot.js";
19
- import type { GuidanceDraftPort } from "../../../guidance/outreach-draft-schema.js";
20
- import type { StateDatabase } from "../../../storage/db/index.js";
21
- import { type OpenClawDeliveryPort } from "../outreach/dispatch-user-outreach.js";
22
- import type { ConnectorExecutor } from "../../../connectors/base/contract.js";
23
- import type { CapabilityContractRegistry } from "../../../connectors/base/manifest.js";
24
- import type { NarrativeStateStore } from "../../../storage/narrative/narrative-state-store.js";
25
- import type { NarrativeTracePayload } from "../../../observability/services/lived-experience-audit.js";
26
- import type { ExperienceWriter } from "../body/tool-experience/experience-writer.js";
27
- import type { QuietDreamSchedulePort } from "../quiet/run-source-backed-quiet.js";
28
- import type { GoalLifecyclePolicy } from "./goal-lifecycle-policy.js";
29
- import type { IdleCuriosityPolicy } from "./idle-curiosity-policy.js";
30
- import type { CircuitBreakerManager } from "../body/circuit-breaker/circuit-breaker-manager.js";
31
- export interface HeartbeatDecisionTracePayload {
32
- scope: RuntimeScope;
33
- status: HeartbeatCycleStatus;
34
- reasons: string[];
35
- selectedIntentId?: string;
36
- rhythmWindowId: string;
37
- allowedIntentKinds: IntentKind[];
38
- candidateCount: number;
39
- lifeEvidenceEmpty: boolean;
40
- trigger: RuntimeTrigger;
41
- }
42
- /** Optional outreach delivery chain: when set, first allowed `user_outreach` runs dispatch (CR-M1). */
43
- export interface HeartbeatOutreachDispatchDeps {
44
- state: StateDatabase;
45
- guidance: GuidanceDraftPort;
46
- delivery: OpenClawDeliveryPort;
47
- }
48
- /** Optional Quiet orchestration: when set, quiet/reflection allows run source-backed Quiet writer (T2.3.3). */
49
- export interface HeartbeatQuietWorkflowDeps {
50
- workspaceRoot: string;
51
- /** v7 T-V7C.C.3: when present, a successful Quiet write auto-triggers Dream scheduling. */
52
- dreamSchedulePort?: QuietDreamSchedulePort;
53
- }
54
- /**
55
- * Resolves the heartbeat outcome for a guard-allowed intent (outreach dispatch, quiet orchestration, or default).
56
- * Exported for unit tests (CR-M1 wiring).
57
- */
58
- export declare function resolveAllowedIntentResult(intent: CandidateIntent, runtime: HeartbeatRuntimeSnapshot, inputs: SnapshotInputs, signal: HeartbeatSignal, deps: Pick<HeartbeatDeps, "outreachDispatch" | "quietWorkflow" | "connectorExecutor" | "state" | "workspaceRoot" | "experienceWriter" | "circuitBreakerManager">): Promise<HeartbeatCycleResult>;
59
- export interface HeartbeatDeps {
60
- /** Load snapshot inputs from state-system */
61
- loadSnapshotInputs: () => Promise<SnapshotInputs>;
62
- /** Optional observability hook (T2.2.1): one record per completed cycle. */
63
- recordDecisionTrace?: (payload: HeartbeatDecisionTracePayload) => Promise<void>;
64
- outreachDispatch?: HeartbeatOutreachDispatchDeps;
65
- quietWorkflow?: HeartbeatQuietWorkflowDeps;
66
- /**
67
- * When present, guard-allowed connector_action intents are dispatched
68
- * through the connector-system instead of returning connector_dispatch_unwired.
69
- */
70
- connectorExecutor?: ConnectorExecutor;
71
- /** T2.1.5: when present, heartbeat writes a source-backed NarrativeState revision after each cycle. */
72
- narrativeStateStore?: NarrativeStateStore;
73
- /** T5.1.2: when present, heartbeat records a NarrativeTrace after successful narrative state update. */
74
- recordNarrativeTrace?: (payload: NarrativeTracePayload) => Promise<void>;
75
- /** T3.3.1: when present, successful connector effects write LifeEvidence artifacts. */
76
- state?: StateDatabase;
77
- /** T3.3.1: workspace root for evidence artifact paths. */
78
- workspaceRoot?: string;
79
- /** T2.4.1: when present, planner resolves platform-specific intents. */
80
- connectorRegistry?: CapabilityContractRegistry;
81
- /** v7 T-V7C.C.2: when present, connector attempts write ToolExperience with triggerSource="heartbeat". */
82
- experienceWriter?: ExperienceWriter;
83
- /** v7 T-CP.C.3: when present, evaluates goal lifecycle transitions before candidate planning. */
84
- goalLifecyclePolicy?: GoalLifecyclePolicy;
85
- /** v7 T-CP.C.3: when present, selects read-only sensing intent when no active goals exist. */
86
- idleCuriosityPolicy?: IdleCuriosityPolicy;
87
- /** v7 T-BTS.C.5: when present, updates breaker state after connector execution. */
88
- circuitBreakerManager?: CircuitBreakerManager;
89
- }
90
- /**
91
- * Ingest a heartbeat rhythm signal and drive one full decision round.
92
- */
93
- export declare function ingestRhythmSignal(signal: HeartbeatSignal, deps: HeartbeatDeps): Promise<HeartbeatCycleResult>;
94
- /**
95
- * Build a snapshot directly from inputs (for testing or when state-system is unavailable).
96
- */
97
- export declare function buildSnapshotFromInputs(inputs: SnapshotInputs): ContinuitySnapshot;
1
+ /**
2
+ * Heartbeat Decision Loop
3
+ *
4
+ * Main entry point for the heartbeat runtime. Accepts a HeartbeatSignal,
5
+ * builds runtime snapshot, plans candidate intents, evaluates hard guards,
6
+ * and returns a HeartbeatCycleResult.
7
+ *
8
+ * Per design doc §4.3: heartbeat round follows the sequence:
9
+ * signal → snapshot → plan → guard → result (HEARTBEAT_OK or intent_selected)
10
+ *
11
+ * Per ADR-005: heartbeat is the free-rhythm main entry; this loop
12
+ * implements the default conservative path where HEARTBEAT_OK is
13
+ * the first-class result when no action is warranted.
14
+ */
15
+ import type { HeartbeatSignal, HeartbeatCycleResult, HeartbeatCycleStatus, RuntimeScope, RuntimeTrigger } from "./signal.js";
16
+ import type { CandidateIntent, ContinuitySnapshot, IntentKind } from "../types.js";
17
+ import { type SnapshotInputs } from "./snapshot-builder.js";
18
+ import { type HeartbeatRuntimeSnapshot } from "./runtime-snapshot.js";
19
+ import type { GuidanceDraftPort } from "../../../guidance/outreach-draft-schema.js";
20
+ import type { StateDatabase } from "../../../storage/db/index.js";
21
+ import { type OpenClawDeliveryPort } from "../outreach/dispatch-user-outreach.js";
22
+ import type { ConnectorExecutor } from "../../../connectors/base/contract.js";
23
+ import type { CapabilityContractRegistry } from "../../../connectors/base/manifest.js";
24
+ import type { NarrativeStateStore } from "../../../storage/narrative/narrative-state-store.js";
25
+ import type { NarrativeTracePayload } from "../../../observability/services/lived-experience-audit.js";
26
+ import type { ExperienceWriter } from "../body/tool-experience/experience-writer.js";
27
+ import type { QuietDreamSchedulePort } from "../quiet/run-source-backed-quiet.js";
28
+ import type { GoalLifecyclePolicy } from "./goal-lifecycle-policy.js";
29
+ import type { IdleCuriosityPolicy } from "./idle-curiosity-policy.js";
30
+ import type { CircuitBreakerManager } from "../body/circuit-breaker/circuit-breaker-manager.js";
31
+ export interface HeartbeatDecisionTracePayload {
32
+ scope: RuntimeScope;
33
+ status: HeartbeatCycleStatus;
34
+ reasons: string[];
35
+ selectedIntentId?: string;
36
+ rhythmWindowId: string;
37
+ allowedIntentKinds: IntentKind[];
38
+ candidateCount: number;
39
+ lifeEvidenceEmpty: boolean;
40
+ trigger: RuntimeTrigger;
41
+ }
42
+ /** Optional outreach delivery chain: when set, first allowed `user_outreach` runs dispatch (CR-M1). */
43
+ export interface HeartbeatOutreachDispatchDeps {
44
+ state: StateDatabase;
45
+ guidance: GuidanceDraftPort;
46
+ delivery: OpenClawDeliveryPort;
47
+ }
48
+ /** Optional Quiet orchestration: when set, quiet/reflection allows run source-backed Quiet writer (T2.3.3). */
49
+ export interface HeartbeatQuietWorkflowDeps {
50
+ workspaceRoot: string;
51
+ /** v7 T-V7C.C.3: when present, a successful Quiet write auto-triggers Dream scheduling. */
52
+ dreamSchedulePort?: QuietDreamSchedulePort;
53
+ }
54
+ /**
55
+ * Resolves the heartbeat outcome for a guard-allowed intent (outreach dispatch, quiet orchestration, or default).
56
+ * Exported for unit tests (CR-M1 wiring).
57
+ */
58
+ export declare function resolveAllowedIntentResult(intent: CandidateIntent, runtime: HeartbeatRuntimeSnapshot, inputs: SnapshotInputs, signal: HeartbeatSignal, deps: Pick<HeartbeatDeps, "outreachDispatch" | "quietWorkflow" | "connectorExecutor" | "state" | "workspaceRoot" | "experienceWriter" | "circuitBreakerManager">): Promise<HeartbeatCycleResult>;
59
+ export interface HeartbeatDeps {
60
+ /** Load snapshot inputs from state-system */
61
+ loadSnapshotInputs: () => Promise<SnapshotInputs>;
62
+ /** Optional observability hook (T2.2.1): one record per completed cycle. */
63
+ recordDecisionTrace?: (payload: HeartbeatDecisionTracePayload) => Promise<void>;
64
+ outreachDispatch?: HeartbeatOutreachDispatchDeps;
65
+ quietWorkflow?: HeartbeatQuietWorkflowDeps;
66
+ /**
67
+ * When present, guard-allowed connector_action intents are dispatched
68
+ * through the connector-system instead of returning connector_dispatch_unwired.
69
+ */
70
+ connectorExecutor?: ConnectorExecutor;
71
+ /** T2.1.5: when present, heartbeat writes a source-backed NarrativeState revision after each cycle. */
72
+ narrativeStateStore?: NarrativeStateStore;
73
+ /** T5.1.2: when present, heartbeat records a NarrativeTrace after successful narrative state update. */
74
+ recordNarrativeTrace?: (payload: NarrativeTracePayload) => Promise<void>;
75
+ /** T3.3.1: when present, successful connector effects write LifeEvidence artifacts. */
76
+ state?: StateDatabase;
77
+ /** T3.3.1: workspace root for evidence artifact paths. */
78
+ workspaceRoot?: string;
79
+ /** T2.4.1: when present, planner resolves platform-specific intents. */
80
+ connectorRegistry?: CapabilityContractRegistry;
81
+ /** v7 T-V7C.C.2: when present, connector attempts write ToolExperience with triggerSource="heartbeat". */
82
+ experienceWriter?: ExperienceWriter;
83
+ /** v7 T-CP.C.3: when present, evaluates goal lifecycle transitions before candidate planning. */
84
+ goalLifecyclePolicy?: GoalLifecyclePolicy;
85
+ /** v7 T-CP.C.3: when present, selects read-only sensing intent when no active goals exist. */
86
+ idleCuriosityPolicy?: IdleCuriosityPolicy;
87
+ /** v7 T-BTS.C.5: when present, updates breaker state after connector execution. */
88
+ circuitBreakerManager?: CircuitBreakerManager;
89
+ }
90
+ /**
91
+ * Ingest a heartbeat rhythm signal and drive one full decision round.
92
+ */
93
+ export declare function ingestRhythmSignal(signal: HeartbeatSignal, deps: HeartbeatDeps): Promise<HeartbeatCycleResult>;
94
+ /**
95
+ * Build a snapshot directly from inputs (for testing or when state-system is unavailable).
96
+ */
97
+ export declare function buildSnapshotFromInputs(inputs: SnapshotInputs): ContinuitySnapshot;