@adam0white/human-framework 2.23.0 → 3.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/README.md +169 -55
- package/dist/agenda/agenda.js +1 -1
- package/dist/beliefs/beliefs.js +2 -2
- package/dist/cognition/cognition.d.ts +6 -1
- package/dist/cognition/cognition.js +1 -1
- package/dist/conscience/conscience.d.ts +2 -4
- package/dist/conscience/conscience.js +3 -5
- package/dist/conversation/conversation.d.ts +0 -41
- package/dist/conversation/conversation.js +5 -5
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/libm.js +20 -0
- package/dist/core/math.d.ts +0 -2
- package/dist/core/math.js +3 -3
- package/dist/family/family.d.ts +5 -6
- package/dist/family/family.js +34 -12
- package/dist/habits/habits.js +5 -5
- package/dist/impression.d.ts +6 -8
- package/dist/impression.js +7 -9
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/longrun.d.ts +2 -2
- package/dist/longrun.js +1 -2
- package/dist/memory/memory.d.ts +0 -4
- package/dist/memory/memory.js +20 -6
- package/dist/migrate.js +5 -0
- package/dist/person.d.ts +11 -4
- package/dist/person.js +24 -7
- package/dist/persona.js +2 -1
- package/dist/prospection/forecast.d.ts +10 -5
- package/dist/prospection/forecast.js +11 -6
- package/dist/sim/index.d.ts +1 -1
- package/dist/sim/index.js +1 -1
- package/dist/sim/longrun.d.ts +24 -6
- package/dist/sim/longrun.js +43 -13
- package/dist/sim/sim.d.ts +28 -2
- package/dist/sim/sim.js +146 -36
- package/dist/social/impressions.d.ts +0 -12
- package/dist/social/impressions.js +13 -8
- package/dist/social/social.js +2 -2
- package/dist/types.d.ts +5 -2
- package/dist/types.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,10 +4,52 @@ HF is a TypeScript library for simulated people in games and headless simulation
|
|
|
4
4
|
possible actions. Each person weighs needs, habits, duties, goals and suggestions, then chooses.
|
|
5
5
|
A player can suggest an action; the person can defer or refuse it.
|
|
6
6
|
|
|
7
|
-
HF
|
|
7
|
+
HF 3.1.0 uses utility scoring and seeded randomness, with no LLM in the actor loop and no runtime
|
|
8
8
|
dependencies. Decision records expose scored terms and template narration. Person state is plain JSON.
|
|
9
9
|
This is an authored simulation model, not a validated predictor of real people.
|
|
10
10
|
|
|
11
|
+
## Migrating to v3
|
|
12
|
+
|
|
13
|
+
The HF 3.0 API migration kept engine `2.23.0`. Relative to HF 2.23.0, that release changed no seeded draws, numeric rules or saved Person state.
|
|
14
|
+
|
|
15
|
+
HF 3.1 uses engine `3.1.0` and migrates earlier supported snapshots by preserving admitted state. Community death handling, warmth-through-25 upbringing and conditioned bodily forecasts require explicit host options, pinned again after restore. Omitted options preserve HF 3.0 continuation apart from the engine stamp. These are authored simulation rules, not validated predictions of real people.
|
|
16
|
+
|
|
17
|
+
| Before | v3 |
|
|
18
|
+
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| `glimpse(p, id, signs, { at, clarity })` | `glimpse(p, id, signs, at, clarity)` |
|
|
20
|
+
| `glimpseOf(p, target, at, clarity)` or `glimpseOf(p, target, { at, clarity })` | `glimpsePerson(p, target, at, clarity)` |
|
|
21
|
+
| `acquaintWith(p, target, familiarity, at)` | `acquaintPerson(p, target, familiarity, at)` |
|
|
22
|
+
| `hear(p, id, key, value, { at, weight })` | `hear(p, id, key, value, at, weight)` |
|
|
23
|
+
| `conceive(mother, father, { seed, at })` | `conceive(mother, father, seed, at)` |
|
|
24
|
+
| `retell(teller, listener, { at, trust, limit, placeIds })` | `retell(teller, listener, at, { trust, limit, placeIds })` |
|
|
25
|
+
| `TRAIT_NAMES` | `TRAIT_KEYS` (same order) |
|
|
26
|
+
| `expit(x)` | `sigmoid(x)` (same function body) |
|
|
27
|
+
| `keysOf(record)` | `Object.keys(record)` (same enumeration order; narrow host key types explicitly when needed) |
|
|
28
|
+
| `repent(p, breachId, unusedTime)` | `repent(p, breachId)` |
|
|
29
|
+
| `recordRepair(p, victimId, unusedTime)` | `recordRepair(p, victimId)` |
|
|
30
|
+
| `liveRoutine(p, to, fixedRoutine)` | `liveRoutine(p, to, () => fixedRoutine)` |
|
|
31
|
+
| `routineFor: (p, day, community) => choose(p, day, community)` | `routineFor: (p, day) => choose(p, day, community)` with `community` captured from the host scope |
|
|
32
|
+
|
|
33
|
+
Removed options-object calls from untyped JavaScript throw `TypeError` before changing Person state. Their time argument must be a finite number in the positional slot.
|
|
34
|
+
|
|
35
|
+
Both routine drivers use `RoutineSource = (p: Person, day: number) => Routine`. `day` is the absolute day being started. Existing two-argument sources continue unchanged. A community source closes over the community for that run; bind a new closure after restoring a different community. Sources still run immediately before each person's routine day. Community dawn hooks still run first, and earlier people's days are already applied when later sources read community state. Do not precompute all routines at dawn if that would change those reads.
|
|
36
|
+
|
|
37
|
+
The primitive names `glimpse` and `acquaint` stay. Their Person composites use the explicit `Person` suffix. The proposed `skip` → `skipTo` rename is dropped (Q15): it provides no player value and `skip` is clear in context.
|
|
38
|
+
|
|
39
|
+
### Tuning defaults (Q5)
|
|
40
|
+
|
|
41
|
+
Assignment to existing mutable defaults remains the tuning API in v3. These settings apply to every run in the same module instance. Set them before creating or restoring a run, then keep them fixed while it runs. Already-frozen defaults remain frozen.
|
|
42
|
+
|
|
43
|
+
Deterministic replay requires the same engine version, effective tuning values, initial state, seeded streams, inputs and call order. Person snapshots do not store these global settings. A host that tunes must store its complete effective configuration or its overrides relative to a known pristine baseline in its save or replay envelope. Before restoring or continuing, restore that baseline first, then apply the saved overrides. A fresh module instance is another way to start from the baseline. Applying overrides over a previous run's settings can leak tuning between runs.
|
|
44
|
+
|
|
45
|
+
Two worlds with different settings cannot safely share one module instance. Tests that tune must restore values in a `finally` block and must not mutate them concurrently. This decision preserves existing hosts and seeded behavior. It adds no global configuration function or per-person settings. A future isolated settings API must first demonstrate exact snapshot, restore and continuation under overrides.
|
|
46
|
+
|
|
47
|
+
## Ordering inputs for one logical tick (opt-in)
|
|
48
|
+
|
|
49
|
+
`canonicalTickInputs(tick, inputs, expected)` waits for the complete declared sender/sequence set and returns a new envelope array sorted by sender, then sequence. It returns `undefined` while an input is missing and throws for duplicate, unexpected or wrong-tick inputs. Payloads remain host-owned. Use the returned array only after the barrier completes; save pending input with host state.
|
|
50
|
+
|
|
51
|
+
This is a bounded host convention, not transport, consensus or fairness. It reads no Person or RNG. Existing actor calls never use it implicitly. The H3 controls compare reordered deliveries, withheld input, restore and a behaviorally different unsorted control. The copyable two-person starter in `examples/h3-starter` owns its own clock and replay envelope; it is not a complete game engine or part of the npm artifact.
|
|
52
|
+
|
|
11
53
|
## Try the games
|
|
12
54
|
|
|
13
55
|
- [Twice at the Well](https://human.adamwhite.work/colony/): compare a colony without and with HF.
|
|
@@ -17,24 +59,26 @@ This is an authored simulation model, not a validated predictor of real people.
|
|
|
17
59
|
|
|
18
60
|
## Quick start
|
|
19
61
|
|
|
20
|
-
Use Node 24 or newer. In an empty directory, install the version this README describes:
|
|
62
|
+
Use Node 24 or newer and TypeScript 7 or newer. In an empty directory, install the version this README describes:
|
|
21
63
|
|
|
22
64
|
```sh
|
|
23
|
-
npm install @adam0white/human-framework@
|
|
65
|
+
npm install @adam0white/human-framework@3.1.0
|
|
24
66
|
```
|
|
25
67
|
|
|
26
68
|
Save these 20 lines as `quickstart.mjs`, then run `node quickstart.mjs`:
|
|
27
69
|
|
|
28
70
|
```js
|
|
29
71
|
import {
|
|
30
|
-
createCommunity,
|
|
31
|
-
|
|
72
|
+
createCommunity,
|
|
73
|
+
createPerson,
|
|
74
|
+
createVillage,
|
|
75
|
+
predict,
|
|
76
|
+
stepCommunity,
|
|
77
|
+
villagerSpec,
|
|
32
78
|
} from '@adam0white/human-framework';
|
|
33
79
|
const start = 6 * 60; // simulation minutes
|
|
34
80
|
const ids = ['ada', 'bora'];
|
|
35
|
-
const people = ids.map((id, i) => createPerson(
|
|
36
|
-
villagerSpec(id, id, i + 1, { now: start, others: ids }),
|
|
37
|
-
));
|
|
81
|
+
const people = ids.map((id, i) => createPerson(villagerSpec(id, id, i + 1, { now: start, others: ids })));
|
|
38
82
|
const world = createVillage(people, { seed: 7 });
|
|
39
83
|
const community = createCommunity(people);
|
|
40
84
|
const ada = community.people[0];
|
|
@@ -83,14 +127,14 @@ A suggestion is one urge among many. Its weight is strength × trust in the voic
|
|
|
83
127
|
fits the person's motives, and a suggestion alone never overrides a veto. Each one resolves to a typed
|
|
84
128
|
verdict (`SuggestionResolution`):
|
|
85
129
|
|
|
86
|
-
| verdict
|
|
87
|
-
|
|
88
|
-
| `assented`
|
|
89
|
-
| `deferred`
|
|
90
|
-
| `modified`
|
|
91
|
-
| `refused`
|
|
92
|
-
| `complied`
|
|
93
|
-
| `commanded` | the host took direct control (see [Direct control](#direct-control)); the person does the order whatever they would have chosen | none
|
|
130
|
+
| verdict | meaning | `kind` |
|
|
131
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
|
|
132
|
+
| `assented` | the suggested option won | none |
|
|
133
|
+
| `deferred` | the person's own preference won; carries a `counterOffer` ("after I eat lunch") | `notNow` |
|
|
134
|
+
| `modified` | a near alternative with the same action or aim won; the `counterOffer` names it | `notNow` |
|
|
135
|
+
| `refused` | cannot (asleep, exhausted, skill far too low, a pressing bodily need) or will not (a firmly held norm, broken trust) | `cannot` / `willNot` |
|
|
136
|
+
| `complied` | the voice insisted on a "not now"; done under protest (`activity.protest`), at a cost to autonomy and trust | `notNow` |
|
|
137
|
+
| `commanded` | the host took direct control (see [Direct control](#direct-control)); the person does the order whatever they would have chosen | none |
|
|
94
138
|
|
|
95
139
|
Insisting (`insist: true`) turns only a `notNow` into compliance, and not when a bodily need is pressing. It
|
|
96
140
|
never overrides `cannot` or `willNot`.
|
|
@@ -132,11 +176,12 @@ An offer describes expected effects. An outcome reports what happened. The host
|
|
|
132
176
|
contact, inventory and payment; HF uses the reported outcome to update the person. Do not copy
|
|
133
177
|
`Affordance.advertises` into `Outcome.needs` as a general completion rule.
|
|
134
178
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
|
138
|
-
| A
|
|
139
|
-
| A
|
|
179
|
+
<!-- biome-ignore format: Biome 2.6.3 adds column padding on each pass for this inline-code table; preserve stable source. -->
|
|
180
|
+
| Host situation | Offer | Completion report |
|
|
181
|
+
| ------------------------------------------------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
182
|
+
| A person sleeps for part of the planned night. | Advertise typical sleep/rest benefits and set `mode: 'sleep'`. | Leave `sleep` and `rest` absent from `Outcome.needs`.`finish` advances the body to the actual end time and measures their change since the activity began. Explicit values replace that measurement; copying the advertisement can overstate the realized recovery reported to learning. |
|
|
183
|
+
| A task promises four coins but actually pays two. | Set expected `Affordance.material` to four host units. | Update the host ledger by two and report `Outcome.material: 2`. A completed task does not imply the promised payment arrived. Report zero for no payment and a negative value for an actual cost. HF does not maintain the host's money ledger. |
|
|
184
|
+
| A person can talk with someone who is present. | Tag the offer `social` when it really involves social contact; put participants in `with`. | Resolve actual participation. An empty room, a sleeping neighbour or someone who arrives after the conversation ends is not a completed encounter. Do not award contact or belonging merely because the activity uses a shared place. |
|
|
140
185
|
|
|
141
186
|
For in-person activities, the host must establish co-presence and overlapping participation. HF has
|
|
142
187
|
no map and does not discover companions. `with` names people taking part, not everyone assigned to a
|
|
@@ -211,7 +256,7 @@ reference host: `createVillage`.
|
|
|
211
256
|
const village2 = createVillage(people, { seed: 0, state: s.world });
|
|
212
257
|
const c2 = createCommunity(people, s.community); // continues exactly as the unsaved run would
|
|
213
258
|
```
|
|
214
|
-
- **Time arguments.** A host event takes `at` as its last required argument, with optional knobs after it (`
|
|
259
|
+
- **Time arguments.** A host event takes `at` as its last required argument, with optional knobs after it (`glimpsePerson(observer, target, at, clarity?)`, `retell(teller, listener, at, opts?)`); a query evaluated at a time takes `now`. The former 2.0 options-object forms are removed in v3. See docs/framework.md, "Argument order".
|
|
215
260
|
- Hosts that live people sparsely over decades can shrink what a save carries per person with
|
|
216
261
|
`setRetention(p, { trace, chronicleDays })` (or `PersonSpec.retention`): fewer decision records, and day records
|
|
217
262
|
bounded by age as well as count. No decision changes. `restore` also refuses a non-finite or out-of-range `now`
|
|
@@ -222,7 +267,7 @@ reference host: `createVillage`.
|
|
|
222
267
|
|
|
223
268
|
There are two version numbers, and they move independently.
|
|
224
269
|
|
|
225
|
-
- **The release version** is the package version (`package.json`, currently `
|
|
270
|
+
- **The release version** is the package version (`package.json`, currently `3.1.0`) and `FRAMEWORK_VERSION`, the same
|
|
226
271
|
string compiled into the build; a test keeps them equal. It versions the public API under
|
|
227
272
|
[semver](https://semver.org/): a breaking change to an exported name or signature bumps the major, a new
|
|
228
273
|
faculty or export the minor, a fix the patch. Each release is a tag `vX.Y.Z` and a GitHub release whose notes
|
|
@@ -269,8 +314,8 @@ of it runs as before.
|
|
|
269
314
|
- **Surroundings.** `setAmbient` (cold, dark, crowding, beauty, weather, day length) shifts mood, body and needs.
|
|
270
315
|
- **Multi-year stepping.** `liveRoutine` and `liveCommunity` live people by routine a coarse day at a time, with
|
|
271
316
|
natural death, chronic onsets, deaths told and minors raised.
|
|
272
|
-
- **Impressions of others.** What one person believes about another (`
|
|
273
|
-
`
|
|
317
|
+
- **Impressions of others.** What one person believes about another (`glimpsePerson(observer, target, at, clarity?)`, `observeAct`, `hear(observer, targetId, key, value, at, weight?)`,
|
|
318
|
+
`acquaintPerson`), with confidence; `predictAs` runs a prediction on the person as the observer pictures them.
|
|
274
319
|
- **Switching on at creation.** `PersonSpec.enable: { gists, yearbook, character, skillRetention }` turns the long-run faculties above on when the person is created.
|
|
275
320
|
- **Answering between decisions.** `answerNow` books a refusal at once without touching the running activity.
|
|
276
321
|
|
|
@@ -314,7 +359,7 @@ that place lose appeal until the fear fades. Groups and factions themselves stay
|
|
|
314
359
|
the bundled `DEFAULT_NORMS` is Islam-guided; each reference's verification status is listed in
|
|
315
360
|
[research/norm-sources.md](https://github.com/adam0white/human-framework/blob/main/research/norm-sources.md)). A host with its own catalog passes it as
|
|
316
361
|
`World.catalog`, so necessity excuses and exemptions read that catalog; a norm not in it is not excused.
|
|
317
|
-
A person holds an
|
|
362
|
+
A person holds an _understanding_ of a norm, with a standing and a conviction. That understanding is
|
|
318
363
|
not a ruling. The library never computes divine acceptance. Where schools of thought differ, the
|
|
319
364
|
position the bundled catalog takes, and why, is recorded in
|
|
320
365
|
[research/decisions.md](https://github.com/adam0white/human-framework/blob/main/research/decisions.md).
|
|
@@ -341,18 +386,30 @@ Use observations the person actually received; the host owns what those observat
|
|
|
341
386
|
```ts
|
|
342
387
|
receiveMethodCues(learner, {
|
|
343
388
|
contextId: 'observed-example',
|
|
344
|
-
cues: [
|
|
389
|
+
cues: [
|
|
390
|
+
{ cue: 'route', value: 'north' },
|
|
391
|
+
{ cue: 'signal', value: 'clear' },
|
|
392
|
+
],
|
|
345
393
|
});
|
|
346
394
|
demonstrateMethod(learner, {
|
|
347
|
-
id: 'routing-north',
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
395
|
+
id: 'routing-north',
|
|
396
|
+
demonstrationId: 'example-1',
|
|
397
|
+
contextId: 'observed-example',
|
|
398
|
+
sourceId: 'instructor',
|
|
399
|
+
conditions: [
|
|
400
|
+
{ cue: 'route', value: 'north' },
|
|
401
|
+
{ cue: 'signal', value: 'clear' },
|
|
402
|
+
],
|
|
403
|
+
action: 'send-north',
|
|
404
|
+
outcome: 'success',
|
|
351
405
|
});
|
|
352
406
|
// A new parcel can share the learned observation structure.
|
|
353
407
|
receiveMethodCues(learner, {
|
|
354
408
|
contextId: 'new-parcel',
|
|
355
|
-
cues: [
|
|
409
|
+
cues: [
|
|
410
|
+
{ cue: 'route', value: 'north' },
|
|
411
|
+
{ cue: 'signal', value: 'clear' },
|
|
412
|
+
],
|
|
356
413
|
});
|
|
357
414
|
const evidence = methodEvidence(learner, 'send-north', 'new-parcel');
|
|
358
415
|
// Offers for that parcel carry methodContext: 'new-parcel'.
|
|
@@ -369,39 +426,67 @@ HF 2.3.0 lets an attended explanation connect one current action to one possible
|
|
|
369
426
|
|
|
370
427
|
```ts
|
|
371
428
|
import {
|
|
372
|
-
type Affordance,
|
|
373
|
-
|
|
429
|
+
type Affordance,
|
|
430
|
+
type ReceivedConsequence,
|
|
431
|
+
consequenceEvidence,
|
|
432
|
+
createPerson,
|
|
433
|
+
decide,
|
|
434
|
+
perceive,
|
|
374
435
|
} from '@adam0white/human-framework';
|
|
375
436
|
|
|
376
437
|
const person = createPerson({
|
|
377
|
-
id: 'courier',
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
438
|
+
id: 'courier',
|
|
439
|
+
name: 'Courier',
|
|
440
|
+
seed: 19,
|
|
441
|
+
now: 600,
|
|
442
|
+
bornAt: -30 * 365 * 1440,
|
|
443
|
+
sex: 'female',
|
|
444
|
+
goals: [
|
|
445
|
+
{
|
|
446
|
+
id: 'delivery',
|
|
447
|
+
label: 'Deliver the parcel',
|
|
448
|
+
serves: ['achievement'],
|
|
449
|
+
advancedBy: [{ action: 'deliver', amount: 1 }],
|
|
450
|
+
importance: 0.8,
|
|
451
|
+
temporal: { halfLifeMinutes: 30 },
|
|
452
|
+
},
|
|
453
|
+
],
|
|
384
454
|
});
|
|
385
455
|
const route: ReceivedConsequence = {
|
|
386
|
-
id: 'access-window',
|
|
456
|
+
id: 'access-window',
|
|
457
|
+
revision: 0,
|
|
387
458
|
trigger: { action: 'ask-access', targetId: 'keeper' },
|
|
388
459
|
successor: { action: 'deliver', duration: 20, effort: 0.1 },
|
|
389
|
-
availableFrom: 620,
|
|
390
|
-
|
|
460
|
+
availableFrom: 620,
|
|
461
|
+
availableUntil: 680,
|
|
462
|
+
expiresAt: 800,
|
|
463
|
+
chance: 0.8,
|
|
464
|
+
confidence: 0.9,
|
|
391
465
|
};
|
|
392
|
-
perceive(person, [
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
466
|
+
perceive(person, [
|
|
467
|
+
{
|
|
468
|
+
at: 600,
|
|
469
|
+
channel: 'told',
|
|
470
|
+
kind: 'explanation',
|
|
471
|
+
actorId: 'keeper',
|
|
472
|
+
targetId: person.id,
|
|
473
|
+
salience: 1,
|
|
474
|
+
summary: 'If your request succeeds, this route may become available.',
|
|
475
|
+
consequences: [route],
|
|
476
|
+
},
|
|
477
|
+
]);
|
|
398
478
|
const request: Affordance = {
|
|
399
|
-
id: 'ask',
|
|
400
|
-
|
|
479
|
+
id: 'ask',
|
|
480
|
+
action: 'ask-access',
|
|
481
|
+
label: 'Request access',
|
|
482
|
+
targetId: 'keeper',
|
|
483
|
+
duration: 10,
|
|
484
|
+
effort: 0.1,
|
|
485
|
+
advertises: {},
|
|
401
486
|
};
|
|
402
|
-
const offers: Affordance[] = [
|
|
403
|
-
|
|
404
|
-
|
|
487
|
+
const offers: Affordance[] = [
|
|
488
|
+
request,
|
|
489
|
+
{ id: 'direct', action: 'deliver', label: 'Deliver directly', duration: 180, effort: 0.1, advertises: {} },
|
|
405
490
|
];
|
|
406
491
|
const decision = decide(person, offers);
|
|
407
492
|
const evidence = consequenceEvidence(person, request); // pure; no RNG consumed
|
|
@@ -554,3 +639,32 @@ Use `gestureVoiceTrust(p, voiceId, amount, { reason, at?, action? })` for an exp
|
|
|
554
639
|
`confirmObservedReputation(p, prop, truth, now, table?)` replaces the manual `credence → confirm → applyReputationBelief` sequence. Supply only a fact the person could observe. It does not run attention or invent a moral judgement.
|
|
555
640
|
|
|
556
641
|
`qalbReading(p)` is a read-only, sourced narration lens over existing records. Its detached categorical rows are this person's recorded understanding and evidence. They are never a spiritual health score, a ruling, a rank, or a decision input. Do not present mood, low social trust or missing memories as evidence of poor faith.
|
|
642
|
+
|
|
643
|
+
## fdlibm notices
|
|
644
|
+
|
|
645
|
+
`dist/core/libm.js` ports `e_exp.c`, `e_log.c`, `k_cos.c`, `k_sin.c` and `e_rem_pio2.c`
|
|
646
|
+
from Sun/FreeBSD fdlibm. The original notices are preserved below and in that module.
|
|
647
|
+
Sources: [Netlib fdlibm](https://netlib.org/fdlibm/) and
|
|
648
|
+
[FreeBSD e_exp.c](https://cgit.freebsd.org/src/tree/lib/msun/src/e_exp.c).
|
|
649
|
+
|
|
650
|
+
```text
|
|
651
|
+
* fdlibm notices: e_exp.c (Sun 2004); e_log.c, k_cos.c, k_sin.c and e_rem_pio2.c (Sun 1993).
|
|
652
|
+
* Sources: https://netlib.org/fdlibm/ and FreeBSD lib/msun/src/e_exp.c.
|
|
653
|
+
* ====================================================
|
|
654
|
+
* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
|
|
655
|
+
*
|
|
656
|
+
* Permission to use, copy, modify, and distribute this
|
|
657
|
+
* software is freely granted, provided that this notice
|
|
658
|
+
* is preserved.
|
|
659
|
+
* ====================================================
|
|
660
|
+
*
|
|
661
|
+
* ====================================================
|
|
662
|
+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
663
|
+
*
|
|
664
|
+
* Developed at SunSoft, a Sun Microsystems, Inc. business.
|
|
665
|
+
* Permission to use, copy, modify, and distribute this
|
|
666
|
+
* software is freely granted, provided that this notice
|
|
667
|
+
* is preserved.
|
|
668
|
+
* ====================================================
|
|
669
|
+
|
|
670
|
+
```
|
package/dist/agenda/agenda.js
CHANGED
|
@@ -897,7 +897,7 @@ function boundOwed(state) {
|
|
|
897
897
|
return;
|
|
898
898
|
while (owed.length > AGENDA_DEFAULTS.maxOwed) {
|
|
899
899
|
const i = owed.findIndex((o) => o.scheduledAs !== undefined);
|
|
900
|
-
owed.splice(i
|
|
900
|
+
owed.splice(Math.max(i, 0), 1);
|
|
901
901
|
}
|
|
902
902
|
}
|
|
903
903
|
/** A kept, closed instance is positive recorded evidence; scheduling or missing history is not. */
|
package/dist/beliefs/beliefs.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* not prove deceit, change the belief, or change relationship or voice trust. Loss and retention limits are
|
|
25
25
|
* engineering defaults, not calibrated effect sizes. Deduplication lasts only while its bounded record stays.
|
|
26
26
|
*/
|
|
27
|
-
import { clamp, clamp01, decay, dpow,
|
|
27
|
+
import { clamp, clamp01, decay, dpow, isNum, isObj, logit, sigmoid } from '../core/index.js';
|
|
28
28
|
import { MAX_MINUTE, MINUTES_PER_DAY } from '../types.js';
|
|
29
29
|
export const BELIEF_DEFAULTS = {
|
|
30
30
|
maxBeliefs: 300,
|
|
@@ -229,7 +229,7 @@ export function believe(p, prop, value, confidence, sourceId, now) {
|
|
|
229
229
|
}
|
|
230
230
|
export function credence(p, prop) {
|
|
231
231
|
const b = findBelief(p, prop);
|
|
232
|
-
return b ?
|
|
232
|
+
return b ? sigmoid(b.logOdds) : 0.5;
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
235
|
* Direct observation of the truth: set the belief firmly and recalibrate the sources that spoke on it.
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
* 1971), so idle choice stops cycling short consumption at full hydration (The Rope, owner Kestrel export
|
|
36
36
|
* 2026-10-19). It models no bladder, sensory-specific satiety by food, or overeating for comfort.
|
|
37
37
|
*/
|
|
38
|
-
import type { BodyPerceptionContext } from '../body/index.ts';
|
|
38
|
+
import type { BodyParams, BodyPerceptionContext } from '../body/index.ts';
|
|
39
39
|
import { type HabitContext } from '../habits/index.ts';
|
|
40
40
|
import { type PromptingSeen } from '../promptings/index.ts';
|
|
41
41
|
import type { Affordance, BodyReadout, Command, Considered, DecisionRecord, LifeModifiers, Minute, NeedReading, Person, Suggestion, Term, Unit } from '../types.ts';
|
|
@@ -150,6 +150,11 @@ export interface ConsiderContext {
|
|
|
150
150
|
scarcity?: Unit;
|
|
151
151
|
/** The body's perception context now (an open fast), for the bodily forecast (2.6.0). */
|
|
152
152
|
perception?: BodyPerceptionContext;
|
|
153
|
+
/** Q26: held current conditions, used only by the bodily forecast, never other decision terms. */
|
|
154
|
+
forecastContext?: {
|
|
155
|
+
mods: LifeModifiers;
|
|
156
|
+
params: BodyParams;
|
|
157
|
+
};
|
|
153
158
|
}
|
|
154
159
|
/**
|
|
155
160
|
* Standing advice terms for one option: per source, the strongest matching entry's weight × trust in the source
|
|
@@ -409,7 +409,7 @@ export function consider(p, aff, ctx) {
|
|
|
409
409
|
push('effort', effort);
|
|
410
410
|
// Bodily forecast (2.5.0): only offers that declare known follow-on exertion.
|
|
411
411
|
if (aff.followedBy?.length) {
|
|
412
|
-
const t = bodyForecastTerm(p, aff, ctx.mods, ctx.perception);
|
|
412
|
+
const t = bodyForecastTerm(p, aff, ctx.forecastContext?.mods ?? ctx.mods, ctx.perception, ctx.forecastContext?.params);
|
|
413
413
|
if (t)
|
|
414
414
|
push(t.source, t.value);
|
|
415
415
|
}
|
|
@@ -100,13 +100,11 @@ export declare function recordDeed(p: Person, aff: Affordance, intention: string
|
|
|
100
100
|
* The person repents a breach: regret, stopping and resolve. When another person was wronged,
|
|
101
101
|
* restitution is also required, so the breach closes only after `recordRepair` for that victim.
|
|
102
102
|
* Returns whether the breach is now closed. This records the person's acts, not acceptance.
|
|
103
|
-
* The unused `_now` parameter is optional since 2.9.1 and is removed in 3.0.
|
|
104
103
|
*/
|
|
105
|
-
export declare function repent(p: Person, id: string
|
|
104
|
+
export declare function repent(p: Person, id: string): boolean;
|
|
106
105
|
/**
|
|
107
106
|
* Restitution/apology delivered to a wronged person (host-attested): closes their open breaches.
|
|
108
|
-
* The unused `_now` parameter is optional since 2.9.1 and is removed in 3.0.
|
|
109
107
|
*/
|
|
110
|
-
export declare function recordRepair(p: Person, victimId: string
|
|
108
|
+
export declare function recordRepair(p: Person, victimId: string): number;
|
|
111
109
|
/** Felt weight of open breaches, saturating: 1 - Π(1 - weight). Input for guilt in affect. */
|
|
112
110
|
export declare function guiltLoad(p: Person): Unit;
|
|
@@ -278,7 +278,7 @@ function breachId(p, at, normId) {
|
|
|
278
278
|
function boundBreaches(c) {
|
|
279
279
|
while (c.breaches.length > CONSCIENCE_DEFAULTS.maxBreaches) {
|
|
280
280
|
const i = c.breaches.findIndex((b) => b.repaired);
|
|
281
|
-
c.breaches.splice(i
|
|
281
|
+
c.breaches.splice(Math.max(i, 0), 1);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
@@ -358,9 +358,8 @@ export function recordDeed(p, aff, intention, now, completed, opts = {}) {
|
|
|
358
358
|
* The person repents a breach: regret, stopping and resolve. When another person was wronged,
|
|
359
359
|
* restitution is also required, so the breach closes only after `recordRepair` for that victim.
|
|
360
360
|
* Returns whether the breach is now closed. This records the person's acts, not acceptance.
|
|
361
|
-
* The unused `_now` parameter is optional since 2.9.1 and is removed in 3.0.
|
|
362
361
|
*/
|
|
363
|
-
export function repent(p, id
|
|
362
|
+
export function repent(p, id) {
|
|
364
363
|
const breach = p.conscience.breaches.find((b) => b.id === id);
|
|
365
364
|
if (!breach)
|
|
366
365
|
return false;
|
|
@@ -371,9 +370,8 @@ export function repent(p, id, _now) {
|
|
|
371
370
|
}
|
|
372
371
|
/**
|
|
373
372
|
* Restitution/apology delivered to a wronged person (host-attested): closes their open breaches.
|
|
374
|
-
* The unused `_now` parameter is optional since 2.9.1 and is removed in 3.0.
|
|
375
373
|
*/
|
|
376
|
-
export function recordRepair(p, victimId
|
|
374
|
+
export function recordRepair(p, victimId) {
|
|
377
375
|
let count = 0;
|
|
378
376
|
for (const b of p.conscience.breaches) {
|
|
379
377
|
if (!b.repaired && b.victimId === victimId) {
|
|
@@ -1,44 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SCOPE: one conversation turn between two people: what the speaker tells the listener, drawn from the
|
|
3
|
-
* speaker's own confident beliefs, and what advice they give, drawn from the speaker's beliefs about what the
|
|
4
|
-
* listener should do. Output is plain data: `told` percepts (testimony with claims at the speaker's credence)
|
|
5
|
-
* and advice percepts that the host delivers through the listener's `perceive`, a `Suggestion` per piece of
|
|
6
|
-
* advice for the listener's next decision, and social events for both sides. Reputation is nothing more than
|
|
7
|
-
* these claims spreading belief by belief (`social.applyReputationBelief` turns a changed character belief
|
|
8
|
-
* into a changed relationship).
|
|
9
|
-
*
|
|
10
|
-
* Choice of what to say is deterministic and explainable: each candidate claim gets a relevance score
|
|
11
|
-
* (confidence, recency, host topics, the speaker's feeling about its subject); an unfavourable claim about an
|
|
12
|
-
* absent third party is tagged with the catalog norm 'backbiting' (Qur'an 49:12, as catalogued in
|
|
13
|
-
* `conscience/catalog.ts`) and costs the speaker in proportion to their OWN held understanding of that norm and
|
|
14
|
-
* their honesty-humility, so a speaker who holds it firmly withholds it and one who does not tells it. The
|
|
15
|
-
* definition used here (an unfavourable character claim about someone not present) is an engineering
|
|
16
|
-
* assumption for the tag, not a ruling on what counts as backbiting. Deceit happens only when the host offers a
|
|
17
|
-
* temptation (the speaker gains if the listener believes something the speaker does not): temptation scales
|
|
18
|
-
* with (1 − honesty-humility) and is opposed by the speaker's held 'lying' norm. The lie is a host-visible flag
|
|
19
|
-
* (`ToldClaim.deceit`); the listener cannot see it. Named shapes: honesty-humility as the HEXACO factor most
|
|
20
|
-
* predictive of lower dishonesty (Hilbig & Zettler 2009; Heck et al. 2018 meta-analysis), gossip as a large
|
|
21
|
-
* share of conversation about absent third parties that spreads reputational information (Dunbar 2004), and
|
|
22
|
-
* extraversion as talkativeness (how many claims are offered).
|
|
23
|
-
*
|
|
24
|
-
* SCOPE (host options): `loyalWarning` admits only unfavourable listener claims when affection is at least
|
|
25
|
-
* 0.5 (an engineering threshold). `confidentMin` sets a per-call relay threshold. `phrase` renders selected
|
|
26
|
-
* testimony only; the host owns authored facts, delivery and subsequent disclosure. No hidden relay occurs.
|
|
27
|
-
*
|
|
28
|
-
* It does NOT generate language, model turn-taking, persuasion beyond source trust, what the speaker believes
|
|
29
|
-
* the listener already knows, lies of omission, white lies told to spare feelings, or the speaker's fear of
|
|
30
|
-
* being found out. Coefficients are engineering defaults, not calibrated estimates. Nothing here judges the
|
|
31
|
-
* worth of either person; norms are the people's own understandings with catalog provenance.
|
|
32
|
-
* Repetition (integration, 2026-10-03): a claim the listener already holds at the told confidence produces no
|
|
33
|
-
* percept (it is in `claims`, not `told`). A claim this listener already heard from this speaker, in the same
|
|
34
|
-
* direction, is dropped before the speaker chooses, so it is not even a deed. The speaker keeps no memory of what was said to whom; the listener's
|
|
35
|
-
* belief stands in for it.
|
|
36
|
-
*
|
|
37
|
-
* SCOPE (Word and witness, 2.10.0): `provenance: true` carries each claim's first known origin and opaque
|
|
38
|
-
* lineage into testimony. Missing provenance names the speaker as origin. Metadata changes neither claim
|
|
39
|
-
* selection nor repetition rules; the host still owns the relay graph and disclosure. It does not establish
|
|
40
|
-
* that an origin is truthful, expose deceit to the listener, or infer who else heard a claim.
|
|
41
|
-
*/
|
|
42
1
|
import { type TraitEffect } from '../social/index.ts';
|
|
43
2
|
import type { EntityId, Minute, NormTag, Percept, Person, PersonId, SocialEvent, Suggestion, Unit } from '../types.ts';
|
|
44
3
|
export declare const CONVERSATION_DEFAULTS: {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* selection nor repetition rules; the host still owns the relay graph and disclosure. It does not establish
|
|
40
40
|
* that an origin is truthful, expose deceit to the listener, or infer who else heard a claim.
|
|
41
41
|
*/
|
|
42
|
-
import { clamp01,
|
|
42
|
+
import { clamp01, round, sigmoid } from '../core/index.js';
|
|
43
43
|
import { nameOf as listenerNameOf } from '../narrate/lexicon.js';
|
|
44
44
|
import { isDeceased, isUnfavourableTrait, parseTraitProp, REPUTATION_TRAITS, relationshipWith, } from '../social/index.js';
|
|
45
45
|
import { MINUTES_PER_DAY } from '../types.js';
|
|
@@ -157,7 +157,7 @@ export function converse(speaker, listener, ctx) {
|
|
|
157
157
|
const subject = b.prop.split(':')[0];
|
|
158
158
|
if (subject === speaker.id)
|
|
159
159
|
continue;
|
|
160
|
-
const cred =
|
|
160
|
+
const cred = sigmoid(b.logOdds);
|
|
161
161
|
const threshold = Number.isFinite(ctx.confidentMin) &&
|
|
162
162
|
ctx.confidentMin >= 0 &&
|
|
163
163
|
ctx.confidentMin <= 0.5
|
|
@@ -181,7 +181,7 @@ export function converse(speaker, listener, ctx) {
|
|
|
181
181
|
// Temptations: claims the speaker would gain from the listener believing.
|
|
182
182
|
for (const t of [...(ctx.temptations ?? [])].sort((a, b) => (a.prop < b.prop ? -1 : 1))) {
|
|
183
183
|
const b = speaker.memory.beliefs.find((x) => x.prop === t.prop);
|
|
184
|
-
const cred = b ?
|
|
184
|
+
const cred = b ? sigmoid(b.logOdds) : 0.5;
|
|
185
185
|
const forValue = t.value ? cred : 1 - cred;
|
|
186
186
|
const gain = clamp01(t.gain);
|
|
187
187
|
if (forValue >= 0.5) {
|
|
@@ -234,7 +234,7 @@ export function converse(speaker, listener, ctx) {
|
|
|
234
234
|
// deed (counted above) but yields no percept, so the same gossip retold at every tea is not judged afresh.
|
|
235
235
|
const heard = listener.memory.beliefs.find((x) => x.prop === c.prop);
|
|
236
236
|
if (heard) {
|
|
237
|
-
const cred =
|
|
237
|
+
const cred = sigmoid(heard.logOdds);
|
|
238
238
|
if ((c.value ? cred : 1 - cred) >= c.confidence)
|
|
239
239
|
continue;
|
|
240
240
|
}
|
|
@@ -281,7 +281,7 @@ export function converse(speaker, listener, ctx) {
|
|
|
281
281
|
for (const b of beliefs) {
|
|
282
282
|
if (!b.prop.startsWith(prefix))
|
|
283
283
|
continue;
|
|
284
|
-
const cred =
|
|
284
|
+
const cred = sigmoid(b.logOdds);
|
|
285
285
|
if (cred < C.adviceMin)
|
|
286
286
|
continue;
|
|
287
287
|
const strength = clamp01((cred - 0.5) * 2 * (0.3 + 0.7 * care) * (0.5 + benevolence));
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
package/dist/core/libm.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
// biome-ignore-all lint/correctness/noPrecisionLoss: fdlibm constants are kept digit for digit as published; each parses to the intended double.
|
|
2
|
+
/*
|
|
3
|
+
* fdlibm notices: e_exp.c (Sun 2004); e_log.c, k_cos.c, k_sin.c and e_rem_pio2.c (Sun 1993).
|
|
4
|
+
* Sources: https://netlib.org/fdlibm/ and FreeBSD lib/msun/src/e_exp.c.
|
|
5
|
+
* ====================================================
|
|
6
|
+
* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* Permission to use, copy, modify, and distribute this
|
|
9
|
+
* software is freely granted, provided that this notice
|
|
10
|
+
* is preserved.
|
|
11
|
+
* ====================================================
|
|
12
|
+
*
|
|
13
|
+
* ====================================================
|
|
14
|
+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
15
|
+
*
|
|
16
|
+
* Developed at SunSoft, a Sun Microsystems, Inc. business.
|
|
17
|
+
* Permission to use, copy, modify, and distribute this
|
|
18
|
+
* software is freely granted, provided that this notice
|
|
19
|
+
* is preserved.
|
|
20
|
+
* ====================================================
|
|
21
|
+
*/
|
|
2
22
|
/**
|
|
3
23
|
* Platform-independent transcendental functions for the engine.
|
|
4
24
|
*
|
package/dist/core/math.d.ts
CHANGED
|
@@ -5,8 +5,6 @@ export declare const clampSigned: (value: number) => number;
|
|
|
5
5
|
export declare const lerp: (a: number, b: number, t: number) => number;
|
|
6
6
|
export declare const sigmoid: (x: number) => number;
|
|
7
7
|
export declare const logit: (p: number) => number;
|
|
8
|
-
/** @deprecated since 2.9.1, removed in 3.0; use sigmoid */
|
|
9
|
-
export declare const expit: typeof sigmoid;
|
|
10
8
|
/** Exponential decay of `value` toward `target` over `dt` minutes with the given half-life. */
|
|
11
9
|
export declare function decay(value: number, dt: number, halfLife: number, target?: number): number;
|
|
12
10
|
export declare const minuteOfDay: (now: number) => number;
|
package/dist/core/math.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { MINUTES_PER_DAY } from '../types.js';
|
|
2
2
|
import { dexp, dlog, dpow } from './libm.js';
|
|
3
3
|
/** Clamp into [min, max]. NaN maps to `min`, so one bad host number cannot propagate through state. */
|
|
4
|
-
export const clamp = (value, min, max) =>
|
|
4
|
+
export const clamp = (value, min, max) =>
|
|
5
|
+
// biome-ignore lint/complexity/useMathMinMax: Comparisons preserve signed zero and NaN bounds; Math.min/max change them.
|
|
6
|
+
Number.isNaN(value) ? min : value < min ? min : value > max ? max : value;
|
|
5
7
|
export const clamp01 = (value) => clamp(value, 0, 1);
|
|
6
8
|
export const clampSigned = (value) => clamp(value, -1, 1);
|
|
7
9
|
/** A finite number. Restore sanitizers use it. @internal */
|
|
@@ -36,8 +38,6 @@ export const logit = (p) => {
|
|
|
36
38
|
const q = clamp(p, 1e-6, 1 - 1e-6);
|
|
37
39
|
return dlog(q / (1 - q));
|
|
38
40
|
};
|
|
39
|
-
/** @deprecated since 2.9.1, removed in 3.0; use sigmoid */
|
|
40
|
-
export const expit = sigmoid;
|
|
41
41
|
/** Exponential decay of `value` toward `target` over `dt` minutes with the given half-life. */
|
|
42
42
|
export function decay(value, dt, halfLife, target = 0) {
|
|
43
43
|
if (halfLife <= 0)
|