dsh-snail-memory 0.0.0-stage → 0.1.6
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/README.md +139 -2
- package/cordis.patch.yml +3 -0
- package/dist/api/command.d.ts +3 -0
- package/dist/api/command.js +73 -0
- package/dist/api/controller.d.ts +70 -0
- package/dist/api/controller.js +156 -0
- package/dist/api/errors.d.ts +6 -0
- package/dist/api/errors.js +29 -0
- package/dist/api/http.d.ts +17 -0
- package/dist/api/http.js +54 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +29 -0
- package/dist/api/validate.d.ts +2 -0
- package/dist/api/validate.js +110 -0
- package/dist/client.js +2352 -0
- package/dist/context/message-source.d.ts +8 -0
- package/dist/context/message-source.js +1 -0
- package/dist/context/service.d.ts +62 -0
- package/dist/context/service.js +233 -0
- package/dist/context/snapshot.d.ts +22 -0
- package/dist/context/snapshot.js +62 -0
- package/dist/context/tool.d.ts +6 -0
- package/dist/context/tool.js +125 -0
- package/dist/contract.d.ts +115 -0
- package/dist/contract.js +5 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +190 -0
- package/dist/lifecycle/activity.d.ts +70 -0
- package/dist/lifecycle/activity.js +104 -0
- package/dist/lifecycle/consolidate.d.ts +13 -0
- package/dist/lifecycle/consolidate.js +118 -0
- package/dist/lifecycle/counters.d.ts +17 -0
- package/dist/lifecycle/counters.js +67 -0
- package/dist/lifecycle/distill.d.ts +24 -0
- package/dist/lifecycle/distill.js +91 -0
- package/dist/lifecycle/index.d.ts +14 -0
- package/dist/lifecycle/index.js +7 -0
- package/dist/lifecycle/llm.d.ts +50 -0
- package/dist/lifecycle/llm.js +164 -0
- package/dist/lifecycle/retention.d.ts +12 -0
- package/dist/lifecycle/retention.js +45 -0
- package/dist/lifecycle/scheduler.d.ts +88 -0
- package/dist/lifecycle/scheduler.js +689 -0
- package/dist/lifecycle/service.d.ts +73 -0
- package/dist/lifecycle/service.js +299 -0
- package/dist/lifecycle/settings.d.ts +13 -0
- package/dist/lifecycle/settings.js +107 -0
- package/dist/lifecycle/writer-runtime.d.ts +25 -0
- package/dist/lifecycle/writer-runtime.js +70 -0
- package/dist/runtime.d.ts +52 -0
- package/dist/runtime.js +144 -0
- package/dist/safety/index.d.ts +5 -0
- package/dist/safety/index.js +4 -0
- package/dist/safety/policy.d.ts +5 -0
- package/dist/safety/policy.js +27 -0
- package/dist/safety/redact.d.ts +3 -0
- package/dist/safety/redact.js +21 -0
- package/dist/safety/scanner.d.ts +2 -0
- package/dist/safety/scanner.js +103 -0
- package/dist/safety/types.d.ts +39 -0
- package/dist/safety/types.js +14 -0
- package/dist/store/aggregate.d.ts +5 -0
- package/dist/store/aggregate.js +20 -0
- package/dist/store/chunks.d.ts +8 -0
- package/dist/store/chunks.js +35 -0
- package/dist/store/json.d.ts +10 -0
- package/dist/store/json.js +157 -0
- package/dist/store/lock.d.ts +42 -0
- package/dist/store/lock.js +263 -0
- package/dist/store/paths.d.ts +20 -0
- package/dist/store/paths.js +45 -0
- package/dist/store/projections.d.ts +5 -0
- package/dist/store/projections.js +140 -0
- package/dist/store/records.d.ts +5 -0
- package/dist/store/records.js +41 -0
- package/dist/store/store.d.ts +54 -0
- package/dist/store/store.js +576 -0
- package/dist/store/types.d.ts +178 -0
- package/dist/store/types.js +6 -0
- package/dist/time.d.ts +3 -0
- package/dist/time.js +15 -0
- package/dsh.plugin.json +31 -0
- package/package.json +127 -4
- package/plugin.json +31 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { memoryId, workspaceId } from '../store/types.js';
|
|
2
|
+
import { MemoryApiError } from './errors.js';
|
|
3
|
+
const CATEGORIES = ['preference', 'project-convention', 'environment-fact', 'troubleshooting', 'long-term-decision'];
|
|
4
|
+
const ID = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/u;
|
|
5
|
+
function record(value) {
|
|
6
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
7
|
+
throw new MemoryApiError('invalid-request', 'Expected a JSON object.');
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function string(value, name, max = 128, optional = false) {
|
|
11
|
+
if (value === undefined && optional)
|
|
12
|
+
return undefined;
|
|
13
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > max || (name !== 'summary' && name !== 'detail' && !ID.test(value))) {
|
|
14
|
+
throw new MemoryApiError('invalid-request', `Invalid ${name}.`);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function scope(value) {
|
|
19
|
+
const input = record(value);
|
|
20
|
+
if (input.kind === 'global')
|
|
21
|
+
return { kind: 'global' };
|
|
22
|
+
if (input.kind === 'workspace')
|
|
23
|
+
return { kind: 'workspace', workspaceId: workspaceId(string(input.workspaceId, 'workspaceId')) };
|
|
24
|
+
throw new MemoryApiError('invalid-request', 'Invalid memory scope.');
|
|
25
|
+
}
|
|
26
|
+
function category(value) {
|
|
27
|
+
if (typeof value !== 'string' || !CATEGORIES.includes(value))
|
|
28
|
+
throw new MemoryApiError('invalid-request', 'Invalid memory category.');
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function session(value, optional = false) {
|
|
32
|
+
return string(value, 'sessionId', 128, optional);
|
|
33
|
+
}
|
|
34
|
+
function settings(input) {
|
|
35
|
+
if (typeof input.reviewEveryUserTurns !== 'number'
|
|
36
|
+
|| !Number.isSafeInteger(input.reviewEveryUserTurns) || input.reviewEveryUserTurns < 1) {
|
|
37
|
+
throw new MemoryApiError('invalid-request', 'Invalid reviewEveryUserTurns.');
|
|
38
|
+
}
|
|
39
|
+
if (typeof input.idleDelayMinutes !== 'number'
|
|
40
|
+
|| !Number.isFinite(input.idleDelayMinutes) || input.idleDelayMinutes < 0) {
|
|
41
|
+
throw new MemoryApiError('invalid-request', 'Invalid idleDelayMinutes.');
|
|
42
|
+
}
|
|
43
|
+
if (typeof input.consolidationCooldownHours !== 'number'
|
|
44
|
+
|| !Number.isFinite(input.consolidationCooldownHours) || input.consolidationCooldownHours < 0) {
|
|
45
|
+
throw new MemoryApiError('invalid-request', 'Invalid consolidationCooldownHours.');
|
|
46
|
+
}
|
|
47
|
+
if (typeof input.globalConsolidationCooldownDays !== 'number'
|
|
48
|
+
|| !Number.isFinite(input.globalConsolidationCooldownDays) || input.globalConsolidationCooldownDays < 0) {
|
|
49
|
+
throw new MemoryApiError('invalid-request', 'Invalid globalConsolidationCooldownDays.');
|
|
50
|
+
}
|
|
51
|
+
if (typeof input.snapshotTokenBudget !== 'number'
|
|
52
|
+
|| !Number.isSafeInteger(input.snapshotTokenBudget) || input.snapshotTokenBudget < 1) {
|
|
53
|
+
throw new MemoryApiError('invalid-request', 'Invalid snapshotTokenBudget.');
|
|
54
|
+
}
|
|
55
|
+
const retention = record(input.retentionDays);
|
|
56
|
+
const retentionDays = {};
|
|
57
|
+
for (const category of CATEGORIES) {
|
|
58
|
+
const days = retention[category];
|
|
59
|
+
if (typeof days !== 'number' || !Number.isFinite(days) || days < 0) {
|
|
60
|
+
throw new MemoryApiError('invalid-request', `Invalid retentionDays.${category}.`);
|
|
61
|
+
}
|
|
62
|
+
retentionDays[category] = days;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
reviewEveryUserTurns: input.reviewEveryUserTurns,
|
|
66
|
+
idleDelayMinutes: input.idleDelayMinutes,
|
|
67
|
+
consolidationCooldownHours: input.consolidationCooldownHours,
|
|
68
|
+
globalConsolidationCooldownDays: input.globalConsolidationCooldownDays,
|
|
69
|
+
snapshotTokenBudget: input.snapshotTokenBudget,
|
|
70
|
+
retentionDays,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function write(input) {
|
|
74
|
+
return {
|
|
75
|
+
scope: scope(input.scope), category: category(input.category),
|
|
76
|
+
summary: string(input.summary, 'summary', 500), detail: string(input.detail, 'detail', 16_000),
|
|
77
|
+
sessionId: session(input.sessionId, true),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function validatePayload(method, payload) {
|
|
81
|
+
const input = record(payload);
|
|
82
|
+
switch (method) {
|
|
83
|
+
case 'getSessionState':
|
|
84
|
+
case 'disable': return { sessionId: session(input.sessionId) };
|
|
85
|
+
case 'enable':
|
|
86
|
+
case 'refresh': {
|
|
87
|
+
if (input.layer !== 'global' && input.layer !== 'workspace')
|
|
88
|
+
throw new MemoryApiError('invalid-request', 'Invalid memory layer.');
|
|
89
|
+
if (input.workspaceId !== undefined && (method !== 'enable' || input.layer !== 'workspace')) {
|
|
90
|
+
throw new MemoryApiError('invalid-request', 'workspaceId is only valid when enabling workspace memory.');
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
sessionId: session(input.sessionId),
|
|
94
|
+
layer: input.layer,
|
|
95
|
+
...(input.workspaceId === undefined ? {} : { workspaceId: workspaceId(string(input.workspaceId, 'workspaceId')) }),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
case 'list':
|
|
99
|
+
case 'consolidate': return { scope: scope(input.scope) };
|
|
100
|
+
case 'read':
|
|
101
|
+
case 'remove':
|
|
102
|
+
case 'promote': return { scope: scope(input.scope), id: memoryId(string(input.id, 'id')) };
|
|
103
|
+
case 'remember': return write(input);
|
|
104
|
+
case 'correct': return { ...write(input), id: memoryId(string(input.id, 'id')) };
|
|
105
|
+
case 'status':
|
|
106
|
+
case 'getSettings':
|
|
107
|
+
case 'listWorkspaces': return {};
|
|
108
|
+
case 'updateSettings': return settings(input);
|
|
109
|
+
}
|
|
110
|
+
}
|