@haaaiawd/second-nature 0.1.39 → 0.1.41

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 (51) hide show
  1. package/index.js +1270 -1270
  2. package/openclaw.plugin.json +29 -29
  3. package/package.json +55 -55
  4. package/runtime/cli/commands/connector-init.js +11 -4
  5. package/runtime/cli/index.js +6 -1
  6. package/runtime/cli/ops/heartbeat-surface.d.ts +75 -75
  7. package/runtime/cli/ops/heartbeat-surface.js +97 -97
  8. package/runtime/cli/ops/ops-router.js +1428 -1428
  9. package/runtime/cli/ops/workspace-heartbeat-runner.js +236 -236
  10. package/runtime/connectors/services/connector-executor-adapter.js +192 -41
  11. package/runtime/core/second-nature/body/tool-affordance/affordance-context-scope.d.ts +1 -1
  12. package/runtime/core/second-nature/body/tool-affordance/affordance-context-scope.js +2 -1
  13. package/runtime/core/second-nature/guidance/apply-guidance.d.ts +12 -12
  14. package/runtime/core/second-nature/guidance/apply-guidance.js +15 -15
  15. package/runtime/core/second-nature/guidance/user-reply-continuity.d.ts +50 -50
  16. package/runtime/core/second-nature/guidance/user-reply-continuity.js +89 -89
  17. package/runtime/core/second-nature/orchestrator/intent-planner.js +15 -0
  18. package/runtime/core/second-nature/runtime/service-entry.d.ts +39 -39
  19. package/runtime/core/second-nature/runtime/service-entry.js +44 -44
  20. package/runtime/dream/dream-engine.d.ts +14 -14
  21. package/runtime/dream/dream-engine.js +306 -306
  22. package/runtime/dream/dream-input-loader.d.ts +37 -37
  23. package/runtime/dream/dream-input-loader.js +150 -150
  24. package/runtime/dream/dream-scheduler.d.ts +75 -75
  25. package/runtime/dream/dream-scheduler.js +131 -131
  26. package/runtime/dream/index.d.ts +16 -16
  27. package/runtime/dream/index.js +14 -14
  28. package/runtime/dream/insight-extractor.d.ts +32 -32
  29. package/runtime/dream/insight-extractor.js +135 -135
  30. package/runtime/dream/memory-consolidator.d.ts +45 -45
  31. package/runtime/dream/memory-consolidator.js +140 -140
  32. package/runtime/dream/narrative-update-proposal.d.ts +34 -34
  33. package/runtime/dream/narrative-update-proposal.js +83 -83
  34. package/runtime/dream/output-validator.d.ts +20 -20
  35. package/runtime/dream/output-validator.js +110 -110
  36. package/runtime/dream/redaction-gate.d.ts +31 -31
  37. package/runtime/dream/redaction-gate.js +109 -109
  38. package/runtime/dream/relationship-update-proposal.d.ts +27 -27
  39. package/runtime/dream/relationship-update-proposal.js +119 -119
  40. package/runtime/dream/sampler.d.ts +30 -30
  41. package/runtime/dream/sampler.js +65 -65
  42. package/runtime/dream/types.d.ts +187 -187
  43. package/runtime/dream/types.js +11 -11
  44. package/runtime/guidance/fallback.js +20 -20
  45. package/runtime/guidance/guidance-assembler.js +76 -76
  46. package/runtime/guidance/output-guard.d.ts +13 -13
  47. package/runtime/guidance/output-guard.js +53 -53
  48. package/runtime/guidance/template-registry.d.ts +20 -20
  49. package/runtime/guidance/template-registry.js +93 -93
  50. package/runtime/guidance/types.d.ts +98 -98
  51. package/runtime/observability/projections/guidance-audit.js +38 -38
@@ -1,109 +1,109 @@
1
- /**
2
- * Dream redaction gate.
3
- *
4
- * Core logic: before sending evidence to LLM, strip credential-like fields,
5
- * PII patterns, and sensitive platform payload. If redaction fails or
6
- * sensitivity is too high, block the LLM stage and record reason.
7
- * Test coverage: tests/integration/dream/t7-1-1-dream-pipeline.test.ts
8
- */
9
- const CREDENTIAL_PATTERNS = [
10
- /password\s*[:=]\s*\S+/gi,
11
- /token\s*[:=]\s*\S+/gi,
12
- /api[_-]?key\s*[:=]\s*\S+/gi,
13
- /secret\s*[:=]\s*\S+/gi,
14
- /cookie\s*[:=]\s*\S+/gi,
15
- /bearer\s+\S+/gi,
16
- ];
17
- const PII_PATTERNS = [
18
- /\b\d{3}-\d{2}-\d{4}\b/g, // SSN-like
19
- /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g, // Credit card-like
20
- /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g, // Email
21
- ];
22
- /**
23
- * Produce a RedactedEvidenceBundle brand type (DR-027).
24
- * Must be called before passing evidence to ModelAssistPort.
25
- * Returns null if redaction gate blocks the bundle.
26
- */
27
- export function redactBundle(evidence, chronicle, memory) {
28
- const result = redactDreamInput({
29
- evidenceSummaries: evidence,
30
- chronicleSummaries: chronicle,
31
- activeMemorySummaries: memory ?? [],
32
- });
33
- if (!result.allowed)
34
- return null;
35
- return {
36
- _brand: "redacted",
37
- evidence: Object.freeze(result.redactedEvidence),
38
- chronicle: Object.freeze(result.redactedChronicle),
39
- memory: result.redactedMemory.length > 0
40
- ? Object.freeze(result.redactedMemory)
41
- : undefined,
42
- };
43
- }
44
- function redactText(text) {
45
- let redacted = text;
46
- let credentialHits = 0;
47
- let piiHits = 0;
48
- for (const pattern of CREDENTIAL_PATTERNS) {
49
- const matches = redacted.match(pattern);
50
- if (matches) {
51
- credentialHits += matches.length;
52
- redacted = redacted.replace(pattern, "[REDACTED_CREDENTIAL]");
53
- }
54
- }
55
- for (const pattern of PII_PATTERNS) {
56
- const matches = redacted.match(pattern);
57
- if (matches) {
58
- piiHits += matches.length;
59
- redacted = redacted.replace(pattern, "[REDACTED_PII]");
60
- }
61
- }
62
- return { redacted, credentialHits, piiHits };
63
- }
64
- export function redactDreamInput(input) {
65
- let totalCredentialHits = 0;
66
- let totalPiiHits = 0;
67
- const redactList = (items) => items.map((item) => {
68
- const result = redactText(item);
69
- totalCredentialHits += result.credentialHits;
70
- totalPiiHits += result.piiHits;
71
- return result.redacted;
72
- });
73
- const redactedEvidence = redactList(input.evidenceSummaries);
74
- const redactedChronicle = redactList(input.chronicleSummaries);
75
- const redactedMemory = redactList(input.activeMemorySummaries ?? []);
76
- // If any sensitivity flag is "credential" or "sensitive", block LLM stage
77
- const hasHighSensitivity = (input.sensitivityFlags ?? []).some((f) => f === "credential" || f === "sensitive");
78
- if (hasHighSensitivity) {
79
- return {
80
- allowed: false,
81
- redactedEvidence,
82
- redactedChronicle,
83
- redactedMemory,
84
- blockedReason: "sensitivity_flag_blocks_llm",
85
- credentialHits: totalCredentialHits,
86
- piiHits: totalPiiHits,
87
- };
88
- }
89
- // If credential hits are excessive, also block
90
- if (totalCredentialHits > 3) {
91
- return {
92
- allowed: false,
93
- redactedEvidence,
94
- redactedChronicle,
95
- redactedMemory,
96
- blockedReason: "excessive_credential_exposure",
97
- credentialHits: totalCredentialHits,
98
- piiHits: totalPiiHits,
99
- };
100
- }
101
- return {
102
- allowed: true,
103
- redactedEvidence,
104
- redactedChronicle,
105
- redactedMemory,
106
- credentialHits: totalCredentialHits,
107
- piiHits: totalPiiHits,
108
- };
109
- }
1
+ /**
2
+ * Dream redaction gate.
3
+ *
4
+ * Core logic: before sending evidence to LLM, strip credential-like fields,
5
+ * PII patterns, and sensitive platform payload. If redaction fails or
6
+ * sensitivity is too high, block the LLM stage and record reason.
7
+ * Test coverage: tests/integration/dream/t7-1-1-dream-pipeline.test.ts
8
+ */
9
+ const CREDENTIAL_PATTERNS = [
10
+ /password\s*[:=]\s*\S+/gi,
11
+ /token\s*[:=]\s*\S+/gi,
12
+ /api[_-]?key\s*[:=]\s*\S+/gi,
13
+ /secret\s*[:=]\s*\S+/gi,
14
+ /cookie\s*[:=]\s*\S+/gi,
15
+ /bearer\s+\S+/gi,
16
+ ];
17
+ const PII_PATTERNS = [
18
+ /\b\d{3}-\d{2}-\d{4}\b/g, // SSN-like
19
+ /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g, // Credit card-like
20
+ /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g, // Email
21
+ ];
22
+ /**
23
+ * Produce a RedactedEvidenceBundle brand type (DR-027).
24
+ * Must be called before passing evidence to ModelAssistPort.
25
+ * Returns null if redaction gate blocks the bundle.
26
+ */
27
+ export function redactBundle(evidence, chronicle, memory) {
28
+ const result = redactDreamInput({
29
+ evidenceSummaries: evidence,
30
+ chronicleSummaries: chronicle,
31
+ activeMemorySummaries: memory ?? [],
32
+ });
33
+ if (!result.allowed)
34
+ return null;
35
+ return {
36
+ _brand: "redacted",
37
+ evidence: Object.freeze(result.redactedEvidence),
38
+ chronicle: Object.freeze(result.redactedChronicle),
39
+ memory: result.redactedMemory.length > 0
40
+ ? Object.freeze(result.redactedMemory)
41
+ : undefined,
42
+ };
43
+ }
44
+ function redactText(text) {
45
+ let redacted = text;
46
+ let credentialHits = 0;
47
+ let piiHits = 0;
48
+ for (const pattern of CREDENTIAL_PATTERNS) {
49
+ const matches = redacted.match(pattern);
50
+ if (matches) {
51
+ credentialHits += matches.length;
52
+ redacted = redacted.replace(pattern, "[REDACTED_CREDENTIAL]");
53
+ }
54
+ }
55
+ for (const pattern of PII_PATTERNS) {
56
+ const matches = redacted.match(pattern);
57
+ if (matches) {
58
+ piiHits += matches.length;
59
+ redacted = redacted.replace(pattern, "[REDACTED_PII]");
60
+ }
61
+ }
62
+ return { redacted, credentialHits, piiHits };
63
+ }
64
+ export function redactDreamInput(input) {
65
+ let totalCredentialHits = 0;
66
+ let totalPiiHits = 0;
67
+ const redactList = (items) => items.map((item) => {
68
+ const result = redactText(item);
69
+ totalCredentialHits += result.credentialHits;
70
+ totalPiiHits += result.piiHits;
71
+ return result.redacted;
72
+ });
73
+ const redactedEvidence = redactList(input.evidenceSummaries);
74
+ const redactedChronicle = redactList(input.chronicleSummaries);
75
+ const redactedMemory = redactList(input.activeMemorySummaries ?? []);
76
+ // If any sensitivity flag is "credential" or "sensitive", block LLM stage
77
+ const hasHighSensitivity = (input.sensitivityFlags ?? []).some((f) => f === "credential" || f === "sensitive");
78
+ if (hasHighSensitivity) {
79
+ return {
80
+ allowed: false,
81
+ redactedEvidence,
82
+ redactedChronicle,
83
+ redactedMemory,
84
+ blockedReason: "sensitivity_flag_blocks_llm",
85
+ credentialHits: totalCredentialHits,
86
+ piiHits: totalPiiHits,
87
+ };
88
+ }
89
+ // If credential hits are excessive, also block
90
+ if (totalCredentialHits > 3) {
91
+ return {
92
+ allowed: false,
93
+ redactedEvidence,
94
+ redactedChronicle,
95
+ redactedMemory,
96
+ blockedReason: "excessive_credential_exposure",
97
+ credentialHits: totalCredentialHits,
98
+ piiHits: totalPiiHits,
99
+ };
100
+ }
101
+ return {
102
+ allowed: true,
103
+ redactedEvidence,
104
+ redactedChronicle,
105
+ redactedMemory,
106
+ credentialHits: totalCredentialHits,
107
+ piiHits: totalPiiHits,
108
+ };
109
+ }
@@ -1,27 +1,27 @@
1
- /**
2
- * Relationship Update Proposal
3
- *
4
- * Core logic: generate relationship update proposal based on chronicle entries.
5
- * Tone/timing/topic deltas include sourceRefs and confidence.
6
- * Owner no-reply signal is recorded as cooldown without inventing preference.
7
- * Prevents over-inference from single samples.
8
- * Test coverage: tests/unit/dream/t7-1-5-relationship-update.test.ts
9
- */
10
- import type { DreamRelationshipUpdate } from "./types.js";
11
- export interface RelationshipProposalInput {
12
- chronicleEntries: Array<{
13
- id: string;
14
- summary: string;
15
- createdAt: string;
16
- kind?: string;
17
- }>;
18
- priorTone?: string;
19
- priorTiming?: string;
20
- priorTopic?: string;
21
- }
22
- export interface RelationshipProposalResult {
23
- proposal?: DreamRelationshipUpdate;
24
- unsupportedClaims: string[];
25
- cooldown?: boolean;
26
- }
27
- export declare function draftRelationshipFromDream(input: RelationshipProposalInput): RelationshipProposalResult;
1
+ /**
2
+ * Relationship Update Proposal
3
+ *
4
+ * Core logic: generate relationship update proposal based on chronicle entries.
5
+ * Tone/timing/topic deltas include sourceRefs and confidence.
6
+ * Owner no-reply signal is recorded as cooldown without inventing preference.
7
+ * Prevents over-inference from single samples.
8
+ * Test coverage: tests/unit/dream/t7-1-5-relationship-update.test.ts
9
+ */
10
+ import type { DreamRelationshipUpdate } from "./types.js";
11
+ export interface RelationshipProposalInput {
12
+ chronicleEntries: Array<{
13
+ id: string;
14
+ summary: string;
15
+ createdAt: string;
16
+ kind?: string;
17
+ }>;
18
+ priorTone?: string;
19
+ priorTiming?: string;
20
+ priorTopic?: string;
21
+ }
22
+ export interface RelationshipProposalResult {
23
+ proposal?: DreamRelationshipUpdate;
24
+ unsupportedClaims: string[];
25
+ cooldown?: boolean;
26
+ }
27
+ export declare function draftRelationshipFromDream(input: RelationshipProposalInput): RelationshipProposalResult;
@@ -1,119 +1,119 @@
1
- /**
2
- * Relationship Update Proposal
3
- *
4
- * Core logic: generate relationship update proposal based on chronicle entries.
5
- * Tone/timing/topic deltas include sourceRefs and confidence.
6
- * Owner no-reply signal is recorded as cooldown without inventing preference.
7
- * Prevents over-inference from single samples.
8
- * Test coverage: tests/unit/dream/t7-1-5-relationship-update.test.ts
9
- */
10
- // Keywords for tone inference
11
- const POSITIVE_TONE = [
12
- "agree", "thanks", "appreciate", "helpful", "good", "great",
13
- "love", "like", "enjoy", "excited", "happy",
14
- ];
15
- const NEGATIVE_TONE = [
16
- "disagree", "frustrated", "annoying", "bad", "hate", "dislike",
17
- "angry", "upset", "disappointed", "concerned",
18
- ];
19
- const BUSY_TIMING = [
20
- "busy", "swamped", "occupied", "tight schedule", "no time",
21
- ];
22
- // Keywords for topic inference
23
- const TOPIC_PATTERNS = {
24
- work: ["work", "project", "task", "job", "delivery", "deadline"],
25
- personal: ["family", "life", "health", "weekend", "trip"],
26
- tech: ["code", "system", "bug", "feature", "architecture", "design"],
27
- social: ["friend", "community", "meetup", "event", "collaboration"],
28
- };
29
- function inferTone(text) {
30
- const lower = text.toLowerCase();
31
- const pos = POSITIVE_TONE.filter((w) => lower.includes(w)).length;
32
- const neg = NEGATIVE_TONE.filter((w) => lower.includes(w)).length;
33
- if (pos > neg && pos > 0)
34
- return { tone: "positive", score: pos };
35
- if (neg > pos && neg > 0)
36
- return { tone: "negative", score: neg };
37
- if (pos === neg && pos > 0)
38
- return { tone: "mixed", score: pos };
39
- return { tone: "neutral", score: 0 };
40
- }
41
- function inferTiming(text) {
42
- const lower = text.toLowerCase();
43
- const busy = BUSY_TIMING.filter((w) => lower.includes(w)).length;
44
- if (busy > 0)
45
- return { timing: "busy", score: busy };
46
- // Check for quick replies (indicator in summary)
47
- if (lower.includes("quick reply") || lower.includes("prompt response")) {
48
- return { timing: "responsive", score: 1 };
49
- }
50
- return { timing: "normal", score: 0 };
51
- }
52
- function inferTopic(text) {
53
- const lower = text.toLowerCase();
54
- let bestTopic = "general";
55
- let bestScore = 0;
56
- for (const [topic, patterns] of Object.entries(TOPIC_PATTERNS)) {
57
- const score = patterns.filter((p) => lower.includes(p)).length;
58
- if (score > bestScore) {
59
- bestScore = score;
60
- bestTopic = topic;
61
- }
62
- }
63
- return { topic: bestTopic, score: bestScore };
64
- }
65
- export function draftRelationshipFromDream(input) {
66
- const unsupportedClaims = [];
67
- const replyEntries = input.chronicleEntries.filter((e) => e.kind === "owner_reply" || e.kind === "user_interaction");
68
- // No-reply signal: if no owner replies, record cooldown without inventing preference
69
- if (replyEntries.length === 0) {
70
- return {
71
- unsupportedClaims: [],
72
- cooldown: true,
73
- };
74
- }
75
- // Prevent over-inference from single sample
76
- if (replyEntries.length < 2) {
77
- unsupportedClaims.push("single_sample_insufficient_for_relationship_inference");
78
- }
79
- // Aggregate tone/timing/topic across replies
80
- const toneVotes = new Map();
81
- const timingVotes = new Map();
82
- const topicVotes = new Map();
83
- const sourceRefs = [];
84
- for (const entry of replyEntries) {
85
- const tone = inferTone(entry.summary);
86
- toneVotes.set(tone.tone, (toneVotes.get(tone.tone) ?? 0) + tone.score);
87
- const timing = inferTiming(entry.summary);
88
- timingVotes.set(timing.timing, (timingVotes.get(timing.timing) ?? 0) + timing.score);
89
- const topic = inferTopic(entry.summary);
90
- topicVotes.set(topic.topic, (topicVotes.get(topic.topic) ?? 0) + topic.score);
91
- sourceRefs.push(entry.id);
92
- }
93
- const topTone = Array.from(toneVotes.entries()).sort((a, b) => b[1] - a[1])[0];
94
- const topTiming = Array.from(timingVotes.entries()).sort((a, b) => b[1] - a[1])[0];
95
- const topTopic = Array.from(topicVotes.entries()).sort((a, b) => b[1] - a[1])[0];
96
- // Compute confidence based on sample size and signal strength
97
- const sampleSize = replyEntries.length;
98
- const signalStrength = Math.max(topTone?.[1] ?? 0, topTiming?.[1] ?? 0, topTopic?.[1] ?? 0);
99
- const confidence = Math.min(0.9, 0.3 + sampleSize * 0.05 + signalStrength * 0.05);
100
- const toneDelta = topTone && topTone[1] > 0
101
- ? `tone_observed_${topTone[0]}`
102
- : undefined;
103
- const timingDelta = topTiming && topTiming[1] > 0
104
- ? `timing_observed_${topTiming[0]}`
105
- : undefined;
106
- const topicDelta = topTopic && topTopic[1] > 0
107
- ? `topic_observed_${topTopic[0]}`
108
- : undefined;
109
- return {
110
- proposal: {
111
- toneDelta,
112
- timingDelta,
113
- topicDelta,
114
- sourceRefs: sourceRefs.slice(0, 20),
115
- confidence: Number(confidence.toFixed(2)),
116
- },
117
- unsupportedClaims,
118
- };
119
- }
1
+ /**
2
+ * Relationship Update Proposal
3
+ *
4
+ * Core logic: generate relationship update proposal based on chronicle entries.
5
+ * Tone/timing/topic deltas include sourceRefs and confidence.
6
+ * Owner no-reply signal is recorded as cooldown without inventing preference.
7
+ * Prevents over-inference from single samples.
8
+ * Test coverage: tests/unit/dream/t7-1-5-relationship-update.test.ts
9
+ */
10
+ // Keywords for tone inference
11
+ const POSITIVE_TONE = [
12
+ "agree", "thanks", "appreciate", "helpful", "good", "great",
13
+ "love", "like", "enjoy", "excited", "happy",
14
+ ];
15
+ const NEGATIVE_TONE = [
16
+ "disagree", "frustrated", "annoying", "bad", "hate", "dislike",
17
+ "angry", "upset", "disappointed", "concerned",
18
+ ];
19
+ const BUSY_TIMING = [
20
+ "busy", "swamped", "occupied", "tight schedule", "no time",
21
+ ];
22
+ // Keywords for topic inference
23
+ const TOPIC_PATTERNS = {
24
+ work: ["work", "project", "task", "job", "delivery", "deadline"],
25
+ personal: ["family", "life", "health", "weekend", "trip"],
26
+ tech: ["code", "system", "bug", "feature", "architecture", "design"],
27
+ social: ["friend", "community", "meetup", "event", "collaboration"],
28
+ };
29
+ function inferTone(text) {
30
+ const lower = text.toLowerCase();
31
+ const pos = POSITIVE_TONE.filter((w) => lower.includes(w)).length;
32
+ const neg = NEGATIVE_TONE.filter((w) => lower.includes(w)).length;
33
+ if (pos > neg && pos > 0)
34
+ return { tone: "positive", score: pos };
35
+ if (neg > pos && neg > 0)
36
+ return { tone: "negative", score: neg };
37
+ if (pos === neg && pos > 0)
38
+ return { tone: "mixed", score: pos };
39
+ return { tone: "neutral", score: 0 };
40
+ }
41
+ function inferTiming(text) {
42
+ const lower = text.toLowerCase();
43
+ const busy = BUSY_TIMING.filter((w) => lower.includes(w)).length;
44
+ if (busy > 0)
45
+ return { timing: "busy", score: busy };
46
+ // Check for quick replies (indicator in summary)
47
+ if (lower.includes("quick reply") || lower.includes("prompt response")) {
48
+ return { timing: "responsive", score: 1 };
49
+ }
50
+ return { timing: "normal", score: 0 };
51
+ }
52
+ function inferTopic(text) {
53
+ const lower = text.toLowerCase();
54
+ let bestTopic = "general";
55
+ let bestScore = 0;
56
+ for (const [topic, patterns] of Object.entries(TOPIC_PATTERNS)) {
57
+ const score = patterns.filter((p) => lower.includes(p)).length;
58
+ if (score > bestScore) {
59
+ bestScore = score;
60
+ bestTopic = topic;
61
+ }
62
+ }
63
+ return { topic: bestTopic, score: bestScore };
64
+ }
65
+ export function draftRelationshipFromDream(input) {
66
+ const unsupportedClaims = [];
67
+ const replyEntries = input.chronicleEntries.filter((e) => e.kind === "owner_reply" || e.kind === "user_interaction");
68
+ // No-reply signal: if no owner replies, record cooldown without inventing preference
69
+ if (replyEntries.length === 0) {
70
+ return {
71
+ unsupportedClaims: [],
72
+ cooldown: true,
73
+ };
74
+ }
75
+ // Prevent over-inference from single sample
76
+ if (replyEntries.length < 2) {
77
+ unsupportedClaims.push("single_sample_insufficient_for_relationship_inference");
78
+ }
79
+ // Aggregate tone/timing/topic across replies
80
+ const toneVotes = new Map();
81
+ const timingVotes = new Map();
82
+ const topicVotes = new Map();
83
+ const sourceRefs = [];
84
+ for (const entry of replyEntries) {
85
+ const tone = inferTone(entry.summary);
86
+ toneVotes.set(tone.tone, (toneVotes.get(tone.tone) ?? 0) + tone.score);
87
+ const timing = inferTiming(entry.summary);
88
+ timingVotes.set(timing.timing, (timingVotes.get(timing.timing) ?? 0) + timing.score);
89
+ const topic = inferTopic(entry.summary);
90
+ topicVotes.set(topic.topic, (topicVotes.get(topic.topic) ?? 0) + topic.score);
91
+ sourceRefs.push(entry.id);
92
+ }
93
+ const topTone = Array.from(toneVotes.entries()).sort((a, b) => b[1] - a[1])[0];
94
+ const topTiming = Array.from(timingVotes.entries()).sort((a, b) => b[1] - a[1])[0];
95
+ const topTopic = Array.from(topicVotes.entries()).sort((a, b) => b[1] - a[1])[0];
96
+ // Compute confidence based on sample size and signal strength
97
+ const sampleSize = replyEntries.length;
98
+ const signalStrength = Math.max(topTone?.[1] ?? 0, topTiming?.[1] ?? 0, topTopic?.[1] ?? 0);
99
+ const confidence = Math.min(0.9, 0.3 + sampleSize * 0.05 + signalStrength * 0.05);
100
+ const toneDelta = topTone && topTone[1] > 0
101
+ ? `tone_observed_${topTone[0]}`
102
+ : undefined;
103
+ const timingDelta = topTiming && topTiming[1] > 0
104
+ ? `timing_observed_${topTiming[0]}`
105
+ : undefined;
106
+ const topicDelta = topTopic && topTopic[1] > 0
107
+ ? `topic_observed_${topTopic[0]}`
108
+ : undefined;
109
+ return {
110
+ proposal: {
111
+ toneDelta,
112
+ timingDelta,
113
+ topicDelta,
114
+ sourceRefs: sourceRefs.slice(0, 20),
115
+ confidence: Number(confidence.toFixed(2)),
116
+ },
117
+ unsupportedClaims,
118
+ };
119
+ }
@@ -1,30 +1,30 @@
1
- /**
2
- * Dream input sampler.
3
- *
4
- * Core logic: when evidence count exceeds threshold, sample recent 7 days
5
- * plus key events (outreach, owner reply, goal milestone, high-confidence refs).
6
- * Goal: prevent token/cost explosion before LLM stage.
7
- * Test coverage: tests/integration/dream/t7-1-1-dream-pipeline.test.ts
8
- */
9
- export interface SamplerInput {
10
- evidenceSummaries: Array<{
11
- id: string;
12
- summary: string;
13
- createdAt: string;
14
- kind?: string;
15
- confidence?: number;
16
- }>;
17
- chronicleSummaries: Array<{
18
- id: string;
19
- summary: string;
20
- createdAt: string;
21
- }>;
22
- evidenceLimit?: number;
23
- }
24
- export interface SamplerResult {
25
- sampledEvidenceIds: string[];
26
- sampledChronicleIds: string[];
27
- droppedCount: number;
28
- reason: string;
29
- }
30
- export declare function sampleDreamInput(input: SamplerInput): SamplerResult;
1
+ /**
2
+ * Dream input sampler.
3
+ *
4
+ * Core logic: when evidence count exceeds threshold, sample recent 7 days
5
+ * plus key events (outreach, owner reply, goal milestone, high-confidence refs).
6
+ * Goal: prevent token/cost explosion before LLM stage.
7
+ * Test coverage: tests/integration/dream/t7-1-1-dream-pipeline.test.ts
8
+ */
9
+ export interface SamplerInput {
10
+ evidenceSummaries: Array<{
11
+ id: string;
12
+ summary: string;
13
+ createdAt: string;
14
+ kind?: string;
15
+ confidence?: number;
16
+ }>;
17
+ chronicleSummaries: Array<{
18
+ id: string;
19
+ summary: string;
20
+ createdAt: string;
21
+ }>;
22
+ evidenceLimit?: number;
23
+ }
24
+ export interface SamplerResult {
25
+ sampledEvidenceIds: string[];
26
+ sampledChronicleIds: string[];
27
+ droppedCount: number;
28
+ reason: string;
29
+ }
30
+ export declare function sampleDreamInput(input: SamplerInput): SamplerResult;