@aletheia-labs/dynamics 0.1.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 +176 -0
- package/README.md +169 -0
- package/dist/authority-decay.d.ts +24 -0
- package/dist/authority-decay.d.ts.map +1 -0
- package/dist/authority-decay.js +75 -0
- package/dist/authority-decay.js.map +1 -0
- package/dist/dynamics-engine.d.ts +96 -0
- package/dist/dynamics-engine.d.ts.map +1 -0
- package/dist/dynamics-engine.js +216 -0
- package/dist/dynamics-engine.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/lineage.d.ts +35 -0
- package/dist/lineage.d.ts.map +1 -0
- package/dist/lineage.js +45 -0
- package/dist/lineage.js.map +1 -0
- package/dist/policy.d.ts +35 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +31 -0
- package/dist/policy.js.map +1 -0
- package/dist/recall-evidence.d.ts +38 -0
- package/dist/recall-evidence.d.ts.map +1 -0
- package/dist/recall-evidence.js +67 -0
- package/dist/recall-evidence.js.map +1 -0
- package/dist/reconsolidation-planner.d.ts +93 -0
- package/dist/reconsolidation-planner.d.ts.map +1 -0
- package/dist/reconsolidation-planner.js +230 -0
- package/dist/reconsolidation-planner.js.map +1 -0
- package/dist/sleep-cycle.d.ts +70 -0
- package/dist/sleep-cycle.d.ts.map +1 -0
- package/dist/sleep-cycle.js +77 -0
- package/dist/sleep-cycle.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# @aletheia-labs/dynamics
|
|
2
|
+
|
|
3
|
+
Deterministic memory dynamics for Aletheia.
|
|
4
|
+
|
|
5
|
+
> **Status**: `0.1.0` public baseline. Dynamics engine, deterministic sleep-cycle reports, explicit multi-cycle runs, and human-confirmed reconsolidation apply are live.
|
|
6
|
+
|
|
7
|
+
## Quickstart
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @aletheia-labs/core @aletheia-labs/store-sqlite @aletheia-labs/dynamics
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { AgentIdSchema, IsoTimestampSchema } from '@aletheia-labs/core';
|
|
15
|
+
import { createDynamicsPolicy, DynamicsEngine, SleepCycleRunner } from '@aletheia-labs/dynamics';
|
|
16
|
+
import { openSqliteStores } from '@aletheia-labs/store-sqlite';
|
|
17
|
+
|
|
18
|
+
const stores = openSqliteStores('./aletheia.sqlite');
|
|
19
|
+
const engine = new DynamicsEngine({
|
|
20
|
+
stores,
|
|
21
|
+
policy: createDynamicsPolicy(AgentIdSchema.parse('agent-dynamics')),
|
|
22
|
+
});
|
|
23
|
+
const runner = new SleepCycleRunner(engine);
|
|
24
|
+
|
|
25
|
+
const report = await runner.run({
|
|
26
|
+
cycleId: 'sleep:demo:1',
|
|
27
|
+
now: IsoTimestampSchema.parse('2026-05-17T12:00:00Z'),
|
|
28
|
+
scope: { kind: 'project', projectId: 'demo' },
|
|
29
|
+
permittedVisibilities: [{ kind: 'private:user' }],
|
|
30
|
+
applyTransitions: false,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
console.log(report.outcome, report.plannedCount, report.appliedCount);
|
|
34
|
+
stores.close();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Use `applyTransitions: true` only when the host wants audited status transitions written through `MemoryStore.transitionStatus()`.
|
|
38
|
+
|
|
39
|
+
## What this package does
|
|
40
|
+
|
|
41
|
+
- Computes pure decayed authority scores for recall ranking without mutating memory status.
|
|
42
|
+
- Walks visible memory atoms in a caller-provided scope.
|
|
43
|
+
- Scans lifecycle candidates without `validAt` filtering so expired or corrupt validity windows can be decommissioned.
|
|
44
|
+
- Plans status transitions from explicit policy and evidence.
|
|
45
|
+
- Applies transitions only through `MemoryStore.transitionStatus`.
|
|
46
|
+
- Treats unresolved or human-required conflicts that touch an atom as authority blockers.
|
|
47
|
+
- Counts source-consistent recall evidence from an append-only `EventLedger`.
|
|
48
|
+
- Provides `SleepCycleRunner` for deterministic dry-run/apply reports over a host-provided store.
|
|
49
|
+
- Runs explicit multi-cycle sleep sequences when the host provides each cycle input; no hidden scheduler is started.
|
|
50
|
+
- Provides `ReconsolidationPlanner` for successor drafts with `supersedes` lineage and planned transitions.
|
|
51
|
+
- Provides `ReconsolidationApplier` for explicit human-confirmed successor insertion plus audited prior-atom deprecation.
|
|
52
|
+
- Provides `LineageTracer` for permission-guarded reconstruction of `supersedes` chains.
|
|
53
|
+
- Keeps `@aletheia-labs/core` SDK-free and free of background scheduling.
|
|
54
|
+
|
|
55
|
+
## Decayed Recall Ranking
|
|
56
|
+
|
|
57
|
+
Memory ages. `decayedAuthority(atom, now)` returns an effective authority score
|
|
58
|
+
for ranking atoms that have already passed core visibility, scope, status, and
|
|
59
|
+
freshness filters. It is not a permission check and it never mutates status.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { AletheiaAuthority } from '@aletheia-labs/core';
|
|
63
|
+
import { decayedAuthority } from '@aletheia-labs/dynamics';
|
|
64
|
+
|
|
65
|
+
const authority = new AletheiaAuthority({
|
|
66
|
+
eventLedger,
|
|
67
|
+
memoryStore,
|
|
68
|
+
conflictRegistry,
|
|
69
|
+
visibilityPolicy,
|
|
70
|
+
clock,
|
|
71
|
+
authorityScorer: (atom, now) => decayedAuthority(atom, now),
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Defaults decay candidates fastest, verified memories over weeks, and trusted
|
|
76
|
+
memories over months. Sealed memory does not decay; rejected, deprecated, and
|
|
77
|
+
human-required memory scores zero.
|
|
78
|
+
|
|
79
|
+
## Recall Evidence
|
|
80
|
+
|
|
81
|
+
`LedgerRecallEvidenceProvider` turns host-recorded recall events into lifecycle
|
|
82
|
+
evidence. It queries the ledger by scope and visibility before inspecting
|
|
83
|
+
payloads, then counts only events whose payload cites the target atom and all of
|
|
84
|
+
its `sourceEventIds`.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import {
|
|
88
|
+
LedgerRecallEvidenceProvider,
|
|
89
|
+
sourceConsistentRecallPayload,
|
|
90
|
+
} from '@aletheia-labs/dynamics';
|
|
91
|
+
|
|
92
|
+
await eventLedger.append({
|
|
93
|
+
eventId,
|
|
94
|
+
kind: 'decision',
|
|
95
|
+
agentId,
|
|
96
|
+
occurredAt,
|
|
97
|
+
scope: atom.scope,
|
|
98
|
+
visibility: atom.visibility,
|
|
99
|
+
payload: sourceConsistentRecallPayload(atom),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const engine = new DynamicsEngine({
|
|
103
|
+
stores,
|
|
104
|
+
policy,
|
|
105
|
+
evidenceProvider: new LedgerRecallEvidenceProvider({ eventLedger }),
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The event is evidence that a host used a memory with its original sources still
|
|
110
|
+
present. It is not permission, not semantic relevance, and not model confidence.
|
|
111
|
+
|
|
112
|
+
## Lineage
|
|
113
|
+
|
|
114
|
+
Reconsolidation never overwrites an atom. A successor carries a `supersedes`
|
|
115
|
+
link to the prior atom, and the prior atom is deprecated through audited status
|
|
116
|
+
history. `LineageTracer` reconstructs that chain only through visible atoms:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { LineageTracer } from '@aletheia-labs/dynamics';
|
|
120
|
+
|
|
121
|
+
const lineage = await new LineageTracer({ memoryStore }).traceBack({
|
|
122
|
+
memoryId: successorId,
|
|
123
|
+
permittedVisibilities,
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
If an ancestor is missing, invisible, cyclic, or too deep, the tracer returns
|
|
128
|
+
`fetch_abstain` with the partial chain instead of inventing continuity.
|
|
129
|
+
|
|
130
|
+
## What this package does NOT do
|
|
131
|
+
|
|
132
|
+
- No hidden daemon.
|
|
133
|
+
- No semantic ranking.
|
|
134
|
+
- No automatic use of `confidence` or `consensus` as authority.
|
|
135
|
+
- No automatic background mutation: hosts must explicitly call `tick({ applyTransitions: true })` or `ReconsolidationApplier.apply({ humanConfirmation })`.
|
|
136
|
+
- No reconsolidation authority upgrade: successors start as `candidate`.
|
|
137
|
+
- No silent reconsolidation partial success: if successor insertion succeeds but a prior-atom transition rejects, the applier returns `partial_applied`.
|
|
138
|
+
- No direct mutation of atom content, scores, visibility, scope, or links.
|
|
139
|
+
|
|
140
|
+
## Stability
|
|
141
|
+
|
|
142
|
+
Public surface for the initial library cycle:
|
|
143
|
+
|
|
144
|
+
- `createDynamicsPolicy`
|
|
145
|
+
- `decayedAuthority`
|
|
146
|
+
- `DEFAULT_AUTHORITY_DECAY_POLICY`
|
|
147
|
+
- `AuthorityDecayPolicy` and `AuthorityDecayPolicyOverrides`
|
|
148
|
+
- `DynamicsEngine`
|
|
149
|
+
- `SleepCycleRunner`
|
|
150
|
+
- `LedgerRecallEvidenceProvider`
|
|
151
|
+
- `sourceConsistentRecallPayload`
|
|
152
|
+
- `SOURCE_CONSISTENT_RECALL_EVENT`
|
|
153
|
+
- `ReconsolidationPlanner`
|
|
154
|
+
- `ReconsolidationApplier`
|
|
155
|
+
- `LineageTracer`
|
|
156
|
+
- policy, decision, report, and evidence-provider types
|
|
157
|
+
|
|
158
|
+
Everything else is lifecycle plumbing and may change during the `0.x` line. Dynamics can change persisted memory status, so hosts should treat policy changes as operationally significant even when TypeScript signatures stay stable.
|
|
159
|
+
|
|
160
|
+
## Development
|
|
161
|
+
|
|
162
|
+
From the repo root:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
pnpm install
|
|
166
|
+
pnpm -F @aletheia-labs/dynamics typecheck
|
|
167
|
+
pnpm -F @aletheia-labs/dynamics test
|
|
168
|
+
pnpm -F @aletheia-labs/dynamics build
|
|
169
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IsoTimestamp, MemoryAtom } from '@aletheia-labs/core';
|
|
2
|
+
export interface AuthorityDecayPolicy {
|
|
3
|
+
readonly candidateHalfLifeMs: number;
|
|
4
|
+
readonly verifiedHalfLifeMs: number;
|
|
5
|
+
readonly trustedHalfLifeMs: number;
|
|
6
|
+
}
|
|
7
|
+
export interface AuthorityDecayPolicyOverrides {
|
|
8
|
+
readonly candidateHalfLifeMs?: number;
|
|
9
|
+
readonly verifiedHalfLifeMs?: number;
|
|
10
|
+
readonly trustedHalfLifeMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const DEFAULT_AUTHORITY_DECAY_POLICY: AuthorityDecayPolicy;
|
|
13
|
+
/**
|
|
14
|
+
* Compute effective authority for an atom at a logical time.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* This is a pure ranking helper: it never mutates status and never grants
|
|
18
|
+
* permission. Hosts can inject it into `RetrievalRouter`/`AletheiaAuthority`
|
|
19
|
+
* as an `authorityScorer` after permission, scope, status, and freshness have
|
|
20
|
+
* already been filtered by core. Sealed memories keep their stored authority;
|
|
21
|
+
* deprecated, rejected, and human-required memories score zero.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decayedAuthority(atom: MemoryAtom, now: IsoTimestamp, policy?: AuthorityDecayPolicyOverrides): number;
|
|
24
|
+
//# sourceMappingURL=authority-decay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authority-decay.d.ts","sourceRoot":"","sources":["../src/authority-decay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAgB,MAAM,qBAAqB,CAAC;AAElF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAKD,eAAO,MAAM,8BAA8B,EAAE,oBAI5C,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,YAAY,EACjB,MAAM,GAAE,6BAAkC,GACzC,MAAM,CAkCR"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
2
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
3
|
+
export const DEFAULT_AUTHORITY_DECAY_POLICY = {
|
|
4
|
+
candidateHalfLifeMs: 12 * HOUR_MS,
|
|
5
|
+
verifiedHalfLifeMs: 14 * DAY_MS,
|
|
6
|
+
trustedHalfLifeMs: 90 * DAY_MS,
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Compute effective authority for an atom at a logical time.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* This is a pure ranking helper: it never mutates status and never grants
|
|
13
|
+
* permission. Hosts can inject it into `RetrievalRouter`/`AletheiaAuthority`
|
|
14
|
+
* as an `authorityScorer` after permission, scope, status, and freshness have
|
|
15
|
+
* already been filtered by core. Sealed memories keep their stored authority;
|
|
16
|
+
* deprecated, rejected, and human-required memories score zero.
|
|
17
|
+
*/
|
|
18
|
+
export function decayedAuthority(atom, now, policy = {}) {
|
|
19
|
+
const baseAuthority = clamp01(atom.scores.authority);
|
|
20
|
+
if (baseAuthority === 0)
|
|
21
|
+
return 0;
|
|
22
|
+
if (atom.status === 'deprecated' ||
|
|
23
|
+
atom.status === 'rejected' ||
|
|
24
|
+
atom.status === 'human_required') {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
const nowMs = timestampMs(now);
|
|
28
|
+
const validFromMs = timestampMs(atom.validFrom);
|
|
29
|
+
if (nowMs === null || validFromMs === null)
|
|
30
|
+
return 0;
|
|
31
|
+
if (validFromMs > nowMs)
|
|
32
|
+
return 0;
|
|
33
|
+
if (atom.validUntil !== null) {
|
|
34
|
+
const validUntilMs = timestampMs(atom.validUntil);
|
|
35
|
+
if (validUntilMs === null || validUntilMs < nowMs)
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
if (atom.status === 'sealed')
|
|
39
|
+
return baseAuthority;
|
|
40
|
+
const anchorMs = timestampMs(atom.lastConfirmedAt ?? atom.validFrom);
|
|
41
|
+
if (anchorMs === null)
|
|
42
|
+
return 0;
|
|
43
|
+
const ageMs = nowMs - anchorMs;
|
|
44
|
+
if (ageMs < 0)
|
|
45
|
+
return 0;
|
|
46
|
+
const halfLifeMs = halfLifeFor(atom.status, { ...DEFAULT_AUTHORITY_DECAY_POLICY, ...policy });
|
|
47
|
+
if (halfLifeMs === null)
|
|
48
|
+
return 0;
|
|
49
|
+
if (halfLifeMs <= 0)
|
|
50
|
+
return ageMs === 0 ? baseAuthority : 0;
|
|
51
|
+
return clamp01(baseAuthority * 2 ** (-ageMs / halfLifeMs));
|
|
52
|
+
}
|
|
53
|
+
function halfLifeFor(status, policy) {
|
|
54
|
+
if (status === 'candidate')
|
|
55
|
+
return policy.candidateHalfLifeMs;
|
|
56
|
+
if (status === 'verified')
|
|
57
|
+
return policy.verifiedHalfLifeMs;
|
|
58
|
+
if (status === 'trusted')
|
|
59
|
+
return policy.trustedHalfLifeMs;
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function timestampMs(timestamp) {
|
|
63
|
+
const parsed = Date.parse(timestamp);
|
|
64
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
65
|
+
}
|
|
66
|
+
function clamp01(value) {
|
|
67
|
+
if (!Number.isFinite(value))
|
|
68
|
+
return 0;
|
|
69
|
+
if (value <= 0)
|
|
70
|
+
return 0;
|
|
71
|
+
if (value >= 1)
|
|
72
|
+
return 1;
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=authority-decay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authority-decay.js","sourceRoot":"","sources":["../src/authority-decay.ts"],"names":[],"mappings":"AAcA,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/B,MAAM,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC;AAE5B,MAAM,CAAC,MAAM,8BAA8B,GAAyB;IAClE,mBAAmB,EAAE,EAAE,GAAG,OAAO;IACjC,kBAAkB,EAAE,EAAE,GAAG,MAAM;IAC/B,iBAAiB,EAAE,EAAE,GAAG,MAAM;CAC/B,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'@aletheia-labs/core';
|
|
2
|
+
import type { DynamicsPolicy } from './policy.js';
|
|
3
|
+
export interface DynamicsEvidence {
|
|
4
|
+
readonly sourceConsistentRecalls: number;
|
|
5
|
+
readonly lastUsedAt?: IsoTimestamp;
|
|
6
|
+
readonly sourceConsistentSince?: IsoTimestamp;
|
|
7
|
+
}
|
|
8
|
+
export interface DynamicsEvidenceContext {
|
|
9
|
+
readonly now: IsoTimestamp;
|
|
10
|
+
readonly scope: Scope;
|
|
11
|
+
readonly permittedVisibilities: readonly Visibility[];
|
|
12
|
+
}
|
|
13
|
+
export interface DynamicsEvidenceProvider {
|
|
14
|
+
/**
|
|
15
|
+
* Return explicit promotion evidence for one atom at a lifecycle instant.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Evidence is not model confidence. Implementations should derive these
|
|
19
|
+
* values from auditable host signals such as repeated source-consistent
|
|
20
|
+
* recalls or operator-confirmed evidence.
|
|
21
|
+
*/
|
|
22
|
+
evidenceFor(atom: MemoryAtom, context: DynamicsEvidenceContext): Promise<DynamicsEvidence>;
|
|
23
|
+
}
|
|
24
|
+
export interface DynamicsEngineStores {
|
|
25
|
+
readonly memoryStore: MemoryStore;
|
|
26
|
+
readonly conflictRegistry: ConflictRegistry;
|
|
27
|
+
}
|
|
28
|
+
export interface DynamicsEngineOptions {
|
|
29
|
+
readonly stores: DynamicsEngineStores;
|
|
30
|
+
readonly policy: DynamicsPolicy;
|
|
31
|
+
readonly evidenceProvider?: DynamicsEvidenceProvider;
|
|
32
|
+
}
|
|
33
|
+
export interface DynamicsTickInput {
|
|
34
|
+
readonly now: IsoTimestamp;
|
|
35
|
+
readonly scope: Scope;
|
|
36
|
+
readonly permittedVisibilities: readonly Visibility[];
|
|
37
|
+
readonly applyTransitions?: boolean;
|
|
38
|
+
readonly statuses?: readonly MemoryStatus[];
|
|
39
|
+
readonly limit?: number;
|
|
40
|
+
}
|
|
41
|
+
export type DynamicsTickOutcome = 'ok' | 'fetch_abstain';
|
|
42
|
+
export type DynamicsDecisionOutcome = 'applied' | 'planned' | 'rejected' | 'skipped';
|
|
43
|
+
export type DynamicsDecisionReason = 'expired' | 'insufficient_promotion_evidence' | 'invalid_clock' | 'not_due' | 'not_yet_valid' | 'promotion_evidence_satisfied' | 'stale_by_policy' | 'status_not_processable' | 'unresolved_conflict';
|
|
44
|
+
export interface DynamicsDecision {
|
|
45
|
+
readonly memoryId: MemoryId;
|
|
46
|
+
readonly fromStatus: MemoryStatus;
|
|
47
|
+
readonly outcome: DynamicsDecisionOutcome;
|
|
48
|
+
readonly reason: DynamicsDecisionReason;
|
|
49
|
+
readonly recommendedStatus?: MemoryStatus;
|
|
50
|
+
readonly conflicts: readonly ConflictId[];
|
|
51
|
+
readonly transition?: StatusTransitionResult;
|
|
52
|
+
}
|
|
53
|
+
export interface DynamicsTickResult {
|
|
54
|
+
readonly outcome: DynamicsTickOutcome;
|
|
55
|
+
readonly now: IsoTimestamp;
|
|
56
|
+
readonly scope: Scope;
|
|
57
|
+
readonly reasons: readonly string[];
|
|
58
|
+
readonly decisions: readonly DynamicsDecision[];
|
|
59
|
+
readonly appliedCount: number;
|
|
60
|
+
readonly plannedCount: number;
|
|
61
|
+
readonly rejectedCount: number;
|
|
62
|
+
readonly skippedCount: number;
|
|
63
|
+
}
|
|
64
|
+
export declare class DynamicsEngine {
|
|
65
|
+
private readonly memoryStore;
|
|
66
|
+
private readonly conflictRegistry;
|
|
67
|
+
private readonly policy;
|
|
68
|
+
private readonly evidenceProvider;
|
|
69
|
+
/**
|
|
70
|
+
* Create a deterministic lifecycle engine over explicit stores and policy.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* The engine owns no scheduler and starts no background work. Hosts trigger
|
|
74
|
+
* lifecycle passes by calling `tick()` or by wrapping it with `SleepCycleRunner`.
|
|
75
|
+
*/
|
|
76
|
+
constructor(options: DynamicsEngineOptions);
|
|
77
|
+
/**
|
|
78
|
+
* Plan or apply one lifecycle pass over visible atoms in a scope.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* The implementation first validates the logical clock and permitted
|
|
82
|
+
* visibilities. It then queries by permission/scope/status but intentionally
|
|
83
|
+
* does not pass `validAt`, because expired or malformed validity windows must
|
|
84
|
+
* remain visible to the lifecycle pass so they can be deprecated. Mutations
|
|
85
|
+
* happen only when `applyTransitions` is true, and only via
|
|
86
|
+
* `MemoryStore.transitionStatus()`.
|
|
87
|
+
*/
|
|
88
|
+
tick(input: DynamicsTickInput): Promise<DynamicsTickResult>;
|
|
89
|
+
private emptyResult;
|
|
90
|
+
private evaluateAtom;
|
|
91
|
+
private unresolvedConflicts;
|
|
92
|
+
private staleDecision;
|
|
93
|
+
private canPromoteCandidate;
|
|
94
|
+
private transition;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=dynamics-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamics-engine.d.ts","sourceRoot":"","sources":["../src/dynamics-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,KAAK,EACL,sBAAsB,EACtB,UAAU,EACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;IACzC,QAAQ,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC;IACnC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,YAAY,CAAC;CAC/C;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,qBAAqB,EAAE,SAAS,UAAU,EAAE,CAAC;CACvD;AAED,MAA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