brainx-skill 1.0.15 → 1.0.17

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.
Files changed (180) hide show
  1. package/README.md +17 -1
  2. package/installation/lib/literature-mcp.js +7 -1
  3. package/manifest.json +1 -1
  4. package/mcp-servers/codex/README.md +46 -20
  5. package/mcp-servers/codex/UPSTREAM.md +20 -16
  6. package/mcp-servers/codex/app-server.mjs +177 -0
  7. package/mcp-servers/codex/cli-invocation.cjs +50 -0
  8. package/mcp-servers/codex/server.mjs +136 -69
  9. package/mcp-servers/codex/skills.json +1 -1
  10. package/mcp-servers/codex/test/fixtures/fake-codex.mjs +80 -3
  11. package/mcp-servers/codex/test/fixtures/run-server.mjs +7 -0
  12. package/mcp-servers/codex/test/server.test.mjs +188 -84
  13. package/package.json +1 -1
  14. package/skills/bio-neuro-lit/SKILL.md +4 -2
  15. package/skills/bio-neuro-lit/references/required-supplements.md +27 -0
  16. package/skills/brainx-acceleration/SKILL.md +30 -437
  17. package/skills/brainx-acceleration/references/audit-and-rewrite-patterns.md +326 -0
  18. package/skills/brainx-general-guard/SKILL.md +24 -8
  19. package/skills/brainx-install/SKILL.md +3 -3
  20. package/skills/brainx-install/references/compatibility-and-release-matching.md +28 -20
  21. package/skills/brainx-install/references/uninstall-and-cleanup.md +11 -4
  22. package/skills/brainx-modeling-loop/SKILL.md +117 -36
  23. package/skills/brainx-modeling-loop/agents/openai.yaml +2 -2
  24. package/skills/brainx-modeling-loop/references/mechanism-comparison.md +62 -0
  25. package/skills/brainx-modeling-loop/references/multiscale-coupling.md +16 -0
  26. package/skills/brainx-modeling-loop/references/paper-reproduction.md +42 -0
  27. package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +14 -14
  28. package/skills/brainx-modeling-loop/references/run-experiment.md +1 -1
  29. package/skills/brainx-modeling-loop/references/training-workflow.md +10 -8
  30. package/skills/brainx-visualization/SKILL.md +6 -2
  31. package/skills/brainx-visualization/references/neural-data-visualization.md +1 -1
  32. package/skills/brainx-visualization/references/statistical-and-model-visualization.md +1 -1
  33. package/skills/package-skills/braincell/SKILL.md +23 -14
  34. package/skills/package-skills/braincell/references/braintools/input-current.md +1 -1
  35. package/skills/package-skills/braincell/references/braintools/metric.md +72 -46
  36. package/skills/package-skills/braincell/references/mixions-for-adaptation.md +1 -1
  37. package/skills/package-skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +1 -1
  38. package/skills/package-skills/braincell/references/multicompartment/cv-policy-reference.md +1 -1
  39. package/skills/package-skills/braincell/references/multicompartment/filter-function-library.md +3 -3
  40. package/skills/package-skills/braincell/references/multicompartment/morphology-io-loading-validation.md +1 -1
  41. package/skills/package-skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +31 -43
  42. package/skills/package-skills/braincell/references/multicompartment/network-workflow.md +49 -0
  43. package/skills/package-skills/braincell/references/multicompartment/probe-reference.md +26 -114
  44. package/skills/package-skills/braincell/references/multicompartment/topology-building-and-visualization.md +40 -28
  45. package/skills/package-skills/braincell/references/scripts/cell_multicompartment_reference.py +13 -17
  46. package/skills/package-skills/brainevent/SKILL.md +0 -3
  47. package/skills/package-skills/brainevent/references/synaptic-plasticity.md +1 -1
  48. package/skills/package-skills/brainmass/SKILL.md +5 -3
  49. package/skills/package-skills/brainmass/references/brainstate/parameter-constraints-regularization.md +9 -7
  50. package/skills/package-skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
  51. package/skills/package-skills/brainmass/references/braintools/data-preprocessing.md +15 -7
  52. package/skills/package-skills/brainmass/references/braintools/metric.md +72 -46
  53. package/skills/package-skills/brainmass/references/coupling-network-api.md +3 -1
  54. package/skills/package-skills/brainmass/references/fitting-with-objectives-api.md +6 -6
  55. package/skills/package-skills/brainmass/references/horn-task-training.md +9 -9
  56. package/skills/package-skills/brainmass/references/modellibrary.md +12 -10
  57. package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +5 -3
  58. package/skills/package-skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +10 -6
  59. package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +3 -1
  60. package/skills/package-skills/brainmass/references/visualization-analysis-api.md +17 -9
  61. package/skills/package-skills/brainspike/SKILL.md +201 -0
  62. package/skills/package-skills/brainspike/references/braintools/connectivity.md +40 -0
  63. package/skills/package-skills/brainspike/references/braintools/data-preprocessing.md +39 -0
  64. package/skills/package-skills/brainspike/references/braintools/input-current.md +55 -0
  65. package/skills/package-skills/brainspike/references/braintools/metric.md +36 -0
  66. package/skills/package-skills/brainspike/references/braintools/optimizer.md +50 -0
  67. package/skills/package-skills/brainspike/references/braintools/parameter-initializer.md +43 -0
  68. package/skills/package-skills/brainspike/references/braintools/surrogate.md +40 -0
  69. package/skills/package-skills/brainspike/references/migration-boundary.md +38 -0
  70. package/skills/package-skills/brainspike/references/model-and-readout-selection.md +41 -0
  71. package/skills/package-skills/brainspike/references/multirate-coupling.md +31 -0
  72. package/skills/package-skills/brainspike/references/multiscale-composition.md +28 -0
  73. package/skills/package-skills/brainspike/references/native-composition.md +52 -0
  74. package/skills/package-skills/brainspike/references/native-delays.md +34 -0
  75. package/skills/package-skills/brainspike/references/native-projections.md +43 -0
  76. package/skills/package-skills/brainspike/references/native-training.md +36 -0
  77. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/devices.md +33 -33
  78. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/divergence-and-parity.md +15 -15
  79. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/integration-categories.md +1 -1
  80. package/skills/package-skills/brainspike/references/nest-compatible/model-library.md +200 -0
  81. package/skills/package-skills/brainspike/references/nest-compatible/network-building.md +276 -0
  82. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brette_et_al_2007.py +23 -26
  83. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_alpha.py +18 -21
  84. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_delta.py +16 -19
  85. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +11 -12
  86. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +10 -11
  87. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/spatial_gaussex.py +18 -18
  88. package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/synapsecollection.py +26 -29
  89. package/skills/package-skills/brainspike/references/nest-compatible/synapse-and-connectivity.md +166 -0
  90. package/skills/package-skills/brainspike/references/nest-delay-boundaries.md +31 -0
  91. package/skills/package-skills/brainspike/references/nonlinear-state-sharing.md +26 -0
  92. package/skills/package-skills/{brainpy-state → brainspike}/references/perturbation-experiment-validity.md +2 -2
  93. package/skills/package-skills/brainspike/references/simulator-training.md +61 -0
  94. package/skills/package-skills/brainspike/references/temporal-task-training.md +36 -0
  95. package/skills/package-skills/brainspike/scripts/advanced_native_patterns.py +76 -0
  96. package/skills/package-skills/brainspike/scripts/delay_workflow.py +44 -0
  97. package/skills/package-skills/brainspike/scripts/delayed_cue_training.py +78 -0
  98. package/skills/package-skills/brainspike/scripts/lif_smoke.py +31 -0
  99. package/skills/package-skills/brainspike/scripts/multiscale_workflow.py +35 -0
  100. package/skills/package-skills/brainspike/scripts/native_ei_network.py +47 -0
  101. package/skills/package-skills/brainspike/scripts/native_workflows.py +77 -0
  102. package/skills/package-skills/brainspike/scripts/nest_boundary_workflows.py +108 -0
  103. package/skills/package-skills/brainspike/scripts/train_native_snn.py +65 -0
  104. package/skills/package-skills/brainspike/scripts/train_nest_simulator.py +69 -0
  105. package/skills/package-skills/brainspike/scripts/train_nest_simulator_two_weights.py +220 -0
  106. package/skills/package-skills/brainstate/SKILL.md +16 -21
  107. package/skills/package-skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +1 -138
  108. package/skills/package-skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
  109. package/skills/package-skills/brainstate/references/brainstate/delay-buffers.md +45 -0
  110. package/skills/package-skills/brainstate/references/brainstate/parameter-constraints-regularization.md +9 -7
  111. package/skills/package-skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
  112. package/skills/package-skills/brainstate/references/brainstate/randomness-and-reproducibility.md +6 -4
  113. package/skills/package-skills/brainstate/references/brainstate/transformation-grad-expansion.md +4 -4
  114. package/skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md +1 -1
  115. package/skills/package-skills/brainstate/references/braintools-optimizer-reference.md +16 -0
  116. package/skills/package-skills/brainstate/references/libraries/prebuilt-layer-library.md +1 -1
  117. package/skills/package-skills/brainstate/references/simulation-environment.md +5 -5
  118. package/skills/package-skills/braintrace/SKILL.md +17 -38
  119. package/skills/package-skills/braintrace/references/Drtrl.md +9 -26
  120. package/skills/package-skills/braintrace/references/algorithm selection.md +7 -12
  121. package/skills/package-skills/braintrace/references/batching.md +15 -35
  122. package/skills/package-skills/braintrace/references/compiler_internal.md +1 -1
  123. package/skills/package-skills/braintrace/references/custom algorithms.md +1 -2
  124. package/skills/package-skills/braintrace/references/customizing_primitive_transforms.md +26 -15
  125. package/skills/package-skills/braintrace/references/pp_pprop workflow.md +5 -139
  126. package/skills/package-skills/brainunit/SKILL.md +7 -2
  127. package/skills/package-skills/brainunit/references/array-mechanics/functional-structural-api.md +1 -1
  128. package/skills/package-skills/brainunit/references/math-function-library.md +2 -2
  129. package/skills/package-skills/brainunit/references/typing-and-runtime-validation.md +5 -2
  130. package/skills/package-skills/brainevent/references/scripts/102_EI_net_1996.py +0 -107
  131. package/skills/package-skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +0 -168
  132. package/skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py +0 -356
  133. package/skills/package-skills/brainpy-state/SKILL.md +0 -247
  134. package/skills/package-skills/brainpy-state/references/array-creation.md +0 -158
  135. package/skills/package-skills/brainpy-state/references/brain-dynamics-delay-protocol.md +0 -147
  136. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/analysis.md +0 -150
  137. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +0 -373
  138. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -150
  139. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +0 -175
  140. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +0 -286
  141. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +0 -111
  142. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -163
  143. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -113
  144. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -136
  145. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -222
  146. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -123
  147. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +0 -107
  148. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -185
  149. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/integrators.md +0 -181
  150. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +0 -102
  151. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +0 -147
  152. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +0 -159
  153. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +0 -127
  154. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +0 -167
  155. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +0 -107
  156. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -186
  157. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +0 -104
  158. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +0 -89
  159. package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +0 -253
  160. package/skills/package-skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +0 -334
  161. package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +0 -206
  162. package/skills/package-skills/brainpy-state/references/braintools/data-preprocessing.md +0 -79
  163. package/skills/package-skills/brainpy-state/references/braintools/input-current.md +0 -199
  164. package/skills/package-skills/brainpy-state/references/braintools/metric.md +0 -152
  165. package/skills/package-skills/brainpy-state/references/braintools/optimizer.md +0 -179
  166. package/skills/package-skills/brainpy-state/references/braintools/parameter-initializer.md +0 -183
  167. package/skills/package-skills/brainpy-state/references/braintools/surrogate.md +0 -147
  168. package/skills/package-skills/brainpy-state/references/component-selection.md +0 -288
  169. package/skills/package-skills/brainpy-state/references/nest-compatible/model-library.md +0 -200
  170. package/skills/package-skills/brainpy-state/references/nest-compatible/nest-workflow.md +0 -156
  171. package/skills/package-skills/brainpy-state/references/nest-compatible/network-building.md +0 -264
  172. package/skills/package-skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +0 -153
  173. package/skills/package-skills/brainpy-state/references/projection-patterns.md +0 -127
  174. package/skills/package-skills/brainpy-state/references/scripts/103_COBA_2005.py +0 -86
  175. package/skills/package-skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +0 -181
  176. package/skills/package-skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +0 -156
  177. package/skills/package-skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +0 -111
  178. package/skills/package-skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -221
  179. package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +0 -240
  180. package/skills/package-skills/brainpy-state/references/scripts/training-snn.py +0 -119
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # BrainX Skill
6
6
 
7
- [![Supported BrainX release](https://img.shields.io/badge/BrainX-v2026.7.9-007EC6?style=flat)](skills/brainx-install/references/compatibility-and-release-matching.md#version-compatibility-matrix) [![License](https://img.shields.io/badge/License-Apache%202.0-4C1?style=flat)](LICENSE) [![npm downloads](https://img.shields.io/npm/dm/brainx-skill?label=npm&color=007EC6&style=flat)](https://www.npmjs.com/package/brainx-skill) [![Skills](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fchaobrain%2FBrainX-skill%2Fmain%2Fmanifest.json&query=%24.skills.length&label=Skills&color=007EC6&style=flat)](manifest.json) [![Agent Skills validation](https://img.shields.io/github/actions/workflow/status/chaobrain/BrainX-skill/agent-skills-validation.yml?branch=main&label=Agent%20Skills&style=flat)](https://github.com/chaobrain/BrainX-skill/actions/workflows/agent-skills-validation.yml) [![OpenSSF Scorecard](https://img.shields.io/ossf-scorecard/github.com/chaobrain/BrainX-skill?label=OpenSSF&style=flat)](https://scorecard.dev/viewer/?uri=github.com/chaobrain/BrainX-skill)
7
+ [![Target BrainX release](https://img.shields.io/badge/BrainX-v2026.10.25-007EC6?style=flat)](skills/brainx-install/references/compatibility-and-release-matching.md#version-compatibility-matrix) [![License](https://img.shields.io/badge/License-Apache%202.0-4C1?style=flat)](LICENSE) [![npm downloads](https://img.shields.io/npm/dm/brainx-skill?label=npm&color=007EC6&style=flat)](https://www.npmjs.com/package/brainx-skill) [![Skills](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fchaobrain%2FBrainX-skill%2Fmain%2Fmanifest.json&query=%24.skills.length&label=Skills&color=007EC6&style=flat)](manifest.json) [![Agent Skills validation](https://img.shields.io/github/actions/workflow/status/chaobrain/BrainX-skill/agent-skills-validation.yml?branch=main&label=Agent%20Skills&style=flat)](https://github.com/chaobrain/BrainX-skill/actions/workflows/agent-skills-validation.yml) [![OpenSSF Scorecard](https://img.shields.io/ossf-scorecard/github.com/chaobrain/BrainX-skill?label=OpenSSF&style=flat)](https://scorecard.dev/viewer/?uri=github.com/chaobrain/BrainX-skill)
8
8
 
9
9
  [![Works with Claude Code, Codex, Cursor, Windsurf, Gemini CLI, and OpenCode](https://img.shields.io/badge/Works%20with-Claude%20Code%20%7C%20Codex%20%7C%20Cursor%20%7C%20Windsurf%20%7C%20Gemini%20CLI%20%7C%20OpenCode-007EC6?style=flat)](#installation-locations)
10
10
 
@@ -14,6 +14,22 @@ make your coding agent understand the power of BrainX
14
14
 
15
15
  - Node.js 18 or newer
16
16
  - macOS, Linux, or Windows
17
+
18
+ The current examples target BrainX `2026.10.25` with Python 3.12 or newer.
19
+ Use the original skill snapshot and runtime to reproduce earlier evaluations.
20
+
21
+ Use the [BrainSpike skill](skills/package-skills/brainspike/SKILL.md) for point-neuron models. Install the Python distribution as `brainspikes` and import `brainspike`. The BrainX release still includes BrainPy at runtime; earlier skill snapshots retain the BrainPy-State guidance.
22
+
23
+ From the checkout, run the single-neuron CPU smoke test in an environment with
24
+ the pinned BrainX release:
25
+
26
+ ```bash
27
+ python skills/package-skills/brainspike/scripts/lif_smoke.py
28
+ ```
29
+
30
+ The test checks that a 500 pA current drives the LIF neuron to fire and that
31
+ 100 ms of simulation produces a `(1000, 1)` spike recording.
32
+
17
33
  ## Install
18
34
 
19
35
  ```bash
@@ -4,6 +4,7 @@ const childProcess = require('node:child_process');
4
4
  const fs = require('node:fs/promises');
5
5
  const os = require('node:os');
6
6
  const path = require('node:path');
7
+ const { codexInvocation, npmInvocation } = require('../../mcp-servers/codex/cli-invocation.cjs');
7
8
 
8
9
  const EUROPE_PMC_NAME = 'europepmc';
9
10
  const FULLTEXT_NAME = 'fulltext_resolver';
@@ -483,13 +484,18 @@ async function runLiteratureMcp(command, options = {}) {
483
484
  const pathApi = options.pathApi || path;
484
485
  const homeDir = options.homeDir || os.homedir();
485
486
  const packageRoot = options.packageRoot || path.resolve(__dirname, '../..');
486
- const runner = options.runner || defaultRunner;
487
487
  const stdout = options.stdout || process.stdout;
488
488
  const stderr = options.stderr || process.stderr;
489
489
  const codexBin = options.codexBin || 'codex';
490
490
  const npmBin = options.npmBin || 'npm';
491
491
  const uvBin = options.uvBin || 'uv';
492
492
  const platform = options.platform || process.platform;
493
+ const runner = options.runner || ((binary, args, runOptions) => {
494
+ let invocation = { binary, prefixArgs: args };
495
+ if (binary === codexBin) invocation = codexInvocation(binary, args);
496
+ if (binary === npmBin) invocation = npmInvocation(binary, args);
497
+ return defaultRunner(invocation.binary, invocation.prefixArgs, runOptions);
498
+ });
493
499
  const paths = runtimePaths(homeDir, pathApi, platform);
494
500
  const expected = expectedServers(paths, options.nodeBin || process.execPath);
495
501
 
package/manifest.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "brainunit",
13
13
  "brainstate",
14
14
  "brainevent",
15
- "brainpy-state",
15
+ "brainspike",
16
16
  "braintrace"
17
17
  ]
18
18
  }
@@ -1,24 +1,34 @@
1
1
  # BrainX Codex MCP server
2
2
 
3
- This server preserves the open-source Codex CLI MCP implementation while specializing fresh sessions for independent BrainX scientific review. It delegates execution and persistence to `codex mcp-server`, so `codex-reply` continues the same native thread with its existing context.
4
-
5
- The proxy changes only fresh `codex` calls:
6
-
7
- - `base-instructions` receives `system-prompt.md`;
8
- - `developer-instructions` identifies the allowed BrainX domain skills and the
9
- exact training and fitting review-reference paths;
10
- - `skills.config` exposes the skill directories listed in `skills.json`.
11
-
12
- The modeling-loop skill is not exposed to the reviewer. The reviewer opens only
13
- `training-workflow.md` and/or `parameter-fitting-workflow.md` when the supplied
14
- `ACTIVE_COVERAGE` requires them.
15
-
16
- All `codex-reply` calls and other MCP messages pass through unchanged.
3
+ This adapter exposes the `codex` and `codex-reply` MCP tools for independent
4
+ BrainX scientific review and runs them through `codex app-server --listen
5
+ stdio://`. Codex owns native thread history and persistence; the adapter returns
6
+ the completed Markdown report and native thread ID to the MCP caller.
7
+
8
+ Use `codex` for a fresh thread and `codex-reply` for `thread/resume` followed by
9
+ another turn in that thread, including after the adapter restarts. Both paths
10
+ enforce the BrainX system prompt, allowed skills, `read-only` sandbox and
11
+ `never` approval policy. Caller settings cannot replace these constraints.
12
+ The reviewer disables the MCP registrations in the effective workspace
13
+ configuration to prevent recursive startup. Tool callers cannot add MCP
14
+ registrations through `config`. When the host uses a custom `CODEX_HOME` or
15
+ environment credentials, list those variable names in the MCP registration's
16
+ `env_vars`; the Codex MCP host filters unlisted environment variables.
17
+
18
+ `system-prompt.md` supplies the scientific review contract. `skills.json` selects
19
+ the exposed domain skills. The developer instructions identify the exact
20
+ training and fitting review references; the modeling-loop workflow itself is
21
+ not exposed as a reviewer skill.
22
+
23
+ The adapter waits for native turn completion, excludes commentary from the
24
+ report, surfaces failed/interrupted/empty turns as MCP tool errors, and
25
+ translates MCP cancellation to `turn/interrupt`. Interactive approval requests
26
+ are declined; unsupported interactive requests return protocol errors.
17
27
 
18
28
  ## Requirements
19
29
 
20
30
  - Node.js 18 or later
21
- - Codex CLI with `codex mcp-server` support
31
+ - Codex CLI with App Server stdio support (tested on 0.166.0 and 0.170.0)
22
32
  - a working Codex login
23
33
 
24
34
  ## Register
@@ -58,11 +68,13 @@ review commonly exceeds Codex's default MCP tool-call budget; when the host
58
68
  cancels that call, the caller may report `user cancelled MCP tool call` even
59
69
  though no user cancelled it.
60
70
 
61
- The proxy forces fresh reviews to `sandbox = "read-only"` and
62
- `approval-policy = "never"` before forwarding them upstream. Auto-approving the
63
- MCP tool therefore does not grant the reviewer write access or command approval.
71
+ The adapter forces fresh and resumed reviews to `sandbox = "read-only"` and
72
+ `approvalPolicy = "never"`. Auto-approving the MCP tool does not grant the
73
+ reviewer write access or command approval.
64
74
 
65
75
  Set `BRAINX_CODEX_BIN` only when `codex` is not on `PATH` for the MCP host.
76
+ On Windows, npm `.cmd`/`.ps1` shims resolve to the package JavaScript entry and
77
+ run through Node without a shell. Custom wrappers should expose an executable.
66
78
 
67
79
  ## Use
68
80
 
@@ -70,13 +82,27 @@ Start a review with `mcp__codex__codex`. Its returned `content` is the reviewer
70
82
  response available to the calling agent in the same turn. The response is a
71
83
  complete Markdown document; the reviewer remains read-only and does not create
72
84
  the file. The calling modeling agent saves `content` verbatim as
73
- `reviews/iteration-<N>.md`, records that path and the returned `threadId`, and
85
+ `reviews/iteration-<N>.md`, records that path and `structuredContent.threadId`, and
74
86
  uses `codex-reply` only for a follow-up that must continue the reviewer's context.
75
87
 
88
+ The successful tool result contains `content: [{type: "text", text: report}]`
89
+ and `structuredContent: {threadId, content: report}`. `codex-reply` accepts
90
+ `{threadId, prompt}`. Fresh calls accept `prompt`, optional `model`, `cwd`, and
91
+ `config`; the former `profile` option now returns an explicit unsupported-option
92
+ error. Review constraints always override legacy instruction/permission options.
93
+
76
94
  Edit `system-prompt.md` to change the reviewer contract. Edit `skills.json` to change the BrainX skills exposed to fresh reviewer sessions.
77
95
 
78
96
  ## Verify
79
97
 
80
98
  ```bash
81
- node --test mcp-servers/codex/test/*.test.mjs
99
+ npm test
100
+ node .github/scripts/smoke-reviewer.mjs
82
101
  ```
102
+
103
+ The transport is dependency-free and uses JSONL stdio on both sides. MCP
104
+ `initialize` initializes the real App Server before advertising the tools.
105
+ The smoke test uses a real Codex CLI, an isolated Codex home and a loopback
106
+ Responses fixture. It verifies the handshake, a fresh review, and continued
107
+ history after restarting the reviewer. Run `npm install` first. Pass a path to
108
+ an extracted package's `server.mjs` to verify the shipped files.
@@ -1,22 +1,26 @@
1
1
  # Upstream provenance
2
2
 
3
- The linked ARIS repository registers the Codex CLI directly:
3
+ The original reviewer forwarded the now-removed `codex mcp-server` command.
4
+ The current implementation exposes the same MCP tool names through a BrainX
5
+ adapter backed by the native Codex App Server stdio protocol.
4
6
 
5
- ```bash
6
- claude mcp add codex -s user -- codex mcp-server
7
- ```
7
+ Verified against CLI 0.166.0 and 0.170.0:
8
8
 
9
- This proxy delegates to that same command. Its tool schemas, native thread creation, persistence, event handling, and `codex-reply` continuation remain implemented by OpenAI Codex.
10
-
11
- Upstream inspected on 2026-08-23:
12
-
13
- - Repository: <https://github.com/openai/codex>
14
- - Revision: `83d1fe0e67b1323f71febc2925817732b449f1d9`
15
- - MCP configuration and schemas: `codex-rs/mcp-server/src/codex_tool_config.rs`
16
- - Session and reply execution: `codex-rs/mcp-server/src/codex_tool_runner.rs`
17
- - JSON-RPC dispatch: `codex-rs/mcp-server/src/message_processor.rs`
9
+ - Official protocol: https://learn.chatgpt.com/docs/app-server
10
+ - Removed command: https://learn.chatgpt.com/docs/developer-commands
11
+ - Version-specific schema: `codex app-server generate-json-schema --out <directory>`
12
+ - Upstream implementation: https://github.com/openai/codex/tree/main/codex-rs/app-server
18
13
  - License: Apache-2.0, the same license used by this repository
19
14
 
20
- Modified behavior is confined to `server.mjs`: fresh `codex` tool calls receive
21
- the BrainX system prompt and skill configuration and are forced to read-only,
22
- no-approval execution before being forwarded upstream.
15
+ `app-server.mjs` implements JSONL requests and native turn-event handling.
16
+ `server.mjs` owns the MCP tool schemas, maps fresh reviews to `thread/start`,
17
+ maps continuation to `thread/resume`, and maps review prompts to `turn/start`.
18
+ Codex retains responsibility for model execution, thread persistence and
19
+ history. The adapter injects BrainX instructions and skill configuration,
20
+ enforces read-only/no-approval execution, prevents recursive reviewer startup,
21
+ returns completed assistant reports, and forwards cancellation to
22
+ `turn/interrupt`. It does not copy or recreate Codex's execution engine.
23
+
24
+ The repository smoke test checks native-thread behavior against the real App
25
+ Server with a local Responses fixture. It verifies persisted-thread resume
26
+ after restarting the adapter without calling a hosted model.
@@ -0,0 +1,177 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { createInterface } from 'node:readline';
3
+ import cliInvocation from './cli-invocation.cjs';
4
+
5
+ const { codexInvocation } = cliInvocation;
6
+
7
+ // App Server owns native threads and persistence. This client translates only
8
+ // transport, turn completion and cancellation; it never reconstructs history.
9
+ export class AppServerClient {
10
+ constructor({ binary = process.env.BRAINX_CODEX_BIN || 'codex', prefixArgs = [],
11
+ timeoutMs = 30 * 60 * 1000 } = {}) {
12
+ this.binary = binary;
13
+ this.prefixArgs = prefixArgs;
14
+ this.timeoutMs = timeoutMs;
15
+ this.pending = new Map();
16
+ this.turns = new Map();
17
+ this.nextId = 1;
18
+ }
19
+
20
+ initialize() {
21
+ if (!this.ready) this.ready = this.connect();
22
+ return this.ready;
23
+ }
24
+
25
+ async connect() {
26
+ const invocation = codexInvocation(this.binary, this.prefixArgs);
27
+ this.child = spawn(invocation.binary, [...invocation.prefixArgs, 'app-server', '--listen', 'stdio://'], {
28
+ env: process.env, stdio: ['pipe', 'pipe', 'inherit'],
29
+ });
30
+ this.child.on('error', (error) => this.fail(new Error(`Cannot start Codex App Server: ${error.message}`)));
31
+ this.child.on('exit', () => this.fail(new Error('Codex App Server exited. Check that the CLI supports codex app-server.')));
32
+ this.child.stdin.on('error', () => this.fail(new Error('Codex App Server input closed')));
33
+ this.lines = createInterface({ input: this.child.stdout, crlfDelay: Infinity });
34
+ this.lines.on('line', (line) => {
35
+ try { this.receive(JSON.parse(line)); }
36
+ catch { this.fail(new Error('Invalid Codex App Server response')); }
37
+ });
38
+ await this.request('initialize', {
39
+ clientInfo: { name: 'brainx_reviewer', title: 'BrainX reviewer', version: '2.0.0' },
40
+ }, 20_000);
41
+ this.send({ method: 'initialized', params: {} });
42
+ this.mcpServerNames = await this.readMcpServerNames();
43
+ }
44
+
45
+ async readMcpServerNames(cwd) {
46
+ const { config } = await this.request('config/read', { cwd, includeLayers: false }, 20_000);
47
+ return Object.keys(config.mcp_servers || {});
48
+ }
49
+
50
+ send(message) {
51
+ if (this.failure) throw this.failure;
52
+ this.child.stdin.write(`${JSON.stringify(message)}\n`);
53
+ }
54
+
55
+ request(method, params, timeoutMs = this.timeoutMs) {
56
+ if (this.failure) return Promise.reject(this.failure);
57
+ const id = this.nextId++;
58
+ return new Promise((resolve, reject) => {
59
+ const timer = setTimeout(() => {
60
+ this.pending.delete(id);
61
+ reject(new Error(`Codex App Server timed out: ${method}`));
62
+ }, timeoutMs);
63
+ this.pending.set(id, { resolve, reject, timer });
64
+ try { this.send({ id, method, params }); }
65
+ catch (error) { clearTimeout(timer); this.pending.delete(id); reject(error); }
66
+ });
67
+ }
68
+
69
+ receive(message) {
70
+ if (message.method && message.id !== undefined) {
71
+ // The reviewer never approves commands, file changes or permission
72
+ // escalation. Unknown server requests fail explicitly instead of hanging.
73
+ if (['item/commandExecution/requestApproval', 'item/fileChange/requestApproval'].includes(message.method)) {
74
+ this.send({ id: message.id, result: { decision: 'decline' } });
75
+ } else {
76
+ this.send({ id: message.id, error: { code: -32601, message: 'Reviewer does not support interactive requests' } });
77
+ }
78
+ return;
79
+ }
80
+ if (message.id !== undefined) {
81
+ const pending = this.pending.get(message.id);
82
+ if (!pending) return;
83
+ this.pending.delete(message.id);
84
+ clearTimeout(pending.timer);
85
+ if (message.error) pending.reject(new Error(message.error.message || 'Codex App Server request failed'));
86
+ else pending.resolve(message.result);
87
+ return;
88
+ }
89
+ const turn = this.turns.get(message.params?.threadId);
90
+ if (turn) {
91
+ if (!turn.id) turn.buffer.push(message);
92
+ else this.turnEvent(turn, message);
93
+ }
94
+ }
95
+
96
+ turnEvent(turn, { method, params }) {
97
+ if (params.turnId !== turn.id && params.turn?.id !== turn.id) return;
98
+ if (method === 'item/completed' && params.item?.type === 'agentMessage'
99
+ && params.item.phase !== 'commentary') {
100
+ turn.messages.set(params.item.id, params.item.text);
101
+ }
102
+ if (method === 'turn/completed') {
103
+ if (params.turn.status !== 'completed') {
104
+ turn.reject(new Error(params.turn.error?.message || `Review turn ${params.turn.status}`));
105
+ } else {
106
+ const text = [...turn.messages.values()].join('\n\n');
107
+ if (!text.trim()) turn.reject(new Error('Reviewer completed without a report'));
108
+ else turn.resolve(text);
109
+ }
110
+ }
111
+ }
112
+
113
+ async runTurn(threadId, prompt, signal) {
114
+ if (signal?.aborted) throw new Error('Review cancelled');
115
+ if (this.turns.has(threadId)) throw new Error('A review is already active on this thread');
116
+ const turn = { buffer: [], messages: new Map() };
117
+ const completion = new Promise((resolve, reject) => Object.assign(turn, { resolve, reject }));
118
+ // A process exit may reject completion while turn/start is still pending.
119
+ completion.catch(() => {});
120
+ this.turns.set(threadId, turn);
121
+ const interrupt = () => {
122
+ if (turn.id) this.request('turn/interrupt', { threadId, turnId: turn.id }, 10_000)
123
+ .catch(() => turn.reject(new Error('Review cancellation failed')));
124
+ };
125
+ const abort = () => {
126
+ interrupt();
127
+ turn.cancelTimer = setTimeout(() => {
128
+ this.fail(new Error('Review cancellation timed out'));
129
+ this.child.kill();
130
+ }, 10_000);
131
+ };
132
+ signal?.addEventListener('abort', abort, { once: true });
133
+ const timer = setTimeout(() => {
134
+ interrupt();
135
+ this.fail(new Error('Review turn timed out'));
136
+ this.child.kill();
137
+ }, this.timeoutMs);
138
+ try {
139
+ const result = await this.request('turn/start', {
140
+ threadId, input: [{ type: 'text', text: prompt, text_elements: [] }],
141
+ approvalPolicy: 'never',
142
+ });
143
+ turn.id = result.turn.id;
144
+ for (const message of turn.buffer) this.turnEvent(turn, message);
145
+ turn.buffer = [];
146
+ if (signal?.aborted) interrupt();
147
+ return await completion;
148
+ } finally {
149
+ clearTimeout(timer);
150
+ clearTimeout(turn.cancelTimer);
151
+ signal?.removeEventListener('abort', abort);
152
+ this.turns.delete(threadId);
153
+ }
154
+ }
155
+
156
+ fail(error) {
157
+ this.failure ||= error;
158
+ for (const pending of this.pending.values()) {
159
+ clearTimeout(pending.timer);
160
+ pending.reject(this.failure);
161
+ }
162
+ this.pending.clear();
163
+ for (const turn of this.turns.values()) turn.reject(this.failure);
164
+ }
165
+
166
+ close() {
167
+ this.fail(new Error('Reviewer connection closed'));
168
+ this.lines?.close();
169
+ const child = this.child;
170
+ if (!child || child.exitCode !== null || child.signalCode !== null) return;
171
+ // Let the CLI exit on EOF. An npm shim can have a native child of its own.
172
+ child.stdin.end();
173
+ const timer = setTimeout(() => child.kill(), 2_000);
174
+ timer.unref();
175
+ child.once('close', () => clearTimeout(timer));
176
+ }
177
+ }
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ const { existsSync } = require('node:fs');
4
+ const { win32 } = require('node:path');
5
+
6
+ function windowsInvocation(binary, args, packageEntry, { pathValue, exists }) {
7
+ let executable = binary;
8
+ if (!/[\\/]/.test(binary)) {
9
+ const names = win32.extname(binary) ? [binary] : [`${binary}.exe`, `${binary}.cmd`, binary];
10
+ for (const directory of pathValue.split(';')) {
11
+ const candidate = names.map((name) => win32.join(directory.replace(/^"|"$/g, ''), name)).find(exists);
12
+ if (candidate) {
13
+ executable = candidate;
14
+ break;
15
+ }
16
+ }
17
+ }
18
+ if (!/\.(cmd|bat|ps1)$/i.test(executable)) return { binary: executable, prefixArgs: args };
19
+
20
+ const directory = win32.dirname(executable);
21
+ const modules = win32.basename(directory) === '.bin'
22
+ ? win32.dirname(directory) : win32.join(directory, 'node_modules');
23
+ const entry = win32.join(modules, ...packageEntry);
24
+ if (!exists(entry)) throw new Error(`Cannot find the JavaScript entry for ${executable}. Use the installed executable or a standard npm shim.`);
25
+ return { binary: process.execPath, prefixArgs: [entry, ...args] };
26
+ }
27
+
28
+ function codexInvocation(binary, prefixArgs = [], {
29
+ platform = process.platform, pathValue = process.env.PATH || '', exists = existsSync,
30
+ } = {}) {
31
+ if (platform !== 'win32') return { binary, prefixArgs };
32
+ try {
33
+ return windowsInvocation(binary, prefixArgs, ['@openai', 'codex', 'bin', 'codex.js'], { pathValue, exists });
34
+ } catch (error) {
35
+ throw new Error(`${error.message} Set BRAINX_CODEX_BIN to a supported Codex executable.`, { cause: error });
36
+ }
37
+ }
38
+
39
+ function npmInvocation(binary, prefixArgs, {
40
+ platform = process.platform, pathValue = process.env.PATH || '', exists = existsSync,
41
+ npmExecPath = process.env.npm_execpath,
42
+ } = {}) {
43
+ if (platform !== 'win32') return { binary, prefixArgs };
44
+ if (binary === 'npm' && npmExecPath && win32.basename(npmExecPath) === 'npm-cli.js' && exists(npmExecPath)) {
45
+ return { binary: process.execPath, prefixArgs: [npmExecPath, ...prefixArgs] };
46
+ }
47
+ return windowsInvocation(binary, prefixArgs, ['npm', 'bin', 'npm-cli.js'], { pathValue, exists });
48
+ }
49
+
50
+ module.exports = { codexInvocation, npmInvocation };