@kumbatio/energy-system 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 +21 -0
- package/README.md +247 -0
- package/dist/compat.d.ts +49 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +109 -0
- package/dist/compat.js.map +1 -0
- package/dist/dom.d.ts +19 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +72 -0
- package/dist/dom.js.map +1 -0
- package/dist/engine.d.ts +26 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +218 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/levels.d.ts +16 -0
- package/dist/levels.d.ts.map +1 -0
- package/dist/levels.js +114 -0
- package/dist/levels.js.map +1 -0
- package/dist/metrics.d.ts +6 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +47 -0
- package/dist/metrics.js.map +1 -0
- package/dist/persistence.d.ts +12 -0
- package/dist/persistence.d.ts.map +1 -0
- package/dist/persistence.js +93 -0
- package/dist/persistence.js.map +1 -0
- package/dist/react.d.ts +45 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +130 -0
- package/dist/react.js.map +1 -0
- package/dist/strategies.d.ts +36 -0
- package/dist/strategies.d.ts.map +1 -0
- package/dist/strategies.js +175 -0
- package/dist/strategies.js.map +1 -0
- package/dist/types.d.ts +88 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +73 -0
- package/src/energy.css +134 -0
package/dist/react.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useSyncExternalStore, } from 'react';
|
|
2
|
+
import { applyEnergyLevel } from './dom.js';
|
|
3
|
+
import { createEnergyEngine } from './engine.js';
|
|
4
|
+
import { getEnergyLevel, getEnergyLevels } from './levels.js';
|
|
5
|
+
// ── Context ──
|
|
6
|
+
const EnergyEngineContext = createContext(null);
|
|
7
|
+
function useEngine() {
|
|
8
|
+
const engine = useContext(EnergyEngineContext);
|
|
9
|
+
if (!engine)
|
|
10
|
+
throw new Error('Energy hooks must be used within an EnergyProvider');
|
|
11
|
+
return engine;
|
|
12
|
+
}
|
|
13
|
+
export function EnergyProvider({ engine: externalEngine, defaultLevel = 100, persistence, onLevelChange, applyToDOM = true, children, }) {
|
|
14
|
+
const internalEngineRef = useRef(null);
|
|
15
|
+
const [, refreshEngine] = useReducer((version) => version + 1, 0);
|
|
16
|
+
// `defaultLevel` and `persistence` are initial-only by contract: they
|
|
17
|
+
// configure the engine the provider creates, they do not reconfigure it.
|
|
18
|
+
const createInternalEngine = () => createEnergyEngine({
|
|
19
|
+
initialLevel: defaultLevel,
|
|
20
|
+
...(persistence ? { persistence } : {}),
|
|
21
|
+
});
|
|
22
|
+
if (!externalEngine && !internalEngineRef.current) {
|
|
23
|
+
internalEngineRef.current = createInternalEngine();
|
|
24
|
+
}
|
|
25
|
+
const engine = externalEngine ?? internalEngineRef.current;
|
|
26
|
+
if (!engine) {
|
|
27
|
+
throw new Error('EnergyProvider could not initialize an engine instance');
|
|
28
|
+
}
|
|
29
|
+
// Own the internal engine's lifecycle. The cleanup disposes it; the setup
|
|
30
|
+
// recreates it when the previous one was disposed (StrictMode re-runs
|
|
31
|
+
// effects without re-rendering, so render-time lazy init cannot recover).
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (externalEngine) {
|
|
34
|
+
// An external engine took over; release the provider-owned engine.
|
|
35
|
+
internalEngineRef.current?.dispose();
|
|
36
|
+
internalEngineRef.current = null;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!internalEngineRef.current) {
|
|
40
|
+
internalEngineRef.current = createInternalEngine();
|
|
41
|
+
refreshEngine();
|
|
42
|
+
}
|
|
43
|
+
return () => {
|
|
44
|
+
internalEngineRef.current?.dispose();
|
|
45
|
+
internalEngineRef.current = null;
|
|
46
|
+
};
|
|
47
|
+
}, [externalEngine]);
|
|
48
|
+
// Sync to DOM when state changes
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!applyToDOM || typeof document === 'undefined')
|
|
51
|
+
return;
|
|
52
|
+
// Apply initial
|
|
53
|
+
applyEnergyLevel(engine.getState().level);
|
|
54
|
+
// Subscribe to changes
|
|
55
|
+
return engine.subscribe((state) => {
|
|
56
|
+
applyEnergyLevel(state.level);
|
|
57
|
+
});
|
|
58
|
+
}, [engine, applyToDOM]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!onLevelChange)
|
|
61
|
+
return;
|
|
62
|
+
return engine.subscribe(onLevelChange);
|
|
63
|
+
}, [engine, onLevelChange]);
|
|
64
|
+
return createElement(EnergyEngineContext.Provider, { value: engine }, children);
|
|
65
|
+
}
|
|
66
|
+
// ── Hooks ──
|
|
67
|
+
function useEnergyStoreState() {
|
|
68
|
+
const engine = useEngine();
|
|
69
|
+
// Stable subscribe identity so useSyncExternalStore doesn't unsubscribe +
|
|
70
|
+
// resubscribe on every render. `engine.getState` is closure-backed (doesn't
|
|
71
|
+
// use `this`), so it's safe to pass unbound as the snapshot getter.
|
|
72
|
+
const subscribe = useCallback((onStoreChange) => engine.subscribe(() => {
|
|
73
|
+
onStoreChange();
|
|
74
|
+
}), [engine]);
|
|
75
|
+
return useSyncExternalStore(subscribe, engine.getState, engine.getState);
|
|
76
|
+
}
|
|
77
|
+
/** Get the full energy state (level + timestamp + source) */
|
|
78
|
+
export function useEnergyState() {
|
|
79
|
+
return useEnergyStoreState();
|
|
80
|
+
}
|
|
81
|
+
/** Read the current energy level and setter */
|
|
82
|
+
export function useEnergyLevel() {
|
|
83
|
+
const engine = useEngine();
|
|
84
|
+
const state = useEnergyStoreState();
|
|
85
|
+
const setLevel = useCallback((level) => {
|
|
86
|
+
engine.setLevel(level);
|
|
87
|
+
}, [engine]);
|
|
88
|
+
return [state.level, setLevel];
|
|
89
|
+
}
|
|
90
|
+
/** @deprecated Use useEnergyState instead. */
|
|
91
|
+
export function useFullEnergyState() {
|
|
92
|
+
return useEnergyStoreState();
|
|
93
|
+
}
|
|
94
|
+
/** Returns a function that cycles to the next energy level */
|
|
95
|
+
export function useEnergyLevelCycler() {
|
|
96
|
+
const engine = useEngine();
|
|
97
|
+
return useCallback(() => {
|
|
98
|
+
engine.cycleLevel();
|
|
99
|
+
}, [engine]);
|
|
100
|
+
}
|
|
101
|
+
/** Resolve a strategy against current energy level */
|
|
102
|
+
export function useStrategy(strategy) {
|
|
103
|
+
const state = useEnergyStoreState();
|
|
104
|
+
return useMemo(() => strategy.resolve(state.level), [strategy, state.level]);
|
|
105
|
+
}
|
|
106
|
+
/** Returns true if current energy level meets or exceeds the given minimum */
|
|
107
|
+
export function useEnergyGate(minLevel) {
|
|
108
|
+
const state = useEnergyStoreState();
|
|
109
|
+
return state.level >= minLevel;
|
|
110
|
+
}
|
|
111
|
+
/** Headless energy indicator - bring your own UI */
|
|
112
|
+
export function EnergyIndicator({ children }) {
|
|
113
|
+
const [level, setLevel] = useEnergyLevel();
|
|
114
|
+
const state = useEnergyStoreState();
|
|
115
|
+
const cycle = useEnergyLevelCycler();
|
|
116
|
+
const definition = useMemo(() => getEnergyLevel(level), [level]);
|
|
117
|
+
const levels = useMemo(() => getEnergyLevels(), []);
|
|
118
|
+
return children({
|
|
119
|
+
level,
|
|
120
|
+
label: definition.label,
|
|
121
|
+
description: definition.description,
|
|
122
|
+
cognitiveProfile: definition.cognitiveProfile,
|
|
123
|
+
state,
|
|
124
|
+
definition,
|
|
125
|
+
levels,
|
|
126
|
+
cycle,
|
|
127
|
+
setLevel,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.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CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AdaptationStrategy, TaskComplexity } from './types.js';
|
|
2
|
+
export interface UIVisibilityConfig {
|
|
3
|
+
readonly sidebar: boolean;
|
|
4
|
+
readonly tabBar: boolean;
|
|
5
|
+
readonly statusBar: boolean;
|
|
6
|
+
readonly toolbar: boolean;
|
|
7
|
+
readonly chromeOpacity: number;
|
|
8
|
+
readonly chromeOpacityHover: number;
|
|
9
|
+
readonly contentMaxWidth: string;
|
|
10
|
+
readonly contentFontScale: number;
|
|
11
|
+
readonly readOnlyCursor: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const uiVisibilityStrategy: AdaptationStrategy<UIVisibilityConfig>;
|
|
14
|
+
export interface NotificationConfig {
|
|
15
|
+
/** Allow visual notifications (badges, toasts) */
|
|
16
|
+
readonly allowVisual: boolean;
|
|
17
|
+
/** Allow audio notifications */
|
|
18
|
+
readonly allowSound: boolean;
|
|
19
|
+
/** Allow haptic feedback */
|
|
20
|
+
readonly allowVibration: boolean;
|
|
21
|
+
/** Minimum ms between batched notifications (0 = immediate) */
|
|
22
|
+
readonly batchInterval: number;
|
|
23
|
+
/** Minimum priority to show */
|
|
24
|
+
readonly priorityThreshold: 'all' | 'high' | 'critical' | 'none';
|
|
25
|
+
}
|
|
26
|
+
export declare const notificationStrategy: AdaptationStrategy<NotificationConfig>;
|
|
27
|
+
export interface TaskComplexityConfig {
|
|
28
|
+
/** Maximum task complexity to surface */
|
|
29
|
+
readonly maxComplexity: TaskComplexity;
|
|
30
|
+
/** Whether to proactively suggest breaks */
|
|
31
|
+
readonly suggestBreaks: boolean;
|
|
32
|
+
/** Minutes between break suggestions (when enabled) */
|
|
33
|
+
readonly breakIntervalMinutes: number;
|
|
34
|
+
}
|
|
35
|
+
export declare const taskComplexityStrategy: AdaptationStrategy<TaskComplexityConfig>;
|
|
36
|
+
//# sourceMappingURL=strategies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAA;CACtC;AA8BD,eAAO,MAAM,sBAAsB,EAAE,kBAAkB,CAAC,oBAAoB,CAY3E,CAAA"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { getEnergyLevel } from './levels.js';
|
|
2
|
+
function freezeObject(value) {
|
|
3
|
+
return Object.freeze(value);
|
|
4
|
+
}
|
|
5
|
+
const UI_CONFIGS = freezeObject({
|
|
6
|
+
100: freezeObject({
|
|
7
|
+
sidebar: true,
|
|
8
|
+
tabBar: true,
|
|
9
|
+
statusBar: true,
|
|
10
|
+
toolbar: true,
|
|
11
|
+
chromeOpacity: 1,
|
|
12
|
+
chromeOpacityHover: 1,
|
|
13
|
+
contentMaxWidth: 'none',
|
|
14
|
+
contentFontScale: 1,
|
|
15
|
+
readOnlyCursor: false,
|
|
16
|
+
}),
|
|
17
|
+
75: freezeObject({
|
|
18
|
+
sidebar: true,
|
|
19
|
+
tabBar: true,
|
|
20
|
+
statusBar: true,
|
|
21
|
+
toolbar: true,
|
|
22
|
+
chromeOpacity: 0.7,
|
|
23
|
+
chromeOpacityHover: 1,
|
|
24
|
+
contentMaxWidth: 'none',
|
|
25
|
+
contentFontScale: 1,
|
|
26
|
+
readOnlyCursor: false,
|
|
27
|
+
}),
|
|
28
|
+
50: freezeObject({
|
|
29
|
+
sidebar: true,
|
|
30
|
+
tabBar: true,
|
|
31
|
+
statusBar: true,
|
|
32
|
+
toolbar: true,
|
|
33
|
+
chromeOpacity: 0.4,
|
|
34
|
+
chromeOpacityHover: 1,
|
|
35
|
+
contentMaxWidth: '90ch',
|
|
36
|
+
contentFontScale: 1,
|
|
37
|
+
readOnlyCursor: false,
|
|
38
|
+
}),
|
|
39
|
+
25: freezeObject({
|
|
40
|
+
sidebar: false,
|
|
41
|
+
tabBar: false,
|
|
42
|
+
statusBar: false,
|
|
43
|
+
toolbar: true,
|
|
44
|
+
chromeOpacity: 0.1,
|
|
45
|
+
chromeOpacityHover: 1,
|
|
46
|
+
contentMaxWidth: '80ch',
|
|
47
|
+
contentFontScale: 1.05,
|
|
48
|
+
readOnlyCursor: false,
|
|
49
|
+
}),
|
|
50
|
+
0: freezeObject({
|
|
51
|
+
sidebar: false,
|
|
52
|
+
tabBar: false,
|
|
53
|
+
statusBar: false,
|
|
54
|
+
toolbar: false,
|
|
55
|
+
chromeOpacity: 0.05,
|
|
56
|
+
chromeOpacityHover: 0.8,
|
|
57
|
+
contentMaxWidth: '75ch',
|
|
58
|
+
contentFontScale: 1.1,
|
|
59
|
+
readOnlyCursor: true,
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
export const uiVisibilityStrategy = {
|
|
63
|
+
name: 'ui-visibility',
|
|
64
|
+
describe(level) {
|
|
65
|
+
const def = getEnergyLevel(level);
|
|
66
|
+
const config = UI_CONFIGS[def.value];
|
|
67
|
+
const hidden = [
|
|
68
|
+
!config.sidebar && 'sidebar',
|
|
69
|
+
!config.tabBar && 'tabs',
|
|
70
|
+
!config.statusBar && 'status bar',
|
|
71
|
+
!config.toolbar && 'toolbar',
|
|
72
|
+
].filter(Boolean);
|
|
73
|
+
if (hidden.length === 0) {
|
|
74
|
+
return `${def.label}: All UI elements visible${config.chromeOpacity < 1 ? `, chrome at ${Math.round(config.chromeOpacity * 100)}% opacity` : ''}`;
|
|
75
|
+
}
|
|
76
|
+
return `${def.label}: ${hidden.join(', ')} hidden, chrome at ${Math.round(config.chromeOpacity * 100)}% opacity`;
|
|
77
|
+
},
|
|
78
|
+
resolve(level) {
|
|
79
|
+
return UI_CONFIGS[getEnergyLevel(level).value];
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
const NOTIFICATION_CONFIGS = freezeObject({
|
|
83
|
+
100: freezeObject({
|
|
84
|
+
allowVisual: true,
|
|
85
|
+
allowSound: true,
|
|
86
|
+
allowVibration: true,
|
|
87
|
+
batchInterval: 0,
|
|
88
|
+
priorityThreshold: 'all',
|
|
89
|
+
}),
|
|
90
|
+
75: freezeObject({
|
|
91
|
+
allowVisual: true,
|
|
92
|
+
allowSound: true,
|
|
93
|
+
allowVibration: false,
|
|
94
|
+
batchInterval: 0,
|
|
95
|
+
priorityThreshold: 'all',
|
|
96
|
+
}),
|
|
97
|
+
50: freezeObject({
|
|
98
|
+
allowVisual: true,
|
|
99
|
+
allowSound: false,
|
|
100
|
+
allowVibration: false,
|
|
101
|
+
batchInterval: 5 * 60 * 1000, // 5 minutes
|
|
102
|
+
priorityThreshold: 'high',
|
|
103
|
+
}),
|
|
104
|
+
25: freezeObject({
|
|
105
|
+
allowVisual: true,
|
|
106
|
+
allowSound: false,
|
|
107
|
+
allowVibration: false,
|
|
108
|
+
batchInterval: 15 * 60 * 1000, // 15 minutes
|
|
109
|
+
priorityThreshold: 'critical',
|
|
110
|
+
}),
|
|
111
|
+
0: freezeObject({
|
|
112
|
+
allowVisual: false,
|
|
113
|
+
allowSound: false,
|
|
114
|
+
allowVibration: false,
|
|
115
|
+
batchInterval: 0,
|
|
116
|
+
priorityThreshold: 'none',
|
|
117
|
+
}),
|
|
118
|
+
});
|
|
119
|
+
export const notificationStrategy = {
|
|
120
|
+
name: 'notifications',
|
|
121
|
+
describe(level) {
|
|
122
|
+
const def = getEnergyLevel(level);
|
|
123
|
+
const config = NOTIFICATION_CONFIGS[def.value];
|
|
124
|
+
if (config.priorityThreshold === 'none')
|
|
125
|
+
return 'Rest: All notifications silenced';
|
|
126
|
+
if (config.priorityThreshold === 'all')
|
|
127
|
+
return `${def.label}: All notifications enabled`;
|
|
128
|
+
return `${def.label}: Only ${config.priorityThreshold} priority, batched every ${config.batchInterval / 60_000}min`;
|
|
129
|
+
},
|
|
130
|
+
resolve(level) {
|
|
131
|
+
return NOTIFICATION_CONFIGS[getEnergyLevel(level).value];
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
const TASK_CONFIGS = freezeObject({
|
|
135
|
+
100: freezeObject({
|
|
136
|
+
maxComplexity: 'complex',
|
|
137
|
+
suggestBreaks: false,
|
|
138
|
+
breakIntervalMinutes: 0,
|
|
139
|
+
}),
|
|
140
|
+
75: freezeObject({
|
|
141
|
+
maxComplexity: 'moderate',
|
|
142
|
+
suggestBreaks: false,
|
|
143
|
+
breakIntervalMinutes: 0,
|
|
144
|
+
}),
|
|
145
|
+
50: freezeObject({
|
|
146
|
+
maxComplexity: 'routine',
|
|
147
|
+
suggestBreaks: true,
|
|
148
|
+
breakIntervalMinutes: 45,
|
|
149
|
+
}),
|
|
150
|
+
25: freezeObject({
|
|
151
|
+
maxComplexity: 'simple',
|
|
152
|
+
suggestBreaks: true,
|
|
153
|
+
breakIntervalMinutes: 25,
|
|
154
|
+
}),
|
|
155
|
+
0: freezeObject({
|
|
156
|
+
maxComplexity: 'consumption',
|
|
157
|
+
suggestBreaks: true,
|
|
158
|
+
breakIntervalMinutes: 15,
|
|
159
|
+
}),
|
|
160
|
+
});
|
|
161
|
+
export const taskComplexityStrategy = {
|
|
162
|
+
name: 'task-complexity',
|
|
163
|
+
describe(level) {
|
|
164
|
+
const def = getEnergyLevel(level);
|
|
165
|
+
const config = TASK_CONFIGS[def.value];
|
|
166
|
+
const parts = [`${def.label}: Max complexity: ${config.maxComplexity}`];
|
|
167
|
+
if (config.suggestBreaks)
|
|
168
|
+
parts.push(`breaks every ${config.breakIntervalMinutes}min`);
|
|
169
|
+
return parts.join(', ');
|
|
170
|
+
},
|
|
171
|
+
resolve(level) {
|
|
172
|
+
return TASK_CONFIGS[getEnergyLevel(level).value];
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=strategies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategies.js","sourceRoot":"","sources":["../src/strategies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAG5C,SAAS,YAAY,CAAmB,KAAQ;IAC9C,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC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,gBAAgB,MAAM,CAAC,oBAAoB,KAAK,CAAC,CAAA;QACtF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IACD,OAAO,CAAC,KAAK;QACX,OAAO,YAAY,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;CACF,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Discrete cognitive capacity values */
|
|
2
|
+
export type EnergyLevel = 0 | 25 | 50 | 75 | 100;
|
|
3
|
+
/** How the energy level was set */
|
|
4
|
+
export type EnergySource = 'manual' | 'scheduled' | 'inferred';
|
|
5
|
+
/** Valid energy level values for runtime validation */
|
|
6
|
+
export declare const ENERGY_LEVEL_VALUES: ReadonlySet<number>;
|
|
7
|
+
/** Valid energy source values for runtime validation */
|
|
8
|
+
export declare const ENERGY_SOURCE_VALUES: ReadonlySet<EnergySource>;
|
|
9
|
+
/** A point-in-time snapshot of cognitive capacity */
|
|
10
|
+
export interface EnergyState {
|
|
11
|
+
/** Current cognitive capacity */
|
|
12
|
+
readonly level: EnergyLevel;
|
|
13
|
+
/** When this state was set (epoch ms) */
|
|
14
|
+
readonly timestamp: number;
|
|
15
|
+
/** How this state was determined */
|
|
16
|
+
readonly source: EnergySource;
|
|
17
|
+
}
|
|
18
|
+
/** Time source contract for deterministic environments (tests, simulations) */
|
|
19
|
+
export interface EnergyClock {
|
|
20
|
+
now(): number;
|
|
21
|
+
}
|
|
22
|
+
export type DecisionCapacity = 'high' | 'moderate' | 'low' | 'minimal' | 'none';
|
|
23
|
+
export type FocusDuration = 'extended' | 'moderate' | 'short' | 'minimal' | 'none';
|
|
24
|
+
export type TaskComplexity = 'complex' | 'moderate' | 'routine' | 'simple' | 'consumption';
|
|
25
|
+
export type InterruptionTolerance = 'high' | 'moderate' | 'low' | 'minimal' | 'none';
|
|
26
|
+
/** What the brain can handle at a given energy level */
|
|
27
|
+
export interface CognitiveProfile {
|
|
28
|
+
readonly decisionCapacity: DecisionCapacity;
|
|
29
|
+
readonly focusDuration: FocusDuration;
|
|
30
|
+
readonly taskComplexity: TaskComplexity;
|
|
31
|
+
readonly interruptionTolerance: InterruptionTolerance;
|
|
32
|
+
}
|
|
33
|
+
/** Complete metadata for a single energy level */
|
|
34
|
+
export interface EnergyLevelDefinition {
|
|
35
|
+
readonly value: EnergyLevel;
|
|
36
|
+
readonly key: string;
|
|
37
|
+
readonly label: string;
|
|
38
|
+
readonly description: string;
|
|
39
|
+
readonly cognitiveProfile: CognitiveProfile;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Maps energy levels to application behavior.
|
|
43
|
+
* Pure function - given a level, produce a configuration.
|
|
44
|
+
*/
|
|
45
|
+
export interface AdaptationStrategy<TConfig> {
|
|
46
|
+
/** Unique name for this strategy */
|
|
47
|
+
name: string;
|
|
48
|
+
/** Human-readable description of what this strategy does at a given level */
|
|
49
|
+
describe(level: EnergyLevel): string;
|
|
50
|
+
/** Compute the configuration for a given energy level */
|
|
51
|
+
resolve(level: EnergyLevel): TConfig;
|
|
52
|
+
}
|
|
53
|
+
/** Storage contract - implement per platform */
|
|
54
|
+
export interface EnergyPersistence {
|
|
55
|
+
load(): Promise<EnergyState | null>;
|
|
56
|
+
save(state: EnergyState): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Optional observer for externally persisted state updates (cross-tab, worker, etc.)
|
|
59
|
+
*/
|
|
60
|
+
observe?(onState: (state: EnergyState) => void): () => void;
|
|
61
|
+
}
|
|
62
|
+
/** Callback for energy state changes */
|
|
63
|
+
export type EnergyChangeListener = (state: EnergyState, prev: EnergyState) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Computed, app-agnostic metrics from an energy state snapshot.
|
|
66
|
+
*/
|
|
67
|
+
export interface EnergyMetrics {
|
|
68
|
+
/** Milliseconds since this state was set */
|
|
69
|
+
readonly stateAgeMs: number;
|
|
70
|
+
/** Rounded minutes since this state was set */
|
|
71
|
+
readonly stateAgeMinutes: number;
|
|
72
|
+
/** Suggested focused-work window length */
|
|
73
|
+
readonly expectedProductivityWindowMinutes: number;
|
|
74
|
+
/** Suggested break cadence for the current level */
|
|
75
|
+
readonly suggestedBreakIntervalMinutes: number;
|
|
76
|
+
/** Recommended task complexity based on cognitive profile */
|
|
77
|
+
readonly recommendedTaskComplexity: TaskComplexity;
|
|
78
|
+
/**
|
|
79
|
+
* Heuristic signal for maintainability of this state.
|
|
80
|
+
* True only for mid-range levels (25/50/75): peak (100) is a burst state
|
|
81
|
+
* that depletes rather than holds, and rest (0) is recovery, not a working
|
|
82
|
+
* state to maintain. Both extremes report false.
|
|
83
|
+
*/
|
|
84
|
+
readonly sustainable: boolean;
|
|
85
|
+
/** Optional guidance for recovery horizon */
|
|
86
|
+
readonly recoveryHintMinutes?: number;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,yCAAyC;AACzC,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;AAEhD,mCAAmC;AACnC,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAA;AAE9D,uDAAuD;AACvD,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAAiC,CAAA;AACrF,wDAAwD;AACxD,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,YAAY,CAIzD,CAAA;AAIF,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,iCAAiC;IACjC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;IAC3B,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,Y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AAW,iBAAiB;IAChC,IAAI,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACnC,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACvC;;OAEG;IACH,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,MAAM,IAAI,CAAA;CAC5D;AAID,wCAAwC;AACxC,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,KAAK,IAAI,CAAA;AAIlF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,iCAAiC,EAAE,MAAM,CAAA;IAClD,oDAAoD;IACpD,QAAQ,CAAC,6BAA6B,EAAE,MAAM,CAAA;IAC9C,6DAA6D;IAC7D,QAAQ,CAAC,yBAAyB,EAAE,cAAc,CAAA;IAClD;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;IAC7B,6CAA6C;IAC7C,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAA;CACtC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// ── Energy Levels ──
|
|
2
|
+
/** Valid energy level values for runtime validation */
|
|
3
|
+
export const ENERGY_LEVEL_VALUES = new Set([0, 25, 50, 75, 100]);
|
|
4
|
+
/** Valid energy source values for runtime validation */
|
|
5
|
+
export const ENERGY_SOURCE_VALUES = new Set([
|
|
6
|
+
'manual',
|
|
7
|
+
'scheduled',
|
|
8
|
+
'inferred',
|
|
9
|
+
]);
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAQtB,uDAAuD;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;AACrF,wDAAwD;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAA8B,IAAI,GAAG,CAAC;IACrE,QAAQ;IACR,WAAW;IACX,UAAU;CACX,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kumbatio/energy-system",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Framework-agnostic TypeScript library for energy-aware application behavior.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"src/energy.css",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": [
|
|
14
|
+
"./src/energy.css"
|
|
15
|
+
],
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./dom": {
|
|
24
|
+
"types": "./dist/dom.d.ts",
|
|
25
|
+
"import": "./dist/dom.js"
|
|
26
|
+
},
|
|
27
|
+
"./react": {
|
|
28
|
+
"types": "./dist/react.d.ts",
|
|
29
|
+
"import": "./dist/react.js"
|
|
30
|
+
},
|
|
31
|
+
"./persistence": {
|
|
32
|
+
"types": "./dist/persistence.d.ts",
|
|
33
|
+
"import": "./dist/persistence.js"
|
|
34
|
+
},
|
|
35
|
+
"./css": "./src/energy.css",
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@happy-dom/global-registrator": "^20.10.2",
|
|
43
|
+
"@types/react": "^19.2.17",
|
|
44
|
+
"@types/react-dom": "^19.2.3",
|
|
45
|
+
"react": "^19.2.7",
|
|
46
|
+
"react-dom": "^19.2.7",
|
|
47
|
+
"tsx": "^4.22.4",
|
|
48
|
+
"typescript": "^6.0.3"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": ">=19"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"react": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=24"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsc -p tsconfig.build.json",
|
|
63
|
+
"check-types": "tsc --noEmit -p tsconfig.json",
|
|
64
|
+
"test": "pnpm run build && node --test --import tsx",
|
|
65
|
+
"pack:dry-run": "npm pack --dry-run",
|
|
66
|
+
"format": "oxfmt --write .",
|
|
67
|
+
"format:check": "oxfmt --check .",
|
|
68
|
+
"lint": "oxlint .",
|
|
69
|
+
"lint:fix": "oxlint --fix .",
|
|
70
|
+
"lint:fix-unsafe": "oxlint --import-plugin --type-aware --type-check --vitest-plugin --fix --fix-suggestions --fix-dangerously src/",
|
|
71
|
+
"check:fix-suggestions": "oxlint --import-plugin --type-aware --type-check --vitest-plugin --fix --fix-suggestions . && oxfmt --write ."
|
|
72
|
+
}
|
|
73
|
+
}
|