sica-fondt/src/endocrine/driver_ps_plus.R
Claude ee640f62d7
Add Drive-Box R reference track (endocrine system + 4 drivers + nervous system)
Executable reference implementation of the Drive-Box endocrine/affective core,
built TDD with a dependency-free R test harness (no testthat; runs on bare
r-base-core). Foundations dropped in as-is; the four drivers and the coupling
layer were each driven from a failing test first.

Modules (src/endocrine/):
- endocrine_array.R : 30-channel affective vector field + visceral friction
- priors.R          : trauma/triumph salience records
- driver_energy.R   : hard gate, tool-lock, exponential drag, asymmetric tool cost
- driver_ps_plus.R  : aggregates endocrine + priors into existential load + arguments
- driver_ethical_integrity.R : antithesis penalty / alignment discount / conviction hardening
- driver_etr.R      : toroidal coordinate, magnitude status bands, update path
- drive_box.R       : the 'nervous system' -- afferent(PS+) -> modulate(Eth-Int)
                      -> efferent gate(Energy) -> regime(ETR); the 'full integration'
                      Energy.request_execution anticipated
- test_framework.R  : minimal assertion harness (expect_*/test_case/test_summary)
- run_tests.sh      : runs every test_*.R from repo root

Suite: 5 test files, 108 assertions, all green (run: bash src/endocrine/run_tests.sh).
An Ada/SPARK port to src/organs/drive_box/ is a later session; this track is its
behavior oracle.
2026-06-10 03:59:46 +00:00

64 lines
2.5 KiB
R

# --- Driver 2: Primal Sensates+ (PS+) ---
# The visceral driver of the Drive-Box. PS+ does not reason; it FEELS.
# It reads the endocrine array and the priors store, then emits arguments --
# weighted, embodied claims about reality -- never logical propositions.
#
# Foundation modules are sourced as-is (repo-root-relative paths).
source("src/endocrine/endocrine_array.R")
source("src/endocrine/priors.R")
# Initialize a fresh PS+ state: a clean endocrine array and an empty priors store.
init_ps_plus_state <- function() {
return(list(
endocrines = init_endocrine_state(),
priors = init_priors_state()
))
}
# Ergonomic setter: set an endocrine channel magnitude on PS+ state.
# Delegates to the foundation's set_vector and returns the updated state.
ps_set_vector <- function(ps_plus_state, name, magnitude) {
ps_plus_state$endocrines <- set_vector(ps_plus_state$endocrines, name, magnitude)
return(ps_plus_state)
}
# Ergonomic wrapper: register a prior on PS+ state.
# Delegates to the foundation's add_prior and returns the updated state.
ps_add_prior <- function(ps_plus_state, id, type, salience, payload) {
ps_plus_state$priors <- add_prior(ps_plus_state$priors, id, type, salience, payload)
return(ps_plus_state)
}
# Evaluate Reality (the visceral way).
# Returns a list:
# existential_load : numeric -- aggregate felt pressure (base + friction + priors)
# arguments : list -- embodied claim strings
# is_logical : FALSE -- PS+ emits arguments, never logic
evaluate_reality <- function(ps_plus_state) {
active_vectors <- get_active_vectors(ps_plus_state$endocrines)
friction <- calculate_visceral_friction(ps_plus_state$endocrines)
base_load <- sum(active_vectors)
arguments <- list()
for (name in names(active_vectors)) {
ch_def <- get_channel_def(name)
if (!is.null(ch_def)) {
arguments[[length(arguments) + 1]] <- sprintf("VISCERAL [%s]: %s (%.2f)", name, ch_def$sensational, active_vectors[[name]])
}
}
if (friction > 0.5) {
arguments[[length(arguments) + 1]] <- sprintf("SYSTEMIC HEAT: Contradictory vectors detected (Friction: %.2f)", friction)
}
active_priors <- get_top_active_priors(ps_plus_state$priors, threshold = 0.8)
prior_load <- 0.0
for (prior in active_priors) {
prior_load <- prior_load + (prior$salience * 10.0)
arguments[[length(arguments) + 1]] <- sprintf("PRIOR [%s]: %s", prior$type, prior$payload)
}
existential_load <- base_load + friction + prior_load
return(list(
existential_load = existential_load,
arguments = arguments,
is_logical = FALSE
))
}