@devflow-tools/database 0.17.8 → 0.18.0
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/LICENSE +21 -0
- package/dist/data/LocalDataProvider.d.ts +63 -0
- package/dist/data/LocalDataProvider.js +332 -0
- package/dist/data/default-enforcer-rules.d.ts +3 -0
- package/dist/data/default-enforcer-rules.js +170 -0
- package/dist/data/devflow-schema.d.ts +2 -0
- package/dist/data/devflow-schema.js +80 -0
- package/dist/database.d.ts +45 -7
- package/dist/database.js +583 -125
- package/dist/index.d.ts +8 -4
- package/dist/index.js +11 -5
- package/dist/retrieval-ledger.d.ts +16 -1
- package/dist/retrieval-ledger.js +6 -0
- package/dist/retrieval-runtime.d.ts +39 -0
- package/dist/retrieval-runtime.js +2 -0
- package/dist/task-aggregate.d.ts +49 -0
- package/dist/task-aggregate.js +2 -0
- package/dist/task-semantic-control.d.ts +8 -1
- package/dist/task-semantic-control.js +2 -4
- package/package.json +15 -3
- package/CHANGELOG.md +0 -844
- package/__tests__/database.failure-category.test.ts +0 -44
- package/__tests__/database.host-actions.test.ts +0 -405
- package/__tests__/database.learning-candidates.test.ts +0 -93
- package/__tests__/database.memory-turn-receipts.test.ts +0 -98
- package/__tests__/database.retrieval-ledger.test.ts +0 -68
- package/__tests__/database.retrieval-sessions.test.ts +0 -79
- package/__tests__/database.semantic-resolution.test.ts +0 -87
- package/__tests__/database.skill-executions.test.ts +0 -456
- package/__tests__/database.task-runtime.test.ts +0 -73
- package/__tests__/database.test.ts +0 -177
- package/__tests__/database.work-queue.test.ts +0 -274
- package/__tests__/database.workflow-workers.test.ts +0 -60
- package/__tests__/node-sqlite.test.ts +0 -68
- package/src/database.ts +0 -5853
- package/src/host-actions.ts +0 -211
- package/src/index.ts +0 -153
- package/src/learning-candidates.ts +0 -181
- package/src/node-sqlite.ts +0 -60
- package/src/obligation-ledger.ts +0 -57
- package/src/retrieval-ledger.ts +0 -35
- package/src/retrieval-sessions.ts +0 -196
- package/src/semantic-resolution.ts +0 -181
- package/src/task-runtime.ts +0 -169
- package/src/task-semantic-control.ts +0 -270
- package/src/types.ts +0 -17
- package/src/work-queue.ts +0 -123
- package/src/workflow-workers.ts +0 -198
- package/tsconfig.json +0 -19
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -41
package/src/host-actions.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
export type HostActionState =
|
|
2
|
-
| 'waiting'
|
|
3
|
-
| 'running'
|
|
4
|
-
| 'reported'
|
|
5
|
-
| 'verified'
|
|
6
|
-
| 'failed'
|
|
7
|
-
| 'cancelled'
|
|
8
|
-
| 'degraded';
|
|
9
|
-
|
|
10
|
-
export interface HostActionRecord {
|
|
11
|
-
actionId: string;
|
|
12
|
-
runId: string;
|
|
13
|
-
engineRunId: string;
|
|
14
|
-
stepId: string;
|
|
15
|
-
projectRoot: string;
|
|
16
|
-
sessionId?: string;
|
|
17
|
-
executionId?: string;
|
|
18
|
-
contextReceipt?: string;
|
|
19
|
-
state: HostActionState;
|
|
20
|
-
report: Record<string, unknown>;
|
|
21
|
-
evidenceHash?: string;
|
|
22
|
-
createdAt: number;
|
|
23
|
-
updatedAt: number;
|
|
24
|
-
finishedAt?: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface RequestHostActionInput {
|
|
28
|
-
actionId?: string;
|
|
29
|
-
runId: string;
|
|
30
|
-
engineRunId: string;
|
|
31
|
-
stepId: string;
|
|
32
|
-
projectRoot: string;
|
|
33
|
-
sessionId?: string;
|
|
34
|
-
executionId?: string;
|
|
35
|
-
contextReceipt?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface StartHostActionInput {
|
|
39
|
-
actionId: string;
|
|
40
|
-
projectRoot: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface ReportHostActionInput {
|
|
44
|
-
actionId: string;
|
|
45
|
-
projectRoot: string;
|
|
46
|
-
report: Record<string, unknown>;
|
|
47
|
-
evidenceHash?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface VerifyHostActionInput extends ReportHostActionInput {
|
|
51
|
-
evidenceHash: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface FailHostActionInput extends ReportHostActionInput {
|
|
55
|
-
outcome?: 'failed' | 'cancelled' | 'degraded';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const HOST_ACTION_STATES = new Set<HostActionState>([
|
|
59
|
-
'waiting',
|
|
60
|
-
'running',
|
|
61
|
-
'reported',
|
|
62
|
-
'verified',
|
|
63
|
-
'failed',
|
|
64
|
-
'cancelled',
|
|
65
|
-
'degraded',
|
|
66
|
-
]);
|
|
67
|
-
|
|
68
|
-
export function isHostActionState(value: unknown): value is HostActionState {
|
|
69
|
-
return typeof value === 'string' && HOST_ACTION_STATES.has(value as HostActionState);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function mapHostActionRow(row: Record<string, unknown>): HostActionRecord {
|
|
73
|
-
if (!isHostActionState(row.state)) {
|
|
74
|
-
throw new Error(`Invalid persisted host action state: ${String(row.state)}`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
actionId: asRequiredString(row.action_id, 'action_id'),
|
|
79
|
-
runId: asRequiredString(row.run_id, 'run_id'),
|
|
80
|
-
engineRunId: asRequiredString(row.engine_run_id, 'engine_run_id'),
|
|
81
|
-
stepId: asRequiredString(row.step_id, 'step_id'),
|
|
82
|
-
projectRoot: asRequiredString(row.project_root, 'project_root'),
|
|
83
|
-
sessionId: asOptionalString(row.session_id),
|
|
84
|
-
executionId: asOptionalString(row.execution_id),
|
|
85
|
-
contextReceipt: asOptionalString(row.context_receipt),
|
|
86
|
-
state: row.state,
|
|
87
|
-
report: parseReport(row.report_json),
|
|
88
|
-
evidenceHash: asOptionalString(row.evidence_hash),
|
|
89
|
-
createdAt: asFiniteNumber(row.created_at, 'created_at'),
|
|
90
|
-
updatedAt: asFiniteNumber(row.updated_at, 'updated_at'),
|
|
91
|
-
finishedAt: asOptionalFiniteNumber(row.finished_at),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function serializeHostActionReport(report: Record<string, unknown>): string {
|
|
96
|
-
if (!isPlainObject(report)) throw new Error('Host action report must be a plain object');
|
|
97
|
-
return JSON.stringify(canonicalizeJson(report, '$', new WeakSet<object>()));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function hostActionReportsEqual(
|
|
101
|
-
left: Record<string, unknown>,
|
|
102
|
-
right: Record<string, unknown>,
|
|
103
|
-
): boolean {
|
|
104
|
-
return serializeHostActionReport(left) === serializeHostActionReport(right);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function parseReport(value: unknown): Record<string, unknown> {
|
|
108
|
-
if (typeof value !== 'string') {
|
|
109
|
-
throw new Error('Invalid persisted host action report_json: expected JSON text');
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
const parsed: unknown = JSON.parse(value);
|
|
113
|
-
if (!isPlainObject(parsed)) {
|
|
114
|
-
throw new Error('expected a JSON object');
|
|
115
|
-
}
|
|
116
|
-
serializeHostActionReport(parsed);
|
|
117
|
-
return parsed;
|
|
118
|
-
} catch (error) {
|
|
119
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
120
|
-
throw new Error(`Invalid persisted host action report_json: ${detail}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function canonicalizeJson(value: unknown, path: string, ancestors: WeakSet<object>): unknown {
|
|
125
|
-
if (value === null || typeof value === 'string' || typeof value === 'boolean') return value;
|
|
126
|
-
if (typeof value === 'number') {
|
|
127
|
-
if (!Number.isFinite(value) || Object.is(value, -0)) {
|
|
128
|
-
throw nonJsonValueError(path);
|
|
129
|
-
}
|
|
130
|
-
return value;
|
|
131
|
-
}
|
|
132
|
-
if (typeof value !== 'object') throw nonJsonValueError(path);
|
|
133
|
-
if (ancestors.has(value)) throw new Error(`Host action report contains a cycle at ${path}`);
|
|
134
|
-
|
|
135
|
-
ancestors.add(value);
|
|
136
|
-
try {
|
|
137
|
-
if (Array.isArray(value)) return canonicalizeArray(value, path, ancestors);
|
|
138
|
-
if (!isPlainObject(value)) throw nonJsonValueError(path);
|
|
139
|
-
|
|
140
|
-
const result: Record<string, unknown> = Object.create(null) as Record<string, unknown>;
|
|
141
|
-
const keys = Reflect.ownKeys(value);
|
|
142
|
-
for (const key of keys) {
|
|
143
|
-
if (typeof key !== 'string') throw nonJsonValueError(`${path}[symbol]`);
|
|
144
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
145
|
-
if (!descriptor?.enumerable || !('value' in descriptor)) {
|
|
146
|
-
throw nonJsonValueError(`${path}.${key}`);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
for (const key of (keys as string[]).slice().sort(comparePropertyKeys)) {
|
|
150
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
|
|
151
|
-
result[key] = canonicalizeJson(descriptor.value, `${path}.${key}`, ancestors);
|
|
152
|
-
}
|
|
153
|
-
return result;
|
|
154
|
-
} finally {
|
|
155
|
-
ancestors.delete(value);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function canonicalizeArray(value: unknown[], path: string, ancestors: WeakSet<object>): unknown[] {
|
|
160
|
-
if (Object.getPrototypeOf(value) !== Array.prototype) throw nonJsonValueError(path);
|
|
161
|
-
const keys = Reflect.ownKeys(value);
|
|
162
|
-
const expectedKeys = new Set(['length', ...Array.from({ length: value.length }, (_, index) => String(index))]);
|
|
163
|
-
if (keys.some(key => typeof key !== 'string' || !expectedKeys.has(key))) {
|
|
164
|
-
throw nonJsonValueError(path);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return Array.from({ length: value.length }, (_, index) => {
|
|
168
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
169
|
-
if (!descriptor?.enumerable || !('value' in descriptor)) {
|
|
170
|
-
throw nonJsonValueError(`${path}[${index}]`);
|
|
171
|
-
}
|
|
172
|
-
return canonicalizeJson(descriptor.value, `${path}[${index}]`, ancestors);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function comparePropertyKeys(left: string, right: string): number {
|
|
177
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function nonJsonValueError(path: string): Error {
|
|
181
|
-
return new Error(`Host action report contains a non-JSON value at ${path}`);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
185
|
-
if (value === null || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
186
|
-
const prototype = Object.getPrototypeOf(value);
|
|
187
|
-
return prototype === Object.prototype || prototype === null;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function asRequiredString(value: unknown, column: string): string {
|
|
191
|
-
if (typeof value !== 'string' || value.length === 0) {
|
|
192
|
-
throw new Error(`Invalid persisted host action ${column}`);
|
|
193
|
-
}
|
|
194
|
-
return value;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function asOptionalString(value: unknown): string | undefined {
|
|
198
|
-
return typeof value === 'string' ? value : undefined;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function asFiniteNumber(value: unknown, column: string): number {
|
|
202
|
-
const number = Number(value);
|
|
203
|
-
if (!Number.isFinite(number)) throw new Error(`Invalid persisted host action ${column}`);
|
|
204
|
-
return number;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function asOptionalFiniteNumber(value: unknown): number | undefined {
|
|
208
|
-
if (value === null || value === undefined) return undefined;
|
|
209
|
-
const number = Number(value);
|
|
210
|
-
return Number.isFinite(number) ? number : undefined;
|
|
211
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
DevFlowDatabase,
|
|
3
|
-
getGlobalDevFlowDbPath,
|
|
4
|
-
openGlobalDevFlowDatabase,
|
|
5
|
-
openGlobalDevFlowReadOnlyDatabase,
|
|
6
|
-
} from './database';
|
|
7
|
-
export type {
|
|
8
|
-
BenchmarkReportMetaRecord,
|
|
9
|
-
BenchmarkReportRecord,
|
|
10
|
-
FeedbackRecord,
|
|
11
|
-
GovernanceAuditRecord,
|
|
12
|
-
GovernanceRuleRecord,
|
|
13
|
-
HookFallbackRecord,
|
|
14
|
-
HookReceiptRecord,
|
|
15
|
-
ContextReceiptRecord,
|
|
16
|
-
ContextSelectionEventRecord,
|
|
17
|
-
PolicyVerificationBaselineRecord,
|
|
18
|
-
MemoryDistillCheckpointRecord,
|
|
19
|
-
MemoryTurnRecord,
|
|
20
|
-
MemoryTurnStatus,
|
|
21
|
-
TelemetryFailureRecord,
|
|
22
|
-
} from './database';
|
|
23
|
-
export type {
|
|
24
|
-
EnqueueWorkInput,
|
|
25
|
-
LeaseWorkInput,
|
|
26
|
-
RequestSessionClosureInput,
|
|
27
|
-
SessionClosureRecord,
|
|
28
|
-
SessionClosureState,
|
|
29
|
-
WorkError,
|
|
30
|
-
WorkItemRecord,
|
|
31
|
-
WorkKind,
|
|
32
|
-
WorkQueueHealth,
|
|
33
|
-
WorkState,
|
|
34
|
-
ProjectMutationLeaseRecord,
|
|
35
|
-
} from './work-queue';
|
|
36
|
-
export type {
|
|
37
|
-
RetrievalLedgerEventRecord,
|
|
38
|
-
RetrievalLedgerSourceType,
|
|
39
|
-
RetrievalLedgerStage,
|
|
40
|
-
} from './retrieval-ledger';
|
|
41
|
-
export {
|
|
42
|
-
hostActionReportsEqual,
|
|
43
|
-
isHostActionState,
|
|
44
|
-
mapHostActionRow,
|
|
45
|
-
serializeHostActionReport,
|
|
46
|
-
} from './host-actions';
|
|
47
|
-
export { RETRIEVAL_MAX_CYCLES, isRetrievalSessionState } from './retrieval-sessions';
|
|
48
|
-
export type {
|
|
49
|
-
AppendRetrievalCycleInput,
|
|
50
|
-
CreateRetrievalSessionInput,
|
|
51
|
-
RetrievalCycleRecord,
|
|
52
|
-
RetrievalGapKind,
|
|
53
|
-
RetrievalGapRecord,
|
|
54
|
-
RetrievalSessionRecord,
|
|
55
|
-
RetrievalSessionState,
|
|
56
|
-
} from './retrieval-sessions';
|
|
57
|
-
export type {
|
|
58
|
-
FailHostActionInput,
|
|
59
|
-
HostActionRecord,
|
|
60
|
-
HostActionState,
|
|
61
|
-
ReportHostActionInput,
|
|
62
|
-
RequestHostActionInput,
|
|
63
|
-
StartHostActionInput,
|
|
64
|
-
VerifyHostActionInput,
|
|
65
|
-
} from './host-actions';
|
|
66
|
-
export {
|
|
67
|
-
mapSessionObligationRow,
|
|
68
|
-
normalizeTurnId,
|
|
69
|
-
} from './obligation-ledger';
|
|
70
|
-
export {
|
|
71
|
-
assertTaskIdentity,
|
|
72
|
-
mapChannelQueryPlanRow,
|
|
73
|
-
mapTaskIntentArtifactRow,
|
|
74
|
-
mapTerminalTransitionRow,
|
|
75
|
-
mapToolNameResolutionRow,
|
|
76
|
-
mapTranscriptCheckpointRow,
|
|
77
|
-
stableSemanticJson,
|
|
78
|
-
} from './task-semantic-control';
|
|
79
|
-
export {
|
|
80
|
-
mapTaskRuntimeEventRow,
|
|
81
|
-
mapTaskRuntimeSnapshotRow,
|
|
82
|
-
stableTaskRuntimeHash,
|
|
83
|
-
stableTaskRuntimeJson,
|
|
84
|
-
} from './task-runtime';
|
|
85
|
-
export type {
|
|
86
|
-
TaskRuntimeChannelRecord,
|
|
87
|
-
TaskRuntimeChannelRequirement,
|
|
88
|
-
TaskRuntimeChannelStatus,
|
|
89
|
-
TaskRuntimeEventRecord,
|
|
90
|
-
TaskRuntimeIdentityRecord,
|
|
91
|
-
TaskRuntimeObligationRecord,
|
|
92
|
-
TaskRuntimeObligationState,
|
|
93
|
-
TaskRuntimeSnapshotRecord,
|
|
94
|
-
} from './task-runtime';
|
|
95
|
-
export type {
|
|
96
|
-
ChannelQueryPlanRecord,
|
|
97
|
-
TaskIdentityRecord,
|
|
98
|
-
TaskIntentArtifactRecord,
|
|
99
|
-
TerminalTransitionRecord,
|
|
100
|
-
ToolNameResolutionRecord,
|
|
101
|
-
ToolNameResolutionStatus,
|
|
102
|
-
TranscriptCheckpointRecord,
|
|
103
|
-
} from './task-semantic-control';
|
|
104
|
-
export {
|
|
105
|
-
LEGAL_WORKFLOW_WORKER_TRANSITIONS,
|
|
106
|
-
TERMINAL_WORKFLOW_WORKER_STATES,
|
|
107
|
-
mapWorkflowMergeRow,
|
|
108
|
-
mapWorkflowWorkerEventRow,
|
|
109
|
-
mapWorkflowWorkerRow,
|
|
110
|
-
} from './workflow-workers';
|
|
111
|
-
export type {
|
|
112
|
-
CreateWorkflowWorkerInput,
|
|
113
|
-
EnqueueWorkflowMergeInput,
|
|
114
|
-
TransitionWorkflowWorkerInput,
|
|
115
|
-
WorkflowMergeRecord,
|
|
116
|
-
WorkflowMergeState,
|
|
117
|
-
WorkflowWorkerEventRecord,
|
|
118
|
-
WorkflowWorkerRecord,
|
|
119
|
-
WorkflowWorkerState,
|
|
120
|
-
} from './workflow-workers';
|
|
121
|
-
export {
|
|
122
|
-
mapLearningCandidateRow,
|
|
123
|
-
mapLearningEvidenceRow,
|
|
124
|
-
mapLearningVersionRow,
|
|
125
|
-
stableLearningJson,
|
|
126
|
-
} from './learning-candidates';
|
|
127
|
-
export type {
|
|
128
|
-
AddLearningCandidateEvidenceInput,
|
|
129
|
-
LearningCandidateEvidenceRecord,
|
|
130
|
-
LearningCandidateKind,
|
|
131
|
-
LearningCandidateRecord,
|
|
132
|
-
LearningCandidateState,
|
|
133
|
-
LearningCandidateVersionRecord,
|
|
134
|
-
LearningEvidencePolarity,
|
|
135
|
-
LearningOutcomeState,
|
|
136
|
-
TransitionLearningCandidateInput,
|
|
137
|
-
UpsertLearningCandidateInput,
|
|
138
|
-
} from './learning-candidates';
|
|
139
|
-
export type {
|
|
140
|
-
SessionObligationKind,
|
|
141
|
-
SessionObligationRecord,
|
|
142
|
-
SessionObligationState,
|
|
143
|
-
} from './obligation-ledger';
|
|
144
|
-
export {
|
|
145
|
-
assertSemanticResolutionRecord,
|
|
146
|
-
mapSemanticResolutionRow,
|
|
147
|
-
stableSemanticResolutionJson,
|
|
148
|
-
} from './semantic-resolution';
|
|
149
|
-
export type {
|
|
150
|
-
PersistedSemanticGeneratedBy,
|
|
151
|
-
PersistedSemanticResolutionState,
|
|
152
|
-
SemanticResolutionRecord,
|
|
153
|
-
} from './semantic-resolution';
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
export type LearningCandidateState =
|
|
2
|
-
| 'observed'
|
|
3
|
-
| 'candidate'
|
|
4
|
-
| 'shadow'
|
|
5
|
-
| 'evaluated'
|
|
6
|
-
| 'active'
|
|
7
|
-
| 'rejected'
|
|
8
|
-
| 'retired';
|
|
9
|
-
|
|
10
|
-
export type LearningCandidateKind =
|
|
11
|
-
| 'convention'
|
|
12
|
-
| 'workflow'
|
|
13
|
-
| 'tool_preference'
|
|
14
|
-
| 'correction';
|
|
15
|
-
|
|
16
|
-
export type LearningEvidencePolarity = 'supporting' | 'contradicting';
|
|
17
|
-
export type LearningOutcomeState = 'positive' | 'negative' | 'unknown';
|
|
18
|
-
|
|
19
|
-
export interface LearningCandidateRecord {
|
|
20
|
-
id: string;
|
|
21
|
-
projectRoot: string;
|
|
22
|
-
scope: 'project' | 'global';
|
|
23
|
-
state: LearningCandidateState;
|
|
24
|
-
kind: LearningCandidateKind;
|
|
25
|
-
trigger: Record<string, unknown>;
|
|
26
|
-
instruction: string;
|
|
27
|
-
confidence: number;
|
|
28
|
-
overlayVersion: number;
|
|
29
|
-
supportingSessions: number;
|
|
30
|
-
successfulOutcomes: number;
|
|
31
|
-
contradictions: number;
|
|
32
|
-
manualOnly: boolean;
|
|
33
|
-
risk: 'low' | 'medium' | 'high';
|
|
34
|
-
graderReceipt?: string;
|
|
35
|
-
expiresAt?: number;
|
|
36
|
-
createdAt: number;
|
|
37
|
-
updatedAt: number;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface LearningCandidateVersionRecord {
|
|
41
|
-
candidateId: string;
|
|
42
|
-
version: number;
|
|
43
|
-
trigger: Record<string, unknown>;
|
|
44
|
-
instruction: string;
|
|
45
|
-
createdAt: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface LearningCandidateEvidenceRecord {
|
|
49
|
-
id: string;
|
|
50
|
-
candidateId: string;
|
|
51
|
-
projectRoot: string;
|
|
52
|
-
sessionId: string;
|
|
53
|
-
executionId?: string;
|
|
54
|
-
memoryObservationId?: string;
|
|
55
|
-
outcomeId?: string;
|
|
56
|
-
sourceType: 'memory' | 'correction' | 'workflow_outcome' | 'tool_preference' | 'convention' | 'grader' | 'manual';
|
|
57
|
-
polarity: LearningEvidencePolarity;
|
|
58
|
-
outcome: LearningOutcomeState;
|
|
59
|
-
evidenceHash: string;
|
|
60
|
-
receipt?: string;
|
|
61
|
-
payload: Record<string, unknown>;
|
|
62
|
-
createdAt: number;
|
|
63
|
-
resolvedAt?: number;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface UpsertLearningCandidateInput {
|
|
67
|
-
id: string;
|
|
68
|
-
projectRoot: string;
|
|
69
|
-
scope: 'project' | 'global';
|
|
70
|
-
kind: LearningCandidateKind;
|
|
71
|
-
trigger: Record<string, unknown>;
|
|
72
|
-
instruction: string;
|
|
73
|
-
confidence: number;
|
|
74
|
-
manualOnly?: boolean;
|
|
75
|
-
risk?: 'low' | 'medium' | 'high';
|
|
76
|
-
expiresAt?: number;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface AddLearningCandidateEvidenceInput {
|
|
80
|
-
id: string;
|
|
81
|
-
candidateId: string;
|
|
82
|
-
projectRoot: string;
|
|
83
|
-
sessionId: string;
|
|
84
|
-
executionId?: string;
|
|
85
|
-
memoryObservationId?: string;
|
|
86
|
-
outcomeId?: string;
|
|
87
|
-
sourceType: LearningCandidateEvidenceRecord['sourceType'];
|
|
88
|
-
polarity: LearningEvidencePolarity;
|
|
89
|
-
outcome?: LearningOutcomeState;
|
|
90
|
-
evidenceHash: string;
|
|
91
|
-
receipt?: string;
|
|
92
|
-
payload?: Record<string, unknown>;
|
|
93
|
-
createdAt?: number;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface TransitionLearningCandidateInput {
|
|
97
|
-
target: LearningCandidateState;
|
|
98
|
-
reason: string;
|
|
99
|
-
graderReceipt?: string;
|
|
100
|
-
manualApproval?: boolean;
|
|
101
|
-
changedAt?: number;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function mapLearningCandidateRow(row: Record<string, unknown>): LearningCandidateRecord {
|
|
105
|
-
return {
|
|
106
|
-
id: String(row.id),
|
|
107
|
-
projectRoot: String(row.project_root),
|
|
108
|
-
scope: row.scope === 'global' ? 'global' : 'project',
|
|
109
|
-
state: row.state as LearningCandidateState,
|
|
110
|
-
kind: row.kind as LearningCandidateKind,
|
|
111
|
-
trigger: parseRecord(row.trigger_json),
|
|
112
|
-
instruction: String(row.instruction),
|
|
113
|
-
confidence: Number(row.confidence),
|
|
114
|
-
overlayVersion: Number(row.overlay_version),
|
|
115
|
-
supportingSessions: Number(row.supporting_sessions),
|
|
116
|
-
successfulOutcomes: Number(row.successful_outcomes),
|
|
117
|
-
contradictions: Number(row.contradictions),
|
|
118
|
-
manualOnly: Number(row.manual_only) === 1,
|
|
119
|
-
risk: row.risk === 'high' ? 'high' : row.risk === 'medium' ? 'medium' : 'low',
|
|
120
|
-
graderReceipt: optionalString(row.grader_receipt),
|
|
121
|
-
expiresAt: optionalNumber(row.expires_at),
|
|
122
|
-
createdAt: Number(row.created_at),
|
|
123
|
-
updatedAt: Number(row.updated_at),
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function mapLearningEvidenceRow(row: Record<string, unknown>): LearningCandidateEvidenceRecord {
|
|
128
|
-
return {
|
|
129
|
-
id: String(row.id),
|
|
130
|
-
candidateId: String(row.candidate_id),
|
|
131
|
-
projectRoot: String(row.project_root),
|
|
132
|
-
sessionId: String(row.session_id),
|
|
133
|
-
executionId: optionalString(row.execution_id),
|
|
134
|
-
memoryObservationId: optionalString(row.memory_observation_id),
|
|
135
|
-
outcomeId: optionalString(row.outcome_id),
|
|
136
|
-
sourceType: row.source_type as LearningCandidateEvidenceRecord['sourceType'],
|
|
137
|
-
polarity: row.polarity as LearningEvidencePolarity,
|
|
138
|
-
outcome: row.outcome as LearningOutcomeState,
|
|
139
|
-
evidenceHash: String(row.evidence_hash),
|
|
140
|
-
receipt: optionalString(row.receipt),
|
|
141
|
-
payload: parseRecord(row.payload_json),
|
|
142
|
-
createdAt: Number(row.created_at),
|
|
143
|
-
resolvedAt: optionalNumber(row.resolved_at),
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function mapLearningVersionRow(row: Record<string, unknown>): LearningCandidateVersionRecord {
|
|
148
|
-
return {
|
|
149
|
-
candidateId: String(row.candidate_id),
|
|
150
|
-
version: Number(row.version),
|
|
151
|
-
trigger: parseRecord(row.trigger_json),
|
|
152
|
-
instruction: String(row.instruction),
|
|
153
|
-
createdAt: Number(row.created_at),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function stableLearningJson(value: unknown): string {
|
|
158
|
-
if (Array.isArray(value)) return `[${value.map(stableLearningJson).join(',')}]`;
|
|
159
|
-
if (!value || typeof value !== 'object') return JSON.stringify(value) ?? 'null';
|
|
160
|
-
const record = value as Record<string, unknown>;
|
|
161
|
-
return `{${Object.keys(record).sort().map(key => `${JSON.stringify(key)}:${stableLearningJson(record[key])}`).join(',')}}`;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function parseRecord(value: unknown): Record<string, unknown> {
|
|
165
|
-
try {
|
|
166
|
-
const parsed = typeof value === 'string' ? JSON.parse(value) as unknown : value;
|
|
167
|
-
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
168
|
-
? parsed as Record<string, unknown>
|
|
169
|
-
: {};
|
|
170
|
-
} catch {
|
|
171
|
-
return {};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function optionalString(value: unknown): string | undefined {
|
|
176
|
-
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function optionalNumber(value: unknown): number | undefined {
|
|
180
|
-
return value === null || value === undefined ? undefined : Number(value);
|
|
181
|
-
}
|
package/src/node-sqlite.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
-
import type { Database, Statement, RunResult } from './types';
|
|
3
|
-
|
|
4
|
-
export class NodeSqliteDatabase implements Database {
|
|
5
|
-
private db: DatabaseSync;
|
|
6
|
-
|
|
7
|
-
constructor(path: string, busyTimeoutMs = 10000, readOnly = false) {
|
|
8
|
-
this.db = readOnly
|
|
9
|
-
? new DatabaseSync(path, { readOnly: true })
|
|
10
|
-
: new DatabaseSync(path);
|
|
11
|
-
this.db.exec(`PRAGMA busy_timeout = ${Math.max(0, Math.floor(busyTimeoutMs))}`);
|
|
12
|
-
if (!readOnly) {
|
|
13
|
-
this.db.exec('PRAGMA journal_mode = WAL');
|
|
14
|
-
this.db.exec('PRAGMA synchronous = NORMAL');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
exec(sql: string): void {
|
|
19
|
-
this.db.exec(sql);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
prepare(sql: string): Statement {
|
|
23
|
-
const stmt = this.db.prepare(sql);
|
|
24
|
-
return {
|
|
25
|
-
run: (...params: any[]): RunResult => {
|
|
26
|
-
const result = stmt.run(...normalizeParams(params));
|
|
27
|
-
return {
|
|
28
|
-
changes: Number(result.changes),
|
|
29
|
-
lastInsertRowid: result.lastInsertRowid,
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
get: (...params: any[]): any => {
|
|
33
|
-
return stmt.get(...normalizeParams(params));
|
|
34
|
-
},
|
|
35
|
-
all: (...params: any[]): any[] => {
|
|
36
|
-
return stmt.all(...normalizeParams(params));
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
transaction<T>(fn: () => T): T {
|
|
42
|
-
this.db.exec('BEGIN');
|
|
43
|
-
try {
|
|
44
|
-
const result = fn();
|
|
45
|
-
this.db.exec('COMMIT');
|
|
46
|
-
return result;
|
|
47
|
-
} catch (err) {
|
|
48
|
-
this.db.exec('ROLLBACK');
|
|
49
|
-
throw err;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
close(): void {
|
|
54
|
-
this.db.close();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function normalizeParams(params: any[]): any[] {
|
|
59
|
-
return params.map(value => typeof value === 'boolean' ? Number(value) : value);
|
|
60
|
-
}
|
package/src/obligation-ledger.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export type SessionObligationKind =
|
|
2
|
-
| 'memory_decision'
|
|
3
|
-
| 'evidence_contract'
|
|
4
|
-
| 'session_finalize';
|
|
5
|
-
|
|
6
|
-
export type SessionObligationState =
|
|
7
|
-
| 'open'
|
|
8
|
-
| 'satisfied'
|
|
9
|
-
| 'degraded'
|
|
10
|
-
| 'cancelled';
|
|
11
|
-
|
|
12
|
-
export interface SessionObligationRecord {
|
|
13
|
-
obligationId: string;
|
|
14
|
-
projectRoot: string;
|
|
15
|
-
sessionId: string;
|
|
16
|
-
executionId?: string;
|
|
17
|
-
turnId?: string;
|
|
18
|
-
kind: SessionObligationKind;
|
|
19
|
-
state: SessionObligationState;
|
|
20
|
-
payload: Record<string, unknown>;
|
|
21
|
-
receiptId?: string;
|
|
22
|
-
reason?: string;
|
|
23
|
-
createdAt: number;
|
|
24
|
-
updatedAt: number;
|
|
25
|
-
resolvedAt?: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function normalizeTurnId(value: string): string {
|
|
29
|
-
const trimmed = value.trim();
|
|
30
|
-
if (!trimmed) throw new Error('Memory turn ID is required');
|
|
31
|
-
return trimmed.startsWith('turn:') ? trimmed : `turn:${trimmed}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function mapSessionObligationRow(row: Record<string, unknown>): SessionObligationRecord {
|
|
35
|
-
let payload: Record<string, unknown> = {};
|
|
36
|
-
try {
|
|
37
|
-
const parsed = JSON.parse(String(row.payload ?? '{}')) as unknown;
|
|
38
|
-
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
39
|
-
payload = parsed as Record<string, unknown>;
|
|
40
|
-
}
|
|
41
|
-
} catch {}
|
|
42
|
-
return {
|
|
43
|
-
obligationId: String(row.obligation_id),
|
|
44
|
-
projectRoot: String(row.project_root),
|
|
45
|
-
sessionId: String(row.session_id),
|
|
46
|
-
executionId: typeof row.execution_id === 'string' ? row.execution_id : undefined,
|
|
47
|
-
turnId: typeof row.turn_id === 'string' ? row.turn_id : undefined,
|
|
48
|
-
kind: row.kind as SessionObligationKind,
|
|
49
|
-
state: row.state as SessionObligationState,
|
|
50
|
-
payload,
|
|
51
|
-
receiptId: typeof row.receipt_id === 'string' ? row.receipt_id : undefined,
|
|
52
|
-
reason: typeof row.reason === 'string' ? row.reason : undefined,
|
|
53
|
-
createdAt: Number(row.created_at),
|
|
54
|
-
updatedAt: Number(row.updated_at),
|
|
55
|
-
resolvedAt: typeof row.resolved_at === 'number' ? row.resolved_at : undefined,
|
|
56
|
-
};
|
|
57
|
-
}
|
package/src/retrieval-ledger.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export type RetrievalLedgerStage =
|
|
2
|
-
| 'eligible' | 'candidate' | 'selected' | 'exposed' | 'adopted' | 'consumed' | 'verified'
|
|
3
|
-
| 'positive_outcome' | 'negative_outcome' | 'unknown' | 'unknown_outcome' | 'rejected';
|
|
4
|
-
|
|
5
|
-
export type RetrievalLedgerSourceType = 'code' | 'memory' | 'knowledge' | 'action';
|
|
6
|
-
|
|
7
|
-
export interface RetrievalLedgerEventRecord {
|
|
8
|
-
schemaVersion?: 'retrieval-ledger-event.v1';
|
|
9
|
-
id: string;
|
|
10
|
-
projectRoot: string;
|
|
11
|
-
sessionId: string;
|
|
12
|
-
executionId?: string;
|
|
13
|
-
turnId?: string;
|
|
14
|
-
requestId: string;
|
|
15
|
-
contextReceipt: string;
|
|
16
|
-
sourceType: RetrievalLedgerSourceType;
|
|
17
|
-
sourceId: string;
|
|
18
|
-
taskSpecHash?: string;
|
|
19
|
-
actor?: string;
|
|
20
|
-
sourceVersion?: string;
|
|
21
|
-
sourceContentHash?: string;
|
|
22
|
-
evidenceIds?: string[];
|
|
23
|
-
reasonCode?: string;
|
|
24
|
-
stage: RetrievalLedgerStage;
|
|
25
|
-
rank?: number;
|
|
26
|
-
rawScore?: number;
|
|
27
|
-
normalizedScore?: number;
|
|
28
|
-
finalScore?: number;
|
|
29
|
-
applicability: string[];
|
|
30
|
-
reason?: string;
|
|
31
|
-
toolEvidence: string[];
|
|
32
|
-
verificationReceipt?: string;
|
|
33
|
-
payload: Record<string, unknown>;
|
|
34
|
-
createdAt: number;
|
|
35
|
-
}
|