@adam0white/human-framework 2.11.0 → 2.12.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/dist/cognition/cognition.js +8 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/migrate.js +6 -1
- package/dist/person.d.ts +6 -0
- package/dist/person.js +14 -2
- package/dist/prospection/prospection.d.ts +17 -1
- package/dist/prospection/prospection.js +118 -35
- package/dist/restore.js +4 -2
- package/dist/types.d.ts +18 -3
- package/dist/types.js +1 -1
- package/package.json +1 -1
|
@@ -248,6 +248,12 @@ function materialValue(p, material, scarcity) {
|
|
|
248
248
|
const sat = Math.sign(material) * (1 - dexp(-Math.abs(material) / scale));
|
|
249
249
|
return K.materialWeight * sat * 2 * weight * (1 + K.scarcityMaterialGain * scarcity);
|
|
250
250
|
}
|
|
251
|
+
/** Shared whole-route valuation for scoring and the read-only plan readout. @internal */
|
|
252
|
+
export function prospectiveRoute(p, aff, ctx) {
|
|
253
|
+
const scarcity = clamp01(Number.isFinite(ctx.scarcity) ? ctx.scarcity : 0);
|
|
254
|
+
return receivedGoalRoute(p, aff, ctx.now, 0.5 + 0.5 * clamp01(ctx.mods.maturity), (successor) => effortValue(p, successor, ctx) +
|
|
255
|
+
(successor.material ? materialValue(p, successor.material, scarcity) : 0));
|
|
256
|
+
}
|
|
251
257
|
/** Needs whose consumption can overfill (2.8.0 fullness): what `body.consume` feeds. */
|
|
252
258
|
const FULL_NEEDS = ['food', 'water', 'relief'];
|
|
253
259
|
/** Score one option. Pure apart from reads; terms are rounded for stable snapshots. */
|
|
@@ -328,12 +334,11 @@ export function consider(p, aff, ctx) {
|
|
|
328
334
|
}
|
|
329
335
|
const maturity = clamp01(ctx.mods.maturity);
|
|
330
336
|
const maturityScale = 0.5 + 0.5 * maturity;
|
|
331
|
-
const received =
|
|
332
|
-
(successor.material ? materialValue(p, successor.material, scarcity) : 0));
|
|
337
|
+
const received = prospectiveRoute(p, aff, ctx);
|
|
333
338
|
for (const t of agendaTermsWithGoalEstimates(p, aff, ctx.now, received?.goals))
|
|
334
339
|
push(t.source, t.value * maturityScale);
|
|
335
340
|
if (received)
|
|
336
|
-
push(received.cost.source, received.cost.value);
|
|
341
|
+
push(received.cost.source, received.cost.value, received.cost.ref);
|
|
337
342
|
// Habit: cue-matched automaticity (cued by the option's own place), stronger before planning matures.
|
|
338
343
|
const habit = p.habits.length === 0
|
|
339
344
|
? 0
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Human Framework public surface. */
|
|
2
|
-
export declare const FRAMEWORK_VERSION = "2.
|
|
2
|
+
export declare const FRAMEWORK_VERSION = "2.12.0";
|
|
3
3
|
export type { CrisisEvent, PracticeKind } from './affect/index.ts';
|
|
4
4
|
export { AFFECT_DEFAULTS, actionTendencies, advanceAffect, appraise, breakAllows, breakBehaviour, breakHazard, CRISIS_DEFAULTS, checkCrisis, createAffect, easeBreak, emotionLevel, enableBreaks, feel, inBreak, readAffect, regulate, release as releaseEmotion, skipCrisis, strain, tendencyEmotions, } from './affect/index.ts';
|
|
5
5
|
export type { GoalTemplate, PrayerCalendar, PrayerSchedule, PrayerTimes, Retimer, } from './agenda/index.ts';
|
|
@@ -30,8 +30,8 @@ export * from './needs/index.ts';
|
|
|
30
30
|
export * from './partnering/index.ts';
|
|
31
31
|
export * from './person.ts';
|
|
32
32
|
export * from './promptings/index.ts';
|
|
33
|
-
export type { ConsequenceEvidence } from './prospection/index.ts';
|
|
34
|
-
export { bodyForecastFor, bodyForecastTerm, consequenceEvidence, FORECAST_DEFAULTS, forecastLine, forecastThresholds, PROSPECTION_DEFAULTS, } from './prospection/index.ts';
|
|
33
|
+
export type { ConsequenceEvidence, PlanRoute, PlanStep } from './prospection/index.ts';
|
|
34
|
+
export { bodyForecastFor, bodyForecastTerm, consequenceEvidence, enablePlanning, FORECAST_DEFAULTS, forecastLine, forecastThresholds, PROSPECTION_DEFAULTS, seedConsequences, } from './prospection/index.ts';
|
|
35
35
|
export { fingerprint, restore, snapshot } from './restore.ts';
|
|
36
36
|
export * from './review/index.ts';
|
|
37
37
|
export * from './scenarios/index.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Human Framework public surface. */
|
|
2
|
-
export const FRAMEWORK_VERSION = '2.
|
|
2
|
+
export const FRAMEWORK_VERSION = '2.12.0';
|
|
3
3
|
export { AFFECT_DEFAULTS, actionTendencies, advanceAffect, appraise, breakAllows, breakBehaviour, breakHazard, CRISIS_DEFAULTS, checkCrisis, createAffect, easeBreak, emotionLevel, enableBreaks, feel, inBreak, readAffect, regulate, release as releaseEmotion, skipCrisis, strain, tendencyEmotions, } from './affect/index.js';
|
|
4
4
|
// `agenda.release` collides with `affect.release`; the agenda one is re-exported under a clearer name.
|
|
5
5
|
export { AGENDA_DEFAULTS, abandonGoal, adoptGoal, advanceAgenda, agendaTerms, applyExemptions, CARE_DEFAULTS, calendarRetimer, careDuty, commitmentPressure, createAgenda, DEFAULT_PRAYER_TIMES, EID_PRAYER_IMPORTANCE, EXEMPTION_DEFAULTS, eidPrayer, eidWindow, fastWindow, iftarWindow, inMakruhTime, isUnderWay, MAKRUH_DEFAULTS, makruhWindows, missedExcuse, onFinished, owedMakeUps, PRAYER_IMPORTANCE, PURPOSE_DEFAULTS, prayerWindows, pressureReachedAt, promise, proposeGoals, RAMADAN_DEFAULTS, ramadanFast, ramadanMeals, release as releaseCommitment, retimeCommitments, revisePurposes, scheduleMakeUp, spanMeetsWindow, suhoorWindow, timesFor, violatesAbstention, } from './agenda/index.js';
|
|
@@ -27,7 +27,7 @@ export * from './needs/index.js';
|
|
|
27
27
|
export * from './partnering/index.js';
|
|
28
28
|
export * from './person.js';
|
|
29
29
|
export * from './promptings/index.js';
|
|
30
|
-
export { bodyForecastFor, bodyForecastTerm, consequenceEvidence, FORECAST_DEFAULTS, forecastLine, forecastThresholds, PROSPECTION_DEFAULTS, } from './prospection/index.js';
|
|
30
|
+
export { bodyForecastFor, bodyForecastTerm, consequenceEvidence, enablePlanning, FORECAST_DEFAULTS, forecastLine, forecastThresholds, PROSPECTION_DEFAULTS, seedConsequences, } from './prospection/index.js';
|
|
31
31
|
export { fingerprint, restore, snapshot } from './restore.js';
|
|
32
32
|
export * from './review/index.js';
|
|
33
33
|
export * from './scenarios/index.js';
|
package/dist/migrate.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* version; fullness stays absent unless enabled, and alongside partners and reconsideration are opt-in.
|
|
19
19
|
* 2.8.0 to 2.9.0 stamps the version; prompting cues and practice half-lives stay absent unless supplied,
|
|
20
20
|
* review terms may carry refs, and an outcome naming several commitments now keeps each rather than only
|
|
21
|
-
* the earliest-ending one. 2.10.0 to 2.11.0 stamps the version (curiosity starts absent). 2.9.0 to 2.10.0 stamps the version; belief provenance, noted contradictions and
|
|
21
|
+
* the earliest-ending one. 2.11.0 to 2.12.0 stamps the version (planning starts absent). 2.10.0 to 2.11.0 stamps the version (curiosity starts absent). 2.9.0 to 2.10.0 stamps the version; belief provenance, noted contradictions and
|
|
22
22
|
* believed regard stay absent unless a host supplies them;
|
|
23
23
|
* `regard` becomes a reserved impression cue key. A migrated save continues under the current engine's rules: it restores and runs,
|
|
24
24
|
* but it does not reproduce what the old engine would have done next where the rules changed (1.4.0 to 1.5.0
|
|
@@ -70,6 +70,11 @@ export const MIGRATIONS = {
|
|
|
70
70
|
note: 'the surroundings field `ambient.now` is renamed `ambient.percept`; per-person retention is optional and starts absent; behaviour unchanged',
|
|
71
71
|
apply: renameAmbient,
|
|
72
72
|
},
|
|
73
|
+
'2.11.0': {
|
|
74
|
+
to: '2.12.0',
|
|
75
|
+
note: 'the planning slice (Person.planning) is optional and starts absent; retained consequences may carry channel known only when seeded; existing hosts retain exact behavior',
|
|
76
|
+
apply: stamp,
|
|
77
|
+
},
|
|
73
78
|
'2.10.0': {
|
|
74
79
|
to: '2.11.0',
|
|
75
80
|
note: 'the curiosity slice (Person.curiosity) is optional and starts absent; existing hosts retain exact behavior',
|
package/dist/person.d.ts
CHANGED
|
@@ -136,6 +136,12 @@ export declare function answerNow(p: Person, affordances: readonly Affordance[],
|
|
|
136
136
|
resolution: SuggestionResolution;
|
|
137
137
|
booked: boolean;
|
|
138
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* Read the best retained-claim route using ordinary scoring costs (scarcity absent).
|
|
141
|
+
* Does not mutate, advance time or consume RNG. `now` values timing against the held state.
|
|
142
|
+
* Returns undefined when no route improves on direct goal value.
|
|
143
|
+
*/
|
|
144
|
+
export declare function planRoute(p: Person, aff: Affordance, now?: Minute): import("./index.ts").PlanRoute | undefined;
|
|
139
145
|
/** Every resolution of a decision record (all voices), oldest API first. */
|
|
140
146
|
export declare const resolutionsOf: (r: {
|
|
141
147
|
suggestion?: SuggestionResolution;
|
package/dist/person.js
CHANGED
|
@@ -25,7 +25,7 @@ import { advanceBeliefs, applyContradiction, attend, believe, confirm, credence,
|
|
|
25
25
|
import { advanceBody, BODY_DEFAULTS, checkDowned, clearDowned, consume, createBody, downedAllows, enableFatigueStore, enableFullness, expose, injure, nextBodyThreshold, readBody, setDowned, sicken, skipBody, } from './body/index.js';
|
|
26
26
|
import { ageCharacter, enableCharacterChange, noteCharacterDay, noteCharacterSocial, } from './character/index.js';
|
|
27
27
|
import { closeDay, enableYearbook, endDay, noteAnswer, noteCommitments, noteDecision, noteMood, noteOutcome, trimChronicle, } from './chronicle/index.js';
|
|
28
|
-
import { decide as cognitionDecide, desperationOf, scoreAll } from './cognition/index.js';
|
|
28
|
+
import { decide as cognitionDecide, desperationOf, prospectiveRoute, scoreAll } from './cognition/index.js';
|
|
29
29
|
import { createConscience, guiltLoad, heldNorms, normVeto, recordDeed, recordRepair, repent, } from './conscience/index.js';
|
|
30
30
|
import { clamp01, clampSigned, createRng, dayOf, isObj, minuteOfDay } from './core/index.js';
|
|
31
31
|
import { enableCuriosity, noteCuriosity } from './curiosity/index.js';
|
|
@@ -38,7 +38,7 @@ import { intentionFor, narrateDecision, voiceLine } from './narrate/index.js';
|
|
|
38
38
|
import { advanceNeeds, createNeeds, levelOf, meanSatisfaction, readNeeds, satisfy, urgencyOf, } from './needs/index.js';
|
|
39
39
|
import { widow } from './partnering/index.js';
|
|
40
40
|
import { enablePromptings, nafsPatterns, notePromptings } from './promptings/index.js';
|
|
41
|
-
import { bodyForecastFor, consumeConsequences, forecastLine, forecastThresholds, pruneConsequences, receiveConsequences, } from './prospection/index.js';
|
|
41
|
+
import { bodyForecastFor, consumeConsequences, enablePlanning, forecastLine, forecastThresholds, pruneConsequences, receiveConsequences, } from './prospection/index.js';
|
|
42
42
|
import { enableReview, reviewIfDue } from './review/index.js';
|
|
43
43
|
import { enableSkillRetention, learnByWatching, practise, seedSkills, } from './skills/index.js';
|
|
44
44
|
import { advanceSocial, applyReputationBelief, careFor, closeness, judge, markDeceased, noteKnownBy, relationshipWith, seedRelationships, socialEvent, threatAppraisal, } from './social/index.js';
|
|
@@ -162,6 +162,8 @@ export function createPerson(spec) {
|
|
|
162
162
|
enableFullness(p);
|
|
163
163
|
if (on?.curiosity)
|
|
164
164
|
enableCuriosity(p, on.curiosity === true ? {} : on.curiosity);
|
|
165
|
+
if (on?.planning)
|
|
166
|
+
enablePlanning(p, on.planning);
|
|
165
167
|
if (on?.promptings)
|
|
166
168
|
enablePromptings(p, on.promptings);
|
|
167
169
|
if (on?.review)
|
|
@@ -852,6 +854,16 @@ export function answerNow(p, affordances, suggestion, opts = {}) {
|
|
|
852
854
|
}
|
|
853
855
|
return out;
|
|
854
856
|
}
|
|
857
|
+
/**
|
|
858
|
+
* Read the best retained-claim route using ordinary scoring costs (scarcity absent).
|
|
859
|
+
* Does not mutate, advance time or consume RNG. `now` values timing against the held state.
|
|
860
|
+
* Returns undefined when no route improves on direct goal value.
|
|
861
|
+
*/
|
|
862
|
+
export function planRoute(p, aff, now = p.now) {
|
|
863
|
+
const held = now === p.now ? p : { ...p, now };
|
|
864
|
+
const { ctx } = decisionInputs(held, [aff], 'plan-readout', {});
|
|
865
|
+
return prospectiveRoute(held, aff, ctx)?.route;
|
|
866
|
+
}
|
|
855
867
|
/** Every resolution of a decision record (all voices), oldest API first. */
|
|
856
868
|
export const resolutionsOf = (r) => r.suggestions ?? (r.suggestion ? [r.suggestion] : []);
|
|
857
869
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Affordance, ConsequenceRevision, Minute, Person, RetainedConsequence } from '../types.ts';
|
|
1
|
+
import type { Affordance, ConsequenceRevision, Minute, Person, PlanningSpec, ReceivedConsequence, RetainedConsequence } from '../types.ts';
|
|
2
2
|
export declare const PROSPECTION_DEFAULTS: {
|
|
3
3
|
maxEntries: number;
|
|
4
4
|
maxRevisions: number;
|
|
@@ -7,6 +7,10 @@ export declare const PROSPECTION_DEFAULTS: {
|
|
|
7
7
|
horizon: number;
|
|
8
8
|
maxMaterialCost: number;
|
|
9
9
|
};
|
|
10
|
+
/** Enable bounded planning. Invalid configuration throws without changing the person. */
|
|
11
|
+
export declare function enablePlanning(p: Person, spec?: PlanningSpec): void;
|
|
12
|
+
/** Seed what the person already knows. Uses claim confidence/chance, without source trust or attention. */
|
|
13
|
+
export declare function seedConsequences(p: Person, sourceId: string, claims: readonly ReceivedConsequence[]): boolean;
|
|
10
14
|
export interface ConsequenceEvidence {
|
|
11
15
|
entry: RetainedConsequence;
|
|
12
16
|
matches: boolean;
|
|
@@ -21,3 +25,15 @@ export declare function consequenceEvidence(p: Person, aff: Affordance, now?: Mi
|
|
|
21
25
|
entries: ConsequenceEvidence[];
|
|
22
26
|
revisions: ConsequenceRevision[];
|
|
23
27
|
};
|
|
28
|
+
/** One successor in a selected route. Times and access are unrounded estimates. */
|
|
29
|
+
export interface PlanStep {
|
|
30
|
+
successor: ReceivedConsequence['successor'];
|
|
31
|
+
start: Minute;
|
|
32
|
+
end: Minute;
|
|
33
|
+
access: number;
|
|
34
|
+
}
|
|
35
|
+
/** Plain JSON readout of the best whole route; goals are unscaled per-goal values. */
|
|
36
|
+
export interface PlanRoute {
|
|
37
|
+
steps: PlanStep[];
|
|
38
|
+
goals: Record<string, number>;
|
|
39
|
+
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SCOPE:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* bounds, not fitted psychological estimates.
|
|
2
|
+
* SCOPE: retained current-action → successor claims, acquired through attended external
|
|
3
|
+
* testimony or host-seeded prior knowledge. Knowledge is person-owned, source-labelled,
|
|
4
|
+
* bounded and saved. Opt-in planning searches chains of retained claims, depth first in
|
|
5
|
+
* stable source/id order, with total depth 2..5 and 64 feasible node expansions.
|
|
6
|
+
* Shapes: depth limits and pruning (Huys et al. 2012; Keramati et al. 2016), resource-rational
|
|
7
|
+
* planning (Callaway et al. 2022), quasi-hyperbolic present bias (Laibson 1997;
|
|
8
|
+
* O'Donoghue and Rabin 1999); see research/curiosity-and-play.md §Planning.
|
|
9
|
+
* Parameters are engineering bounds, not fitted psychological estimates.
|
|
10
|
+
* Without planning, only one successor is considered. One coherent route contributes;
|
|
11
|
+
* it never executes actions, grants consent or advances goals. Actual completed triggers
|
|
12
|
+
* consume opportunities. This is not a general planner: it does not search the host's
|
|
13
|
+
* world, infer procedures, execute plans or model another person's agency, future bodies
|
|
14
|
+
* or waiting opportunity cost. Revision memory is bounded, not an audit.
|
|
10
15
|
*/
|
|
11
16
|
import { temporalGoalValue } from '../agenda/agenda.js';
|
|
12
17
|
import { trustOf } from '../beliefs/index.js';
|
|
@@ -21,6 +26,32 @@ export const PROSPECTION_DEFAULTS = {
|
|
|
21
26
|
horizon: 7 * MINUTES_PER_DAY,
|
|
22
27
|
maxMaterialCost: 1_000_000,
|
|
23
28
|
};
|
|
29
|
+
/** Validate the optional planning configuration. Malformed saved state is dropped. @internal */
|
|
30
|
+
export function sanitizePlanning(input) {
|
|
31
|
+
if (!isObj(input) ||
|
|
32
|
+
!Number.isInteger(input.depth) ||
|
|
33
|
+
!isNum(input.depth) ||
|
|
34
|
+
input.depth < 2 ||
|
|
35
|
+
input.depth > 5)
|
|
36
|
+
return undefined;
|
|
37
|
+
if (input.presentBias !== undefined &&
|
|
38
|
+
(!isNum(input.presentBias) || input.presentBias <= 0 || input.presentBias > 1))
|
|
39
|
+
return undefined;
|
|
40
|
+
return {
|
|
41
|
+
depth: input.depth,
|
|
42
|
+
...(input.presentBias !== undefined ? { presentBias: input.presentBias } : {}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Enable bounded planning. Invalid configuration throws without changing the person. */
|
|
46
|
+
export function enablePlanning(p, spec = {}) {
|
|
47
|
+
const state = sanitizePlanning({ ...spec, depth: spec.depth ?? 4 });
|
|
48
|
+
if (!state)
|
|
49
|
+
throw new RangeError('Planning requires depth 2..5 and presentBias in (0, 1]');
|
|
50
|
+
p.planning = state;
|
|
51
|
+
}
|
|
52
|
+
const maxEntries = (planning) => (planning ? 64 : PROSPECTION_DEFAULTS.maxEntries);
|
|
53
|
+
const maxBatch = (p) => (p.planning ? 16 : PROSPECTION_DEFAULTS.maxBatch);
|
|
54
|
+
const reliability = (p, e) => e.channel === 'known' ? 1 : trustOf(p, e.sourceId);
|
|
24
55
|
const id = (x) => typeof x === 'string' &&
|
|
25
56
|
x.length > 0 &&
|
|
26
57
|
x.length <= PROSPECTION_DEFAULTS.maxIdentifierLength &&
|
|
@@ -90,7 +121,11 @@ function consequence(x, receivedAt) {
|
|
|
90
121
|
};
|
|
91
122
|
}
|
|
92
123
|
function retained(x, now) {
|
|
93
|
-
if (!isObj(x) ||
|
|
124
|
+
if (!isObj(x) ||
|
|
125
|
+
!id(x.sourceId) ||
|
|
126
|
+
(x.channel !== 'told' && x.channel !== 'known') ||
|
|
127
|
+
!minute(x.receivedAt) ||
|
|
128
|
+
x.receivedAt > now)
|
|
94
129
|
return undefined;
|
|
95
130
|
const c = consequence(x, x.receivedAt);
|
|
96
131
|
if (!c ||
|
|
@@ -100,7 +135,7 @@ function retained(x, now) {
|
|
|
100
135
|
return {
|
|
101
136
|
...c,
|
|
102
137
|
sourceId: x.sourceId,
|
|
103
|
-
channel:
|
|
138
|
+
channel: x.channel,
|
|
104
139
|
receivedAt: x.receivedAt,
|
|
105
140
|
...(x.triggeredAt !== undefined ? { triggeredAt: x.triggeredAt } : {}),
|
|
106
141
|
};
|
|
@@ -132,11 +167,18 @@ export function receiveConsequences(p, pc) {
|
|
|
132
167
|
pc.actorId === p.id ||
|
|
133
168
|
(pc.targetId !== undefined && pc.targetId !== p.id))
|
|
134
169
|
return false;
|
|
135
|
-
|
|
136
|
-
|
|
170
|
+
return acceptConsequences(p, pc.actorId, pc.consequences ?? [], pc.withdrawConsequences ?? [], 'told');
|
|
171
|
+
}
|
|
172
|
+
/** Seed what the person already knows. Uses claim confidence/chance, without source trust or attention. */
|
|
173
|
+
export function seedConsequences(p, sourceId, claims) {
|
|
174
|
+
if (!id(sourceId) || sourceId === p.id)
|
|
175
|
+
return false;
|
|
176
|
+
return acceptConsequences(p, sourceId, claims, [], 'known');
|
|
177
|
+
}
|
|
178
|
+
function acceptConsequences(p, sourceId, adds, removes, channel) {
|
|
137
179
|
if (!Array.isArray(adds) ||
|
|
138
180
|
!Array.isArray(removes) ||
|
|
139
|
-
adds.length + removes.length >
|
|
181
|
+
adds.length + removes.length > maxBatch(p) ||
|
|
140
182
|
adds.length + removes.length === 0)
|
|
141
183
|
return false;
|
|
142
184
|
const additions = adds.map((x) => consequence(x, p.now));
|
|
@@ -148,7 +190,6 @@ export function receiveConsequences(p, pc) {
|
|
|
148
190
|
if (new Set(batch.map((x) => x.id)).size !== batch.length)
|
|
149
191
|
return false;
|
|
150
192
|
const state = cleaned(structuredClone(p.prospection ?? { entries: [], revisions: [] }), p.now);
|
|
151
|
-
const sourceId = pc.actorId;
|
|
152
193
|
const updates = batch.filter((b) => !state.revisions.some((r) => r.sourceId === sourceId && r.id === b.id && r.revision >= (b.revision ?? 0)));
|
|
153
194
|
const newIds = updates.filter((b) => !state.revisions.some((r) => r.sourceId === sourceId && r.id === b.id));
|
|
154
195
|
// Never evict a still-valid tombstone to admit a batch; dedup holds within the stated horizon.
|
|
@@ -159,13 +200,13 @@ export function receiveConsequences(p, pc) {
|
|
|
159
200
|
state.revisions = state.revisions.filter((r) => !(r.sourceId === sourceId && r.id === b.id));
|
|
160
201
|
const addition = additions.find((a) => a?.id === b.id);
|
|
161
202
|
if (addition)
|
|
162
|
-
state.entries.push({ ...addition, sourceId, channel
|
|
203
|
+
state.entries.push({ ...addition, sourceId, channel, receivedAt: p.now });
|
|
163
204
|
state.revisions.push({ sourceId, id: b.id, revision: b.revision, receivedAt: p.now });
|
|
164
205
|
}
|
|
165
|
-
if (state.entries.length >
|
|
206
|
+
if (state.entries.length > maxEntries(p.planning !== undefined)) {
|
|
166
207
|
const oldest = [...state.entries]
|
|
167
208
|
.sort((a, b) => Number(b.triggeredAt !== undefined) - Number(a.triggeredAt !== undefined) || order(a, b))
|
|
168
|
-
.slice(0, state.entries.length -
|
|
209
|
+
.slice(0, state.entries.length - maxEntries(p.planning !== undefined));
|
|
169
210
|
state.entries = state.entries.filter((e) => !oldest.includes(e));
|
|
170
211
|
}
|
|
171
212
|
store(p, state);
|
|
@@ -190,7 +231,7 @@ export function consequenceEvidence(p, aff, now = p.now) {
|
|
|
190
231
|
now <= entry.expiresAt &&
|
|
191
232
|
end <= entry.availableUntil &&
|
|
192
233
|
Number.isFinite(end);
|
|
193
|
-
const accessProbability = expectedEffect(p, aff).successRate * entry.chance * entry.confidence *
|
|
234
|
+
const accessProbability = expectedEffect(p, aff).successRate * entry.chance * entry.confidence * reliability(p, entry);
|
|
194
235
|
return {
|
|
195
236
|
entry: structuredClone(entry),
|
|
196
237
|
matches: match,
|
|
@@ -223,30 +264,72 @@ export function receivedGoalRoute(p, aff, now, maturityScale, costs) {
|
|
|
223
264
|
const baseline = direct.reduce((sum, value) => sum + round(value * maturityScale), 0);
|
|
224
265
|
let bestScore = baseline;
|
|
225
266
|
let best;
|
|
226
|
-
const entries =
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
267
|
+
const entries = [...p.prospection.entries].sort((a, b) => cmpStr(a.sourceId, b.sourceId) || cmpStr(a.id, b.id));
|
|
268
|
+
const beta = p.planning?.presentBias ?? 1;
|
|
269
|
+
let remaining = p.planning ? 64 : Infinity;
|
|
270
|
+
function visit(previous, previousEnd, access, path, steps, values, accumulatedCost, done) {
|
|
271
|
+
if (path.length >= (p.planning?.depth ?? 2) - 1 || remaining <= 0)
|
|
272
|
+
return;
|
|
273
|
+
for (const entry of entries) {
|
|
274
|
+
if (remaining <= 0)
|
|
275
|
+
return;
|
|
276
|
+
// Completing an action consumes every open opportunity it triggers, so a
|
|
277
|
+
// link whose trigger an earlier simulated step already performed is gone.
|
|
278
|
+
if (path.includes(entry) ||
|
|
279
|
+
!matches(entry.trigger, previous) ||
|
|
280
|
+
done.some((a) => matches(entry.trigger, a)) ||
|
|
281
|
+
entry.triggeredAt !== undefined ||
|
|
282
|
+
now > entry.expiresAt)
|
|
283
|
+
continue;
|
|
284
|
+
const start = Math.max(previousEnd, entry.availableFrom);
|
|
285
|
+
const end = start + entry.successor.duration;
|
|
286
|
+
if (!Number.isFinite(end) || end > entry.availableUntil)
|
|
287
|
+
continue;
|
|
288
|
+
remaining -= 1;
|
|
289
|
+
const nextAccess = access *
|
|
290
|
+
expectedEffect(p, previous).successRate *
|
|
291
|
+
entry.chance *
|
|
292
|
+
entry.confidence *
|
|
293
|
+
reliability(p, entry);
|
|
294
|
+
const successor = successorOffer(entry);
|
|
295
|
+
const nextValues = goals.map((g, i) => Math.max(values[i] ?? 0, nextAccess * beta * temporalGoalValue(p, g, successor, now, end)));
|
|
296
|
+
const nextCost = accumulatedCost + beta * nextAccess * Math.min(0, costs(successor));
|
|
297
|
+
const cost = round(nextCost);
|
|
298
|
+
const total = nextValues.reduce((sum, value) => sum + round(value * maturityScale), 0) + cost;
|
|
299
|
+
const nextPath = [...path, entry];
|
|
300
|
+
const nextSteps = [
|
|
301
|
+
...steps,
|
|
302
|
+
{ successor: structuredClone(entry.successor), start, end, access: nextAccess },
|
|
303
|
+
];
|
|
304
|
+
if (round(total - bestScore) > 0) {
|
|
305
|
+
bestScore = total;
|
|
306
|
+
// Keep the original root's source string; the ref explains longer routes.
|
|
307
|
+
const root = nextPath[0];
|
|
308
|
+
best = {
|
|
309
|
+
goals: new Map(goals.map((g, i) => [g.id, nextValues[i] ?? 0])),
|
|
310
|
+
cost: {
|
|
311
|
+
source: `prospection:cost:${root.sourceId}:${root.id}`,
|
|
312
|
+
value: cost,
|
|
313
|
+
...(nextPath.length > 1 ? { ref: nextPath.map((e) => e.id).join('>') } : {}),
|
|
314
|
+
},
|
|
315
|
+
route: {
|
|
316
|
+
steps: nextSteps,
|
|
317
|
+
goals: Object.fromEntries(goals.map((g, i) => [g.id, nextValues[i] ?? 0])),
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
visit(successor, end, nextAccess, nextPath, nextSteps, nextValues, nextCost, [...done, previous]);
|
|
322
|
+
}
|
|
241
323
|
}
|
|
324
|
+
visit(aff, now + Math.max(0, aff.duration), 1, [], [], direct, 0, []);
|
|
242
325
|
return best;
|
|
243
326
|
}
|
|
244
327
|
/** Conservative optional-slice restore; ambiguous identities drop the slice. @internal */
|
|
245
|
-
export function sanitizeProspection(input, now, personId) {
|
|
328
|
+
export function sanitizeProspection(input, now, personId, planning = false) {
|
|
246
329
|
if (!isObj(input) ||
|
|
247
330
|
!Array.isArray(input.entries) ||
|
|
248
331
|
!Array.isArray(input.revisions) ||
|
|
249
|
-
input.entries.length >
|
|
332
|
+
input.entries.length > maxEntries(planning) ||
|
|
250
333
|
input.revisions.length > PROSPECTION_DEFAULTS.maxRevisions)
|
|
251
334
|
return undefined;
|
|
252
335
|
const entries = input.entries.map((x) => retained(x, now)).filter((e) => e?.sourceId !== personId);
|
package/dist/restore.js
CHANGED
|
@@ -23,7 +23,7 @@ import { migrate } from './migrate.js';
|
|
|
23
23
|
import { sanitizeBonds } from './partnering/index.js';
|
|
24
24
|
import { cleanRetention, createPerson, traceLimit } from './person.js';
|
|
25
25
|
import { sanitizePromptings } from './promptings/index.js';
|
|
26
|
-
import { sanitizeProspection } from './prospection/index.js';
|
|
26
|
+
import { sanitizePlanning, sanitizeProspection } from './prospection/index.js';
|
|
27
27
|
import { sanitizeReview } from './review/index.js';
|
|
28
28
|
import { sanitizeSkillRetention } from './skills/index.js';
|
|
29
29
|
import { sanitizeGroups, sanitizeImpressions } from './social/index.js';
|
|
@@ -85,6 +85,7 @@ const OPTIONAL_KEYS = new Set([
|
|
|
85
85
|
'retention',
|
|
86
86
|
'methods',
|
|
87
87
|
'prospection',
|
|
88
|
+
'planning',
|
|
88
89
|
'promptings',
|
|
89
90
|
'curiosity',
|
|
90
91
|
'review',
|
|
@@ -201,7 +202,8 @@ export function restore(input) {
|
|
|
201
202
|
keepValid(out, 'ambient', sanitizeAmbient);
|
|
202
203
|
keepValid(out, 'retention', cleanRetention);
|
|
203
204
|
keepValid(out, 'methods', sanitizeMethods);
|
|
204
|
-
keepValid(out, '
|
|
205
|
+
keepValid(out, 'planning', sanitizePlanning);
|
|
206
|
+
keepValid(out, 'prospection', (x) => sanitizeProspection(x, out.now, out.id, out.planning !== undefined));
|
|
205
207
|
keepValid(out, 'curiosity', (x) => sanitizeCuriosity(x, out.now));
|
|
206
208
|
keepValid(out, 'promptings', (x) => sanitizePromptings(x, out.now));
|
|
207
209
|
keepValid(out, 'review', (x) => sanitizeReview(x, out.now));
|
package/dist/types.d.ts
CHANGED
|
@@ -885,7 +885,7 @@ export declare const PERSON_SCHEMA = "human/person@1";
|
|
|
885
885
|
* and an activity that would cover a closing stretch is reviewed when the stretch begins (`isUnderWay`,
|
|
886
886
|
* `dutyReviewAt`). Person shape unchanged.
|
|
887
887
|
*/
|
|
888
|
-
export declare const ENGINE_VERSION = "2.
|
|
888
|
+
export declare const ENGINE_VERSION = "2.12.0";
|
|
889
889
|
/** A pregnancy carried by this person (host-driven; see `family/`). */
|
|
890
890
|
export interface Pregnancy {
|
|
891
891
|
fatherId: PersonId;
|
|
@@ -1019,7 +1019,7 @@ export interface ConsequenceRevision {
|
|
|
1019
1019
|
}
|
|
1020
1020
|
export interface RetainedConsequence extends ReceivedConsequence {
|
|
1021
1021
|
sourceId: EntityId;
|
|
1022
|
-
channel: 'told';
|
|
1022
|
+
channel: 'told' | 'known';
|
|
1023
1023
|
receivedAt: Minute;
|
|
1024
1024
|
/** Own completed trigger; does not establish access or goal progress. */
|
|
1025
1025
|
triggeredAt?: Minute;
|
|
@@ -1029,6 +1029,17 @@ export interface ProspectionState {
|
|
|
1029
1029
|
entries: RetainedConsequence[];
|
|
1030
1030
|
revisions: ConsequenceRevision[];
|
|
1031
1031
|
}
|
|
1032
|
+
/** Bounded retained-claim search, owned by `prospection/`. */
|
|
1033
|
+
export interface PlanningSpec {
|
|
1034
|
+
/** Total steps including the current offer: integer 2..5, default 4. */
|
|
1035
|
+
depth?: number;
|
|
1036
|
+
/** Quasi-hyperbolic beta in (0, 1]; absent means no present bias. */
|
|
1037
|
+
presentBias?: Unit;
|
|
1038
|
+
}
|
|
1039
|
+
export interface PlanningState {
|
|
1040
|
+
depth: number;
|
|
1041
|
+
presentBias?: Unit;
|
|
1042
|
+
}
|
|
1032
1043
|
export interface Person {
|
|
1033
1044
|
schema: typeof PERSON_SCHEMA;
|
|
1034
1045
|
/** Engine version that last wrote this state. */
|
|
@@ -1048,8 +1059,10 @@ export interface Person {
|
|
|
1048
1059
|
skills: Record<string, Skill>;
|
|
1049
1060
|
/** Acquired conditional method evidence and current received cues; absent until used. */
|
|
1050
1061
|
methods?: MethodsState;
|
|
1051
|
-
/** Received future consequences, absent until attended testimony supplies them. */
|
|
1062
|
+
/** Received future consequences, absent until attended testimony or `seedConsequences` supplies them. */
|
|
1052
1063
|
prospection?: ProspectionState;
|
|
1064
|
+
/** Opt-in bounded planning over retained consequences. Owned by `prospection/`. */
|
|
1065
|
+
planning?: PlanningState;
|
|
1053
1066
|
/** Noticed promptings and practised turnings-away (2.4.0, opt-in via `enablePromptings`). Owned by `promptings/`. */
|
|
1054
1067
|
promptings?: PromptingsState;
|
|
1055
1068
|
/** Intrinsic exploration and varied repetition. Owned by `curiosity/`; absent unless enabled. */
|
|
@@ -1500,6 +1513,8 @@ export interface PersonSpec {
|
|
|
1500
1513
|
promptings?: PromptingsSpec;
|
|
1501
1514
|
/** Enable intrinsic exploration and play, using engineering defaults or bounded overrides. */
|
|
1502
1515
|
curiosity?: boolean | CuriositySpec;
|
|
1516
|
+
/** Bounded planning: the same as `enablePlanning(p, spec)` after creation. */
|
|
1517
|
+
planning?: PlanningSpec;
|
|
1503
1518
|
/** Evening self-review (2.7.0): the same as `enableReview(p, spec)` after creation. */
|
|
1504
1519
|
review?: ReviewSpec;
|
|
1505
1520
|
};
|
package/dist/types.js
CHANGED
|
@@ -120,4 +120,4 @@ export const PERSON_SCHEMA = 'human/person@1';
|
|
|
120
120
|
* and an activity that would cover a closing stretch is reviewed when the stretch begins (`isUnderWay`,
|
|
121
121
|
* `dutyReviewAt`). Person shape unchanged.
|
|
122
122
|
*/
|
|
123
|
-
export const ENGINE_VERSION = '2.
|
|
123
|
+
export const ENGINE_VERSION = '2.12.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adam0white/human-framework",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Deterministic, explainable simulated people: body, needs, affect, memory, beliefs, skills, habits, relationships, values and a will that can refuse a suggestion",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"simulation",
|