@haaaiawd/second-nature 0.2.9 → 0.2.13

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 (115) hide show
  1. package/index.js +102 -6
  2. package/openclaw.plugin.json +2 -5
  3. package/package.json +1 -1
  4. package/runtime/cli/commands/index.js +85 -11
  5. package/runtime/cli/host-capability/host-discovery-port.d.ts +85 -0
  6. package/runtime/cli/host-capability/host-discovery-port.js +137 -0
  7. package/runtime/cli/host-capability/probe-host-capability.js +1 -1
  8. package/runtime/cli/host-capability/types.d.ts +2 -7
  9. package/runtime/cli/host-capability/types.js +0 -5
  10. package/runtime/cli/ops/heartbeat-surface.d.ts +5 -3
  11. package/runtime/cli/ops/heartbeat-surface.js +38 -8
  12. package/runtime/cli/ops/ops-router.d.ts +6 -2
  13. package/runtime/cli/ops/ops-router.js +1275 -1147
  14. package/runtime/cli/ops/workspace-heartbeat-runner.js +2 -5
  15. package/runtime/connectors/base/normalized-evidence-content.d.ts +4 -0
  16. package/runtime/connectors/base/normalized-evidence-content.js +21 -2
  17. package/runtime/connectors/evidence-normalizer.js +32 -1
  18. package/runtime/connectors/manifest/manifest-schema.d.ts +2 -2
  19. package/runtime/connectors/registry/dynamic-connector-registry.js +16 -1
  20. package/runtime/connectors/services/connector-executor-adapter.js +54 -35
  21. package/runtime/core/second-nature/action/action-closure-recorder.d.ts +4 -0
  22. package/runtime/core/second-nature/action/action-closure-recorder.js +51 -38
  23. package/runtime/core/second-nature/action/action-proposal-builder.js +8 -34
  24. package/runtime/core/second-nature/action/policy-bound-dispatch.d.ts +2 -0
  25. package/runtime/core/second-nature/action/policy-bound-dispatch.js +10 -5
  26. package/runtime/core/second-nature/control-plane/accepted-projection-loader.js +1 -11
  27. package/runtime/core/second-nature/control-plane/cycle-finalizer.d.ts +82 -0
  28. package/runtime/core/second-nature/control-plane/cycle-finalizer.js +187 -0
  29. package/runtime/core/second-nature/control-plane/heartbeat-orchestrator.d.ts +1 -0
  30. package/runtime/core/second-nature/control-plane/heartbeat-orchestrator.js +23 -15
  31. package/runtime/core/second-nature/control-plane/real-runtime-spine.d.ts +2 -0
  32. package/runtime/core/second-nature/control-plane/real-runtime-spine.js +2 -1
  33. package/runtime/core/second-nature/guidance/guidance-proposal-consumer.d.ts +2 -1
  34. package/runtime/core/second-nature/guidance/guidance-proposal-consumer.js +4 -2
  35. package/runtime/core/second-nature/heartbeat/heartbeat-loop.js +4 -3
  36. package/runtime/core/second-nature/heartbeat/runtime-snapshot.d.ts +3 -2
  37. package/runtime/core/second-nature/heartbeat/snapshot-builder.d.ts +3 -2
  38. package/runtime/core/second-nature/orchestrator/intent-planner.js +4 -2
  39. package/runtime/core/second-nature/orchestrator/narrative-update.js +1 -2
  40. package/runtime/core/second-nature/orchestrator/platform-capability-router.d.ts +2 -2
  41. package/runtime/core/second-nature/orchestrator/platform-capability-router.js +1 -1
  42. package/runtime/core/second-nature/outreach/build-outreach-draft-request.js +2 -3
  43. package/runtime/core/second-nature/outreach/dispatch-user-outreach.d.ts +2 -2
  44. package/runtime/core/second-nature/outreach/dispatch-user-outreach.js +6 -1
  45. package/runtime/core/second-nature/outreach/judge-input-from-snapshot.js +3 -14
  46. package/runtime/core/second-nature/outreach/judge-outreach.d.ts +6 -5
  47. package/runtime/core/second-nature/perception/judgment-engine.js +10 -16
  48. package/runtime/core/second-nature/perception/perception-builder.js +15 -11
  49. package/runtime/core/second-nature/quiet/run-source-backed-quiet.js +13 -15
  50. package/runtime/core/second-nature/quiet-dream/daily-rhythm-scheduler.js +40 -16
  51. package/runtime/core/second-nature/quiet-dream/dream-consolidation-runner.d.ts +5 -1
  52. package/runtime/core/second-nature/quiet-dream/dream-consolidation-runner.js +68 -29
  53. package/runtime/core/second-nature/quiet-dream/dream-scheduler.js +2 -3
  54. package/runtime/core/second-nature/quiet-dream/memory-projection-lifecycle.js +2 -13
  55. package/runtime/core/second-nature/quiet-dream/quiet-daily-review-builder.d.ts +1 -0
  56. package/runtime/core/second-nature/quiet-dream/quiet-daily-review-builder.js +34 -11
  57. package/runtime/core/second-nature/types.d.ts +2 -9
  58. package/runtime/dream/dream-engine.js +11 -4
  59. package/runtime/guidance/outreach-draft-schema.d.ts +12 -12
  60. package/runtime/guidance/persona-selection.js +5 -0
  61. package/runtime/guidance/template-registry.js +6 -1
  62. package/runtime/guidance/types.d.ts +2 -2
  63. package/runtime/observability/causal-loop-health.d.ts +2 -1
  64. package/runtime/observability/causal-loop-health.js +7 -0
  65. package/runtime/observability/living-loop-health-gate.js +2 -8
  66. package/runtime/observability/loop-stage-event-sink.js +6 -2
  67. package/runtime/observability/loop-status.d.ts +2 -0
  68. package/runtime/observability/loop-status.js +14 -1
  69. package/runtime/observability/services/heartbeat-digest-assembler.d.ts +3 -0
  70. package/runtime/observability/services/heartbeat-digest-assembler.js +9 -0
  71. package/runtime/observability/services/lived-experience-audit.d.ts +7 -7
  72. package/runtime/shared/degraded-status-classifier.d.ts +16 -0
  73. package/runtime/shared/degraded-status-classifier.js +68 -0
  74. package/runtime/shared/evidence-level-classifier.d.ts +61 -0
  75. package/runtime/shared/evidence-level-classifier.js +116 -0
  76. package/runtime/shared/provenance-tier.d.ts +37 -0
  77. package/runtime/shared/provenance-tier.js +97 -0
  78. package/runtime/shared/serialization.d.ts +17 -0
  79. package/runtime/shared/serialization.js +27 -0
  80. package/runtime/shared/setup-ack.d.ts +54 -0
  81. package/runtime/shared/setup-ack.js +108 -0
  82. package/runtime/shared/source-ref-compat.d.ts +26 -0
  83. package/runtime/shared/source-ref-compat.js +64 -0
  84. package/runtime/shared/types/goal.d.ts +4 -4
  85. package/runtime/shared/types/goal.js +1 -1
  86. package/runtime/shared/types/index.d.ts +1 -0
  87. package/runtime/shared/types/index.js +1 -3
  88. package/runtime/shared/types/source-ref.d.ts +2 -2
  89. package/runtime/shared/types/v7-entities.d.ts +5 -5
  90. package/runtime/shared/types/v7-entities.js +1 -1
  91. package/runtime/shared/types/v8-contracts.d.ts +13 -2
  92. package/runtime/storage/db/index.js +60 -12
  93. package/runtime/storage/db/migrations/index.js +4 -0
  94. package/runtime/storage/db/migrations/v8-004-schema-closure.d.ts +19 -0
  95. package/runtime/storage/db/migrations/v8-004-schema-closure.js +74 -0
  96. package/runtime/storage/db/migrations/v8-005-single-status-schema.d.ts +11 -0
  97. package/runtime/storage/db/migrations/v8-005-single-status-schema.js +16 -0
  98. package/runtime/storage/db/migrations/v8-006-loop-stage-event-proof-trace-columns.d.ts +9 -0
  99. package/runtime/storage/db/migrations/v8-006-loop-stage-event-proof-trace-columns.js +15 -0
  100. package/runtime/storage/db/schema/v8-entities.d.ts +65 -84
  101. package/runtime/storage/db/schema/v8-entities.js +8 -7
  102. package/runtime/storage/delivery/types.d.ts +2 -2
  103. package/runtime/storage/fallback/load-operator-fallback.d.ts +2 -2
  104. package/runtime/storage/fallback/operator-fallback-types.d.ts +2 -2
  105. package/runtime/storage/fallback/operator-fallback-view.d.ts +2 -2
  106. package/runtime/storage/index.d.ts +1 -1
  107. package/runtime/storage/life-evidence/types.d.ts +5 -5
  108. package/runtime/storage/quiet/quiet-artifact-types.d.ts +4 -4
  109. package/runtime/storage/quiet/quiet-artifact-writer.d.ts +2 -2
  110. package/runtime/storage/services/write-validation-gate.d.ts +1 -1
  111. package/runtime/storage/services/write-validation-gate.js +15 -3
  112. package/runtime/storage/snapshots/types.d.ts +8 -8
  113. package/runtime/storage/user-interest/types.d.ts +3 -3
  114. package/runtime/storage/v8-state-stores.d.ts +15 -3
  115. package/runtime/storage/v8-state-stores.js +60 -39
@@ -35,7 +35,7 @@ export interface HeartbeatSurfaceResult {
35
35
  /** True when structured fields mirror a fake adapter for schema parity only */
36
36
  schemaParityOnly?: boolean;
37
37
  /** T-CP.R.2: v8 real runtime spine result when state-backed action-closure spine ran */
38
- v8Spine?: RealRuntimeSpineResult & {
38
+ v8Spine?: Partial<RealRuntimeSpineResult> & {
39
39
  degradedReason?: string;
40
40
  };
41
41
  /** T-GVS.R.1: agent-facing impulse context artifact read pointer */
@@ -45,6 +45,8 @@ export interface HeartbeatSurfaceResult {
45
45
  capabilityClass?: string | null;
46
46
  impulseText?: string | null;
47
47
  atmosphereText?: string | null;
48
+ expressionBoundaryConstraints?: string[] | null;
49
+ expressionBoundaryStyle?: string | null;
48
50
  freshnessMs?: number;
49
51
  missingReason?: string;
50
52
  };
@@ -99,8 +101,8 @@ export interface HeartbeatCheckInput {
99
101
  /** T-OBS.R.1: shared audit sink for connector/Quiet events consumed by heartbeat_digest. */
100
102
  auditStore?: AppendOnlyAuditStore;
101
103
  /**
102
- * T-CP.R.2: when true and state DB is wired, runs the v8 real runtime action-closure spine
103
- * in addition to the v7 heartbeat loop. Produces state-backed closure/no-action records.
104
+ * T-CP.R.5: v8 living-loop spine is the default operator-facing heartbeat model.
105
+ * Explicit false can be used by legacy callers to force a carrier-only path.
104
106
  */
105
107
  v8SpineEnabled?: boolean;
106
108
  }
@@ -1,6 +1,23 @@
1
1
  import { createWorkspaceHeartbeatRunner } from "./workspace-heartbeat-runner.js";
2
2
  // T-CP.R.2: v8 real runtime spine bridge
3
3
  import { runRealRuntimeHeartbeatCycle, } from "../../core/second-nature/control-plane/real-runtime-spine.js";
4
+ async function refreshHeartbeatImpulseContext(state, now) {
5
+ const { assembleImpulseSync } = await import("../../guidance/impulse-assembler.js");
6
+ const { buildExpressionBoundary } = await import("../../guidance/output-guard.js");
7
+ const { getShortAtmosphereTemplate } = await import("../../guidance/template-registry.js");
8
+ const { writeImpulseContext } = await import("../../core/second-nature/guidance/impulse-context-writer.js");
9
+ const impulseResult = assembleImpulseSync({ sceneType: "heartbeat" });
10
+ const atmosphere = getShortAtmosphereTemplate("active", "low");
11
+ const expressionBoundary = buildExpressionBoundary("heartbeat");
12
+ const result = await writeImpulseContext(state, {
13
+ sceneType: "heartbeat",
14
+ impulseResult,
15
+ atmosphereText: atmosphere.text,
16
+ expressionBoundaryConstraints: expressionBoundary.constraints,
17
+ expressionBoundaryStyle: expressionBoundary.style,
18
+ }, { now });
19
+ return "id" in result ? result.id : undefined;
20
+ }
4
21
  function mapCycleToSurface(cycle, surfaceMode) {
5
22
  const status = cycle.status === "runtime_carrier_only"
6
23
  ? "runtime_carrier_only"
@@ -89,8 +106,9 @@ export async function heartbeatCheck(input) {
89
106
  try {
90
107
  const cycle = await run(signal);
91
108
  const surfaceResult = mapCycleToSurface(cycle, "workspace_full_runtime");
92
- // T-CP.R.2: run v8 real runtime spine when enabled and state is available
93
- if (input.v8SpineEnabled && input.state && input.workspaceRoot) {
109
+ // T-CP.R.5: v8 living-loop spine is the default operator-facing model when state is wired
110
+ const v8SpineEnabled = input.v8SpineEnabled !== false && Boolean(input.state && input.workspaceRoot);
111
+ if (v8SpineEnabled && input.state && input.workspaceRoot) {
94
112
  try {
95
113
  const v8Result = await runRealRuntimeHeartbeatCycle({
96
114
  workspaceRoot: input.workspaceRoot,
@@ -98,10 +116,10 @@ export async function heartbeatCheck(input) {
98
116
  requestedAt: timestamp,
99
117
  trigger: "host",
100
118
  });
101
- if ("status" in v8Result && v8Result.status === "degraded") {
119
+ if ("status" in v8Result && "operatorNextAction" in v8Result) {
120
+ // T-CP.R.6: degraded path must not fabricate cycleId/cycleSequence.
121
+ // Only set degradedReason; cycleId/cycleSequence remain absent.
102
122
  surfaceResult.v8Spine = {
103
- cycleId: "",
104
- cycleSequence: 0,
105
123
  degradedReason: v8Result.reason,
106
124
  };
107
125
  surfaceResult.reasons = [
@@ -111,6 +129,11 @@ export async function heartbeatCheck(input) {
111
129
  }
112
130
  else {
113
131
  const spine = v8Result;
132
+ const artifactId = await refreshHeartbeatImpulseContext(input.state, timestamp);
133
+ if (artifactId) {
134
+ spine.impulseContextArtifactId = artifactId;
135
+ surfaceResult.reasons.push(`impulse_context_refreshed:${artifactId}`);
136
+ }
114
137
  surfaceResult.v8Spine = spine;
115
138
  surfaceResult.livedExperienceLoopClaimed = Boolean(spine.cycleId && (spine.closureRef || spine.noActionReason));
116
139
  surfaceResult.reasons = [
@@ -134,7 +157,7 @@ export async function heartbeatCheck(input) {
134
157
  if (input.state) {
135
158
  try {
136
159
  const { readImpulseContext } = await import("../../core/second-nature/guidance/impulse-context-reader.js");
137
- const ctx = await readImpulseContext(input.state, "social");
160
+ const ctx = await readImpulseContext(input.state, "heartbeat");
138
161
  if (ctx.available) {
139
162
  surfaceResult.impulseContext = {
140
163
  available: true,
@@ -142,6 +165,8 @@ export async function heartbeatCheck(input) {
142
165
  capabilityClass: ctx.artifact.capabilityClass,
143
166
  impulseText: ctx.artifact.impulseText,
144
167
  atmosphereText: ctx.artifact.atmosphereText,
168
+ expressionBoundaryConstraints: ctx.artifact.expressionBoundaryConstraints,
169
+ expressionBoundaryStyle: ctx.artifact.expressionBoundaryStyle,
145
170
  freshnessMs: ctx.freshnessMs,
146
171
  };
147
172
  surfaceResult.reasons.push(`impulse_context:${ctx.artifact.id}`);
@@ -154,8 +179,13 @@ export async function heartbeatCheck(input) {
154
179
  surfaceResult.reasons.push(`impulse_context_missing:${ctx.reason}`);
155
180
  }
156
181
  }
157
- catch {
158
- // Non-fatal: impulse context is advisory
182
+ catch (readErr) {
183
+ const msg = readErr instanceof Error ? readErr.message : String(readErr);
184
+ surfaceResult.impulseContext = {
185
+ available: false,
186
+ missingReason: `read_exception:${msg.slice(0, 120)}`,
187
+ };
188
+ surfaceResult.reasons.push(`impulse_context_read_failed:${msg.slice(0, 120)}`);
159
189
  }
160
190
  }
161
191
  return surfaceResult;
@@ -1,4 +1,5 @@
1
1
  import { type HeartbeatCheckInput, type HeartbeatSurfaceResult } from "./heartbeat-surface.js";
2
+ import type { SurfaceMode } from "../runtime/runtime-artifact-boundary.js";
2
3
  import type { CliReadModels } from "../read-models/index.js";
3
4
  import type { RuntimeDecisionRecorder } from "../../observability/services/runtime-decision-recorder.js";
4
5
  import type { StateDatabase } from "../../storage/db/index.js";
@@ -12,12 +13,13 @@ import { AppendOnlyAuditStore } from "../../observability/audit/append-only-audi
12
13
  import type { RestoreSnapshotStore } from "../../storage/services/restore-snapshot-store.js";
13
14
  import type { CapabilityContractRegistry } from "../../connectors/base/manifest.js";
14
15
  import type { AffordanceAssembler } from "../../core/second-nature/body/tool-affordance/affordance-assembler.js";
15
- /** Unified response envelope for all v7 runtime-ops commands. */
16
+ import type { EvidenceLevel } from "../../shared/types/v8-contracts.js";
17
+ /** Unified response envelope for all v7/v8 runtime-ops commands. */
16
18
  export interface RuntimeOpsEnvelope<T = unknown> {
17
19
  ok: boolean;
18
20
  command: string;
19
21
  runtimeMode: "host_safe_carrier" | "workspace_full_runtime" | "unavailable";
20
- surfaceMode: "cli" | "openclaw_tool" | "plugin_command" | "cron_probe";
22
+ surfaceMode: SurfaceMode | "cli" | "openclaw_tool" | "plugin_command" | "cron_probe";
21
23
  generatedAt: string;
22
24
  data?: T;
23
25
  error?: {
@@ -27,6 +29,8 @@ export interface RuntimeOpsEnvelope<T = unknown> {
27
29
  };
28
30
  warnings: string[];
29
31
  sourceRefs: string[];
32
+ /** T-OBS.R.7: how strongly this response is backed by runtime proof. */
33
+ evidenceLevel?: EvidenceLevel;
30
34
  }
31
35
  export interface OpsRouterDeps {
32
36
  /** When true, packaged runtime artifacts resolved and full graph is loadable */