dotmem 0.0.0-stage → 0.0.2
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.md +11 -0
- package/README.md +347 -3
- package/global.d.ts +14 -0
- package/index.d.ts +15 -0
- package/package.json +84 -3
- package/types/agent.d.ts +87 -0
- package/types/assets.d.ts +4 -0
- package/types/bun-sqlite.d.ts +14 -0
- package/types/exports.d.ts +285 -0
- package/types/fflate-browser.d.ts +7 -0
- package/types/inspect.d.ts +14 -0
- package/types/llm-cache.d.ts +53 -0
- package/types/logic.d.ts +79 -0
- package/types/memory.d.ts +336 -0
- package/types/policy.d.ts +291 -0
- package/types/profile.d.ts +27 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
export type MemoryScope = 'hot' | 'session' | 'local' | 'durable'
|
|
2
|
+
|
|
3
|
+
export type MemoryType =
|
|
4
|
+
| 'fact'
|
|
5
|
+
| 'preference'
|
|
6
|
+
| 'decision'
|
|
7
|
+
| 'task'
|
|
8
|
+
| 'context'
|
|
9
|
+
|
|
10
|
+
export type MemoryStatus = 'active' | 'obsolete' | 'superseded'
|
|
11
|
+
export type MemoryKind = 'experience' | 'agent' | 'relationship' | 'logic' | 'note'
|
|
12
|
+
|
|
13
|
+
export type JsonPrimitive = string | number | boolean | null
|
|
14
|
+
export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }
|
|
15
|
+
|
|
16
|
+
export interface EvidenceReference {
|
|
17
|
+
id: string
|
|
18
|
+
source?: string
|
|
19
|
+
observedAt?: string
|
|
20
|
+
/** The bounded statement or result this evidence directly supports. */
|
|
21
|
+
supports?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type EpistemicType = 'observed' | 'inferred' | 'human-stated' | 'verified'
|
|
25
|
+
|
|
26
|
+
export interface ClaimProvenance {
|
|
27
|
+
source: string
|
|
28
|
+
detail?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface RevisionRelationship {
|
|
32
|
+
kind: 'refines' | 'supersedes' | 'retracts'
|
|
33
|
+
claimIds: string[]
|
|
34
|
+
reason?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface AcquiredClaim {
|
|
38
|
+
id: string
|
|
39
|
+
knowledge: JsonValue
|
|
40
|
+
applicability: Record<string, JsonPrimitive>
|
|
41
|
+
evidence: EvidenceReference[]
|
|
42
|
+
epistemicType?: EpistemicType
|
|
43
|
+
provenance?: ClaimProvenance
|
|
44
|
+
acquiredAt?: string
|
|
45
|
+
revision?: RevisionRelationship
|
|
46
|
+
scope?: 'user' | 'project'
|
|
47
|
+
kind?: MemoryKind
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface AcquiredContext {
|
|
51
|
+
knowledgeVersion: number
|
|
52
|
+
claims: AcquiredClaim[]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type DiscoveryDepth = 'current' | 'deep'
|
|
56
|
+
export type DiscoveryField = 'id' | 'knowledge' | 'applicability' | 'evidence' | 'provenance'
|
|
57
|
+
|
|
58
|
+
/** Outcome of one applicability dimension comparison. Never a float score. */
|
|
59
|
+
export type ApplicabilityDimensionState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED'
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whole-claim applicability outcome.
|
|
63
|
+
*
|
|
64
|
+
* - MATCH: every declared dimension the situation also knows matched
|
|
65
|
+
* - MISMATCH: at least one declared dimension conflicts (hard exclusion)
|
|
66
|
+
* - PARTIAL: some dimensions matched, others are unknown in the situation
|
|
67
|
+
* - UNSPECIFIED: the claim declares nothing the situation can resolve
|
|
68
|
+
*/
|
|
69
|
+
export type ApplicabilityState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED' | 'PARTIAL'
|
|
70
|
+
|
|
71
|
+
export interface ApplicabilityMatch {
|
|
72
|
+
state: ApplicabilityState
|
|
73
|
+
/** A MISMATCH is the only state that removes a claim from eligibility. */
|
|
74
|
+
eligible: boolean
|
|
75
|
+
dimensions: Record<string, ApplicabilityDimensionState>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Structured interpretation of a situation, using canonical applicability values. */
|
|
79
|
+
export type SituationApplicability = Record<string, JsonPrimitive>
|
|
80
|
+
|
|
81
|
+
/** Explicit runtime facts (command, tool call, structured intent, known API operation). */
|
|
82
|
+
export type SituationFacts = SituationApplicability
|
|
83
|
+
|
|
84
|
+
/** Environment facts observed from the runtime, when they can be determined. */
|
|
85
|
+
export interface RuntimeEnvironment {
|
|
86
|
+
platform?: string
|
|
87
|
+
shell?: string
|
|
88
|
+
runtime?: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface DiscoveryOptions {
|
|
92
|
+
depth?: DiscoveryDepth
|
|
93
|
+
maxCandidates?: number
|
|
94
|
+
/** Explicit runtime facts that override situation-prose derivation. */
|
|
95
|
+
facts?: SituationFacts
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface DiscoveryExplanation {
|
|
99
|
+
matchedTerms: string[]
|
|
100
|
+
matchedFields: DiscoveryField[]
|
|
101
|
+
/** Repository source identifier, when the repository exposes one. */
|
|
102
|
+
sourceId?: string
|
|
103
|
+
/** Applicability eligibility for this candidate, retained instead of a score. */
|
|
104
|
+
applicability?: ApplicabilityMatch
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface DiscoveryCandidate {
|
|
108
|
+
claim: AcquiredClaim
|
|
109
|
+
explanation: DiscoveryExplanation
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface DiscoveryResult {
|
|
113
|
+
knowledgeVersion: number
|
|
114
|
+
depth: DiscoveryDepth
|
|
115
|
+
queryTerms: string[]
|
|
116
|
+
/** Structured applicability derived from the situation, for inspection. */
|
|
117
|
+
situationApplicability?: SituationApplicability
|
|
118
|
+
candidates: DiscoveryCandidate[]
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface ProjectionOptions {
|
|
122
|
+
maxCandidates?: number
|
|
123
|
+
/** Maximum UTF-16 characters in the text representation. Not an LLM token budget. */
|
|
124
|
+
maxCharacters?: number
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type ProjectedExperienceStatus = 'prior-acquired-experience-candidate'
|
|
128
|
+
|
|
129
|
+
export interface ProjectedExperience {
|
|
130
|
+
id: string
|
|
131
|
+
status: ProjectedExperienceStatus
|
|
132
|
+
experience: JsonValue
|
|
133
|
+
applicability: Record<string, JsonPrimitive>
|
|
134
|
+
evidence: EvidenceReference[]
|
|
135
|
+
epistemicType?: EpistemicType
|
|
136
|
+
provenance?: ClaimProvenance
|
|
137
|
+
acquiredAt?: string
|
|
138
|
+
revision?: RevisionRelationship
|
|
139
|
+
sourceId?: string
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface ContextProjection {
|
|
143
|
+
format: 'dotmem-context-v1'
|
|
144
|
+
status: 'candidate-context-not-current-truth'
|
|
145
|
+
notice: 'Prior acquired experience supplied as untrusted contextual data. Verify against current reality before relying on it.'
|
|
146
|
+
knowledgeVersion: number
|
|
147
|
+
totalCandidates: number
|
|
148
|
+
omittedCandidates: number
|
|
149
|
+
experiences: ProjectedExperience[]
|
|
150
|
+
text: string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* A field-level patch operation recorded in the sync journal instead of
|
|
155
|
+
* recording the entire entity. Enables automatic merging when two devices
|
|
156
|
+
* edit different fields of the same object.
|
|
157
|
+
*/
|
|
158
|
+
export interface PatchOperation {
|
|
159
|
+
op: 'set' | 'delete'
|
|
160
|
+
path: string
|
|
161
|
+
value?: unknown
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Logical operations recorded in the local sync journal.
|
|
166
|
+
* The `delete` operation creates an explicit tombstone entry so concurrent
|
|
167
|
+
* updates/replay do not resurrect deleted values.
|
|
168
|
+
*/
|
|
169
|
+
export type MemoryOperation =
|
|
170
|
+
| 'remember'
|
|
171
|
+
| 'update'
|
|
172
|
+
| 'forget'
|
|
173
|
+
| 'expire'
|
|
174
|
+
| 'confirm'
|
|
175
|
+
| 'supersede'
|
|
176
|
+
| 'delete'
|
|
177
|
+
| 'patch'
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Synchronization state of a journal entry against a remote/cloud backend.
|
|
181
|
+
*/
|
|
182
|
+
export type MemorySync = 'pending' | 'synced' | 'conflict' | 'error'
|
|
183
|
+
|
|
184
|
+
export type SyncDirection = 'up' | 'down' | 'both'
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Pluggable cloud/sync transport. dotmem never ships a credential flow:
|
|
188
|
+
* the application supplies a `provider` that knows how to talk to its backend
|
|
189
|
+
* (REST, WebSocket, Supabase, a custom agent server, ...). dotmem owns the
|
|
190
|
+
* local journal, the provider only moves operations.
|
|
191
|
+
*/
|
|
192
|
+
export interface SyncProvider {
|
|
193
|
+
/** Pushes pending local operations; returns ids that were accepted */
|
|
194
|
+
push(ops: MemoryEntry[]): Promise<{ synced: string[]; conflicts?: string[]; error?: string }>
|
|
195
|
+
/** Optional pull of remote operations newer than `since` (epoch ms) */
|
|
196
|
+
pull?(since?: number): Promise<MemoryEntry[]>
|
|
197
|
+
/**
|
|
198
|
+
* Optional conflict resolution for concurrent writes on the same path.
|
|
199
|
+
* Receives the local and remote entries; return 'local', 'remote', or 'merge'.
|
|
200
|
+
* Uses HLC timestamps for causal comparison when available.
|
|
201
|
+
*/
|
|
202
|
+
resolve?(op: MemoryEntry): Promise<'local' | 'remote' | 'merge'>
|
|
203
|
+
/**
|
|
204
|
+
* Optional conflict resolver with HLC context. Called when two devices
|
|
205
|
+
* wrote concurrently to the same key/path. Implementations can use
|
|
206
|
+
* `local.hlc` and `remote.hlc` for causal determination.
|
|
207
|
+
*/
|
|
208
|
+
resolveConflict?(local: MemoryEntry, remote: MemoryEntry): Promise<'local' | 'remote' | 'merge'>
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface SyncConfig {
|
|
212
|
+
/** Sync provider implementation (application supplied) */
|
|
213
|
+
provider?: SyncProvider
|
|
214
|
+
/** Which direction to sync; 'both' is the default */
|
|
215
|
+
direction?: SyncDirection
|
|
216
|
+
/** Auto-sync on every local write? defaults to true */
|
|
217
|
+
auto?: boolean
|
|
218
|
+
/** Tenant/user/device partition for the operation journal. Contexts with
|
|
219
|
+
* different namespaces cannot read each other's operations. */
|
|
220
|
+
namespace?: string
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface SyncAck {
|
|
224
|
+
synced: string[]
|
|
225
|
+
conflicts?: string[]
|
|
226
|
+
error?: string
|
|
227
|
+
resolved?: { id: string; resolution: 'local' | 'remote' | 'merge' }[]
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export interface MemoryEntry<T = any> {
|
|
231
|
+
id: string
|
|
232
|
+
key: string
|
|
233
|
+
value: T
|
|
234
|
+
type: MemoryType
|
|
235
|
+
confidence: number
|
|
236
|
+
scope: MemoryScope
|
|
237
|
+
ttl?: number | null
|
|
238
|
+
tags: string[]
|
|
239
|
+
source?: string
|
|
240
|
+
status: MemoryStatus
|
|
241
|
+
createdAt: number
|
|
242
|
+
lastConfirmedAt: number
|
|
243
|
+
supersededId?: string | null
|
|
244
|
+
/** Monotonic per-key write counter, used for last-writer / conflict resolution */
|
|
245
|
+
version?: number
|
|
246
|
+
/** Epoch ms of the last mutation that touched this entry */
|
|
247
|
+
updatedAt?: number
|
|
248
|
+
/** Last logical operation that produced this entry */
|
|
249
|
+
operation?: MemoryOperation
|
|
250
|
+
/** Local-cloud sync state of the entry (undefined => not tracked for sync) */
|
|
251
|
+
sync?: MemorySync
|
|
252
|
+
/**
|
|
253
|
+
* Hybrid Logical Clock timestamp for causal ordering across devices.
|
|
254
|
+
* Replaces wall-clock-only ordering which is vulnerable to clock drift.
|
|
255
|
+
*/
|
|
256
|
+
hlc?: string
|
|
257
|
+
/**
|
|
258
|
+
* Field-level path for path-level journaling (e.g. "user.role").
|
|
259
|
+
* When set, the journal entry represents a patch to a sub-path
|
|
260
|
+
* rather than a full entity replacement.
|
|
261
|
+
*/
|
|
262
|
+
path?: string
|
|
263
|
+
/** Array of JSON Patch-style operations for compound path-level mutations. */
|
|
264
|
+
patches?: PatchOperation[]
|
|
265
|
+
/** ISO-8601 timestamp of when this memory was acquired. */
|
|
266
|
+
acquiredAt?: string
|
|
267
|
+
/** Epoch ms when this entry expires and should become inactive. */
|
|
268
|
+
expiresAt?: number
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface RememberOptions<T = any> {
|
|
272
|
+
id?: string
|
|
273
|
+
type?: MemoryType
|
|
274
|
+
confidence?: number
|
|
275
|
+
scope?: MemoryScope
|
|
276
|
+
ttl?: number | null
|
|
277
|
+
tags?: string | string[]
|
|
278
|
+
source?: string
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface AcquireOptions {
|
|
282
|
+
id: string
|
|
283
|
+
knowledge: JsonValue
|
|
284
|
+
applicability: Record<string, JsonPrimitive>
|
|
285
|
+
evidence: EvidenceReference[]
|
|
286
|
+
epistemicType?: EpistemicType
|
|
287
|
+
provenance?: ClaimProvenance
|
|
288
|
+
/** ISO-8601 acquisition time. Defaults to the time acquire() is called. */
|
|
289
|
+
acquiredAt?: string
|
|
290
|
+
refines?: string | string[]
|
|
291
|
+
supersedes?: string | string[]
|
|
292
|
+
retracts?: string | string[]
|
|
293
|
+
reason?: string
|
|
294
|
+
scope?: 'user' | 'project'
|
|
295
|
+
kind?: MemoryKind
|
|
296
|
+
sourceProject?: string
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export interface RecallOptions {
|
|
300
|
+
type?: MemoryType | MemoryType[]
|
|
301
|
+
tags?: string | string[]
|
|
302
|
+
minConfidence?: number
|
|
303
|
+
includeObsolete?: boolean
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export interface ContextOptions {
|
|
307
|
+
tags?: string | string[]
|
|
308
|
+
types?: MemoryType | MemoryType[]
|
|
309
|
+
minConfidence?: number
|
|
310
|
+
maxEntries?: number
|
|
311
|
+
scopes?: MemoryScope[]
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface AcquiredContextOptions {
|
|
315
|
+
acquired: Record<string, JsonPrimitive> | Record<string, JsonPrimitive>[]
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export interface ContextEntry {
|
|
319
|
+
key: string
|
|
320
|
+
value: any
|
|
321
|
+
type: MemoryType
|
|
322
|
+
confidence: number
|
|
323
|
+
scope: MemoryScope
|
|
324
|
+
tags: string[]
|
|
325
|
+
age: number
|
|
326
|
+
/** Deterministic relevance proxy (tag breadth). dotmem does not track per-entry access counts. */
|
|
327
|
+
tagBreadth: number
|
|
328
|
+
lastAccessedAt: number
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface MemoryStats {
|
|
332
|
+
total: number
|
|
333
|
+
byScope: Record<MemoryScope, number>
|
|
334
|
+
byType: Partial<Record<MemoryType, number>>
|
|
335
|
+
expired: number
|
|
336
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOTMEM POLICY AND BRAIN DECLARATIONS
|
|
3
|
+
*
|
|
4
|
+
* Policy is a separate authority domain from memory: how memory may influence
|
|
5
|
+
* behavior. The shipped declarations must mirror the runtime surface in
|
|
6
|
+
* `core/knowledge/policy.ts`, `core/knowledge/policy-store.ts`,
|
|
7
|
+
* `core/knowledge/contract.ts` and `core/knowledge/brain-memory.ts`.
|
|
8
|
+
*
|
|
9
|
+
* A governed claim never selects its own enforcement tier: effective tiers
|
|
10
|
+
* are resolved only from the policy store, and `memory.acquire` (direct and
|
|
11
|
+
* staged) evaluates the `memory.acquire` event against the payload before
|
|
12
|
+
* persistence.
|
|
13
|
+
*
|
|
14
|
+
* Adds the privileged out-of-band policy override: an authorized,
|
|
15
|
+
* explicit, auditable change of effective policy state that never mutates
|
|
16
|
+
* the base policy and is bound to the exact generation of the policy it
|
|
17
|
+
* relaxes.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export type EnforcementTier = 'context' | 'precondition' | 'hard-precondition'
|
|
21
|
+
|
|
22
|
+
export type PolicyAuthorityKind = 'HI' | 'operator'
|
|
23
|
+
|
|
24
|
+
export interface PolicyAuthority {
|
|
25
|
+
/** Who granted the policy assignment. Never a governed claim. */
|
|
26
|
+
kind: PolicyAuthorityKind
|
|
27
|
+
/** Explicit provenance of the grant. Required, never inferred. */
|
|
28
|
+
source: string
|
|
29
|
+
detail?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type ConditionKind = 'payload-language' | 'field-equals'
|
|
33
|
+
|
|
34
|
+
export interface PolicyCondition {
|
|
35
|
+
kind: ConditionKind
|
|
36
|
+
field: string
|
|
37
|
+
value: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ConditionOutcome = 'satisfied' | 'violated' | 'unresolved'
|
|
41
|
+
|
|
42
|
+
export type PolicyAction = 'allow' | 'block-and-ask' | 'block'
|
|
43
|
+
|
|
44
|
+
export interface TierEnforcement {
|
|
45
|
+
blocks: boolean
|
|
46
|
+
requiresHumanResolution: boolean
|
|
47
|
+
conversationCanOverride: boolean
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface PolicyRecord {
|
|
51
|
+
id: string
|
|
52
|
+
/** Canonical event this policy applies to, e.g. `artifact.write`. */
|
|
53
|
+
event: string
|
|
54
|
+
/** Memory claim this policy governs. The claim never selects its own tier. */
|
|
55
|
+
claimId: string
|
|
56
|
+
tier: EnforcementTier
|
|
57
|
+
field?: string
|
|
58
|
+
value?: string
|
|
59
|
+
condition?: PolicyCondition
|
|
60
|
+
authority: PolicyAuthority
|
|
61
|
+
grantedAt: string
|
|
62
|
+
reason?: string
|
|
63
|
+
/** Monotonic generation counter. Never reused. */
|
|
64
|
+
revision?: number
|
|
65
|
+
/** Canonical semantic fingerprint, system-derived and verified on load. */
|
|
66
|
+
fingerprint?: string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A valid tier an override may relax to. `context` is the floor. */
|
|
70
|
+
export type OverrideRelaxTo = EnforcementTier
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A privileged out-of-band override. Relaxes the effective tier of
|
|
74
|
+
* one target policy without mutating it, bound to the policy generation.
|
|
75
|
+
*/
|
|
76
|
+
export interface PolicyOverride {
|
|
77
|
+
id: string
|
|
78
|
+
event: string
|
|
79
|
+
/** The policy this override targets. Exactly one active slot per target. */
|
|
80
|
+
targetPolicyId: string
|
|
81
|
+
/** Target policy revision captured at grant time. */
|
|
82
|
+
targetRevision: number
|
|
83
|
+
/** Canonical semantic fingerprint of the target captured at grant time. */
|
|
84
|
+
targetFingerprint: string
|
|
85
|
+
relaxTo: OverrideRelaxTo
|
|
86
|
+
authority: PolicyAuthority
|
|
87
|
+
grantedAt: string
|
|
88
|
+
expiresAt: string
|
|
89
|
+
reason: string
|
|
90
|
+
revokedAt?: string
|
|
91
|
+
supersededBy?: string
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type PolicyOverrideState = 'ACTIVE' | 'EXPIRED' | 'STALE' | 'INERT' | 'NONE'
|
|
95
|
+
|
|
96
|
+
export type PolicyOverrideInertDetail =
|
|
97
|
+
| 'active'
|
|
98
|
+
| 'policy-missing'
|
|
99
|
+
| 'policy-changed'
|
|
100
|
+
| 'expired'
|
|
101
|
+
| 'revoked'
|
|
102
|
+
| 'superseded'
|
|
103
|
+
| 'multiple-active'
|
|
104
|
+
|
|
105
|
+
export interface ResolvedOverride {
|
|
106
|
+
override: PolicyOverride
|
|
107
|
+
state: Exclude<PolicyOverrideState, 'NONE'>
|
|
108
|
+
detail: PolicyOverrideInertDetail
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The scar: provenance of a relaxation, exposed by effective state. */
|
|
112
|
+
export interface PolicyOverrideProvenance {
|
|
113
|
+
policyOverrideId: string
|
|
114
|
+
relaxedFrom: EnforcementTier
|
|
115
|
+
by: string
|
|
116
|
+
until: string
|
|
117
|
+
reason: string
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface EffectivePolicyState {
|
|
121
|
+
policyId: string
|
|
122
|
+
event: string
|
|
123
|
+
claimId: string
|
|
124
|
+
baseTier: EnforcementTier
|
|
125
|
+
effectiveTier: EnforcementTier
|
|
126
|
+
overrideState: PolicyOverrideState
|
|
127
|
+
override?: PolicyOverride
|
|
128
|
+
provenance?: PolicyOverrideProvenance
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface PolicyOverrideGrantInput {
|
|
132
|
+
event: string
|
|
133
|
+
targetPolicyId: string
|
|
134
|
+
relaxTo: OverrideRelaxTo
|
|
135
|
+
expiresAt: string
|
|
136
|
+
reason: string
|
|
137
|
+
authority: PolicyAuthority
|
|
138
|
+
grantedAt?: string
|
|
139
|
+
id?: string
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface PolicyOverrideRevokeInput {
|
|
143
|
+
id: string
|
|
144
|
+
authority: PolicyAuthority
|
|
145
|
+
reason?: string
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface PolicyDecision {
|
|
149
|
+
policyId: string
|
|
150
|
+
claimId: string
|
|
151
|
+
event: string
|
|
152
|
+
tier: EnforcementTier
|
|
153
|
+
action: PolicyAction
|
|
154
|
+
blocks: boolean
|
|
155
|
+
requiresHumanResolution: boolean
|
|
156
|
+
conversationCanOverride: boolean
|
|
157
|
+
field?: string
|
|
158
|
+
value?: string
|
|
159
|
+
condition?: { kind: ConditionKind; field: string; value: string; outcome: ConditionOutcome; detail: string }
|
|
160
|
+
authority: PolicyAuthority
|
|
161
|
+
grantedAt: string
|
|
162
|
+
/** The governed memory claim, when present in the evaluated store. */
|
|
163
|
+
claim?: unknown
|
|
164
|
+
/** Effective-state provenance: present only under a targeting override. */
|
|
165
|
+
override?: {
|
|
166
|
+
policyOverrideId: string
|
|
167
|
+
state: Exclude<PolicyOverrideState, 'NONE'>
|
|
168
|
+
detail: PolicyOverrideInertDetail
|
|
169
|
+
relaxedFrom?: EnforcementTier
|
|
170
|
+
by?: string
|
|
171
|
+
until?: string
|
|
172
|
+
reason?: string
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface PolicyEvaluation {
|
|
177
|
+
event: string
|
|
178
|
+
decisions: PolicyDecision[]
|
|
179
|
+
blocked: boolean
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export type PolicyNamespace = 'operator' | 'security'
|
|
183
|
+
|
|
184
|
+
export interface PolicyAssignmentInput {
|
|
185
|
+
id?: string
|
|
186
|
+
event: string
|
|
187
|
+
claimId: string
|
|
188
|
+
tier: EnforcementTier
|
|
189
|
+
field?: string
|
|
190
|
+
value?: string
|
|
191
|
+
condition?: PolicyCondition
|
|
192
|
+
authority: PolicyAuthority
|
|
193
|
+
grantedAt?: string
|
|
194
|
+
reason?: string
|
|
195
|
+
/** Optimistic concurrency check, evaluated inside the lock. */
|
|
196
|
+
basedOnRevision?: number
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Privileged out-of-band override surface. */
|
|
200
|
+
export interface MemoryPolicyOverrideAPI {
|
|
201
|
+
/**
|
|
202
|
+
* Relax the effective tier of one policy. The target policy, its revision
|
|
203
|
+
* and its canonical fingerprint are derived from the store, never accepted
|
|
204
|
+
* from the payload. Exactly one active slot per target; a new grant
|
|
205
|
+
* atomically supersedes the previous one.
|
|
206
|
+
*/
|
|
207
|
+
grant(
|
|
208
|
+
input: PolicyOverrideGrantInput,
|
|
209
|
+
namespace?: PolicyNamespace,
|
|
210
|
+
basedOnRevision?: number
|
|
211
|
+
): Promise<PolicyOverride>
|
|
212
|
+
/** Remove a relaxation and restore the base policy. */
|
|
213
|
+
revoke(
|
|
214
|
+
input: PolicyOverrideRevokeInput,
|
|
215
|
+
namespace?: PolicyNamespace,
|
|
216
|
+
basedOnRevision?: number
|
|
217
|
+
): Promise<PolicyOverride>
|
|
218
|
+
/** Every override with its resolved state (ACTIVE / EXPIRED / STALE / INERT). */
|
|
219
|
+
list(namespace?: PolicyNamespace): Promise<ResolvedOverride[]>
|
|
220
|
+
/** Effective policy state with the provenance scar. */
|
|
221
|
+
effective(event?: string, namespace?: PolicyNamespace): Promise<EffectivePolicyState[]>
|
|
222
|
+
}
|
|
223
|
+
/** Durable policy audit entry: every mutation the document records. */
|
|
224
|
+
export interface PolicyAuditEntry {
|
|
225
|
+
id: string
|
|
226
|
+
action: 'assign' | 'remove' | 'clear' | 'override' | 'revoke' | 'lock-break'
|
|
227
|
+
at: string
|
|
228
|
+
authority: PolicyAuthority | { kind: 'system'; source: string }
|
|
229
|
+
target?: string
|
|
230
|
+
reason?: string
|
|
231
|
+
outcome: 'applied' | 'rejected'
|
|
232
|
+
detail?: string
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** The exported operator contract: memory is data, never authority. */
|
|
236
|
+
export interface MemoryProjectionContract {
|
|
237
|
+
authority: 'data-only'
|
|
238
|
+
trusted: false
|
|
239
|
+
instructionsAllowed: false
|
|
240
|
+
verifyCurrent: true
|
|
241
|
+
policyGoverned: true
|
|
242
|
+
chatCanLowerPolicyTier: false
|
|
243
|
+
tiers: Record<EnforcementTier, TierEnforcement>
|
|
244
|
+
overridePath: string
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Privileged policy authority surface. Ordinary acquisition cannot write policy. */
|
|
248
|
+
export interface MemoryPolicyAPI {
|
|
249
|
+
/** Privileged assignment. Requires explicit HI or operator authority. */
|
|
250
|
+
assign(input: PolicyAssignmentInput, namespace?: PolicyNamespace, basedOnRevision?: number): Promise<PolicyRecord>
|
|
251
|
+
list(): Promise<PolicyRecord[]>
|
|
252
|
+
remove(id: string, namespace?: PolicyNamespace, basedOnRevision?: number): Promise<void>
|
|
253
|
+
/**
|
|
254
|
+
* Privileged reset. Deletion is a modification: explicit authority
|
|
255
|
+
* required. Clears the active state and preserves the durable audit trail
|
|
256
|
+
* with a terminal CLEAR entry.
|
|
257
|
+
*/
|
|
258
|
+
clear(authority: PolicyAuthority): Promise<void>
|
|
259
|
+
/** Decision-time pull: only the policies applicable to the event, as effective state. */
|
|
260
|
+
evaluate(event: string, payload?: unknown): Promise<PolicyEvaluation>
|
|
261
|
+
/** Privileged out-of-band override surface. */
|
|
262
|
+
override: MemoryPolicyOverrideAPI
|
|
263
|
+
/** The durable audit trail, read-only. */
|
|
264
|
+
audit(namespace?: PolicyNamespace): Promise<PolicyAuditEntry[]>
|
|
265
|
+
/** The machine-readable operator contract. */
|
|
266
|
+
contract(): MemoryProjectionContract
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Advisory relationship index over memories (@brain.mem). Non-authoritative. */
|
|
270
|
+
export type BrainRelationshipKind =
|
|
271
|
+
| 'uses'
|
|
272
|
+
| 'related-to'
|
|
273
|
+
| 'supersedes'
|
|
274
|
+
| 'encountered-in'
|
|
275
|
+
| 'associated-with'
|
|
276
|
+
|
|
277
|
+
export interface BrainRelationship {
|
|
278
|
+
id: string
|
|
279
|
+
kind: BrainRelationshipKind
|
|
280
|
+
from: string
|
|
281
|
+
to: string
|
|
282
|
+
epistemicType?: 'observed' | 'inferred' | 'human-stated' | 'verified'
|
|
283
|
+
note?: string
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export interface MemoryBrainAPI {
|
|
287
|
+
addRelationship(kind: BrainRelationshipKind, from: string, to: string, note?: string): Promise<string>
|
|
288
|
+
getRelationships(from?: string, to?: string): Promise<BrainRelationship[]>
|
|
289
|
+
removeRelationship(id: string): Promise<void>
|
|
290
|
+
clear(): Promise<void>
|
|
291
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOTMEM PROFILE DECLARATIONS
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the source-owned built-in identity exported by `core/profile.ts`.
|
|
5
|
+
* The profile is immutable through normal runtime memory operations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface DotMemProfileDocument {
|
|
9
|
+
readonly name: string
|
|
10
|
+
readonly content: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DotMemProfile {
|
|
14
|
+
readonly format: 'dotmem.profile'
|
|
15
|
+
readonly version: 1
|
|
16
|
+
readonly id: 'joy'
|
|
17
|
+
readonly name: 'Joy'
|
|
18
|
+
readonly alternative: ['Jo']
|
|
19
|
+
readonly documents: ReadonlyArray<DotMemProfileDocument>
|
|
20
|
+
readonly type: 'ai-persona'
|
|
21
|
+
readonly role: string
|
|
22
|
+
readonly immutable: true
|
|
23
|
+
readonly description: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Embedded source-owned built-in identity profile. */
|
|
27
|
+
export declare const JO_PROFILE: Readonly<DotMemProfile>
|