@evo-dev/core 0.0.1-alpha.2 → 0.0.1-alpha.20
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/assets/skills/coding/knowledge-distillation/SKILL.md +5 -3
- package/assets/team/agents/code-reviewer.md +48 -0
- package/assets/team/agents/docs-maintainer.md +51 -0
- package/assets/team/agents/implementation-engineer.md +51 -0
- package/assets/team/agents/product-scope-analyst.md +58 -0
- package/assets/team/agents/release-engineer.md +55 -0
- package/assets/team/agents/security-boundary-reviewer.md +50 -0
- package/assets/team/agents/solution-architect.md +51 -0
- package/assets/team/agents/verification-engineer.md +51 -0
- package/assets/team/team.md +102 -0
- package/dist/assets/index.js +5 -5
- package/dist/config/index.js +793 -241
- package/dist/index.js +20840 -12908
- package/dist/plugins/index.js +13 -13
- package/package.json +1 -1
- package/src/agents/index.ts +1 -265
- package/src/code-agent-traces/index.ts +11 -12
- package/src/config/index.ts +2 -0
- package/src/config/settings.ts +116 -7
- package/src/config/store.ts +1 -1
- package/src/daemon/index.ts +1 -41
- package/src/evolution/candidates/index.ts +730 -0
- package/src/evolution/control/index.ts +20 -0
- package/src/evolution/evidence/analysis.ts +533 -0
- package/src/evolution/evidence/index.ts +3 -0
- package/src/evolution/evidence/session-memory/analysis.ts +287 -0
- package/src/evolution/evidence/session-memory/constants.ts +9 -0
- package/src/evolution/evidence/session-memory/index.ts +9 -0
- package/src/evolution/evidence/session-memory/paths.ts +29 -0
- package/src/evolution/evidence/session-memory/policy.ts +39 -0
- package/src/evolution/evidence/session-memory/retention.ts +643 -0
- package/src/evolution/evidence/session-memory/segment.ts +216 -0
- package/src/evolution/evidence/session-memory/semantic-packet.ts +408 -0
- package/src/evolution/evidence/session-memory/sensitivity.ts +335 -0
- package/src/evolution/evidence/session-memory/state-machine.ts +249 -0
- package/src/evolution/evidence/session-memory/storage.ts +744 -0
- package/src/evolution/evidence/session-memory/types.ts +296 -0
- package/src/evolution/evidence/session-memory/updater.ts +199 -0
- package/src/evolution/formatters.ts +169 -0
- package/src/evolution/imports/apply.ts +435 -0
- package/src/evolution/imports/diff.ts +472 -0
- package/src/evolution/imports/index.ts +7 -0
- package/src/evolution/imports/materialize.ts +640 -0
- package/src/evolution/imports/paths.ts +129 -0
- package/src/evolution/imports/stage.ts +414 -0
- package/src/evolution/imports/storage.ts +952 -0
- package/src/evolution/imports/types.ts +226 -0
- package/src/evolution/index.ts +19 -2827
- package/src/evolution/knowledge/change-store.ts +558 -0
- package/src/evolution/knowledge/changes.ts +459 -0
- package/src/evolution/knowledge/freshness.ts +69 -0
- package/src/{knowledge → evolution/knowledge}/index.ts +1532 -206
- package/src/evolution/knowledge/review.ts +446 -0
- package/src/evolution/knowledge/support.ts +135 -0
- package/src/evolution/paths.ts +44 -0
- package/src/evolution/processor/distillation.ts +518 -0
- package/src/evolution/processor/index.ts +3 -0
- package/src/evolution/processor/process.ts +594 -0
- package/src/{learning → evolution/review}/index.ts +10 -14
- package/src/evolution/schema.ts +639 -0
- package/src/evolution/shared.ts +1053 -0
- package/src/evolution/triggers/classification.ts +102 -0
- package/src/evolution/triggers/index.ts +295 -0
- package/src/hooks/index.ts +281 -197
- package/src/index.ts +15 -4
- package/src/projects/index.ts +934 -0
- package/src/runtime-logs/index.ts +100 -13
- package/src/team/index.ts +582 -3
- package/src/utils/errors.ts +13 -0
- package/src/utils/fs.ts +40 -0
- package/src/utils/hash.ts +9 -0
- package/src/utils/ids.ts +12 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/parsing.ts +11 -0
- package/src/utils/text.ts +18 -0
- package/src/utils/time.ts +5 -0
- package/src/workflow/index.ts +3 -21
- package/src/project/index.ts +0 -507
- package/src/task/index.ts +0 -840
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
export type SessionMemoryTarget = "claude" | "codex" | "unknown";
|
|
2
|
+
export type SessionMemorySegmentReason =
|
|
3
|
+
| "session-memory-init"
|
|
4
|
+
| "session-memory-threshold"
|
|
5
|
+
| "intent-refinement"
|
|
6
|
+
| "user-interruption"
|
|
7
|
+
| "failure-signal"
|
|
8
|
+
| "permission-denied"
|
|
9
|
+
| "verification-after-fix"
|
|
10
|
+
| "explicit-memory-intent"
|
|
11
|
+
| "historical-import";
|
|
12
|
+
export type SessionMemorySignalStrength = "normal" | "strong";
|
|
13
|
+
export type SessionMemorySensitivity = "safe-metadata" | "private-content" | "credential";
|
|
14
|
+
export type SessionMemorySensitivityReason =
|
|
15
|
+
| "credential-field"
|
|
16
|
+
| "credential-shape"
|
|
17
|
+
| "credential-url-parameter"
|
|
18
|
+
| "credential-url-userinfo"
|
|
19
|
+
| "legacy-sensitive-flag"
|
|
20
|
+
| "private-marker"
|
|
21
|
+
| "url";
|
|
22
|
+
|
|
23
|
+
export interface SessionMemoryPolicySnapshot {
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
storeRawSegments: boolean;
|
|
26
|
+
maxRawSegmentBytes: number;
|
|
27
|
+
retentionDays: number;
|
|
28
|
+
minimumMessageTokensToInit: number;
|
|
29
|
+
minimumTokensBetweenUpdate: number;
|
|
30
|
+
toolCallsBetweenUpdates: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface SessionMemorySignal {
|
|
34
|
+
eventId: string;
|
|
35
|
+
eventType: string;
|
|
36
|
+
reason: SessionMemorySegmentReason | "observed";
|
|
37
|
+
strength: SessionMemorySignalStrength;
|
|
38
|
+
occurredAt: string | null;
|
|
39
|
+
summary: string;
|
|
40
|
+
rawEventLine: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SessionMemorySpan {
|
|
44
|
+
spanId: string;
|
|
45
|
+
status: "open" | "closed" | "interrupted";
|
|
46
|
+
openedAt: string;
|
|
47
|
+
closedAt: string | null;
|
|
48
|
+
openedByEventId: string;
|
|
49
|
+
lastEventId: string;
|
|
50
|
+
userPromptCount: number;
|
|
51
|
+
toolCallCount: number;
|
|
52
|
+
workStarted: boolean;
|
|
53
|
+
tokenEstimate: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SessionMemoryStateV1 {
|
|
57
|
+
schemaVersion: 1;
|
|
58
|
+
kind: "session-memory-state";
|
|
59
|
+
projectKey: string;
|
|
60
|
+
sessionKey: string;
|
|
61
|
+
target: SessionMemoryTarget;
|
|
62
|
+
runId: string | null;
|
|
63
|
+
roleId: string | null;
|
|
64
|
+
initialized: boolean;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
updatedAt: string;
|
|
67
|
+
counters: {
|
|
68
|
+
messageTokenEstimate: number;
|
|
69
|
+
tokensSinceLastUpdate: number;
|
|
70
|
+
toolCallsSinceLastUpdate: number;
|
|
71
|
+
userPromptCount: number;
|
|
72
|
+
assistantTurnCount: number;
|
|
73
|
+
toolCallCount: number;
|
|
74
|
+
failureSignalCount: number;
|
|
75
|
+
verificationSignalCount: number;
|
|
76
|
+
};
|
|
77
|
+
activeSpan: SessionMemorySpan | null;
|
|
78
|
+
pendingSignals: SessionMemorySignal[];
|
|
79
|
+
lastSegmentId: string | null;
|
|
80
|
+
lastMemoryUpdateAt: string | null;
|
|
81
|
+
policy: SessionMemoryPolicySnapshot;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface SessionMemoryCursorV1 {
|
|
85
|
+
schemaVersion: 1;
|
|
86
|
+
kind: "session-memory-cursor";
|
|
87
|
+
sessionKey: string;
|
|
88
|
+
traceRefId: string | null;
|
|
89
|
+
sourcePath: string | null;
|
|
90
|
+
lastCapturedOffset: number | null;
|
|
91
|
+
lastCapturedLine: number | null;
|
|
92
|
+
lastCapturedEventId: string | null;
|
|
93
|
+
updatedAt: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface HistoricalImportOriginV1 {
|
|
97
|
+
kind: "historical-import";
|
|
98
|
+
importId: string;
|
|
99
|
+
generationId: string;
|
|
100
|
+
snapshotId: string;
|
|
101
|
+
sourceKey: string;
|
|
102
|
+
firstRecordKeyHash: string;
|
|
103
|
+
lastRecordKeyHash: string;
|
|
104
|
+
recordCount: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface SessionEvidenceRetentionV1 {
|
|
108
|
+
policyDays: number;
|
|
109
|
+
expiresAt: string;
|
|
110
|
+
rawState: "available" | "purged";
|
|
111
|
+
rawPurgedAt: string | null;
|
|
112
|
+
originalRawSha256: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type HistoricalImportRetentionV1 = SessionEvidenceRetentionV1;
|
|
116
|
+
|
|
117
|
+
export interface HistoricalImportStoredRecordV1 {
|
|
118
|
+
schemaVersion: 1;
|
|
119
|
+
kind: "historical-import-record";
|
|
120
|
+
recordKeyHash: string;
|
|
121
|
+
recordType: "user" | "reasoning" | "assistant" | "assistant-tool-call" | "tool";
|
|
122
|
+
canonicalJson: string;
|
|
123
|
+
canonicalJsonTruncated: boolean;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface SemanticEvidencePacketV1 {
|
|
127
|
+
schemaVersion: 1;
|
|
128
|
+
kind: "semantic-evidence-packet";
|
|
129
|
+
projectKey: string;
|
|
130
|
+
segmentId: string;
|
|
131
|
+
conversation: Array<{
|
|
132
|
+
role: "user" | "assistant";
|
|
133
|
+
text: string;
|
|
134
|
+
recordKeyHash: string;
|
|
135
|
+
}>;
|
|
136
|
+
toolEvidence: Array<{
|
|
137
|
+
reason: "failure" | "verification" | "permission" | "rollback";
|
|
138
|
+
toolName: string;
|
|
139
|
+
safeInputExcerpt: string | null;
|
|
140
|
+
outputExcerpt: string | null;
|
|
141
|
+
status: string | null;
|
|
142
|
+
exitCode: number | null;
|
|
143
|
+
inputTruncated: boolean;
|
|
144
|
+
outputTruncated: boolean;
|
|
145
|
+
}>;
|
|
146
|
+
touchedPaths: string[];
|
|
147
|
+
selection: {
|
|
148
|
+
selectedRecords: number;
|
|
149
|
+
droppedRecords: number;
|
|
150
|
+
redactionCount: number;
|
|
151
|
+
truncated: boolean;
|
|
152
|
+
};
|
|
153
|
+
privacy: {
|
|
154
|
+
containsPrivateContent: true;
|
|
155
|
+
credentialRedacted: true;
|
|
156
|
+
rawSegmentIncluded: false;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface SessionEvidenceSegmentV1 {
|
|
161
|
+
schemaVersion: 1;
|
|
162
|
+
kind: "session-evidence-segment";
|
|
163
|
+
id: string;
|
|
164
|
+
projectKey: string;
|
|
165
|
+
runId: string | null;
|
|
166
|
+
roleId: string | null;
|
|
167
|
+
sessionKey: string;
|
|
168
|
+
target: SessionMemoryTarget;
|
|
169
|
+
createdAt: string;
|
|
170
|
+
reason: SessionMemorySegmentReason;
|
|
171
|
+
strength: SessionMemorySignalStrength;
|
|
172
|
+
origin?: HistoricalImportOriginV1;
|
|
173
|
+
retention?: SessionEvidenceRetentionV1;
|
|
174
|
+
source: {
|
|
175
|
+
traceRefId: string | null;
|
|
176
|
+
sourcePath: string | null;
|
|
177
|
+
fromOffset: number | null;
|
|
178
|
+
toOffset: number | null;
|
|
179
|
+
fromLine: number | null;
|
|
180
|
+
toLine: number | null;
|
|
181
|
+
fromEventId: string | null;
|
|
182
|
+
toEventId: string | null;
|
|
183
|
+
};
|
|
184
|
+
signals: SessionMemorySignal[];
|
|
185
|
+
rawExcerpt: {
|
|
186
|
+
stored: boolean;
|
|
187
|
+
encoding: "utf8";
|
|
188
|
+
content: string;
|
|
189
|
+
truncated: boolean;
|
|
190
|
+
byteLength: number;
|
|
191
|
+
sha256: string;
|
|
192
|
+
};
|
|
193
|
+
normalized: {
|
|
194
|
+
summary: string;
|
|
195
|
+
userIntent: string | null;
|
|
196
|
+
intentDelta: string | null;
|
|
197
|
+
decisions: string[];
|
|
198
|
+
failures: string[];
|
|
199
|
+
verifications: string[];
|
|
200
|
+
touchedTools: string[];
|
|
201
|
+
};
|
|
202
|
+
privacy: {
|
|
203
|
+
localOnly: true;
|
|
204
|
+
rawPromptStored: boolean;
|
|
205
|
+
rawOutputStored: boolean;
|
|
206
|
+
sourceContentStored: boolean;
|
|
207
|
+
secretsDetected: boolean;
|
|
208
|
+
sensitivity?: SessionMemorySensitivity;
|
|
209
|
+
sensitivityReasons?: SessionMemorySensitivityReason[];
|
|
210
|
+
redactionApplied: boolean;
|
|
211
|
+
externalUploadAllowed: false;
|
|
212
|
+
};
|
|
213
|
+
lifecycle: {
|
|
214
|
+
status:
|
|
215
|
+
| "captured"
|
|
216
|
+
| "pending-review"
|
|
217
|
+
| "reviewed"
|
|
218
|
+
| "distilled"
|
|
219
|
+
| "ignored"
|
|
220
|
+
| "deleted"
|
|
221
|
+
| "raw-expired";
|
|
222
|
+
reviewState: "not-required" | "unreviewed" | "accepted" | "rejected" | "deferred";
|
|
223
|
+
consumedByBatchIds: string[];
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface SessionMemoryRawEventV1 {
|
|
228
|
+
schemaVersion: 1;
|
|
229
|
+
kind: "session-memory-raw-event";
|
|
230
|
+
eventId: string;
|
|
231
|
+
eventType: string;
|
|
232
|
+
occurredAt: string | null;
|
|
233
|
+
receivedAt: string;
|
|
234
|
+
summary: string;
|
|
235
|
+
rawPayloadJson: string;
|
|
236
|
+
rawPayloadByteLength: number;
|
|
237
|
+
rawPayloadTruncated: boolean;
|
|
238
|
+
rawPayloadExpired?: boolean;
|
|
239
|
+
secretsDetected: boolean;
|
|
240
|
+
sensitivity?: SessionMemorySensitivity;
|
|
241
|
+
sensitivityReasons?: SessionMemorySensitivityReason[];
|
|
242
|
+
credentialRedactionApplied?: boolean;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface SessionMemoryPaths {
|
|
246
|
+
rootDir: string;
|
|
247
|
+
projectDir: string;
|
|
248
|
+
sessionDir: string;
|
|
249
|
+
statePath: string;
|
|
250
|
+
cursorPath: string;
|
|
251
|
+
eventsPath: string;
|
|
252
|
+
segmentsDir: string;
|
|
253
|
+
segmentPath: (segmentId: string) => string;
|
|
254
|
+
indexPath: string;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface UpdateSessionMemoryInput {
|
|
258
|
+
homeDir: string;
|
|
259
|
+
target: SessionMemoryTarget;
|
|
260
|
+
event: {
|
|
261
|
+
eventId: string;
|
|
262
|
+
type: string;
|
|
263
|
+
time: {
|
|
264
|
+
occurredAt: string | null;
|
|
265
|
+
receivedAt: string;
|
|
266
|
+
};
|
|
267
|
+
scope: {
|
|
268
|
+
taskId: string | null;
|
|
269
|
+
};
|
|
270
|
+
payload: {
|
|
271
|
+
summary: string;
|
|
272
|
+
metadata: Record<string, string | number | boolean | string[]>;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
rawPayload: Record<string, unknown>;
|
|
276
|
+
environment?: Record<string, string | undefined>;
|
|
277
|
+
receivedAt?: string;
|
|
278
|
+
policy?: Partial<SessionMemoryPolicySnapshot>;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface SessionMemoryUpdateResult {
|
|
282
|
+
state: SessionMemoryStateV1 | null;
|
|
283
|
+
cursor: SessionMemoryCursorV1 | null;
|
|
284
|
+
segment: SessionEvidenceSegmentV1 | null;
|
|
285
|
+
stateWrites: string[];
|
|
286
|
+
warnings: string[];
|
|
287
|
+
queuedSegmentTriggerId: string | null;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface SessionMemoryIndexSegment {
|
|
291
|
+
id: string;
|
|
292
|
+
reason: SessionMemorySegmentReason;
|
|
293
|
+
strength: SessionMemorySignalStrength;
|
|
294
|
+
createdAt: string;
|
|
295
|
+
reviewState: "not-required" | "unreviewed" | "accepted" | "rejected" | "deferred";
|
|
296
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { resolveProjectWorkspaceFromCwd } from "../../../projects/index.ts";
|
|
3
|
+
import {
|
|
4
|
+
resolveProjectLogKey,
|
|
5
|
+
resolveTraceSessionKey,
|
|
6
|
+
resolveTraceTeamContext,
|
|
7
|
+
} from "../../../runtime-logs/index.ts";
|
|
8
|
+
import { normalizeTimestamp, optionalString, sanitizeStorageId } from "../../../utils/index.ts";
|
|
9
|
+
import { enqueueSegmentEvolutionTrigger } from "../../triggers/index.ts";
|
|
10
|
+
import { resolveSessionMemoryPaths } from "./paths.ts";
|
|
11
|
+
import { parseSessionMemoryPolicy } from "./policy.ts";
|
|
12
|
+
import { createRawEvent, createSegment, createSignal, estimateTokenCount } from "./segment.ts";
|
|
13
|
+
import {
|
|
14
|
+
appendBoundedSignal,
|
|
15
|
+
applyEventToState,
|
|
16
|
+
cloneState,
|
|
17
|
+
createInitialState,
|
|
18
|
+
decideSegment,
|
|
19
|
+
} from "./state-machine.ts";
|
|
20
|
+
import {
|
|
21
|
+
appendRawEvent,
|
|
22
|
+
readSessionCursor,
|
|
23
|
+
readSessionState,
|
|
24
|
+
resetSessionRawEvents,
|
|
25
|
+
writeJson,
|
|
26
|
+
writeSessionIndex,
|
|
27
|
+
} from "./storage.ts";
|
|
28
|
+
import type {
|
|
29
|
+
SessionEvidenceSegmentV1,
|
|
30
|
+
SessionMemoryUpdateResult,
|
|
31
|
+
UpdateSessionMemoryInput,
|
|
32
|
+
} from "./types.ts";
|
|
33
|
+
|
|
34
|
+
export async function updateSessionMemoryFromHook(
|
|
35
|
+
input: UpdateSessionMemoryInput,
|
|
36
|
+
): Promise<SessionMemoryUpdateResult> {
|
|
37
|
+
const policy = parseSessionMemoryPolicy(input.policy);
|
|
38
|
+
if (!policy.enabled || !policy.storeRawSegments) {
|
|
39
|
+
return emptyResult();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const team = resolveTraceTeamContext({
|
|
43
|
+
homeDir: input.homeDir,
|
|
44
|
+
environment: input.environment,
|
|
45
|
+
payload: input.rawPayload,
|
|
46
|
+
});
|
|
47
|
+
const cwd = optionalString(input.rawPayload.cwd);
|
|
48
|
+
const workspace =
|
|
49
|
+
team === null && cwd !== null
|
|
50
|
+
? await resolveProjectWorkspaceFromCwd({ homeDir: input.homeDir, cwd })
|
|
51
|
+
: null;
|
|
52
|
+
const projectKey = sanitizeStorageId(
|
|
53
|
+
team?.projectKey ??
|
|
54
|
+
workspace?.projectKey ??
|
|
55
|
+
resolveProjectLogKey(input.homeDir, cwd ?? input.homeDir),
|
|
56
|
+
"project",
|
|
57
|
+
);
|
|
58
|
+
const sessionKey = sanitizeStorageId(resolveTraceSessionKey(input.rawPayload), "session");
|
|
59
|
+
const paths = resolveSessionMemoryPaths({ homeDir: input.homeDir, projectKey, sessionKey });
|
|
60
|
+
const now = normalizeTimestamp(input.receivedAt ?? input.event.time.receivedAt);
|
|
61
|
+
const existingState = await readSessionState(paths.statePath);
|
|
62
|
+
|
|
63
|
+
if (existingState === null && input.event.type !== "UserPromptSubmit") {
|
|
64
|
+
return emptyResult();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const rawEvent = createRawEvent(input, now);
|
|
68
|
+
const appended = await appendRawEvent(paths.eventsPath, rawEvent);
|
|
69
|
+
const tokenEstimate = estimateTokenCount(rawEvent.rawPayloadJson, input.event.payload.summary);
|
|
70
|
+
const currentSignal = createSignal(input, rawEvent, appended.lineNumber);
|
|
71
|
+
const state =
|
|
72
|
+
existingState ??
|
|
73
|
+
createInitialState({
|
|
74
|
+
projectKey,
|
|
75
|
+
sessionKey,
|
|
76
|
+
target: input.target,
|
|
77
|
+
runId: team?.runId ?? null,
|
|
78
|
+
roleId: team?.roleId ?? null,
|
|
79
|
+
now,
|
|
80
|
+
policy,
|
|
81
|
+
eventId: input.event.eventId,
|
|
82
|
+
tokenEstimate,
|
|
83
|
+
});
|
|
84
|
+
const cursor = await readSessionCursor(paths.cursorPath, sessionKey, paths.eventsPath, now);
|
|
85
|
+
const previous = cloneState(state);
|
|
86
|
+
|
|
87
|
+
applyEventToState(state, {
|
|
88
|
+
input,
|
|
89
|
+
now,
|
|
90
|
+
tokenEstimate,
|
|
91
|
+
policy,
|
|
92
|
+
teamRunId: team?.runId ?? null,
|
|
93
|
+
teamRoleId: team?.roleId ?? null,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const decision = decideSegment({
|
|
97
|
+
previous,
|
|
98
|
+
next: state,
|
|
99
|
+
input,
|
|
100
|
+
rawEvent,
|
|
101
|
+
currentSignal,
|
|
102
|
+
tokenEstimate,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
let segment: SessionEvidenceSegmentV1 | null = null;
|
|
106
|
+
let segmentPath: string | null = null;
|
|
107
|
+
let queuedSegmentTriggerId: string | null = null;
|
|
108
|
+
const stateWrites: string[] = [paths.eventsPath];
|
|
109
|
+
|
|
110
|
+
if (decision === null) {
|
|
111
|
+
state.pendingSignals = appendBoundedSignal(state.pendingSignals, currentSignal);
|
|
112
|
+
} else {
|
|
113
|
+
const signals = [
|
|
114
|
+
...state.pendingSignals,
|
|
115
|
+
{ ...currentSignal, reason: decision.reason, strength: decision.strength },
|
|
116
|
+
];
|
|
117
|
+
segment = await createSegment({
|
|
118
|
+
paths,
|
|
119
|
+
state,
|
|
120
|
+
cursor,
|
|
121
|
+
reason: decision.reason,
|
|
122
|
+
strength: decision.strength,
|
|
123
|
+
signals,
|
|
124
|
+
currentLine: appended.lineNumber,
|
|
125
|
+
now,
|
|
126
|
+
});
|
|
127
|
+
segmentPath = paths.segmentPath(segment.id);
|
|
128
|
+
await writeJson(segmentPath, segment);
|
|
129
|
+
await writeSessionIndex(paths, state, segment, now);
|
|
130
|
+
if (shouldQueueSegmentForEvolution(segment)) {
|
|
131
|
+
const trigger = await enqueueSegmentEvolutionTrigger({
|
|
132
|
+
homeDir: input.homeDir,
|
|
133
|
+
projectKey: segment.projectKey,
|
|
134
|
+
sessionKey: segment.sessionKey,
|
|
135
|
+
runId: segment.runId,
|
|
136
|
+
roleId: segment.roleId,
|
|
137
|
+
segmentId: segment.id,
|
|
138
|
+
segmentPath,
|
|
139
|
+
strength: segment.strength,
|
|
140
|
+
reason: segment.reason,
|
|
141
|
+
summary: segment.normalized.summary,
|
|
142
|
+
now,
|
|
143
|
+
});
|
|
144
|
+
queuedSegmentTriggerId = trigger.id;
|
|
145
|
+
}
|
|
146
|
+
await resetSessionRawEvents(paths.eventsPath);
|
|
147
|
+
cursor.lastCapturedLine = 0;
|
|
148
|
+
cursor.lastCapturedEventId = input.event.eventId;
|
|
149
|
+
cursor.updatedAt = now;
|
|
150
|
+
state.lastSegmentId = segment.id;
|
|
151
|
+
state.lastMemoryUpdateAt = now;
|
|
152
|
+
state.counters.tokensSinceLastUpdate = 0;
|
|
153
|
+
state.counters.toolCallsSinceLastUpdate = 0;
|
|
154
|
+
state.pendingSignals = [];
|
|
155
|
+
stateWrites.push(segmentPath, paths.indexPath);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
state.updatedAt = now;
|
|
159
|
+
await writeJson(paths.statePath, state);
|
|
160
|
+
await writeJson(paths.cursorPath, cursor);
|
|
161
|
+
stateWrites.push(paths.statePath, paths.cursorPath);
|
|
162
|
+
if (queuedSegmentTriggerId !== null) {
|
|
163
|
+
stateWrites.push(
|
|
164
|
+
join(
|
|
165
|
+
input.homeDir,
|
|
166
|
+
".evodev",
|
|
167
|
+
"state",
|
|
168
|
+
"evolution",
|
|
169
|
+
projectKey,
|
|
170
|
+
"segments",
|
|
171
|
+
`${queuedSegmentTriggerId}.json`,
|
|
172
|
+
),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
state,
|
|
178
|
+
cursor,
|
|
179
|
+
segment,
|
|
180
|
+
stateWrites,
|
|
181
|
+
warnings: [],
|
|
182
|
+
queuedSegmentTriggerId,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function shouldQueueSegmentForEvolution(segment: SessionEvidenceSegmentV1): boolean {
|
|
187
|
+
return segment.reason !== "session-memory-threshold" && segment.reason !== "session-memory-init";
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function emptyResult(): SessionMemoryUpdateResult {
|
|
191
|
+
return {
|
|
192
|
+
state: null,
|
|
193
|
+
cursor: null,
|
|
194
|
+
segment: null,
|
|
195
|
+
stateWrites: [],
|
|
196
|
+
warnings: [],
|
|
197
|
+
queuedSegmentTriggerId: null,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EvolutionActivationResult,
|
|
3
|
+
EvolutionAnalyzeResult,
|
|
4
|
+
EvolutionDistillationBatch,
|
|
5
|
+
EvolutionProcessResult,
|
|
6
|
+
EvolutionReviewSnapshot,
|
|
7
|
+
EvolutionWriteResult,
|
|
8
|
+
} from "./schema.ts";
|
|
9
|
+
import { collectRoleIds } from "./shared.ts";
|
|
10
|
+
|
|
11
|
+
export function formatEvolutionAnalyzeResult(result: EvolutionAnalyzeResult): string {
|
|
12
|
+
const roles = collectRoleIds(result.evidenceWindow);
|
|
13
|
+
return [
|
|
14
|
+
"EvoDev evolution analyze",
|
|
15
|
+
"",
|
|
16
|
+
`Project: ${result.evidenceWindow.projectKey}`,
|
|
17
|
+
`Run: ${result.evidenceWindow.runId}`,
|
|
18
|
+
`Evidence window: ${result.evidenceWindow.id}`,
|
|
19
|
+
`Sources: ${result.evidenceWindow.sourceRefs.length}`,
|
|
20
|
+
`Events: ${result.evidenceWindow.events.length}`,
|
|
21
|
+
`Episodes: ${result.evidenceWindow.episodes.length}`,
|
|
22
|
+
`Trigger: ${result.evidenceWindow.triggerPolicy.strongest} (${result.evidenceWindow.triggerPolicy.reasons.join(", ") || "none"}); distillRecommended=${result.evidenceWindow.triggerPolicy.distillRecommended}`,
|
|
23
|
+
`Roles: ${roles.length === 0 ? "none" : roles.join(", ")}`,
|
|
24
|
+
"Privacy: metadata-only; rawLogs=false; rawPrompts=false; sourceDumps=false; rawCommandOutput=false",
|
|
25
|
+
...(result.warnings.length === 0
|
|
26
|
+
? ["Warnings: none"]
|
|
27
|
+
: ["Warnings:", ...result.warnings.map((warning) => ` - ${warning}`)]),
|
|
28
|
+
].join("\n");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function formatEvolutionDistillationBatch(batch: EvolutionDistillationBatch): string {
|
|
32
|
+
return [
|
|
33
|
+
"EvoDev evolution distillation",
|
|
34
|
+
"",
|
|
35
|
+
`Batch: ${batch.id}`,
|
|
36
|
+
`Project: ${batch.projectKey}`,
|
|
37
|
+
`Run: ${batch.runId}`,
|
|
38
|
+
`Evidence events: ${batch.evidenceWindow.events.length}`,
|
|
39
|
+
`Episodes: ${batch.evidenceWindow.episodes.length}`,
|
|
40
|
+
`Trigger: ${batch.evidenceWindow.triggerPolicy.strongest}; distillRecommended=${batch.evidenceWindow.triggerPolicy.distillRecommended}`,
|
|
41
|
+
`Knowledge records: ${batch.knowledgeRecords.length}`,
|
|
42
|
+
`Evos cases: ${batch.evosCases.length}`,
|
|
43
|
+
`Repo proposals: ${batch.repoProposals.length}`,
|
|
44
|
+
"Default batch review state: contextual until the OKF plan auto-accepts or queues review.",
|
|
45
|
+
"Runtime authority: accepted/auto-accepted only; hardBlocking=false.",
|
|
46
|
+
...(batch.knowledgeRecords.length === 0
|
|
47
|
+
? ["Knowledge: none"]
|
|
48
|
+
: [
|
|
49
|
+
"Knowledge:",
|
|
50
|
+
...batch.knowledgeRecords.map(
|
|
51
|
+
(record) =>
|
|
52
|
+
` - ${record.id} (${record.kind}, ${record.reviewState}, ${record.confidence}): ${record.title}`,
|
|
53
|
+
),
|
|
54
|
+
]),
|
|
55
|
+
...(batch.evosCases.length === 0
|
|
56
|
+
? ["Evos cases: none"]
|
|
57
|
+
: [
|
|
58
|
+
"Evos cases:",
|
|
59
|
+
...batch.evosCases.map(
|
|
60
|
+
(evosCase) =>
|
|
61
|
+
` - ${evosCase.id} (${evosCase.reviewState}, ${evosCase.confidence}): ${evosCase.title}`,
|
|
62
|
+
),
|
|
63
|
+
]),
|
|
64
|
+
...(batch.repoProposals.length === 0
|
|
65
|
+
? ["Repo proposals: none"]
|
|
66
|
+
: [
|
|
67
|
+
"Repo proposals:",
|
|
68
|
+
...batch.repoProposals.map(
|
|
69
|
+
(proposal) =>
|
|
70
|
+
` - ${proposal.id} (${proposal.kind}, ${proposal.reviewState}, ${proposal.confidence}): ${proposal.title}`,
|
|
71
|
+
),
|
|
72
|
+
]),
|
|
73
|
+
...(batch.warnings.length === 0
|
|
74
|
+
? []
|
|
75
|
+
: ["Warnings:", ...batch.warnings.map((warning) => ` - ${warning}`)]),
|
|
76
|
+
].join("\n");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function formatEvolutionWriteResult(result: EvolutionWriteResult): string {
|
|
80
|
+
return [
|
|
81
|
+
"EvoDev evolution write",
|
|
82
|
+
"",
|
|
83
|
+
`Evidence window: ${result.evidenceWindowPath}`,
|
|
84
|
+
`Distillation batch: ${result.batchPath}`,
|
|
85
|
+
`Knowledge records: ${result.knowledgePaths.length}`,
|
|
86
|
+
...result.knowledgePaths.map((path) => ` - ${path}`),
|
|
87
|
+
`Evos cases: ${result.evosCasePaths.length}`,
|
|
88
|
+
...result.evosCasePaths.map((path) => ` - ${path}`),
|
|
89
|
+
`Repo proposals: ${result.repoProposalPaths.length}`,
|
|
90
|
+
...result.repoProposalPaths.map((path) => ` - ${path}`),
|
|
91
|
+
`Knowledge index: ${result.knowledgeIndexPath}`,
|
|
92
|
+
`Evos index: ${result.evosIndexPath}`,
|
|
93
|
+
].join("\n");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function formatEvolutionActivationResult(result: EvolutionActivationResult): string {
|
|
97
|
+
return [
|
|
98
|
+
"EvoDev evolution activate",
|
|
99
|
+
"",
|
|
100
|
+
`Evidence window: ${result.evidenceWindowPath}`,
|
|
101
|
+
`Distillation batch: ${result.batchPath}`,
|
|
102
|
+
`OKF concepts: ${result.okf.conceptPaths.length}`,
|
|
103
|
+
...result.okf.conceptPaths.map((path) => ` - ${path}`),
|
|
104
|
+
`OKF overlays: ${result.okf.overlayPaths.length}`,
|
|
105
|
+
...result.okf.overlayPaths.map((path) => ` - ${path}`),
|
|
106
|
+
`Skipped candidates: ${result.okf.skippedCandidates.length}`,
|
|
107
|
+
...result.okf.skippedCandidates.map((id) => ` - ${id}`),
|
|
108
|
+
`Needs human: ${result.okf.needsHumanCandidates.length}`,
|
|
109
|
+
...result.okf.needsHumanCandidates.map((id) => ` - ${id}`),
|
|
110
|
+
`Evos cases: ${result.evosCasePaths.length}`,
|
|
111
|
+
...result.evosCasePaths.map((path) => ` - ${path}`),
|
|
112
|
+
`Repo proposals: ${result.repoProposalPaths.length}`,
|
|
113
|
+
...result.repoProposalPaths.map((path) => ` - ${path}`),
|
|
114
|
+
`OKF derived indexes: ${result.okf.derivedIndexPaths.length}`,
|
|
115
|
+
...result.okf.derivedIndexPaths.map((path) => ` - ${path}`),
|
|
116
|
+
`Evos index: ${result.evosIndexPath}`,
|
|
117
|
+
].join("\n");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function formatEvolutionProcessResult(result: EvolutionProcessResult): string {
|
|
121
|
+
return [
|
|
122
|
+
"EvoDev evolution process",
|
|
123
|
+
"",
|
|
124
|
+
`Mode: ${result.dryRun ? "dry-run" : "write"}`,
|
|
125
|
+
`Processed triggers: ${result.processed}`,
|
|
126
|
+
`Consumed: ${result.consumed}`,
|
|
127
|
+
`Skipped: ${result.skipped}`,
|
|
128
|
+
`Failed: ${result.failed}`,
|
|
129
|
+
`Still pending: ${result.pending}`,
|
|
130
|
+
`Batches: ${result.batchIds.length}`,
|
|
131
|
+
...result.batchIds.map((batchId) => ` - ${batchId}`),
|
|
132
|
+
...(result.warnings.length === 0
|
|
133
|
+
? ["Warnings: none"]
|
|
134
|
+
: ["Warnings:", ...result.warnings.map((warning) => ` - ${warning}`)]),
|
|
135
|
+
].join("\n");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function formatEvolutionReviewSnapshot(snapshot: EvolutionReviewSnapshot): string {
|
|
139
|
+
return [
|
|
140
|
+
"EvoDev evolution review snapshot",
|
|
141
|
+
"",
|
|
142
|
+
`Project: ${snapshot.projectKey ?? "all"}`,
|
|
143
|
+
`Knowledge records: ${snapshot.knowledgeRecords.length}`,
|
|
144
|
+
...snapshot.knowledgeRecords.map(
|
|
145
|
+
(record) =>
|
|
146
|
+
` - ${record.id} (${record.projectKey}, ${record.kind}, ${record.reviewState}, ${record.confidence}): ${record.title}`,
|
|
147
|
+
),
|
|
148
|
+
`Evos cases: ${snapshot.evosCases.length}`,
|
|
149
|
+
...snapshot.evosCases.map(
|
|
150
|
+
(evosCase) =>
|
|
151
|
+
` - ${evosCase.id} (${evosCase.projectKey}, ${evosCase.reviewState}, ${evosCase.confidence}): ${evosCase.title}`,
|
|
152
|
+
),
|
|
153
|
+
`Repo proposals: ${snapshot.repoProposals.length}`,
|
|
154
|
+
...snapshot.repoProposals.map(
|
|
155
|
+
(proposal) =>
|
|
156
|
+
` - ${proposal.id} (${proposal.projectKey}, ${proposal.kind}, ${proposal.reviewState}, ${proposal.confidence}): ${proposal.title}`,
|
|
157
|
+
),
|
|
158
|
+
`Review candidates: ${snapshot.reviewCandidates.length}`,
|
|
159
|
+
...snapshot.reviewCandidates.map(
|
|
160
|
+
(candidate) =>
|
|
161
|
+
` - ${candidate.id} (${candidate.projectKey}, ${candidate.candidateKind}, ${candidate.reviewState}): ${candidate.title}`,
|
|
162
|
+
),
|
|
163
|
+
`Triggers: ${snapshot.triggers.length}`,
|
|
164
|
+
...snapshot.triggers.map(
|
|
165
|
+
(trigger) =>
|
|
166
|
+
` - ${trigger.id} (${trigger.projectKey}, ${trigger.runId}, ${trigger.eventType}, ${trigger.status}, ${trigger.triggerStrength}): ${trigger.summary}`,
|
|
167
|
+
),
|
|
168
|
+
].join("\n");
|
|
169
|
+
}
|