@longtable/memory 0.1.9
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/README.md +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/state.d.ts +12 -0
- package/dist/state.js +145 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @longtable/memory
|
|
2
|
+
|
|
3
|
+
Memory contracts and helpers for LongTable research state.
|
|
4
|
+
|
|
5
|
+
Current responsibilities:
|
|
6
|
+
|
|
7
|
+
- explicit state storage
|
|
8
|
+
- inferred hypothesis handling
|
|
9
|
+
- open tension tracking
|
|
10
|
+
- narrative trace handling
|
|
11
|
+
- summary compaction contracts
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ArtifactRecord, DecisionRecord, InferredHypothesis, InteractionMode, MemorySummary, NarrativeTrace, ResearchState } from "./types.js";
|
|
2
|
+
export declare function createEmptyResearchState(): ResearchState;
|
|
3
|
+
export declare function addInferredHypothesis(state: ResearchState, hypothesis: InferredHypothesis): ResearchState;
|
|
4
|
+
export declare function promoteHypothesisToExplicitState(state: ResearchState, hypothesisText: string, explicitKey: string, explicitValue: unknown): ResearchState;
|
|
5
|
+
export declare function rejectInferredHypothesis(state: ResearchState, hypothesisText: string): ResearchState;
|
|
6
|
+
export declare function appendDecisionRecord(state: ResearchState, decision: DecisionRecord): ResearchState;
|
|
7
|
+
export declare function recordArtifactProvenance(state: ResearchState, artifact: ArtifactRecord): ResearchState;
|
|
8
|
+
export declare function appendNarrativeTrace(state: ResearchState, trace: NarrativeTrace): ResearchState;
|
|
9
|
+
export declare function attachStudyContract(state: ResearchState, studyContract: ResearchState["studyContract"]): ResearchState;
|
|
10
|
+
export declare function restoreWorkingState(state: ResearchState): ResearchState;
|
|
11
|
+
export declare function summarizeForCheckpoint(state: ResearchState, mode: InteractionMode): MemorySummary;
|
|
12
|
+
export declare function summarizeStateForMode(state: ResearchState, mode: InteractionMode): MemorySummary;
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
function clampConfidence(value) {
|
|
2
|
+
if (value < 0) {
|
|
3
|
+
return 0;
|
|
4
|
+
}
|
|
5
|
+
if (value > 1) {
|
|
6
|
+
return 1;
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
export function createEmptyResearchState() {
|
|
11
|
+
return {
|
|
12
|
+
explicitState: {},
|
|
13
|
+
workingState: {},
|
|
14
|
+
inferredHypotheses: [],
|
|
15
|
+
openTensions: [],
|
|
16
|
+
decisionLog: [],
|
|
17
|
+
artifactRecords: [],
|
|
18
|
+
narrativeTraces: []
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function addInferredHypothesis(state, hypothesis) {
|
|
22
|
+
return {
|
|
23
|
+
...state,
|
|
24
|
+
inferredHypotheses: [
|
|
25
|
+
...state.inferredHypotheses,
|
|
26
|
+
{
|
|
27
|
+
...hypothesis,
|
|
28
|
+
confidence: clampConfidence(hypothesis.confidence)
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function promoteHypothesisToExplicitState(state, hypothesisText, explicitKey, explicitValue) {
|
|
34
|
+
return {
|
|
35
|
+
explicitState: {
|
|
36
|
+
...state.explicitState,
|
|
37
|
+
[explicitKey]: explicitValue
|
|
38
|
+
},
|
|
39
|
+
workingState: state.workingState,
|
|
40
|
+
inferredHypotheses: state.inferredHypotheses.map((entry) => entry.hypothesis === hypothesisText ? { ...entry, status: "confirmed" } : entry),
|
|
41
|
+
openTensions: state.openTensions,
|
|
42
|
+
decisionLog: state.decisionLog,
|
|
43
|
+
artifactRecords: state.artifactRecords,
|
|
44
|
+
narrativeTraces: state.narrativeTraces,
|
|
45
|
+
studyContract: state.studyContract
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function rejectInferredHypothesis(state, hypothesisText) {
|
|
49
|
+
return {
|
|
50
|
+
...state,
|
|
51
|
+
inferredHypotheses: state.inferredHypotheses.map((entry) => entry.hypothesis === hypothesisText ? { ...entry, status: "rejected" } : entry)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function appendDecisionRecord(state, decision) {
|
|
55
|
+
return {
|
|
56
|
+
...state,
|
|
57
|
+
decisionLog: [...state.decisionLog, decision],
|
|
58
|
+
studyContract: state.studyContract
|
|
59
|
+
? {
|
|
60
|
+
...state.studyContract,
|
|
61
|
+
decisionRecordIds: [...state.studyContract.decisionRecordIds, decision.id]
|
|
62
|
+
}
|
|
63
|
+
: state.studyContract
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function recordArtifactProvenance(state, artifact) {
|
|
67
|
+
return {
|
|
68
|
+
...state,
|
|
69
|
+
artifactRecords: [...state.artifactRecords, artifact]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function appendNarrativeTrace(state, trace) {
|
|
73
|
+
return {
|
|
74
|
+
...state,
|
|
75
|
+
narrativeTraces: [...state.narrativeTraces, trace]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export function attachStudyContract(state, studyContract) {
|
|
79
|
+
return {
|
|
80
|
+
...state,
|
|
81
|
+
studyContract
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function restoreWorkingState(state) {
|
|
85
|
+
return {
|
|
86
|
+
explicitState: { ...state.explicitState },
|
|
87
|
+
workingState: { ...state.workingState },
|
|
88
|
+
inferredHypotheses: [...state.inferredHypotheses],
|
|
89
|
+
openTensions: [...state.openTensions],
|
|
90
|
+
decisionLog: [...state.decisionLog],
|
|
91
|
+
artifactRecords: [...state.artifactRecords],
|
|
92
|
+
narrativeTraces: [...state.narrativeTraces],
|
|
93
|
+
studyContract: state.studyContract
|
|
94
|
+
? {
|
|
95
|
+
...state.studyContract,
|
|
96
|
+
openTensions: [...state.studyContract.openTensions],
|
|
97
|
+
decisionRecordIds: [...state.studyContract.decisionRecordIds]
|
|
98
|
+
}
|
|
99
|
+
: undefined
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export function summarizeForCheckpoint(state, mode) {
|
|
103
|
+
const summary = summarizeStateForMode(state, mode);
|
|
104
|
+
return {
|
|
105
|
+
...summary,
|
|
106
|
+
decisionLog: mode === "commit" || mode === "submit"
|
|
107
|
+
? state.decisionLog.slice(-5)
|
|
108
|
+
: state.decisionLog.slice(-2),
|
|
109
|
+
artifactRecords: mode === "submit"
|
|
110
|
+
? state.artifactRecords.slice(-5)
|
|
111
|
+
: state.artifactRecords.slice(-2),
|
|
112
|
+
narrativeTraces: mode === "commit" || mode === "submit"
|
|
113
|
+
? state.narrativeTraces.slice(-5)
|
|
114
|
+
: state.narrativeTraces.slice(-2)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export function summarizeStateForMode(state, mode) {
|
|
118
|
+
const baseSummary = {
|
|
119
|
+
explicitState: state.explicitState,
|
|
120
|
+
workingState: state.workingState,
|
|
121
|
+
inferredHypotheses: [],
|
|
122
|
+
openTensions: [],
|
|
123
|
+
decisionLog: [],
|
|
124
|
+
artifactRecords: [],
|
|
125
|
+
narrativeTraces: []
|
|
126
|
+
};
|
|
127
|
+
if (mode === "explore" || mode === "review" || mode === "draft") {
|
|
128
|
+
return baseSummary;
|
|
129
|
+
}
|
|
130
|
+
if (mode === "critique") {
|
|
131
|
+
return {
|
|
132
|
+
...baseSummary,
|
|
133
|
+
inferredHypotheses: state.inferredHypotheses.filter((entry) => entry.status === "unconfirmed"),
|
|
134
|
+
narrativeTraces: state.narrativeTraces.filter((trace) => trace.visibility === "inferred")
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
...baseSummary,
|
|
139
|
+
inferredHypotheses: state.inferredHypotheses.filter((entry) => entry.status !== "rejected"),
|
|
140
|
+
openTensions: state.openTensions,
|
|
141
|
+
decisionLog: state.decisionLog.slice(-3),
|
|
142
|
+
artifactRecords: state.artifactRecords.slice(-3),
|
|
143
|
+
narrativeTraces: state.narrativeTraces.slice(-3)
|
|
144
|
+
};
|
|
145
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ArtifactRecord, DecisionRecord, InferredHypothesis, NarrativeTrace } from "@longtable/core";
|
|
2
|
+
export interface MemorySummary {
|
|
3
|
+
explicitState: Record<string, unknown>;
|
|
4
|
+
workingState: Record<string, unknown>;
|
|
5
|
+
inferredHypotheses: InferredHypothesis[];
|
|
6
|
+
openTensions: string[];
|
|
7
|
+
decisionLog: DecisionRecord[];
|
|
8
|
+
artifactRecords: ArtifactRecord[];
|
|
9
|
+
narrativeTraces: NarrativeTrace[];
|
|
10
|
+
}
|
|
11
|
+
export type { ArtifactRecord, DecisionRecord, InferredHypothesis, InteractionMode, NarrativeTrace, ResearchState } from "@longtable/core";
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longtable/memory",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Memory contracts for LongTable explicit state, inferred hypotheses, and open tensions",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@longtable/core": "0.1.9"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.6.0"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"longtable",
|
|
31
|
+
"research",
|
|
32
|
+
"memory",
|
|
33
|
+
"state"
|
|
34
|
+
],
|
|
35
|
+
"author": "Hosung You",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/HosungYou/LongTable.git"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/HosungYou/LongTable#readme",
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|