@haaaiawd/second-nature 0.1.21 → 0.1.23

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 (73) hide show
  1. package/openclaw.plugin.json +1 -1
  2. package/package.json +1 -1
  3. package/runtime/cli/commands/connector-init.d.ts +19 -0
  4. package/runtime/cli/commands/connector-init.js +168 -0
  5. package/runtime/cli/commands/connector-status.d.ts +12 -0
  6. package/runtime/cli/commands/connector-status.js +156 -0
  7. package/runtime/cli/commands/index.js +40 -0
  8. package/runtime/cli/index.js +8 -6
  9. package/runtime/cli/ops/ops-router.d.ts +5 -0
  10. package/runtime/cli/ops/ops-router.js +34 -0
  11. package/runtime/cli/ops/workspace-heartbeat-runner.js +22 -0
  12. package/runtime/connectors/base/manifest.d.ts +13 -0
  13. package/runtime/connectors/base/manifest.js +47 -0
  14. package/runtime/connectors/manifest/manifest-parser.d.ts +16 -0
  15. package/runtime/connectors/manifest/manifest-parser.js +35 -0
  16. package/runtime/connectors/manifest/manifest-schema.d.ts +145 -0
  17. package/runtime/connectors/manifest/manifest-schema.js +51 -0
  18. package/runtime/connectors/registry/dynamic-connector-registry.d.ts +29 -0
  19. package/runtime/connectors/registry/dynamic-connector-registry.js +123 -0
  20. package/runtime/connectors/registry/index.d.ts +3 -0
  21. package/runtime/connectors/registry/index.js +3 -0
  22. package/runtime/connectors/registry/manifest-scanner.d.ts +9 -0
  23. package/runtime/connectors/registry/manifest-scanner.js +29 -0
  24. package/runtime/connectors/registry/trust-policy.d.ts +13 -0
  25. package/runtime/connectors/registry/trust-policy.js +37 -0
  26. package/runtime/core/second-nature/heartbeat/heartbeat-loop.d.ts +3 -0
  27. package/runtime/core/second-nature/heartbeat/heartbeat-loop.js +52 -1
  28. package/runtime/core/second-nature/heartbeat/snapshot-builder.d.ts +3 -0
  29. package/runtime/core/second-nature/orchestrator/goal-priority.d.ts +19 -0
  30. package/runtime/core/second-nature/orchestrator/goal-priority.js +67 -0
  31. package/runtime/core/second-nature/orchestrator/intent-planner.js +8 -0
  32. package/runtime/core/second-nature/orchestrator/narrative-update.d.ts +27 -0
  33. package/runtime/core/second-nature/orchestrator/narrative-update.js +107 -0
  34. package/runtime/core/second-nature/runtime/service-entry.js +1 -1
  35. package/runtime/core/second-nature/types.d.ts +4 -0
  36. package/runtime/guidance/draft-narrative-outreach.d.ts +36 -0
  37. package/runtime/guidance/draft-narrative-outreach.js +84 -0
  38. package/runtime/guidance/index.d.ts +1 -0
  39. package/runtime/guidance/index.js +1 -0
  40. package/runtime/guidance/outreach-draft-schema.d.ts +3 -3
  41. package/runtime/observability/connector-inventory-ledger.d.ts +45 -0
  42. package/runtime/observability/connector-inventory-ledger.js +72 -0
  43. package/runtime/observability/db/index.js +13 -0
  44. package/runtime/observability/db/schema/connector-inventory.d.ts +174 -0
  45. package/runtime/observability/db/schema/connector-inventory.js +15 -0
  46. package/runtime/observability/db/schema/index.d.ts +1 -0
  47. package/runtime/observability/db/schema/index.js +1 -0
  48. package/runtime/storage/chronicle/session-chronicle-store.d.ts +42 -0
  49. package/runtime/storage/chronicle/session-chronicle-store.js +66 -0
  50. package/runtime/storage/db/index.js +75 -0
  51. package/runtime/storage/db/schema/agent-goal.d.ts +235 -0
  52. package/runtime/storage/db/schema/agent-goal.js +19 -0
  53. package/runtime/storage/db/schema/index.d.ts +5 -0
  54. package/runtime/storage/db/schema/index.js +5 -0
  55. package/runtime/storage/db/schema/memory-store.d.ts +199 -0
  56. package/runtime/storage/db/schema/memory-store.js +18 -0
  57. package/runtime/storage/db/schema/narrative-state.d.ts +195 -0
  58. package/runtime/storage/db/schema/narrative-state.js +16 -0
  59. package/runtime/storage/db/schema/relationship-memory.d.ts +174 -0
  60. package/runtime/storage/db/schema/relationship-memory.js +14 -0
  61. package/runtime/storage/db/schema/session-chronicle.d.ts +199 -0
  62. package/runtime/storage/db/schema/session-chronicle.js +18 -0
  63. package/runtime/storage/goal/agent-goal-store.d.ts +57 -0
  64. package/runtime/storage/goal/agent-goal-store.js +109 -0
  65. package/runtime/storage/index.d.ts +5 -0
  66. package/runtime/storage/index.js +5 -0
  67. package/runtime/storage/memory-store/memory-store-lifecycle.d.ts +70 -0
  68. package/runtime/storage/memory-store/memory-store-lifecycle.js +113 -0
  69. package/runtime/storage/narrative/narrative-state-store.d.ts +40 -0
  70. package/runtime/storage/narrative/narrative-state-store.js +79 -0
  71. package/runtime/storage/relationship/relationship-memory-store.d.ts +42 -0
  72. package/runtime/storage/relationship/relationship-memory-store.js +76 -0
  73. package/workspace-ops-bridge.js +1 -0
@@ -0,0 +1,79 @@
1
+ import { eq } from "drizzle-orm";
2
+ import { narrativeState } from "../db/schema/narrative-state.js";
3
+ function safeParseJson(json, fallback) {
4
+ try {
5
+ return JSON.parse(json);
6
+ }
7
+ catch {
8
+ return fallback;
9
+ }
10
+ }
11
+ function rowToState(row) {
12
+ return {
13
+ narrativeId: row.narrativeId,
14
+ revision: row.revision,
15
+ focus: row.focus,
16
+ progress: safeParseJson(row.progressJson, []),
17
+ nextIntent: row.nextIntent,
18
+ confidence: row.confidence,
19
+ sourceRefs: safeParseJson(row.sourceRefsJson, []),
20
+ unsupportedClaims: safeParseJson(row.unsupportedClaimsJson, []),
21
+ status: row.status,
22
+ updatedAt: row.updatedAt,
23
+ };
24
+ }
25
+ const DEFAULT_NARRATIVE_ID = "default";
26
+ export function createNarrativeStateStore(database) {
27
+ const db = database.db;
28
+ return {
29
+ async updateNarrativeState(input) {
30
+ const existing = await db
31
+ .select()
32
+ .from(narrativeState)
33
+ .where(eq(narrativeState.narrativeId, input.narrativeId))
34
+ .limit(1);
35
+ if (existing.length > 0) {
36
+ await db
37
+ .update(narrativeState)
38
+ .set({
39
+ revision: input.revision,
40
+ focus: input.focus,
41
+ progressJson: JSON.stringify(input.progress),
42
+ nextIntent: input.nextIntent,
43
+ confidence: input.confidence,
44
+ sourceRefsJson: JSON.stringify(input.sourceRefs),
45
+ unsupportedClaimsJson: JSON.stringify(input.unsupportedClaims),
46
+ status: input.status,
47
+ updatedAt: input.updatedAt,
48
+ })
49
+ .where(eq(narrativeState.narrativeId, input.narrativeId));
50
+ }
51
+ else {
52
+ await db.insert(narrativeState).values({
53
+ narrativeId: input.narrativeId,
54
+ revision: input.revision,
55
+ focus: input.focus,
56
+ progressJson: JSON.stringify(input.progress),
57
+ nextIntent: input.nextIntent,
58
+ confidence: input.confidence,
59
+ sourceRefsJson: JSON.stringify(input.sourceRefs),
60
+ unsupportedClaimsJson: JSON.stringify(input.unsupportedClaims),
61
+ status: input.status,
62
+ updatedAt: input.updatedAt,
63
+ });
64
+ }
65
+ return { narrativeId: input.narrativeId, status: "acknowledged" };
66
+ },
67
+ async loadNarrativeState(narrativeId) {
68
+ const id = narrativeId ?? DEFAULT_NARRATIVE_ID;
69
+ const rows = await db
70
+ .select()
71
+ .from(narrativeState)
72
+ .where(eq(narrativeState.narrativeId, id))
73
+ .limit(1);
74
+ if (rows.length === 0)
75
+ return null;
76
+ return rowToState(rows[0]);
77
+ },
78
+ };
79
+ }
@@ -0,0 +1,42 @@
1
+ import type { StateDatabase } from "../db/index.js";
2
+ export interface SourceRef {
3
+ sourceId: string;
4
+ kind: string;
5
+ url?: string;
6
+ snippet?: string;
7
+ }
8
+ export interface TopicAffinity {
9
+ topic: string;
10
+ affinity: number;
11
+ }
12
+ export interface RelationshipMemory {
13
+ relationshipId: string;
14
+ revision: number;
15
+ tonePreference: "casual" | "direct" | "quiet" | "unknown";
16
+ averageReplyDelayMinutes?: number;
17
+ noReplyCount: number;
18
+ topicAffinities: TopicAffinity[];
19
+ lastInteractionAt?: string;
20
+ sourceRefs: SourceRef[];
21
+ updatedAt: string;
22
+ }
23
+ export interface RelationshipMemoryUpdate {
24
+ relationshipId: string;
25
+ revision: number;
26
+ tonePreference: "casual" | "direct" | "quiet" | "unknown";
27
+ averageReplyDelayMinutes?: number;
28
+ noReplyCount: number;
29
+ topicAffinities: TopicAffinity[];
30
+ lastInteractionAt?: string;
31
+ sourceRefs: SourceRef[];
32
+ updatedAt: string;
33
+ }
34
+ export interface RelationshipMemoryWriteAck {
35
+ relationshipId: string;
36
+ status: "acknowledged" | "degraded";
37
+ }
38
+ export interface RelationshipMemoryStore {
39
+ upsertRelationshipMemory(input: RelationshipMemoryUpdate): Promise<RelationshipMemoryWriteAck>;
40
+ loadRelationshipMemory(relationshipId?: string): Promise<RelationshipMemory | null>;
41
+ }
42
+ export declare function createRelationshipMemoryStore(database: StateDatabase): RelationshipMemoryStore;
@@ -0,0 +1,76 @@
1
+ import { eq } from "drizzle-orm";
2
+ import { relationshipMemory } from "../db/schema/relationship-memory.js";
3
+ function safeParseJson(json, fallback) {
4
+ try {
5
+ return JSON.parse(json);
6
+ }
7
+ catch {
8
+ return fallback;
9
+ }
10
+ }
11
+ function rowToMemory(row) {
12
+ return {
13
+ relationshipId: row.relationshipId,
14
+ revision: row.revision,
15
+ tonePreference: row.tonePreference,
16
+ averageReplyDelayMinutes: row.averageReplyDelayMinutes ?? undefined,
17
+ noReplyCount: row.noReplyCount,
18
+ topicAffinities: safeParseJson(row.topicAffinitiesJson, []),
19
+ lastInteractionAt: row.lastInteractionAt ?? undefined,
20
+ sourceRefs: safeParseJson(row.sourceRefsJson, []),
21
+ updatedAt: row.updatedAt,
22
+ };
23
+ }
24
+ const DEFAULT_RELATIONSHIP_ID = "default";
25
+ export function createRelationshipMemoryStore(database) {
26
+ const db = database.db;
27
+ return {
28
+ async upsertRelationshipMemory(input) {
29
+ const existing = await db
30
+ .select()
31
+ .from(relationshipMemory)
32
+ .where(eq(relationshipMemory.relationshipId, input.relationshipId))
33
+ .limit(1);
34
+ if (existing.length > 0) {
35
+ await db
36
+ .update(relationshipMemory)
37
+ .set({
38
+ revision: input.revision,
39
+ tonePreference: input.tonePreference,
40
+ averageReplyDelayMinutes: input.averageReplyDelayMinutes ?? null,
41
+ noReplyCount: input.noReplyCount,
42
+ topicAffinitiesJson: JSON.stringify(input.topicAffinities),
43
+ lastInteractionAt: input.lastInteractionAt ?? null,
44
+ sourceRefsJson: JSON.stringify(input.sourceRefs),
45
+ updatedAt: input.updatedAt,
46
+ })
47
+ .where(eq(relationshipMemory.relationshipId, input.relationshipId));
48
+ }
49
+ else {
50
+ await db.insert(relationshipMemory).values({
51
+ relationshipId: input.relationshipId,
52
+ revision: input.revision,
53
+ tonePreference: input.tonePreference,
54
+ averageReplyDelayMinutes: input.averageReplyDelayMinutes ?? null,
55
+ noReplyCount: input.noReplyCount,
56
+ topicAffinitiesJson: JSON.stringify(input.topicAffinities),
57
+ lastInteractionAt: input.lastInteractionAt ?? null,
58
+ sourceRefsJson: JSON.stringify(input.sourceRefs),
59
+ updatedAt: input.updatedAt,
60
+ });
61
+ }
62
+ return { relationshipId: input.relationshipId, status: "acknowledged" };
63
+ },
64
+ async loadRelationshipMemory(relationshipId) {
65
+ const id = relationshipId ?? DEFAULT_RELATIONSHIP_ID;
66
+ const rows = await db
67
+ .select()
68
+ .from(relationshipMemory)
69
+ .where(eq(relationshipMemory.relationshipId, id))
70
+ .limit(1);
71
+ if (rows.length === 0)
72
+ return null;
73
+ return rowToMemory(rows[0]);
74
+ },
75
+ };
76
+ }
@@ -46,6 +46,7 @@ export async function openWorkspaceOpsBridge(workspaceRoot) {
46
46
  observabilityDb,
47
47
  state: stateDb,
48
48
  workspaceRoot: resolvedRoot,
49
+ connectorExecutor: deps.connectorExecutor,
49
50
  });
50
51
  const commands = commandsMod.createCliCommands({
51
52
  readModels: deps.readModels,