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.
- package/README.md +17 -1
- package/installation/lib/literature-mcp.js +7 -1
- package/manifest.json +1 -1
- package/mcp-servers/codex/README.md +46 -20
- package/mcp-servers/codex/UPSTREAM.md +20 -16
- package/mcp-servers/codex/app-server.mjs +177 -0
- package/mcp-servers/codex/cli-invocation.cjs +50 -0
- package/mcp-servers/codex/server.mjs +136 -69
- package/mcp-servers/codex/skills.json +1 -1
- package/mcp-servers/codex/test/fixtures/fake-codex.mjs +80 -3
- package/mcp-servers/codex/test/fixtures/run-server.mjs +7 -0
- package/mcp-servers/codex/test/server.test.mjs +188 -84
- package/package.json +1 -1
- package/skills/bio-neuro-lit/SKILL.md +4 -2
- package/skills/bio-neuro-lit/references/required-supplements.md +27 -0
- package/skills/brainx-acceleration/SKILL.md +30 -437
- package/skills/brainx-acceleration/references/audit-and-rewrite-patterns.md +326 -0
- package/skills/brainx-general-guard/SKILL.md +24 -8
- package/skills/brainx-install/SKILL.md +3 -3
- package/skills/brainx-install/references/compatibility-and-release-matching.md +28 -20
- package/skills/brainx-install/references/uninstall-and-cleanup.md +11 -4
- package/skills/brainx-modeling-loop/SKILL.md +117 -36
- package/skills/brainx-modeling-loop/agents/openai.yaml +2 -2
- package/skills/brainx-modeling-loop/references/mechanism-comparison.md +62 -0
- package/skills/brainx-modeling-loop/references/multiscale-coupling.md +16 -0
- package/skills/brainx-modeling-loop/references/paper-reproduction.md +42 -0
- package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +14 -14
- package/skills/brainx-modeling-loop/references/run-experiment.md +1 -1
- package/skills/brainx-modeling-loop/references/training-workflow.md +10 -8
- package/skills/brainx-visualization/SKILL.md +6 -2
- package/skills/brainx-visualization/references/neural-data-visualization.md +1 -1
- package/skills/brainx-visualization/references/statistical-and-model-visualization.md +1 -1
- package/skills/package-skills/braincell/SKILL.md +23 -14
- package/skills/package-skills/braincell/references/braintools/input-current.md +1 -1
- package/skills/package-skills/braincell/references/braintools/metric.md +72 -46
- package/skills/package-skills/braincell/references/mixions-for-adaptation.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/braincell-manual-morphology-construction.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/cv-policy-reference.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/filter-function-library.md +3 -3
- package/skills/package-skills/braincell/references/multicompartment/morphology-io-loading-validation.md +1 -1
- package/skills/package-skills/braincell/references/multicompartment/multicompartment-cell-workflow.md +31 -43
- package/skills/package-skills/braincell/references/multicompartment/network-workflow.md +49 -0
- package/skills/package-skills/braincell/references/multicompartment/probe-reference.md +26 -114
- package/skills/package-skills/braincell/references/multicompartment/topology-building-and-visualization.md +40 -28
- package/skills/package-skills/braincell/references/scripts/cell_multicompartment_reference.py +13 -17
- package/skills/package-skills/brainevent/SKILL.md +0 -3
- package/skills/package-skills/brainevent/references/synaptic-plasticity.md +1 -1
- package/skills/package-skills/brainmass/SKILL.md +5 -3
- package/skills/package-skills/brainmass/references/brainstate/parameter-constraints-regularization.md +9 -7
- package/skills/package-skills/brainmass/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
- package/skills/package-skills/brainmass/references/braintools/data-preprocessing.md +15 -7
- package/skills/package-skills/brainmass/references/braintools/metric.md +72 -46
- package/skills/package-skills/brainmass/references/coupling-network-api.md +3 -1
- package/skills/package-skills/brainmass/references/fitting-with-objectives-api.md +6 -6
- package/skills/package-skills/brainmass/references/horn-task-training.md +9 -9
- package/skills/package-skills/brainmass/references/modellibrary.md +12 -10
- package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +5 -3
- package/skills/package-skills/brainmass/references/scripts/wilson-cowan-ei-dynamics.py +10 -6
- package/skills/package-skills/brainmass/references/simulator-input-monitor-api.md +3 -1
- package/skills/package-skills/brainmass/references/visualization-analysis-api.md +17 -9
- package/skills/package-skills/brainspike/SKILL.md +201 -0
- package/skills/package-skills/brainspike/references/braintools/connectivity.md +40 -0
- package/skills/package-skills/brainspike/references/braintools/data-preprocessing.md +39 -0
- package/skills/package-skills/brainspike/references/braintools/input-current.md +55 -0
- package/skills/package-skills/brainspike/references/braintools/metric.md +36 -0
- package/skills/package-skills/brainspike/references/braintools/optimizer.md +50 -0
- package/skills/package-skills/brainspike/references/braintools/parameter-initializer.md +43 -0
- package/skills/package-skills/brainspike/references/braintools/surrogate.md +40 -0
- package/skills/package-skills/brainspike/references/migration-boundary.md +38 -0
- package/skills/package-skills/brainspike/references/model-and-readout-selection.md +41 -0
- package/skills/package-skills/brainspike/references/multirate-coupling.md +31 -0
- package/skills/package-skills/brainspike/references/multiscale-composition.md +28 -0
- package/skills/package-skills/brainspike/references/native-composition.md +52 -0
- package/skills/package-skills/brainspike/references/native-delays.md +34 -0
- package/skills/package-skills/brainspike/references/native-projections.md +43 -0
- package/skills/package-skills/brainspike/references/native-training.md +36 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/devices.md +33 -33
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/divergence-and-parity.md +15 -15
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/integration-categories.md +1 -1
- package/skills/package-skills/brainspike/references/nest-compatible/model-library.md +200 -0
- package/skills/package-skills/brainspike/references/nest-compatible/network-building.md +276 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brette_et_al_2007.py +23 -26
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_alpha.py +18 -21
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/brunel_delta.py +16 -19
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/clopath_synapse_spike_pairing.py +11 -12
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/evaluate_tsodyks2_synapse.py +10 -11
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/spatial_gaussex.py +18 -18
- package/skills/package-skills/{brainpy-state → brainspike}/references/nest-compatible/scripts/synapsecollection.py +26 -29
- package/skills/package-skills/brainspike/references/nest-compatible/synapse-and-connectivity.md +166 -0
- package/skills/package-skills/brainspike/references/nest-delay-boundaries.md +31 -0
- package/skills/package-skills/brainspike/references/nonlinear-state-sharing.md +26 -0
- package/skills/package-skills/{brainpy-state → brainspike}/references/perturbation-experiment-validity.md +2 -2
- package/skills/package-skills/brainspike/references/simulator-training.md +61 -0
- package/skills/package-skills/brainspike/references/temporal-task-training.md +36 -0
- package/skills/package-skills/brainspike/scripts/advanced_native_patterns.py +76 -0
- package/skills/package-skills/brainspike/scripts/delay_workflow.py +44 -0
- package/skills/package-skills/brainspike/scripts/delayed_cue_training.py +78 -0
- package/skills/package-skills/brainspike/scripts/lif_smoke.py +31 -0
- package/skills/package-skills/brainspike/scripts/multiscale_workflow.py +35 -0
- package/skills/package-skills/brainspike/scripts/native_ei_network.py +47 -0
- package/skills/package-skills/brainspike/scripts/native_workflows.py +77 -0
- package/skills/package-skills/brainspike/scripts/nest_boundary_workflows.py +108 -0
- package/skills/package-skills/brainspike/scripts/train_native_snn.py +65 -0
- package/skills/package-skills/brainspike/scripts/train_nest_simulator.py +69 -0
- package/skills/package-skills/brainspike/scripts/train_nest_simulator_two_weights.py +220 -0
- package/skills/package-skills/brainstate/SKILL.md +16 -21
- package/skills/package-skills/brainstate/references/brainstate/brainstate-control-flow-patterns.md +1 -138
- package/skills/package-skills/brainstate/references/brainstate/brainstate-transformed-diagnostics.md +1 -1
- package/skills/package-skills/brainstate/references/brainstate/delay-buffers.md +45 -0
- package/skills/package-skills/brainstate/references/brainstate/parameter-constraints-regularization.md +9 -7
- package/skills/package-skills/brainstate/references/brainstate/parameter-transforms-regularizers-catalog.md +4 -4
- package/skills/package-skills/brainstate/references/brainstate/randomness-and-reproducibility.md +6 -4
- package/skills/package-skills/brainstate/references/brainstate/transformation-grad-expansion.md +4 -4
- package/skills/package-skills/brainstate/references/brainstate/transformation-vmap-expansion.md +1 -1
- package/skills/package-skills/brainstate/references/braintools-optimizer-reference.md +16 -0
- package/skills/package-skills/brainstate/references/libraries/prebuilt-layer-library.md +1 -1
- package/skills/package-skills/brainstate/references/simulation-environment.md +5 -5
- package/skills/package-skills/braintrace/SKILL.md +17 -38
- package/skills/package-skills/braintrace/references/Drtrl.md +9 -26
- package/skills/package-skills/braintrace/references/algorithm selection.md +7 -12
- package/skills/package-skills/braintrace/references/batching.md +15 -35
- package/skills/package-skills/braintrace/references/compiler_internal.md +1 -1
- package/skills/package-skills/braintrace/references/custom algorithms.md +1 -2
- package/skills/package-skills/braintrace/references/customizing_primitive_transforms.md +26 -15
- package/skills/package-skills/braintrace/references/pp_pprop workflow.md +5 -139
- package/skills/package-skills/brainunit/SKILL.md +7 -2
- package/skills/package-skills/brainunit/references/array-mechanics/functional-structural-api.md +1 -1
- package/skills/package-skills/brainunit/references/math-function-library.md +2 -2
- package/skills/package-skills/brainunit/references/typing-and-runtime-validation.md +5 -2
- package/skills/package-skills/brainevent/references/scripts/102_EI_net_1996.py +0 -107
- package/skills/package-skills/brainevent/references/scripts/204_joglekar_2018_propagation.py +0 -168
- package/skills/package-skills/brainevent/references/scripts/coba_ei_teaching.py +0 -356
- package/skills/package-skills/brainpy-state/SKILL.md +0 -247
- package/skills/package-skills/brainpy-state/references/array-creation.md +0 -158
- package/skills/package-skills/brainpy-state/references/brain-dynamics-delay-protocol.md +0 -147
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/analysis.md +0 -150
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/brainpy legacy workflow.md +0 -373
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/built-in dynamic neuron model.md +0 -150
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/connecting neurons.md +0 -175
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/customize neuron and synpase.md +0 -286
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Input generation.md +0 -111
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/More about simulation.md +0 -163
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Multi-device array sharding.md +0 -113
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/Parallel experiment execution.md +0 -136
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/array creation and mechanics.md +0 -222
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/brainpy math environment setting.md +0 -123
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/delays.md +0 -107
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/infrastructure/object oriented transformations and control flows.md +0 -185
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/integrators.md +0 -181
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/route activity through connectivity.md +0 -102
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synaptic projections.md +0 -147
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/synpase properties.md +0 -159
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/loss library.md +0 -127
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/optimizers.md +0 -167
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/parameter initializers.md +0 -107
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/prebuilt neural network layers.md +0 -186
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/surrogate gradients.md +0 -104
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainer library.md +0 -89
- package/skills/package-skills/brainpy-state/references/brainPy(legacy)/training/trainingworkflows.md +0 -253
- package/skills/package-skills/brainpy-state/references/braintools/brainstate-control-flow-patterns.md +0 -334
- package/skills/package-skills/brainpy-state/references/braintools/connectivity.md +0 -206
- package/skills/package-skills/brainpy-state/references/braintools/data-preprocessing.md +0 -79
- package/skills/package-skills/brainpy-state/references/braintools/input-current.md +0 -199
- package/skills/package-skills/brainpy-state/references/braintools/metric.md +0 -152
- package/skills/package-skills/brainpy-state/references/braintools/optimizer.md +0 -179
- package/skills/package-skills/brainpy-state/references/braintools/parameter-initializer.md +0 -183
- package/skills/package-skills/brainpy-state/references/braintools/surrogate.md +0 -147
- package/skills/package-skills/brainpy-state/references/component-selection.md +0 -288
- package/skills/package-skills/brainpy-state/references/nest-compatible/model-library.md +0 -200
- package/skills/package-skills/brainpy-state/references/nest-compatible/nest-workflow.md +0 -156
- package/skills/package-skills/brainpy-state/references/nest-compatible/network-building.md +0 -264
- package/skills/package-skills/brainpy-state/references/nest-compatible/synapse-and-connectivity.md +0 -153
- package/skills/package-skills/brainpy-state/references/projection-patterns.md +0 -127
- package/skills/package-skills/brainpy-state/references/scripts/103_COBA_2005.py +0 -86
- package/skills/package-skills/brainpy-state/references/scripts/106_COBA_HH_2007.py +0 -181
- package/skills/package-skills/brainpy-state/references/scripts/107_gamma_oscillation_1996.py +0 -156
- package/skills/package-skills/brainpy-state/references/scripts/109_fast_global_oscillation.py +0 -111
- package/skills/package-skills/brainpy-state/references/scripts/201_surrogate_grad_lif_fashion_mnist.py +0 -221
- package/skills/package-skills/brainpy-state/references/scripts/sound_localization.py +0 -240
- package/skills/package-skills/brainpy-state/references/scripts/training-snn.py +0 -119
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { spawn } from 'node:child_process';
|
|
4
3
|
import { readFileSync } from 'node:fs';
|
|
5
4
|
import { dirname, resolve } from 'node:path';
|
|
6
5
|
import { createInterface } from 'node:readline';
|
|
7
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
+
import { AppServerClient } from './app-server.mjs';
|
|
8
8
|
|
|
9
9
|
const serverDirectory = dirname(fileURLToPath(import.meta.url));
|
|
10
10
|
const repositoryRoot = resolve(serverDirectory, '../..');
|
|
@@ -62,81 +62,148 @@ const skillInstructions = [
|
|
|
62
62
|
`FITTING_REVIEW_REFERENCE: ${reviewReferences.fitting}`,
|
|
63
63
|
].join('\n');
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const originalArguments = message.params.arguments;
|
|
79
|
-
const args = originalArguments && typeof originalArguments === 'object'
|
|
80
|
-
? { ...originalArguments }
|
|
81
|
-
: {};
|
|
82
|
-
const config = args.config && typeof args.config === 'object'
|
|
83
|
-
? { ...args.config }
|
|
84
|
-
: {};
|
|
85
|
-
|
|
86
|
-
config['skills.config'] = exposedSkills;
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
...message,
|
|
90
|
-
params: {
|
|
91
|
-
...message.params,
|
|
92
|
-
arguments: {
|
|
93
|
-
...args,
|
|
94
|
-
config,
|
|
95
|
-
'approval-policy': 'never',
|
|
96
|
-
'base-instructions': systemPrompt,
|
|
97
|
-
'developer-instructions': skillInstructions,
|
|
98
|
-
sandbox: 'read-only',
|
|
65
|
+
const tools = [
|
|
66
|
+
{
|
|
67
|
+
name: 'codex', description: 'Start an independent read-only BrainX scientific review.',
|
|
68
|
+
inputSchema: {
|
|
69
|
+
type: 'object', required: ['prompt'], additionalProperties: false,
|
|
70
|
+
properties: {
|
|
71
|
+
prompt: { type: 'string' }, model: { type: 'string' }, cwd: { type: 'string' },
|
|
72
|
+
config: { type: 'object', additionalProperties: true },
|
|
73
|
+
'approval-policy': { type: 'string', description: 'Ignored: reviews always use never.' },
|
|
74
|
+
sandbox: { type: 'string', description: 'Ignored: reviews always use read-only.' },
|
|
75
|
+
'base-instructions': { type: 'string', description: 'Ignored: the BrainX reviewer contract is mandatory.' },
|
|
76
|
+
'developer-instructions': { type: 'string', description: 'Ignored: BrainX skill guidance is mandatory.' },
|
|
77
|
+
profile: { type: 'string', description: 'Unsupported; use model, cwd or config overrides.' },
|
|
99
78
|
},
|
|
100
79
|
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'codex-reply', description: 'Continue a BrainX review in its native Codex thread.',
|
|
83
|
+
inputSchema: {
|
|
84
|
+
type: 'object', required: ['threadId', 'prompt'], additionalProperties: false,
|
|
85
|
+
properties: { threadId: { type: 'string' }, prompt: { type: 'string' } },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
].map((tool) => ({ ...tool, outputSchema: {
|
|
89
|
+
type: 'object', properties: { threadId: { type: 'string' }, content: { type: 'string' } },
|
|
90
|
+
required: ['threadId', 'content'],
|
|
91
|
+
} }));
|
|
92
|
+
|
|
93
|
+
function reviewOptions(args = {}, mcpServerNames = []) {
|
|
94
|
+
const overrides = Object.fromEntries(Object.entries(args.config || {}).filter(
|
|
95
|
+
([key]) => key !== 'mcp_servers' && !key.startsWith('mcp_servers.'),
|
|
96
|
+
));
|
|
97
|
+
const config = { ...overrides,
|
|
98
|
+
'skills.config': exposedSkills,
|
|
99
|
+
approval_policy: 'never', sandbox_mode: 'read-only',
|
|
100
|
+
base_instructions: systemPrompt, developer_instructions: skillInstructions,
|
|
101
|
+
};
|
|
102
|
+
// Disable only registrations that actually exist. A lone enabled=false
|
|
103
|
+
// override creates an invalid transport when the child has no such server.
|
|
104
|
+
for (const name of mcpServerNames) config[`mcp_servers.${name}.enabled`] = false;
|
|
105
|
+
return {
|
|
106
|
+
...(args.model ? { model: args.model } : {}),
|
|
107
|
+
...(args.cwd ? { cwd: args.cwd } : {}),
|
|
108
|
+
approvalPolicy: 'never', sandbox: 'read-only',
|
|
109
|
+
baseInstructions: systemPrompt, developerInstructions: skillInstructions, config,
|
|
101
110
|
};
|
|
102
111
|
}
|
|
103
112
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
export function serve(client = new AppServerClient()) {
|
|
114
|
+
let initialization;
|
|
115
|
+
let initialized = false;
|
|
116
|
+
const active = new Map();
|
|
117
|
+
const locks = new Set();
|
|
118
|
+
const input = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
119
|
+
const write = (message) => process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', ...message })}\n`);
|
|
120
|
+
const error = (id, code, message) => write({ id, error: { code, message } });
|
|
121
|
+
|
|
122
|
+
async function review(name, args, signal) {
|
|
123
|
+
if (!args || typeof args.prompt !== 'string' || !args.prompt.trim()) {
|
|
124
|
+
throw new Error('prompt must be a non-empty string');
|
|
125
|
+
}
|
|
126
|
+
if (name === 'codex' && args.profile !== undefined) {
|
|
127
|
+
throw new Error('profile is not supported; use explicit model, cwd or config overrides');
|
|
128
|
+
}
|
|
129
|
+
let threadId;
|
|
130
|
+
if (name === 'codex') {
|
|
131
|
+
const servers = args.cwd ? await client.readMcpServerNames(args.cwd) : client.mcpServerNames;
|
|
132
|
+
const result = await client.request('thread/start', reviewOptions(args, servers));
|
|
133
|
+
threadId = result.thread.id;
|
|
134
|
+
} else {
|
|
135
|
+
if (typeof args.threadId !== 'string' || !args.threadId) throw new Error('threadId is required');
|
|
136
|
+
threadId = args.threadId;
|
|
137
|
+
}
|
|
138
|
+
if (locks.has(threadId)) throw new Error('A review is already active on this thread');
|
|
139
|
+
locks.add(threadId);
|
|
140
|
+
try {
|
|
141
|
+
if (signal.aborted) throw new Error('Review cancelled');
|
|
142
|
+
if (name === 'codex-reply') {
|
|
143
|
+
const { thread } = await client.request('thread/read', { threadId, includeTurns: false });
|
|
144
|
+
const servers = thread.cwd ? await client.readMcpServerNames(thread.cwd) : client.mcpServerNames;
|
|
145
|
+
await client.request('thread/resume', {
|
|
146
|
+
threadId, excludeTurns: true, ...reviewOptions({}, servers),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const content = await client.runTurn(threadId, args.prompt, signal);
|
|
150
|
+
return { content: [{ type: 'text', text: content }], structuredContent: { threadId, content } };
|
|
151
|
+
} finally { locks.delete(threadId); }
|
|
117
152
|
}
|
|
118
|
-
});
|
|
119
153
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
154
|
+
async function dispatch(message, signal) {
|
|
155
|
+
const { id, method, params } = message;
|
|
156
|
+
if (method === 'initialize') {
|
|
157
|
+
if (initialization) throw Object.assign(new Error('Already initialized'), { code: -32600 });
|
|
158
|
+
initialization = client.initialize();
|
|
159
|
+
await initialization;
|
|
160
|
+
initialized = true;
|
|
161
|
+
return {
|
|
162
|
+
protocolVersion: ['2024-11-05', '2025-03-26', '2025-06-18', '2025-11-25'].includes(params?.protocolVersion)
|
|
163
|
+
? params.protocolVersion : '2024-11-05',
|
|
164
|
+
capabilities: { tools: {} }, serverInfo: { name: 'brainx-codex-reviewer', version: '2.0.0' },
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (method === 'ping') return {};
|
|
168
|
+
if (!initialized) throw Object.assign(new Error('Not initialized'), { code: -32000 });
|
|
169
|
+
if (method === 'tools/list') return { tools };
|
|
170
|
+
if (method === 'tools/call') {
|
|
171
|
+
if (!tools.some((tool) => tool.name === params?.name)) {
|
|
172
|
+
throw Object.assign(new Error('Unknown reviewer tool'), { code: -32602 });
|
|
173
|
+
}
|
|
174
|
+
try { return await review(params.name, params.arguments, signal); }
|
|
175
|
+
catch (failure) { return { isError: true, content: [{ type: 'text', text: failure.message }] }; }
|
|
176
|
+
}
|
|
177
|
+
throw Object.assign(new Error('Method not found'), { code: -32601 });
|
|
130
178
|
}
|
|
131
|
-
});
|
|
132
|
-
input.on('close', () => child.stdin.end());
|
|
133
179
|
|
|
134
|
-
|
|
135
|
-
|
|
180
|
+
input.on('line', (line) => {
|
|
181
|
+
let message;
|
|
182
|
+
try { message = JSON.parse(line); }
|
|
183
|
+
catch { error(null, -32700, 'Parse error'); return; }
|
|
184
|
+
if (!message || Array.isArray(message) || message.jsonrpc !== '2.0'
|
|
185
|
+
|| typeof message.method !== 'string') {
|
|
186
|
+
error(message?.id ?? null, -32600, 'Invalid request'); return;
|
|
187
|
+
}
|
|
188
|
+
if (message.method === 'notifications/cancelled') {
|
|
189
|
+
active.get(message.params?.requestId)?.controller.abort(); return;
|
|
190
|
+
}
|
|
191
|
+
if (message.id === undefined) return;
|
|
192
|
+
if (active.has(message.id)) { error(message.id, -32600, 'Duplicate active request id'); return; }
|
|
193
|
+
const controller = new AbortController();
|
|
194
|
+
const task = dispatch(message, controller.signal)
|
|
195
|
+
.then((result) => write({ id: message.id, result }))
|
|
196
|
+
.catch((failure) => error(message.id, failure.code || -32603, failure.message))
|
|
197
|
+
.finally(() => active.delete(message.id));
|
|
198
|
+
active.set(message.id, { controller, task });
|
|
199
|
+
});
|
|
200
|
+
input.on('close', () => {
|
|
201
|
+
for (const { controller } of active.values()) controller.abort();
|
|
202
|
+
Promise.allSettled([...active.values()].map(({ task }) => task)).finally(() => client.close());
|
|
203
|
+
});
|
|
204
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
205
|
+
process.once(signal, () => { client.close(); input.close(); process.stdin.pause(); });
|
|
206
|
+
}
|
|
136
207
|
}
|
|
137
208
|
|
|
138
|
-
|
|
139
|
-
input.close();
|
|
140
|
-
process.stdin.pause();
|
|
141
|
-
process.exitCode = code ?? (signal ? 1 : 0);
|
|
142
|
-
});
|
|
209
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) serve();
|
|
@@ -1,6 +1,83 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
import { createInterface } from 'node:readline';
|
|
4
2
|
|
|
3
|
+
const threads = new Map();
|
|
4
|
+
const turns = new Map();
|
|
5
|
+
const approvals = new Map();
|
|
6
|
+
let nextThread = 1;
|
|
7
|
+
let nextTurn = 1;
|
|
8
|
+
const write = (message) => process.stdout.write(`${JSON.stringify(message)}\n`);
|
|
9
|
+
function finish(threadId, turnId, prompt, decision) {
|
|
10
|
+
if (prompt === 'empty') {
|
|
11
|
+
write({ method: 'turn/completed', params: { threadId, turn: { id: turnId, status: 'completed' } } });
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const thread = threads.get(threadId);
|
|
15
|
+
write({ method: 'item/completed', params: { threadId, turnId,
|
|
16
|
+
item: { type: 'agentMessage', id: 'comment', phase: 'commentary', text: 'Ignore commentary' } } });
|
|
17
|
+
// An event from another turn must never enter the report.
|
|
18
|
+
write({ method: 'item/completed', params: { threadId, turnId: 'unrelated',
|
|
19
|
+
item: { type: 'agentMessage', id: 'wrong', text: 'Wrong turn' } } });
|
|
20
|
+
write({ method: 'item/completed', params: { threadId, turnId,
|
|
21
|
+
item: { type: 'agentMessage', id: 'report', phase: 'final_answer',
|
|
22
|
+
text: JSON.stringify({ thread, turn: turns.get(turnId), decision,
|
|
23
|
+
argv: process.argv.slice(2) }) } } });
|
|
24
|
+
write({ method: 'turn/completed', params: { threadId, turn: { id: turnId, status: 'completed' } } });
|
|
25
|
+
}
|
|
26
|
+
|
|
5
27
|
const input = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
6
|
-
input.on('line', (line) =>
|
|
28
|
+
input.on('line', (line) => {
|
|
29
|
+
const { id, method, params, result } = JSON.parse(line);
|
|
30
|
+
if (approvals.has(id)) {
|
|
31
|
+
const turn = approvals.get(id); finish(...turn, result.decision); approvals.delete(id); return;
|
|
32
|
+
}
|
|
33
|
+
if (method === 'initialize') { write({ id, result: {} }); return; }
|
|
34
|
+
if (method === 'config/read') {
|
|
35
|
+
const servers = process.env.TEST_NO_MCP ? {} : { codex: { command: 'node' } };
|
|
36
|
+
if (params.cwd) servers.project_mcp = { command: 'node' };
|
|
37
|
+
write({ id, result: { config: { mcp_servers: servers } } }); return;
|
|
38
|
+
}
|
|
39
|
+
if (method === 'thread/start') {
|
|
40
|
+
const threadId = `thread-${nextThread++}`;
|
|
41
|
+
threads.set(threadId, { start: params, history: [] });
|
|
42
|
+
write({ id, result: { thread: { id: threadId } } }); return;
|
|
43
|
+
}
|
|
44
|
+
if (method === 'thread/resume') {
|
|
45
|
+
const thread = threads.get(params.threadId);
|
|
46
|
+
if (!thread) { write({ id, error: { code: -32000, message: 'Thread not found' } }); return; }
|
|
47
|
+
thread.resume = params;
|
|
48
|
+
write({ id, result: { thread: { id: params.threadId } } }); return;
|
|
49
|
+
}
|
|
50
|
+
if (method === 'thread/read') {
|
|
51
|
+
const thread = threads.get(params.threadId);
|
|
52
|
+
if (!thread) { write({ id, error: { code: -32000, message: 'Thread not found' } }); return; }
|
|
53
|
+
write({ id, result: { thread: { id: params.threadId, cwd: thread.start.cwd } } }); return;
|
|
54
|
+
}
|
|
55
|
+
if (method === 'turn/start') {
|
|
56
|
+
const { threadId } = params;
|
|
57
|
+
const turnId = `turn-${nextTurn++}`;
|
|
58
|
+
const prompt = params.input[0].text;
|
|
59
|
+
threads.get(threadId).history.push(prompt);
|
|
60
|
+
turns.set(turnId, params);
|
|
61
|
+
if (prompt === 'crash') { process.exit(1); }
|
|
62
|
+
if (prompt !== 'early') write({ id, result: { turn: { id: turnId } } });
|
|
63
|
+
if (prompt === 'stall') return;
|
|
64
|
+
if (prompt === 'approval') {
|
|
65
|
+
const approvalId = `approval-${turnId}`;
|
|
66
|
+
approvals.set(approvalId, [threadId, turnId, prompt]);
|
|
67
|
+
write({ id: approvalId, method: 'item/commandExecution/requestApproval', params: { threadId, turnId } });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (prompt === 'fail') {
|
|
71
|
+
write({ method: 'turn/completed', params: { threadId,
|
|
72
|
+
turn: { id: turnId, status: 'failed', error: { message: 'Model unavailable' } } } }); return;
|
|
73
|
+
}
|
|
74
|
+
finish(threadId, turnId, prompt);
|
|
75
|
+
if (prompt === 'early') write({ id, result: { turn: { id: turnId } } });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (method === 'turn/interrupt') {
|
|
79
|
+
write({ id, result: {} });
|
|
80
|
+
write({ method: 'turn/completed', params: { threadId: params.threadId,
|
|
81
|
+
turn: { id: params.turnId, status: 'interrupted' } } });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AppServerClient } from '../../app-server.mjs';
|
|
2
|
+
import { serve } from '../../server.mjs';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
serve(new AppServerClient({ binary: process.execPath,
|
|
5
|
+
prefixArgs: [fileURLToPath(new URL('./fake-codex.mjs', import.meta.url))],
|
|
6
|
+
timeoutMs: Number(process.env.TEST_REVIEW_TIMEOUT_MS || 5000),
|
|
7
|
+
}));
|
|
@@ -1,99 +1,203 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { createInterface } from 'node:readline';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import test from 'node:test';
|
|
6
|
-
import
|
|
6
|
+
import cliInvocation from '../cli-invocation.cjs';
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const server = resolve(testDirectory, '..', 'server.mjs');
|
|
10
|
-
const fakeCodex = resolve(testDirectory, 'fixtures', 'fake-codex.mjs');
|
|
11
|
-
chmodSync(fakeCodex, 0o755);
|
|
8
|
+
const { codexInvocation, npmInvocation } = cliInvocation;
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
10
|
+
const runner = fileURLToPath(new URL('./fixtures/run-server.mjs', import.meta.url));
|
|
11
|
+
class Session {
|
|
12
|
+
constructor(t, env = {}) {
|
|
13
|
+
this.child = spawn(process.execPath, [runner], {
|
|
14
|
+
env: { ...process.env, ...env }, stdio: ['pipe', 'pipe', 'pipe'],
|
|
15
|
+
});
|
|
16
|
+
this.pending = new Map();
|
|
17
|
+
this.nextId = 1;
|
|
18
|
+
this.stderr = '';
|
|
19
|
+
this.child.stderr.on('data', (data) => { this.stderr += data; });
|
|
20
|
+
this.lines = createInterface({ input: this.child.stdout });
|
|
21
|
+
this.lines.on('line', (line) => {
|
|
22
|
+
const message = JSON.parse(line);
|
|
23
|
+
const entry = this.pending.get(message.id);
|
|
24
|
+
if (!entry) return;
|
|
25
|
+
clearTimeout(entry.timer); this.pending.delete(message.id);
|
|
26
|
+
entry.resolve(message);
|
|
27
|
+
});
|
|
28
|
+
this.child.on('exit', () => {
|
|
29
|
+
for (const entry of this.pending.values()) { clearTimeout(entry.timer); entry.reject(new Error(this.stderr)); }
|
|
30
|
+
this.pending.clear();
|
|
18
31
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
child.on('error', reject);
|
|
24
|
-
child.on('exit', (code) => {
|
|
25
|
-
if (code !== 0) {
|
|
26
|
-
reject(new Error(`proxy exited ${code}: ${stderr}`));
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
resolveOutput(stdout.trimEnd().split('\n').map((line) => JSON.parse(line)));
|
|
32
|
+
t.after(async () => {
|
|
33
|
+
this.child.stdin.end();
|
|
34
|
+
if (this.child.exitCode === null) await new Promise((resolve) => this.child.once('exit', resolve));
|
|
35
|
+
this.lines.close();
|
|
30
36
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
}
|
|
38
|
+
send(method, params, id) { this.child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method, params, ...(id === undefined ? {} : { id }) })}\n`); }
|
|
39
|
+
request(method, params) {
|
|
40
|
+
const id = this.nextId++;
|
|
41
|
+
const promise = new Promise((resolve, reject) => {
|
|
42
|
+
const timer = setTimeout(() => { this.child.kill(); reject(new Error(`Timed out: ${method}: ${this.stderr}`)); }, 10000);
|
|
43
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
44
|
+
});
|
|
45
|
+
this.send(method, params, id);
|
|
46
|
+
return { id, promise };
|
|
47
|
+
}
|
|
48
|
+
async call(method, params) {
|
|
49
|
+
const response = await this.request(method, params).promise;
|
|
50
|
+
assert.equal(response.error, undefined, JSON.stringify(response.error));
|
|
51
|
+
return response.result;
|
|
52
|
+
}
|
|
53
|
+
async initialize() {
|
|
54
|
+
await this.call('initialize', { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'test', version: '1' } });
|
|
55
|
+
this.send('notifications/initialized');
|
|
56
|
+
}
|
|
57
|
+
review(args, name = 'codex') { return this.call('tools/call', { name, arguments: args }); }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function assertContract(options) {
|
|
61
|
+
assert.equal(options.approvalPolicy, 'never');
|
|
62
|
+
assert.equal(options.sandbox, 'read-only');
|
|
63
|
+
assert.match(options.baseInstructions, /independent computational-neuroscience/);
|
|
64
|
+
assert.match(options.baseInstructions, /Open and read `brainx-general-guard` first/);
|
|
65
|
+
assert.match(options.baseInstructions, /RETURN_TO_STUDY/);
|
|
66
|
+
assert.match(options.baseInstructions, /# BrainX iteration review/);
|
|
67
|
+
assert.match(options.developerInstructions, /TRAINING_REVIEW_REFERENCE: .*training-workflow\.md/);
|
|
68
|
+
assert.match(options.developerInstructions, /FITTING_REVIEW_REFERENCE: .*parameter-fitting-workflow\.md/);
|
|
69
|
+
assert.doesNotMatch(options.developerInstructions, /^- brainx-modeling-loop$/m);
|
|
70
|
+
assert.equal(options.config['skills.config'].length, 8);
|
|
71
|
+
assert.ok(options.config['skills.config'].every((skill) => skill.enabled));
|
|
72
|
+
assert.equal(options.config['mcp_servers.codex.enabled'], false);
|
|
73
|
+
assert.equal(options.config.approval_policy, 'never');
|
|
74
|
+
assert.equal(options.config.sandbox_mode, 'read-only');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
test('advertises legacy tool names over MCP after initializing App Server', async (t) => {
|
|
78
|
+
const session = new Session(t); await session.initialize();
|
|
79
|
+
const result = await session.call('tools/list');
|
|
80
|
+
assert.deepEqual(result.tools.map((tool) => tool.name), ['codex', 'codex-reply']);
|
|
81
|
+
assert.deepEqual(result.tools[1].inputSchema.required, ['threadId', 'prompt']);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('starts a native review with enforced instructions, read-only policy and caller settings', async (t) => {
|
|
85
|
+
const session = new Session(t); await session.initialize();
|
|
86
|
+
const result = await session.review({ prompt: 'Review iteration 4', model: 'test-model', cwd: process.cwd(),
|
|
87
|
+
sandbox: 'danger-full-access', 'approval-policy': 'on-request',
|
|
88
|
+
'base-instructions': 'bypass', config: { model_reasoning_effort: 'xhigh',
|
|
89
|
+
sandbox_mode: 'danger-full-access', 'skills.config': [],
|
|
90
|
+
mcp_servers: { other: { command: 'node' } }, 'mcp_servers.other.command': 'node' } });
|
|
91
|
+
assert.equal(result.isError, undefined);
|
|
92
|
+
const report = JSON.parse(result.content[0].text);
|
|
93
|
+
assertContract(report.thread.start);
|
|
94
|
+
assert.equal(report.thread.start.model, 'test-model');
|
|
95
|
+
assert.equal(report.thread.start.cwd, process.cwd());
|
|
96
|
+
assert.equal(report.thread.start.config.model_reasoning_effort, 'xhigh');
|
|
97
|
+
assert.equal(report.thread.start.config['mcp_servers.project_mcp.enabled'], false);
|
|
98
|
+
assert.equal(report.thread.start.config['mcp_servers.other.command'], undefined);
|
|
99
|
+
assert.equal(report.thread.start.config.mcp_servers, undefined);
|
|
100
|
+
assert.deepEqual(report.argv, ['app-server', '--listen', 'stdio://']);
|
|
101
|
+
assert.equal(result.structuredContent.threadId, 'thread-1');
|
|
102
|
+
assert.equal(result.structuredContent.content, result.content[0].text);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('resumes the same native thread and reapplies reviewer constraints', async (t) => {
|
|
106
|
+
const session = new Session(t); await session.initialize();
|
|
107
|
+
const first = await session.review({ prompt: 'first', cwd: process.cwd() });
|
|
108
|
+
const threadId = first.structuredContent.threadId;
|
|
109
|
+
const next = await session.review({ threadId, prompt: 'follow-up' }, 'codex-reply');
|
|
110
|
+
const report = JSON.parse(next.content[0].text);
|
|
111
|
+
assert.deepEqual(report.thread.history, ['first', 'follow-up']);
|
|
112
|
+
assertContract(report.thread.resume);
|
|
113
|
+
assert.equal(report.thread.resume.config['mcp_servers.project_mcp.enabled'], false);
|
|
114
|
+
assert.equal(report.thread.resume.excludeTurns, true);
|
|
115
|
+
assert.equal(next.structuredContent.threadId, threadId);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('handles completion arriving before the turn/start response', async (t) => {
|
|
119
|
+
const session = new Session(t); await session.initialize();
|
|
120
|
+
const result = await session.review({ prompt: 'early' });
|
|
121
|
+
assert.equal(result.isError, undefined);
|
|
122
|
+
assert.deepEqual(JSON.parse(result.content[0].text).thread.history, ['early']);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
for (const [prompt, message] of [['fail', /Model unavailable/], ['empty', /without a report/], ['crash', /exited/]]) {
|
|
126
|
+
test(`returns a tool error for ${prompt}`, async (t) => {
|
|
127
|
+
const session = new Session(t); await session.initialize();
|
|
128
|
+
const result = await session.review({ prompt });
|
|
129
|
+
assert.equal(result.isError, true); assert.match(result.content[0].text, message);
|
|
35
130
|
});
|
|
36
131
|
}
|
|
37
132
|
|
|
38
|
-
test('
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
assert.match(
|
|
61
|
-
assert.match(args['base-instructions'], /\*\*Architecture:\*\*/);
|
|
62
|
-
assert.match(args['base-instructions'], /\*\*Hyperparameters and method:\*\*/);
|
|
63
|
-
assert.match(args['base-instructions'], /BrainState's prebuilt `brainstate\.nn` layers/);
|
|
64
|
-
assert.match(args['base-instructions'], /braintools\.optim\.Adam/);
|
|
65
|
-
assert.match(args['base-instructions'], /BrainTools API gap/);
|
|
66
|
-
assert.match(args['base-instructions'], /RETURN_TO_STUDY/);
|
|
67
|
-
assert.match(args['base-instructions'], /Return a Markdown document as the tool response/);
|
|
68
|
-
assert.match(args['base-instructions'], /# BrainX iteration review/);
|
|
69
|
-
assert.match(args['base-instructions'], /- \*\*OUTCOME:\*\* `PASS \| REFUSE`/);
|
|
70
|
-
assert.match(args['base-instructions'], /- \*\*LOSS_CLOSURE:\*\* `NOT_APPLICABLE/);
|
|
71
|
-
assert.match(args['base-instructions'], /## Findings/);
|
|
72
|
-
assert.doesNotMatch(args['base-instructions'], /```text\s+OUTCOME:/);
|
|
73
|
-
assert.match(args['base-instructions'], /Keep plotting code minimal and clean/);
|
|
74
|
-
assert.match(args['developer-instructions'], /brainx-general-guard/);
|
|
75
|
-
assert.match(args['developer-instructions'], /TRAINING_REVIEW_REFERENCE: \/.*\/training-workflow\.md/);
|
|
76
|
-
assert.match(args['developer-instructions'], /FITTING_REVIEW_REFERENCE: \/.*\/parameter-fitting-workflow\.md/);
|
|
77
|
-
assert.doesNotMatch(args['developer-instructions'], /^- brainx-modeling-loop$/m);
|
|
78
|
-
assert.equal(args.config.model_reasoning_effort, 'xhigh');
|
|
79
|
-
assert.equal(args['approval-policy'], 'never');
|
|
80
|
-
assert.equal(args.sandbox, 'read-only');
|
|
81
|
-
assert.equal(args.config['skills.config'].length, 8);
|
|
82
|
-
assert.ok(args.config['skills.config'].every((skill) => skill.enabled));
|
|
83
|
-
assert.ok(args.config['skills.config'].every((skill) => skill.path.startsWith('/')));
|
|
133
|
+
test('declines unexpected command approval rather than granting write access', async (t) => {
|
|
134
|
+
const session = new Session(t); await session.initialize();
|
|
135
|
+
const result = await session.review({ prompt: 'approval' });
|
|
136
|
+
assert.equal(JSON.parse(result.content[0].text).decision, 'decline');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('cancellation interrupts the native turn and leaves the thread usable', async (t) => {
|
|
140
|
+
const session = new Session(t); await session.initialize();
|
|
141
|
+
const first = await session.review({ prompt: 'first' }); const threadId = first.structuredContent.threadId;
|
|
142
|
+
const request = session.request('tools/call', { name: 'codex-reply', arguments: { threadId, prompt: 'stall' } });
|
|
143
|
+
// Let the fake backend start its stalled turn before cancellation.
|
|
144
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
145
|
+
session.send('notifications/cancelled', { requestId: request.id });
|
|
146
|
+
const cancelled = (await request.promise).result;
|
|
147
|
+
assert.equal(cancelled.isError, true); assert.match(cancelled.content[0].text, /interrupted|cancelled/i);
|
|
148
|
+
const next = await session.review({ threadId, prompt: 'after cancellation' }, 'codex-reply');
|
|
149
|
+
assert.equal(next.isError, undefined);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('a stalled review times out instead of leaving the MCP call pending', async (t) => {
|
|
153
|
+
const session = new Session(t, { TEST_REVIEW_TIMEOUT_MS: '300' }); await session.initialize();
|
|
154
|
+
const result = await session.review({ prompt: 'stall' });
|
|
155
|
+
assert.equal(result.isError, true); assert.match(result.content[0].text, /timed out/);
|
|
84
156
|
});
|
|
85
157
|
|
|
86
|
-
test('
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
158
|
+
test('rejects invalid input, unknown tools, and requests before initialization', async (t) => {
|
|
159
|
+
const session = new Session(t);
|
|
160
|
+
assert.equal((await session.request('tools/list').promise).error.code, -32000);
|
|
161
|
+
await session.initialize();
|
|
162
|
+
assert.equal((await session.review({ prompt: '' })).isError, true);
|
|
163
|
+
assert.equal((await session.review({ prompt: 'x', profile: 'unsafe' })).isError, true);
|
|
164
|
+
assert.equal((await session.request('tools/call', { name: 'unknown', arguments: {} }).promise).error.code, -32602);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('resolves Windows npm shims without a shell and preserves argument boundaries', () => {
|
|
168
|
+
const entry = 'C:\\Program Files\\npm\\node_modules\\@openai\\codex\\bin\\codex.js';
|
|
169
|
+
const shim = 'C:\\Program Files\\npm\\codex.cmd';
|
|
170
|
+
const invocation = codexInvocation('codex', ['argument with spaces'], {
|
|
171
|
+
platform: 'win32', pathValue: 'C:\\missing;"C:\\Program Files\\npm"',
|
|
172
|
+
exists: (path) => [shim, entry].includes(path),
|
|
173
|
+
});
|
|
174
|
+
assert.equal(invocation.binary, process.execPath);
|
|
175
|
+
assert.deepEqual(invocation.prefixArgs, [entry, 'argument with spaces']);
|
|
176
|
+
assert.throws(() => codexInvocation(shim, [], { platform: 'win32', exists: () => false }), /BRAINX_CODEX_BIN/);
|
|
177
|
+
|
|
178
|
+
const localShim = 'C:\\Program Files\\npm\\node_modules\\.bin\\codex.cmd';
|
|
179
|
+
assert.deepEqual(codexInvocation(localShim, [], {
|
|
180
|
+
platform: 'win32', exists: (path) => path === entry,
|
|
181
|
+
}), { binary: process.execPath, prefixArgs: [entry] });
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('runs npm through its JavaScript entry when installing runtimes on Windows', () => {
|
|
185
|
+
const root = 'C:\\Program Files\\nodejs';
|
|
186
|
+
const entry = `${root}\\node_modules\\npm\\bin\\npm-cli.js`;
|
|
187
|
+
const args = ['install', '--ignore-scripts'];
|
|
188
|
+
const options = {
|
|
189
|
+
platform: 'win32', pathValue: root,
|
|
190
|
+
exists: (path) => [`${root}\\npm.cmd`, entry].includes(path),
|
|
95
191
|
};
|
|
96
|
-
const
|
|
192
|
+
for (const npmExecPath of ['', entry]) {
|
|
193
|
+
const invocation = npmInvocation('npm', args, { ...options, npmExecPath });
|
|
194
|
+
assert.deepEqual(invocation, { binary: process.execPath, prefixArgs: [entry, ...args] });
|
|
195
|
+
}
|
|
196
|
+
});
|
|
97
197
|
|
|
98
|
-
|
|
198
|
+
test('does not manufacture an invalid disabled MCP transport in an empty child configuration', async (t) => {
|
|
199
|
+
const session = new Session(t, { TEST_NO_MCP: '1' }); await session.initialize();
|
|
200
|
+
const result = await session.review({ prompt: 'isolated config' });
|
|
201
|
+
assert.equal(result.isError, undefined);
|
|
202
|
+
assert.equal(JSON.parse(result.content[0].text).thread.start.config['mcp_servers.codex.enabled'], undefined);
|
|
99
203
|
});
|
package/package.json
CHANGED