@haaaiawd/second-nature 0.1.22 → 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.
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/runtime/cli/commands/connector-init.d.ts +19 -0
- package/runtime/cli/commands/connector-init.js +168 -0
- package/runtime/cli/commands/connector-status.d.ts +12 -0
- package/runtime/cli/commands/connector-status.js +156 -0
- package/runtime/cli/commands/index.js +40 -0
- package/runtime/cli/ops/ops-router.d.ts +5 -0
- package/runtime/cli/ops/ops-router.js +34 -0
- package/runtime/cli/ops/workspace-heartbeat-runner.js +22 -0
- package/runtime/connectors/base/manifest.d.ts +13 -0
- package/runtime/connectors/base/manifest.js +47 -0
- package/runtime/connectors/manifest/manifest-parser.d.ts +16 -0
- package/runtime/connectors/manifest/manifest-parser.js +35 -0
- package/runtime/connectors/manifest/manifest-schema.d.ts +145 -0
- package/runtime/connectors/manifest/manifest-schema.js +51 -0
- package/runtime/connectors/registry/dynamic-connector-registry.d.ts +29 -0
- package/runtime/connectors/registry/dynamic-connector-registry.js +123 -0
- package/runtime/connectors/registry/index.d.ts +3 -0
- package/runtime/connectors/registry/index.js +3 -0
- package/runtime/connectors/registry/manifest-scanner.d.ts +9 -0
- package/runtime/connectors/registry/manifest-scanner.js +29 -0
- package/runtime/connectors/registry/trust-policy.d.ts +13 -0
- package/runtime/connectors/registry/trust-policy.js +37 -0
- package/runtime/core/second-nature/heartbeat/heartbeat-loop.d.ts +3 -0
- package/runtime/core/second-nature/heartbeat/heartbeat-loop.js +52 -1
- package/runtime/core/second-nature/heartbeat/snapshot-builder.d.ts +3 -0
- package/runtime/core/second-nature/orchestrator/goal-priority.d.ts +19 -0
- package/runtime/core/second-nature/orchestrator/goal-priority.js +67 -0
- package/runtime/core/second-nature/orchestrator/intent-planner.js +8 -0
- package/runtime/core/second-nature/orchestrator/narrative-update.d.ts +27 -0
- package/runtime/core/second-nature/orchestrator/narrative-update.js +107 -0
- package/runtime/core/second-nature/types.d.ts +4 -0
- package/runtime/guidance/draft-narrative-outreach.d.ts +36 -0
- package/runtime/guidance/draft-narrative-outreach.js +84 -0
- package/runtime/guidance/index.d.ts +1 -0
- package/runtime/guidance/index.js +1 -0
- package/runtime/guidance/outreach-draft-schema.d.ts +3 -3
- package/runtime/observability/connector-inventory-ledger.d.ts +45 -0
- package/runtime/observability/connector-inventory-ledger.js +72 -0
- package/runtime/observability/db/index.js +13 -0
- package/runtime/observability/db/schema/connector-inventory.d.ts +174 -0
- package/runtime/observability/db/schema/connector-inventory.js +15 -0
- package/runtime/observability/db/schema/index.d.ts +1 -0
- package/runtime/observability/db/schema/index.js +1 -0
- package/runtime/storage/chronicle/session-chronicle-store.d.ts +42 -0
- package/runtime/storage/chronicle/session-chronicle-store.js +66 -0
- package/runtime/storage/db/index.js +75 -0
- package/runtime/storage/db/schema/agent-goal.d.ts +235 -0
- package/runtime/storage/db/schema/agent-goal.js +19 -0
- package/runtime/storage/db/schema/index.d.ts +5 -0
- package/runtime/storage/db/schema/index.js +5 -0
- package/runtime/storage/db/schema/memory-store.d.ts +199 -0
- package/runtime/storage/db/schema/memory-store.js +18 -0
- package/runtime/storage/db/schema/narrative-state.d.ts +195 -0
- package/runtime/storage/db/schema/narrative-state.js +16 -0
- package/runtime/storage/db/schema/relationship-memory.d.ts +174 -0
- package/runtime/storage/db/schema/relationship-memory.js +14 -0
- package/runtime/storage/db/schema/session-chronicle.d.ts +199 -0
- package/runtime/storage/db/schema/session-chronicle.js +18 -0
- package/runtime/storage/goal/agent-goal-store.d.ts +57 -0
- package/runtime/storage/goal/agent-goal-store.js +109 -0
- package/runtime/storage/index.d.ts +5 -0
- package/runtime/storage/index.js +5 -0
- package/runtime/storage/memory-store/memory-store-lifecycle.d.ts +70 -0
- package/runtime/storage/memory-store/memory-store-lifecycle.js +113 -0
- package/runtime/storage/narrative/narrative-state-store.d.ts +40 -0
- package/runtime/storage/narrative/narrative-state-store.js +79 -0
- package/runtime/storage/relationship/relationship-memory-store.d.ts +42 -0
- package/runtime/storage/relationship/relationship-memory-store.js +76 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
export declare const sessionChronicle: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
2
|
+
name: "session_chronicle";
|
|
3
|
+
schema: undefined;
|
|
4
|
+
columns: {
|
|
5
|
+
entryId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
6
|
+
name: "entry_id";
|
|
7
|
+
tableName: "session_chronicle";
|
|
8
|
+
dataType: "string";
|
|
9
|
+
columnType: "SQLiteText";
|
|
10
|
+
data: string;
|
|
11
|
+
driverParam: string;
|
|
12
|
+
notNull: true;
|
|
13
|
+
hasDefault: false;
|
|
14
|
+
isPrimaryKey: true;
|
|
15
|
+
isAutoincrement: false;
|
|
16
|
+
hasRuntimeDefault: false;
|
|
17
|
+
enumValues: [string, ...string[]];
|
|
18
|
+
baseColumn: never;
|
|
19
|
+
identity: undefined;
|
|
20
|
+
generated: undefined;
|
|
21
|
+
}, {}, {
|
|
22
|
+
length: number | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
eventKind: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
25
|
+
name: "event_kind";
|
|
26
|
+
tableName: "session_chronicle";
|
|
27
|
+
dataType: "string";
|
|
28
|
+
columnType: "SQLiteText";
|
|
29
|
+
data: string;
|
|
30
|
+
driverParam: string;
|
|
31
|
+
notNull: true;
|
|
32
|
+
hasDefault: false;
|
|
33
|
+
isPrimaryKey: false;
|
|
34
|
+
isAutoincrement: false;
|
|
35
|
+
hasRuntimeDefault: false;
|
|
36
|
+
enumValues: [string, ...string[]];
|
|
37
|
+
baseColumn: never;
|
|
38
|
+
identity: undefined;
|
|
39
|
+
generated: undefined;
|
|
40
|
+
}, {}, {
|
|
41
|
+
length: number | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
actor: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
44
|
+
name: "actor";
|
|
45
|
+
tableName: "session_chronicle";
|
|
46
|
+
dataType: "string";
|
|
47
|
+
columnType: "SQLiteText";
|
|
48
|
+
data: string;
|
|
49
|
+
driverParam: string;
|
|
50
|
+
notNull: true;
|
|
51
|
+
hasDefault: false;
|
|
52
|
+
isPrimaryKey: false;
|
|
53
|
+
isAutoincrement: false;
|
|
54
|
+
hasRuntimeDefault: false;
|
|
55
|
+
enumValues: [string, ...string[]];
|
|
56
|
+
baseColumn: never;
|
|
57
|
+
identity: undefined;
|
|
58
|
+
generated: undefined;
|
|
59
|
+
}, {}, {
|
|
60
|
+
length: number | undefined;
|
|
61
|
+
}>;
|
|
62
|
+
occurredAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
63
|
+
name: "occurred_at";
|
|
64
|
+
tableName: "session_chronicle";
|
|
65
|
+
dataType: "string";
|
|
66
|
+
columnType: "SQLiteText";
|
|
67
|
+
data: string;
|
|
68
|
+
driverParam: string;
|
|
69
|
+
notNull: true;
|
|
70
|
+
hasDefault: false;
|
|
71
|
+
isPrimaryKey: false;
|
|
72
|
+
isAutoincrement: false;
|
|
73
|
+
hasRuntimeDefault: false;
|
|
74
|
+
enumValues: [string, ...string[]];
|
|
75
|
+
baseColumn: never;
|
|
76
|
+
identity: undefined;
|
|
77
|
+
generated: undefined;
|
|
78
|
+
}, {}, {
|
|
79
|
+
length: number | undefined;
|
|
80
|
+
}>;
|
|
81
|
+
summary: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
82
|
+
name: "summary";
|
|
83
|
+
tableName: "session_chronicle";
|
|
84
|
+
dataType: "string";
|
|
85
|
+
columnType: "SQLiteText";
|
|
86
|
+
data: string;
|
|
87
|
+
driverParam: string;
|
|
88
|
+
notNull: true;
|
|
89
|
+
hasDefault: false;
|
|
90
|
+
isPrimaryKey: false;
|
|
91
|
+
isAutoincrement: false;
|
|
92
|
+
hasRuntimeDefault: false;
|
|
93
|
+
enumValues: [string, ...string[]];
|
|
94
|
+
baseColumn: never;
|
|
95
|
+
identity: undefined;
|
|
96
|
+
generated: undefined;
|
|
97
|
+
}, {}, {
|
|
98
|
+
length: number | undefined;
|
|
99
|
+
}>;
|
|
100
|
+
result: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
101
|
+
name: "result";
|
|
102
|
+
tableName: "session_chronicle";
|
|
103
|
+
dataType: "string";
|
|
104
|
+
columnType: "SQLiteText";
|
|
105
|
+
data: string;
|
|
106
|
+
driverParam: string;
|
|
107
|
+
notNull: true;
|
|
108
|
+
hasDefault: false;
|
|
109
|
+
isPrimaryKey: false;
|
|
110
|
+
isAutoincrement: false;
|
|
111
|
+
hasRuntimeDefault: false;
|
|
112
|
+
enumValues: [string, ...string[]];
|
|
113
|
+
baseColumn: never;
|
|
114
|
+
identity: undefined;
|
|
115
|
+
generated: undefined;
|
|
116
|
+
}, {}, {
|
|
117
|
+
length: number | undefined;
|
|
118
|
+
}>;
|
|
119
|
+
sourceRefsJson: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
120
|
+
name: "source_refs_json";
|
|
121
|
+
tableName: "session_chronicle";
|
|
122
|
+
dataType: "string";
|
|
123
|
+
columnType: "SQLiteText";
|
|
124
|
+
data: string;
|
|
125
|
+
driverParam: string;
|
|
126
|
+
notNull: true;
|
|
127
|
+
hasDefault: false;
|
|
128
|
+
isPrimaryKey: false;
|
|
129
|
+
isAutoincrement: false;
|
|
130
|
+
hasRuntimeDefault: false;
|
|
131
|
+
enumValues: [string, ...string[]];
|
|
132
|
+
baseColumn: never;
|
|
133
|
+
identity: undefined;
|
|
134
|
+
generated: undefined;
|
|
135
|
+
}, {}, {
|
|
136
|
+
length: number | undefined;
|
|
137
|
+
}>;
|
|
138
|
+
relatedDecisionId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
139
|
+
name: "related_decision_id";
|
|
140
|
+
tableName: "session_chronicle";
|
|
141
|
+
dataType: "string";
|
|
142
|
+
columnType: "SQLiteText";
|
|
143
|
+
data: string;
|
|
144
|
+
driverParam: string;
|
|
145
|
+
notNull: false;
|
|
146
|
+
hasDefault: false;
|
|
147
|
+
isPrimaryKey: false;
|
|
148
|
+
isAutoincrement: false;
|
|
149
|
+
hasRuntimeDefault: false;
|
|
150
|
+
enumValues: [string, ...string[]];
|
|
151
|
+
baseColumn: never;
|
|
152
|
+
identity: undefined;
|
|
153
|
+
generated: undefined;
|
|
154
|
+
}, {}, {
|
|
155
|
+
length: number | undefined;
|
|
156
|
+
}>;
|
|
157
|
+
relatedDreamRunId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
158
|
+
name: "related_dream_run_id";
|
|
159
|
+
tableName: "session_chronicle";
|
|
160
|
+
dataType: "string";
|
|
161
|
+
columnType: "SQLiteText";
|
|
162
|
+
data: string;
|
|
163
|
+
driverParam: string;
|
|
164
|
+
notNull: false;
|
|
165
|
+
hasDefault: false;
|
|
166
|
+
isPrimaryKey: false;
|
|
167
|
+
isAutoincrement: false;
|
|
168
|
+
hasRuntimeDefault: false;
|
|
169
|
+
enumValues: [string, ...string[]];
|
|
170
|
+
baseColumn: never;
|
|
171
|
+
identity: undefined;
|
|
172
|
+
generated: undefined;
|
|
173
|
+
}, {}, {
|
|
174
|
+
length: number | undefined;
|
|
175
|
+
}>;
|
|
176
|
+
ownerReplyJson: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
177
|
+
name: "owner_reply_json";
|
|
178
|
+
tableName: "session_chronicle";
|
|
179
|
+
dataType: "string";
|
|
180
|
+
columnType: "SQLiteText";
|
|
181
|
+
data: string;
|
|
182
|
+
driverParam: string;
|
|
183
|
+
notNull: false;
|
|
184
|
+
hasDefault: false;
|
|
185
|
+
isPrimaryKey: false;
|
|
186
|
+
isAutoincrement: false;
|
|
187
|
+
hasRuntimeDefault: false;
|
|
188
|
+
enumValues: [string, ...string[]];
|
|
189
|
+
baseColumn: never;
|
|
190
|
+
identity: undefined;
|
|
191
|
+
generated: undefined;
|
|
192
|
+
}, {}, {
|
|
193
|
+
length: number | undefined;
|
|
194
|
+
}>;
|
|
195
|
+
};
|
|
196
|
+
dialect: "sqlite";
|
|
197
|
+
}>;
|
|
198
|
+
export type SessionChronicleRow = typeof sessionChronicle.$inferSelect;
|
|
199
|
+
export type NewSessionChronicleRow = typeof sessionChronicle.$inferInsert;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { index, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
2
|
+
export const sessionChronicle = sqliteTable("session_chronicle", {
|
|
3
|
+
entryId: text("entry_id").primaryKey(),
|
|
4
|
+
eventKind: text("event_kind").notNull(),
|
|
5
|
+
actor: text("actor").notNull(),
|
|
6
|
+
occurredAt: text("occurred_at").notNull(),
|
|
7
|
+
summary: text("summary").notNull(),
|
|
8
|
+
result: text("result").notNull(),
|
|
9
|
+
sourceRefsJson: text("source_refs_json").notNull(),
|
|
10
|
+
relatedDecisionId: text("related_decision_id"),
|
|
11
|
+
relatedDreamRunId: text("related_dream_run_id"),
|
|
12
|
+
ownerReplyJson: text("owner_reply_json"),
|
|
13
|
+
}, (table) => [
|
|
14
|
+
index("session_chronicle_event_kind_idx").on(table.eventKind),
|
|
15
|
+
index("session_chronicle_occurred_at_idx").on(table.occurredAt),
|
|
16
|
+
index("session_chronicle_actor_idx").on(table.actor),
|
|
17
|
+
index("session_chronicle_decision_idx").on(table.relatedDecisionId),
|
|
18
|
+
]);
|
|
@@ -0,0 +1,57 @@
|
|
|
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 AgentGoal {
|
|
9
|
+
goalId: string;
|
|
10
|
+
kind: "short_term" | "long_term";
|
|
11
|
+
status: "proposal" | "accepted" | "rejected" | "completed" | "paused";
|
|
12
|
+
origin: "owner_set" | "agent_proposed" | "policy_seeded";
|
|
13
|
+
description: string;
|
|
14
|
+
completionCriteria: string;
|
|
15
|
+
risk: "low" | "medium" | "high";
|
|
16
|
+
priorityHint: number;
|
|
17
|
+
sourceRefs: SourceRef[];
|
|
18
|
+
acceptedBy?: "owner" | "policy_allowlist";
|
|
19
|
+
createdAt: string;
|
|
20
|
+
updatedAt: string;
|
|
21
|
+
}
|
|
22
|
+
export interface AgentGoalWrite {
|
|
23
|
+
goalId: string;
|
|
24
|
+
kind: "short_term" | "long_term";
|
|
25
|
+
status: "proposal" | "accepted" | "rejected" | "completed" | "paused";
|
|
26
|
+
origin: "owner_set" | "agent_proposed" | "policy_seeded";
|
|
27
|
+
description: string;
|
|
28
|
+
completionCriteria: string;
|
|
29
|
+
risk: "low" | "medium" | "high";
|
|
30
|
+
priorityHint: number;
|
|
31
|
+
sourceRefs: SourceRef[];
|
|
32
|
+
acceptedBy?: "owner" | "policy_allowlist";
|
|
33
|
+
createdAt: string;
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
}
|
|
36
|
+
export interface AgentGoalStatusTransition {
|
|
37
|
+
goalId: string;
|
|
38
|
+
newStatus: "proposal" | "accepted" | "rejected" | "completed" | "paused";
|
|
39
|
+
acceptedBy?: "owner" | "policy_allowlist";
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
}
|
|
42
|
+
export interface AgentGoalQuery {
|
|
43
|
+
statuses?: AgentGoal["status"][];
|
|
44
|
+
origins?: AgentGoal["origin"][];
|
|
45
|
+
limit?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface AgentGoalWriteAck {
|
|
48
|
+
goalId: string;
|
|
49
|
+
status: "acknowledged" | "degraded";
|
|
50
|
+
}
|
|
51
|
+
export interface AgentGoalStore {
|
|
52
|
+
upsertAgentGoal(goal: AgentGoalWrite): Promise<AgentGoalWriteAck>;
|
|
53
|
+
listAgentGoals(query: AgentGoalQuery): Promise<AgentGoal[]>;
|
|
54
|
+
transitionGoalStatus(input: AgentGoalStatusTransition): Promise<AgentGoalWriteAck>;
|
|
55
|
+
loadAgentGoal(goalId: string): Promise<AgentGoal | null>;
|
|
56
|
+
}
|
|
57
|
+
export declare function createAgentGoalStore(database: StateDatabase): AgentGoalStore;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { eq, inArray, desc, and } from "drizzle-orm";
|
|
2
|
+
import { agentGoal } from "../db/schema/agent-goal.js";
|
|
3
|
+
function safeParseJson(json, fallback) {
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(json);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return fallback;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function rowToGoal(row) {
|
|
12
|
+
return {
|
|
13
|
+
goalId: row.goalId,
|
|
14
|
+
kind: row.kind,
|
|
15
|
+
status: row.status,
|
|
16
|
+
origin: row.origin,
|
|
17
|
+
description: row.description,
|
|
18
|
+
completionCriteria: row.completionCriteria,
|
|
19
|
+
risk: row.risk,
|
|
20
|
+
priorityHint: row.priorityHint,
|
|
21
|
+
sourceRefs: safeParseJson(row.sourceRefsJson, []),
|
|
22
|
+
acceptedBy: row.acceptedBy ? row.acceptedBy : undefined,
|
|
23
|
+
createdAt: row.createdAt,
|
|
24
|
+
updatedAt: row.updatedAt,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function createAgentGoalStore(database) {
|
|
28
|
+
const db = database.db;
|
|
29
|
+
return {
|
|
30
|
+
async upsertAgentGoal(goal) {
|
|
31
|
+
const existing = await db
|
|
32
|
+
.select()
|
|
33
|
+
.from(agentGoal)
|
|
34
|
+
.where(eq(agentGoal.goalId, goal.goalId))
|
|
35
|
+
.limit(1);
|
|
36
|
+
if (existing.length > 0) {
|
|
37
|
+
await db
|
|
38
|
+
.update(agentGoal)
|
|
39
|
+
.set({
|
|
40
|
+
kind: goal.kind,
|
|
41
|
+
status: goal.status,
|
|
42
|
+
origin: goal.origin,
|
|
43
|
+
description: goal.description,
|
|
44
|
+
completionCriteria: goal.completionCriteria,
|
|
45
|
+
risk: goal.risk,
|
|
46
|
+
priorityHint: goal.priorityHint,
|
|
47
|
+
sourceRefsJson: JSON.stringify(goal.sourceRefs),
|
|
48
|
+
acceptedBy: goal.acceptedBy ?? null,
|
|
49
|
+
updatedAt: goal.updatedAt,
|
|
50
|
+
})
|
|
51
|
+
.where(eq(agentGoal.goalId, goal.goalId));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
await db.insert(agentGoal).values({
|
|
55
|
+
goalId: goal.goalId,
|
|
56
|
+
kind: goal.kind,
|
|
57
|
+
status: goal.status,
|
|
58
|
+
origin: goal.origin,
|
|
59
|
+
description: goal.description,
|
|
60
|
+
completionCriteria: goal.completionCriteria,
|
|
61
|
+
risk: goal.risk,
|
|
62
|
+
priorityHint: goal.priorityHint,
|
|
63
|
+
sourceRefsJson: JSON.stringify(goal.sourceRefs),
|
|
64
|
+
acceptedBy: goal.acceptedBy ?? null,
|
|
65
|
+
createdAt: goal.createdAt,
|
|
66
|
+
updatedAt: goal.updatedAt,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return { goalId: goal.goalId, status: "acknowledged" };
|
|
70
|
+
},
|
|
71
|
+
async listAgentGoals(query) {
|
|
72
|
+
const conditions = [];
|
|
73
|
+
if (query.statuses && query.statuses.length > 0) {
|
|
74
|
+
conditions.push(inArray(agentGoal.status, query.statuses));
|
|
75
|
+
}
|
|
76
|
+
if (query.origins && query.origins.length > 0) {
|
|
77
|
+
conditions.push(inArray(agentGoal.origin, query.origins));
|
|
78
|
+
}
|
|
79
|
+
const rows = await db
|
|
80
|
+
.select()
|
|
81
|
+
.from(agentGoal)
|
|
82
|
+
.where(conditions.length > 0 ? and(...conditions) : undefined)
|
|
83
|
+
.orderBy(desc(agentGoal.updatedAt))
|
|
84
|
+
.limit(query.limit ?? 100);
|
|
85
|
+
return rows.map(rowToGoal);
|
|
86
|
+
},
|
|
87
|
+
async transitionGoalStatus(input) {
|
|
88
|
+
await db
|
|
89
|
+
.update(agentGoal)
|
|
90
|
+
.set({
|
|
91
|
+
status: input.newStatus,
|
|
92
|
+
acceptedBy: input.acceptedBy ?? null,
|
|
93
|
+
updatedAt: input.updatedAt,
|
|
94
|
+
})
|
|
95
|
+
.where(eq(agentGoal.goalId, input.goalId));
|
|
96
|
+
return { goalId: input.goalId, status: "acknowledged" };
|
|
97
|
+
},
|
|
98
|
+
async loadAgentGoal(goalId) {
|
|
99
|
+
const rows = await db
|
|
100
|
+
.select()
|
|
101
|
+
.from(agentGoal)
|
|
102
|
+
.where(eq(agentGoal.goalId, goalId))
|
|
103
|
+
.limit(1);
|
|
104
|
+
if (rows.length === 0)
|
|
105
|
+
return null;
|
|
106
|
+
return rowToGoal(rows[0]);
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -17,6 +17,11 @@ export { probeNativeSqliteLoad } from "./bootstrap/native-sqlite-probe.js";
|
|
|
17
17
|
export { runStorageModeSmoke, type StorageModeSmokeReport, type RunStorageModeSmokeOptions, } from "./bootstrap/storage-mode-smoke.js";
|
|
18
18
|
export { repairStateIndexes, type RepairSummary, type RepairStateIndexesOptions, type RepairGateStatus, } from "./bootstrap/repair-gate.js";
|
|
19
19
|
export { createStateAPI, type StateAPI, type MemoryReadPort, type MemoryWritePort, type CredentialContextPort, type IntentCommitPort, type ProvenancePort } from "./state-api.js";
|
|
20
|
+
export { createSessionChronicleStore, type SessionChronicleStore, type SessionChronicleEntry, type ChronicleQuery, type ChronicleWriteAck, type ChronicleEventKind, } from "./chronicle/session-chronicle-store.js";
|
|
21
|
+
export { createNarrativeStateStore, type NarrativeStateStore, type NarrativeState, type NarrativeStateUpdate, type NarrativeStateWriteAck, } from "./narrative/narrative-state-store.js";
|
|
22
|
+
export { createRelationshipMemoryStore, type RelationshipMemoryStore, type RelationshipMemory, type RelationshipMemoryUpdate, type RelationshipMemoryWriteAck, type TopicAffinity, } from "./relationship/relationship-memory-store.js";
|
|
23
|
+
export { createAgentGoalStore, type AgentGoalStore, type AgentGoal, type AgentGoalWrite, type AgentGoalStatusTransition, type AgentGoalQuery, type AgentGoalWriteAck, } from "./goal/agent-goal-store.js";
|
|
24
|
+
export { createMemoryStoreLifecycle, type MemoryStorePort, type MemoryStore, type MemoryStoreWrite, type MemoryStoreLifecycleTransition, type MemoryStoreAck, type CanonicalMemoryEntry, type DreamInsight, type MemoryStoreValidation, } from "./memory-store/memory-store-lifecycle.js";
|
|
20
25
|
export type { LifeEvidence, LifeEvidenceCandidate, LifeEvidenceType, LifeEvidenceWriteAck, Sensitivity, SourceRef, } from "./life-evidence/types.js";
|
|
21
26
|
export { appendLifeEvidence, type AppendLifeEvidenceOptions } from "./life-evidence/append-life-evidence.js";
|
|
22
27
|
export { loadRhythmPolicySnapshot, type RhythmPolicySnapshot } from "./rhythm/rhythm-policy-snapshot.js";
|
package/runtime/storage/index.js
CHANGED
|
@@ -17,6 +17,11 @@ export { probeNativeSqliteLoad } from "./bootstrap/native-sqlite-probe.js";
|
|
|
17
17
|
export { runStorageModeSmoke, } from "./bootstrap/storage-mode-smoke.js";
|
|
18
18
|
export { repairStateIndexes, } from "./bootstrap/repair-gate.js";
|
|
19
19
|
export { createStateAPI } from "./state-api.js";
|
|
20
|
+
export { createSessionChronicleStore, } from "./chronicle/session-chronicle-store.js";
|
|
21
|
+
export { createNarrativeStateStore, } from "./narrative/narrative-state-store.js";
|
|
22
|
+
export { createRelationshipMemoryStore, } from "./relationship/relationship-memory-store.js";
|
|
23
|
+
export { createAgentGoalStore, } from "./goal/agent-goal-store.js";
|
|
24
|
+
export { createMemoryStoreLifecycle, } from "./memory-store/memory-store-lifecycle.js";
|
|
20
25
|
export { appendLifeEvidence } from "./life-evidence/append-life-evidence.js";
|
|
21
26
|
export { loadRhythmPolicySnapshot } from "./rhythm/rhythm-policy-snapshot.js";
|
|
22
27
|
export { loadLifeEvidenceSnapshot } from "./snapshots/life-evidence-snapshot.js";
|
|
@@ -0,0 +1,70 @@
|
|
|
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 CanonicalMemoryEntry {
|
|
9
|
+
entryId: string;
|
|
10
|
+
kind: string;
|
|
11
|
+
summary: string;
|
|
12
|
+
sourceRefs: SourceRef[];
|
|
13
|
+
createdAt: string;
|
|
14
|
+
}
|
|
15
|
+
export interface DreamInsight {
|
|
16
|
+
id: string;
|
|
17
|
+
type: "pattern" | "learning" | "observation" | "conflict";
|
|
18
|
+
summary: string;
|
|
19
|
+
sourceRefs: string[];
|
|
20
|
+
confidence: number;
|
|
21
|
+
}
|
|
22
|
+
export interface MemoryStoreValidation {
|
|
23
|
+
passed: boolean;
|
|
24
|
+
summary: string;
|
|
25
|
+
checkedAt: string;
|
|
26
|
+
unsupportedClaims?: string[];
|
|
27
|
+
redactionIssues?: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface MemoryStore {
|
|
30
|
+
memoryStoreId: string;
|
|
31
|
+
lifecycleStatus: "candidate" | "accepted" | "archived" | "partial" | "superseded";
|
|
32
|
+
createdAt: string;
|
|
33
|
+
inputMemoryStoreId?: string;
|
|
34
|
+
dreamRunId?: string;
|
|
35
|
+
canonicalEntries: CanonicalMemoryEntry[];
|
|
36
|
+
insights: DreamInsight[];
|
|
37
|
+
narrativeSnapshot?: Record<string, unknown>;
|
|
38
|
+
relationshipSnapshot?: Record<string, unknown>;
|
|
39
|
+
validation: MemoryStoreValidation;
|
|
40
|
+
}
|
|
41
|
+
export interface MemoryStoreWrite {
|
|
42
|
+
memoryStoreId: string;
|
|
43
|
+
lifecycleStatus: "candidate" | "accepted" | "archived" | "partial" | "superseded";
|
|
44
|
+
createdAt: string;
|
|
45
|
+
inputMemoryStoreId?: string;
|
|
46
|
+
dreamRunId?: string;
|
|
47
|
+
canonicalEntries: CanonicalMemoryEntry[];
|
|
48
|
+
insights: DreamInsight[];
|
|
49
|
+
narrativeSnapshot?: Record<string, unknown>;
|
|
50
|
+
relationshipSnapshot?: Record<string, unknown>;
|
|
51
|
+
validation: MemoryStoreValidation;
|
|
52
|
+
}
|
|
53
|
+
export interface MemoryStoreLifecycleTransition {
|
|
54
|
+
memoryStoreId: string;
|
|
55
|
+
newStatus: "candidate" | "accepted" | "archived" | "partial" | "superseded";
|
|
56
|
+
validation?: MemoryStoreValidation;
|
|
57
|
+
updatedAt: string;
|
|
58
|
+
}
|
|
59
|
+
export interface MemoryStoreAck {
|
|
60
|
+
memoryStoreId: string;
|
|
61
|
+
status: "acknowledged" | "degraded";
|
|
62
|
+
}
|
|
63
|
+
export interface MemoryStorePort {
|
|
64
|
+
writeMemoryStore(output: MemoryStoreWrite): Promise<MemoryStoreAck>;
|
|
65
|
+
loadMemoryStore(memoryStoreId: string): Promise<MemoryStore | null>;
|
|
66
|
+
transitionMemoryStoreLifecycle(input: MemoryStoreLifecycleTransition): Promise<MemoryStoreAck>;
|
|
67
|
+
loadAcceptedMemoryProjection(): Promise<MemoryStore | null>;
|
|
68
|
+
listMemoryStoresByStatus(status: MemoryStore["lifecycleStatus"]): Promise<MemoryStore[]>;
|
|
69
|
+
}
|
|
70
|
+
export declare function createMemoryStoreLifecycle(database: StateDatabase): MemoryStorePort;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { eq, desc } from "drizzle-orm";
|
|
2
|
+
import { memoryStore } from "../db/schema/memory-store.js";
|
|
3
|
+
function safeParseJson(json, fallback) {
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(json);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return fallback;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function rowToStore(row) {
|
|
12
|
+
return {
|
|
13
|
+
memoryStoreId: row.memoryStoreId,
|
|
14
|
+
lifecycleStatus: row.lifecycleStatus,
|
|
15
|
+
createdAt: row.createdAt,
|
|
16
|
+
inputMemoryStoreId: row.inputMemoryStoreId ?? undefined,
|
|
17
|
+
dreamRunId: row.dreamRunId ?? undefined,
|
|
18
|
+
canonicalEntries: safeParseJson(row.canonicalEntriesJson, []),
|
|
19
|
+
insights: safeParseJson(row.insightsJson, []),
|
|
20
|
+
narrativeSnapshot: row.narrativeSnapshotJson ? safeParseJson(row.narrativeSnapshotJson, undefined) : undefined,
|
|
21
|
+
relationshipSnapshot: row.relationshipSnapshotJson ? safeParseJson(row.relationshipSnapshotJson, undefined) : undefined,
|
|
22
|
+
validation: safeParseJson(row.validationJson, { passed: false, summary: "", checkedAt: "" }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function createMemoryStoreLifecycle(database) {
|
|
26
|
+
const db = database.db;
|
|
27
|
+
return {
|
|
28
|
+
async writeMemoryStore(output) {
|
|
29
|
+
const existing = await db
|
|
30
|
+
.select()
|
|
31
|
+
.from(memoryStore)
|
|
32
|
+
.where(eq(memoryStore.memoryStoreId, output.memoryStoreId))
|
|
33
|
+
.limit(1);
|
|
34
|
+
if (existing.length > 0) {
|
|
35
|
+
await db
|
|
36
|
+
.update(memoryStore)
|
|
37
|
+
.set({
|
|
38
|
+
lifecycleStatus: output.lifecycleStatus,
|
|
39
|
+
inputMemoryStoreId: output.inputMemoryStoreId ?? null,
|
|
40
|
+
dreamRunId: output.dreamRunId ?? null,
|
|
41
|
+
canonicalEntriesJson: JSON.stringify(output.canonicalEntries),
|
|
42
|
+
insightsJson: JSON.stringify(output.insights),
|
|
43
|
+
narrativeSnapshotJson: output.narrativeSnapshot ? JSON.stringify(output.narrativeSnapshot) : null,
|
|
44
|
+
relationshipSnapshotJson: output.relationshipSnapshot ? JSON.stringify(output.relationshipSnapshot) : null,
|
|
45
|
+
validationJson: JSON.stringify(output.validation),
|
|
46
|
+
})
|
|
47
|
+
.where(eq(memoryStore.memoryStoreId, output.memoryStoreId));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
await db.insert(memoryStore).values({
|
|
51
|
+
memoryStoreId: output.memoryStoreId,
|
|
52
|
+
lifecycleStatus: output.lifecycleStatus,
|
|
53
|
+
createdAt: output.createdAt,
|
|
54
|
+
inputMemoryStoreId: output.inputMemoryStoreId ?? null,
|
|
55
|
+
dreamRunId: output.dreamRunId ?? null,
|
|
56
|
+
canonicalEntriesJson: JSON.stringify(output.canonicalEntries),
|
|
57
|
+
insightsJson: JSON.stringify(output.insights),
|
|
58
|
+
narrativeSnapshotJson: output.narrativeSnapshot ? JSON.stringify(output.narrativeSnapshot) : null,
|
|
59
|
+
relationshipSnapshotJson: output.relationshipSnapshot ? JSON.stringify(output.relationshipSnapshot) : null,
|
|
60
|
+
validationJson: JSON.stringify(output.validation),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return { memoryStoreId: output.memoryStoreId, status: "acknowledged" };
|
|
64
|
+
},
|
|
65
|
+
async loadMemoryStore(memoryStoreId) {
|
|
66
|
+
const rows = await db
|
|
67
|
+
.select()
|
|
68
|
+
.from(memoryStore)
|
|
69
|
+
.where(eq(memoryStore.memoryStoreId, memoryStoreId))
|
|
70
|
+
.limit(1);
|
|
71
|
+
if (rows.length === 0)
|
|
72
|
+
return null;
|
|
73
|
+
return rowToStore(rows[0]);
|
|
74
|
+
},
|
|
75
|
+
async transitionMemoryStoreLifecycle(input) {
|
|
76
|
+
const existing = await db
|
|
77
|
+
.select()
|
|
78
|
+
.from(memoryStore)
|
|
79
|
+
.where(eq(memoryStore.memoryStoreId, input.memoryStoreId))
|
|
80
|
+
.limit(1);
|
|
81
|
+
if (existing.length === 0) {
|
|
82
|
+
return { memoryStoreId: input.memoryStoreId, status: "degraded" };
|
|
83
|
+
}
|
|
84
|
+
const updates = { lifecycleStatus: input.newStatus };
|
|
85
|
+
if (input.validation) {
|
|
86
|
+
updates.validationJson = JSON.stringify(input.validation);
|
|
87
|
+
}
|
|
88
|
+
await db
|
|
89
|
+
.update(memoryStore)
|
|
90
|
+
.set(updates)
|
|
91
|
+
.where(eq(memoryStore.memoryStoreId, input.memoryStoreId));
|
|
92
|
+
return { memoryStoreId: input.memoryStoreId, status: "acknowledged" };
|
|
93
|
+
},
|
|
94
|
+
async loadAcceptedMemoryProjection() {
|
|
95
|
+
const rows = await db
|
|
96
|
+
.select()
|
|
97
|
+
.from(memoryStore)
|
|
98
|
+
.where(eq(memoryStore.lifecycleStatus, "accepted"))
|
|
99
|
+
.orderBy(desc(memoryStore.createdAt))
|
|
100
|
+
.limit(1);
|
|
101
|
+
if (rows.length === 0)
|
|
102
|
+
return null;
|
|
103
|
+
return rowToStore(rows[0]);
|
|
104
|
+
},
|
|
105
|
+
async listMemoryStoresByStatus(status) {
|
|
106
|
+
const rows = await db
|
|
107
|
+
.select()
|
|
108
|
+
.from(memoryStore)
|
|
109
|
+
.where(eq(memoryStore.lifecycleStatus, status));
|
|
110
|
+
return rows.map(rowToStore);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 NarrativeState {
|
|
9
|
+
narrativeId: string;
|
|
10
|
+
revision: number;
|
|
11
|
+
focus: string;
|
|
12
|
+
progress: string[];
|
|
13
|
+
nextIntent: string;
|
|
14
|
+
confidence: number;
|
|
15
|
+
sourceRefs: SourceRef[];
|
|
16
|
+
unsupportedClaims: string[];
|
|
17
|
+
status: "active" | "insufficient_sources" | "awaiting_sources";
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
}
|
|
20
|
+
export interface NarrativeStateUpdate {
|
|
21
|
+
narrativeId: string;
|
|
22
|
+
revision: number;
|
|
23
|
+
focus: string;
|
|
24
|
+
progress: string[];
|
|
25
|
+
nextIntent: string;
|
|
26
|
+
confidence: number;
|
|
27
|
+
sourceRefs: SourceRef[];
|
|
28
|
+
unsupportedClaims: string[];
|
|
29
|
+
status: "active" | "insufficient_sources" | "awaiting_sources";
|
|
30
|
+
updatedAt: string;
|
|
31
|
+
}
|
|
32
|
+
export interface NarrativeStateWriteAck {
|
|
33
|
+
narrativeId: string;
|
|
34
|
+
status: "acknowledged" | "degraded";
|
|
35
|
+
}
|
|
36
|
+
export interface NarrativeStateStore {
|
|
37
|
+
updateNarrativeState(input: NarrativeStateUpdate): Promise<NarrativeStateWriteAck>;
|
|
38
|
+
loadNarrativeState(narrativeId?: string): Promise<NarrativeState | null>;
|
|
39
|
+
}
|
|
40
|
+
export declare function createNarrativeStateStore(database: StateDatabase): NarrativeStateStore;
|